Dynamic light source rendering method and device based on Web end
By performing clustering and fast light source division algorithms in the view space, the problem of small number of light sources and insufficient dynamic division capabilities in the Web-end 3D rendering technology is solved, and high-performance multi-light source rendering and flexible rendering pipeline switching are realized , improve rendering efficiency and performance.
Patent Information
- Application Number
- CN202411373465.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2024-12-27
AI Technical Summary
The existing 3D rendering technology is difficult to support real-time rendering of a large number of dynamic light sources on the web side. The traditional forward rendering pipeline light sources support is small, the dynamic increase and decrease consumption is high, delayed rendering does not support translucent object rendering, and does not support MSAA. Shader There are limited types, and Clustered Shading's division in the world space leads to poor universality and cannot be adjusted dynamically.
The light source is clustered in the view space, the light-encircling ball index is calculated using the fast light source division algorithm, and the light-encircling ball index is transmitted to the shader for rendering, dynamically update the view space division parameters, support the rendering of multi-light source effects, and store cluster information data through maps Improve efficiency.
Achieve high-performance rendering of a large number of light sources, avoid clustering configuration problems in different scenarios, dynamically adjust the ability of light to affect body clusters, improve light source division efficiency, reduce performance losses caused by dynamic addition and reduction of light sources, and support more Number of light sources and more flexible rendering pipeline switching.
Smart Images

Figure CN119206031A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of 3D rendering technology, and in particular to a method and device for rendering dynamic light sources based on a Web terminal. Background Art
[0002] In 3D scenes, abundant light sources can greatly improve the rendering effect of the scene, especially the night scene effect; in addition, in digital twin projects, a large number of light sources are also more conducive to the intuitive display of visual effects such as lighting and marking. However, most engines (Web side) use the traditional forward rendering pipeline, which does not support real-time rendering of a large number of lights; a small number of engines use the traditional deferred rendering pipeline, which supports the rendering of a large number of lights, but has many limitations; some engines use the Clustered Shading technology in world space to transform the traditional forward rendering pipeline and gain the ability to render a large number of light sources, but because the light source space is divided in world space, the division parameters are highly bound to the scene, the versatility is not strong, and the light source division will not be dynamically allocated with the camera changes, and the performance is not optimal. Summary of the invention
[0003] In view of the above problems existing in the existing 3D rendering technology, the present application provides a method and device for rendering dynamic light sources based on a Web terminal.
[0004] In a first aspect, the present application provides a method for rendering a dynamic light source based on a Web terminal, the method comprising: In the view space, clustering the light source to obtain volume clustering information and light source information data, and passing the volume clustering data, the volume clustering information and the light source information data into a shader; The multi-light source effect is rendered in the shader by using the volume cluster division information, the volume cluster data and the light source information data.
[0005] Furthermore, clustering the light sources in the view space to obtain volume clustering information and light source information data specifically includes: In the view space, according to the fast light source partitioning algorithm, the volume cluster index in the view space covered by the light bounding sphere corresponding to the light source is calculated; In the volume cluster data, according to the volume cluster index, the covered volume cluster data is found, and the light source index is written into the volume cluster data; The light source information data is obtained according to the light source index.
[0006] Further, the using the volume cluster division information, the volume cluster data and the searched light source information data to render a multi-light source effect in the shader specifically includes: Convert the position coordinates of the light source in the world coordinate system to the position in the view space; Calculate the volume cluster subscript in the volume cluster data where the position coordinates in the view space are located according to the position in the view space and the input view space volume cluster division information; Use the volume cluster index to obtain the light source index that affects the volume cluster data from the incoming volume cluster data; Use the obtained light source index to obtain the light source lighting information from the input light source information data; Perform lighting rendering based on light source information.
[0007] Furthermore, the method further comprises: According to the camera data, update the parameter data on which the view space division depends; Calculate the light bounding sphere and transform it into the coordinate system of the view space.
[0008] Furthermore, the converting the position coordinates of the light source in the world coordinate system to the position in the view space specifically includes: By using the position of the light source in the world coordinate system and the view matrix of the camera, the position in the world coordinate system is applied to the view matrix to obtain the position of the light source in the view space.
[0009] Furthermore, the using the volume cluster index to obtain the light source index affecting the volume cluster data from the input volume cluster data specifically includes: According to the volume cluster index calculated in the previous step, the volume cluster index is converted into the UV coordinate of the sampled storage volume cluster data map, and the light source index of the current volume cluster affected by the light source is obtained from the volume cluster data map.
[0010] In a second aspect, the present application also provides a Web-based rendering dynamic light source device, the device comprising: A first processing module, configured to cluster the light source in the view space to obtain volume cluster division information and light source information data, and to transfer the volume cluster data, the volume cluster division information and the light source information data to a shader; The second processing module is used to render a multi-light source effect in the shader by using the volume cluster division information, the volume cluster data and the light source information data.
[0011] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, a method for rendering dynamic light sources based on a Web terminal as described in any one of the first aspects is implemented.
[0012] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for rendering dynamic light sources based on a Web terminal as described in any one of the first aspects is implemented.
[0013] The present application provides a method for rendering dynamic light sources based on the Web, including clustering the light sources in the view space to obtain cluster division information and light source information data, and passing the cluster data, the cluster division information and the light source information data into the shader; using the cluster division information, the cluster data and the light source information data to render a multi-light source effect in the shader. The present invention solves the problem of a small number of dynamic light sources supported by the traditional forward rendering pipeline. The traditional forward rendering pipeline has a high consumption for dynamically increasing and decreasing light sources. Delayed rendering has poor support for rendering of translucent objects, does not support MSAA, and has a limited number of shader types. The Clustered Shading (W) & Forward+ rendering pipeline has a high cost for switching between different scenes and does not support dynamic division of light sources as the camera changes. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:
[0015] Figure 1 is a schematic diagram of a fast light source division algorithm provided in an embodiment of the present application; Figure 2 This is a flowchart of a method for rendering dynamic light sources based on a Web terminal provided by another embodiment of the present application; Figure 3 This is a schematic diagram of a Web-based rendering dynamic light source device provided by another embodiment of the present application. DETAILED DESCRIPTION
[0016] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present invention can be combined with each other without conflict.
[0017] The following detailed description is an exemplary description, which is intended to provide further detailed description of the present invention. Unless otherwise specified, all technical terms used in the present invention have the same meaning as those generally understood by those skilled in the art to which the present invention belongs. The terms used in the present invention are only for describing specific embodiments, and are not intended to limit the exemplary embodiments according to the present invention.
[0018] Forward Rendering: Traditional forward rendering pipeline.
[0019] Deferred Rendering: Traditional deferred rendering pipeline.
[0020] Clustered Shading (V): Clustered shading divides the light source into spatial components in the view space and passes the division result to the shader, which then shades only the pixels in the space affected by the light source based on the result.
[0021] Clustered Shading (W): Clustered shading divides the light source into spaces in the world space and passes the division results to the shader. The shader shades only the pixels in the space affected by the light source based on the results. This clustering method is highly bound to scene information and does not have the ability to dynamically divide the light source as the camera changes.
[0022] Forward+: In this article, it refers to the Forward rendering pipeline that has been modified by Clustered Shading (V), which supports high-performance rendering of multiple light sources.
[0023] MSAA: Multi-sampling Anti-Aliasing.
[0024] The present invention solves the problem of the small number of dynamic light sources supported by the traditional forward rendering pipeline. It solves the problem of the high consumption of dynamically increasing and decreasing light sources in the traditional forward rendering pipeline. It solves the problem that delayed rendering does not support the rendering of semi-transparent objects well, does not support MSAA, and has a limited number of shader types. It solves the problem that the Clustered Shading (W) & Forward+ rendering pipeline has high cost for switching different scenes and does not support dynamic division of light sources with camera changes.
[0025] The core technical solution of the present invention Before rendering begins, light sources are clustered in view space. Updates the data on which the view space division (along the XYZ directions) depends, based on the camera data.
[0026] Specifically, according to the near section and far section of the camera, the a and b factors required for depth division in formula 3 are calculated. According to the projection matrix data, the fovTan and aspectFovTan parameters required by formulas 1 and 2 are calculated.
[0027] Formula 1: Formula 2: Formula 3: Calculate the bounding sphere of the light (point light, spot light) and transform the bounding sphere to view space. For point light, use the light's position and distance (the light's range) to calculate the center and radius of the bounding box, then apply the camera view matrix to the bounding sphere center to transform it to view space.
[0028] For a spotlight, the center and radius of the bounding box are calculated using the light's position, direction, distance, and light cone cosine. Then, similarly, the center of the bounding box is transformed to view space using the view matrix.
[0029] In the XYZ direction, the volume cluster index in the view space covered by the light bounding sphere is quickly calculated according to the calculation formulas shown in formulas 1, 2, and 3 respectively.
[0030] In view space, the volume cluster index in view space covered by the light bounding sphere is calculated according to the fast light source partitioning algorithm, see Figure 1 , and formulas 1, 2, and 3.
[0031] The volume cluster data is a one-dimensional array. Use the index value in the XYZ direction obtained in the previous step to find the volume cluster at the corresponding index position from the volume cluster data and write the light source index.
[0032] In the volume cluster data, find the covered volume cluster according to the index obtained in the previous step, and write the light source index. In the light source information data, write the light information according to the light index.
[0033] The light source data is a one-dimensional array. Because it is ultimately uploaded to the GPU as a map of four RGBA channels, each array element represents a channel. Four pixels are allocated to each light, that is, a light occupies 4*4 array elements. According to the light source index, the starting position of the light source in the array can be calculated according to the formula index*4*4. Starting from this position, the light source type, light source color, light source position, light source radius, light source attenuation and other information of the light are written into the array.
[0034] The volume cluster division information, volume cluster data, and light source information data are passed into the shader.
[0035] Render multiple light effects in source shaders.
[0036] Convert the world position of the source to the view space. In the fragment shader, we can get the world position of the current fragment and the camera's view matrix. Apply the view matrix to the world position to get the position of the fragment in the view space.
[0037] According to the position and the input view space volume cluster division information, the volume cluster index of the position is calculated.
[0038] The calculation here is the XYZ direction subscript of the cluster where the current fragment is located, which is based on the position of the fragment in the view space, using Figure 2 The calculation formula in is obtained.
[0039] Use this index to get the index of the light source that affects the cluster from the incoming cluster data. According to the cluster index calculated in the previous step, convert the index to the UV coordinate of the sample storage cluster data map, and get the light source index of the current cluster affected by the light source from the map.
[0040] Use the obtained light source index to obtain the light source lighting information from the passed in light source information data.
[0041] According to the light source subscript obtained in the previous step, convert the subscript into the UV coordinates of the sampled storage lighting data map, and take out the light source from the map. Perform lighting rendering based on light information.
[0042] Beneficial effects brought by the technical solution of the present invention The Clustered Shading technology is used to transform the traditional forward rendering pipeline, enabling the engine to support high-performance rendering of a large number of light sources (point lights, spotlights).
[0043] Using Clustered Shading technology in view space avoids the need to set up different clustering configurations in different scenes, and brings the ability to dynamically redistribute the volume clusters affected by lights according to changes in camera position.
[0044] A lightweight light division algorithm that is more suitable for the Web is used to improve the complexity from O(m*n) to O(n) (n is the number of lights; m is the number of clusters), which speeds up the efficiency of light division.
[0045] By transforming the traditional forward rendering pipeline, the various limitations brought by the deferred rendering pipeline are avoided.
[0046] Using maps to store cluster information data and light source information data improves information transmission efficiency, increases the number of light sources supported by the traditional forward rendering pipeline, and reduces shader recompilation performance loss caused by dynamically increasing or decreasing light sources in the scene.
[0047] The following will be combined with the attached Figure 2 , a method for rendering dynamic light sources based on a Web terminal provided in an embodiment of the present application is described, comprising the following steps: In the view space, clustering the light source to obtain volume clustering information and light source information data, and passing the volume clustering data, the volume clustering information and the light source information data into a shader; The multi-light source effect is rendered in the shader by using the volume cluster division information, the volume cluster data and the light source information data.
[0048] Furthermore, clustering the light sources in the view space to obtain volume clustering information and light source information data specifically includes: In the view space, according to the fast light source partitioning algorithm, the volume cluster index in the view space covered by the light bounding sphere corresponding to the light source is calculated; In the volume cluster data, according to the volume cluster index, the covered volume cluster data is found, and the light source index is written into the volume cluster data; The light source information data is obtained according to the light source index.
[0049] Further, the using the volume cluster division information, the volume cluster data and the searched light source information data to render a multi-light source effect in the shader specifically includes: Convert the position coordinates of the light source in the world coordinate system to the position in the view space; Calculate the volume cluster subscript in the volume cluster data where the position coordinates in the view space are located according to the position in the view space and the input view space volume cluster division information; Use the volume cluster index to obtain the light source index that affects the volume cluster data from the incoming volume cluster data; Use the obtained light source index to obtain the light source lighting information from the input light source information data; Perform lighting rendering based on light source information.
[0050] Furthermore, the method further comprises: According to the camera data, update the parameter data on which the view space division depends; Calculate the light bounding sphere and transform it into the coordinate system of the view space.
[0051] Furthermore, the converting the position coordinates of the light source in the world coordinate system to the position in the view space specifically includes: By using the position of the light source in the world coordinate system and the view matrix of the camera, the position in the world coordinate system is applied to the view matrix to obtain the position of the light source in the view space.
[0052] Furthermore, the using the volume cluster index to obtain the light source index affecting the volume cluster data from the input volume cluster data specifically includes: According to the volume cluster index calculated in the previous step, the volume cluster index is converted into the UV coordinate of the sampled storage volume cluster data map, and the light source index of the current volume cluster affected by the light source is obtained from the volume cluster data map.
[0053] The present embodiment provides a method for rendering dynamic light sources based on the Web, including clustering the light sources in the view space to obtain cluster division information and light source information data, and passing the cluster data, the cluster division information and the light source information data into the shader; using the cluster division information, the cluster data and the light source information data to render a multi-light source effect in the shader. The present invention solves the problem of a small number of dynamic light sources supported by the traditional forward rendering pipeline. The traditional forward rendering pipeline has a high consumption problem for dynamically increasing and decreasing light sources. Delayed rendering has poor support for rendering of translucent objects, does not support MSAA, and has a limited number of shader types. The Clustered Shading (W) & Forward+ rendering pipeline has a high cost for switching between different scenes and does not support dynamic division of light sources as the camera changes.
[0054] As attached Figure 3 The present application also provides a Web-based rendering dynamic light source device, the device comprising: A first processing module, configured to cluster the light source in the view space to obtain volume cluster division information and light source information data, and to transfer the volume cluster data, the volume cluster division information and the light source information data to a shader; The second processing module is used to render a multi-light source effect in the shader by using the volume cluster division information, the volume cluster data and the light source information data.
[0055] In addition, an embodiment of the present application includes a computer device, including a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, it implements a Web-based rendering dynamic light source method described in any one of the above technical solutions.
[0056] An embodiment of the present application also includes a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, a method for rendering dynamic light sources based on a Web terminal is implemented in any one of the above technical solutions.
[0057] The above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, a person skilled in the art should understand that the specific implementation modes of the present invention may still be modified or replaced by equivalents, and any modification or equivalent replacement that does not depart from the spirit and scope of the present invention shall be included in the scope of protection of the claims of the present invention.
Claims
1. A method for rendering dynamic light sources based on a Web terminal, characterized in that: The method comprises: In the view space, clustering the light source to obtain volume clustering information and light source information data, and passing the volume clustering data, the volume clustering information and the light source information data into a shader; The multi-light source effect is rendered in the shader using the volume cluster division information, the volume cluster data and the light source information data.
2. The method for rendering dynamic light source based on a Web terminal according to claim 1, characterized in that: The clustering of the light sources in the view space to obtain volume clustering information and light source information data specifically includes: In the view space, according to the fast light source partitioning algorithm, the volume cluster index in the view space covered by the light bounding sphere corresponding to the light source is calculated; In the volume cluster data, according to the volume cluster index, the covered volume cluster data is found, and the light source index is written into the volume cluster data; The light source information data is obtained according to the light source index.
3. The method for rendering dynamic light source based on a Web terminal according to claim 1, characterized in that: The rendering of the multi-light source effect in the shader by using the volume cluster division information, the volume cluster data and the searched light source information data specifically includes: Convert the position coordinates of the light source in the world coordinate system to the position in the view space; Calculate the volume cluster subscript in the volume cluster data where the position coordinates in the view space are located according to the position in the view space and the input view space volume cluster division information; Use the volume cluster index to obtain the light source index that affects the volume cluster data from the incoming volume cluster data; Use the obtained light source index to obtain the light source lighting information from the input light source information data; Perform lighting rendering based on light source information.
4. The method for rendering dynamic light source based on a Web terminal according to claim 1, characterized in that: The method further comprises: According to the camera data, update the parameter data on which the view space division depends; Calculate the light bounding sphere and transform it into the coordinate system of the view space.
5. The method for rendering dynamic light source based on a Web terminal according to claim 3, characterized in that: The converting the position coordinates of the light source in the world coordinate system to the position in the view space specifically includes: By using the position of the light source in the world coordinate system and the view matrix of the camera, the position in the world coordinate system is applied to the view matrix to obtain the position of the light source in the view space.
6. The method for rendering dynamic light source based on a Web terminal according to claim 3, characterized in that: The method of using the volume cluster index to obtain the light source index that affects the volume cluster data from the input volume cluster data specifically includes: According to the volume cluster index calculated in the previous step, the volume cluster index is converted into the UV coordinate of the sampled storage volume cluster data map, and the light source index of the current volume cluster affected by the light source is taken out from the volume cluster data map.
7. A dynamic light source rendering device based on a Web terminal, characterized in that: The device comprises: A first processing module, configured to cluster the light source in the view space to obtain volume cluster division information and light source information data, and to transfer the volume cluster data, the volume cluster division information and the light source information data to a shader; The second processing module is used to render a multi-light source effect in the shader by using the volume cluster division information, the volume cluster data and the light source information data.
8. The Web-based rendering dynamic light source device according to claim 7, characterized in that: The first processing module is used to calculate the volume cluster index in the view space covered by the light bounding sphere corresponding to the light source according to the fast light source segmentation algorithm in the view space; In the volume cluster data, according to the volume cluster index, the covered volume cluster data is found, and the light source index is written into the volume cluster data; The light source information data is obtained according to the light source index.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the method for rendering dynamic light sources based on the Web side according to any one of claims 1 to 6 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for rendering dynamic light sources based on a Web terminal as described in any one of claims 1 to 6 is implemented.
