Animation rendering method, device, electronic device and storage medium
By reasonably allocating the storage locations of vertex position information and normal information in the texture file, the problem of low efficiency in texture storage animation data in the prior art is solved, and the effect of reducing the number of samples and improving efficiency is achieved.
Patent Information
- Application Number
- CN202210342235.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-03-31
AI Technical Summary
The existing methods of storing animation data through textures are less efficient, especially when a large number of rendering objects, resulting in high hardware pressure and large sampling times.
By placing a part of the RGB channel in the same texture file, the vertex position information and normal information occupy a part of the RGB channel and using the A channel to store normal information, it is necessary to sample only one texture file during the animation rendering process to obtain the required information.
Reduces the number of texture samples during rendering, improves the efficiency of storing animation data through textures, and reduces hardware bandwidth pressure.
Smart Images

Figure CN114882149B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of animation technology, and in particular to an animation rendering method, device, electronic device and storage medium. Background Art
[0002] With the development of games, the more objects are rendered in the game, the better the game effect will be. For example, in strategy games (SLG), large-scale soldiers marching and fighting are an indispensable part of the game. Current games generally use the graphics processing unit (GPU) skin instance method to render a large number of soldiers, reduce draw calls and improve game efficiency. GPU Skin Instance is a method of rendering multiple skin meshes in one Drawcall through the GPU instantiation rendering capability. The premise of Instance rendering is that all skin meshes use the same resources, including material parameters and skeletal animation data. Traditional animation data is set object by object. Before rendering each skin mesh, the skeletal animation is updated and transferred to the constant buffer const buffer for GPU skin use. Therefore, in order to implement Skin Instance of skin mesh, the animation data must be packaged into a resource. The more appropriate method is to store it in a texture. When rendering animation, the animation data is obtained by sampling the texture and rendered. However, the efficiency of storing animation data in texture is currently low. Summary of the invention
[0003] An animation rendering method, device, electronic device and storage medium can improve the efficiency of storing animation data through texture.
[0004] In a first aspect, an animation rendering method is provided, comprising:
[0005] In vertex animation mode, vertex position information and normal information are obtained from the same first texture file, the vertex position information occupies part of the R channel, part of the G channel and part of the B channel, and the normal information occupies another part of the R channel, another part of the G channel, another part of the B channel and the position of the A channel;
[0006] Animation rendering is performed based on vertex position information and normal information.
[0007] In a possible implementation, the format of the first texture file is RGBAHalf;
[0008] The vertex position information occupies 8 bits of the decimal place in each of the R, G, and B channels;
[0009] Normal information occupies 2 bits of the decimal place in each of the R channel, G channel and B channel and 16 bits of the A channel.
[0010] In a possible implementation, the process of obtaining vertex position information and normal information from the same first texture file includes:
[0011] Sampling the first texture file in the shader to obtain first original data;
[0012] The first original data is decoded to obtain vertex position information and normal information.
[0013] In a possible implementation, the animation rendering method further includes:
[0014] In the skeletal animation mode, the motion data is obtained from the second texture file, the motion data including the translation data and the rotation data of the quaternion;
[0015] Animation rendering based on motion data.
[0016] In a possible implementation manner, the action data further includes scaling data.
[0017] In a possible implementation, obtaining the action data from the second texture file includes:
[0018] Sampling the second texture file in the shader to obtain second original data;
[0019] The second original data is decoded to obtain translation data, rotation data and scaling data.
[0020] In a second aspect, an animation rendering device is provided, comprising:
[0021] An acquisition module, used for acquiring vertex position information and normal information from the same first texture file in vertex animation mode, wherein the vertex position information occupies part of the position of the R channel, part of the position of the G channel and part of the position of the B channel, and the normal information occupies another part of the position of the R channel, another part of the position of the G channel, another part of the position of the B channel and the position of the A channel;
[0022] The rendering module is used to perform animation rendering based on vertex position information and normal information.
[0023] According to a third aspect, an electronic device is provided, comprising a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute the above method.
[0024] In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the above method.
[0025] According to a fifth aspect, a computer program product is provided. The computer program product includes executable instructions. When the executable instructions are executed on a computer, the computer executes the above method.
[0026] The animation rendering method, device, electronic device, storage medium and computer program product in the embodiments of the present application enable the vertex position information and normal information to respectively occupy a part of each RGB channel in the texture file, and the normal information occupies the position of the A channel. In this way, the vertex position information and the normal information can be stored simultaneously through the same texture file. In this way, during the animation rendering process, only one texture file needs to be sampled to obtain two types of information, namely the vertex position information and the normal information, so as to facilitate animation rendering, save the number of sampling times in the rendering process, and thus improve the efficiency of storing animation data through textures. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 A schematic diagram of a texture storing vertex position information in the related art;
[0028] Figure 2 A schematic diagram of a texture storing normal information in the related art;
[0029] Figure 3 A schematic diagram of a bone matrix baking texture in the related art;
[0030] Figure 4 A flowchart of an animation rendering method in an embodiment of the present application;
[0031] Figure 5 This is a schematic diagram of the structure of Half type data in an embodiment of the present application;
[0032] Figure 6 A texture diagram of a first texture file in an embodiment of the present application;
[0033] Figure 7 A schematic diagram of a flow chart of another animation rendering method in an embodiment of the present application;
[0034] Figure 8 A texture diagram of a second texture file in an embodiment of the present application;
[0035] Fig. 9 This is a structural block diagram of an animation rendering device in an embodiment of the present application;
[0036] Fig.10 This is a structural block diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The terms used in the implementation section of this application are only used to explain the specific embodiments of this application and are not intended to limit this application.
[0038] Before introducing the embodiments of the present application, the problems in the related art are first described. The Skin Instance method targets two animation modes: vertex animation mode and skeletal animation mode. The technical problems in the two modes are described below.
[0039] Vertex animation mode is to soft-skin each frame of animation data to the mesh data, directly obtain the mesh vertex position information from the memory, and at the same time obtain the normal information corresponding to each vertex position information. This requires two textures: for example, one texture format is RGBAHalf, used to store vertex position information; the other texture format is RGB24, used to store normals. When rendering, update the animation state of the rendering instance in the script, calculate the UV coordinates in the texture according to the keyframes and vertex indices played in the current animation, and then obtain the vertex position information and normal information.
[0040] In vertex animation mode, rendering an object requires sampling the texture that stores vertex position information and the texture that stores normal information, which means two samples are needed. In addition, motion fusion doubles the number of samples, which means a total of four samples are needed. For a large number of rendered objects, this will put a lot of pressure on the hardware, so reducing the number of texture samples becomes an effective way to improve texture storage efficiency.
[0041] In order to reduce the number of texture sampling times, it can be achieved by merging two textures, for example, Figure 1 As shown, the texture format for storing vertex position information is RGBAHalf, and the 16-bit space of channel A is not used, such as Figure 2As shown, the texture format for storing normal information is RGB24, which requires 24 bits of space. One method is to compress the R channel data and G channel data of the normal information into 7 bits and merge them into the A channel of the texture of the vertex position information. The B channel data of the normal information can be calculated from the R channel data and the G channel data. For example, b = sqrt (1-r*r-g*g), sqrt is the square root function, r is the R channel data of the normal information, and g is the G channel data of the normal information. In this way, the sign bit of b occupies one bit, and a total of 15 bits are required to store the discovery signal. However, experiments have found that this method of sampling to obtain discovery information will eventually lead to severe normal flickering, because there is a large waste of precision in the process of calculating b.
[0042] Compared with vertex animation mode, bone animation mode bakes the transformation matrix of bones in animation data into texture. For a 4*4 matrix of floating point type Float, only 3*4 data needs to be stored. Since each data format is consistent, such as Figure 3 As shown, it can be stored in the same texture file to form a bone matrix baked texture. When rendering, it can be sampled three times to obtain 3*4 data and assembled into a matrix. The advantages of the skeletal animation mode over the vertex animation mode are: 1. The baked data is only related to the number of bones; 2. The baked data can be shared by the modes using the same skeleton. The disadvantage is that the number of samples is too high. If each vertex is bound to two bones, it needs to be sampled 6 times. If different actions are fused, the number of samples doubles to 12 times, which puts a lot of pressure on the hardware bandwidth during animation rendering.
[0043] For vertex animation mode, in order to improve the above-mentioned normal flickering problem, one method of storing normal information is to store two channels with smaller values among R, G, and B, and obtain the other channel by calculation. The specific algorithm can be implemented by the following code:
[0044]
[0045]
[0046] However, this encoding requires an additional 3 bits to store the additional information, so the 16 bits of the A channel are not enough.
[0047] Therefore, the present application embodiment provides an animation rendering method, such as Figure 4 As shown, the method includes:
[0048] In the vertex animation mode, executing step 101, obtaining vertex position information and normal information from the same first texture file;
[0049] Among them, the vertex position information occupies part of the R channel, part of the G channel and part of the B channel, and the normal information occupies another part of the R channel, another part of the G channel, another part of the B channel and the position of the A channel. That is to say, the vertex position data of each channel in the texture that originally stores the vertex position information is compressed, and the remaining space after compression is used to store the normal information, that is, the normal information is stored by borrowing each RGB channel of the vertex position information. In addition, the position of the A channel is also used to store the normal information. In this way, the vertex position information and the normal information can be stored at the same time through the same texture file.
[0050] Step 102: Perform animation rendering according to vertex position information and normal information.
[0051] The animation rendering method in the embodiment of the present application makes the vertex position information and normal information occupy a part of each RGB channel in the texture file respectively, and the normal information occupies the position of the A channel. In this way, the vertex position information and the normal information can be stored simultaneously through the same texture file. In this way, during the animation rendering process, only one texture file needs to be sampled to obtain two types of information, namely the vertex position information and the normal information, so as to facilitate animation rendering, save the number of sampling times in the rendering process, and thus improve the efficiency of storing animation data through textures.
[0052] In a possible implementation, the format of the first texture file is RGBAHalf, which has high compatibility. Half-precision floating point data has the following format: Figure 5 The structure shown in FIG. 1 includes a 1-bit sign bit, a 5-bit exponent bit, and a 10-bit fraction bit. Through testing, it is found that only 8 bits of precision are needed to store the fractional bits of vertex position information. Therefore, 2 bits can be borrowed from each RGB channel that originally stores the vertex position information, and 16 bits of the A channel are added, for a total of 22 bits to store the normal information, as shown in FIG. Figure 6 As shown, it can just store normal information in R7G8B7 format. Vertex position information occupies 8 bits of the decimal place of each channel in R channel, G channel and B channel, and vertex position information can occupy the first 8 bits of the decimal place of each channel of RGB, for example; normal information occupies 2 bits of the decimal place of each channel in R channel, G channel and B channel and 16 bits of A channel, and normal information can occupy the last 2 bits of the decimal place of each channel of RGB, for example.
[0053] In a possible implementation, step 101, the process of obtaining vertex position information and normal information from the same first texture file includes:
[0054] Step 1011: sampling the first texture file in the shader to obtain first original data;
[0055] Step 1012: Decode the first original data to obtain vertex position information and normal information.
[0056] Among them, since the vertex position information and normal information are stored in the same texture file according to certain rules, the first original data obtained by sampling the texture file each time needs to be decoded to assemble the corresponding vertex position information and normal information.
[0057] In a possible implementation, Figure 7 As shown, the above method also includes:
[0058] In the skeletal animation mode, executing step 201, obtaining motion data from the second texture file, the motion data including translation data and quaternion rotation data;
[0059] Step 202: Perform animation rendering according to the motion data.
[0060] In a possible implementation manner, the action data further includes scaling data.
[0061] In a possible implementation, step 201, obtaining action data from the second texture file, includes: sampling the second texture file in a shader to obtain second original data; decoding the second original data to obtain translation data, rotation data, and scaling data.
[0062] Specifically, the action data in the skeletal animation mode is the matrix data baked into the second texture file. In fact, the action data is obtained through a series of scaling, rotation and translation. Therefore, quaternions are used in the embodiment of the present application to replace the rotation data and retain the translation data. Since the scaling in the skeletal animation mode is geometric scaling (for example, in SLG, if the scaling is non-geometric scaling, the color correction will be deformed when performing the action, which is almost non-existent), the scaling data is represented by a floating-point type float data, that is, the action data is two vector4 type data. The action data is specifically stored in the second texture file as half-precision floating-point Half type data, where the two vector4 type data are encoded as RGBAFloat type, and all data can be obtained by sampling the second texture file once, such as Figure 8 As shown, Figure 3By comparison, the data volume of texture files is reduced by 33%. In addition, by encoding the motion data, the number of texture sampling is reduced. During the animation rendering process, the number of texture sampling is reduced from 6 to 2. Considering the case of motion fusion, the number of texture sampling is reduced from 12 to 4. It can be seen that the reduction in sampling times reduces the bandwidth pressure of the hardware during rendering.
[0063] like Fig. 9 As shown, the embodiment of the present application also provides an animation rendering device, including: an acquisition module 1, used to acquire vertex position information and normal information from the same first texture file in vertex animation mode, the vertex position information occupies part of the position of the R channel, part of the position of the G channel and part of the position of the B channel, and the normal information occupies another part of the position of the R channel, another part of the position of the G channel, another part of the position of the B channel and the position of the A channel; a rendering module 2, used to perform animation rendering according to the vertex position information and the normal information. The animation rendering device can apply the animation rendering method in any of the above embodiments, and the specific process and principle are the same as those in the above embodiments, which will not be repeated here.
[0064] It should be understood that the division of the above animation rendering device is only a division of logical functions. In actual implementation, it can be fully or partially integrated into a physical entity, or it can be physically separated. And these modules can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software calling through processing elements, and some modules can be implemented in the form of hardware. For example, any one of the acquisition module 1 and the rendering module 2 can be a separately established processing element, or it can be integrated in the animation rendering device, such as being integrated in a chip of the animation rendering device. In addition, it can also be stored in the memory of the animation rendering device in the form of a program, and called and executed by a processing element of the animation rendering device. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or an instruction in the form of software. In addition, the above animation rendering device can be the same device or different devices.
[0065] For example, the animation rendering device may be one or more integrated circuits configured to implement the above method, such as one or more application specific integrated circuits (ASIC), or one or more microprocessors (digital signal processors, DSP), or one or more field programmable gate arrays (FPGA), etc. For another example, when a certain module above is implemented in the form of a processing element scheduler, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call a program. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0066] In a possible implementation, the format of the first texture file is RGBAHalf; the vertex position information occupies 8 bits of the decimal place of each of the R channel, the G channel, and the B channel; the normal information occupies 2 bits of the decimal place of each of the R channel, the G channel, and the B channel and 16 bits of the A channel.
[0067] In a possible implementation, the process of obtaining vertex position information and normal information from the same first texture file includes: sampling the first texture file in a shader to obtain first original data; decoding the first original data to obtain vertex position information and normal information.
[0068] In a possible implementation, the acquisition module 1 is further used to acquire action data from the second texture file in the skeletal animation mode, where the action data includes translation data and quaternion rotation data; the rendering module 2 is further used to perform animation rendering according to the action data.
[0069] In a possible implementation manner, the action data further includes scaling data.
[0070] In a possible implementation, obtaining the action data from the second texture file includes:
[0071] Sampling the second texture file in the shader to obtain second original data;
[0072] The second original data is decoded to obtain translation data, rotation data and scaling data.
[0073] like Fig.10As shown, the embodiment of the present application also provides an electronic device, a processor 51 and a memory 52, the memory 52 is used to store at least one instruction, and the instruction is loaded and executed by the processor 51 to implement the animation rendering method in any of the above embodiments. The specific process and principle of the animation rendering method are the same as those in the above embodiment, and will not be repeated here.
[0074] The number of processors 51 may be one or more, and the processor 51 and the memory 52 may be connected via a bus 53 or other means. The memory 52, as a non-transient computer-readable storage medium, may be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the data processing device in the embodiment of the present application. The processor executes various functional applications and data processing by running non-transient software programs, instructions and modules stored in the memory, that is, implementing the method in any of the above method embodiments. The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; and necessary data, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. The electronic device may be, for example, an electronic product such as a server, a computer, and a mobile phone.
[0075] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, which, when executed on a computer, enables the computer to execute the method in any of the above embodiments.
[0076] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in this application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integration. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk), etc.
[0077] The embodiments of the present application also provide a computer program product, which includes executable instructions. When the executable instructions are executed on a computer, the computer executes the method in any of the above embodiments.
[0078] In the embodiments of the present application, "at least one" refers to one or more, and "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone. Among them, A and B can be singular or plural. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can be represented by: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0079] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. An animation rendering method, characterized in that: include: In vertex animation mode, vertex position information and normal information are obtained from the same first texture file, the vertex position information occupies part of the position of the R channel, part of the position of the G channel, and part of the position of the B channel, and the normal information occupies another part of the position of the R channel, another part of the position of the G channel, another part of the position of the B channel, and the position of the A channel; Perform animation rendering according to the vertex position information and the normal information; In the skeletal animation mode, obtaining motion data from the second texture file, wherein the motion data includes translation data and quaternion rotation data; Animation rendering is performed according to the action data.
2. The method according to claim 1, characterized in that The format of the first texture file is RGBAHalf; The vertex position information occupies 8 bits of the decimal place of each of the R channel, the G channel and the B channel; The normal information occupies 2 bits of the decimal place of each of the R channel, the G channel, and the B channel and 16 bits of the A channel.
3. The method according to claim 2, characterized in that The process of obtaining vertex position information and normal information from the same first texture file includes: Sampling the first texture file in a shader to obtain first original data; The first original data is decoded to obtain the vertex position information and the normal information.
4. The method according to claim 1, characterized in that: The motion data also includes scaling data.
5. The method according to claim 4, characterized in that The acquiring of the action data from the second texture file comprises: Sampling the second texture file in a shader to obtain second original data; The second original data is decoded to obtain the translation data, the rotation data and the scaling data.
6. An animation rendering device, characterized in that: include: an acquisition module, used for acquiring vertex position information and normal information from the same first texture file in a vertex animation mode, wherein the vertex position information occupies a part of the position of the R channel, a part of the position of the G channel, and a part of the position of the B channel, and the normal information occupies another part of the position of the R channel, another part of the position of the G channel, another part of the position of the B channel, and the position of the A channel; A rendering module, used for performing animation rendering according to the vertex position information and the normal information; The acquisition module is also used to, in the skeletal animation mode, acquire action data from the second texture file, the action data including translation data and quaternion rotation data; The rendering module is also used to perform animation rendering according to the action data.
7. An electronic device, characterized in that: The device comprises a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 5.
9. A computer program product, characterized in that The computer program product comprises executable instructions, and when the executable instructions are executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 5.