Volume fog rendering method and device, computer equipment and storage medium
By calculating the light source cone space and the number of voxels in the three-dimensional virtual scene and using parallel threads for lighting calculation and information fusion, the problem of low lighting calculation efficiency caused by too many light sources in the three-dimensional virtual scene is solved, and the efficiency of volumetric fog rendering is improved.
Patent Information
- Application Number
- CN202410460583.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-16
- Publication Date
- 2025-10-24
AI Technical Summary
When there are a large number of light sources in a three-dimensional virtual scene, the lighting calculation for the light sources and voxels outside the actual lighting range in the prior art results in reduced lighting calculation efficiency, thereby affecting the volumetric fog rendering efficiency.
By obtaining the light source range information in the three-dimensional virtual scene, calculating the light source cone space, and determining the number of threads based on the number of voxels, the light source identification information is calculated, and parallel threads are used for lighting calculation and information fusion, the total lighting calculation task volume is reduced and the lighting and volume fog rendering efficiency is improved.
It effectively reduces the total workload of lighting calculations, improves the efficiency of lighting and volumetric fog rendering, and calculates the lighting of multiple light sources through parallel threads, avoiding the waste of resources for separate calculations of each light source and improving computing efficiency.
Smart Images

Figure CN120833434A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of three-dimensional virtual scenes, and in particular to a volume fog rendering method and device, a computer device, a storage medium, and a computer program product. BACKGROUND
[0002] With the development of three-dimensional virtual scene technology, volume fog rendering technology has emerged. Volume fog is a graphical effect used to simulate the semi-transparent and irregular properties of fog in the real world, commonly found in video games and film special effects to increase the sense of depth and realism of the scene. Volume fog simulates the scattering effect of light rays interacting with small particles in the air, such as dust, water droplets, etc., when the light rays propagate in the air. This effect causes the light rays to scatter when they encounter fog, thus creating the effect of volume fog in vision. Currently, when rendering volume fog in real time, it is necessary to calculate the lighting results of each light source with each voxel in the camera frustum space, and then perform volume fog rendering. However, when there are a large number of light sources in a three-dimensional virtual scene, there will be lighting calculations between light sources and voxels outside the actual lighting range, i.e., there are a large number of invalid calculations, which reduces the efficiency of lighting calculation, and further reduces the efficiency of volume fog real-time rendering. SUMMARY
[0003] Therefore, it is necessary to provide a volume fog rendering method, device, computer device, computer readable storage medium, and computer program product that can improve the efficiency of volume fog rendering to solve the above technical problems.
[0004] In a first aspect, the present application provides a volume fog rendering method. The method comprises:
[0005] Obtaining light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculating the projection of the light source range information in the corresponding camera frustum space of the three-dimensional virtual scene to obtain the light source frustum space corresponding to the at least two light source identifiers respectively;
[0006] Determining the number of threads corresponding to the at least two light source identifiers based on the number of voxels in the light source frustum space corresponding to the at least two light source identifiers respectively, and counting the total number of threads of the number of threads;
[0007] Performing light source identification information calculation based on the number of threads corresponding to the at least two light source identifiers to obtain light source identification information corresponding to the at least two light source identifiers respectively;
[0008] run each thread according to the total number of threads, and for each thread, determine a target light source identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and the light source identification information, and determine a target voxel identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and voxels in the light source viewing cone space corresponding to the target light source identifier, and perform volume fog lighting calculation based on the target light source identifier and the target voxel identifier to obtain volume fog lighting information corresponding to the thread;
[0009] fuse the volume fog lighting information corresponding to each thread to obtain volume fog lighting fusion information corresponding to the three-dimensional virtual scene, and perform volume fog rendering in the three-dimensional virtual scene based on the volume fog lighting fusion information to obtain a target volume fog in the three-dimensional virtual scene.
[0010] In a second aspect, the present application also provides a volume fog rendering device. The device comprises:
[0011] a projection module configured to obtain light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculate a projection of the light source range information in a three-dimensional virtual scene corresponding camera viewing cone space to obtain light source viewing cone spaces corresponding to the at least two light source identifiers respectively;
[0012] a quantity determination module configured to determine the number of threads corresponding to the at least two light source identifiers based on the number of voxels in the light source viewing cone space corresponding to the at least two light source identifiers respectively, and count the total number of threads of the number of threads;
[0013] an information obtaining module configured to perform light source identification information calculation based on the number of threads corresponding to the at least two light source identifiers respectively to obtain light source identification information corresponding to the at least two light source identifiers respectively;
[0014] a lighting calculation module configured to run each thread according to the total number of threads, and for each thread, determine a target light source identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and the light source identification information, and determine a target voxel identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and voxels in the light source viewing cone space corresponding to the target light source identifier, and perform volume fog lighting calculation based on the target light source identifier and the target voxel identifier to obtain volume fog lighting information corresponding to the thread;
[0015] a rendering module configured to fuse the volume fog lighting information corresponding to each thread to obtain volume fog lighting fusion information corresponding to the three-dimensional virtual scene, and perform volume fog rendering in the three-dimensional virtual scene based on the volume fog lighting fusion information to obtain a target volume fog in the three-dimensional virtual scene.
[0016] In a third aspect, the present application also provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0017] obtaining light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculating a projection of the light source range information in a camera frustum space corresponding to the three-dimensional virtual scene to obtain light source frustum spaces corresponding to the at least two light source identifiers respectively;
[0018] determining thread numbers corresponding to the at least two light source identifiers respectively based on the number of voxels in the light source frustum spaces corresponding to the at least two light source identifiers respectively, and counting a total number of threads of the thread numbers;
[0019] performing light source identification information calculation based on the thread numbers corresponding to the at least two light source identifiers respectively to obtain light source identification information corresponding to the at least two light source identifiers respectively;
[0020] running each thread according to the total number of threads, and for each thread, determining a target light source identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and the light source identification information, determining a target voxel identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and voxels in the light source frustum space corresponding to the target light source identifier, and performing volume fog lighting calculation based on the target light source identifier and the target voxel identifier to obtain volume fog lighting information corresponding to the thread;
[0021] fusing the volume fog lighting information corresponding to each thread respectively to obtain volume fog lighting fusion information corresponding to the three-dimensional virtual scene, and performing volume fog rendering in the three-dimensional virtual scene based on the volume fog lighting fusion information to obtain a target volume fog in the three-dimensional virtual scene.
[0022] In a fourth aspect, the present application also provides a computer readable storage medium. The computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the following steps:
[0023] obtaining light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculating a projection of the light source range information in a camera frustum space corresponding to the three-dimensional virtual scene to obtain light source frustum spaces corresponding to the at least two light source identifiers respectively;
[0024] determining thread numbers corresponding to the at least two light source identifiers respectively based on the number of voxels in the light source frustum spaces corresponding to the at least two light source identifiers respectively, and counting a total number of threads of the thread numbers;
[0025] performing light source identification information calculation based on the thread numbers corresponding to the at least two light source identifiers respectively to obtain light source identification information corresponding to the at least two light source identifiers respectively;
[0026] Run each thread according to the total number of threads, and for each thread, determine the target light source identification corresponding to the thread based on the mapping relationship between the thread identification information and the light source identification information, and determine the target voxel identification corresponding to the thread based on the mapping relationship between the thread identification information and the voxels in the light source cone space corresponding to the target light source identification, and perform volume fog lighting calculation based on the target light source identification and the target voxel identification to obtain the volume fog lighting information corresponding to the thread;
[0027] The volumetric fog lighting information corresponding to each thread is fused to obtain the volumetric fog lighting fusion information corresponding to the three-dimensional virtual scene, and volumetric fog rendering is performed in the three-dimensional virtual scene based on the volumetric fog lighting fusion information to obtain the target volumetric fog in the three-dimensional virtual scene.
[0028] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the following steps:
[0029] Obtaining light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculating a projection of the light source range information in a camera viewing cone space corresponding to the three-dimensional virtual scene, to obtain light source viewing cone spaces corresponding to the at least two light source identifiers respectively;
[0030] Determine the number of threads corresponding to the at least two light source identifiers based on the number of voxels in the light source cone space corresponding to the at least two light source identifiers, and count the total number of threads;
[0031] Calculating light source identification information based on the number of threads corresponding to the at least two light source identifiers, to obtain light source identification information corresponding to the at least two light source identifiers;
[0032] Run each thread according to the total number of threads, and for each thread, determine the target light source identification corresponding to the thread based on the mapping relationship between the thread identification information and the light source identification information, and determine the target voxel identification corresponding to the thread based on the mapping relationship between the thread identification information and the voxels in the light source cone space corresponding to the target light source identification, and perform volume fog lighting calculation based on the target light source identification and the target voxel identification to obtain the volume fog lighting information corresponding to the thread;
[0033] The volumetric fog lighting information corresponding to each thread is fused to obtain the volumetric fog lighting fusion information corresponding to the three-dimensional virtual scene, and volumetric fog rendering is performed in the three-dimensional virtual scene based on the volumetric fog lighting fusion information to obtain the target volumetric fog in the three-dimensional virtual scene.
[0034] The above-mentioned volumetric fog rendering method, device, computer equipment, storage medium and computer program product obtain the light source range information of at least two light source identifiers in the three-dimensional virtual scene, and calculate the projection of the light source range information in the camera cone space corresponding to the three-dimensional virtual scene, thereby obtaining the light source cone space corresponding to the at least two light source identifiers respectively; based on the number of voxels in the light source cone space corresponding to the at least two light source identifiers respectively, the number of threads corresponding to the at least two light source identifiers is determined, and the total number of threads of the thread number is counted; based on the number of threads corresponding to the at least two light source identifiers respectively, light source identification information is calculated to obtain the light source identification information corresponding to the at least two light source identifiers respectively; and according to the total number of threads, the number of threads is calculated. Each thread is executed. For each thread, based on the mapping relationship between the thread identification information and the light source identification information, the target light source identifier corresponding to the thread is determined. Based on the mapping relationship between the thread identification information and the voxels in the light source view cone corresponding to the target light source identifier, the target voxel identifier corresponding to the thread is determined. Volumetric fog lighting calculation is performed based on the target light source identifier and the target voxel identifier, obtaining volumetric fog lighting information corresponding to the thread. The volumetric fog lighting information corresponding to each thread is fused to obtain volumetric fog lighting fusion information corresponding to the 3D virtual scene. Volumetric fog rendering is performed in the 3D virtual scene based on the volumetric fog lighting fusion information, obtaining the target volumetric fog in the 3D virtual scene. In other words, lighting calculation is performed only for the light source view cone space projected by the light source, thereby reducing the total lighting calculation workload and improving lighting calculation efficiency. Then, lighting calculations for multiple light sources are performed simultaneously by running parallel threads simultaneously, eliminating the need to perform separate calculations for each light source, further improving lighting calculation efficiency. Finally, the volumetric fog lighting information corresponding to each thread is fused before performing volumetric fog rendering, thereby improving volumetric fog rendering efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A diagram of an application environment of a volumetric fog rendering method according to an embodiment;
[0036] Figure 2 1 is a flow chart of a volumetric fog rendering method according to an embodiment;
[0037] Figure 3 It is a two-dimensional simplified schematic diagram of projection calculation in a specific embodiment;
[0038] Figure 4 A schematic diagram of a process for operating a computing unit in one embodiment;
[0039] Figure 5 FIG. 1 is a flow chart of obtaining a target voxel identifier in one embodiment;
[0040] Figure 6 is a schematic diagram of the association relationship in a specific embodiment;
[0041] Figure 7 a flowchart of a volume fog rendering method in one embodiment;
[0042] Figure 8 a schematic diagram of a game virtual scene in one embodiment;
[0043] Figure 9 a time consumption schematic diagram of volume fog rendering in one embodiment;
[0044] Figure 10 a time consumption schematic diagram of volume fog rendering in another embodiment;
[0045] Figure 11 a structural block diagram of a volume fog rendering device in one embodiment;
[0046] Figure 12 an internal structure diagram of a computer device in one embodiment;
[0047] Figure 13 an internal structure diagram of a computer device in another embodiment. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not used to limit the present application.
[0049] The volume fog rendering method provided by the embodiments of the present application can be applied to, for example, Figure 1The application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data required by the server 104 to process. The data storage system can be integrated on the server 104, or placed on the cloud or other servers. The terminal 102 sends the volume fog rendering instruction to the server, and the server 104 obtains the light source range information of at least two light source identifiers in the three-dimensional virtual scene according to the volume fog rendering instruction, and calculates the projection of the light source range information in the three-dimensional virtual scene corresponding to the camera view cone space, to obtain the light source view cone space corresponding to the at least two light source identifiers respectively. The server 104 determines the number of threads corresponding to the at least two light source identifiers based on the number of voxels in the light source view cone space corresponding to the at least two light source identifiers respectively, and counts the total number of threads. The server 104 performs light source identification information calculation based on the number of threads corresponding to the at least two light source identifiers, to obtain the light source identification information corresponding to the at least two light source identifiers respectively. The server 104 runs each thread according to the total number of threads, and for each thread, determines the target light source identifier corresponding to the thread based on the mapping relationship between the identifier information of the thread and the light source identification information, and determines the target voxel identifier corresponding to the thread based on the mapping relationship between the identifier information of the thread and the voxels in the light source view cone space corresponding to the target light source identifier, and performs volume fog lighting calculation based on the target light source identifier and the target voxel identifier, to obtain the volume fog lighting information corresponding to the thread. The server 104 fuses the volume fog lighting information corresponding to each thread respectively to obtain the volume fog lighting fusion information corresponding to the three-dimensional virtual scene, and performs volume fog rendering in the three-dimensional virtual scene based on the volume fog lighting fusion information, to obtain the target volume fog in the three-dimensional virtual scene. Among them, the terminal 102 can be, but is not limited to, various desktop computers, notebook computers, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things device can be a smart speaker, a smart television, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The server can be a standalone physical server, a server cluster composed of multiple physical servers, or a distributed system, or a cloud server providing cloud computing services. The terminal and the server can be connected directly or indirectly through wired or wireless communication, which is not limited in the present application.
[0050] In one embodiment, as shown in Figure 2 , a volume fog rendering method is provided. Taking the server in Figure 1 as an example for illustration, it can be understood that the method can also be applied to the terminal, and can also be applied to a system including the terminal and the server, and is realized through the interaction of the terminal and the server. In this embodiment, the method includes the following steps:
[0051] S202, obtain light source range information of at least two light source identifiers in the three-dimensional virtual scene, and calculate the projection of the light source range information in the three-dimensional virtual scene in the corresponding camera frustum space of the three-dimensional virtual scene to obtain the light source frustum space corresponding to the at least two light source identifiers respectively.
[0052] The three-dimensional virtual scene refers to modeling three-dimensional objects, scenes, light and shadow elements in the real world into a virtual three-dimensional world by using computer technology. The three-dimensional virtual scene can be a scene in various fields, such as a game three-dimensional virtual scene, a movie three-dimensional virtual scene, and a building three-dimensional virtual scene, etc. The three-dimensional virtual scene can be realized by manual modeling, scanning real objects, picture-based modeling, voxel-based modeling, etc. Preferably, the three-dimensional virtual scene can be realized by voxel-based modeling. The three-dimensional virtual scene is a virtual scene including a large number of light sources. The light source identifier is used to identify the light source in the three-dimensional virtual scene. Different light sources in the same three-dimensional virtual scene have different light source identifiers. Different light sources in different three-dimensional virtual scenes can have the same light source identifier. For example, there are light source 1, light source 2 and light source 3 in three-dimensional virtual scene A, and there can also be light source 1, light source 2 and light source 3 in three-dimensional virtual scene B. The light source corresponding to the same light source identifier in different three-dimensional virtual scenes is different. The light source identifier is identified in turn according to a pre-set order. For example, the light source identifier can be a pre-set number, that is, different light sources in the same three-dimensional virtual scene can be numbered in turn to obtain the light source number corresponding to each light source. For example, there are three light sources in the three-dimensional virtual scene, which can be numbered as light source 1, light source 2 and light source 3. The light source refers to a virtual object that can emit light in the three-dimensional virtual scene. For example, the light source can include a natural light source such as a sun light source, and can also include a man-made light source such as a point light source, a spotlight light source, etc. The light source range information refers to the range space irradiated by the light emitted by the light source. The camera frustum space refers to the space visible to the camera in the three-dimensional virtual scene. The content shot by the camera is the content in the camera frustum space. The light source frustum space refers to the range space covered by the light source range information in the camera frustum space, that is, the range space covered by the range space irradiated by the light emitted by the light source in the camera frustum space.
[0053] Specifically, the server receives a volume fog rendering instruction sent by the terminal, the volume fog rendering instruction can carry an identifier of a three-dimensional virtual scene, and then the server can obtain light source range information of a plurality of light sources identified in an established three-dimensional virtual scene from a database according to the identifier of the three-dimensional virtual scene in response to the volume fog rendering instruction, the plurality can be at least two. Wherein, the three-dimensional virtual scene is pre-established and saved, the server can find the light source range information corresponding to the light source identification according to the data in the saved three-dimensional virtual scene. Then the server calculates the range covered by the light range of each light source identified in the three-dimensional virtual scene. That is, the server can calculate the projection of the light source range information in the three-dimensional virtual scene corresponding to the camera frustum space, wherein the server can obtain the projection parameters of the three-dimensional virtual scene corresponding to the camera frustum space, and then use the projection parameters to project and calculate the light source range information to obtain the light source frustum space corresponding to the light source identification. For example, the server can calculate the product of the range boundary value in the light source range information and the projection parameter to obtain the boundary value of the light source frustum space, and determine the light source frustum space according to the boundary value of the light source frustum space. Then the server projects and calculates the light source range information of each light source identification to obtain the light source frustum space corresponding to each light source identification.
[0054] S204, determining the number of threads corresponding to at least two light source identifications respectively based on the number of voxels in the light source frustum space corresponding to the at least two light source identifications respectively, and counting the total number of threads.
[0055] Wherein, the voxel refers to dividing the camera frustum space in the NDC (normalized device coordinate space) space into a plurality of body blocks of the same size, each body block is called a voxel. The voxel in the light source frustum space refers to the voxel in the frustum space covered by the light of the light source. The voxel in the camera frustum space is pre-divided, and the spatial size of the voxel is pre-set. The number of voxels in the light source frustum space refers to the number of voxels contained in the light source frustum space. The number of threads is used to represent the number of threads required when the light source identified by the light source identification performs light calculation. The number of threads corresponding to different light source identifications can be different or the same. The total number of threads refers to the number of threads required when all the light sources in the three-dimensional virtual scene perform light calculation.
[0056] Specifically, the server calculates the number of threads needed to be allocated when each light source identified by a light source identifier performs light illumination calculation. Each voxel can have a corresponding thread to perform light illumination calculation, at this time, the server can directly take the number of voxels in the light source frustum space of the light source corresponding to the light source identifier as the number of threads corresponding to the light source identifier. The server can also determine the number of computing units needed according to the number of threads contained in the computing unit in the server, and then use the number of threads contained in the computing unit and the number of voxels in the light source frustum space corresponding to the light source identifier to determine the number of computing units needed, and determine the number of threads corresponding to the light source identifier according to the number of computing units. That is, the number of threads corresponding to the light source identifier determined by the server is greater than the number of voxels in the light source frustum space corresponding to the light source identifier. The server determines the number of threads corresponding to each light source identifier using the number of voxels in the light source frustum space corresponding to the light source identifier. Finally, the server sums up the total number of threads needed for all light sources in the three-dimensional virtual scene to perform light illumination calculation.
[0057] S206, perform light source identification information calculation based on the number of threads corresponding to each of the at least two light source identifiers respectively, to obtain light source identification information corresponding to each of the at least two light source identifiers respectively.
[0058] The light source identification information is information used to identify the corresponding light source, and different light source identifiers have different light source identification information.
[0059] Specifically, the server can sequentially accumulate the number of threads corresponding to the light source identifiers in order to obtain the number of threads accumulated for each light source identifier, and then the server can directly take the number of threads accumulated as the light source identification information. Then the server can associate and save the light source identifier and the corresponding light source identification information. Then when the light source identification information is determined, the corresponding light source identifier can be determined according to the light source identification information according to the saved association relationship.
[0060] S208, run each thread according to the total number of threads, and for each thread, determine the target light source identifier corresponding to the thread based on the mapping relationship between the thread identifier and the light source identification information, and determine the target voxel identifier corresponding to the thread based on the mapping relationship between the thread identifier and the voxels in the light source frustum space corresponding to the target light source identifier, and perform volume fog light illumination calculation based on the target light source identifier and the target voxel identifier to obtain volume fog light illumination information corresponding to the thread.
[0061] The mapping relationship between the identification information of the thread and the light source identification information is used to represent a condition for successful matching of the identification information of the thread and the light source identification information. The mapping relationship between the identification information of the thread and the voxels in the target light source identification corresponding light source view volume space is used to represent a condition for successful matching of the identification information of the thread and the voxels in the light source view volume space. The target light source identification refers to the identification of the light source to be calculated by the thread. Different threads can correspond to the same light source identification, or can correspond to different light source identifications. The target voxel identification refers to the identification of the voxel to be calculated by the thread, and the voxel of the target voxel identification is determined from the voxel in the target light source identification corresponding light source view volume space. The volume fog lighting information is used to represent the volume fog lighting result obtained by lighting through the light source. The volume fog lighting information corresponding to the thread refers to the volume fog lighting information corresponding to the voxel of the target voxel identification in the target light source identification corresponding light source view volume space, that is, the volume fog lighting result obtained by the light source of the target light source identification performing lighting calculation on the voxel of the target voxel identification. Different threads can calculate the volume fog lighting result of different voxels corresponding to the same light source, or can calculate the volume fog lighting result of different voxels corresponding to different light sources. That is, different voxels corresponding to different light sources perform lighting calculation independently in parallel, and do not repeat lighting calculation on the same voxel.
[0062] Specifically, the server runs the same number of threads as the total number of threads, obtains each running thread, and then each running thread determines the target light source identification to be calculated by the thread according to the mapping relationship between the identification information of the thread and the light source identification information, and determines the target voxel identification to be calculated according to the mapping relationship between the identification information of the thread and the voxels in the target light source identification corresponding light source view volume space. Then, the calculation parameters required for volume fog lighting calculation are obtained according to the target light source identification and the target voxel identification, and then the lighting calculation is performed using the obtained lighting calculation parameters to obtain the volume fog lighting result of the voxel of the target voxel identification in the light source of the target light source identification. At this time, the thread obtains the running result, that is, the corresponding volume fog lighting information.
[0063] In one embodiment, the central processing unit (CPU) in the server serves as the execution subject, and the total number of threads is calculated. Then, when the total number of threads is small, each thread in the CPU can be directly run according to the total number of threads, and lighting calculation is performed simultaneously by each thread in the CPU to obtain the volume fog lighting information calculated by each thread. Directly performing lighting calculation by the threads in the CPU can improve the efficiency of lighting calculation.
[0064] In one embodiment, the image processor (GPU) in the server acts as an execution body to calculate the total number of threads, then directly run each thread in the GPU according to the total number of threads, and perform light calculation through each thread in the GPU to obtain the volume fog light information corresponding to each thread. The light calculation through the GPU improves the efficiency of a large number of light calculations.
[0065] In one embodiment, the CPU in the server calculates the total number of threads, and when the number of threads in the current CPU cannot meet the total number of threads required for light calculation or using the threads in the CPU for light calculation will result in reduced efficiency, the CPU in the server can send a light calculation instruction to the GPU, which carries the total number of threads. Then the GPU in the server runs each thread in the GPU according to the light calculation instruction according to the total number of threads, and performs light calculation through each thread in the GPU in parallel to obtain the volume fog light information corresponding to each thread. That is, a large number of light calculations are performed simultaneously through the threads in the GPU, improving the efficiency of light calculation. And by sending one instruction to the GPU, light calculation can be performed on multiple light sources at the same time. When each light source needs to perform light calculation separately, each light source needs to send an instruction to the GPU, reducing the time and resource overhead of sending multiple instructions to the GPU, thereby further improving the efficiency of light calculation.
[0066] S210, fuse the volume fog light information corresponding to each thread to obtain the volume fog light fusion information corresponding to the three-dimensional virtual scene, and perform volume fog rendering in the three-dimensional virtual scene based on the volume fog light fusion information to obtain the target volume fog in the three-dimensional virtual scene.
[0067] Among them, the volume fog light fusion information is used to represent the light result of the voxel in the camera frustum space corresponding to the three-dimensional virtual scene. The target volume fog refers to the volume fog obtained by using the light result of the light source in the three-dimensional virtual scene for volume fog rendering.
[0068] Specifically, the server finds all volume fog light information corresponding to the same voxel identifier from the volume fog light information corresponding to each thread according to the voxel identifier of each voxel in the three-dimensional virtual scene, then fuses all volume fog light information corresponding to the same voxel identifier to obtain the volume fog light fusion information of all voxels covered by light in the three-dimensional virtual scene, that is, to obtain the volume fog light fusion information corresponding to the three-dimensional virtual scene. Finally, the server performs volume fog rendering in the three-dimensional virtual scene using the volume fog light fusion information to obtain the target volume fog in the three-dimensional virtual scene.
[0069] The volume fog rendering method, by obtaining the light source range information of at least two light source identifiers in the three-dimensional virtual scene, and calculating the projection of the light source range information in the camera frustum space corresponding to the three-dimensional virtual scene, obtains the light source frustum space corresponding to the at least two light source identifiers respectively; based on the number of voxels in the light source frustum space corresponding to the at least two light source identifiers respectively, determine the number of threads corresponding to the at least two light source identifiers respectively, and count the total number of threads; based on the number of threads corresponding to the at least two light source identifiers respectively, the light source identification information is calculated, and the light source identification information corresponding to the at least two light source identifiers respectively is obtained; running each thread according to the total number of threads, and for each thread, based on the mapping relationship between the identifier information of the thread and the light source identification information, the target light source identifier corresponding to the thread is determined, and based on the mapping relationship between the identifier information of the thread and the target light source frustum space corresponding to the target light source identifier, the target voxel identifier corresponding to the thread is determined, and the volume fog lighting calculation is carried out based on the target light source identifier and the target voxel identifier, and the volume fog lighting information corresponding to the thread is obtained; the volume fog lighting information corresponding to each thread is fused respectively, and the volume fog lighting fusion information corresponding to the three-dimensional virtual scene is obtained, and the volume fog rendering is carried out in the three-dimensional virtual scene based on the volume fog lighting fusion information, and the target volume fog in the three-dimensional virtual scene is obtained. That is, only the light source frustum space of the light source projection is calculated, so as to reduce the total task amount of the lighting calculation, and the efficiency of the lighting calculation is improved. Then the lighting of multiple light sources is calculated by simultaneously running parallel threads, so as to not need to calculate each light source separately, and the efficiency of the lighting calculation is further improved. Finally, the volume fog lighting information corresponding to each thread is fused and then the volume fog rendering is carried out, so as to improve the efficiency of the volume fog rendering.
[0070] In one embodiment, S202, the projection of the light source range information in the camera frustum space corresponding to the three-dimensional virtual scene is calculated, and the light source frustum space corresponding to the at least two light source identifiers respectively is obtained, including the steps of:
[0071] For each light source identifier, the corresponding light source enclosing space is determined based on the range coordinates in the light source range information of the light source identifier; the projection parameters of the camera frustum space corresponding to the three-dimensional virtual scene are obtained, and the light source enclosing space is projected and calculated based on the projection parameters, to obtain the light source frustum space corresponding to the at least two light source identifiers respectively.
[0072] The range coordinates are used to represent the coordinates of the range of the light source, such as the illumination boundary coordinates. The light source surrounding space refers to the space surrounding the illumination range of the light source. The light source surrounding space is larger than the illumination range of the light source and the light source surrounding space contains the illumination range of the light source, such as the light source surrounding space can be a bounding box of the illumination range. The projection parameter refers to the parameter used by the camera in the three-dimensional virtual scene for projection, and the projection parameter is determined according to the parameter of the camera in the three-dimensional virtual scene.
[0073] Specifically, the server calculates the optimal surrounding space using the range coordinates in the light source range information of the light source identifier, and then takes the optimal surrounding space as the light source surrounding space corresponding to the light source identifier. The bounding box algorithm can be used to calculate the optimal surrounding space. Then the server obtains the projection parameter of the camera view cone space corresponding to the three-dimensional virtual scene from the database. The projection parameter has been determined when the three-dimensional virtual scene is established. Then the light source surrounding space is projected and calculated using the projection parameter to obtain the light source view cone space corresponding to the light source identifier. Then the server iteratively calculates each light source identifier to obtain the light source view cone space corresponding to each light source identifier.
[0074] In one embodiment, the server performs bounding box calculation through the bounding box algorithm according to the light source range information of the light source identifier to obtain the bounding box corresponding to the light source identifier. For example, for the light source range information of a point light source, the axis-aligned bounding box (AABB) algorithm can be used to calculate the bounding box of the point light source. For a spotlight, the oriented bounding box (OBB) algorithm can be used to calculate the bounding box of the spotlight. Then the bounding box is projected in the camera view cone space corresponding to the three-dimensional virtual scene to obtain the light source view cone space corresponding to the light source identifier. For example, the position coordinates of each vertex of the bounding box can be obtained, and then the product of each vertex position coordinate and the projection matrix of the main camera in the three-dimensional virtual scene is calculated to obtain the coordinates of each vertex in the camera view cone space. The voxel interval covered by the bounding box in the camera view cone space is obtained according to the coordinates of each vertex in the camera view cone space, that is, the light source view cone space is obtained. As shown in FIG. 8, it is a two-dimensional simplified schematic diagram of projection calculation, including a projection example of a spotlight and a projection example of a point light source. When projecting the spotlight, the light source bounding box is calculated according to the illumination range information of the spotlight, and then the light source bounding box of the spotlight is projected into the camera view cone space to obtain the voxel region projected by the light source bounding box, that is, the light source view cone space of the spotlight. When projecting the point light source, the light source bounding box is calculated according to the illumination range information of the point light source, and then the light source bounding box of the point light source is projected into the camera view cone space to obtain the voxel region projected by the light source bounding box, that is, the light source view cone space of the point light source. Figure 3 As shown in FIG. 8, it is a two-dimensional simplified schematic diagram of projection calculation, including a projection example of a spotlight and a projection example of a point light source. When projecting the spotlight, the light source bounding box is calculated according to the illumination range information of the spotlight, and then the light source bounding box of the spotlight is projected into the camera view cone space to obtain the voxel region projected by the light source bounding box, that is, the light source view cone space of the spotlight. When projecting the point light source, the light source bounding box is calculated according to the illumination range information of the point light source, and then the light source bounding box of the point light source is projected into the camera view cone space to obtain the voxel region projected by the light source bounding box, that is, the light source view cone space of the point light source.
[0075] In the above embodiment, the range coordinates in the light source range information identified by using the light source are used to determine the corresponding light source enclosing space, and then the light source enclosing space is projected and calculated by using the projection parameters to obtain the light source view cone space, that is, the light source enclosing space is projected and calculated, so that all the light ranges of the light source can be projected, thereby improving the accuracy of the obtained light source view cone space.
[0076] In one embodiment, S204, that is, determining the thread number corresponding to each of the at least two light source identifications based on the number of voxels in the light source view cone space corresponding to each of the at least two light source identifications, comprises the following steps:
[0077] For each light source identification, the starting voxel identification and the ending voxel identification in the light source view cone space corresponding to the light source identification are obtained; the number of voxels in the light source view cone space corresponding to the light source identification is determined based on the difference between the starting voxel identification and the ending voxel identification, and the thread number corresponding to the light source identification is determined based on the number of voxels.
[0078] The starting voxel identification is used to identify the starting voxel, that is, the first voxel, in the light source view cone space. The ending voxel identification is used to identify the ending voxel, that is, the last voxel, in the light source view cone space. The voxel identification of the voxel in the camera view cone space is obtained by sequentially identifying the voxels in the order of the pre-set order when the voxels are divided, for example, the voxel identification can be a voxel number or a position coordinate identification of the voxel. The voxel identification is used to identify the corresponding voxel. Different voxels in the three-dimensional virtual scene have different voxel identifications, and the same voxel has the same voxel identification.
[0079] Specifically, the server obtains the starting voxel identification and the ending voxel identification in the light source view cone space corresponding to the light source identification. Then, the difference between the starting voxel identification and the ending voxel identification is calculated to obtain the identification difference between the first voxel and the last voxel, and then the number of voxels in the light source view cone space corresponding to the light source identification can be determined according to the identification difference, for example, when the voxel identification is a voxel number, the number difference can be directly used as the number of voxels. At this time, the server determines the thread number corresponding to the light source identification according to the number of voxels, and can set one thread corresponding to each voxel, and then directly uses the number of voxels as the number of threads. Finally, the server can traverse and calculate the number of voxels in the light source view cone space corresponding to each light source identification, and then determine the thread number corresponding to the light source identification.
[0080] In a specific embodiment, the server can obtain the coordinate number of the first voxel covered by the i-th light source (Xmin_i, Ymin_i, Zmin_i), and then obtain the coordinate number of the last voxel covered (Xmax_i, Ymax_i, Zmax_i). At this time, the server can calculate the number of voxels covered by the i-th light source using formula (1) as shown below.
[0081] FroxelNum_i = (Xmax_i - Xmin_i + 1) * (Ymax_i - Ymin_i + 1) * (Zmax_i - Zmin_i + 1) Formula (1)
[0082] Wherein, FroxelNum_i represents the number of voxels covered by the i-th light source.
[0083] In an embodiment, when the calculated number of voxels covered by the light source is less than the pre-set threshold, the light source less than the pre-set threshold can be processed separately, avoiding too many threads in a single calculation unit that will not perform lighting calculation, and avoiding waste of thread resources.
[0084] In the above embodiment, by obtaining the starting voxel identifier and the ending voxel identifier in the light source frustum space corresponding to the light source identifier, determining the number of voxels in the light source frustum space corresponding to the light source identifier based on the difference between the starting voxel identifier and the ending voxel identifier, i.e. using the starting voxel identifier and the ending voxel identifier to determine the number of voxels, it can be avoided to count the voxels outside the light source frustum space, improving the accuracy of obtaining the number of voxels, and then determining the number of threads corresponding to the light source identifier according to the number of voxels, improving the accuracy of obtaining the number of threads.
[0085] In an embodiment, determining the number of threads corresponding to the light source identifier based on the number of voxels includes the steps of:
[0086] Obtaining the number of unit threads of the calculation unit, performing ratio calculation based on the number of voxels and the number of unit threads to obtain the number of calculation units corresponding to the light source identifier; performing summation calculation based on the number of calculation units and the number of unit threads to obtain the number of threads corresponding to the light source identifier.
[0087] Wherein, the calculation unit refers to a unit for lighting calculation. Each calculation unit can include the same number of threads. The number of unit threads refers to the number of threads included in the calculation unit, which is pre-set. For example, the calculation unit can be a physical thread unit (Wrap) of a GPU, which includes 32 threads. The calculation unit can also include multiple physical thread units of the GPU, such as an integer multiple of a physical thread unit (Wrap). The number of calculation units refers to the number of calculation units required for the light source to perform lighting calculation.
[0088] Specifically, the threads in the server are provided in the form of a calculation unit, at this time, the server can obtain the preset number of unit threads of the calculation unit, then calculate the ratio of the number of voxels to the number of unit threads, and obtain the number of calculation units required for the light source to perform light calculation. Then multiply the number of calculation units and the number of unit threads to obtain the number of threads required for the light source to perform light calculation. The number of threads is usually greater than or equal to the number of voxels. The server iterates to calculate each light source identifier to obtain the corresponding calculation unit number and thread number of each light source identifier.
[0089] In a specific embodiment, when the number of unit threads in the calculation unit is 32, the number of calculation units corresponding to the i-th light source can be calculated using formula (2) as shown below, which can ensure that all threads in each calculation unit correspond to the same light source, that is, all threads in the calculation unit perform light calculation on the same light source.
[0090] GroupNum_i =(FroxelNum_i+31) / 32 Formula (2)
[0091] Where GroupNum_i refers to the number of calculation units of the i-th light source, and FroxelNum_i refers to the number of voxels covered by the i-th light source. The number of calculation units of the i-th light source is obtained by calculating the sum of the number of voxels covered by the i-th light source and the number of unit threads minus one, then calculating the ratio of the sum to the number of unit threads, and then rounding the ratio to obtain the number of calculation units of the i-th light source. Then the server saves the calculated number of calculation units corresponding to each light source identifier.
[0092] In the above embodiment, by obtaining the number of unit threads of the calculation unit, calculating the ratio based on the number of voxels and the number of unit threads, obtaining the number of calculation units corresponding to the light source identifier, and calculating the sum based on the number of calculation units and the number of unit threads, obtaining the number of threads corresponding to the light source identifier. Then calculate the number of threads corresponding to the light source identifier according to the calculation unit, improve the accuracy of the obtained number of threads, and facilitate subsequent thread running in units of calculation units, improve the efficiency of thread running.
[0093] In one embodiment, as Figure 4 shown, S406, based on the number of threads corresponding to at least two light source identifiers respectively, calculate the light source identification information to obtain the light source identification information corresponding to at least two light source identifiers respectively, including:
[0094] S402, obtaining the number of calculation units corresponding to at least two light source identifiers respectively, and counting the total number of calculation units;
[0095] S404, sequentially add the number of calculation units corresponding to each light source identifier to obtain the unit accumulated number corresponding to each light source identifier;
[0096] S406, take the unit accumulated number as the light source identification information to obtain the light source identification information corresponding to each light source identifier.
[0097] The unit total number refers to the total number of calculation units required for all light sources in the three-dimensional virtual scene to perform light calculation. The unit accumulated number is obtained by summing the number of calculation units corresponding to the current light source identifier and the number of calculation units corresponding to all light source identifiers before the current light source identifier, for example, the unit accumulated number of the third light source is the sum of the number of calculation units of the third light source and the number of calculation units of the first two light sources.
[0098] Specifically, the server obtains the number of calculation units corresponding to each light source identifier from the database, and counts the unit total number of the number of calculation units, that is, sums the number of calculation units corresponding to all light source identifiers to obtain the unit total number. Then, the number of calculation units corresponding to each light source identifier is sequentially added to obtain the unit accumulated number corresponding to each light source identifier, for example, the unit accumulated number corresponding to the first light source identifier is the number of calculation units corresponding to the first light source identifier, the unit accumulated number corresponding to the second light source identifier is the sum of the number of calculation units corresponding to the second light source identifier and the unit accumulated number corresponding to the first light source identifier, the unit accumulated number corresponding to the third light source identifier is the sum of the number of calculation units corresponding to the third light source identifier and the unit accumulated number corresponding to the second light source identifier, and then the same is applied to the subsequent light source identifiers. Then, the server can take the unit accumulated number corresponding to each light source identifier as the light source identification information to obtain the light source identification information corresponding to each light source identifier. The server can save the unit accumulated number corresponding to each light source identifier to facilitate subsequent light source identification.
[0099] In a specific embodiment, the server can calculate the prefix sum of GroupNum to obtain the unit accumulated number, and store the unit accumulated number in GroupOffset, for example, the unit accumulated number corresponding to the ith light source is stored in GroupOffset[i], which is the sum of the number of calculation units GroupNum_0 of the 0th light source and the number of calculation units GroupNum_i of the ith light source. Then, the sum of the number of calculation units corresponding to all light sources is obtained to obtain the unit total number GroupNumTotal.
[0100] S208, run each thread according to the total number of threads, including:
[0101] S408, running threads in each calculation unit according to the total number of units.
[0102] Specifically, the server runs the same number of calculation units according to the total number of units, that is, all threads in each calculation unit are run, and the running calculation units are obtained.
[0103] In one embodiment, the server can run the corresponding calculation units according to the total number of units, that is, all threads in each calculation unit are run, and the running calculation units are obtained.
[0104] In one embodiment, the GPU in the server obtains the illumination calculation instruction sent by the CPU, which carries the total number of units to be run, and then the GPU in the server runs the corresponding calculation units according to the total number of units, and performs illumination calculation through the threads in the running calculation units in the GPU, thereby improving the efficiency of illumination calculation.
[0105] In the above embodiment, the number of calculation units corresponding to at least two light source identifiers is sequentially calculated by adding up, the number of unit accumulations corresponding to at least two light source identifiers is obtained, and the number of unit accumulations is used as light source identification information, that is, light source identification is performed by using the number of unit accumulations as light source identification information, which can improve the efficiency of light source identification. And running threads in each calculation unit according to the total number of units, so as to ensure that all threads in each calculation unit perform illumination calculation on the same light source, that is, all threads in each calculation unit perform the same calculation task of the same light source on the continuous voxels, which ensures the hit rate of data cache in the calculation unit, reduces the actual execution branch, ensures the continuity of the equation, and reduces the average task time consumption.
[0106] In one embodiment, S206, based on the number of threads corresponding to at least two light source identifiers, the light source identification information is calculated to obtain the light source identification information corresponding to at least two light source identifiers, including the steps of:
[0107] The number of threads corresponding to at least two light source identifiers is sequentially calculated by adding up to obtain the number of thread accumulations corresponding to at least two light source identifiers; and the number of thread accumulations is used as light source identification information to obtain the light source identification information corresponding to at least two light source identifiers.
[0108] The number of thread accumulations is the sum of the number of threads corresponding to the current light source identifier and the number of threads corresponding to all light source identifiers before the current light source identifier, for example, the number of thread accumulations of the third light source is the sum of the number of threads of the third light source and the number of threads of the first two light sources.
[0109] Specifically, the server sequentially accumulates the thread quantity corresponding to each light source identifier to obtain the thread accumulation quantity corresponding to each light source identifier. For example, the thread accumulation quantity corresponding to the first light source identifier is the thread quantity corresponding to the first light source identifier, the thread accumulation quantity corresponding to the second light source identifier is the thread quantity corresponding to the second light source identifier plus the thread accumulation quantity corresponding to the first light source identifier, the thread accumulation quantity corresponding to the third light source identifier is the thread quantity corresponding to the third light source identifier plus the thread accumulation quantity corresponding to the second light source identifier, and then the same is applied to the subsequent light source identifiers until the thread accumulation quantity corresponding to the last light source identifier is obtained. Finally, the server obtains the light source identification information corresponding to each light source identifier by taking the thread accumulation quantity as the light source identification information. The server can also directly save the thread accumulation quantity corresponding to each light source identifier, that is, save the light source identifier in association with the thread accumulation quantity, so as to facilitate subsequent searching for the corresponding light source identifier according to the determined thread accumulation quantity.
[0110] In the above embodiment, the thread accumulation quantity corresponding to each light source identifier is obtained by sequentially accumulating the thread quantity corresponding to each light source identifier, and then the thread accumulation quantity is directly taken as the light source identification information to obtain the light source identification information corresponding to each light source identifier. The thread accumulation quantity is directly used as the light source identification information, which improves the accuracy of the obtained light source identification information, so that the corresponding light source identifier can be accurately determined using the light source identification information.
[0111] In one embodiment, S208, that is, determining the target light source identifier corresponding to the thread based on the mapping relationship between the thread identification information and the light source identification information, includes:
[0112] The mapping relationship between the thread identification information and the light source identification information is used to represent the condition for successful matching of the thread identification information and the light source identification information. The light source identifier corresponding to the target light source identification information is taken as the target light source identifier corresponding to the thread.
[0113] The thread identification information is used to identify the corresponding thread and is obtained by sequentially numbering all threads according to a pre-set order. The mapping relationship is used to represent the condition for successful matching of the thread identification information and the light source identification information. The mapping relationship is pre-set, that is, the pre-set condition for successful matching of the thread identification information and the light source identification information.
[0114] Specifically, the server acquires a mapping relationship between the identification information of the thread and the light source identification information, and then matches the identification information of the thread with the light source identification information corresponding to the at least two light source identifications according to the mapping relationship, that is, the server determines whether the identification information of the thread and the light source identification information meet the matching success condition. When the matching success condition is not met, the server matches the identification information of the thread with the next light source identification information. When the matching success condition is met, the server takes the light source identification information meeting the matching success condition as the target light source identification information matched by the thread. Then, the server looks up the light source identification in the pre-stored association relationship between the light source identification and the light source identification information, thereby obtaining the target light source identification corresponding to the thread.
[0115] In the above embodiment, the identification information of the thread is matched with the light source identification information corresponding to the at least two light source identifications by using the mapping relationship, the target light source identification matched by the thread is obtained, and then the light source identification corresponding to the target light source identification is taken as the target light source identification corresponding to the thread, that is, the matching is performed by using the pre-set matching success condition, thereby improving the matching accuracy.
[0116] In one embodiment, the light source identification information includes a thread accumulation number, the identification information of the thread is matched with the light source identification information corresponding to the at least two light source identifications based on the mapping relationship between the identification information of the thread and the light source identification information, and the target light source identification matched by the thread is obtained, including the following steps:
[0117] The identification information of the thread is compared with each thread accumulation number in turn, and when a target thread accumulation number in the thread accumulation numbers is greater than or equal to the identification information of the thread and a forward thread accumulation number corresponding to the target thread accumulation number is less than the identification information of the thread, the target thread accumulation number is taken as the target light source identification matched by the thread.
[0118] The target thread accumulation number can be any one of the thread accumulation numbers. The forward thread accumulation number refers to a thread accumulation number before the target thread accumulation number.
[0119] Specifically, the server can compare the identification information of the thread with each thread accumulation number, that is, select a thread accumulation number from the thread accumulation numbers as a target thread accumulation number to be compared. Then, the comparison is performed, and when the thread accumulation number is less than the identification information of the thread, it is indicated that the thread accumulation number is not the thread accumulation number matched by the identification information of the thread. When the thread accumulation number is greater than or equal to the identification information of the thread and a forward thread accumulation number corresponding to the target thread accumulation number is less than the identification information of the thread, the server directly takes the target thread accumulation number as the target light source identification matched by the thread.
[0120] In the above embodiment, by comparing the identification information of the thread with each thread cumulative number in turn, when the target thread cumulative number is greater than or equal to the identification information of the thread and the forward thread cumulative number corresponding to the target thread cumulative number is less than the identification information of the thread, the target thread cumulative number is taken as the target light source identification information matched by the thread, that is, the target light source identification information matched by the thread is determined by comparison, thereby improving the matching efficiency.
[0121] In one embodiment, the light source identification information includes a unit cumulative number, the identification information of the thread is matched with each light source identification information to obtain the target light source identification information corresponding to the thread, including the steps of:
[0122] Based on the identification information of the thread, the corresponding target computing unit identifier is obtained, and the target computing unit identifier is compared with each unit cumulative number in turn; when the target unit cumulative number in each unit cumulative number is greater than or equal to the target computing unit identifier and the forward unit cumulative number corresponding to the target unit cumulative number is less than the target computing unit identifier, the target unit cumulative number is taken as the target light source identification information matched by the thread.
[0123] The target computing unit identifier is used to identify the computing unit where the thread is located, and the computing unit identifier is used to identify the corresponding computing unit, which can be obtained by sequentially numbering all computing units according to a pre-set order. The target unit cumulative number can be any one of the unit cumulative numbers, which is the unit cumulative number that needs to be compared with the identification information of the thread. The forward unit cumulative number is the previous unit cumulative number of the target unit cumulative number.
[0124] Specifically, the server finds the target computing unit identifier corresponding to the identification information of the thread according to the pre-set relationship between the thread identifier and the computing unit it belongs to, and then judges according to the pre-set matching condition, which can be whether the unit cumulative number is greater than or equal to the target computing unit identifier and whether the forward unit cumulative number corresponding to the target unit cumulative number is less than the target computing unit identifier. Then, according to the judgment result, the target unit cumulative number that meets the matching condition is determined from each unit cumulative number as the target light source identification information matched by the thread.
[0125] In one specific embodiment, the target computing unit identifier SV_GroupID corresponding to the identification information of the thread is obtained. Then, SV_GroupID is compared with the values in GroupOffset in turn, and when the first GroupOffset[i] value greater than SV_GroupID is encountered, the light source number i corresponding to the value is taken as the target light source identifier corresponding to the thread.
[0126] In the above embodiment, the target unit accumulation number meeting the matching success condition is determined as the target light source identification information of the thread by comparing the identification of the calculation unit to which the thread belongs with the respective unit accumulation numbers, that is, the target light source identification information of the thread is determined by comparison, thereby improving the matching efficiency.
[0127] In one embodiment, as shown in S208, based on the mapping relationship between the identification information of the thread and the target light source identification in the voxel of the corresponding light source view volume space, the target voxel identification corresponding to the thread is determined, including: Figure 5
[0128] S502, based on the identification information of the thread, the corresponding target calculation unit identification is obtained, and the forward unit accumulation number corresponding to the target calculation unit identification is obtained.
[0129] S504, based on the target calculation unit identification, the forward unit accumulation number and the unit thread identification of the thread, the light source thread identification is calculated to obtain the light source thread identification corresponding to the thread.
[0130] The forward unit accumulation number corresponding to the target calculation unit identification refers to the previous unit accumulation number of the unit accumulation number corresponding to the light source identification to which the target calculation unit identification belongs. For example, the target calculation unit identification is the calculation unit identification for performing light calculation on the 3rd light source, and the forward unit accumulation number corresponding to the target calculation unit identification refers to the unit accumulation number corresponding to the 2nd light source identification. The forward unit accumulation number of the first light source is set to 0. The unit thread identification is used to represent the identification of the current thread in the corresponding calculation unit, which can be the number of the thread in the current calculation unit. For example, the calculation unit can have 32 threads, and the current thread can be the 5th thread of the calculation unit, so the unit thread identification is the number 5. The light source thread identification is used to represent the current thread which is the thread for performing light calculation on the light source. The light source thread identification can be a number, for example, the calculation unit can have 32 threads, if the current thread is the 5th thread in the second calculation unit corresponding to the light source 1, the number of the calculation unit can start from 0, so the identification of the second calculation unit is the number 1, at this time the obtained light source thread identification is the number 37, which represents that the current thread is the 37th thread for performing light calculation on the light source 1. The numbering can start from zero in turn.
[0131] Specifically, the server obtains the target computing unit identifier corresponding to the thread's identification information, and searches for the corresponding light source identifier based on the target computing unit identifier. Then, based on the light source identifier, it searches for the unit cumulative number corresponding to the previous light source identifier to obtain the forward unit cumulative number. That is, the forward unit cumulative number is the unit cumulative number corresponding to the previous light source identifier of the current light source identifier. The target computing unit identifier, the forward unit cumulative number, and the unit thread identifier of the thread are then used to calculate the light source thread identifier, that is, the difference between the target computing unit identifier and the forward unit cumulative number is calculated, and then the sum of the difference and the unit thread identifier is calculated to obtain the light source thread identifier corresponding to the thread.
[0132] S506 , obtaining a starting voxel identifier and an ending voxel identifier in the light source viewing cone space, performing voxel identifier calculation based on the starting voxel identifier, the ending voxel identifier, and the light source thread identifier, and obtaining a target voxel identifier corresponding to the thread.
[0133] In this embodiment, after obtaining the light source thread identifier corresponding to the current thread, the server obtains the starting voxel identifier and the ending voxel identifier in the light source cone space of the light source corresponding to the current thread, and then uses the starting voxel identifier, the ending voxel identifier and the light source thread identifier to calculate the voxel identifier for the current thread to perform lighting calculations, wherein a simple mapping relationship between the light source thread identifier and the voxel identifier is established, and a simple mapping relationship between the light source thread identifier and the voxel identifier can be established for all light source thread identifiers of the light source that are less than the number of voxels covered by the light source. The thread whose light source thread identifier is greater than or equal to the number of voxels is an invalid thread in the computing unit and does not need to perform actual lighting calculations. Then, according to the mapping relationship, the target voxel identifier corresponding to the thread can be calculated using the light source thread identifier.
[0134] In one embodiment, the server can determine that the current thread is the number of threads that perform lighting calculations for the corresponding light source based on the light source thread identifier. Then, each thread in the light source calculates a voxel corresponding to the number of threads that perform lighting calculations, and the number of voxels to be calculated is determined based on the number of threads that perform lighting calculations. For example, if the current thread is the 10th thread of the light source, it is determined that the voxel to be calculated by the current thread is the 10th voxel of the light source, and the voxel identifier corresponding to the 10th voxel is obtained to obtain the target voxel identifier corresponding to the thread.
[0135] In the above embodiment, the light source thread identifier corresponding to the thread is calculated by using the target calculation unit identifier, the accumulated number of forward units and the unit thread identifier of the thread. The light source thread identifier corresponding to the thread can be quickly calculated in real time, and then the target voxel identifier corresponding to the thread is calculated in real time using the light source thread identifier as well as the starting voxel identifier and the ending voxel identifier, thereby improving the efficiency of obtaining the target voxel identifier.
[0136] In one embodiment,Figure 5 As shown, S504, i.e. based on the target calculation unit identification, the forward unit cumulative number and the unit thread identification of the thread, the light source thread identification calculation is performed to obtain the light source thread identification corresponding to the thread, including steps of:
[0137] S504a, calculating the difference between the target calculation unit identification and the forward unit cumulative number to obtain the target unit number corresponding to the target light source identification;
[0138] S504b, obtaining the unit thread number of the calculation unit, and calculating the product of the target unit number and the unit thread number to obtain the target thread number corresponding to the target light source identification;
[0139] S504c, obtaining the unit thread identification corresponding to the thread, and determining the light source thread identification corresponding to the thread based on the target thread number and the unit thread identification.
[0140] Wherein, the target light source identification is used to identify the light source corresponding to the current thread. The target unit number is used to represent the number of calculation units required by the light source corresponding to the target light source identification before the target calculation unit identification. The target thread number refers to the total number of threads contained in the calculation unit of the target unit number.
[0141] Specifically, the server calculates the difference between the target calculation unit identification and the forward unit cumulative number, i.e. the difference between the target calculation number and the forward unit cumulative number, to obtain the target unit number, then calculates the product of the target unit number and the unit thread number to obtain the target thread number corresponding to the target light source identification, and finally calculates the sum of the target thread number and the unit thread identification to obtain the light source thread identification corresponding to the thread.
[0142] In one specific embodiment, the light source thread identification can be calculated using formula (3) as shown below.
[0143] LightThreadID=(SV_GroupID-GroupOffset[i-1])*32+SV_GroupThreadID Formula (3)
[0144] Wherein, LightThreadID refers to the light source thread identification, SV_GroupID refers to the target unit identification. GroupOffset[i-1] represents the forward unit accumulation quantity of the light source i. 32 refers to the unit thread quantity of the calculation unit, and the calculation unit includes 32 threads. SV_GroupThreadID refers to the unit thread identification, and is used to represent the number of the current thread in the current calculation unit (from 0 to 31). For example, the forward unit accumulation quantity corresponding to the light source 1 is obtained as 0. The current calculation unit number is obtained as 1, and the unit thread identification is obtained as the number 5, indicating that the current thread is the 6th thread of the current calculation unit number 1 (the number starts from 0), then (1-0)*32+5=37, and the light source thread identification is obtained as 37, that is, the current thread is the 37th thread of the light source 1 for illumination calculation.
[0145] In the above embodiment, by calculating the difference between the target calculation unit identification and the forward unit accumulation quantity, the target unit quantity corresponding to the target light source identification is obtained, the product of the target unit quantity and the unit thread quantity is calculated, the target thread quantity corresponding to the target light source identification is obtained, and finally the light source thread identification corresponding to the thread is determined based on the target thread quantity and the unit thread identification, that is, the light source thread identification can be obtained by calculation through identification, the calculation result can be quickly obtained, and the efficiency of real-time calculation is improved.
[0146] In one embodiment, the target voxel identification includes a target horizontal coordinate identification, a target vertical coordinate identification and a target vertical coordinate identification, as shown in Figure 5 S506, based on the starting voxel identification, the ending voxel identification and the light source thread identification, voxel identification calculation is performed to obtain the target voxel identification corresponding to the thread, including:
[0147] S506a, based on the starting horizontal coordinate identification in the starting voxel identification, the ending horizontal coordinate identification in the ending voxel identification and the light source thread identification, horizontal coordinate identification calculation is performed to obtain the target horizontal coordinate identification;
[0148] S506b, based on the starting vertical coordinate identification in the starting voxel identification, the ending vertical coordinate identification in the ending voxel identification, the starting horizontal coordinate identification, the ending horizontal coordinate identification and the light source thread identification, vertical coordinate identification calculation is performed to obtain the target vertical coordinate identification;
[0149] S506c, based on the starting vertical coordinate identification in the starting voxel identification, the starting vertical coordinate identification, the ending vertical coordinate identification, the starting horizontal coordinate identification, the ending horizontal coordinate identification and the light source thread identification, vertical coordinate identification calculation is performed to obtain the target vertical coordinate identification;
[0150] S506d, the target horizontal coordinate identifier, the target vertical coordinate identifier and the target vertical coordinate identifier are taken as the target voxel identifier corresponding to the thread.
[0151] In this embodiment, the voxel identifier is provided in the form of position coordinates, which can include horizontal coordinate identifier, vertical coordinate identifier and vertical coordinate identifier, i.e. the corresponding voxel is identified by the horizontal coordinate identifier, vertical coordinate identifier and vertical coordinate identifier. When one of the horizontal coordinate identifier, vertical coordinate identifier and vertical coordinate identifier is different, the corresponding voxel is different. The voxel identifier including the horizontal coordinate identifier, vertical coordinate identifier and vertical coordinate identifier can be generated according to the center coordinates of the voxel, or can be obtained by numbering the voxel according to the pre-set order, for example, the horizontal coordinate identifier of the first voxel can be 1, the vertical coordinate identifier can be 1 and the vertical coordinate identifier can be 1, then the identifier of the first voxel can be (1, 1, 1). Then the current thread in the server performs horizontal coordinate identifier calculation, i.e. the horizontal coordinate difference between the terminal horizontal coordinate identifier and the starting horizontal coordinate identifier can be calculated, then the horizontal coordinate difference is divided by the light source thread identifier to obtain the integer division and remainder operation result, then the sum of the integer division and remainder operation result and the starting horizontal coordinate identifier is calculated to obtain the horizontal coordinate identifier of the voxel corresponding to the current thread, i.e. the target horizontal coordinate identifier. Then the current thread in the server performs vertical coordinate identifier calculation. That is, the horizontal coordinate difference between the terminal horizontal coordinate identifier and the starting horizontal coordinate identifier can be calculated, then the vertical coordinate difference between the terminal vertical coordinate identifier and the starting vertical coordinate identifier is calculated, then the product of the two differences is calculated, then the product is divided by the light source thread identifier to obtain the remainder operation result, then the ratio of the remainder operation result to the vertical coordinate difference is calculated, and finally the sum of the ratio and the starting vertical coordinate identifier is calculated to obtain the vertical coordinate identifier of the voxel corresponding to the current thread, i.e. the target vertical coordinate identifier. Then the current thread in the server performs vertical coordinate identifier calculation, i.e. the horizontal coordinate difference between the terminal horizontal coordinate identifier and the starting horizontal coordinate identifier can be calculated, then the vertical coordinate difference between the terminal vertical coordinate identifier and the starting vertical coordinate identifier is calculated, then the product of the two differences is calculated, and the ratio of the product to the light source thread identifier is calculated, and finally the sum of the ratio and the starting vertical coordinate identifier is calculated to obtain the vertical coordinate identifier of the voxel corresponding to the current thread, i.e. the target vertical coordinate identifier. Finally, the target horizontal coordinate identifier, the target vertical coordinate identifier and the target vertical coordinate identifier are taken as the target voxel identifier corresponding to the thread.
[0152] In one specific embodiment, the current thread in the server can obtain the starting voxel coordinate number (Xmin_i, Ymin_i, Zmin_i) and the terminal voxel coordinate number (Xmax_i, Ymax_i, Zmax_i) corresponding to the i-th light source, and then can use the formula (4) shown as follows to calculate the target horizontal coordinate identifier, and then can use the formula (5) shown as follows to calculate the target vertical coordinate identifier, and then can use the formula (6) shown as follows to calculate the target vertical coordinate identifier.
[0153] X0 = LightThreadID % (Xmax_i-Xmin_i+1) + Xmin_i Formula (4)
[0154] Y0 = LightThreadID % [(Xmax_i-Xmin_i+1)* (Ymax_i-Ymin_i+1)] / (Xmax_i-Xmin_i+1) + Ymin_i Formula (5)
[0155] Z0 = LightThreadID / [(Xmax_i-Xmin_i+1)* (Ymax_i-Ymin_i+1)] + Zmin_i Formula (6)
[0156] Wherein, X0 refers to the target horizontal coordinate identifier, Y0 refers to the target vertical coordinate identifier, and Z0 refers to the target vertical coordinate identifier. Xmin_i refers to the starting horizontal coordinate identifier. Ymin_i refers to the starting vertical coordinate identifier. Zmin_i refers to the starting vertical coordinate identifier. Xmax_i refers to the terminal horizontal coordinate identifier. Ymax_i refers to the terminal vertical coordinate identifier. Zmin_i refers to the terminal vertical coordinate identifier. LightThreadID refers to the light source thread identifier.
[0157] In the above embodiment, the horizontal coordinate identifier, the total coordinate identifier, and the vertical coordinate identifier are calculated by using the starting voxel identifier, the terminal voxel identifier, and the light source thread identifier, respectively, so as to improve the accuracy of the obtained target voxel identifier.
[0158] In one specific embodiment, as Figure 6As shown, it is a schematic diagram of the association relationship between the light source, thread and the unit accumulation quantity. Among them, the GPU in the server includes a plurality of computing units, and each computing unit includes 32 threads. The light source i-1 needs to use two computing units when performing light calculation, and the light source 1 needs to use four computing units when performing light calculation. Each light source has a corresponding saved unit accumulation quantity. The current thread is the 8th thread in the third computing unit in the light source i. At this time, the 8th thread is associated with the light source i and the unit accumulation quantity corresponding to the light source i. Then the light source identifier corresponding to the current thread to be calculated for light calculation and the voxel identifier in the light source of the light source identifier to be calculated for light calculation can be calculated according to the association relationship, thereby improving the accuracy of the light source identifier and the voxel identifier calculated by the thread.
[0159] In one embodiment, S208, based on the target light source identifier and the target voxel identifier, the volume fog light calculation is performed to obtain the volume fog light information corresponding to the thread, including the steps of:
[0160] Obtaining the light intensity information corresponding to the target light source identifier and the fog concentration information corresponding to the target voxel identifier; calculating the product of the light intensity information and the fog concentration information to obtain the volume fog light information corresponding to the thread.
[0161] In this embodiment, after the thread running in the server calculates the target light source identifier and the target voxel identifier, the thread obtains the light intensity information corresponding to the target light source identifier and the fog concentration information corresponding to the target voxel identifier. The light intensity information is used to represent the light intensity of the light source of the target light source identifier. The fog concentration information is used to represent the concentration of the volume fog in the voxel space corresponding to the target voxel identifier. The light intensity information and the fog concentration information can be determined when the three-dimensional virtual scene is established. Then the server uses the light intensity information and the fog concentration information to perform light calculation, which can be to calculate the product of the light intensity information and the fog concentration information to obtain the light result of the light source of the target light source identifier on the voxel space of the target voxel identifier, that is, the operation result of the current thread.
[0162] In the above embodiment, the target light source identifier and the target voxel identifier calculated by the thread are used to obtain the parameters required for volume fog light calculation, and then the volume fog light calculation is performed to obtain the volume fog light result, which can enable a large number of threads to simultaneously calculate the light result, thereby improving the efficiency of the light calculation.
[0163] In one embodiment, S210, the volume fog light information corresponding to each thread is fused to obtain the volume fog light fusion information corresponding to the three-dimensional virtual scene, including the steps of:
[0164] Determine the volume fog lighting information corresponding to each voxel in the three-dimensional virtual scene from the volume fog lighting information corresponding to each thread respectively; accumulate the volume fog lighting information corresponding to each voxel to obtain volume fog lighting accumulation information corresponding to each voxel; traverse each voxel in the three-dimensional virtual scene to obtain volume fog lighting accumulation information corresponding to each voxel respectively, and use the volume fog lighting accumulation information corresponding to each voxel respectively as the volume fog lighting fusion information corresponding to the three-dimensional virtual scene.
[0165] In the embodiment, the same voxel space in the three-dimensional virtual scene can be within the lighting range of different light sources. At this time, different threads calculate the lighting results of the same voxel illuminated by different light sources. The server can find the volume fog lighting information corresponding to the same voxel from the volume fog lighting information corresponding to each thread respectively according to the voxel identifier, then accumulate the volume fog lighting information corresponding to the same voxel to obtain volume fog lighting accumulation information corresponding to the voxel. Finally, the server traverses all voxels involved in the lighting range of the light source in the three-dimensional virtual scene to obtain the volume fog lighting accumulation information of each voxel, and then uses the volume fog lighting accumulation information of each voxel to perform volume fog rendering of the three-dimensional virtual scene.
[0166] In the above embodiment, by accumulating the volume fog lighting information corresponding to each voxel in the three-dimensional virtual scene, the volume fog lighting accumulation information corresponding to each voxel respectively is obtained, thereby improving the accuracy of the obtained lighting result, and then using the volume fog lighting accumulation information corresponding to each voxel respectively for volume fog rendering improves the accuracy of volume fog rendering.
[0167] In a specific embodiment, as shown in Figure 7 a volume fog rendering method is provided, which is executed by a computer device, which can be a terminal or a server, and specifically includes the following steps:
[0168] S702, obtain the light source range information of at least two light source identifiers in the three-dimensional virtual scene, and for each light source identifier, determine the corresponding light source enclosing space based on the range coordinates in the light source range information of the light source identifier, obtain the projection parameters of the camera view cone space corresponding to the three-dimensional virtual scene, and perform projection calculation on the light source enclosing space based on the projection parameters to obtain the light source view cone space corresponding to each of the at least two light source identifiers.
[0169] S704, for each light source identifier, obtain the start voxel identifier and the end voxel identifier in the light source view cone space corresponding to the light source identifier, and determine the number of voxels in the light source view cone space corresponding to the light source identifier based on the difference between the start voxel identifier and the end voxel identifier.
[0170] S706, for each light source identifier, obtain the number of unit threads of the computing unit, perform ratio calculation based on the number of voxels and the number of unit threads, obtain the number of computing units corresponding to the light source identifier, perform summation calculation based on the number of computing units and the number of unit threads, obtain the number of threads corresponding to the light source identifier, and count the total number of threads.
[0171] S708, count the total number of computing units, and sequentially perform accumulation calculation on the number of computing units corresponding to at least two light source identifiers respectively to obtain the accumulated number of computing units corresponding to at least two light source identifiers respectively, and run the threads in each computing unit according to the total number of computing units.
[0172] S710, for each thread, obtain the target computing unit identifier corresponding to the thread based on the identification information of the thread, compare the target computing unit identifier with each accumulated number of computing units in sequence, when the target accumulated number of computing units is greater than or equal to the target computing unit identifier and the forward accumulated number of computing units corresponding to the target accumulated number of computing units is less than the target computing unit identifier, take the light source identifier corresponding to the target accumulated number of computing units as the target light source identifier corresponding to the thread.
[0173] S712, for each thread, obtain the forward accumulated number of computing units corresponding to the target computing unit identifier, calculate the difference between the target computing unit identifier and the forward accumulated number of computing units to obtain the target number of computing units corresponding to the target light source identifier, calculate the product of the target number of computing units and the number of unit threads to obtain the target number of threads corresponding to the target light source identifier, obtain the unit thread identifier corresponding to the thread, and determine the light source thread identifier corresponding to the thread based on the target number of threads and the unit thread identifier.
[0174] S714, for each thread, obtain the start voxel identifier and the end voxel identifier in the light source view frustum space, perform horizontal coordinate identifier calculation based on the start horizontal coordinate identifier in the start voxel identifier, the end horizontal coordinate identifier in the end voxel identifier, and the light source thread identifier to obtain the target horizontal coordinate identifier, perform vertical coordinate identifier calculation based on the start vertical coordinate identifier in the start voxel identifier, the end vertical coordinate identifier in the end voxel identifier, the start horizontal coordinate identifier, the end horizontal coordinate identifier, and the light source thread identifier to obtain the target vertical coordinate identifier, perform vertical coordinate identifier calculation based on the start vertical coordinate identifier in the start voxel identifier, the start vertical coordinate identifier, the end vertical coordinate identifier, the start horizontal coordinate identifier, the end horizontal coordinate identifier, and the light source thread identifier to obtain the target vertical coordinate identifier, and take the target horizontal coordinate identifier, the target vertical coordinate identifier, and the target vertical coordinate identifier as the target voxel identifier corresponding to the thread.
[0175] S716, for each thread, obtaining the corresponding light intensity information of the target light source identifier and the corresponding fog density information of the target voxel identifier, calculating the product of the light intensity information and the fog density information, and obtaining the volume fog light information corresponding to the thread.
[0176] S718, fusing the volume fog light information corresponding to each thread respectively to obtain the volume fog light fusion information corresponding to the three-dimensional virtual scene, and performing volume fog rendering in the three-dimensional virtual scene based on the volume fog light fusion information to obtain the target volume fog in the three-dimensional virtual scene.
[0177] In the embodiment, steps S702 to S708 can be executed by the CPU in the computer device, and then steps S710 to S716 can be executed by the GPU in the computer device, and then step 718 can be executed by the CPU in the computer device. That is, the light calculation of the voxels in the light range of the light source is performed in parallel by each thread in the GPU of the computer device to obtain the light result, and the light calculation of the voxels outside the light range of the light source is not needed, which reduces the task amount of light calculation and improves the efficiency. Moreover, the threads in each calculation unit are simultaneously run according to the total number of units by the GPU, which does not need to run the threads linearly according to the light sources, saves the running overhead of the threads in the GPU, and further improves the efficiency.
[0178] In one specific embodiment, the volume fog rendering method can be applied to a game virtual scene, specifically: Figure 8As shown, it is a schematic diagram of a game virtual scene, which is a virtual scene of a dark night, and there are hundreds of spotlights in the virtual scene of the dark night, the white area outside the black area in the figure is the light range of the hundreds of spotlights, the light area is far away from the light source, and the dark white area is close to the light source. Then volume fog rendering is performed on the game virtual scene, that is, the server obtains the light source range information of each spotlight in the game virtual scene, and then calculates the light source view cone space corresponding to each spotlight. Then the number of calculation units and the number of threads required for each spotlight to perform light calculation are calculated, and the total number of threads is counted, and the number of units accumulated by each spotlight is calculated and saved. The server runs the same number of calculation units in the GPU according to the number of calculation units, and then each running thread in the calculation unit calculates the corresponding spotlight number and the voxel number in the game virtual scene. The thread obtains the parameters required for light calculation according to the spotlight number and the voxel number in the game virtual scene, and then performs light calculation using the obtained parameters to obtain the light result of the voxel space calculated by the thread. Then the light result calculated by each thread is accumulated in the data buffer area of the voxel, so as to obtain the light accumulation result of each voxel in the light range of the game virtual scene. Then the light accumulation result of each voxel in the light range of the game virtual scene is used for volume fog rendering, so as to obtain the volume fog of the game virtual scene under a large number of spotlights, that is, by calculating the light accumulation result of each voxel in the light range, the efficiency of light calculation is improved, and then the efficiency of volume fog rendering is improved. Then, the comparison test is performed, and the GPU running time is intercepted using the Nsight (GPU debugging and performance analysis tool) tool, as shown in Figure 9 As shown, it is a schematic diagram of time consumption of volume fog rendering using a conventional light accumulation method, and the volume fog rendering lasts for 60 milliseconds (ms), and almost all of the time consumption is 59.51 milliseconds of the light accumulation part. As shown in Figure 10 As shown, it is a schematic diagram of time consumption of volume fog rendering using the volume fog rendering method in the present application, and the volume fog rendering consumes only about 3 milliseconds, and the light accumulation part consumes about 2.2 milliseconds, which significantly improves the rendering efficiency of volume fog in a large number of light source scenes. The volume fog rendering method in the present application can be applied to a film and television virtual scene to improve the efficiency of volume fog rendering in a film and television virtual scene with a large number of light sources, and can also be applied to a building virtual scene and other three-dimensional virtual scenes with a large number of light sources to improve the efficiency of volume fog rendering.
[0179] It should be understood that although the steps in the flowcharts involved in the embodiments described above are shown in sequence according to the arrows, the steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of the steps is not strictly limited in sequence, and the steps can be executed in other orders. Moreover, at least some of the steps in the flowcharts involved in the embodiments described above can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of the steps or stages is not necessarily sequential, but can be alternately or alternately executed with at least part of other steps or steps or stages in other steps.
[0180] Based on the same inventive concept, the embodiments of the present application also provide a volume fog rendering device for implementing the volume fog rendering method described above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more volume fog rendering device embodiments provided below can refer to the limitations of the volume fog rendering method described above, which will not be repeated here.
[0181] In one embodiment, as shown in Figure 11 A volume fog rendering device 1100 is provided, including a projection module 1102, a quantity determination module 1104, an information obtaining module 1106, an illumination calculation module 1108, and a rendering module 1110, wherein:
[0182] The projection module 1102 is configured to obtain light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculate a projection of the light source range information in a three-dimensional virtual scene corresponding camera frustum space, to obtain a light source frustum space corresponding to each of the at least two light source identifiers.
[0183] The quantity determination module 1104 is configured to determine a thread quantity corresponding to each of the at least two light source identifiers based on a voxel quantity in the light source frustum space corresponding to each of the at least two light source identifiers, and count a total thread quantity of the thread quantities.
[0184] The information obtaining module 1106 is configured to perform light source identification information calculation based on the thread quantity corresponding to each of the at least two light source identifiers, to obtain light source identification information corresponding to each of the at least two light source identifiers.
[0185] The light calculation module 1108 is configured to run threads according to a total number of threads, and for each thread, determine a target light source identifier corresponding to the thread based on a mapping relationship between identifier information of the thread and light source identification information, determine a target voxel identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and a voxel in a target light cone space corresponding to the target light source identifier, and perform volume fog light calculation based on the target light source identifier and the target voxel identifier to obtain volume fog light information corresponding to the thread.
[0186] The rendering module 1110 is configured to fuse the volume fog light information corresponding to each thread to obtain volume fog light fusion information corresponding to the three-dimensional virtual scene, and perform volume fog rendering in the three-dimensional virtual scene based on the volume fog light fusion information to obtain a target volume fog in the three-dimensional virtual scene.
[0187] In an embodiment, the projection module 1102 is further configured to, for each light source identifier, determine a corresponding light source enclosing space based on range coordinates in light source range information of the light source identifier, obtain projection parameters of a camera view cone space corresponding to the three-dimensional virtual scene, and perform projection calculation on the light source enclosing space based on the projection parameters to obtain light cone spaces corresponding to the at least two light source identifiers.
[0188] In an embodiment, the quantity determination module 1104 is further configured to, for each light source identifier, obtain a start voxel identifier and an end voxel identifier in a light cone space corresponding to the light source identifier, determine a number of voxels in the light cone space corresponding to the light source identifier based on a difference between the start voxel identifier and the end voxel identifier, and determine a number of threads corresponding to the light source identifier based on the number of voxels.
[0189] In an embodiment, the quantity determination module 1104 is further configured to obtain a number of unit threads of a calculation unit, perform ratio calculation based on the number of voxels and the number of unit threads to obtain a number of calculation units corresponding to the light source identifier, and perform summation calculation based on the number of calculation units and the number of unit threads to obtain the number of threads corresponding to the light source identifier.
[0190] In an embodiment, the information obtaining module 1106 is further configured to obtain a number of calculation units corresponding to the at least two light source identifiers, and count a total number of units; sequentially perform accumulation calculation on the number of calculation units corresponding to the at least two light source identifiers to obtain unit accumulation numbers corresponding to the at least two light source identifiers; and obtain light source identification information corresponding to the at least two light source identifiers by taking the unit accumulation numbers as the light source identification information.
[0191] The light calculation module 1108 is further configured to run threads in each calculation unit according to the total number of units.
[0192] In an embodiment, the information obtaining module 1106 is further configured to sequentially perform accumulation calculation on the respective thread numbers corresponding to the at least two light source identifications respectively, to obtain thread accumulation numbers corresponding to the at least two light source identifications respectively; and obtain the light source identification information by taking the thread accumulation numbers as the light source identification information.
[0193] In an embodiment, the light calculation module 1108 is further configured to match the identification information of the thread with the light source identification information corresponding to the at least two light source identifications based on a mapping relationship between the identification information of the thread and the light source identification information, to obtain target light source identification information matched by the thread, the mapping relationship being used to represent a condition for matching the identification information of the thread with the light source identification information successfully; and take the light source identification corresponding to the target light source identification information as the target light source identification corresponding to the thread.
[0194] In an embodiment, the light source identification information includes the thread accumulation numbers, and the light calculation module 1108 is further configured to sequentially compare the identification information of the thread with each thread accumulation number, and when a target thread accumulation number in the thread accumulation numbers is greater than or equal to the identification information of the thread and a forward thread accumulation number corresponding to the target thread accumulation number is less than the identification information of the thread, take the target thread accumulation number as the target light source identification information matched by the thread.
[0195] In an embodiment, the light source identification information includes the unit accumulation numbers, and the light calculation module 1108 is further configured to obtain a target calculation unit identification corresponding to the identification information of the thread, and sequentially compare the target calculation unit identification with each unit accumulation number; when a target unit accumulation number in the unit accumulation numbers is greater than or equal to the target calculation unit identification and a forward unit accumulation number corresponding to the target unit accumulation number is less than the target calculation unit identification, take the target unit accumulation number as the target light source identification information matched by the thread.
[0196] In an embodiment, the light calculation module 1108 is further configured to obtain a target calculation unit identification corresponding to the identification information of the thread, and obtain a forward unit accumulation number corresponding to the target calculation unit identification; perform light source thread identification calculation based on the target calculation unit identification, the forward unit accumulation number and a unit thread identification of the thread, to obtain a light source thread identification corresponding to the thread; obtain a start voxel identification and an end voxel identification in a light source view volume, and perform voxel identification calculation based on the start voxel identification, the end voxel identification and the light source thread identification, to obtain a target voxel identification corresponding to the thread.
[0197] In an embodiment, the light calculation module 1108 is further configured to calculate a difference between the target calculation unit identifier and the forward unit accumulation number, to obtain a target unit number corresponding to the target light source identifier; obtain a unit thread number of the calculation unit, and calculate a product of the target unit number and the unit thread number, to obtain a target thread number corresponding to the target light source identifier; obtain a unit thread identifier corresponding to the thread, and determine a light source thread identifier corresponding to the thread based on the target thread number and the unit thread identifier.
[0198] In an embodiment, the light calculation module 1108 is further configured to perform horizontal coordinate identifier calculation based on a starting horizontal coordinate identifier in the starting voxel identifier, a terminal horizontal coordinate identifier in the terminal voxel identifier, and the light source thread identifier, to obtain a target horizontal coordinate identifier; perform vertical coordinate identifier calculation based on a starting vertical coordinate identifier in the starting voxel identifier, a terminal vertical coordinate identifier in the terminal voxel identifier, the starting horizontal coordinate identifier, the terminal horizontal coordinate identifier, and the light source thread identifier, to obtain a target vertical coordinate identifier; perform vertical coordinate identifier calculation based on a starting vertical coordinate identifier in the starting voxel identifier, the starting vertical coordinate identifier, the terminal vertical coordinate identifier, the starting horizontal coordinate identifier, the terminal horizontal coordinate identifier, and the light source thread identifier, to obtain a target vertical coordinate identifier; and take the target horizontal coordinate identifier, the target vertical coordinate identifier, and the target vertical coordinate identifier as a target voxel identifier corresponding to the thread.
[0199] In an embodiment, the light calculation module 1108 is further configured to obtain light intensity information corresponding to the target light source identifier, and obtain fog density information corresponding to the target voxel identifier; and calculate a product of the light intensity information and the fog density information, to obtain volume fog light information corresponding to the thread.
[0200] In an embodiment, the rendering module 1110 is further configured to determine, from the volume fog light information corresponding to each thread respectively, volume fog light information corresponding to each voxel in the three-dimensional virtual scene; accumulate the volume fog light information corresponding to each voxel, to obtain volume fog light accumulation information corresponding to each voxel; and traverse each voxel in the three-dimensional virtual scene, to obtain volume fog light accumulation information corresponding to each voxel respectively, and take the volume fog light accumulation information corresponding to each voxel respectively as volume fog light fusion information corresponding to the three-dimensional virtual scene.
[0201] The above modules in the volume fog rendering apparatus can be implemented by software, hardware, or a combination thereof, in whole or in part. The above modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in the computer device in software form, so as to be called and executed by a processor to perform operations corresponding to the above modules.
[0202] In an embodiment, a computer device is provided, which can be a server, and an internal structure diagram of the computer device can be as shown in FIG. 8. Figure 12As shown in the figure. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through the system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control ability. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store three-dimensional virtual scene, light source identification, light source range information, camera view cone space and voxel identification and other data. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with the terminal outside through the network connection. The computer program is executed by the processor to implement a volume fog virtual method.
[0203] In one embodiment, a computer device is provided, which can be a terminal, and its internal structure diagram can be as shown in the figure. Figure 13 As shown in the figure. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through the system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control ability. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store three-dimensional virtual scene, light source identification, light source range information, camera view cone space and voxel identification and other data. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with the terminal outside through the network connection. The computer program is executed by the processor to implement a volume fog virtual method.
[0204] Those skilled in the art can understand that, Figure 12 Or Figure 13The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0205] In one embodiment, a computer device is also provided, including a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method embodiments when executing the computer program.
[0206] In one embodiment, a computer readable storage medium is provided, storing a computer program, and the computer program implements the steps in the above method embodiments when executed by a processor.
[0207] In one embodiment, a computer program product is provided, including a computer program, and the computer program implements the steps in the above method embodiments when executed by a processor.
[0208] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0209] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0210] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.
[0211] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A method of volume fog rendering, characterized by, The method comprises: acquiring light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculating projection of the light source range information in a camera frustum space corresponding to the three-dimensional virtual scene to obtain light source frustum spaces corresponding to the at least two light source identifiers respectively; determining thread numbers corresponding to the at least two light source identifiers respectively based on voxel numbers in the light source frustum spaces corresponding to the at least two light source identifiers respectively, and counting a total number of threads of the thread numbers; performing light source identification information calculation based on the thread numbers corresponding to the at least two light source identifiers respectively to obtain light source identification information corresponding to the at least two light source identifiers respectively; running each thread according to the total number of threads, and for each thread, determining a target light source identifier corresponding to the thread based on a mapping relationship between identifier information of the thread and the light source identification information, determining a target voxel identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and voxels in a light source frustum space corresponding to the target light source identifier, and performing volume fog lighting calculation based on the target light source identifier and the target voxel identifier to obtain volume fog lighting information corresponding to the thread; fusing the volume fog lighting information corresponding to each thread respectively to obtain volume fog lighting fusion information corresponding to the three-dimensional virtual scene, and performing volume fog rendering in the three-dimensional virtual scene based on the volume fog lighting fusion information to obtain a target volume fog in the three-dimensional virtual scene.
2. The method of claim 1, wherein, The calculation of the projection of the light source range information in the camera frustum space corresponding to the three-dimensional virtual scene to obtain the light source frustum spaces corresponding to the at least two light source identifiers respectively comprises: for each light source identifier, determining a corresponding light source enclosing space based on range coordinates in the light source range information of the light source identifier; acquiring projection parameters of the camera frustum space corresponding to the three-dimensional virtual scene, and performing projection calculation on the light source enclosing space based on the projection parameters to obtain the light source frustum spaces corresponding to the at least two light source identifiers respectively.
3. The method of claim 1, wherein, The determination of the thread numbers corresponding to the at least two light source identifiers respectively based on the voxel numbers in the light source frustum spaces corresponding to the at least two light source identifiers respectively comprises: for each light source identifier, acquiring a start voxel identifier and an end voxel identifier in the light source frustum space corresponding to the light source identifier; determining the voxel number in the light source frustum space corresponding to the light source identifier based on a difference between the start voxel identifier and the end voxel identifier, and determining the thread number corresponding to the light source identifier based on the voxel number.
4. The method of claim 3, wherein, The determination of the thread number corresponding to the light source identifier based on the voxel number comprises: acquiring a unit thread number of a calculation unit, performing ratio calculation based on the voxel number and the unit thread number to obtain a calculation unit number corresponding to the light source identifier; performing summation calculation based on the calculation unit number and the unit thread number to obtain the thread number corresponding to the light source identifier.
5. The method of claim 1, wherein, The light source identification information is calculated based on the thread number corresponding to each of the at least two light source identifiers, and the light source identification information corresponding to each of the at least two light source identifiers is obtained, including: The number of calculation units corresponding to each of the at least two light source identifiers is obtained, and the total number of units is counted; The number of calculation units corresponding to each of the at least two light source identifiers is sequentially accumulated, and the accumulated number of units corresponding to each of the at least two light source identifiers is obtained; The accumulated number of units is taken as the light source identification information, and the light source identification information corresponding to each of the at least two light source identifiers is obtained; The threads are run according to the total number of threads. The threads in each calculation unit are run according to the total number of units.
6. The method of claim 1, wherein, The light source identification information is calculated based on the thread number corresponding to each of the at least two light source identifiers, and the light source identification information corresponding to each of the at least two light source identifiers is obtained, including: The thread number corresponding to each of the at least two light source identifiers is sequentially accumulated, and the accumulated thread number corresponding to each of the at least two light source identifiers is obtained; The accumulated thread number is taken as the light source identification information, and the light source identification information corresponding to each of the at least two light source identifiers is obtained.
7. The method of claim 1, wherein, The target light source identifier corresponding to the thread is determined based on the mapping relationship between the thread-based identifier information and the light source identification information, including: The mapping relationship between the thread-based identifier information and the light source identification information is used to represent the condition for matching the thread-based identifier information and the light source identification information successfully. The light source identifier corresponding to the target light source identification information is taken as the target light source identifier corresponding to the thread.
8. The method of claim 7, wherein, The light source identification information includes the accumulated thread number, and the mapping relationship between the thread-based identifier information and the light source identification information is used to match the thread-based identifier information and the light source identification information corresponding to each of the at least two light source identifiers, and obtain the target light source identification information matched by the thread, including: The thread-based identifier information is sequentially compared with each accumulated thread number. When the target accumulated thread number in the accumulated thread numbers is greater than or equal to the thread-based identifier information and the forward accumulated thread number corresponding to the target accumulated thread number is less than the thread-based identifier information, the target accumulated thread number is taken as the target light source identification information matched by the thread.
9. The method of claim 7, wherein, The light source identification information includes the accumulated unit number, and the thread-based identifier information is matched with each light source identification information to obtain the target light source identification information corresponding to the thread, including: The target calculation unit identifier corresponding to the thread-based identifier information is obtained, and the target calculation unit identifier is sequentially compared with each accumulated unit number. When the target unit accumulation number of the respective unit accumulations is greater than or equal to the target calculation unit identifier and the forward unit accumulation number corresponding to the target unit accumulation number is less than the target calculation unit identifier, the target unit accumulation number is taken as the target light source identification information matched by the thread.
10. The method of claim 1, wherein, The mapping relationship between the identification information of the thread and the target light source identifier is used to determine the target voxel identifier corresponding to the thread, including: The target calculation unit identifier corresponding to the thread is obtained based on the identification information of the thread, and the forward unit accumulation number corresponding to the target calculation unit identifier is obtained. Light source thread identification calculation is performed based on the target calculation unit identifier, the forward unit accumulation number and the unit thread identifier of the thread, to obtain the light source thread identifier corresponding to the thread. The start voxel identifier and the end voxel identifier in the light source view cone space are obtained, and voxel identifier calculation is performed based on the start voxel identifier, the end voxel identifier and the light source thread identifier, to obtain the target voxel identifier corresponding to the thread.
11. The method of claim 10, wherein, The light source thread identification calculation based on the target calculation unit identifier, the forward unit accumulation number and the unit thread identifier of the thread to obtain the light source thread identifier corresponding to the thread includes: The difference between the target calculation unit identifier and the forward unit accumulation number is calculated to obtain the target unit number corresponding to the target light source identifier. The unit thread number of the calculation unit is obtained, and the product of the target unit number and the unit thread number is calculated to obtain the target thread number corresponding to the target light source identifier. The unit thread identifier corresponding to the thread is obtained, and the light source thread identifier corresponding to the thread is determined based on the target thread number and the unit thread identifier.
12. The method of claim 10, wherein, The target voxel identifier includes a target horizontal coordinate identifier, a target vertical coordinate identifier and a target vertical coordinate identifier; the voxel identifier calculation based on the start voxel identifier, the end voxel identifier and the light source thread identifier to obtain the target voxel identifier corresponding to the thread includes: The horizontal coordinate identifier calculation is performed based on the start horizontal coordinate identifier in the start voxel identifier, the end horizontal coordinate identifier in the end voxel identifier and the light source thread identifier, to obtain the target horizontal coordinate identifier. The vertical coordinate identifier calculation is performed based on the start vertical coordinate identifier in the start voxel identifier, the start horizontal coordinate identifier, the end horizontal coordinate identifier and the light source thread identifier, to obtain the target vertical coordinate identifier. The vertical coordinate identifier calculation is performed based on the start vertical coordinate identifier in the start voxel identifier, the start vertical coordinate identifier, the end vertical coordinate identifier, the start horizontal coordinate identifier, the end horizontal coordinate identifier and the light source thread identifier, to obtain the target vertical coordinate identifier. The target horizontal coordinate identifier, the target vertical coordinate identifier and the target vertical coordinate identifier are taken as the target voxel identifier corresponding to the thread.
13. The method of claim 1, wherein, The volume fog light calculation based on the target light source identifier and the target voxel identifier obtains volume fog light information corresponding to the thread, and includes: Obtain the light intensity information corresponding to the target light source identifier, and obtain the fog concentration information corresponding to the target voxel identifier; Calculate the product of the light intensity information and the fog concentration information to obtain the volume fog light information corresponding to the thread.
14. The method of claim 1, wherein, The volume fog light information corresponding to each thread is fused to obtain the volume fog light fusion information corresponding to the three-dimensional virtual scene, and includes: Determine the volume fog light information corresponding to each voxel in the three-dimensional virtual scene from the volume fog light information corresponding to each thread; Accumulate the volume fog light information corresponding to each voxel to obtain the volume fog light accumulation information corresponding to the voxel; Iterate through each voxel in the three-dimensional virtual scene to obtain the volume fog light accumulation information corresponding to each voxel, and use the volume fog light accumulation information corresponding to each voxel as the volume fog light fusion information corresponding to the three-dimensional virtual scene.
15. A volume fog rendering apparatus, characterized by, The device includes: A projection module configured to obtain light source range information of at least two light source identifiers in a three-dimensional virtual scene, and calculate projections of the light source range information in a camera view cone space corresponding to the three-dimensional virtual scene to obtain light source view cone spaces corresponding to the at least two light source identifiers respectively; A quantity determination module configured to determine the number of threads corresponding to the at least two light source identifiers based on the number of voxels in the light source view cone spaces corresponding to the at least two light source identifiers respectively, and count the total number of threads corresponding to the number of threads; An information obtaining module configured to calculate light source identification information corresponding to the at least two light source identifiers based on the number of threads corresponding to the at least two light source identifiers respectively; A light calculation module configured to run each thread according to the total number of threads, determine a target light source identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and the light source identification information, determine a target voxel identifier corresponding to the thread based on a mapping relationship between the identifier information of the thread and voxels in the light source view cone space corresponding to the target light source identifier, and perform volume fog light calculation based on the target light source identifier and the target voxel identifier to obtain volume fog light information corresponding to the thread; A rendering module configured to fuse the volume fog light information corresponding to each thread to obtain volume fog light fusion information corresponding to the three-dimensional virtual scene, and perform volume fog rendering in the three-dimensional virtual scene based on the volume fog light fusion information to obtain a target volume fog in the three-dimensional virtual scene. 16.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-15. The processor executes the computer program to implement the steps of the method of any one of claims 1 to 14.
17. A computer readable storage medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 14.
18. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 14.