Image set processing method and device for dynamically adjusting small image texture and medium
Through dynamic atlas technology, the tree area splitting and insertion/deletion algorithm is used to solve the problem of low-efficiency atlas management in game development, improve game rendering efficiency and memory utilization, reduce drawing commands, and meet game interface requirements .
Patent Information
- Application Number
- CN202410886824.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-11-22
AI Technical Summary
The static and dynamic graphic atlas technologies used in existing game development have problems such as low development efficiency, low space utilization and increased number of graphic atlas, which lead to low rendering efficiency, especially when there are many textures in the game interface, which leads to frequent switching of graphic atlas. Add drawing commands to affect the game experience.
By designing a dynamic picture atlas, dividing tree areas and dynamically inserting and deleting small pictures according to preset splitting methods, ensuring compact arrangement and efficient utilization in the picture atlas, reducing drawing commands during rendering, and improving the utilization of memory space.
It realizes the function of dynamically adding and removing small pictures, reducing drawing commands during rendering, improving game rendering efficiency, rationally utilizing memory space, avoiding space waste, and meeting runtime needs.
Smart Images

Figure CN119006950A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of game interface image processing, and in particular to an atlas processing method, device and medium for dynamically adjusting small image textures. Background Art
[0002] Many images are used in game development, and each image corresponds to a texture. When the game is rendered, a drawing command is submitted for each texture. When there are too many textures in the game rendering interface, the game frame rate will drop, thus affecting the gaming experience.
[0003] If you merge the small images into a large atlas in advance, you can use one drawing to complete the rendering operation of all the corresponding images in the atlas, which greatly reduces the problem of increased drawing commands caused by rendering different textures. There are many methods for generating and using atlases on the market, mainly in the following two ways: one is to use tools to merge small images into atlases in advance, and directly use atlases instead of small images in the project, that is, use static atlases. The second is to dynamically merge small images into atlases during the game running process, and arrange them in the order of insertion into the atlas. The height of each row in the atlas is the height of the highest image in the row. If there are many small images, multiple atlases will be generated.
[0004] Both of the above methods have great limitations: using static atlases affects development efficiency. During the development process, there is often a need to modify image resources, and each change requires a new atlas. Although automatic merging is convenient, the existing technology has low space utilization. The space utilization is affected by the height difference of small images and the order of merging. There will be a large number of idle areas, and it does not support dynamic removal of small images, resulting in an increasing number of atlases. As the number of atlases increases, it is difficult to ensure that different small images displayed on the interface can be put into the same atlas, resulting in the need to frequently switch atlases during rendering, thereby increasing the call of drawing commands. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a method, device and medium for processing an atlas for dynamically adjusting the texture of small images, effectively avoiding the problem of too many drawing commands and low rendering efficiency due to a large number of images in the game rendering process, while improving memory utilization.
[0006] In a first aspect, the present invention provides an atlas processing method for dynamically adjusting small image textures, comprising: Step 1, set an atlas, divide the atlas texture into tree-like regions, pre-define the root region as a horizontal region or a vertical region, and set the region splitting method. The further splitting of the horizontal region is left-right splitting, the left side is a vertical region, and the right side is a horizontal region. The further splitting of the vertical region is top-bottom splitting, the top side is a horizontal region, and the bottom side is a vertical region. Step 2: When a small image needs to be inserted into the atlas, find an area that can accommodate the current small image from the root area layer by layer and insert the small image into the atlas in combination with a preset area splitting method; Step 3: Before rendering each frame, check whether the free area of the texture is less than a threshold. If so, delete small images with a usage frequency lower than a preset value and release the free area.
[0007] Furthermore, the specific process of "inserting the small image into the atlas" in step 2 is as follows: Step 21, recursively traverse from the head root area to find a free area large enough to accommodate the small image; Step 22, determining whether the idle area is a horizontal area, if so, proceeding to step 23, otherwise, proceeding to step 24; Step 23, determine whether the width of the idle area minus the width of the thumbnail is less than the minimum width, if so, put the thumbnail into the idle area and end the process; otherwise, split the idle area into two left and right areas, set the left area as a vertical area, the right area as a horizontal area, and set the width of the left area to the thumbnail width, then split the left area into two upper and lower areas, the upper area is a horizontal area, the lower area is a vertical area, and the size of the upper area is the size of the thumbnail, and insert the thumbnail into the upper area; Step 24, determine whether the height of the idle area minus the height of the thumbnail is less than the minimum height. If so, put the thumbnail into the idle area and end the process; otherwise, split the idle area into two upper and lower areas, set the upper area as the horizontal area, the lower area as the vertical area, and set the height of the upper area to the height of the thumbnail. Then split the upper area into two left and right areas, the left area as the vertical area, the right area as the horizontal area, and the size of the left area is the size of the thumbnail, and insert the thumbnail into the left area.
[0008] Furthermore, after inserting the small image by splitting the region, the split region is also reorganized, as follows: After "inserting the small image into the upper area" in step 23, the method further includes: determining whether the parent area of the idle area is also a horizontal area, if so, deleting the idle area, and directly adding the left and right areas of the idle area to the parent area of the idle area, otherwise, adding the left and right areas to the idle area; After "inserting the small image into the left area" in step 24, it also includes: determining whether the parent area of the idle area is also a vertical area. If so, deleting the idle area and directly adding the upper and lower areas of the idle area to the parent area of the idle area; otherwise, adding the upper and lower areas to the idle area.
[0009] Furthermore, before step 2, the step also includes initializing the root area, defining the size of the root area, and defining the direction of the root area as horizontal or vertical.
[0010] Furthermore, when a small image is inserted into the atlas for the first time, small images that meet the conditions are recursively inserted in a pre-order traversal manner until the atlas is full. The small images that meet the conditions are small images in uncompressed format and the size of the small images is smaller than a preset size. When refreshing the frame afterwards, if there is a small image that needs to be rendered and the small image is not in the atlas, the small image is dynamically inserted into the atlas.
[0011] Furthermore, the step 3 specifically includes: Step 31: Before rendering each frame, check whether the free area of the texture is less than the threshold. If so, sort all the small images according to the frequency of use and go to step 32. Otherwise, end the process. Step 32: Calculate the small images to be deleted according to the size of the area to be reclaimed and the order in which the small images are arranged; Step 33, delete the area where the thumbnail is located; Step 34: reset the current area to an idle area, determine whether the idle area has a parent area, if so, obtain its index in the parent area, merge the areas before the index in sequence until a non-idle area is encountered, and then merge the areas after the index in sequence until a non-idle area is encountered; otherwise, end the process; Step 35: If there is only one child area left in the parent area of the idle area, delete the current idle area, and return to step 34 with its parent area as the current area for recursive deletion.
[0012] In a second aspect, the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.
[0013] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0014] The advantages of the present invention are: by designing a dynamic atlas, it supports dynamic addition and removal of small pictures, only one atlas is needed to meet runtime requirements, the number of drawing commands in the rendering process is reduced, and the game rendering efficiency is improved; and through a customized small picture insertion and deletion algorithm, the area is reasonably utilized, making the image inside the atlas more compact, reducing space waste, and improving memory space utilization. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 This is a flowchart of an execution of an atlas processing method for dynamically adjusting small image textures in Embodiment 1 of the present invention; Figure 2 is a schematic diagram of the structure of an electronic device in Embodiment 2 of the present invention; Figure 3 Schematic diagram of the structure of the medium in the third embodiment of the present invention.
[0016] Figure 4 This is a schematic diagram of the regional structure of the first small image inserted into the atlas in a specific implementation manner of the present invention.
[0017] Figure 5 for Figure 4 Dendrogram corresponding to the schematic diagram of the regional structure.
[0018] Figure 6 This is a schematic diagram of the regional structure after the second small picture in a specific implementation manner of the present invention is inserted into the atlas.
[0019] Figure 7 for Figure 4 Dendrogram corresponding to the schematic diagram of the regional structure.
[0020] Figure 8 for Figure 7 The dendrogram obtained after the pruning operation.
[0021] Fig. 9 for Figure 8 The corresponding dendrogram after deleting the second small image. DETAILED DESCRIPTION
[0022] The present invention designs a set of algorithms to enable the dynamic atlas to support dynamic addition and removal of small images, and has a high space utilization rate. Only one atlas is needed to meet runtime requirements.
[0023] Embodiment 1 like Figure 1 As shown, a method for processing an atlas for dynamically adjusting the texture of a small image of the present invention comprises: Step 1, set an atlas, divide the atlas texture into tree-like regions, pre-define the root region as a horizontal region or a vertical region, and set the region splitting method. The further splitting of the horizontal region is left-right splitting, the left side is a vertical region, and the right side is a horizontal region. The further splitting of the vertical region is top-bottom splitting, the top side is a horizontal region, and the bottom side is a vertical region. Step 2: When a small image needs to be inserted into the atlas, find an area that can accommodate the current small image from the root area layer by layer and insert the small image into the atlas in combination with a preset area splitting method; Step 3: Before rendering each frame, check whether the free area of the texture is less than a threshold. If so, delete small images with a usage frequency lower than a preset value and release the free area.
[0024] Preferably, the specific process of "inserting the small image into the atlas" in step 2 is as follows: Step 21, recursively traverse from the head root area to find a free area large enough to accommodate the small image; Step 22, determining whether the idle area is a horizontal area, if so, proceeding to step 23, otherwise, proceeding to step 24; Step 23, determine whether the width of the idle area minus the width of the thumbnail is less than the minimum width, if so, put the thumbnail into the idle area and end the process; otherwise, split the idle area into two left and right areas, set the left area as a vertical area, the right area as a horizontal area, and set the width of the left area to the thumbnail width, then split the left area into two upper and lower areas, the upper area is a horizontal area, the lower area is a vertical area, and the size of the upper area is the size of the thumbnail, and insert the thumbnail into the upper area; Step 24, determine whether the height of the idle area minus the height of the thumbnail is less than the minimum height. If so, put the thumbnail into the idle area and end the process; otherwise, split the idle area into two upper and lower areas, set the upper area as the horizontal area, the lower area as the vertical area, and set the height of the upper area to the height of the thumbnail. Then split the upper area into two left and right areas, the left area as the vertical area, the right area as the horizontal area, and the size of the left area is the size of the thumbnail, and insert the thumbnail into the left area.
[0025] Preferably, after inserting the thumbnail by splitting the region, the split region is also reorganized, as follows: After "inserting the small image into the upper area" in step 23, the method further includes: determining whether the parent area of the idle area is also a horizontal area, if so, deleting the idle area, and directly adding the left and right areas of the idle area to the parent area of the idle area, otherwise, adding the left and right areas to the idle area; After "inserting the small image into the left area" in step 24, it also includes: determining whether the parent area of the idle area is also a vertical area. If so, deleting the idle area and directly adding the upper and lower areas of the idle area to the parent area of the idle area; otherwise, adding the upper and lower areas to the idle area.
[0026] Preferably, before step 2, the step further includes initializing the root area, defining the size of the root area, and defining the direction of the root area as horizontal or vertical.
[0027] Preferably, when inserting a small image into the atlas for the first time, recursively insert small images that meet the conditions in a pre-order traversal manner until the atlas is full, and the small images that meet the conditions are small images in an uncompressed format and the size of the small images is smaller than a preset size; subsequently, when refreshing the frame, if there is a small image that needs to be rendered and the small image is not in the atlas, the small image is dynamically inserted into the atlas, and the insertion method is the same as the insertion method of the small image for the first time.
[0028] Preferably, the step 3 specifically includes: Step 31: Before rendering each frame, check whether the free area of the texture is less than the threshold. If so, sort all the small images according to the frequency of use and go to step 32. Otherwise, end the process. Step 32: Calculate the small images to be deleted according to the size of the area to be reclaimed and the order in which the small images are arranged; Step 33, delete the area where the thumbnail is located; Step 34: reset the current area to an idle area, determine whether the idle area has a parent area, if so, obtain its index in the parent area, merge the areas before the index in sequence until a non-idle area is encountered, and then merge the areas after the index in sequence until a non-idle area is encountered; otherwise, end the process; Step 35: If there is only one child area left in the parent area of the idle area, delete the current idle area, and return to step 34 with its parent area as the current area for recursive deletion.
[0029] In order to more clearly illustrate the thumbnail insertion process of the present invention, the following is an example with reference to the accompanying drawings: 1 Initialize the root region. Set the region size (i.e. free size, texture size), and the region direction is vertical (the root region can set the size and direction as needed).
[0030] 2. Start recursively traversing from the head root area and find area a with sufficient free space.
[0031] 3 If area a is a horizontal area, then: 3.1 If the width of area a minus the width of the thumbnail is less than the minimum width, put the thumbnail into area a and end.
[0032] 3.2 Split area a into two left and right areas a1 and a2. The width of the left area a1 is the width of the small picture, vertically. The right area a2 is horizontally. Then split the vertical area a1 into two upper and lower areas b1 and b2. The size of b1 is the size of the small picture. b1 is the horizontal area and b2 is the vertical area.
[0033] 3.2.1 If the parent area of area a is also a horizontal area, delete area a and add areas a1 and a2 to the parent area of area a. Otherwise, add areas a1 and a2 to area a.
[0034] 3.2.2 Continue recursive insertion with area a1. 4 If area a is a vertical area, then: 4.1 If the height of area a minus the height of the small image is less than the minimum height, put the small image into area a and end.
[0035] 4.2 Split area a into two upper and lower areas a1 and a2. The height of the upper area a1 is the height of the small picture, horizontally. The right area a2 is vertically. Then split the horizontal area a1 into two left and right areas b1 and b2. The size of b1 is the size of the small picture. b1 is a vertical area and b2 is a horizontal area.
[0036] 4.2.1 If the parent region of region a is also a vertical region, delete region a and add regions a1 and a2 to the parent region of region a. Otherwise, add regions a1 and a2 to region a.
[0037] 4.2.2 Continue recursive insertion with area a1.
[0038] Since the root area is set as a vertical area, when the thumbnail is inserted for the first time, it will be divided into two areas a1 and a2, and a1 is set as a horizontal area, a2 is set as a vertical area, and a1 is divided into b1 and b2. Since a1 is positioned as a horizontal area, b1 and b2 are the vertical area on the left and the horizontal area on the right respectively, and the size of b1 is set to the size of the first thumbnail. The first thumbnail is inserted into b1. The regional distribution structure at this time is as follows: Figure 4 The corresponding tree diagram is shown in Figure 5 As shown; When the second small image needs to be inserted, continue to insert it according to the above insertion method. Specifically, starting from the root area, the traversal order is: root area-a1-b1-b2-a2. Since the root area and a1 are not leaf nodes, they will be ignored. b1 has been occupied, so the actual traversal order is b2-a2. When traversing to the free area b2, it is found that its free size is large enough. At this time, after judging it as a horizontal area, its width minus the width of the small image is still greater than the minimum width. Therefore, the binary split method is used again to further divide the horizontal area b2 into the vertical area c1 on the left and the horizontal area c2 on the right, and then divide the vertical area into the upper horizontal area d1 and the lower vertical area d2. The size of d1 is set to the size of the second small image, and the second small image is inserted into d1. The regional distribution structure at this time is as follows Figure 6 The corresponding tree diagram is shown in Figure 7 As shown; In order to further optimize the tree structure, the present invention also designs a branch reduction method so that the calculation of hierarchical relationships can be reduced and efficiency can be improved when the region is reorganized later. For example, when the first small graph is inserted for the first time, the idle area found is the root area, so there is no need to perform a branch reduction operation if there is no corresponding parent area. However, when the second small graph is inserted, since the idle area b2 found has a parent area, and b2 and its parent area a1 are both horizontal areas, a branch reduction operation is performed to delete the b2 node and add the child nodes of b2 (c1 and c2) directly to the parent node a1 of b2, that is, a1 contains the child areas b1, c1, and c2, see FIG. Figure 8 The tree structure shown.
[0039] Similarly, when you need to delete a small image, for example, when you need to delete the second small image, delete the area where the second small image is located, that is, the area of d1, set the area of d1 as a free area, and then find its index in its parent area. Its parent area is c1, and the child areas of c1 are d1 and d2 from left to right. Therefore, the index of area d1 in parent area c1 is the first child area. Then, if no brother area is found in the front, search forward, and find that the brother area d2 is free in the back, then merge the two. After the merger, there is only one child area under c1. Therefore, delete c1 again. Similarly, take c1 as the current free area, obtain and find its parent area a1, and then find c1's brother areas (b1, c2) through a1. After merging forward, it is found that b1 is not free, so the free c2 is found backward and merged into c2. At this time, there are only child areas b1 and c2 left under a1. Since there is more than one child area, the process ends. See Fig. 9 shown.
[0040] Based on the same inventive concept, the present application provides an electronic device embodiment corresponding to the first embodiment, see the second embodiment for details.
[0041] Embodiment 2 This embodiment provides an electronic device, such as Figure 2 As shown, it includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in the first embodiment can be implemented.
[0042] Since the electronic device introduced in this embodiment is a device used to implement the method in the first embodiment of the present application, based on the method introduced in the first embodiment of the present application, a person skilled in the art can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the device used by the method in the embodiment of the present application, it belongs to the scope of protection of the present application.
[0043] Based on the same inventive concept, the present application provides a storage medium corresponding to Example 1, see Example 3 for details.
[0044] Embodiment 3 This embodiment provides a computer-readable storage medium, such as Figure 3 As shown, a computer program is stored thereon, and when the computer program is executed by a processor, any implementation method in Example 1 can be implemented.
[0045] The above method of the present invention can realize the dynamic insertion and dynamic deletion process of the dynamic atlas. When the atlas is distributed for the first time, each small picture is recursively inserted into the atlas through a preset insertion method until it can no longer be inserted, that is, the position is full. Then, in the subsequent frame refresh process, space is released before the frame refresh, and a certain space is reserved to prevent small pictures from needing to be inserted subsequently. After the space is released before each frame refresh, if there is a small picture that needs to be rendered and the small picture is not in the atlas, the small picture will be inserted into the atlas to realize dynamic deletion and insertion. At the same time, the present invention also sets a dynamic illustration and deletion algorithm for the atlas, which can reasonably allocate the space of the atlas, arrange it as compactly as possible, maximize the use of the space of the atlas, reduce the generation of gaps, and improve memory utilization.
[0046] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A method for processing an atlas for dynamically adjusting the texture of a small image, characterized in that: include: Step 1, set an atlas, divide the atlas texture into tree-like regions, pre-define the root region as a horizontal region or a vertical region, and set the region splitting method. The further splitting of the horizontal region is left-right splitting, the left side is a vertical region, and the right side is a horizontal region. The further splitting of the vertical region is top-bottom splitting, the top side is a horizontal region, and the bottom side is a vertical region. Step 2: When a small image needs to be inserted into the atlas, find an area that can accommodate the current small image from the root area layer by layer and insert the small image into the atlas in combination with a preset area splitting method; Step 3: Before rendering each frame, check whether the free area of the texture is less than a threshold. If so, delete small images with a usage frequency lower than a preset value and release the free area.
2. The atlas processing method for dynamically adjusting the texture of a small image as claimed in claim 1, characterized in that: The specific process of "inserting a small image into the atlas" in step 2 is as follows: Step 21, recursively traverse from the head root area to find a free area large enough to accommodate the small image; Step 22, determining whether the idle area is a horizontal area, if so, proceeding to step 23, otherwise, proceeding to step 24; Step 23, determine whether the width of the idle area minus the width of the thumbnail is less than the minimum width, if so, put the thumbnail into the idle area and end the process; otherwise, split the idle area into two left and right areas, set the left area as a vertical area, the right area as a horizontal area, and set the width of the left area to the thumbnail width, then split the left area into two upper and lower areas, the upper area is a horizontal area, the lower area is a vertical area, and the size of the upper area is the size of the thumbnail, and insert the thumbnail into the upper area; Step 24, determine whether the height of the idle area minus the height of the thumbnail is less than the minimum height. If so, put the thumbnail into the idle area and end the process; otherwise, split the idle area into two upper and lower areas, set the upper area as the horizontal area, the lower area as the vertical area, and set the height of the upper area to the height of the thumbnail. Then split the upper area into two left and right areas, the left area as the vertical area, the right area as the horizontal area, and the size of the left area is the size of the thumbnail, and insert the thumbnail into the left area.
3. The atlas processing method for dynamically adjusting the texture of a small image as claimed in claim 2, characterized in that: After inserting the thumbnails by splitting the regions, the split regions are also reorganized as follows: After "inserting the small image into the upper area" in step 23, the method further includes: determining whether the parent area of the idle area is also a horizontal area, if so, deleting the idle area, and directly adding the left and right areas of the idle area to the parent area of the idle area; otherwise, adding the left and right areas to the idle area; After "inserting a small image into the left area" in step 24, the method further includes: determining whether the parent area of the idle area is also a vertical area; if so, deleting the idle area, and directly adding the upper and lower areas of the idle area to the parent area of the idle area; otherwise, adding the upper and lower areas to the idle area.
4. The atlas processing method for dynamically adjusting the texture of a small image as claimed in claim 1, characterized in that: The step 2 also includes initializing the root area, defining the size of the root area, and defining the direction of the root area as horizontal or vertical.
5. The atlas processing method for dynamically adjusting small image textures according to claim 1, characterized in that: When inserting a small image into the atlas for the first time, recursively insert small images that meet the conditions in a pre-order traversal manner until the atlas is full. The small images that meet the conditions are small images in uncompressed format and the size of the small images is smaller than the preset size. When refreshing the frame afterwards, if there is a small image that needs to be rendered and the small image is not in the atlas, the small image is dynamically inserted into the atlas.
6. The atlas processing method for dynamically adjusting small image textures according to claim 1, characterized in that: The step 3 specifically includes: Step 31: Before rendering each frame, check whether the free area of the texture is less than the threshold. If so, sort all the small images according to the frequency of use and go to step 32. Otherwise, end the process. Step 32: Calculate the small images to be deleted according to the size of the area to be reclaimed and the order in which the small images are arranged; Step 33, delete the area where the thumbnail is located; Step 34: reset the current area to an idle area, determine whether the idle area has a parent area, if so, obtain its index in the parent area, merge the areas before the index in sequence until a non-idle area is encountered, and then merge the areas after the index in sequence until a non-idle area is encountered; otherwise, end the process; Step 35: If there is only one child area left in the parent area of the idle area, delete the current idle area, and return to step 34 with its parent area as the current area for recursive deletion.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 6 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
