A scene rendering method, apparatus, device and storage medium
By synchronously rendering multiple consecutive 3D scene textures, the problem of high GPU resource consumption is solved, and efficient scene rendering is achieved.
Patent Information
- Application Number
- CN202211436352.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-16
- Publication Date
- 2026-01-13
- Estimated Expiration
- 2042-11-16
AI Technical Summary
In existing technologies, the rendering of 3D scenes results in high GPU resource utilization and increased power consumption because multiple textures pass through the rendering pipeline sequentially.
The rendering pipeline synchronously renders textures with the same vertex data across multiple consecutive vertexes. It then processes the vertex data to generate scene fragments and combines them with pixel data for blending rendering to produce the final scene image.
While ensuring rendering accuracy, it reduces GPU utilization and power consumption, thereby improving rendering efficiency.
Smart Images

Figure CN115908685B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a scene rendering method, apparatus, device, and storage medium. Background Technology
[0002] For any created 3D scene, there are usually different scene objects in different spatial locations, such as virtual cameras, models, and light sources. Therefore, when rendering the corresponding scene image on the display screen, it is usually necessary to blend and render multiple textures represented by different scene objects within the 3D scene in order to successfully render a scene image.
[0003] Currently, rendering any 3D scene typically involves using a rendering pipeline to render multiple textures within that scene sequentially, ensuring each texture completes all stages of the rendering pipeline. However, each stage of the rendering pipeline requires graphics resources from a Graphics Processing Unit (GPU) to run successfully. Therefore, when multiple textures from any scene sequentially pass through the rendering pipeline, it significantly consumes GPU memory and increases GPU power consumption. Summary of the Invention
[0004] This application provides a scene rendering method, apparatus, device, and storage medium that synchronously renders multiple consecutive target textures with the same vertex data through a rendering pipeline, thereby greatly reducing GPU usage and power consumption during scene rendering while ensuring scene rendering accuracy.
[0005] In a first aspect, embodiments of this application provide a scene rendering method, the method comprising:
[0006] When rendering multiple textures in a scene to be rendered sequentially through the rendering pipeline, if the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, the vertex data is processed through the rendering pipeline to obtain the corresponding scene fragments.
[0007] Based on the first pixel data after rendering the first target texture and the second pixel data after mixing multiple target textures, the scene fragments are pixel-shaded to complete the rendering of multiple target textures.
[0008] When the rendering pipeline completes the rendering of each texture in the scene to be rendered, a scene image of the scene to be rendered is generated.
[0009] Secondly, embodiments of this application provide a scene rendering apparatus, the apparatus comprising:
[0010] The vertex processing module is used to process the vertex data of multiple consecutive target textures to be rendered in the scene to be rendered in sequence through the rendering pipeline, if the vertex data of multiple consecutive target textures to be rendered in the rendering pipeline are the same, and obtain the corresponding scene fragments through the rendering pipeline.
[0011] The texture rendering module is used to perform pixel shading on the scene fragments based on the first pixel data after the rendering pipeline has completed the rendering of the first target texture and the second pixel data after the multiple target textures have been mixed, so as to complete the rendering of multiple target textures.
[0012] The scene rendering module is used to generate a scene image of the scene to be rendered when the rendering pipeline completes the rendering of each texture in the scene to be rendered.
[0013] Thirdly, embodiments of this application provide an electronic device, which includes:
[0014] A processor and a memory, the memory for storing computer programs, and the processor for calling and running the computer programs stored in the memory to execute the scene rendering method provided in the first aspect of this application.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium for storing a computer program that causes a computer to execute the scene rendering method provided in the first aspect of this application.
[0016] Fifthly, embodiments of this application provide a computer program product, including a computer program / instructions that cause a computer to execute the scene rendering method provided in the first aspect of this application.
[0017] The technical solution of this application, when rendering multiple textures in a scene to be rendered sequentially through the rendering pipeline, if the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, then the rendering pipeline first processes the vertex data to obtain the corresponding scene fragment. Then, based on the first pixel data after the rendering pipeline has completed the rendering of the first target texture and the second pixel data after the multiple target textures are mixed, the scene fragment is pixel-shaded to complete the rendering of multiple target textures. This allows the scene image of the scene to be rendered to be generated when the rendering pipeline completes the rendering of each texture in the scene to be rendered, thereby achieving accurate rendering of the scene to be rendered. Moreover, during the scene rendering process, by running the rendering pipeline once, multiple consecutive target textures with the same vertex data can be rendered synchronously, greatly reducing the GPU utilization and power consumption during scene rendering while ensuring the accuracy of scene rendering. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A schematic diagram of the existing workflow of the rendering pipeline provided in this application;
[0020] Figure 2 A flowchart illustrating a scene rendering method provided in an embodiment of this application;
[0021] Figure 3 This is a schematic diagram of the improved rendering pipeline provided in an embodiment of this application;
[0022] Figure 4 A flowchart illustrating another scene rendering method provided in this application embodiment;
[0023] Figure 5 A schematic diagram of a scene rendering apparatus provided in an embodiment of this application;
[0024] Figure 6 A schematic block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0027] In this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or solution described as "exemplary" or "for example" in this application should not be construed as being better or more advantageous than other embodiments or solutions. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0028] Before introducing the specific technical solution of this application, the existing architecture of the rendering pipeline involved in this application will be described below:
[0029] Typically, the main purpose of the rendering pipeline is to convert a 3D scene into a corresponding 2D image, which is then rendered and displayed to the user on the screen. Within any given 3D scene to be rendered, various scene objects typically exist in different spatial locations. Different scene objects have different irregular patterns mapped onto their surfaces in different ways, serving as their textures. This results in different scene objects possessing different textures, meaning a 3D scene may contain multiple textures.
[0030] Therefore, when converting any 3D scene into a 2D scene image, it is usually necessary to render each texture mapped to the surface of different scene objects in the 3D scene sequentially through the rendering pipeline in order to successfully render a scene image.
[0031] like Figure 1 As shown, the rendering pipeline can be divided into the following stages according to its workflow: application stage, geometry stage, and rasterization stage.
[0032] 1. Application Phase
[0033] The process involves acquiring various scene data from the 3D scene to be rendered, such as camera position, view frustum, models within the scene, and lighting information. Then, coarse-grained culling is performed on this scene data to remove invisible 3D objects from the scene. Finally, by setting the corresponding rendering states, including but not limited to materials, textures, and shaders, the geometric information (i.e., vertex data) and pixel data of each texture required for rendering are output.
[0034] 2. Geometric Stage
[0035] This stage can include, but is not limited to, five processing stages: vertex shader, primitive assembly, geometry shader, clipping, and screen mapping. The vertex shader transforms the vertex data of the texture to be rendered from the object coordinate system to the world coordinate system, ensuring that all vertices in the 3D scene have a unified coordinate system. Then, the vertex data in the world coordinate system is transformed to the camera coordinate system, resulting in the vertices of the scene as observed with the virtual camera as the origin of the view space. Next, primitive assembly assembles the vertices into corresponding geometric primitives. The geometry shader performs operations on these geometric primitives, outputting the vertices that form them. Then, the vertices outside the camera viewport of these geometric primitives are clipped according to the screen size. Finally, the clipped geometric primitives are often 3D, which can be mapped onto the 2D screen space to obtain 2D geometric primitives.
[0036] 3. Rasterization stage
[0037] Rasterization maps two-dimensional geometric primitives onto fragments, and the fragment shader obtains the pixel values of the corresponding texture to be rendered. Then, the pixel values of this texture are blended with the existing pixel values in the memory buffer (Framebuffer), and new pixel values are blended in the Framebuffer, thus completing the rendering of a texture.
[0038] For any 3D scene to be rendered, vertex and pixel data of multiple textures contained within it are typically obtained during the application phase. Then, according to the rendering order of each texture in the rendering pipeline, each texture can be input into the rendering pipeline sequentially, ensuring that each texture undergoes all stages of the rendering pipeline completely.
[0039] However, each stage of the rendering pipeline requires GPU graphics resources to run successfully. Therefore, when multiple textures in any given 3D scene pass through the rendering pipeline sequentially, it will consume a significant amount of GPU memory and increase GPU power consumption.
[0040] To address the aforementioned issues, this application proposes a novel rendering scheme based on the rendering pipeline workflow. When the rendering pipeline sequentially renders multiple textures within a scene to be rendered, if the vertex data of multiple consecutive target textures to be rendered is identical, the rendering pipeline first processes this vertex data to obtain the corresponding scene fragment. Then, based on the first pixel data after rendering the first target texture and the second pixel data resulting from the blending of multiple target textures, pixel shading is applied to the scene fragment to complete the rendering of multiple target textures. This allows the scene image of the scene to be rendered to be generated as the rendering pipeline completes the rendering of each texture within the scene to be rendered, thereby achieving accurate rendering of the scene. Furthermore, during scene rendering, by running the rendering pipeline once, the synchronous rendering of multiple consecutive target textures with identical vertex data can be completed, significantly reducing GPU utilization and power consumption during scene rendering while ensuring scene rendering accuracy.
[0041] Figure 2 This is a flowchart illustrating a scene rendering method provided in an embodiment of this application. This method can be executed by the scene rendering apparatus provided in this application, which can be implemented using any software and / or hardware method. Exemplarily, the scene rendering apparatus can be, but is not limited to, tablet computers, mobile phones (such as foldable phones, large-screen phones, etc.), wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), smart TVs, smart screens, high-definition TVs, 4K TVs, smart speakers, smart projectors, and other Internet of Things (IoT) devices. This disclosure does not impose any limitations on the specific type of electronic device.
[0042] Specifically, such as Figure 2 As shown, the method may include the following steps:
[0043] S210: When rendering multiple textures in the scene to be rendered sequentially through the rendering pipeline, if the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, the vertex data is processed through the rendering pipeline to obtain the corresponding scene fragments.
[0044] For any given scene to be rendered, there are usually multiple textures that are mapped to the surfaces of different scene objects. Moreover, each texture carries corresponding vertex and pixel data to represent the pattern shape, material, etc. of that texture.
[0045] The vertex data of each texture can represent the geometry of the texture, and the pixel data of each texture can represent the color and transparency of each pixel in the texture.
[0046] In some implementations, the pixel data of each texture in this application can be represented by four pixel values in a color space consisting of four channels: red, green, blue, and alpha (which can be denoted as RGBA space), so that the pixel data of each texture can include the pixel color (i.e., RGB value) and pixel transparency (Alpha value) of each pixel in the texture.
[0047] Normally, when rendering any scene to be rendered through the rendering pipeline, each texture is rendered sequentially according to the rendering order of the textures in that scene, so that each texture can go through all stages of the rendering pipeline.
[0048] In this application, considering that there may be textures with the same geometry but different pixel colors in the scene to be rendered, it is understood that the geometric processing operations of such textures are the same, but the pixel shading is different. Therefore, in order to improve the efficiency of the rendering pipeline for multi-texture rendering, this application, when rendering a certain texture in the scene to be rendered each time, first determines whether the vertex data between the texture that the rendering pipeline is currently preparing to render and the next texture after that texture are the same, in order to analyze whether there are the same geometric processing operations among multiple consecutive textures starting from the texture that is currently preparing to render.
[0049] If the vertex data of the texture the rendering pipeline is currently preparing to render differs from that of the next texture following it, then the rendering pipeline can directly perform normal rendering on the texture being rendered. After the texture is rendered, the rendering pipeline continues to render the next texture sequentially using the same method.
[0050] However, if the vertex data of the texture currently being rendered by the rendering pipeline is the same as that of the next texture following it, the texture will at least perform the same geometric processing operations as the next texture. Therefore, this application can start from the texture currently being rendered and find a series of consecutive textures that have the same vertex data as the current texture, thereby forming a series of consecutive target textures to be rendered by the rendering pipeline in this application. These consecutive target textures include at least the texture currently being rendered by the rendering pipeline and the next texture following it.
[0051] Furthermore, such as Figure 3 As shown, the same vertex data from multiple consecutive target textures are input into the rendering pipeline. Through the stages of vertex shader, primitive assembly, geometry shader, clipping, and screen mapping in the rendering pipeline, the same vertex data is processed accordingly to obtain geometric primitives mapped onto the display space.
[0052] Then, in order to ensure the accuracy of subsequent pixel shading for each target texture, this application will also perform corresponding rasterization processing on the obtained geometric primitives to map the geometric primitives onto the corresponding fragments, thereby obtaining the corresponding scene fragments, so as to perform accurate pixel shading processing on the scene fragments through the fragment shader in the rendering pipeline.
[0053] S220: Based on the first pixel data after rendering the first target texture and the second pixel data after mixing multiple target textures, the scene fragments are pixel-shaded to complete the rendering of multiple target textures.
[0054] For each of the aforementioned textures that are preceding multiple target textures in the scene to be rendered, the aforementioned textures have already completed the corresponding rendering process through the rendering pipeline. Moreover, after the rendering pipeline has completed the rendering of each of the aforementioned textures, the first pixel data that has been rendered can be determined, and this first rendering data will be cached in the memory buffer (Framebuffer) of the rendering pipeline.
[0055] Therefore, after processing the vertex data of multiple consecutive target textures with the same characteristics through the rendering pipeline to obtain the corresponding scene fragments, it is necessary to retrieve the existing first pixel data from the rendering pipeline's memory buffer (Framebuffer) and use the first pixel data as the original pixel data of the scene fragment. Then, based on the first pixel data, the pixel data of each target texture is rendered sequentially onto the scene fragment, giving the scene fragment a new texture.
[0056] In this application, considering that each run of the rendering pipeline performs an actual texture blending operation, in order to achieve one-time blending of scene fragments for multiple target textures, this application first determines the blending factor defined in the blend function of the rendering pipeline. Then, it determines the blending parameters used when blending multiple target textures from the first pixel data and the pixel data of each target texture.
[0057] When multiple target textures are blended, the blending parameters used are the first pixel data after the aforementioned textures are rendered and the target pixel transparency in the pixel data of each target texture that matches the blending factor defined in the rendering pipeline.
[0058] It should be understood that texture blending in the rendering pipeline typically involves mixing existing pixel data before blending with the pixel data to be blended to calculate new pixel data. The existing pixel data before blending is used as the target pixel, and the pixel data to be blended is used as the source pixel. Then, using the blending factors defined for the source and target pixels in the blend function, the source and target pixels are multiplied by their respective blending factors and then summed to obtain the new blended pixel. In the blend function, the blending factor defined for the source pixel can be the source factor, and the blending factor defined for the target pixel can be the target factor.
[0059] Furthermore, the blending factors defined for the source and destination pixels in the blending function of the rendering pipeline can include a variety of the following:
[0060] 1) GL_ZERO: Indicates that 0 is used as the blending factor, which is equivalent to not using this pixel in the blending operation;
[0061] 2) GL_ONE: Indicates that 1 is used as the blending factor, which is equivalent to using this pixel entirely in the blending operation;
[0062] 3) GL_SRC_ALPHA: Indicates that the pixel transparency in the source pixel is used as the blending factor;
[0063] 4) GL_DST_ALPHA: Indicates that the pixel transparency in the target pixel is used as the blending factor;
[0064] 5) GL_ONE_MINUS_SRC_ALPHA: This indicates that the blending factor is the value obtained by subtracting the pixel transparency of the source pixel from 1.
[0065] 6) GL_ONE_MINUS_DST_ALPHA: This indicates that the value obtained by subtracting the pixel transparency in the target pixel from 1 is used as the blending factor.
[0066] In this application, a blending factor defined in the blending function of the rendering pipeline can be used to calculate the second pixel data after the blending of multiple target textures, based on the pixel results of sequential rendering of the first pixel data after the aforementioned textures have been rendered. Then, using the blending factor defined in the blending function of the rendering pipeline, the new pixel value after blending the first and second pixel data is calculated again. Furthermore, as... Figure 3 As shown, the new pixel value is used to color the obtained scene fragments through the fragment shader in the rendering pipeline, thereby completing the rendering of multiple target textures at once in the rendering pipeline.
[0067] It should be understood that the pixel data of each texture in the scene to be rendered includes pixel color and pixel transparency. Therefore, the pixel data obtained after rendering a texture by mixing the pixel data of each texture through the rendering pipeline also includes pixel color and pixel transparency. In other words, the first pixel data and the second pixel data used in the rendering process of each texture in this application also include both pixel color and pixel transparency.
[0068] Then, for each of the multiple target textures described later, the same texture rendering process described above is executed through the rendering pipeline to complete the rendering of each texture in the scene to be rendered.
[0069] S230 generates a scene image of the scene to be rendered when the rendering pipeline completes the rendering of each texture in the scene to be rendered.
[0070] When the rendering pipeline completes the rendering of each texture in the scene to be rendered, it means that the blending rendering of all textures in the scene to be rendered has been completed, resulting in a final two-dimensional image, which can be the scene image of the scene to be rendered.
[0071] The technical solution provided in this application embodiment renders multiple textures in a scene to be rendered sequentially through the rendering pipeline. If the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, the rendering pipeline first processes the vertex data to obtain the corresponding scene fragment. Then, based on the first pixel data after the rendering pipeline has rendered the first target texture and the second pixel data after the multiple target textures are mixed, the scene fragment is pixel-shaded to complete the rendering of multiple target textures. This allows the scene image of the scene to be rendered to be generated when the rendering pipeline completes the rendering of each texture in the scene to be rendered, thereby achieving accurate rendering of the scene to be rendered. Moreover, during the scene rendering process, by running the rendering pipeline once, multiple consecutive target textures with the same vertex data can be rendered synchronously, greatly reducing the GPU usage and power consumption during scene rendering while ensuring the accuracy of scene rendering.
[0072] According to one or more embodiments of this application, considering that the rendering positions of multiple consecutive target textures to be rendered in the scene are uncertain, there may be cases where multiple target textures do not exist. Therefore, different blending operations need to be performed on multiple target textures for different situations to ensure the accuracy of multi-texture blending in the scene to be rendered.
[0073] Next, this application will provide a detailed description of the specific process of rendering multiple target textures through the rendering pipeline.
[0074] Figure 4 A flowchart of another scene rendering method provided in this application embodiment, the method may include the following steps:
[0075] S410: When rendering multiple textures in the scene to be rendered sequentially through the rendering pipeline, if the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, the vertex data is processed through the rendering pipeline to obtain the corresponding scene fragments.
[0076] S420, if the aforementioned texture of the first target texture is empty, then according to the pre-set sequential blending rules, the pixel data of each target texture are sequentially blended to obtain the second pixel data after the blending of multiple target textures.
[0077] If the first target texture among multiple target textures does not exist, it means that the first target texture is the first texture rendered in the rendering pipeline, and there is no first pixel data that has been rendered. In other words, the multiple target textures are at the bottom layer of the scene to be rendered, and the multiple target textures need to be rendered first, followed by other textures after the multiple target textures.
[0078] Therefore, by using the blending factor in the blend function of the rendering pipeline and applying the conventional sequential blending rules to sequentially blend the pixel data of each target texture, the second pixel data after blending multiple target textures can be obtained.
[0079] Taking two target textures as an example, assuming the pixel data of the target textures are s1 and s2, and the pixel opacities they contain are a1 and a2 respectively, the rendering order of the target textures is s1->s2, and the blending factor in the blend function is set to (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). From the above, we know that the source pixel is s2, the target pixel is s1, the source factor is the pixel opacity of the source pixel a2, and the target factor is the value obtained by subtracting the pixel opacity of the source pixel from 1 (1-a2). Therefore, the second pixel data after blending the two target textures can be calculated as: OutColor = s2*a2 + s1*(1-a2).
[0080] S430 performs pixel coloring on scene fragments based on the second pixel data.
[0081] Since the aforementioned texture does not exist, there is also no first pixel data after the aforementioned texture has been rendered. Therefore, the scene fragment is directly pixel-colored according to the second pixel data after the multiple target textures are mixed by the fragment shader in the rendering pipeline, thereby completing the rendering of multiple target textures.
[0082] S440, if the aforementioned texture of the first target texture is not empty, then according to the synchronous blending rules corresponding to multiple target textures, the pixel data of each target texture is synchronously blended to obtain the second pixel data after the multiple target textures are blended.
[0083] If the first target texture among multiple targets already contains the aforementioned texture, it means that the rendering pipeline already has the aforementioned texture rendered before rendering the multiple target textures. Therefore, it needs to continue blending the pixel data of the multiple target textures onto the first pixel data after the aforementioned texture has been rendered. In other words, the multiple target textures are located at the upper layer of the scene to be rendered, and the rendering of the multiple target textures continues based on the previously rendered texture.
[0084] At this point, for the texture blending process in the rendering pipeline, different synchronization blending rules are set for different numbers of target textures. Based on the number of target textures, a suitable synchronization blending rule is first determined. Then, according to the synchronization blending rule, the pixel data of each target texture is synchronously blended to obtain the second pixel data after blending multiple target textures.
[0085] As an optional implementation in this application, in order to ensure that the final rendering effect is consistent when multiple target textures are sequentially mixed based on the first pixel data of the aforementioned texture through the rendering pipeline, and when multiple target textures are mixed first and then mixed with the first pixel data of the aforementioned texture, the synchronous mixing rules corresponding to multiple target textures can be determined by the following steps:
[0086] The first step is to determine the pixel variables of each target texture, the first pixel variable after the aforementioned textures are rendered, and the second pixel variable after multiple target textures are blended.
[0087] Determining the synchronous blending rules for multiple target textures involves analyzing the calculation formula for the second pixel data after blending the multiple target textures. Therefore, this application can set corresponding pixel variables for each pixel data involved in calculating the second pixel data after blending multiple target textures.
[0088] That is, set a corresponding pixel variable for the pixel data of each target texture, set a corresponding first pixel variable for the first pixel data after the aforementioned texture has been rendered, and set a corresponding second pixel variable for the second pixel data after multiple target textures have been blended.
[0089] The second step is to sequentially blend the first pixel variable and the pixel variables of each target texture according to the pre-defined sequential blending rules to obtain the first sequential blending result.
[0090] To ensure consistent rendering results when multiple target textures are sequentially blended based on the first pixel data of the aforementioned texture via the rendering pipeline, and when multiple target textures are blended first and then blended with the first pixel data of the aforementioned texture, this application can perform sequential blending on the first pixel variable of the aforementioned texture after rendering and the pixel variables of each target texture according to pre-defined sequential blending rules, thereby obtaining a first sequential blending result. This first sequential blending result can represent the final blending result after sequentially blending multiple target textures based on the first pixel variable of the aforementioned texture after it has been blended.
[0091] Taking two target textures as an example, assuming the pixel variables of the target textures are S1 and S2, and the pixel opacities they contain are A1 and A2 respectively, and the first pixel variable of the aforementioned texture after rendering is Screen, which contains pixel opacity A0. Then, the rendering order of the aforementioned texture and the target texture is Screen->S1->S2, and the blending factor in the blend function is set to (source factor is GL_SRC_ALPHA, target factor is GL_ONE_MINUS_SRC_ALPHA).
[0092] Therefore, the first sequential blending result after sequentially blending the first pixel variable and the pixel variables of each target texture is S2*A2+(S1*A1+Screen*(1-A1))*(1-A2)=S2*A2+S1*A1*(1-A2)+Screen*(1-(A1+A2-A1*A2).
[0093] The third step is to perform sequential blending on the first pixel variable and the second pixel variable according to the sequential blending rules to obtain the second sequential blending result.
[0094] After setting the second pixel variable after blending multiple target textures, the first pixel variable after rendering the aforementioned textures and the second pixel variable after blending multiple target textures can be sequentially blended according to the pre-defined sequential blending rules to obtain the second sequential blending result. This second sequential blending result can represent the final blending result after sequentially blending multiple target textures based on the first pixel variable after blending the aforementioned textures.
[0095] Taking two target textures as an example, suppose the second pixel variable after blending the two target textures is Si, which contains pixel opacities Ai, and the first pixel variable after rendering the aforementioned texture is Screen, which contains pixel opacities A0. Then, the rendering order of the first pixel variable after rendering the aforementioned texture and the second pixel variable after blending the two target textures is Screen->Si, and the blending factor in the blend function is set to (source factor is GL_SRC_ALPHA, target factor is GL_ONE_MINUS_SRC_ALPHA).
[0096] Therefore, the second sequential blending result after sequentially blending the first pixel variable and the second pixel variable is Si*Ai+Screen*(1-Ai).
[0097] The fourth step is to determine the variable solution function for the second pixel variable based on the equivalence between the first and second order mixing results, which will serve as the synchronization mixing rule for multiple target textures.
[0098] The independent variables in the variable solving function for the second pixel variable can include the first pixel variable and the pixel variables of each target texture.
[0099] Considering that both the first sequential blending result in the second step and the second sequential blending result in the third step represent the final blending result after sequentially blending multiple target textures based on the first pixel variable after the aforementioned texture blending is completed, there is equivalence between the two. Therefore, the variable solution function for the second pixel variable can be calculated based on the equation between the first and second sequential blending results. The independent variables in this variable solution function can include the first pixel variable and the pixel variable of each target texture, while the dependent variable is the second pixel variable. Then, this variable solution function for the second pixel variable is used as the synchronous blending rule corresponding to multiple target textures in this application, so as to subsequently calculate the corresponding second pixel data.
[0100] Taking the first and second order blending results of the two target textures mentioned above as an example, we can determine that S2*A2+S1*A1*(1-A2)+Screen*(1-(A1+A2-A1*A2)=Si*Ai+Screen*(1-Ai); based on this, we can obtain Ai=1-(A1+A2-A1*A2).
[0101] Therefore, the function for solving the second pixel variable is:
[0102] Si=(S2*A2+S1*A1*(1-A2)) / (1-(A1+A2-A1*A2).
[0103] Furthermore, in this application, the calculation of the second pixel data after the blending of multiple target textures can be specifically achieved by substituting the first pixel data after the aforementioned textures have been rendered and the pixel data of each target texture into the variable solving function of the second pixel variable to calculate the second pixel data after the blending of multiple target textures.
[0104] In other words, the target pixel transparency represented by each blending factor can be determined from the first pixel data after the aforementioned texture has been rendered and the pixel data of each target texture. Then, the actual values of the first pixel data and the pixel data of each target texture, along with the corresponding target pixel transparency, are substituted into the corresponding independent variables in the variable solving function of the second pixel variable to calculate the second pixel data after the blending of multiple target textures.
[0105] S450, according to the sequential blending rule, sequentially blends the first and second pixel data of the aforementioned texture after rendering to obtain the third pixel data of the scene fragment.
[0106] After calculating the second pixel data after mixing multiple target textures, the second pixel data needs to be sequentially mixed again based on the first pixel data of the aforementioned texture after rendering to calculate the corresponding third pixel data. The third pixel data is the pixel data suitable for scene fragments in this application.
[0107] S460 performs pixel coloring on scene fragments based on the third pixel data.
[0108] By using the fragment shader in the rendering pipeline, the scene fragment is pixel-colored directly according to the third pixel data of the scene fragment, thereby completing the rendering of multiple target textures.
[0109] It should be understood that S420-S430 and S440-S460 in this application represent different rendering processes for multiple target textures under two different conditions: whether or not the aforementioned texture exists. Therefore, for S420-S430 and S440-S460, a suitable rendering method can be selected based on whether the aforementioned texture exists among the multiple target textures to complete the rendering pipeline for multiple target textures.
[0110] S470 generates a scene image of the scene to be rendered while the rendering pipeline has completed rendering each texture in the scene to be rendered.
[0111] The technical solution provided in this application embodiment renders multiple textures in a scene to be rendered sequentially through the rendering pipeline. If the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, the rendering pipeline first processes the vertex data to obtain the corresponding scene fragment. Then, based on the first pixel data after the rendering pipeline has rendered the first target texture and the second pixel data after the multiple target textures are mixed, the scene fragment is pixel-shaded to complete the rendering of multiple target textures. This allows the scene image of the scene to be rendered to be generated when the rendering pipeline completes the rendering of each texture in the scene to be rendered, thereby achieving accurate rendering of the scene to be rendered. Moreover, during the scene rendering process, by running the rendering pipeline once, multiple consecutive target textures with the same vertex data can be rendered synchronously, greatly reducing the GPU usage and power consumption during scene rendering while ensuring the accuracy of scene rendering.
[0112] Figure 5 This is a schematic diagram of a scene rendering apparatus provided in an embodiment of this application. The scene rendering apparatus 500 may include:
[0113] The vertex processing module 510 is used to process the vertex data of multiple consecutive target textures to be rendered in the scene to be rendered in sequence through the rendering pipeline, so as to obtain the corresponding scene fragments.
[0114] The texture rendering module 520 is used to perform pixel shading on the scene fragments based on the first pixel data after the rendering pipeline has completed the rendering of the first target texture and the second pixel data after the multiple target textures have been mixed, so as to complete the rendering of multiple target textures.
[0115] The scene rendering module 530 is used to generate a scene image of the scene to be rendered when the rendering pipeline completes the rendering of each texture in the scene to be rendered.
[0116] In some implementations, the texture rendering module 520 may include:
[0117] The first texture rendering unit is configured to, if the aforementioned texture of the first target texture is empty, sequentially blend the pixel data of each target texture according to a pre-defined sequential blending rule to obtain the second pixel data after blending multiple target textures; and perform pixel shading on the scene fragments according to the second pixel data.
[0118] The second texture rendering unit is configured to, if the aforementioned texture of the first target texture is not empty, synchronously blend the pixel data of each target texture according to the synchronous blending rules corresponding to the multiple target textures to obtain the second pixel data after the multiple target textures are blended; sequentially blend the first pixel data and the second pixel data after the aforementioned textures are rendered according to the sequential blending rules to obtain the third pixel data of the scene fragment; and perform pixel shading on the scene fragment according to the third pixel data.
[0119] In some implementations, the scene rendering apparatus 500 may further include a synchronous blending determination module. This synchronous blending determination module can be used to:
[0120] Determine the pixel variables for each target texture, the first pixel variable after the aforementioned texture has been rendered, and the second pixel variable after the multiple target textures have been blended;
[0121] According to the pre-defined sequential blending rules, the first pixel variable and the pixel variables of each target texture are sequentially blended to obtain the first sequential blending result;
[0122] According to the sequential blending rule, the first pixel variable and the second pixel variable are sequentially blended to obtain a second sequential blending result;
[0123] Based on the equivalence between the first sequential blending result and the second sequential blending result, the variable solving function of the second pixel variable is determined as the synchronous blending rule corresponding to multiple target textures;
[0124] The independent variables in the variable solving function include the first pixel variable and the pixel variables of each target texture.
[0125] In some implementations, the second texture rendering unit can be specifically used for:
[0126] The first pixel data after the aforementioned texture is rendered and the pixel data of each target texture are respectively substituted into the variable solving function of the second pixel variable to calculate the second pixel data after the multiple target textures are mixed.
[0127] In some implementations, the pixel data of each texture in the scene to be rendered includes pixel color and pixel transparency. Therefore, the pixel data obtained after rendering each texture in the scene to be rendered by the rendering pipeline also includes pixel color and pixel transparency.
[0128] In some implementations, the blending parameters used when blending multiple target textures are the first pixel data after the aforementioned textures have been rendered and the target pixel transparency in the pixel data of each target texture that matches the blending factor defined by the rendering pipeline.
[0129] In this embodiment, when the rendering pipeline renders multiple textures in the scene to be rendered sequentially, if the vertex data of multiple consecutive target textures to be rendered in the current rendering pipeline are the same, then the rendering pipeline first processes the vertex data to obtain the corresponding scene fragment. Then, based on the first pixel data after the rendering pipeline has completed rendering of the first target texture and the second pixel data after the multiple target textures are mixed, the scene fragment is pixel-shaded to complete the rendering of multiple target textures. This allows the scene image of the scene to be rendered to be generated when the rendering pipeline completes the rendering of each texture in the scene to be rendered, thereby achieving accurate rendering of the scene to be rendered. Moreover, during the scene rendering process, by running the rendering pipeline once, multiple consecutive target textures with the same vertex data can be rendered synchronously, greatly reducing the GPU usage and power consumption during scene rendering while ensuring the accuracy of scene rendering.
[0130] It should be understood that the device embodiment described herein corresponds to the method embodiment in this application, and similar descriptions can be found in the method embodiment in this application. To avoid repetition, further details are omitted here.
[0131] Specifically, Figure 5The apparatus 500 shown can perform any of the method embodiments provided in this application, and Figure 5 The aforementioned and other operations and / or functions of each module in the illustrated device 500 are respectively for implementing the corresponding processes of the above method embodiments, and will not be described in detail here for the sake of brevity.
[0132] The above-described method embodiments of this application, in conjunction with the accompanying drawings, are presented from the perspective of functional modules. It should be understood that these functional modules can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the methods disclosed in this application can be directly manifested as execution by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above-described method embodiments.
[0133] Figure 6 A schematic block diagram of an electronic device provided in an embodiment of this application.
[0134] like Figure 6 As shown, the electronic device 600 may include:
[0135] The system includes a memory 610 and a processor 620. The memory 610 stores computer programs and transfers the program code to the processor 620. In other words, the processor 620 can retrieve and run the computer program from the memory 610 to implement the methods described in the embodiments of this application.
[0136] For example, the processor 620 can be used to execute the above-described method embodiments according to instructions in the computer program.
[0137] In some embodiments of this application, the processor 620 may include, but is not limited to:
[0138] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0139] In some embodiments of this application, the memory 610 includes, but is not limited to:
[0140] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0141] In some embodiments of this application, the computer program may be divided into one or more modules, which are stored in the memory 610 and executed by the processor 620 to perform the method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the electronic device 600.
[0142] like Figure 6 As shown, the electronic device may further include:
[0143] Transceiver 630, which can be connected to processor 620 or memory 610.
[0144] The processor 620 can control the transceiver 630 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 630 may include a transmitter and a receiver. The transceiver 630 may further include antennas, and the number of antennas may be one or more.
[0145] It should be understood that the various components in the electronic device 600 are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.
[0146] This application also provides a computer storage medium storing a computer program thereon, which, when executed by a computer, enables the computer to perform the methods described in the above method embodiments.
[0147] This application also provides a computer program product containing a computer program / instructions, which, when executed by a computer, causes the computer to perform the method described in the above method embodiments.
[0148] When implemented using software, it can be implemented entirely or partially as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. 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. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. 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 integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0149] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method of scene rendering, characterized by, The method comprises the following steps: When a plurality of textures in a to-be-rendered scene are rendered in sequence by a rendering pipeline, if vertex data of a plurality of target textures currently to be rendered by the rendering pipeline is the same, the vertex data is processed by the rendering pipeline to obtain corresponding scene fragments; According to first pixel data of the rendering pipeline after the rendering of the first target texture and second pixel data after the mixing of the plurality of target textures, the scene fragments are pixel shaded to complete the rendering of the plurality of target textures; When the rendering pipeline completes the rendering of each texture in the to-be-rendered scene, a scene image of the to-be-rendered scene is generated; The pixel shading of the scene fragments according to the first pixel data of the rendering pipeline after the rendering of the first target texture and the second pixel data after the mixing of the plurality of target textures comprises the following steps: If the first target texture is empty, the pixel data of each target texture is sequentially mixed according to a preset sequential mixing rule to obtain second pixel data after the mixing of the plurality of target textures; The scene fragments are pixel shaded according to the second pixel data; If the first target texture is not empty, the pixel data of each target texture is synchronously mixed according to a synchronous mixing rule corresponding to the plurality of target textures to obtain second pixel data after the mixing of the plurality of target textures; The first pixel data after the rendering of the first target texture and the second pixel data are sequentially mixed according to the sequential mixing rule to obtain third pixel data of the scene fragments; The scene fragments are pixel shaded according to the third pixel data; The synchronous mixing rule is determined by the following steps: Pixel variables of each target texture, first pixel variables after the rendering of the first target texture and second pixel variables after the mixing of the plurality of target textures are determined; The first pixel variables and the pixel variables of each target texture are sequentially mixed according to the preset sequential mixing rule to obtain a first sequential mixing result; The first pixel variables and the second pixel variables are sequentially mixed according to the sequential mixing rule to obtain a second sequential mixing result; According to the equivalence between the first sequential mixing result and the second sequential mixing result, a variable solving function of the second pixel variables is determined as the synchronous mixing rule corresponding to the plurality of target textures; The independent variables in the variable solving function comprise the first pixel variables and the pixel variables of each target texture.
2. The method of claim 1, wherein, The synchronous mixing of the pixel data of each target texture according to the synchronous mixing rule corresponding to the plurality of target textures to obtain second pixel data after the mixing of the plurality of target textures comprises the following steps: The first pixel data after the rendering of the first target texture and the pixel data of each target texture are respectively substituted into the variable solving function of the second pixel variables to calculate the second pixel data after the mixing of the plurality of target textures.
3. The method according to claim 1 or 2, characterized in that, The pixel data of each texture in the to-be-rendered scene includes pixel color and pixel transparency, and the pixel data obtained after rendering each texture in the to-be-rendered scene by the rendering pipeline also includes pixel color and pixel transparency.
4. The method of claim 3, wherein, The blending parameters used when the plurality of target textures are blended are target pixel transparencies in the first pixel data obtained after rendering the aforementioned texture and the pixel data of each target texture, which match the blending factors defined by the rendering pipeline.
5. A scene rendering apparatus, characterized by comprising: The application comprises: a vertex processing module, configured to, when a plurality of textures in a to-be-rendered scene are sequentially rendered by a rendering pipeline, if vertex data of a plurality of target textures currently to be rendered by the rendering pipeline are the same, process the vertex data by the rendering pipeline to obtain corresponding scene fragments; a texture rendering module, configured to, according to first pixel data obtained after rendering the aforementioned texture of a first target texture and second pixel data obtained after blending a plurality of target textures, perform pixel shading on the scene fragments to complete rendering of the plurality of target textures; a scene rendering module, configured to, when the rendering pipeline completes rendering of each texture in the to-be-rendered scene, generate a scene image of the to-be-rendered scene; The texture rendering module is specifically configured to: if the aforementioned texture of the first target texture is empty, sequentially blend pixel data of each target texture according to a set sequential blending rule to obtain second pixel data obtained after blending a plurality of target textures; perform pixel shading on the scene fragments according to the second pixel data; if the aforementioned texture of the first target texture is not empty, synchronously blend pixel data of each target texture according to a corresponding synchronous blending rule of a plurality of target textures to obtain second pixel data obtained after blending a plurality of target textures; sequentially blend the first pixel data obtained after rendering the aforementioned texture and the second pixel data according to the sequential blending rule to obtain third pixel data of the scene fragments; perform pixel shading on the scene fragments according to the third pixel data; the synchronous blending rule is determined by a synchronous blending determination module, and the synchronous blending determination module is configured to: determine pixel variables of each target texture, first pixel variables obtained after rendering the aforementioned texture, and second pixel variables obtained after blending a plurality of target textures; sequentially blend the first pixel variables and pixel variables of each target texture according to a set sequential blending rule to obtain a first sequential blending result; sequentially blend the first pixel variables and the second pixel variables according to the sequential blending rule to obtain a second sequential blending result; determine a variable solving function of the second pixel variables as a corresponding synchronous blending rule of a plurality of target textures according to equivalence between the first sequential blending result and the second sequential blending result; wherein, the independent variables in the variable solving function include the first pixel variables and pixel variables of each target texture.
6. An electronic device, comprising: The application comprises: a processor; and a memory for storing executable instructions of the processor; The processor is configured to execute the scene rendering method of any one of claims 1-4 via execution of the executable instructions.
7. A computer readable storage medium having stored thereon a computer program, characterized in that The computer program, when executed by a processor, implements the scene rendering method of any one of claims 1-4.
8. A computer program product comprising computer programs / instructions, characterized in that, The computer program product, when running on an electronic device, causes the electronic device to execute the scene rendering method of any one of claims 1-4.
Citation Information
Patent Citations
Skeletal animation rendering method and system based on Unity 3D
CN112489183A
Image rendering method and device, equipment, storage medium and program product
CN114399580A