WO2023241210A1 - 虚拟场景的渲染方法、装置、设备及存储介质 - Google Patents
虚拟场景的渲染方法、装置、设备及存储介质 Download PDFInfo
- Publication number
- WO2023241210A1 WO2023241210A1 PCT/CN2023/088979 CN2023088979W WO2023241210A1 WO 2023241210 A1 WO2023241210 A1 WO 2023241210A1 CN 2023088979 W CN2023088979 W CN 2023088979W WO 2023241210 A1 WO2023241210 A1 WO 2023241210A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- rendering
- result
- lighting
- geometric
- chip memory
- Prior art date
Links
- 238000009877 rendering Methods 0.000 title claims abstract description 768
- 238000000034 method Methods 0.000 title claims abstract description 75
- 239000012634 fragment Substances 0.000 claims description 41
- 238000004590 computer program Methods 0.000 claims description 8
- 230000008569 process Effects 0.000 abstract description 21
- 238000005286 illumination Methods 0.000 abstract description 18
- 238000012545 processing Methods 0.000 description 14
- 238000010586 diagram Methods 0.000 description 10
- 230000007613 environmental effect Effects 0.000 description 10
- 238000005516 engineering process Methods 0.000 description 6
- 238000004364 calculation method Methods 0.000 description 4
- 230000003190 augmentative effect Effects 0.000 description 2
- 230000008901 benefit Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 230000009466 transformation Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000002269 spontaneous effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/005—General purpose rendering architectures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/04—Texture mapping
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/50—Lighting effects
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T15/00—3D [Three Dimensional] image rendering
- G06T15/50—Lighting effects
- G06T15/506—Illumination models
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2215/00—Indexing scheme for image rendering
- G06T2215/12—Shadow map, environment map
Definitions
- Embodiments of the present application relate to the field of rendering technology, and in particular to a virtual scene rendering method, device, equipment and storage medium.
- Multi-light source processing has always been an important part of virtual scene rendering.
- most mobile platform graphics processors Graphic Processing Unit, GPU
- tiled rendering TBR
- the GPU needs to write the geometry buffer (G-Buffer) containing the tiled rendering results into the main memory, and then re-read the geometry buffer from the main memory during the lighting rendering phase. , to complete lighting rendering based on the tiled rendering results.
- G-Buffer geometry buffer
- Embodiments of the present application provide a virtual scene rendering method, device, equipment and storage medium, which can reduce bandwidth consumption during the virtual scene rendering process.
- the technical solutions are as follows:
- embodiments of the present application provide a virtual scene rendering method, which is executed by a computer device.
- the method includes:
- geometric rendering is performed on the virtual scene to obtain geometric rendering results
- the geometric rendering result is read from the on-chip memory based on extended features, which are used to extend the way the GPU reads data from the on-chip memory;
- the lighting rendering results are written into the on-chip memory.
- a virtual scene rendering device which includes:
- the geometric rendering module is used to perform geometric rendering on the virtual scene in the geometric rendering stage to obtain the geometric rendering result; write the geometric rendering result into the on-chip memory, the on-chip memory is the memory set in the GPU, and the geometric rendering result is Rendering results are not written to main memory;
- a lighting rendering module used in the lighting rendering stage, to read the geometric rendering result from the on-chip memory based on extended characteristics.
- the extended characteristics are used to extend the way the GPU reads data from the on-chip memory; based on The light source information and the geometric rendering result are subjected to lighting rendering to obtain the lighting rendering result; the lighting rendering result is written into the on-chip memory.
- inventions of the present application provide a computer device.
- the computer device includes a processor and a memory; the memory stores at least one instruction, and the at least one instruction is used to be executed by the processor to implement the following: The virtual scene rendering method described in the above aspects.
- embodiments of the present application provide a computer-readable storage medium in which at least one program code is stored, and the program code is loaded and executed by a processor to implement the above aspects.
- Virtual scene rendering method
- inventions of the present application provide a computer program product.
- the computer program product includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
- a processor of a computer device converts data from a computer-readable storage medium to The computer instruction is read, and the processor executes the computer instruction, so that the computer device executes the virtual scene rendering method provided in various optional implementations of the above aspect.
- the GPU writes the geometry rendering results obtained in the geometry rendering stage into the GPU's on-chip memory instead of writing them into the main memory, and in the lighting rendering stage, reads the geometry rendering results from the on-chip memory based on the extended features.
- This combines the light source information to perform lighting rendering, and writes the lighting rendering results to the on-chip memory.
- the GPU can use the extended features to directly read the geometric rendering results from the on-chip memory during the lighting rendering stage, eliminating the need to write the geometric rendering results into the main memory and then read them from the main memory. link, reducing bandwidth consumption during virtual environment rendering.
- Figure 1 shows a schematic diagram of the rendering process in the related art
- Figure 2 shows a flow chart of a virtual scene rendering method provided by an exemplary embodiment of the present application
- Figure 3 is a schematic diagram of the implementation of the virtual scene rendering process shown in an exemplary embodiment of the present application
- Figure 4 shows a flow chart of a virtual scene rendering method provided by another exemplary embodiment of the present application.
- Figure 5 is a schematic diagram of the implementation of the virtual scene rendering process shown in an exemplary embodiment of the present application.
- Figure 6 is a schematic diagram of another virtual scene rendering process according to an exemplary embodiment of the present application.
- Figure 7 shows a flow chart of a virtual scene rendering method provided by another exemplary embodiment of the present application.
- Figure 8 is a schematic diagram of the implementation of the virtual scene rendering process shown in another exemplary embodiment of the present application.
- Figure 9 is an implementation schematic diagram of another virtual scene rendering process shown in another exemplary embodiment of the present application.
- Figure 10 is a flow chart for implementing multi-light source rendering based on extended features provided by an exemplary embodiment of the present application
- Figure 11 is a structural block diagram of a virtual scene rendering device provided by an exemplary embodiment of the present application.
- Figure 12 shows a schematic structural diagram of a computer device provided by an exemplary embodiment of the present application.
- TBR rendering mode is mostly used to render virtual scenes.
- the deferred rendering process mainly includes the geometry rendering stage and the lighting rendering stage.
- the GPU calculates and draws the geometric information corresponding to the virtual scene to obtain the geometric rendering result, and stores the geometric rendering result through the geometry buffer (G-Buffer);
- the GPU based on the geometric rendering result and light source information, perform lighting calculation and processing, obtain lighting rendering results, and finally complete the rendering of the virtual scene.
- the GPU divides the scene into several slices (tiles) according to the size of the on-chip memory (tile memory). By performing geometric rendering and lighting rendering processing on each slice separately, the lighting rendering results corresponding to each slice are obtained. , and then stitch the final lighting rendering results to complete the rendering of the entire scene.
- the geometry buffer storing the geometry rendering results will be written into the main memory.
- the geometry rendering results in the geometry buffer need to be re-read from the main memory. And perform lighting rendering. Since a large amount of data is stored in the main memory and the transmission speed is slow, during the rendering process, the GPU needs to continuously write and read the geometry buffer between the main memory and the main memory, which increases bandwidth consumption and leads to more Power consumption.
- the GPU reads the geometric information (Geometry Data) 101 of the virtual scene from the main memory and places it in the on-chip memory, and reads the geometric information 101 from the on-chip memory for geometric rendering. processing, and then write the geometry rendering result into the geometry buffer 102 in the on-chip memory, and write the geometry buffer 102 into the main memory at the same time.
- geometric information Geometry Data
- the GPU When performing lighting rendering processing, the GPU reads the geometry buffer 102 from the main memory into the on-chip memory, performs lighting rendering processing on the geometry rendering result of the geometry buffer 102 in the on-chip memory to obtain the lighting rendering result 103, and converts the lighting The rendering result 103 is written into the on-chip memory, and finally the lighting rendering result 103 is written into the main memory.
- the GPU writes the geometric rendering results to the on-chip memory without writing them to the main memory.
- the extended feature is used to directly read the geometric rendering results from the on-chip memory. The result is illuminated and rendered.
- the rendering of each slice is completed through the interaction between the GPU and on-chip memory, without writing the geometric rendering results to the main memory midway, avoiding the bandwidth consumption caused by frequent writing and reading operations to the main memory. , helps improve rendering efficiency and reduces power consumption during the rendering process.
- the solution provided by the embodiment of the present application can be executed by a mobile platform computer device (such as a smart phone, a tablet computer, a personal portable computer, etc.), the computer device is equipped with a GPU, and the computer device runs a virtual environment rendering on-demand applications. Because it can reduce bandwidth consumption during the rendering process when rendering virtual environments containing complex lighting, it helps improve device battery life.
- a mobile platform computer device such as a smart phone, a tablet computer, a personal portable computer, etc.
- the computer device is equipped with a GPU, and the computer device runs a virtual environment rendering on-demand applications. Because it can reduce bandwidth consumption during the rendering process when rendering virtual environments containing complex lighting, it helps improve device battery life.
- FIG. 2 shows a flow chart of a virtual scene rendering method provided by an exemplary embodiment of the present application.
- the method may include the following steps:
- Step 201 In the geometric rendering stage, geometric rendering is performed on the virtual scene to obtain a geometric rendering result.
- each virtual object in the virtual scene is presented in the form of a three-dimensional model
- the GPU needs to process the geometric information corresponding to the three-dimensional model of each virtual object in the virtual scene.
- each The geometric information of the virtual object is transformed from the three-dimensional space to the screen space, and the geometric rendering result corresponding to the screen space is obtained.
- the geometric rendering result may include color information, normal information, environmental occlusion information, reflection information and other information that can characterize the state of the virtual object in the virtual scene. This is not limited in the embodiments of the present application.
- the geometric rendering process may include vertex shading, coordinate transformation, primitive generation, projection, cropping, screen mapping and other processes.
- the GPU performs geometric rendering processing on each virtual object in the virtual scene to obtain the virtual scene. The geometric rendering results corresponding to each virtual object in .
- the GPU reads the geometric information 301 corresponding to the virtual scene, and performs geometric rendering processing on the virtual scene based on the geometric information 301, thereby obtaining a geometric rendering result 302.
- Step 202 Write the geometry rendering result into the on-chip memory.
- the on-chip memory is the memory set in the GPU, and the geometry rendering result is not written into the main memory.
- the on-chip memory is the memory set in the GPU, which is a high-speed cache and has the characteristics of fast speed, small capacity, and low consumption.
- the main memory also called system memory
- the main memory has a large capacity and a slow transmission speed, and reading and writing data into the main memory requires a large amount of bandwidth.
- the GPU when the TBR rendering mode is enabled, the GPU writes the geometry rendering results to the on-chip memory. If the TBR rendering mode is not enabled, you need to enable the TBR rendering mode first.
- the GPU divides the virtual scene into several slices according to the size of the on-chip memory, and renders each slice separately, so that the on-chip memory can be used to complete the writing and reading of rendering data, which improves Rendering efficiency.
- the GPU writes the geometry rendering results to the on-chip memory, and before all rendering stages are completed, the geometry rendering results are not written to the main memory.
- the GPU only writes and reads rendering data in the on-chip memory. Pick.
- the GPU writes the generated geometry rendering result 302 into the on-chip memory instead of into the main memory.
- Step 203 In the lighting rendering stage, the geometric rendering results are read from the on-chip memory based on the extended features.
- the extended features are used to extend the way the GPU reads data from the on-chip memory.
- the GPU needs to take advantage of the extension feature to read the geometry rendering results from the on-chip memory.
- the extension feature is used to expand the GPU's ability to read data from on-chip memory. method (without going through the main memory).
- this extension feature is used to extend the GPU to read the geometry rendering results from the on-chip memory without going through the main memory.
- this extension is used to allow fragment shaders to directly access on-chip memory.
- the extended feature is a framebuffer fetch extended feature.
- the GPU directly reads the geometric rendering results from the on-chip memory, including color information, normal information, environmental occlusion information, reflection information, etc. of virtual objects in the virtual scene.
- the GPU directly reads the geometric rendering result 302 obtained in the geometric rendering stage from the on-chip memory based on the extended feature.
- Step 204 Perform lighting rendering based on the light source information and geometric rendering results to obtain lighting rendering results.
- the same virtual object is illuminated by multiple light sources, and the same light source also illuminates multiple virtual objects at the same time. Therefore, in order to express the lighting conditions of each virtual object in the virtual scene, the GPU uses different light source information. And the geometric rendering results are used for lighting rendering to obtain the lighting rendering results.
- the light source information can be divided according to light source types, and different drawing forms are used for different types of light sources.
- the GPU performs lighting rendering based on the light source information 304 and the geometric rendering result 302, and obtains the lighting rendering result 303.
- Step 205 Write the lighting rendering results into the on-chip memory.
- the GPU writes the lighting rendering results into the on-chip memory to complete the rendering of a slice in the virtual scene. For each slice corresponding to the virtual scene picture, the computer device repeats the above steps until each slice is rendered.
- the GPU writes the lighting rendering result 303 into the on-chip memory.
- the GPU writes the geometry rendering results obtained in the geometry rendering stage into the GPU's on-chip memory instead of writing them into the main memory, and in the lighting rendering stage, reads them from the on-chip memory based on the extended characteristics. Get the geometric rendering result, perform lighting rendering based on the light source information, and write the lighting rendering result into the on-chip memory.
- the GPU can use the extended features to directly read the geometric rendering results from the on-chip memory during the lighting rendering stage, eliminating the need to write the geometric rendering results into the main memory and then read them from the main memory. link, reducing bandwidth consumption during virtual environment rendering.
- the GPU uses a vertex shader and a fragment shader to perform rendering in the geometry rendering stage and lighting rendering stage respectively, and creates a rendering texture in the geometry buffer of the on-chip memory. (Render Texture), by storing the geometric rendering results in the rendering texture, the geometric rendering results are read. This is described in detail below through specific embodiments.
- FIG. 4 shows a flow chart of a virtual scene rendering method provided by another exemplary embodiment of the present application.
- the method may include the following steps:
- Step 401 In the geometry rendering stage, n rendering textures are created. Different rendering textures are used to store different types of rendering results. The rendering textures are located in the geometry buffer of the on-chip memory.
- n is an integer greater than or equal to 2.
- the n rendering textures created by the GPU are used not only to store the geometric rendering results of the geometry rendering stage, but also to store the lighting of the lighting rendering stage.
- the rendering results, i.e. geometry rendering and lighting rendering are done on the basis of the created rendering texture.
- the results of geometry rendering and lighting rendering can be stored in different rendering textures.
- the GPU creates five rendering textures (located in the geometry buffer 502).
- the first rendering texture 5021 is used to store the color and ambient occlusion (Ambient Occlusion, AO) information of the virtual object.
- the second rendering texture 5022 is used to store the normal information of the virtual object
- the third rendering texture 5023 is used to store the spontaneous light and highlight information of the virtual object
- the fourth rendering texture 5024 is used to store the virtual object.
- the fifth rendering texture 5025 is used to store the final rendering result of the lighting rendering stage.
- this embodiment only takes the creation of 5 rendering textures as an example for schematic explanation. In actual applications, the number and type of rendering textures can be set according to needs. This embodiment does not specify the number and type of rendering textures. constitute a limitation.
- Step 402 In the geometry rendering stage, perform vertex rendering on the virtual scene through the first vertex shader to obtain the first vertex rendering result.
- the GPU first determines the rendering information of each vertex through the first vertex shader, so that the vertices can be collected and assembled into points, lines, and triangles based on the determined vertex information.
- the GPU performs vertex rendering of the virtual scene through a first vertex shader, where the first vertex shader acts on each vertex of the virtual object.
- the vertices may also include methods. Line, color and other information, the GPU can transform the vertex information of the virtual object from the model space to the screen space by using the first vertex shader, thereby obtaining the first vertex rendering result.
- the GPU reads the geometric information 501 of the virtual scene, and performs vertex rendering on the virtual scene through the first vertex shader 503 to obtain the first vertex rendering result.
- Step 403 Based on the first vertex rendering result, perform fragment rendering through the first fragment shader to obtain a geometry rendering result, where the first fragment shader uses the inout keyword to define an output variable.
- the GPU performs fragment rendering through the first fragment shader to render the triangle (consisting of vertices) Method, all fragments are rendered to obtain geometric rendering results.
- the first fragment shader uses the inout keyword to define the output variable, that is, through The inout keyword defines the geometric rendering result, so that the geometric rendering result serves as both input and output.
- the method of defining the output variable through the inout keyword can replace the original value with the changed value when the variable changes, thereby realizing geometric rendering.
- the results are updated in real time and ensure that the subsequent lighting rendering stage can accurately read the rendering texture obtained in the geometry rendering stage.
- the GPU performs fragment rendering through the first fragment shader 504 to obtain a geometry rendering result.
- Step 404 Write the geometric rendering result into the created rendering texture.
- the GPU writes the geometry rendering results to the corresponding rendering textures.
- the rendering texture is located in a geometry buffer in the on-chip memory.
- the geometry buffer can store information related to each virtual object in the virtual scene and is used to meet the calculation requirements of the subsequent lighting rendering stage.
- the GPU writes the geometric rendering results into the 1st to n-1th rendering textures, and the 1st to n-1th rendering textures correspond to different types of rendering results in the geometry rendering stage, and the nth rendering texture Render textures are used to store the final rendering results of the lighting rendering stage.
- FIG. 5 Schematically, as shown in Figure 5, there are five rendering textures in the geometry buffer 502 of the on-chip memory.
- the GPU writes the color and environmental occlusion information of the virtual object obtained in the geometry rendering stage into the first rendering texture 5021, and the virtual object is The normal information of the virtual object is written into the second rendering texture 5022, the self-illumination and highlight information of the virtual object is written into the third rendering texture 5023, and the depth information of the virtual object is written into the fourth rendering texture 5024.
- Step 405 In the lighting rendering stage, the geometric rendering result is read from the rendering texture based on the first extended feature.
- the first extended feature is used to extend the way the GPU reads data from the geometry buffer of the on-chip memory.
- the GPU reads the corresponding geometric rendering results from each rendering texture based on the first extended characteristic, where the first extended characteristic is used to extend the geometry of the GPU from the on-chip memory.
- the method of reading data from the buffer is used to extend the GPU to read the geometric rendering result in the rendering texture from the geometry buffer of the on-chip memory, and the read rendering texture is geometric
- the rendering phase stores the rendering texture of the geometry rendering results.
- the first extended feature is the mobile platform GPU OpenGLES GL_EXT_shader_framebuffer_fetch extended feature.
- Step 406 Perform vertex rendering on the light source surrounding volume represented by the light source information through the second vertex shader to obtain a second vertex rendering result.
- the types of light sources are complex, direct light that affects the entire scene requires lighting calculations pixel by pixel; there are also local light sources that only affect a part of the area, which only affect certain pixels on the screen, without the need to do so pixel by pixel.
- the pixels perform illumination calculations. Therefore, the GPU draws the corresponding light source surrounding body based on different light source information.
- the size of the surrounding body is greater than or equal to the attenuation range of the light source.
- different types of light sources correspond to different shapes of light source surrounding bodies.
- direct lighting uses a full-screen quadrilateral bounding volume
- point light sources use a spherical bounding volume
- spotlights use a conical bounding volume.
- the GPU performs vertex rendering on the light source surrounding volume represented by the light source information through the second vertex shader, and projects the vertex transformation of the light source surrounding volume to the corresponding area on the screen, thereby obtaining the second vertex rendering result.
- the GPU performs vertex rendering on the light source surrounding volume represented by the light source information through the second vertex shader 505 to obtain a second vertex rendering result.
- Step 407 Based on the second vertex rendering result and the geometry rendering result, perform lighting rendering through the second fragment shader to obtain the lighting rendering result, where the second fragment shader uses the inout keyword to define input variables.
- the second fragment shader uses inout The keyword defines the way of input variables, obtains the geometric rendering result (i.e., rendering texture) obtained in the geometric rendering stage, and uses the lighting equation to calculate the geometric rendering result based on the second vertex rendering result to obtain the lighting rendering result.
- the keyword defines the way of input variables, obtains the geometric rendering result (i.e., rendering texture) obtained in the geometric rendering stage, and uses the lighting equation to calculate the geometric rendering result based on the second vertex rendering result to obtain the lighting rendering result.
- the GPU uses lighting equations to calculate color and ambient occlusion information, normal information, self-illumination and highlight information to obtain lighting rendering results.
- the GPU performs lighting rendering through the second fragment shader 506 to obtain the lighting rendering result.
- Step 408 Write the lighting rendering result into the rendering texture.
- the GPU writes the lighting rendering results into the nth rendering texture.
- the GPU writes the lighting rendering result to the fifth rendering texture 5025 in the geometry buffer 502.
- Step 409 Write the lighting rendering results stored in the on-chip memory into the main memory.
- the GPU writes the lighting rendering results stored in the on-chip memory into the main memory to complete the rendering of a slice.
- the GPU clears the rendering results stored in the on-chip memory and starts rendering the next slice. Finally, based on the rendering results of each slice, the entire virtual scene is rendered.
- the GPU writes the fifth rendering texture 5025 where the lighting rendering result of the current slice stored in the on-chip memory is stored in the main memory.
- the GPU creates a rendering texture for storing the geometry rendering results in the geometry buffer of the on-chip memory, and creates a rendering texture for storing the lighting rendering results in the geometry buffer, ensuring that during the geometry rendering stage No switching of rendering textures occurs during the lighting and lighting rendering stages, and only the final lighting rendering results are written to the main memory, reducing memory usage; at the same time, based on the first extended feature, the geometry rendering results can be read from the rendering texture, and the entire rendering The stage only interacts with data on-chip memory, which improves rendering efficiency and reduces bandwidth consumption.
- the fragment shader can directly use the extended feature to read data from the on-chip memory when reading the rendering texture, ensuring that the lighting rendering stage further renders the results of the corresponding geometry rendering stage, ensuring rendering Process accuracy.
- lighting rendering and geometry rendering can reuse the same rendering texture. Since the geometric rendering results stored in the rendering texture are no longer needed after the lighting rendering is completed, during the lighting rendering stage, after the GPU performs lighting rendering through the second fragment shader, the obtained lighting rendering results can be directly overwritten and stored in it. in any rendering texture. By reducing the need to create render textures that store lighting rendering results, you can further reduce the cost of rendering. memory usage.
- the GPU only creates 4 rendering textures in the geometry buffer 601.
- the first rendering texture 6011 is used to store the color and environmental occlusion information of the virtual object
- the second rendering texture 6012 is used to store the color and environmental occlusion information of the virtual object.
- the normal information of the virtual object is stored
- the third rendering texture 6013 is used to store the self-illumination and highlight information of the virtual object
- the fourth rendering texture 6014 is used to store the depth information of the virtual object.
- the GPU After performing lighting rendering through the second fragment shader 602 and obtaining the lighting rendering result, the GPU directly overwrites the color and ambient occlusion information in the first rendering texture 6011 with the lighting rendering result. Further, the GPU will store the third lighting rendering result.
- a render texture 6011 is written into main memory.
- the geometry rendering results do not need to be stored entirely in the rendering texture.
- the GPU can store part of the geometry rendering results in the rendering texture, and the rest directly in the on-chip memory, thus eliminating the need to create additional rendering textures. Accordingly, the GPU uses different methods to obtain the geometric rendering results of different storage methods during the lighting rendering stage. This is explained below through exemplary embodiments.
- FIG. 7 shows a flow chart of a virtual scene rendering method provided by another exemplary embodiment of the present application.
- the method may include the following steps:
- Step 701 In the geometry rendering stage, m rendering textures are created.
- the rendering textures are located in the geometry buffer of the on-chip memory, and different rendering textures are used to store different types of rendering results.
- m is an integer greater than or equal to 2.
- the GPU creates m rendering textures and stores different types of rendering results in different rendering textures.
- the GPU directly obtains the rendering result information that can be obtained from the on-chip memory according to the second extended feature without creating a corresponding rendering texture, therefore, m is smaller than n.
- the difference between m and n is 1, and m is equal to n-1.
- the GPU creates four rendering textures.
- the first rendering texture 8021 is used to store the color and environmental occlusion information of the virtual object
- the second rendering texture 8022 is used to store the normal information of the virtual object.
- the third rendering texture 8023 is used to store the self-illumination and highlight information of the virtual object
- the fourth rendering texture 8024 is used to store the final rendering result of the lighting rendering stage.
- Step 702 In the geometry rendering stage, perform vertex rendering on the virtual scene through the first vertex shader to obtain the first vertex rendering result.
- Step 703 Based on the first vertex rendering result, perform fragment rendering through the first fragment shader to obtain a geometry rendering result, where the first fragment shader uses the inout keyword to define an output variable.
- step 702 and step 703 reference can be made to the above-mentioned steps 402 and 403, which will not be described again in this embodiment.
- Step 704 Write the first rendering result among the geometric rendering results into the created rendering texture.
- the GPU writes the first rendering result defined by the inout keyword in the geometry rendering result into the created rendering texture, where the rendering texture is located in the geometry buffer of the on-chip memory, and the on-chip memory is tile memory.
- the first rendering result includes rendering information other than depth information, which may be color information, normal information, self-illumination information, etc.
- the GPU writes the first rendering result among the geometric rendering results into the 1st to m-1th rendering textures, where the 1st to m-1th rendering textures correspond to different types of rendering.
- the mth rendering texture is used to store the final rendering result of the lighting rendering stage.
- FIG. 8 Schematically, as shown in Figure 8, there are four rendering textures in the geometry buffer 802 of the on-chip memory.
- the GPU writes the color and environmental occlusion information of the virtual object obtained in the geometry rendering stage into the first rendering texture 8021, and the virtual object is The normal information is written into the second rendering texture 8022, and the self-illumination and highlight information of the virtual object is written into the third rendering texture 8023.
- Step 705 Write the second rendering result among the geometric rendering results into an area other than the rendering texture in the on-chip memory.
- the GPU directly writes the second rendering result in the geometric rendering result to an area other than the rendering texture in the on-chip memory. There is no need to create a corresponding rendering texture for storage of the second rendering result, thereby reducing the number of on-chip Memory usage.
- the rendering type corresponding to the second rendering result needs to support reading directly from the on-chip memory through extended features.
- the second rendering result includes depth information.
- the second rendering result may also include other types of information that support direct reading from on-chip memory through extended features, which is not limited in the embodiments of the present application.
- the GPU writes the depth information 801 combined with the rendering into an area other than the rendering texture in the on-chip memory.
- Step 706 In the lighting rendering stage, based on the extended characteristics, the first rendering result is read from the rendering texture, and the second rendering result is read from the on-chip memory.
- the GPU Since the first rendering result and the second rendering result are stored in different locations in the on-chip memory, during the lighting rendering stage, the GPU reads the first rendering result and the second rendering result respectively from the rendering texture and the on-chip memory based on different extended characteristics. .
- the GPU reads the first rendering result from the rendering texture, and the first extended characteristic is used to extend the way in which the GPU reads data from the geometry buffer of the on-chip memory.
- the GPU reads from the rendering texture through a first extension feature that is used to extend the way the GPU reads data from the geometry buffer of the on-chip memory.
- the first extended feature is the mobile platform GPU OpenGLES GL_EXT_shader_framebuffer_fetch extended feature, when the inout keyword is used to define the geometry rendering result and the rendering texture created in the geometry rendering stage is used (that is, no rendering texture switching occurs ), the GPU can directly read the first rendering result from the geometry buffer of the on-chip memory based on the first extended feature.
- the GPU reads the second rendering result from the on-chip memory, and the second extended feature is used to extend the way in which the GPU reads depth information from the on-chip memory.
- the GPU directly reads from the on-chip memory through the second extension feature.
- This second extension feature is used to extend the way the GPU reads depth information from the on-chip memory. .
- the second extended feature is the mobile platform GPU OpenGLES GL_ARM_shader_framebuffer_fetch_depth_stencil extended feature.
- the GPU can directly read depth information from the built-in variable gl_LastFragDepthARM in on-chip memory.
- Step 707 Use the second vertex shader to perform vertex rendering on the light source surrounding volume represented by the light source information to obtain a second vertex rendering result.
- Step 708 Based on the second vertex rendering result and the geometry rendering result, perform lighting rendering through the second fragment shader to obtain the lighting rendering result, where the second fragment shader uses the inout keyword to define input variables.
- step 707 and step 708 reference can be made to the above-mentioned steps 406 and 407, which will not be described again in this embodiment.
- Step 709 Write the lighting rendering result into the rendering texture.
- the GPU writes the lighting rendering result into the m-th rendering texture, which is located in the geometry buffer in the on-chip memory.
- the GPU writes the lighting rendering result into a fourth rendering texture 8024, which is located in the geometry buffer 802 in the on-chip memory.
- Step 710 Write the lighting rendering results stored in the on-chip memory into the main memory.
- the GPU directly reads the depth information from the on-chip memory through the second extended feature, avoiding the need to create a corresponding rendering texture for the depth information, which can not only ensure that the depth information is read correctly, but also reduce the occupation of the on-chip memory. .
- the GPU performs lighting rendering through the second fragment shader, it directly overwrites the obtained lighting rendering result by multiplexing the rendering texture. Stored in any render texture within the geometry buffer.
- the GPU only creates three rendering textures in the geometry buffer 902.
- the first rendering texture 9021 is used to store the color and environmental occlusion information of the virtual object
- the second rendering texture 9022 is used to store the color and environmental occlusion information of the virtual object.
- the third rendering texture 9023 is used to store the self-illumination and highlight information of the virtual object.
- FIG. 10 shows a flow chart for implementing multi-light source rendering based on extended features provided by an exemplary embodiment of the present application.
- Step 1001 create a rendering texture.
- the GPU creates four rendering textures.
- the first rendering texture is used to store the color and environmental occlusion information of the virtual object.
- the second rendering texture is used to store the normal information of the virtual object.
- the third rendering texture is used to store the virtual object.
- the object's self-illumination and highlight information, the fourth rendering texture is used to store the final rendering result of the lighting rendering stage.
- Step 1002 Draw objects in the virtual scene.
- the GPU draws virtual objects in the virtual scene, performs geometric rendering based on the drawn geometric information, and obtains geometric rendering results, including color, ambient occlusion, normals, self-illumination and highlight information.
- Step 1003 Write color, ambient occlusion, normal, self-illumination and highlight information into the rendering texture.
- the GPU writes color, ambient occlusion, normal, self-illumination and highlight information into the corresponding rendering texture, which is located in the geometry buffer of the tile memory.
- Step 1004 Write the depth information into the tile memory.
- the GPU writes depth information directly into the tile memory.
- the second extended feature is the mobile platform GPU OpenGLES GL_ARM_shader_framebuffer_fetch_depth_stencil extended feature.
- Step 1005 Draw corresponding bounding volumes of all light sources in the scene.
- the GPU draws corresponding bounding volumes for all light sources in the scene, and performs vertex rendering on the light source bounding volumes through the second vertex shader to obtain the second vertex rendering result.
- Step 1006 Read color, ambient occlusion, normal, self-illumination and highlight information from the rendering texture.
- the GPU reads color, ambient occlusion, normal, self-illumination and highlight information from the rendering texture.
- the first extended feature is the mobile platform GPU OpenGLES GL_EXT_shader_framebuffer_fetch extended feature.
- Step 1007 read depth information from tile memory.
- the GPU reads depth information from the built-in variable gl_LastFragDepthARM in the tile memory.
- Step 1008 Use the lighting equation to calculate the lighting rendering result.
- the GPU uses the lighting equation to calculate the lighting rendering result.
- FIG. 11 shows a structural block diagram of a virtual scene rendering device provided by an exemplary embodiment of the present application.
- the device may include the following structure:
- the geometric rendering module 1101 is used to perform geometric rendering on the virtual scene during the geometric rendering stage to obtain the geometric rendering result; write the geometric rendering result into the on-chip memory, the on-chip memory is the memory set in the GPU, and the Geometry rendering results are not written to main memory;
- the lighting rendering module 1102 is used to read the geometric rendering result from the on-chip memory based on extended characteristics during the lighting rendering stage.
- the extended characteristics are used to extend the way in which the GPU reads data from the on-chip memory; Lighting rendering is performed based on the light source information and the geometric rendering result to obtain a lighting rendering result; and the lighting rendering result is written into the on-chip memory.
- the geometry rendering module 1101 is used for:
- the lighting rendering module 1102 is used for:
- the geometric rendering result is read from the rendering texture based on a first extended characteristic, which is used to extend the way in which the GPU reads data from the geometry buffer of the on-chip memory;
- the lighting rendering module 1102 is also used to:
- the geometry rendering module 1101 is used to create n rendering textures in the geometry rendering stage. Different rendering textures are used to store different types of rendering results, and n is an integer greater than or equal to 2;
- the geometry rendering module 1101 is also used to:
- the lighting rendering module 1102 is also used to:
- the geometry rendering module 1101 is used for:
- the lighting rendering module 1102 is used for:
- the lighting rendering module 1102 is also used to:
- the second rendering result includes depth information
- the first rendering result includes rendering information other than the depth information
- the lighting rendering module 1102 is used for:
- the first extension characteristic is used to extend the way in which the GPU reads data from the geometry buffer of the on-chip memory
- the second rendering result is read from the on-chip memory based on a second extended characteristic.
- the second extended characteristic is used to extend the way in which the GPU reads the depth information from the on-chip memory.
- the geometry rendering module 1101 is also used to create m rendering textures during the geometry rendering stage. Different rendering textures are used to store different types of rendering results, and m is an integer greater than or equal to 2;
- the geometry rendering module 1101 is also used to:
- the lighting rendering module 1102 is also used to:
- the geometry rendering module 1101 is used for:
- the lighting rendering module 1102 is used for:
- lighting rendering is performed through a second fragment shader to obtain the lighting rendering result, wherein the second fragment shader uses the inout keyword to define input variables.
- the device also includes:
- a result writing module is configured to write the lighting rendering results stored in the on-chip memory into the main memory.
- the GPU is a mobile platform GPU
- the on-chip memory is tile memory
- the GPU writes the geometry rendering results obtained in the geometry rendering stage into the GPU's on-chip memory instead of writing them into the main memory, and in the lighting rendering stage, reads them from the on-chip memory based on the extended characteristics. Get the geometric rendering result, perform lighting rendering based on the light source information, and write the lighting rendering result into the on-chip memory.
- the GPU can use the extended features to directly read the geometric rendering results from the on-chip memory during the lighting rendering stage, eliminating the need to write the geometric rendering results into the main memory and then read them from the main memory. link, reducing bandwidth consumption during virtual environment rendering.
- the device provided in the above embodiments is only exemplified by the division of the above functional modules.
- the above function allocation can be completed by different functional modules as needed, that is, the internal structure of the device is divided into Different functional modules to complete all or part of the functions described above.
- the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the implementation process can be found in the method embodiments, which will not be described again here.
- the computer device 1200 includes a processor 1201, a system memory 1204 including a random access memory 1202 and a read-only memory 1203, and a system bus 1205 connecting the system memory 1204 and the central processing unit 1201.
- the computer device 1200 also includes a basic input/output system (Input/Output, I/O system) 1206 that helps transmit information between various devices in the computer, and is used to store an operating system 1213, application programs 1214 and other program modules. 1215 mass storage device 1207.
- I/O system Basic input/output system
- the processor 1201 includes a central processing unit (Central Processing Unit, CPU) 1216 and a graphics processor (Graphic Processing Unit, GPU) 1217, wherein the graphics processor 1217 is provided with a Tile memory, and the graphics processor is used for Implement the virtual scene rendering method in the embodiment of this application.
- CPU Central Processing Unit
- GPU Graphic Processing Unit
- the basic input/output system 1206 includes a display 1208 for displaying information and an input device 1209 such as a mouse and a keyboard for the user to input information.
- the display 1208 and the input device 1209 are both connected to the processor 1201 through the input and output controller 1210 connected to the system bus 1205 .
- the basic input/output system 1206 may also include an input/output controller 1210 for receiving and processing input from a plurality of other devices such as a keyboard, mouse, or electronic stylus.
- input and output controller 1210 also provides output to a display screen, printer, or other type of output device.
- the mass storage device 1207 is connected to the processor 1201 through a mass storage controller (not shown) connected to the system bus 1205 .
- the mass storage device 1207 and its associated computer-readable media provide non-volatile storage for the computer device 1200 . That is, the mass storage device 1207 may include a computer-readable medium (not shown) such as a hard disk or drive.
- the computer-readable media may include computer storage media and communication media.
- Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data.
- Computer storage media include random access memory (RAM, Random Access Memory), read-only memory (ROM, Read Only Memory), flash memory or other solid-state storage technologies, read-only disk (Compact Disc Read-Only Memory, CD-ROM) ), Digital Versatile Disc (DVD) or other optical storage, tape cassette, magnetic tape, disk storage or other magnetic storage device.
- RAM Random Access Memory
- ROM Read Only Memory
- flash memory or other solid-state storage technologies
- read-only disk Compact Disc Read-Only Memory
- DVD Digital Versatile Disc
- tape cassette magnetic tape
- disk storage disk storage or other magnetic storage device.
- the above-mentioned system memory 1204 and mass storage device 1207 may be collectively referred to as memory.
- the memory stores one or more programs.
- the one or more programs are configured to be executed by one or more processors 1201.
- the one or more programs contain instructions for implementing the above methods.
- the processor 1201 executes the one or more programs.
- the program implements the methods provided by each of the above method embodiments.
- the computer device 1200 may also be connected to a remote computer on the network through a network such as the Internet to run. That is, the computer device 1200 can connect to the system bus 1205 through the network.
- the network interface unit 1211 is connected to the network 1212, or the network interface unit 1211 may also be used to connect to other types of networks or remote computer systems (not shown).
- Embodiments of the present application also provide a computer-readable storage medium, which stores at least one instruction.
- the at least one instruction is loaded and executed by a processor to implement the virtual scene rendering method provided by the above embodiments.
- Embodiments of the present application provide a computer program product or computer program.
- the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
- the processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the virtual scene rendering method described in the above embodiments.
Landscapes
- Engineering & Computer Science (AREA)
- Computer Graphics (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Image Generation (AREA)
Abstract
本申请实施例公开了一种虚拟场景的渲染方法、装置、设备及存储介质,属于渲染技术领域。该方法包括:在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果(201);将几何渲染结果写入片上内存,片上内存为设置在GPU中的内存,且几何渲染结果不写入主内存(202);在光照渲染阶段,基于扩展特性,从片上内存中读取几何渲染结果,扩展特性用于扩展GPU从片上内存中读取数据的方式(203);基于光源信息以及几何渲染结果进行光照渲染,得到光照渲染结果(204);将光照渲染结果写入片上内存(205)。采用本申请实施例提供的方案,在渲染过程中,几何渲染结果不再需要存入主内存中,从而减少了带宽消耗。
Description
本申请要求于2022年06月17日提交,申请号为202210690977.5、发明名称为“虚拟场景的渲染方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请实施例涉及渲染技术领域,特别涉及一种虚拟场景的渲染方法、装置、设备及存储介质。
多光源处理一直是虚拟场景渲染中的重要环节。相关技术中,移动平台的图形处理器(Graphic Processing Unit,GPU)大多采用分块渲染(Tile Base Rendering,TBR)模式进行虚拟场景的渲染。
在几何渲染阶段结束之后,GPU需要将包含分块渲染结果的几何缓冲区(Geometry Buffer,G-Buffer)写入主内存中,然后在光照渲染阶段再从主内存中重新读取该几何缓冲区,以基于分块渲染结果完成光照渲染。
由于渲染过程中,需要频繁与主内存进行写入和读取操作,导致需要消耗大量的带宽,进而导致渲染过程的电量消耗较高。
发明内容
本申请实施例提供了一种虚拟场景的渲染方法、装置、设备及存储介质,能够降低虚拟场景渲染过程中的带宽消耗。所述技术方案如下:
一方面,本申请实施例提供了一种虚拟场景的渲染方法,所述方法由计算机设备执行,所述方法包括:
在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果;
将所述几何渲染结果写入片上内存,所述片上内存为设置在GPU中的内存,且所述几何渲染结果不写入主内存;
在光照渲染阶段,基于扩展特性,从所述片上内存中读取所述几何渲染结果,所述扩展特性用于扩展GPU从所述片上内存中读取数据的方式;
基于光源信息以及所述几何渲染结果进行光照渲染,得到光照渲染结果;
将所述光照渲染结果写入所述片上内存。
另一方面,本申请实施例提供了一种虚拟场景的渲染装置,所述装置包括:
几何渲染模块,用于在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果;将所述几何渲染结果写入片上内存,所述片上内存为设置在GPU中的内存,且所述几何渲染结果不写入主内存;
光照渲染模块,用于在光照渲染阶段,基于扩展特性,从所述片上内存中读取所述几何渲染结果,所述扩展特性用于扩展GPU从所述片上内存中读取数据的方式;基于光源信息以及所述几何渲染结果进行光照渲染,得到光照渲染结果;将所述光照渲染结果写入所述片上内存。
另一方面,本申请实施例提供了一种计算机设备,所述计算机设备包括处理器和存储器;所述存储器存储有至少一条指令,所述至少一条指令用于被所述处理器执行以实现如上述方面所述的虚拟场景的渲染方法。
另一方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有至少一条程序代码,所述程序代码由处理器加载并执行以实现如上述方面所述的虚拟场景的渲染方法。
另一方面,本申请实施例提供了一种计算机程序产品,该计算机程序产品包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介
质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行上述方面的各种可选实现方式中提供的虚拟场景的渲染方法。
本申请实施例中,GPU将在几何渲染阶段得到的几何渲染结果写入GPU的片上内存,而不写入主内存,并在光照渲染阶段,基于扩展特性从片上内存中读取几何渲染结果,从而结合光源信息进行光照渲染,并将光照渲染结果写入片上内存。采用本申请实施例提供的方案,GPU能够利用扩展特性在光照渲染阶段直接从片上内存中读取该几何渲染结果,免去了将几何渲染结果写入主内存,再从主内存中读取的环节,降低了虚拟环境渲染过程中的带宽消耗。
图1示出了相关技术中渲染过程的示意图;
图2示出了本申请一个示例性实施例提供的虚拟场景的渲染方法的流程图;
图3是本申请一个示例性实施例示出的虚拟场景渲染过程的实施示意图;
图4示出了本申请另一个示例性实施例提供的虚拟场景的渲染方法的流程图;
图5是本申请一个示例性实施例示出的虚拟场景渲染过程的实施示意图;
图6是本申请一个示例性实施例示出的另一个虚拟场景渲染过程的实施示意图;
图7示出了本申请另一个示例性实施例提供的虚拟场景的渲染方法的流程图;
图8是本申请另一个示例性实施例示出的虚拟场景渲染过程的实施示意图;
图9是本申请另一个示例性实施例示出的另一个虚拟场景渲染过程的实施示意图;
图10是本申请一个示例性实施例提供的基于扩展特性实现多光源渲染的流程图;
图11是本申请一个示例性实施例提供的虚拟场景的渲染装置的结构框图;
图12示出了本申请一个示例性实施例提供的计算机设备的结构示意图。
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
基于移动平台带宽有限的特点,在移动平台进行延迟渲染(Deferred rendering)的过程中,大多采用TBR渲染模式对虚拟场景进行渲染。
其中,延迟渲染过程主要包括几何渲染阶段和光照渲染阶段。在几何渲染阶段,GPU对虚拟场景对应的几何信息进行计算和绘制,得到几何渲染结果,并通过几何缓冲区(G-Buffer)存储该几何渲染结果;在光照渲染阶段,GPU基于该几何渲染结果和光源信息,进行光照计算和处理,得到光照渲染结果,最终完成对虚拟场景的渲染。
TBR渲染模式下,GPU根据片上内存(tile memory)的大小将场景画面划分成若干个切片(tile),通过对每一个切片分别进行几何渲染和光照渲染处理,得到每一个切片对应的光照渲染结果,进而将最终的光照渲染结果进行拼接,从而完成对整个场景的渲染。
相关技术中,对每一个切片进行几何渲染之后,会将存储几何渲染结果的几何缓冲区写入主内存中,在光照渲染阶段需要从主内存中重新读取该几何缓冲区中的几何渲染结果并进行光照渲染。由于主内存中存储了大量的数据,且传输速度慢,因此,在渲染过程中,GPU需要不断与主内存之间进行几何缓冲区的写入与读取,增加了带宽消耗,导致更多的电量消耗。
示意性的,如图1所示,相关技术中,GPU从主内存中读取虚拟场景的几何信息(Geometry Data)101放置在片上内存中,并从片上内存中读取几何信息101进行几何渲染处理,进而将几何渲染结果写入片上内存中的几何缓冲区102,并将几何缓冲区102同时写入主内存中。
在进行光照渲染处理时,GPU从主内存中读取几何缓冲区102到片上内存中,通过对片上内存中几何缓冲区102的几何渲染结果进行光照渲染处理得到光照渲染结果103,并将该光照渲染结果103写入片上内存中,最终将该光照渲染结果103写入主内存中。
为了减少虚拟场景渲染过程中的带宽消耗,本申请实施例中,GPU将几何渲染结果写入片上内存后不再写入主内存,在光照渲染阶段利用扩展特性直接从片上内存中读取几何渲染结果进行光照渲染。在渲染过程中,通过GPU和片上内存交互完成对每一个切片的渲染,而没有中途将几何渲染结果写入主内存中,避免频繁与主内存进行写入和读取操作所带来的带宽消耗,有助于提高渲染的效率,并降低了渲染过程中的功耗。
需要说明的是,本申请实施例提供的方案可以应用于支持虚拟环境的应用程序,比如支持虚拟环境的游戏应用程序、虚拟现实(Virtual Reality,VR)应用程序、增强现实(Augmented Reality,AR)应用程序等等,本申请实施例并不对具体的应用场景进行限定。
此外,本申请实施例提供的方案可以由移动平台的计算机设备执行(比如智能手机、平板电脑、个人便携式计算机等等),该计算机设备中设置有GPU,且该计算机设备运行有具有虚拟环境渲染需求的应用程序。由于在渲染包含复杂光照的虚拟环境时,能够降低渲染过程中的带宽消耗,因此有助于提高设备续航。
请参考图2,其示出了本申请一个示例性实施例提供的虚拟场景的渲染方法的流程图。该方法可以包括如下步骤:
步骤201,在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果。
由于虚拟场景中各个虚拟物体都是以三维模型的形式呈现,因此在几何渲染阶段,GPU需要对虚拟场景中各个虚拟物体的三维模型对应的几何信息进行处理,通过几何渲染阶段的绘制,将各个虚拟物体的几何信息从三维空间变换到屏幕空间,得到屏幕空间对应的几何渲染结果。
可选的,几何渲染结果可以包括虚拟场景中虚拟物体的颜色信息、法线信息、环境遮挡信息、反射信息等能够表征虚拟物体状态的信息,本申请实施例对此并不作限定。
在一种可能的实施方式中,几何渲染处理可以包括顶点着色、坐标变换、生成图元、投影、裁剪、屏幕映射等流程,GPU通过对虚拟场景中各个虚拟物体进行几何渲染处理,得到虚拟场景中各个虚拟物体对应的几何渲染结果。
示意性的,如图3所示,在几何渲染阶段,GPU读取虚拟场景对应的几何信息301,并基于该几何信息301,对虚拟场景进行几何渲染处理,从而得到几何渲染结果302。
步骤202,将几何渲染结果写入片上内存,片上内存为设置在GPU中的内存,且几何渲染结果不写入主内存。
可选的,片上内存为设置在GPU中的内存,是一种高速缓存,具有速度快、容量小、消耗低的特点。而主内存(也被成为系统内存)容量大、传输速度慢,且对主内存进行数据的读取与写入需要消耗大量的带宽。
由于片上内存的容量较小,因此在一些实施例中,在TBR渲染渲染模式处于启用状态的情况下,GPU将几何渲染结果写入片上内存。若未开启TBR渲染模式,则首先需要开启TBR渲染模式。
在TBR渲染模式下,GPU根据片上内存的大小,将虚拟场景画面划分为若干个切片,并分别对各个切片进行渲染处理,从而能够实现利用片上内存完成渲染数据的写入与读取,提高了渲染的效率。
在一种可能的实施方式中,GPU将几何渲染结果写入片上内存,且在所有渲染阶段完成之前,几何渲染结果不写入主内存,GPU仅在片上内存中进行渲染数据的写入与读取。
示意性的,如图3所示,GPU将生成的几何渲染结果302写入片上内存,而不写入主内存。
步骤203,在光照渲染阶段,基于扩展特性,从片上内存中读取几何渲染结果,扩展特性用于扩展GPU从片上内存中读取数据的方式。
由于几何渲染结果仅写入片上内存,而没有写入主内存,因此GPU需要利用扩展特性,从片上内存中读取几何渲染结果。其中,扩展特性用于扩展GPU从片上内存中读取数据的
方式(无需经过主内存),本申请实施例中,该扩展特性用于扩展GPU从片上内存中读取几何渲染结果,而不需要经过主内存的方式。
可选的,该扩展特性用于允许片段着色器直接访问片上内存。
在一些实施例中,该扩展特性为帧缓冲获取(framebuffer fetch)扩展特性。
在一种可能的实施方式中,基于扩展特性,GPU直接从片上内存中读取几何渲染结果,包括虚拟场景中虚拟物体的颜色信息、法线信息、环境遮挡信息、反射信息等。
示意性的,如图3所示,GPU基于扩展特性,直接从片上内存中读取几何渲染阶段得到的几何渲染结果302。
步骤204,基于光源信息以及几何渲染结果进行光照渲染,得到光照渲染结果。
由于虚拟场景中大多存在多光源照射,同一个虚拟物体存在多个光源进行照射,同一光源也同时照射多个虚拟物体,因此为了表现对虚拟场景中各个虚拟物体的光照情况,GPU基于不同光源信息以及几何渲染结果进行光照渲染,从而得到光照渲染结果。
可选的,光源信息可以按照光源类型进行划分,对不同类型的光源采用不同的绘制形式。
示意性的,如图3所示,GPU基于光源信息304以及几何渲染结果302进行光照渲染,得到光照渲染结果303。
步骤205,将光照渲染结果写入片上内存。
进一步的,GPU将光照渲染结果写入片上内存,从而完成对虚拟场景中一个切片的渲染。对于虚拟场景画面对应的各个切片,计算机设备重复执行上述步骤,直至各个切片均完成渲染。
示意性的,如图3所示,GPU将光照渲染结果303写入片上内存。
综上所述,本申请实施例中,GPU将在几何渲染阶段得到的几何渲染结果写入GPU的片上内存,而不写入主内存,并在光照渲染阶段,基于扩展特性从片上内存中读取几何渲染结果,从而结合光源信息进行光照渲染,并将光照渲染结果写入片上内存。采用本申请实施例提供的方案,GPU能够利用扩展特性在光照渲染阶段直接从片上内存中读取该几何渲染结果,免去了将几何渲染结果写入主内存,再从主内存中读取的环节,降低了虚拟环境渲染过程中的带宽消耗。
在一种可能的实施方式中,GPU利用顶点着色器(vertex shader)和片段着色器(fragment shader)分别在几何渲染阶段和光照渲染阶段进行渲染,并在片上内存的几何缓冲区内创建渲染纹理(Render Texture),通过将几何渲染结果存储在渲染纹理中,实现对几何渲染结果的读取。下面通过具体的实施例对此进行详细说明。
请参考图4,其示出了本申请另一个示例性实施例提供的虚拟场景的渲染方法的流程图。该方法可以包括如下步骤:
步骤401,在几何渲染阶段,创建n张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,渲染纹理位于片上内存的几何缓冲区。
为了能够对不同类型的渲染结果进行存储,GPU创建n张渲染纹理,将不同类型的渲染结果对应存储在不同的渲染纹理中,n为大于或等于2的整数。
并且,为了避免几何渲染与光照渲染阶段发生渲染纹理切换,本申请实施例中,GPU创建的n张渲染纹理除了用于存储几何渲染阶段的几何渲染结果外,还用于存储光照渲染阶段的光照渲染结果,即几何渲染和光照渲染均在创建的渲染纹理的基础上完成。
在一种可能的实施方式中,几何渲染和光照渲染的结果可以存储在不同的渲染纹理中。
示意性的,如图5所示,GPU创建5张渲染纹理(位于几何缓冲区502),其中,第一渲染纹理5021用于存储虚拟物体的颜色和环境遮挡(Ambient Occlusion,AO)信息,第二渲染纹理5022用于存储虚拟物体的法线(normal)信息,第三渲染纹理5023用于存储虚拟物体的自发光(Spontaneous light)和高光(highlights)信息,第四渲染纹理5024用于存储虚拟物体的深度(depth)信息,第五渲染纹理5025用于存储光照渲染阶段的最终渲染结果。
需要说明的是,本实施例仅以创建5张渲染纹理为例进行示意性说明,在实际应用中,渲染纹理的数量以及类型可以根据需求进行设置,本实施例并不对渲染纹理的数量以及类型构成限定。
步骤402,在几何渲染阶段,通过第一顶点着色器对虚拟场景进行顶点渲染,得到第一顶点渲染结果。
在一种可能的实施方式中,GPU首先通过第一顶点着色器确定每一个顶点的渲染信息,从而能够基于已经确定的顶点信息,对顶点进行集合、组装成点、直线以及三角形。
在一种可能的实施方式中,GPU通过第一顶点着色器对虚拟场景进行顶点渲染,其中,第一顶点着色器作用于虚拟物体的每一个顶点上,顶点除了包含位置信息,还可以包括法线、颜色等信息,GPU通过利用第一顶点着色器,能够将虚拟物体的顶点信息从模型空间变换到屏幕空间,从而得到第一顶点渲染结果。
示意性的,如图5所示,GPU读取虚拟场景的几何信息501,并通过第一顶点着色器503,对虚拟场景进行顶点渲染,得到第一顶点渲染结果。
步骤403,基于第一顶点渲染结果,通过第一片段着色器进行片段渲染,得到几何渲染结果,其中,第一片段着色器采用inout关键字定义输出变量。
进一步的,为了得到整个场景的颜色和其他属性,基于第一顶点渲染结果(以及虚拟场景的其他贴图等信息),GPU通过第一片段着色器进行片段渲染,以渲染三角形(由顶点构成)的方式,对所有的片段进行渲染,从而得到几何渲染结果。
在一种可能的实施方式中,为了保证后续光照渲染仍旧使用几何渲染阶段得到的渲染纹理,避免发生渲染纹理切换,本实施例中,第一片段着色器采用inout关键字定义输出变量,即通过inout关键字定义几何渲染结果,使几何渲染结果既作为输入又作为输出,通过inout关键字定义输出变量的方法,能够在变量发生改变时,用改变的值替换原来的值,从而实现对几何渲染结果的实时更新,并确保后续光照渲染阶段能够准确读取几何渲染阶段得到的渲染纹理。
示意性的,如图5所示,基于第一顶点渲染结果,GPU通过第一片段着色器504进行片段渲染,得到几何渲染结果。
步骤404,将几何渲染结果写入创建的渲染纹理。
根据创建的渲染纹理对应的不同类型,GPU将几何渲染结果写入对应的渲染纹理。
在一种可能的实施方式中,渲染纹理位于片上内存的几何缓冲区,该几何缓冲区可以存储虚拟场景中各个虚拟物体相关的信息,用于满足后续光照渲染阶段计算需求。
在一种可能的实施方式中,GPU将几何渲染结果写入第1至第n-1张渲染纹理,第1至第n-1张渲染纹理对应几何渲染阶段不同类型的渲染结果,第n张渲染纹理用于存储光照渲染阶段的最终渲染结果。
示意性的,如图5所示,片上内存的几何缓冲区502中有五张渲染纹理,GPU将几何渲染阶段得到的虚拟物体的颜色和环境遮挡信息写入第一渲染纹理5021,将虚拟物体的法线信息写入第二渲染纹理5022,将虚拟物体的自发光和高光信息写入第三渲染纹理5023,将虚拟物体的深度信息写入第四渲染纹理5024。
步骤405,在光照渲染阶段,基于第一扩展特性,从渲染纹理中读取几何渲染结果,第一扩展特性用于扩展GPU从片上内存的几何缓冲区中读取数据的方式。
在一种可能的实施方式中,在光照渲染阶段,GPU基于第一扩展特性,从各个渲染纹理中读取对应的几何渲染结果,其中,该第一扩展特性用于扩展GPU从片上内存的几何缓冲区中读取数据的方式,本申请实施例中,该第一扩展特性用于扩展GPU从片上内存的几何缓冲区中读取渲染纹理中的几何渲染结果,且读取的渲染纹理为几何渲染阶段存储几何渲染结果的渲染纹理。
在一个示意性的例子中,第一扩展特性为移动平台GPU OpenGLES GL_EXT_shader_framebuffer_fetch扩展特性。
步骤406,通过第二顶点着色器对光源信息所表征的光源包围体进行顶点渲染,得到第二顶点渲染结果。
由于多光源虚拟场景中,光源种类复杂,有影响整个场景的直接光,需要逐像素的进行光照计算;也有只影响一部分区域的局部光源,只影响到屏幕上的某些像素,而不需要逐像素的进行光照计算,因此,GPU根据不同的光源信息绘制对应的光源包围体,该包围体的大小大于等于光源的衰减范围。
可选的,不同类型的光源对应不同形态的光源包围体。比如,直接光照使用全屏幕的四边形包围体,点光源使用球包围体,聚光灯使用圆锥包围体。
进一步的,GPU通过第二顶点着色器对光源信息所表征的光源包围体进行顶点渲染,将光源包围体的顶点变换投影到屏幕上的对应区域,从而得到第二顶点渲染结果。
示意性的,如图5所示,GPU通过第二顶点着色器505对光源信息所表征的光源包围体进行顶点渲染,得到第二顶点渲染结果。
步骤407,基于第二顶点渲染结果以及几何渲染结果,通过第二片段着色器进行光照渲染,得到光照渲染结果,其中,第二片段着色器采用inout关键字定义输入变量。
与几何渲染阶段中第二片段着色器采用inout关键字定义输出变量相对应的,为了能够基于扩展特性读取几何渲染结果,并在光照渲染阶段使用该几何渲染结果,第二片段着色器采用inout关键字定义输入变量的方式,获取几何渲染阶段得到的几何渲染结果(即渲染纹理),并基于第二顶点渲染结果,使用光照方程对几何渲染结果进行计算,从而得到光照渲染结果。
在一个示意性的例子中,GPU使用光照方程对颜色和环境遮挡信息、法线信息、自发光和高光信息进行计算,得到光照渲染结果。
示意性的,如图5所示,基于第二顶点渲染结果以及几何渲染结果,GPU通过第二片段着色器506进行光照渲染,得到光照渲染结果。
步骤408,将光照渲染结果写入渲染纹理。
进一步的,GPU将光照渲染结果写入第n张渲染纹理。
示意性的,如图5所示,GPU将光照渲染结果写入几何缓冲区502中的第五渲染纹理5025。
步骤409,将片上内存中存储的光照渲染结果写入主内存。
进一步的,GPU将片上内存中存储的光照渲染结果写入主内存中,从而完成对一个切片的渲染。当需要对下一切片进行渲染时,GPU即将片上内存中存储的渲染结果清除,开始对下一个切片进行渲染,最终基于各个切片的渲染结果,实现对整个虚拟场景的渲染。
示意性的,如图5所示,GPU将片上内存中存储的当前切片的光照渲染结果所在第五渲染纹理5025写入主内存。
本申请实施例中,GPU通过在片上内存的几何缓冲区中创建用于存储几何渲染结果的渲染纹理,并该该几何缓冲区内创建用于存储光照渲染结果的渲染纹理,保证在几何渲染阶段和光照渲染阶段不发生渲染纹理的切换,且仅将最终的光照渲染结果写入主内存,减少了内存的占用;同时基于第一扩展特性,能够从渲染纹理中读取几何渲染结果,整个渲染阶段仅和片上内存进行数据交互,提高了渲染的效率,同时降低了带宽消耗。
此外,通过使用inout定义输入输出变量,使片段着色器能够在读取渲染纹理时,直接使用扩展特性从片上内存读取数据,保证光照渲染阶段对对应几何渲染阶段的结果进行进一步渲染,保证渲染过程的准确性。
在另一种可能的实施方式中,光照渲染可以和几何渲染复用复用同一渲染纹理。由于在光照渲染结束之后,渲染纹理中存储的几何渲染结果不再需要,因此,在光照渲染阶段,GPU通过第二片段着色器进行光照渲染之后,可以将得到的光照渲染结果直接覆盖存储在其中的任一张渲染纹理中。通过减少创建存储光照渲染结果的渲染纹理,可以进一步降低片
上内存的占用。
示意性的,如图6所示,GPU在几何缓冲区601中仅创建4张渲染纹理,其中,第一渲染纹理6011用于存储虚拟物体的颜色和环境遮挡信息,第二渲染纹理6012用于存储虚拟物体的法线信息,第三渲染纹理6013用于存储虚拟物体的自发光和高光信息,第四渲染纹理6014用于存储虚拟物体的深度信息。在通过第二片段着色器602进行光照渲染,得到光照渲染结果之后,GPU直接用光照渲染结果覆盖第一渲染纹理6011中的颜色和环境遮挡信息,进一步的,GPU将存储有光照渲染结果的第一渲染纹理6011写入主内存中。
在一种可能的实施方式中,几何渲染结果不需要全部存储在渲染纹理中,GPU可以将部分几何渲染结果存储在渲染纹理中,其余部分直接存储在片上内存中,从而免除了创建额外渲染纹理所占用的内存,相应的,对于不同存储方式的几何渲染结果,在光照渲染阶段,GPU采用不同的方式获取,下面通过示例性的实施例对此进行说明。
请参考图7,其示出了本申请另一个示例性实施例提供的虚拟场景的渲染方法的流程图。该方法可以包括如下步骤:
步骤701,在几何渲染阶段,创建m张渲染纹理,渲染纹理位于片上内存的几何缓冲区,且不同渲染纹理用于存储不同类型的渲染结果,m为大于或等于2的整数。
为了能够对根据不同类型的渲染结果进行区分存储,GPU创建m张渲染纹理,将不同类型的渲染结果对应存储在不同的渲染纹理中。
由于本申请实施例中,GPU根据第二扩展特性对能够获取的渲染结果信息直接从片上内存中获取,而不再另外创建对应的渲染纹理,因此,m小于n。可选的,m与n差值为1,m等于n-1。
示意性的,如图8所示,GPU创建4张渲染纹理,其中,第一渲染纹理8021用于存储虚拟物体的颜色和环境遮挡信息,第二渲染纹理8022用于存储虚拟物体的法线信息,第三渲染纹理8023用于存储虚拟物体的自发光和高光信息,第四渲染纹理8024用于存储光照渲染阶段的最终渲染结果。
步骤702,在几何渲染阶段,通过第一顶点着色器对虚拟场景进行顶点渲染,得到第一顶点渲染结果。
步骤703,基于第一顶点渲染结果,通过第一片段着色器进行片段渲染,得到几何渲染结果,其中,第一片段着色器采用inout关键字定义输出变量。
步骤702和步骤703的实施方式可以参考上述步骤402和403,本实施例在此不作赘述。
步骤704,将几何渲染结果中的第一渲染结果写入创建的渲染纹理。
在一种可能的实施方式中,GPU将几何渲染结果中经过inout关键字定义的第一渲染结果,写入创建的渲染纹理中,其中,渲染纹理位于片上内存的几何缓冲区,该片上内存为tile内存。
在一种可能的实施方式中,第一渲染结果包括除深度信息以外的渲染信息,可以是颜色信息、法线信息、自发光信息等。
在一种可能的实施方式中,GPU将几何渲染结果中的第一渲染结果写入第1至第m-1张渲染纹理,其中,第1至第m-1张渲染纹理对应不同类型的渲染结果,第m张渲染纹理用于存储光照渲染阶段的最终渲染结果。
示意性的,如图8所示,片上内存的几何缓冲区802中有四张渲染纹理,GPU将几何渲染阶段得到的虚拟物体的颜色和环境遮挡信息写入第一渲染纹理8021,将虚拟物体的法线信息写入第二渲染纹理8022,将虚拟物体的自发光和高光信息写入第三渲染纹理8023。
步骤705,将几何渲染结果中的第二渲染结果写入片上内存中渲染纹理以外的区域。
在一种可能的实施方式中,GPU将几何渲染结果中的第二渲染结果直接写入片上内存中渲染纹理以外的区域,无需为第二渲染结果创建对应的渲染纹理进行存储,从而减少了片上内存的占用。
为了保证能够第二渲染结果后续能够被正常读取,第二渲染结果对应的渲染类型需要支持通过扩展特性直接从片上内存读取。
在一种可能的实施方式中,第二渲染结果包括深度信息。当然,除了深度信息以外,第二渲染结果也可以包括其他类型支持通过扩展特性直接从片上内存读取的信息,本申请实施例并不对此进行限定。
示意性的,如图8所示,GPU将结合渲染得到的深度信息801写入片上内存中渲染纹理以外的区域。
步骤706,在光照渲染阶段,基于扩展特性,从渲染纹理中读取第一渲染结果,以及从片上内存中读取第二渲染结果。
由于第一渲染结果和第二渲染结果存储在片上内存的不同位置,因此在光照渲染阶段,GPU基于不同的扩展特性,分别从渲染纹理和片上内存中读取第一渲染结果和第二渲染结果。
在一种可能的实施方式中,基于第一扩展特性,GPU从渲染纹理中读取第一渲染结果,第一扩展特性用于扩展GPU从片上内存的几何缓冲区中读取数据的方式。
对于存储在几何缓冲区渲染纹理中的第一渲染结果,GPU通过第一扩展特性从渲染纹理中读取,该第一扩展特性用于扩展GPU从片上内存的几何缓冲区读取数据的方式。
在一个示意性的例子中,第一扩展特性为移动平台GPU OpenGLES GL_EXT_shader_framebuffer_fetch扩展特性,在使用inout关键字定义几何渲染结果,且使用几何渲染阶段创建的渲染纹理的情况下(即未发生渲染纹理切换),GPU能够基于该第一扩展特性直接从片上内存的几何缓冲区读取第一渲染结果。
在一种可能的实施方式中,基于第二扩展特性,GPU从片上内存中读取第二渲染结果,第二扩展特性用于扩展GPU从片上内存中读取深度信息的方式。
对于直接存储在片上内存中渲染纹理以外区域的第二渲染结果,GPU通过第二扩展特性从片上内存中直接读取,该第二扩展特性用于扩展GPU从片上内存中读取深度信息的方式。
在一个示意性的例子中,第二扩展特性为移动平台GPU OpenGLES GL_ARM_shader_framebuffer_fetch_depth_stencil扩展特性,通过使用该第二扩展特性,GPU能够直接从片上内存中的内置变量gl_LastFragDepthARM中读取深度信息。
步骤707,通过第二顶点着色器对光源信息所表征的光源包围体进行顶点渲染,得到第二顶点渲染结果。
步骤708,基于第二顶点渲染结果以及几何渲染结果,通过第二片段着色器进行光照渲染,得到光照渲染结果,其中,第二片段着色器采用inout关键字定义输入变量。
步骤707和步骤708的实施方式可以参考上述步骤406和407,本实施例在此不作赘述。
步骤709,将光照渲染结果写入渲染纹理。
进一步的,GPU将光照渲染结果写入第m张渲染纹理,该第m张渲染纹理位于片上内存中的几何缓冲区内。
示意性的,如图8所示,GPU将光照渲染结果写入第四渲染纹理8024,该第四渲染纹理8024位于片上内存中的几何缓冲区802内。
步骤710,将片上内存中存储的光照渲染结果写入主内存。
本步骤的实施方式可以参考上述步骤409,本实施例在此不作赘述。
本申请实施例中,GPU通过第二扩展特性直接从片上内存中读取深度信息,避免了为深度信息创建对应的渲染纹理,既能够保证深度信息被正确读取,又能够减少片上内存的占用。
在一种可能的实施方式中,为减少片上内存的占用,在光照渲染阶段,GPU通过第二片段着色器进行光照渲染之后,采用复用渲染纹理的方式,直接将得到的光照渲染结果覆盖
存储在几何缓冲区内的任一张渲染纹理中。
示意性的,如图9所示,GPU在几何缓冲区902中仅创建3张渲染纹理,其中,第一渲染纹理9021用于存储虚拟物体的颜色和环境遮挡信息,第二渲染纹理9022用于存储虚拟物体的法线信息,第三渲染纹理9023用于存储虚拟物体的自发光和高光信息,在通过第二片段着色器901进行光照渲染,得到光照渲染结果之后,GPU直接用光照渲染结果覆盖第一渲染纹理9021中的颜色和环境遮挡信息,进一步的,GPU将存储有光照渲染结果的第一渲染纹理9021写入主内存中。
请参考图10,其示出了本申请一个示例性实施例提供的基于扩展特性实现多光源渲染的流程图。
步骤1001,创建渲染纹理。
GPU创建四张渲染纹理,其中,第一张渲染纹理用于存储虚拟物体的颜色和环境遮挡信息,第二张渲染纹理用于存储虚拟物体的法线信息,第三张渲染纹理用于存储虚拟物体的自发光和高光信息,第四张渲染纹理用于存储光照渲染阶段的最终渲染结果。
步骤1002,绘制虚拟场景中的物体。
GPU对虚拟场景中的虚拟物体进行绘制,根据绘制得到的几何信息,进行几何渲染,得到几何渲染结果,包括颜色、环境遮挡、法线、自发光和高光信息。
步骤1003,将颜色、环境遮挡、法线、自发光和高光信息写入渲染纹理。
GPU将颜色、环境遮挡、法线、自发光和高光信息写入对应的渲染纹理中,渲染纹理位于tile内存的几何缓冲区内。
步骤1004,将深度信息写入tile内存中。
基于第二扩展特性,GPU将深度信息直接写入tile内存中,第二扩展特性为移动平台GPU OpenGLES GL_ARM_shader_framebuffer_fetch_depth_stencil扩展特性。
步骤1005,绘制场景中所有光源的对应包围体。
根据场景中光源的不同类型,GPU对场景中所有光源绘制对应的包围体,并通过第二顶点着色器对光源包围体进行顶点渲染,得到第二顶点渲染结果。
步骤1006,从渲染纹理中读取颜色、环境遮挡、法线、自发光和高光信息。
基于第一扩展特性,GPU从渲染纹理中读取颜色、环境遮挡、法线、自发光和高光信息,第一扩展特性为移动平台GPU OpenGLES GL_EXT_shader_framebuffer_fetch扩展特性。
步骤1007,从tile内存中读取深度信息。
基于第二扩展特性,GPU从tile内存中的内置变量gl_LastFragDepthARM中读取深度信息。
步骤1008,使用光照方程计算得到光照渲染结果。
基于几何渲染结果和第二顶点渲染结果,GPU使用光照方程计算得到光照渲染结果。
请参考图11,其示出了本申请一个示例性实施例提供的虚拟场景的渲染装置的结构框图,该装置可以包括如下结构:
几何渲染模块1101,用于在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果;将所述几何渲染结果写入片上内存,所述片上内存为设置在GPU中的内存,且所述几何渲染结果不写入主内存;
光照渲染模块1102,用于在光照渲染阶段,基于扩展特性,从所述片上内存中读取所述几何渲染结果,所述扩展特性用于扩展GPU从所述片上内存中读取数据的方式;基于光源信息以及所述几何渲染结果进行光照渲染,得到光照渲染结果;将所述光照渲染结果写入所述片上内存。
可选的,所述几何渲染模块1101,用于:
将所述几何渲染结果写入创建的渲染纹理,所述渲染纹理位于所述片上内存的几何缓冲
区;
所述光照渲染模块1102,用于:
基于第一扩展特性,从所述渲染纹理中读取所述几何渲染结果,所述第一扩展特性用于扩展GPU从所述片上内存的所述几何缓冲区中读取数据的方式;
所述光照渲染模块1102,还用于:
将所述光照渲染结果写入所述渲染纹理。
可选的,
几何渲染模块1101,用于在几何渲染阶段,创建n张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,n为大于或等于2的整数;
所述几何渲染模块1101,还用于:
将所述几何渲染结果写入第1至第n-1张渲染纹理;
所述光照渲染模块1102,还用于:
将所述光照渲染结果写入第n张渲染纹理。
可选的,所述几何渲染模块1101,用于:
将所述几何渲染结果中的第一渲染结果写入创建的渲染纹理,所述渲染纹理位于所述片上内存的几何缓冲区;
将所述几何渲染结果中的第二渲染结果写入所述片上内存中所述渲染纹理以外的区域;
所述光照渲染模块1102,用于:
基于所述扩展特性,从所述渲染纹理中读取所述第一渲染结果,以及从所述片上内存中读取所述第二渲染结果;
所述光照渲染模块1102,还用于:
将所述光照渲染结果写入所述渲染纹理。
可选的,所述第二渲染结果包括深度信息,所述第一渲染结果包括除所述深度信息以外的渲染信息。
可选的,所述光照渲染模块1102,用于:
基于第一扩展特性,从所述渲染纹理中读取所述第一渲染结果,所述第一扩展特性用于扩展GPU从所述片上内存的所述几何缓冲区中读取数据的方式;
基于第二扩展特性,从所述片上内存中读取所述第二渲染结果,所述第二扩展特性用于扩展GPU从所述片上内存中读取所述深度信息的方式。
可选的,
几何渲染模块1101,还用于在几何渲染阶段,创建m张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,m为大于或等于2的整数;
所述几何渲染模块1101,还用于:
将所述几何渲染结果中的所述第一渲染结果写入第1至第m-1张渲染纹理;
所述光照渲染模块1102,还用于:
将所述光照渲染结果写入第m张渲染纹理。
可选的,所述几何渲染模块1101,用于:
通过第一顶点着色器对所述虚拟场景进行顶点渲染,得到第一顶点渲染结果;
基于所述第一顶点渲染结果,通过第一片段着色器进行片段渲染,得到所述几何渲染结果,其中,所述第一片段着色器采用inout关键字定义输出变量;
所述光照渲染模块1102,用于:
通过第二顶点着色器对所述光源信息所表征的光源包围体进行顶点渲染,得到第二顶点渲染结果;
基于所述第二顶点渲染结果以及所述几何渲染结果,通过第二片段着色器进行光照渲染,得到所述光照渲染结果,其中,所述第二片段着色器采用inout关键字定义输入变量。
可选的,所述装置还包括:
结果写入模块,用于将所述片上内存中存储的所述光照渲染结果写入所述主内存。
可选的,所述GPU为移动平台GPU,所述片上内存为tile内存。
综上所述,本申请实施例中,GPU将在几何渲染阶段得到的几何渲染结果写入GPU的片上内存,而不写入主内存,并在光照渲染阶段,基于扩展特性从片上内存中读取几何渲染结果,从而结合光源信息进行光照渲染,并将光照渲染结果写入片上内存。采用本申请实施例提供的方案,GPU能够利用扩展特性在光照渲染阶段直接从片上内存中读取该几何渲染结果,免去了将几何渲染结果写入主内存,再从主内存中读取的环节,降低了虚拟环境渲染过程中的带宽消耗。
需要说明的是:上述实施例提供的装置,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的装置与方法实施例属于同一构思,其实现过程详见方法实施例,这里不再赘述。
请参考图12,其示出了本申请一个示例性实施例提供的计算机设备的结构示意图。具体来讲:所述计算机设备1200包括处理器1201、包括随机存取存储器1202和只读存储器1203的系统存储器1204,以及连接系统存储器1204和中央处理单元1201的系统总线1205。所述计算机设备1200还包括帮助计算机内的各个器件之间传输信息的基本输入/输出系统(Input/Output,I/O系统)1206,和用于存储操作系统1213、应用程序1214和其他程序模块1215的大容量存储设备1207。
所述处理器1201包括中央处理单元(Central Processing Unit,CPU)1216和图形处理器(Graphic Processing Unit,GPU)1217,其中,所述图形处理器1217中设置有Tile内存,所述图形处理器用于实现本申请实施例中虚拟场景的渲染方法。
所述基本输入/输出系统1206包括有用于显示信息的显示器1208和用于用户输入信息的诸如鼠标、键盘之类的输入设备1209。其中所述显示器1208和输入设备1209都通过连接到系统总线1205的输入输出控制器1210连接到处理器1201。所述基本输入/输出系统1206还可以包括输入输出控制器1210以用于接收和处理来自键盘、鼠标、或电子触控笔等多个其他设备的输入。类似地,输入输出控制器1210还提供输出到显示屏、打印机或其他类型的输出设备。
所述大容量存储设备1207通过连接到系统总线1205的大容量存储控制器(未示出)连接到处理器1201。所述大容量存储设备1207及其相关联的计算机可读介质为计算机设备1200提供非易失性存储。也就是说,所述大容量存储设备1207可以包括诸如硬盘或者驱动器之类的计算机可读介质(未示出)。
不失一般性,所述计算机可读介质可以包括计算机存储介质和通信介质。计算机存储介质包括以用于存储诸如计算机可读指令、数据结构、程序模块或其他数据等信息的任何方法或技术实现的易失性和非易失性、可移动和不可移动介质。计算机存储介质包括随机存取记忆体(RAM,Random Access Memory)、只读存储器(ROM,Read Only Memory)、闪存或其他固态存储其技术,只读光盘(Compact Disc Read-Only Memory,CD-ROM)、数字通用光盘(Digital Versatile Disc,DVD)或其他光学存储、磁带盒、磁带、磁盘存储或其他磁性存储设备。当然,本领域技术人员可知所述计算机存储介质不局限于上述几种。上述的系统存储器1204和大容量存储设备1207可以统称为存储器。
存储器存储有一个或多个程序,一个或多个程序被配置成由一个或多个处理器1201执行,一个或多个程序包含用于实现上述方法的指令,处理器1201执行该一个或多个程序实现上述各个方法实施例提供的方法。
根据本申请的各种实施例,所述计算机设备1200还可以通过诸如因特网等网络连接到网络上的远程计算机运行。也即计算机设备1200可以通过连接在所述系统总线1205上的网
络接口单元1211连接到网络1212,或者说,也可以使用网络接口单元1211来连接到其他类型的网络或远程计算机系统(未示出)。
本申请实施例还提供一种计算机可读存储介质,该可读存储介质中存储有至少一条指令,至少一条指令由处理器加载并执行以实现上述实施例提供的虚拟场景的渲染方法。
本申请实施例提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行上述实施例所述的虚拟场景的渲染方法。
以上所述仅为本申请的可选的实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。
Claims (22)
- 一种虚拟场景的渲染方法,所述方法由计算机设备执行,所述方法包括:在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果;将所述几何渲染结果写入片上内存,所述片上内存为设置在GPU中的内存,且所述几何渲染结果不写入主内存;在光照渲染阶段,基于扩展特性,从所述片上内存中读取所述几何渲染结果,所述扩展特性用于扩展GPU从所述片上内存中读取数据的方式;基于光源信息以及所述几何渲染结果进行光照渲染,得到光照渲染结果;将所述光照渲染结果写入所述片上内存。
- 根据权利要求1所述的方法,其中,所述将所述几何渲染结果写入片上内存,包括:将所述几何渲染结果写入创建的渲染纹理,所述渲染纹理位于所述片上内存的几何缓冲区;所述基于扩展特性,从所述片上内存中读取所述几何渲染结果,包括:基于第一扩展特性,从所述渲染纹理中读取所述几何渲染结果,所述第一扩展特性用于扩展GPU从所述片上内存的所述几何缓冲区中读取数据的方式;所述将所述光照渲染结果写入所述片上内存,包括:将所述光照渲染结果写入所述渲染纹理。
- 根据权利要求2所述的方法,其中,所述方法还包括:在几何渲染阶段,创建n张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,n为大于或等于2的整数;所述将所述几何渲染结果写入创建的渲染纹理,包括:将所述几何渲染结果写入第1至第n-1张渲染纹理;所述将所述光照渲染结果写入所述渲染纹理,包括:将所述光照渲染结果写入第n张渲染纹理。
- 根据权利要求1所述的方法,其中,所述将所述几何渲染结果写入片上内存,包括:将所述几何渲染结果中的第一渲染结果写入创建的渲染纹理,所述渲染纹理位于所述片上内存的几何缓冲区;将所述几何渲染结果中的第二渲染结果写入所述片上内存中所述渲染纹理以外的区域;所述基于扩展特性,从所述片上内存中读取所述几何渲染结果,包括:基于所述扩展特性,从所述渲染纹理中读取所述第一渲染结果,以及从所述片上内存中读取所述第二渲染结果;所述将所述光照渲染结果写入所述片上内存,包括:将所述光照渲染结果写入所述渲染纹理。
- 根据权利要求4所述的方法,其中,所述第二渲染结果包括深度信息,所述第一渲染结果包括除所述深度信息以外的渲染信息。
- 根据权利要求5所述的方法,其中,所述基于所述扩展特性,从所述渲染纹理中读取所述第一渲染结果,以及从所述片上内存中读取所述第二渲染结果,包括:基于第一扩展特性,从所述渲染纹理中读取所述第一渲染结果,所述第一扩展特性用于扩展GPU从所述片上内存的所述几何缓冲区中读取数据的方式;基于第二扩展特性,从所述片上内存中读取所述第二渲染结果,所述第二扩展特性用于扩展GPU从所述片上内存中读取所述深度信息的方式。
- 根据权利要求4所述的方法,其中,所述方法还包括:在几何渲染阶段,创建m张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,m为大于或等于2的整数;所述将所述几何渲染结果中的第一渲染结果写入创建的渲染纹理,包括:将所述几何渲染结果中的所述第一渲染结果写入第1至第m-1张渲染纹理;所述将所述光照渲染结果写入所述渲染纹理,包括:将所述光照渲染结果写入第m张渲染纹理。
- 根据权利要求1至7任一所述的方法,其中,所述对虚拟场景进行几何渲染,得到几何渲染结果,包括:通过第一顶点着色器对所述虚拟场景进行顶点渲染,得到第一顶点渲染结果;基于所述第一顶点渲染结果,通过第一片段着色器进行片段渲染,得到所述几何渲染结果,其中,所述第一片段着色器采用inout关键字定义输出变量;所述基于光源信息以及所述几何渲染结果进行光照渲染,得到光照渲染结果,包括:通过第二顶点着色器对所述光源信息所表征的光源包围体进行顶点渲染,得到第二顶点渲染结果;基于所述第二顶点渲染结果以及所述几何渲染结果,通过第二片段着色器进行光照渲染,得到所述光照渲染结果,其中,所述第二片段着色器采用inout关键字定义输入变量。
- 根据权利要求1至7任一所述的方法,其中,所述方法还包括:将所述片上内存中存储的所述光照渲染结果写入所述主内存。
- 根据权利要求1至7任一所述的方法,其中,所述GPU为移动平台GPU,所述片上内存为tile内存。
- 一种虚拟场景的渲染装置,所述装置包括:几何渲染模块,用于在几何渲染阶段,对虚拟场景进行几何渲染,得到几何渲染结果;将所述几何渲染结果写入片上内存,所述片上内存为设置在GPU中的内存,且所述几何渲染结果不写入主内存;光照渲染模块,用于在光照渲染阶段,基于扩展特性,从所述片上内存中读取所述几何渲染结果,所述扩展特性用于扩展GPU从所述片上内存中读取数据的方式;基于光源信息以及所述几何渲染结果进行光照渲染,得到光照渲染结果;将所述光照渲染结果写入所述片上内存。
- 根据权利要求11所述的装置,其中,所述几何渲染模块,用于:将所述几何渲染结果写入创建的渲染纹理,所述渲染纹理位于所述片上内存的几何缓冲区;所述光照渲染模块,用于:基于第一扩展特性,从所述渲染纹理中读取所述几何渲染结果,所述第一扩展特性用于扩展GPU从所述片上内存的所述几何缓冲区中读取数据的方式;所述光照渲染模块,还用于:将所述光照渲染结果写入所述渲染纹理。
- 根据权利要求12所述的装置,其中,所述几何渲染模块,用于:在几何渲染阶段,创建n张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,n为大于或等于1的整数;将所述几何渲染结果写入第1至第n-1张渲染纹理;所述光照渲染模块,用于:将所述光照渲染结果写入第n张渲染纹理。
- 根据权利要求11所述的装置,其中,所述几何渲染模块,用于:将所述几何渲染结果中的第一渲染结果写入创建的渲染纹理,所述渲染纹理位于所述片上内存的几何缓冲区;将所述几何渲染结果中的第二渲染结果写入所述片上内存中所述渲染纹理以外的区域;所述光照渲染模块,用于:基于所述扩展特性,从所述渲染纹理中读取所述第一渲染结果,以及从所述片上内存中读取所述第二渲染结果;将所述光照渲染结果写入所述渲染纹理。
- 根据权利要求14所述的装置,其中,所述第二渲染结果包括深度信息,所述第一渲染结果包括除所述深度信息以外的渲染信息。
- 根据权利要求15所述的装置,其中,所述光照渲染模块,用于:基于第一扩展特性,从所述渲染纹理中读取所述第一渲染结果,所述第一扩展特性用于扩展GPU从所述片上内存的所述几何缓冲区中读取数据的方式;基于第二扩展特性,从所述片上内存中读取所述第二渲染结果,所述第二扩展特性用于扩展GPU从所述片上内存中读取所述深度信息的方式。
- 根据权利要求14所述的装置,其中,所述几何渲染模块,还用于:在几何渲染阶段,创建m张渲染纹理,不同渲染纹理用于存储不同类型的渲染结果,m为大于或等于2的整数;将所述几何渲染结果中的所述第一渲染结果写入第1至第m-1张渲染纹理;所述光照渲染模块,用于:将所述光照渲染结果写入第m张渲染纹理。
- 根据权利要求11至17任一所述的装置,其中,所述几何渲染模块,用于:通过第一顶点着色器对所述虚拟场景进行顶点渲染,得到第一顶点渲染结果;基于所述第一顶点渲染结果,通过第一片段着色器进行片段渲染,得到所述几何渲染结果,其中,所述第一片段着色器采用inout关键字定义输出变量;所述光照渲染模块,用于:通过第二顶点着色器对所述光源信息所表征的光源包围体进行顶点渲染,得到第二顶点渲染结果;基于所述第二顶点渲染结果以及所述几何渲染结果,通过第二片段着色器进行光照渲染,得到所述光照渲染结果,其中,所述第二片段着色器采用inout关键字定义输入变量。
- 根据权利要求11至17任一所述的装置,其中,所述装置还包括:结果写入模块,用于将所述片上内存中存储的所述光照渲染结果写入所述主内存。
- 一种计算机设备,所述计算机设备包括处理器和存储器;所述存储器存储有至少一条指令,所述至少一条指令用于被所述处理器执行以实现如权利要求1至10任一所述的虚拟场景的渲染方法。
- 一种计算机可读存储介质,所述计算机可读存储介质中存储有至少一条程序代码,所述程序代码由处理器加载并执行以实现如权利要求1至10任一所述的虚拟场景的渲染方法。
- 一种计算机程序产品,所述计算机程序产品包括计算机指令,所述计算机指令存储在计算机可读存储介质中;计算机设备的处理器从所述计算机可读存储介质读取所述计算机指令,所述处理器执行所述计算机指令,使得所述计算机设备实现如权利要求1至10任一所述的虚拟场景的渲染方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210690977.5A CN117292034A (zh) | 2022-06-17 | 2022-06-17 | 虚拟场景的渲染方法、装置、设备及存储介质 |
CN202210690977.5 | 2022-06-17 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023241210A1 true WO2023241210A1 (zh) | 2023-12-21 |
Family
ID=89192143
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2023/088979 WO2023241210A1 (zh) | 2022-06-17 | 2023-04-18 | 虚拟场景的渲染方法、装置、设备及存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN117292034A (zh) |
WO (1) | WO2023241210A1 (zh) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112233217A (zh) * | 2020-12-18 | 2021-01-15 | 完美世界(北京)软件科技发展有限公司 | 一种虚拟场景的渲染方法和装置 |
CN112288841A (zh) * | 2020-12-18 | 2021-01-29 | 完美世界(北京)软件科技发展有限公司 | 一种渲染框架图的创建方法和装置 |
WO2021158449A1 (en) * | 2020-02-03 | 2021-08-12 | Sony Interactive Entertainment Inc. | System and method for efficient multi-gpu rendering of geometry by region testing while rendering |
CN114419234A (zh) * | 2021-12-30 | 2022-04-29 | 北京三快在线科技有限公司 | 三维场景渲染方法、装置、电子设备及存储介质 |
CN114581596A (zh) * | 2022-02-25 | 2022-06-03 | 北京构力科技有限公司 | 基于图形处理单元gpu驱动的几何形体快速渲染的方法 |
-
2022
- 2022-06-17 CN CN202210690977.5A patent/CN117292034A/zh active Pending
-
2023
- 2023-04-18 WO PCT/CN2023/088979 patent/WO2023241210A1/zh unknown
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2021158449A1 (en) * | 2020-02-03 | 2021-08-12 | Sony Interactive Entertainment Inc. | System and method for efficient multi-gpu rendering of geometry by region testing while rendering |
CN112233217A (zh) * | 2020-12-18 | 2021-01-15 | 完美世界(北京)软件科技发展有限公司 | 一种虚拟场景的渲染方法和装置 |
CN112288841A (zh) * | 2020-12-18 | 2021-01-29 | 完美世界(北京)软件科技发展有限公司 | 一种渲染框架图的创建方法和装置 |
CN114419234A (zh) * | 2021-12-30 | 2022-04-29 | 北京三快在线科技有限公司 | 三维场景渲染方法、装置、电子设备及存储介质 |
CN114581596A (zh) * | 2022-02-25 | 2022-06-03 | 北京构力科技有限公司 | 基于图形处理单元gpu驱动的几何形体快速渲染的方法 |
Also Published As
Publication number | Publication date |
---|---|
CN117292034A (zh) | 2023-12-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20230053462A1 (en) | Image rendering method and apparatus, device, medium, and computer program product | |
US11344806B2 (en) | Method for rendering game, and method, apparatus and device for generating game resource file | |
US11232534B2 (en) | Scheme for compressing vertex shader output parameters | |
US9715750B2 (en) | System and method for layering using tile-based renderers | |
US10242481B2 (en) | Visibility-based state updates in graphical processing units | |
JP5032670B2 (ja) | グラフィックスシステムにおいて2次プロセッサを使用するための方法及びシステム | |
US8817021B1 (en) | System for writing, interpreting, and translating three-dimensional (3D) scenes | |
JP4704348B2 (ja) | 画像生成装置および画像生成方法 | |
EP3180773B1 (en) | Bandwidth reduction using texture lookup by adaptive shading | |
KR20100004119A (ko) | 포스트-렌더링 그래픽스 오버레이 | |
CN111754381B (zh) | 图形渲染方法、装置和计算机可读存储介质 | |
JP2008533628A (ja) | タイル化されたプリフェッチ及びキャッシングされたデプスバッファ | |
KR102381945B1 (ko) | 그래픽 프로세싱 장치 및 그래픽 프로세싱 장치에서 그래픽스 파이프라인을 수행하는 방법 | |
KR20140133067A (ko) | 그래픽 프로세싱 유닛, 이를 포함하는 그래픽 프로세싱 시스템, 및 이를 이용한 렌더링 방법 | |
KR20180056316A (ko) | 타일-기반 렌더링을 수행하는 방법 및 장치 | |
CN105550973B (zh) | 图形处理单元、图形处理系统及抗锯齿处理方法 | |
TWI395152B (zh) | 繪圖處理單元及處理邊框顏色資訊之方法 | |
WO2023241210A1 (zh) | 虚拟场景的渲染方法、装置、设备及存储介质 | |
JP2005332195A (ja) | テクスチャユニット、画像描画装置、テクセル転送方法 | |
CN118043842A (zh) | 一种渲染格式选择方法及其相关设备 | |
US11869123B2 (en) | Anti-aliasing two-dimensional vector graphics using a compressed vertex buffer | |
KR20180015564A (ko) | 타일-기반 렌더링을 수행하는 방법 및 장치 | |
CN117435521B (zh) | 基于gpu渲染的纹理显存映射方法、装置及介质 | |
WO2024045701A9 (zh) | 数据处理方法、装置、设备及存储介质 | |
JP4419480B2 (ja) | 画像処理装置およびその方法 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 23822781 Country of ref document: EP Kind code of ref document: A1 |