Scene rendering method and device, electronic equipment and storage medium
By sampling the direction of the light source in scene rendering and superimposing it with historical light and shadow effects, the problem of large amount of calculation of the ray tracing algorithm is solved, the performance requirements of hardware equipment are reduced, and real-time rendering of realistic scene image frames is achieved.
Patent Information
- Application Number
- CN202411361082.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2024-12-27
AI Technical Summary
In the prior art, scene rendering based on ray tracing algorithms requires high-performance hardware equipment, which has a large amount of calculation, resulting in high performance requirements of hardware equipment, making it difficult to render realistic scene image frames in real time.
When the target scene is updated, the lighting direction of the light source is sampled, direct lighting rendering is performed, combined with the current and historical light and shadow effects to superimpose it, and the image frame is rendered using the direct lighting model to reduce the amount of ray tracing calculation.
While maintaining the scene realistic, the performance requirements of hardware devices are reduced, rendering efficiency is improved, real-time rendering is realized, and the time required to generate images per frame is reduced.
Smart Images

Figure CN119206030A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a scene rendering method, device, electronic device and storage medium. Background Art
[0002] In the field of image processing technology, physical objects can be modeled based on digital twin technology to obtain virtual objects. Accordingly, a virtual system including virtual objects can be obtained by modeling the physical objects included in the physical system. After running the virtual system, the operating status and performance of the virtual system can be monitored, and the obtained monitoring results can indicate the operating status and performance of the physical system. Obviously, when the virtual object is closer to the physical object, that is, the virtual object is more realistic, the operating status and performance of the physical system indicated by the monitoring results are more accurate. Furthermore, the physical system is optimized based on more accurate operating status and performance, and the optimization effect is better. In order to obtain a more realistic virtual object, the light and shadow effects of the physical object under the illumination of the light source can be simulated according to the light source of the scene where the physical system is located. The light and shadow effects include illumination effects and shadow effects; then the light and shadow effects are added to the virtual object.
[0003] In the related art, the light map can be pre-calculated by baking the scene based on the ray tracing algorithm. That is, each ray in the scene is tracked, and the light and shadow effect produced by each reflection of each ray in the scene is determined. Then, the light and shadow effect produced by each reflection of each ray is combined to simulate the light and shadow effect of the physical object under the light source, and the simulated light and shadow effect is pre-stored in the light map. Then, the light and shadow effect is added to the virtual object based on the light map to obtain the image frame of the scene.
[0004] However, the amount of calculation involved in the ray tracing algorithm is extremely large, which means that based on the existing technology, it is necessary to use hardware devices with higher performance to render realistic scenes, that is, high performance requirements are placed on the hardware devices. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a scene rendering method, device, electronic device and storage medium, so as to reduce the performance requirements of hardware devices while obtaining realistic scene image frames. The specific technical solutions are as follows:
[0006] In a first aspect of an embodiment of the present application, a scene rendering method is first provided, the method comprising: when a target scene is updated, sampling the illumination direction currently generated by a light source in the target scene to obtain a current direction to be processed; performing direct illumination rendering on the target scene according to the light in the current direction to be processed to obtain a light and shadow effect corresponding to the image frame currently to be generated of the target scene as the current light and shadow effect to be superimposed; wherein the light and shadow effect to be superimposed comprises: the illumination intensity at each virtual position on the surface of a virtual object in the target scene under the illumination of the light in the current direction to be processed; superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the image frame currently to be generated; based on the superimposed light and shadow effect corresponding to the image frame currently to be generated and an attribute map representing the attributes of the virtual object itself in the target scene, rendering the target scene using a direct illumination model to obtain the image frame currently to be generated, and returning to execute the step of sampling the illumination direction currently generated by the light source in the target scene to obtain the current direction to be processed, until a preset number of image frames are obtained after the target scene is updated.
[0007] Optionally, the illumination direction currently generated by the light source in the target scene is sampled to obtain the current direction to be processed, including: generating a random number within a specified numerical range as a first random number; if the generated first random number is greater than the ambient scattered light probability weight, randomly generating an illumination direction in the target scene to obtain the current direction to be processed; wherein the ambient scattered light probability weight represents the reflectivity of the target scene; the ambient scattered light probability weight belongs to the specified numerical range; if the generated first random number is not greater than the ambient scattered light probability weight, performing random sampling based on the probability distribution representing the direction of the incident light of the light source in the target scene to obtain the current direction to be processed.
[0008] Optionally, there are multiple first random numbers;
[0009] The target scene is directly illuminated and rendered according to the light from the current direction to be processed, and the light and shadow effects corresponding to the image frame to be generated of the target scene are obtained as the current light and shadow effects to be superimposed, including: for each first random number, the target scene is directly illuminated and rendered according to the light from the direction to be processed obtained based on the first random number, and the light and shadow effects for the image frame to be generated of the target scene for the first random number are obtained; and the average level of the light and shadow effects rendered using each first random number is calculated as the current light and shadow effects to be superimposed.
[0010] Optionally, the probability distribution is a normal distribution with the main direction of the incident light of the light source as the center and the scattering degree of the light source as the variance.
[0011] Optionally, the random sampling is performed based on the probability distribution representing the direction of the incident light of the light source in the target scene to obtain the current direction to be processed, including: generating a random number in the range of 0 to 1 as a second random number; determining the direction whose corresponding probability in the normal distribution is the second random number to obtain the current direction to be processed.
[0012] Optionally, before superimposing the current light and shadow effect to be superimposed with the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated, the method also includes: obtaining the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated from the current inactivated light map; superimposing the current light and shadow effect to be superimposed with the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated, including: determining the light intensity at the same virtual position in the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map; superimposing the determined light intensities at the same virtual position to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; After superimposing the current light and shadow effects to be superimposed and the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effects corresponding to the current image frame to be generated, the method further includes: recording the superimposed light and shadow effects corresponding to the current image frame to be generated in the current activated light map according to the pre-recorded mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map; adjusting the current activated light map to an inactivated state, and adjusting the current inactivated light map to an activated state; based on the superimposed light and shadow effects corresponding to the current image frame to be generated and the attribute map representing the attributes of the virtual object itself in the target scene, rendering the target scene using a direct illumination model to obtain the current image frame to be generated, including: based on the current inactivated light map and the attribute map representing the attributes of the virtual object itself in the target scene, rendering the target scene using a direct illumination model to obtain the current image frame to be generated.
[0013] Optionally, the light intensities at the same determined virtual positions are superimposed to obtain the superimposed light and shadow effects corresponding to the image frame to be generated, including: according to the first weight of the current light and shadow effects to be superimposed, and the second weight of the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated, the light intensities at the same determined virtual positions are superimposed to obtain the superimposed light and shadow effects corresponding to the image frame to be generated; wherein the sum of the first weight and the second weight is 1, and the first weight is the reciprocal of the sum of the preset number and the specified positive integer.
[0014] Optionally, the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map are consistent with the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, and are determined by arranging the bounding boxes of the virtual objects in the target scene based on a greedy algorithm.
[0015] Optionally, the update of the target scene includes: an update of a virtual object in the target scene, and / or an update of a light source in the target scene; the update of the virtual object in the target scene includes at least one of the following: an update of the position of the virtual object in the target scene, an update of the shape of the virtual object in the target scene, and an update of the number of virtual objects in the target scene; the update of the light source in the target scene includes at least one of the following: an update of the type of the light source in the target scene, an update of the position of the light source in the target scene, an update of the illumination intensity of the light source in the target scene, and an update of the number of light sources in the target scene.
[0016] Optionally, the attribute map includes at least one of the following: a color map, a normal map, and a material map.
[0017] Optionally, the method further includes: based on the superimposed light and shadow effects used when obtaining a preset number of image frames after the target scene is updated, and the attribute map, rendering the target scene using a direct lighting model to obtain image frames until the target scene is updated again.
[0018] In a second aspect of an embodiment of the present application, a scene rendering device is provided, the device comprising:
[0019] A sampling module, used for sampling the illumination direction currently generated by the light source in the target scene when the target scene is updated, to obtain the current direction to be processed;
[0020] A first rendering module is used to perform direct illumination rendering on the target scene according to the light in the current direction to be processed, and obtain the light and shadow effect corresponding to the image frame to be generated currently of the target scene as the current light and shadow effect to be superimposed; wherein the light and shadow effect to be superimposed includes: the light intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the light in the current direction to be processed;
[0021] A superposition module, used for superimposing the current light and shadow effect to be superimposed with the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated;
[0022] The second rendering module is used to render the target scene using a direct lighting model based on the superimposed light and shadow effects corresponding to the current image frame to be generated and the attribute map representing the attributes of the virtual object itself in the target scene, to obtain the current image frame to be generated, and return to execute the step of sampling the lighting direction currently generated by the light source in the target scene to obtain the current direction to be processed, until a preset number of image frames are obtained after the target scene is updated.
[0023] Optionally, the sampling module is specifically used to: generate a random number within a specified numerical range as a first random number; if the generated first random number is greater than the ambient scattered light probability weight, randomly generate a lighting direction in the target scene to obtain a current direction to be processed; wherein the ambient scattered light probability weight represents the reflectivity of the target scene; the ambient scattered light probability weight belongs to the specified numerical range; if the generated first random number is not greater than the ambient scattered light probability weight, perform random sampling based on the probability distribution representing the direction of incident light of the light source in the target scene to obtain the current direction to be processed.
[0024] Optionally, there are multiple first random numbers;
[0025] The superposition module is specifically used to: for each first random number, directly illuminate the target scene according to the light in the direction to be processed obtained based on the first random number, to obtain the light and shadow effect of the image frame to be generated currently in the target scene for the first random number; calculate the average level of the light and shadow effects rendered using each first random number as the current light and shadow effect to be superimposed.
[0026] Optionally, the probability distribution is a normal distribution with the main direction of the incident light of the light source as the center and the scattering degree of the light source as the variance.
[0027] Optionally, the sampling module is specifically used to: generate a random number in the range of 0 to 1 as a second random number; determine a direction representing a corresponding probability of the second random number in a normal distribution, and obtain a current direction to be processed.
[0028] Optionally, the device also includes: an acquisition module, which is used to obtain the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated from the current inactivated light map before the superposition module executes superposition of the current light and shadow effects to be superimposed and the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated, to obtain the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated; the superposition module is specifically used to: determine the light intensity at the same virtual position in the current light and shadow effect to be superimposed and the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map; superimpose the determined light intensities at the same virtual position to obtain the superimposed light and shadow effects corresponding to the current image frame to be generated. The device also includes: a recording module, which is used to perform superposition of the current light and shadow effects to be superimposed and the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated in the superposition module to obtain the superimposed light and shadow effects corresponding to the current image frame to be generated, and then perform recording of the superimposed light and shadow effects corresponding to the current image frame to be generated in the current activated light map according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map; adjusting the current activated light map to an inactivated state, and adjusting the current inactivated light map to an activated state; the second rendering module is specifically used to render the target scene using a direct lighting model based on the current inactivated light map and the attribute map representing the attributes of the virtual object itself in the target scene to obtain the current image frame to be generated.
[0029] Optionally, the superposition module is specifically used to: superimpose the light intensity at the same virtual position determined according to the first weight of the current light and shadow effect to be superimposed and the second weight of the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, so as to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; wherein the sum of the first weight and the second weight is 1, and the first weight is the reciprocal of the sum of the preset number and the specified positive integer.
[0030] Optionally, the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map are consistent with the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, and are determined by arranging the bounding boxes of the virtual objects in the target scene based on a greedy algorithm.
[0031] Optionally, the update of the target scene includes: an update of a virtual object in the target scene, and / or an update of a light source in the target scene; the update of the virtual object in the target scene includes at least one of the following: an update of the position of the virtual object in the target scene, an update of the shape of the virtual object in the target scene, and an update of the number of virtual objects in the target scene; the update of the light source in the target scene includes at least one of the following: an update of the type of the light source in the target scene, an update of the position of the light source in the target scene, an update of the illumination intensity of the light source in the target scene, and an update of the number of light sources in the target scene.
[0032] Optionally, the attribute map includes at least one of the following: a color map, a normal map, and a material map.
[0033] Optionally, the device also includes: a third rendering module, which is used to render the target scene using a direct lighting model to obtain image frames based on the superimposed light and shadow effects used when obtaining a preset number of image frames after the target scene is updated, and the attribute map, until the target scene is updated again.
[0034] In a third aspect of an embodiment of the present application, an electronic device is provided, comprising: a memory for storing a computer program; and a processor for implementing any of the scene rendering methods described in the first aspect above when executing the program stored in the memory.
[0035] In a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the scene rendering method described in any one of the first aspects is implemented.
[0036] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described scene rendering methods.
[0037] A scene rendering method provided by an embodiment of the present application comprises: when a target scene is updated, sampling the illumination direction currently generated by a light source in the target scene to obtain a current direction to be processed; performing direct illumination rendering on the target scene according to the light in the current direction to be processed to obtain a light and shadow effect corresponding to the image frame to be generated of the target scene as the current light and shadow effect to be superimposed; wherein the light and shadow effect to be superimposed includes: the illumination intensity at each virtual position on the surface of a virtual object in the target scene under the illumination of the light in the current direction to be processed; superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the image frame to be generated; rendering the target scene using a direct illumination model based on the superimposed light and shadow effect corresponding to the image frame to be generated and an attribute map representing the attributes of the virtual object itself in the target scene to obtain the current image frame to be generated, and returning to execute the step of sampling the illumination direction currently generated by the light source in the target scene to obtain the current direction to be processed, until a preset number of image frames are obtained after the target scene is updated.
[0038] Based on the above processing, when the target scene is updated, for the current image frame to be generated, the electronic device will perform direct illumination rendering on the target scene based on the light in the current direction to be processed obtained by sampling, and obtain the current light and shadow effect to be superimposed. For each image frame to be generated, the amount of calculation can be reduced by reducing the number of light to be processed by sampling and avoiding the calculation of the light and shadow effect generated by each reflection of the light by direct illumination rendering. In addition, the superimposed light and shadow effect corresponding to the current image frame to be generated is obtained by superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, and the light and shadow effect to be used when generating the current image frame to be generated is obtained. That is, when each image frame is obtained, the light and shadow effect generated by the light in the direction to be processed obtained by sampling corresponding to the image frame itself, and the light and shadow effects of all image frames generated before the image frame after the target scene is updated, are combined to obtain the light and shadow effect used when obtaining the image frame. In this way, as the rendering process continues to advance, the image frame will be obtained based on the light and shadow effects generated by the light in the direction to be processed obtained by more and more sampling. It is understandable that when the target scene is updated to obtain a preset number of image frames, the generated preset number of image frames also combines the light and shadow effects produced by light from more directions, which is closer to the situation where there are light from more directions in the real scene, and the obtained light and shadow effects are more realistic. Rendering the target scene based on more realistic light and shadow effects can improve the realism of the rendered target scene. In the above process, the calculation of the light and shadow effects produced by a large number of lights can be distributed in a preset number of image frames, so the amount of calculation allocated when generating each image frame is very small, and it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time. In this way, the performance requirements for hardware devices will be relatively lower, and the performance requirements for hardware devices will be reduced on the premise of being able to obtain image frames of realistic scenes. In addition, since it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time, the time required to generate each image frame will be reduced accordingly, and real-time rendering can be well achieved.
[0039] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0041] Figure 1A first flow chart of a scene rendering method provided in an embodiment of the present application;
[0042] Figure 2 A second flow chart of the scene rendering method provided in an embodiment of the present application;
[0043] Figure 3 A schematic diagram of a light sampling process provided in an embodiment of the present application;
[0044] Figure 4 A third flow chart of the scene rendering method provided in an embodiment of the present application;
[0045] Figure 5 A fourth flow chart of the scene rendering method provided in an embodiment of the present application;
[0046] Figure 6 A flow chart of the light and shadow effect superposition process provided in an embodiment of the present application;
[0047] Figure 7 A schematic diagram of a scene rendering method provided in an embodiment of the present application;
[0048] Figure 8 A structural diagram of a scene rendering device provided in an embodiment of the present application;
[0049] Fig. 9 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0051] With the development of real-time rendering technology in recent years, in the field of digital twin technology, real-time rendering technology and ray tracing algorithms can be used to obtain real and natural global illumination effects (i.e., light and shadow effects), that is, to render the scene. For example, global illumination effects can include indirect illumination effects, shadow effects, diffuse illumination effects, and the like. Obviously, the amount of calculation involved in rendering a scene based on real-time rendering technology is extremely large, and high-performance hardware devices are required to provide the real-time rendering technology with a large amount of computing resources required for sufficient rendering. Therefore, pre-calculating light maps based on ray tracing algorithms to bake scenes, that is, pre-calculating light and shadow effects based on ray tracing algorithms, storing pre-calculated light and shadow effects, and then directly using pre-stored light and shadow effects to render the scene, has become a common means of rendering scenes based on real-time rendering technology in this field, which can reduce the performance requirements for hardware devices during real-time rendering.
[0052] Light map is a computer graphics technology. Based on light map, the light and shadow effects of each object in the scene under fixed static lighting can be pre-calculated, and then the pre-calculated light and shadow effects are stored in the texture map, that is, pre-calculated light map. When adding light and shadow effects to virtual models based on light map, JavaScript (Java script) and OpenGL ES2.0 (Open Graphics Library for Embedded Systems 2.0) can also be combined based on WebGL (Web Graphics Library) drawing protocol. By adding JavaScript binding to OpenGL ES2.0, hardware 3D (3-Dimension) accelerated rendering is provided for HTML5 Canvas (Hyper Text Markup Language 5 Canvas). In this way, 3D scenes and models can be displayed smoothly in the browser with the help of the system graphics card, and complex navigation and data visualization can be created based on 3D scenes and models, that is, physical systems can be optimized based on 3D scenes and models.
[0053] Obviously, by pre-calculating light maps, we can only reduce the performance requirements of hardware devices in the real-time rendering process. However, in the process of pre-calculating light maps, we still need to use hardware devices with higher performance (such as rendering engines) to pre-calculate light maps by baking scenes, which means that there are still high requirements on the performance of hardware devices.
[0054] Assuming that the ray tracing algorithm can be simplified to a certain extent, such as using approximate calculations to calculate the light and shadow effects produced by indirect lighting to reduce the amount of calculations for the ray tracing algorithm, this still requires a huge amount of calculations and places high demands on the performance of the hardware. You can also use offline rendering or cloud baking to obtain a reference light map based on the ray tracing algorithm in advance, and then perform dynamic synthesis based on the position of the light source in the scene and the reference light map obtained, and then render the scene based on the dynamic synthesis result. Obviously, this also places high demands on the performance of the hardware.
[0055] In order to solve the above problems, the embodiment of the present application provides a scene rendering method, which is applied to an electronic device. For example, the target scene to be rendered can be a game scene of a 3D game, and the electronic device can be a terminal device used by a user playing the game; if the target scene to be rendered can be a virtual object obtained by modeling a physical object to be optimized, the electronic device can be a computer device used by a technician who optimizes the physical object.
[0056] When the target scene is updated, the electronic device will sample the illumination direction currently generated by the light source in the target scene to obtain the current direction to be processed; then the target scene is directly illuminated and rendered according to the light in the current direction to be processed, and the illumination intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the current direction to be processed is obtained, that is, the current light and shadow effect to be superimposed is obtained. Then the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated are superimposed to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; then based on the superimposed light and shadow effect corresponding to the current image frame to be generated and the attribute map representing the attributes of the virtual object itself in the target scene, the target scene is rendered using the direct illumination model to obtain the current image frame to be generated, and the step of sampling the illumination direction currently generated by the light source in the target scene to obtain the current direction to be processed is returned until a preset number of image frames are obtained after the target scene is updated. In this way, this progressive rendering method distributes a large amount of lighting calculations to the rendering of each frame. Each frame only needs to process a small amount of lighting calculations, and the effects are gradually superimposed and presented with real-time rendering, which reduces the performance requirements of hardware devices while being able to obtain image frames of realistic scenes. In addition, since it is not necessary to calculate the lighting effects produced by a large amount of light at the same time, the time required to generate each image frame will be reduced accordingly, and real-time rendering can be well achieved.
[0057] See also Figure 1 , Figure 1 A first flow chart of a scene rendering method provided in an embodiment of the present application, the method comprising the following steps:
[0058] S101: When a target scene is updated, a lighting direction currently generated by a light source in the target scene is sampled to obtain a current direction to be processed.
[0059] S102: Direct illumination rendering is performed on the target scene according to the light in the current direction to be processed, and the light and shadow effect corresponding to the image frame to be generated currently of the target scene is obtained as the current light and shadow effect to be superimposed.
[0060] The light and shadow effects to be superimposed include: the light intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the light in the current direction to be processed.
[0061] S103: Superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated.
[0062] S104: Based on the superimposed light and shadow effects corresponding to the current image frame to be generated, and the attribute map representing the attributes of the virtual object itself in the target scene, the target scene is rendered using the direct lighting model to obtain the current image frame to be generated, and the step of sampling the lighting direction currently generated by the light source in the target scene to obtain the current direction to be processed is returned to execute until a preset number of image frames are obtained after the target scene is updated.
[0063] Based on the scene rendering method provided by the embodiment of the present application, when the target scene is updated, for the current image frame to be generated, the electronic device will perform direct illumination rendering on the target scene based on the light in the current direction to be processed obtained by sampling, and obtain the current light and shadow effect to be superimposed. For each image frame to be generated, the number of light rays to be processed is reduced by sampling, and the light and shadow effect generated by each reflection of the light is avoided by direct illumination rendering, so that the amount of calculation can be reduced. In addition, the superimposed light and shadow effect corresponding to the current image frame to be generated is obtained by superimposing the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, and the light and shadow effect to be used when generating the current image frame to be generated is obtained. That is, when each image frame is obtained, the light and shadow effect generated by the light in the direction to be processed obtained by sampling corresponding to the image frame itself, and the light and shadow effects of all image frames generated before the image frame after the target scene is updated, are combined to obtain the light and shadow effect used when obtaining the image frame. In this way, as the rendering process continues to advance, the image frame will be obtained based on the light and shadow effects generated by the light in the direction to be processed obtained by more and more sampling. It is understandable that when the target scene is updated to obtain a preset number of image frames, the generated preset number of image frames also combines the light and shadow effects produced by light from more directions, which is closer to the situation where there are light from more directions in the real scene, and the obtained light and shadow effects are more realistic. Rendering the target scene based on more realistic light and shadow effects can improve the realism of the rendered target scene. In the above process, the calculation of the light and shadow effects produced by a large number of lights can be distributed in a preset number of image frames, so the amount of calculation allocated when generating each image frame is very small, and it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time. In this way, the performance requirements for hardware devices will be relatively lower, and the performance requirements for hardware devices will be reduced on the premise of being able to obtain image frames of realistic scenes. In addition, since it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time, the time required to generate each image frame will be reduced accordingly, and real-time rendering can be well achieved.
[0064] For step S101, the target scene is a virtual scene that needs to render light and shadow effects, such as a modeled scene including multiple virtual objects. For example, the target scene may be a game scene of a 3D game, and the virtual objects may include modeled buildings, modeled trees, modeled vehicles, etc.
[0065] The target scene may also include one or more light sources that emit light to illuminate the target scene, such as the sun, street lamps, etc. It is understandable that the lighting direction currently generated by the light source is the lighting direction generated by the light emitted by the light source. A light source can emit multiple light rays, and the lighting directions generated by different light rays may be different. For example, when multiple light rays are irradiated on a relatively rough surface, these light rays will produce diffuse reflection, that is, they will be reflected in different directions, and the lighting directions generated by these light rays will also be different. The lighting direction generated by the light source may include the lighting direction of the incident light emitted by the light source, and the lighting direction of the reflected light obtained by one reflection of the incident light. The light and shadow effect generated by the incident light can be called the light and shadow effect under direct lighting, and the light and shadow effect generated by the reflected light can be called the light and shadow effect under indirect lighting.
[0066] It is understandable that a light source can emit a large number of light rays. If the illumination direction generated by each light ray emitted by the light source is determined as the current direction to be processed, the amount of calculation involved in the process of obtaining the light and shadow effect based on the current direction to be processed will be extremely large, and the performance requirements for the hardware device are relatively high. Therefore, in order to reduce the performance requirements for the hardware device, the electronic device can distribute the calculation of the light and shadow effects generated by a large number of lights over a preset number of image frames. That is, for each image frame to be generated, the electronic device can only calculate the light and shadow effects generated by a small number of lights (i.e., the current light and shadow effects to be superimposed), and then combine the light and shadow effects of all image frames generated before the image frame after the target scene is updated (i.e., the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated), and jointly obtain the light and shadow effects used when obtaining the image frame (i.e., the superimposed light and shadow effects corresponding to the current image frame to be generated).
[0067] Specifically, the electronic device can sample the lighting direction currently generated by the light source in the target scene to obtain the current direction to be processed, and then the light and shadow effect obtained based on the current direction to be processed obtained by sampling is the light and shadow effect produced by a smaller number of lights.
[0068] It is understandable that after the target scene is updated, the light and shadow effects to be rendered on the surface of the virtual object in the target scene will also change accordingly. Therefore, when the target scene is updated, the electronic device can sample and obtain the current direction to be processed, and then render the target scene based on the current direction to be processed.
[0069] For step S102, after sampling and obtaining the current direction to be processed, the electronic device can use the light of the current direction to be processed to perform direct lighting rendering on the target scene, such as using the Directionallight of the current direction to be processed to perform direct lighting rendering on the target scene. The light source of the directional light is assumed to come from an infinite distance, that is, the light rays of the directional light are parallel, and the intensity of the light rays does not change with distance. All light rays emitted by the light source of the directional light propagate in parallel along the direction of the directional light, regardless of the position of the light rays.
[0070] The electronic device can perform direct illumination rendering on the target scene through a physics-based physical illumination model, that is, the current direction to be processed obtained by sampling is the direction of the light emitted by the light source, and the directional light is used as the type of light source. The physical illumination model is used to calculate the illumination intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the current direction to be processed, that is, to obtain the current light and shadow effect to be superimposed. The physical illumination model can be a Phong model, a Blinn-Phong model, etc. And it can be understood that the light and shadow effects can include illumination effects and shadow effects produced under illumination, such as the illumination intensity can be recorded as a grayscale value.
[0071] The sampled directional light can be used to simulate the lighting effects produced by the reflected light formed by the reflection of the light. That is, the electronic device can use the directional light sampled from the lighting direction generated by the light source to perform direct lighting rendering, and use the obtained lighting effects to simulate the diffuse lighting effects.
[0072] For step S103, as mentioned above, the electronic device distributes the calculation of the light and shadow effects generated by a large amount of light in a preset number of image frames. Therefore, after obtaining the current light and shadow effect to be superimposed, in order to obtain the light and shadow effect generated by combining light from more directions, the electronic device superimposes the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated (hereinafter referred to as the historical light and shadow effect), and obtains the superimposed light and shadow effect corresponding to the current image frame to be generated (hereinafter referred to as the target light and shadow effect). For example, the electronic device can calculate the weighted sum of the current light and shadow effect to be superimposed and the historical light and shadow effect at the same virtual position according to the virtual position of the surface of the virtual object in the target scene, and obtain the target light and shadow effect at the virtual position. The specific manner in which the electronic device superimposes the current light and shadow effect to be superimposed and the historical light and shadow effect can be found in the detailed description of the subsequent embodiments.
[0073] In this way, the current light and shadow effect to be superimposed generated by the light from the direction to be processed obtained by sampling the corresponding image frame to be generated and the historical light and shadow effects of all image frames generated before the current image frame to be generated after the target scene is updated are combined to obtain the light and shadow effect used when obtaining the current image frame to be generated. That is, the target light and shadow effect generated by combining light from multiple directions is obtained.
[0074] It is understandable that when the current image frame to be generated is the first image frame to be generated after the target scene is updated, since there are no other image frames before the current image frame to be generated after the target scene is updated, there is naturally no historical light and shadow effect at this time. Therefore, the current light and shadow effect to be superimposed can be directly used as the target light and shadow effect.
[0075] For step S104, after obtaining the target light and shadow effects, the electronic device can also add corresponding light and shadow effects to the virtual object. Specifically, the electronic device can use the direct illumination model to process the target light and shadow effects and the attribute map representing the attributes of the virtual object itself in the target scene, and obtain the processing result of the direct illumination model, that is, obtain the image frame of the target scene rendered with the target light and shadow effects. The direct illumination model can be the Phong model, Blinn-Phong model, etc. introduced above. And the direct illumination model and the physical illumination model can be different models, which is not limited in this application.
[0076] Furthermore, in order to further reduce the performance requirements for hardware devices, when obtaining the target scene that renders the target light and shadow effects based on the direct lighting model, it is also possible to set the relevant parameters of the object material of the virtual object in the direct lighting model to only have the most basic reflection parameters and transmission parameters, and when setting the calculation of the light and shadow effects, only the most basic shadowmap method is used to calculate the shadow effects, without setting any softening processing.
[0077] Furthermore, in order to ensure the realism of the rendered scene, if the preset number of image frames has not been obtained after the target scene is updated, that is, the current target light and shadow effect is not a light and shadow effect produced by combining light from a sufficient number of directions, and the current target light and shadow effect is not realistic enough. Therefore, the electronic device can return to execute the aforementioned step S101, that is, continue to render the current light and shadow effect to be superimposed of the image frame to be generated based on a smaller number of light rays, and then continue to combine the current light and shadow effect to be superimposed and the historical light and shadow effect to obtain the target light and shadow effect, and so on, until a preset number of image frames are obtained after the target scene is updated. At this time, it can be considered that the current target light and shadow effect is already a realistic light and shadow effect produced by combining light from a sufficient number of directions (hereinafter referred to as the light and shadow effect to be rendered), and the light and shadow effect to be rendered is balanced. That is, even if the current light and shadow effect to be superimposed is obtained again based on the direction to be processed obtained by sampling, and then combined with the current light and shadow effect to be superimposed and the light and shadow effect to be rendered, the difference between the combined result and the light and shadow effect to be rendered is less than the preset threshold. This method of distributing the calculation of light and shadow effects generated by a large amount of light in a preset number of image frames can also be called progressive calculation of light and shadow effects. Obviously, the rendering effect in the present application is gradually superimposed and presented as the image frames are rendered. That is, at the beginning, an image frame of the target scene is generated based on relatively unrealistic light and shadow effects, and as the image frames are gradually generated, the light and shadow effects rendered in the target scene are gradually realistic. When a preset number of image frames are obtained after the target scene is updated, the preset number of image frames generated are image frames based on the target scene that have rendered realistic light and shadow effects to be rendered.
[0078] It is understandable that after the image frame is generated, when the electronic device needs to display the generated image frame, the image frame switching speed is extremely fast, such as 20 image frames may be switched in one second. Although the rendering effect in this application is to be gradually superimposed and presented as the image frame is rendered, for users browsing the image frame, the superimposed presentation process of this rendering effect is extremely short, and therefore, it will not affect the user's browsing experience, that is, it will not reduce the user's viewing experience.
[0079] It is understandable that before obtaining a preset number of image frames after the target scene is updated, for each image frame to be generated, the electronic device will sample to obtain a direction to be processed; and when the electronic device samples the image frame to be generated, it can also sample to obtain multiple directions to be processed. The number of image frames to be generated is the preset number, and the number of directions sampled for one image frame to be generated is the number of first random numbers in the subsequent embodiments. Obviously, the product of the preset number and the number of the first random numbers can represent the number of light and shadow effects participating in the combination. When the number of light and shadow effects participating in the combination reaches a specified number, it can indicate that the current target light and shadow effect is already a realistic light and shadow effect to be rendered by combining light from enough directions. The specified number can be determined by the technician according to work experience, such as 250. Correspondingly, when the electronic device samples and obtains 5 current directions to be processed each time, the preset number can be set to 50; when the electronic device samples and obtains 10 current directions to be processed each time, the preset number can be set to 25, but it is not limited thereto.
[0080] In some embodiments, after the target scene is updated, a preset number of image frames have not been obtained, but when the target scene has been updated again, the light and shadow effects to be rendered on the surface of the virtual object in the target scene will be changed accordingly again. At this time, the current image frame to be generated is the first image frame to be generated after the target scene is updated again, and the electronic device can restart the scene rendering method provided by the present application.
[0081] In some embodiments, the method may further include the following steps: based on the superimposed light and shadow effects and attribute maps used when obtaining a preset number of image frames after the target scene is updated, the target scene is rendered using a direct lighting model to obtain image frames until the target scene is updated again.
[0082] When the preset number of image frames have been obtained after the target scene is updated, the electronic device has obtained a balanced and realistic light and shadow effect to be rendered. At this time, the electronic device can directly use the light and shadow effect to be rendered to render the target scene. In this way, each image frame generated subsequently can be obtained based on the target scene rendered with realistic light and shadow effects to be rendered, that is, an image frame of a realistic scene can be obtained.
[0083] In some embodiments, the attribute map representing the attributes of the virtual object itself in the target scene includes at least one of the following: a color map, a normal map, and a material map. It is understandable that the color map may record the color of each virtual position on the surface of the virtual object; the normal map may record the concave and convex state of each position on the surface of the virtual object; and the material map may record the material of each position on the surface of the virtual object, such as metal material, cement material, leather material, etc.
[0084] In some embodiments, the target scene is updated including: the virtual object in the target scene is updated, and / or the light source in the target scene is updated. The virtual object in the target scene is updated including at least one of the following: the position of the virtual object in the target scene is updated, the shape of the virtual object in the target scene is updated, and the number of virtual objects in the target scene is updated. The light source in the target scene is updated including at least one of the following: the type of the light source in the target scene is updated, the position of the light source in the target scene is updated, the illumination intensity of the light source in the target scene is updated, and the number of light sources in the target scene is updated.
[0085] The types of light sources may include point light sources, parallel light sources, etc. It is understandable that whether the position, shape, or quantity of the virtual object in the target scene is updated, or the type, position, illumination intensity, or quantity of the light source in the target scene is updated, the illumination intensity at the virtual position of the surface of the virtual object in the target scene will change. Therefore, when the virtual object in the target scene is updated, and / or when the light source in the target scene is updated, it can indicate that the target scene is updated. For example, the electronic device can determine that the target scene is updated after receiving a modification instruction for the virtual object and / or the light source in the target scene.
[0086] Furthermore, after the electronic device determines that the target scene has been updated, it is necessary to restart the scene rendering method provided by the present application. That is, the illumination direction currently generated by the light source in the updated target scene is sampled to obtain the current direction to be processed, and then the current light and shadow effect to be superimposed is determined based on the current direction to be processed, and the current light and shadow effect to be superimposed and the historical light and shadow effect are recombined until the target scene is updated again and a preset number of image frames are obtained, that is, until the light and shadow effect to be rendered that is generated by combining light from more directions is obtained.
[0087] Based on the above processing, after determining that the target scene is updated, the electronic device can re-determine the light and shadow effects of the surface of the virtual object in the updated target scene under the illumination of the light source of the updated target scene according to the scene rendering method provided in the present application, that is, to achieve light and shadow effect rendering of the dynamic target scene and improve user experience.
[0088] In some embodiments, Figure 1 Based on Figure 2 , step S101 may include the following steps:
[0089] S1011: When the target scene is updated, generate a random number within a specified numerical range as a first random number.
[0090] S1012: If the first random number generated is greater than the probability weight of ambient scattered light, randomly generate a lighting direction in the target scene to obtain the current direction to be processed; if the first random number generated is not greater than the probability weight of ambient scattered light, randomly sample based on the probability distribution of the direction of incident light of the light source in the target scene to obtain the current direction to be processed.
[0091] The probability weight of ambient scattered light represents the reflectivity of the target scene; and the probability weight of ambient scattered light belongs to a specified numerical range.
[0092] The electronic device can pre-acquire the probability weight of ambient scattered light that characterizes the reflectivity of the target scene. It can be understood that the reflectivity of the target scene is determined by comprehensively considering the overall surface reflection coefficient of the virtual objects in the target scene. For example, when the target scene includes more virtual objects with rough surfaces, the reflectivity of the target scene is small, and the target scene can be an indoor scene including cement walls; when the target scene includes more virtual objects with smooth surfaces, the reflectivity of the target scene is large, and the target scene can be a scene including more metals. According to the overall surface reflection coefficient of the virtual objects in the target scene, the technician can determine the reflectivity of the target scene according to work experience, and then obtain the probability weight of ambient scattered light that characterizes the reflectivity of the target scene. The reflectivity of the target scene is proportional to the probability weight of ambient scattered light.
[0093] When the probability weight of ambient scattered light is large, that is, the reflectivity of the target scene is large, the surfaces of the virtual objects in the target scene are mostly smoother (hereinafter referred to as smooth scenes). Obviously, for these virtual objects with smooth surfaces, when incident light shines on these smooth surfaces, the light will mostly reflect in one direction instead of scattering in space. Naturally, under the illumination of the light source, the light and shadow effects on the surface of the virtual object in the smooth scene are mostly generated based on the incident light of the light source. When determining the light and shadow effects corresponding to the smooth scene, it is also necessary to consider more the light and shadow effects directly generated by the incident light of the light source, that is, the direction of the incident light of the light source can be sampled more to obtain the current direction to be processed.
[0094] When the probability weight of the ambient scattered light is small, that is, the reflectivity of the target scene is small, the surfaces of the virtual objects in the target scene are mostly rough (hereinafter referred to as rough scenes). Obviously, for these virtual objects with rough surfaces, when incident light shines on these rough surfaces, the light will mostly scatter into the space. Naturally, under the illumination of the light source, the light and shadow effects on the surface of the virtual object in the rough scene are mostly based on the light scattered into the space. When determining the light and shadow effects corresponding to the rough scene, it is also necessary to consider the light and shadow effects generated by the scattered light more, that is, the current direction to be processed can be obtained more in random directions in space, and then the light and shadow effects generated by the current direction to be processed based on the random light and shadow effects are used to simulate the light and shadow effects generated by the scattered light.
[0095] Therefore, the electronic device can generate a first random number that belongs to the same specified numerical range as the ambient scattered light probability weight, such as the specified numerical range can be 0 to 1. Naturally, when the ambient scattered light probability weight is large, the probability that the generated first random number is not greater than the ambient scattered light probability weight will be greater. Since the light and shadow effects directly generated by the incident light of the light source should be considered more at this time, it can be set that when the first random number is not greater than the ambient scattered light probability weight, random sampling is performed based on the probability distribution representing the direction of the incident light of the light source in the target scene to obtain the current direction to be processed. This sampling method is hereinafter referred to as the first sampling method.
[0096] When the probability weight of ambient scattered light is small, the probability that the generated first random number is greater than the probability weight of ambient scattered light will be greater. Since the light and shadow effects produced by scattered light need to be considered more at this time, it can be set that when the first random number is greater than the probability weight of ambient scattered light, the illumination direction is randomly generated in the target scene to obtain the current direction to be processed. This sampling method is hereinafter referred to as the second sampling method.
[0097] Based on the above processing, the specific sampling method is determined by the generated first random number. Then, among the lights in more directions corresponding to the light and shadow effects to be rendered, the ratio of the lights in the direction to be processed sampled based on the first sampling method to the lights in all the directions to be processed sampled based on the first sampling method and the second sampling method is consistent with the probability weight of the ambient scattered light. That is, the light and shadow effects to be rendered are finally obtained according to the reflectivity of the target scene, and the light and shadow effects to be rendered match the target scene, that is, the target scene rendered with the light and shadow effects to be rendered is more realistic, that is, the scene rendering effect is better.
[0098] For example, see Figure 3 , Figure 3 A schematic diagram of the light sampling process provided in an embodiment of the present application. Figure 3 The thicker arrow in the figure indicates the direction of the main light source I i, i.e., the main direction of the light source in the aforementioned embodiment; Figure 3 The lines distributed around the main direction of the light source in α represent the light emitted by the light source. α represents the first random number in the above-mentioned embodiment, and p amb represents the probability weight of ambient scattered light in the above embodiment. Figure 3 As shown, a beam of light emitted by a light source is incident downward onto a rough surface, causing each light ray in the beam to scatter in space, forming scattered light.
[0099] When sampling, if the first random number α generated is greater than p amb ,Right now Figure 3 α>p amb , then you can get the current direction to be processed in a random direction in space, such as Figure 3 The current direction to be processed is obtained from the upper hemisphere shown, that is, the illumination direction is randomly generated in the target scene to obtain the current direction to be processed; if the first random number α generated is less than p amb ,Right now Figure 3 α in <p amb At this time, the probability distribution of the direction of the incident light from the light source can be sampled to obtain the current direction to be processed. amb When , the probability distribution of the direction of the incident light of the light source can also be sampled to obtain the current direction to be processed.
[0100] In some embodiments, the first random number is multiple.
[0101] Accordingly, in Figure 2 Based on Figure 4 , step S102 may include the following steps:
[0102] S1021: For each first random number, directly illuminate and render the target scene according to the light in the direction to be processed obtained based on the first random number, to obtain the light and shadow effect of the image frame to be generated currently in the target scene for the first random number.
[0103] S1022: Calculate the average level of the light and shadow effects rendered using the first random numbers as the current light and shadow effect to be superimposed.
[0104] As mentioned above, for each image frame to be generated, the electronic device can sample multiple directions to be processed when sampling the image frame to be generated. Sampling an image frame to be generated to obtain a direction to be processed can be called sampling. And it can be understood that when the target scene is not updated again, the probability weight of ambient scattered light is fixed. Obviously, the size relationship between a first random number that has been generated and the fixed probability weight of ambient scattered light is fixed. Then, based on a first random number, only the sampling method used for sampling can be determined once, and naturally only one sampling can be performed to obtain a current direction to be processed. That is, the first random number and the current direction to be processed obtained by sampling are one-to-one corresponding. Therefore, the number of first random numbers is the number of current directions to be processed obtained by sampling for an image frame to be generated.
[0105] Naturally, in the case where there are multiple first random numbers, based on each first random number, the electronic device can determine the current direction to be processed corresponding to the first random number in accordance with the method of obtaining the current direction to be processed based on sampling of the first random number as described in the above embodiment, thereby obtaining multiple current directions to be processed. The number of first random numbers can be determined by the technician based on work experience, such as being set to 5, but is not limited thereto.
[0106] Furthermore, for each first random number, the electronic device can perform direct lighting rendering on the target scene according to the light from the direction to be processed obtained based on the first random number, and obtain the light and shadow effect of the image frame to be generated by the target scene for the first random number. The manner in which the electronic device performs direct lighting rendering on the target scene according to the light from the direction to be processed is described in the aforementioned embodiment, and will not be repeated here. The manner in which the target scene is directly rendered based on the light from each direction to be processed may be the same or different, and this application does not limit this.
[0107] Furthermore, the electronic device can calculate the average level of the light and shadow effects rendered using the first random numbers, such as the average level can be represented by the mean, median, mode, etc. Specifically, for each virtual position on the surface of the virtual object in the target scene, the electronic device can determine the light and shadow effects at the virtual position among the light and shadow effects rendered using the first random numbers, and then calculate the average of the determined light and shadow effects to obtain the average level of the light and shadow effects rendered using the first random numbers at the virtual position, that is, to obtain the current light and shadow effects to be superimposed at the virtual position, and then to obtain the current light and shadow effects to be superimposed of the image frame to be generated.
[0108] Based on the above processing, for the current image frame to be generated, the electronic device can determine multiple current directions to be processed based on multiple first random numbers, and subsequently can obtain the current light and shadow effects to be superimposed based on multiple lights. Correspondingly, the light and shadow effects to be rendered can be combined based on a smaller number of image frames to be generated, so that the number of image frames generated before generating image frames of the scene with the light and shadow effects to be rendered is smaller, which can reduce the number of image frames of scenes with relatively unrealistic light and shadow effects browsed by users, thereby avoiding a decrease in user experience.
[0109] In some embodiments, the probability distribution is a normal distribution with the main direction of the incident light of the light source as the center and the scattering degree of the light source as the variance.
[0110] It is understandable that a light source can emit multiple light rays, and for each light ray, the direction from the light source to the position where the light ray is to reach is the direction of the light ray. Obviously, the directions of these light rays can be different; naturally, there may be some light rays with the same direction. Among the directions of these light rays, the direction with the largest number of corresponding light rays can be the main direction of these light rays, that is, the main direction of the incident light of the light source. For example, when the light source is the sun and the target scene is a virtual city including modeled buildings, the main direction can be the direction pointing vertically to the ground of the virtual city.
[0111] The scattering degree of a light source can indicate the proportion of light rays with the same direction in all the light rays emitted by the light source. The greater the scattering degree of a light source, the smaller the proportion of light rays with the same direction in all the light rays emitted by the light source. For example, when the light source is a point light source, the number of light rays with the same direction is very small. Naturally, the proportion of light rays with the same direction in all the light rays emitted by the light source is small, and the scattering degree of the point light source is large; when the light source is a parallel light source, the light rays emitted by the parallel light source are the light rays with the same direction. Naturally, the proportion of light rays with the same direction in all the light rays emitted by the light source is large, and the scattering degree of the parallel light source is small.
[0112] For example, the normal distribution can be expressed as the following formula (1):
[0113] p(θ)=N(I i ,σ 2 ) (1)
[0114] Among them, I i represents the main direction of the incident light of the light source, σ represents the scattering degree of the light source, θ represents the angle between the direction of the light and the main direction, and p(θ) represents the probability that the angle between the direction of the light and the main direction is θ.
[0115] Based on the above processing, the normal distribution is used as the probability distribution of the direction of the incident light. The probability distribution is obtained based on the main direction of the incident light and the degree of scattering of the incident light, that is, the probability distribution of the direction of the incident light is more accurate. The subsequent light and shadow effects determined based on a more accurate probability distribution will be more realistic, that is, the scene rendering effect will be better.
[0116] In some embodiments, step S1012 may include the following steps:
[0117] Step 1: Generate a random number in the range of 0 to 1 as the second random number.
[0118] Step 2: Determine the direction representing the corresponding probability of the second random number in the normal distribution, and obtain the current direction to be processed.
[0119] When sampling the probability distribution of the direction of the incident light of the light source, a second random number representing the probability can be generated first, and then the corresponding probability θ of the second random number is determined from the normal distribution, and the direction of the light whose angle θ with the main direction of the incident light is determined. In this way, random sampling can be achieved on the probability distribution of the direction of the incident light to obtain the current direction to be processed. Among the lights in more directions corresponding to the light and shadow effects to be rendered, the ratio of the light in the direction to be processed sampled based on the first sampling method to the light in all directions to be processed sampled based on the first sampling method and the second sampling method is consistent with the probability weight of the ambient scattered light, that is, the realistic light and shadow effects to be rendered produced by combining the lights in more directions are obtained according to the reflectivity of the target scene, and the light and shadow effects to be rendered match the target scene, that is, the target scene rendered with the light and shadow effects to be rendered is more realistic, that is, the scene rendering effect is better.
[0120] In some embodiments, the electronic device may also randomly generate an azimuth angle not less than 0° and not more than 360°, and randomly generate an elevation angle not less than -180° and not more than 180°, and set the distance to 1, so that a position can be determined in the spherical coordinate system according to the azimuth angle, elevation angle and distance, and the direction of the position relative to the origin of the spherical coordinate system is the illumination direction randomly generated in the target scene. Alternatively, the electronic device may also determine the direction of the second random number corresponding to the probability in the uniform distribution as the illumination direction randomly generated in the target scene, that is, obtain the current direction to be processed.
[0121] In some embodiments, the target scene may include multiple light sources. At this time, for each light source, the electronic device can construct a normal distribution with the main direction of the incident light of the light source as the center and the scattering degree of the light source as the variance, that is, obtain the normal distribution corresponding to each light source. Then, these normal distributions are superimposed using the normal distribution addition formula, and the superposition result is used as the probability distribution representing the direction of the incident light of the light source in the target scene. In this way, the light and shadow effects can be determined by combining all the light sources in the target scene, and the determined light and shadow effects will be more realistic.
[0122] In some embodiments, Figure 1 Based on Figure 5 Before step S103, the method may further include the following steps:
[0123] S105: Obtaining, from the current inactivated light map, the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated.
[0124] Accordingly, step S103 may include the following steps:
[0125] S1031: Determine the current light and shadow effect to be superimposed according to the pre-recorded mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map, and the light intensity at the same virtual position in the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated.
[0126] S1032: Superimposing the determined light intensities at the same virtual position to obtain a superimposed light and shadow effect corresponding to the image frame to be generated.
[0127] Accordingly, after step S103, the method may further include the following steps:
[0128] S106: Record the superimposed light and shadow effects corresponding to the current image frame to be generated in the current activated light map according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map.
[0129] S107: adjusting the currently activated light map to an inactive state, and adjusting the currently inactive light map to an active state.
[0130] Accordingly, step S104 may include the following steps:
[0131] S1041: Based on the current inactivated light map and the attribute map representing the attributes of the virtual object itself in the target scene, the target scene is rendered using a direct lighting model to obtain the current image frame to be generated.
[0132] Based on the foregoing embodiments, it can be seen that the scene rendering method of the present application involves multiple light and shadow effects. In order to uniformly and effectively manage these light and shadow effects, a specified container can be used to record the light and shadow effects, such as using a light map to record the light and shadow effects obtained by rendering. Specifically, the electronic device can create two sets of blank light maps, and then arrange the bounding box of the virtual object in the target scene, and determine the map coordinates of the virtual position of the surface of the virtual object in the target scene in each set of blank light maps. For example, the electronic device can create a blank light map of a corresponding size according to the complexity of the target scene, that is, the size, number and other information of the virtual objects in the target scene. Alternatively, in order to be compatible with various graphics cards, the electronic device can pre-create a blank light map of a size of 2048×2048. This application is not limited to this. It can be understood that the arranged map coordinates can be UV coordinates.
[0133] It is understandable that each virtual position of all virtual object surfaces in the target scene corresponds to a unique texture coordinate in a set of blank light maps. For example, the electronic device can pre-create a blank light map with a size of 2048×2048. Figure 1 , and then arrange the virtual position of the virtual object surface in the blank light map Figure 1 In the blank lightmap Figure 1 When it is no longer possible to arrange the bounding box of the virtual object, the electronic device can continue to create a blank light map Figure 2 , and then paste it in the blank light Figure 2 Continue to arrange the bounding boxes of virtual objects until the bounding boxes of each virtual object in the target scene are arranged. Figure 1 and blank light stickers Figure 2 They belong to the same set of blank lightmaps. According to the above method, the electronic device can create two sets of blank lightmaps, and then activate any set of blank lightmaps to obtain the initial activated lightmaps. Correspondingly, the other set of inactivated blank lightmaps is the initial inactivated lightmap.
[0134] Furthermore, when the target scene is updated, when the electronic device needs to generate the first image frame of the updated target scene, it can first record the current light and shadow effects to be superimposed based on the light in the current direction to be processed in the fragment shader. Obviously, the initial inactivated light map does not record the light and shadow effects. Therefore, the electronic device can directly record the light and shadow effects recorded in the fragment shader in the initial inactivated light map. Then, based on the light and shadow effects and attribute maps recorded in the initial inactivated light map, the target scene is rendered using the direct lighting model to obtain the current image frame to be generated. Then, the initial activated light map is adjusted to an inactivated state to obtain the current inactivated light map; and the initial inactivated light map is adjusted to an activated state to obtain the current activated light map.
[0135] When the electronic device generates other image frames of the updated target scene except the first image frame, it can directly obtain the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated from the current inactivated light map. It can be understood that the superimposed light and shadow effects include the superimposed light and shadow effects corresponding to each map position, and as mentioned above, each virtual position on the surface of all virtual objects in the target scene uniquely corresponds to a map coordinate in a set of blank light maps, that is, the electronic device can obtain: the superimposed light and shadow effects at each virtual position included in the last image frame obtained after the target scene is updated.
[0136] Furthermore, the electronic device can determine the current light and shadow effect to be superimposed according to the pre-recorded mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map. Furthermore, the electronic device can superimpose the superimposed light and shadow effect corresponding to the same virtual position obtained and the light and shadow effect to be superimposed to obtain the superimposed light and shadow effect corresponding to the virtual position. In this way, the superimposed light and shadow effect corresponding to the current image frame to be generated can be obtained.
[0137] In some embodiments, the above step S1032 may include the following steps: according to the first weight of the current light and shadow effect to be superimposed and the second weight of the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, the determined light intensity at the same virtual position is superimposed to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated. The sum of the first weight and the second weight is 1, and the first weight is the reciprocal of the sum of the preset number and the specified positive integer.
[0138] Exemplarily, the superimposed light and shadow effects corresponding to the current image frame to be generated may be calculated based on the following formula (2):
[0139] Ld=Ld×(1-alpha)+Li×alpha (2)
[0140] Among them, alpha represents the first weight, which can be set to n represents a preset number, m represents a specified positive integer, such as the specified positive integer can be set to 1, or can also be set to 2, which is not limited in this application; (1-alpha) represents the second weight, which can be specifically set to Li represents the current light and shadow effect to be superimposed, and Ld represents the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated.
[0141] Based on the above processing, the first weight and the second weight are both determined based on a preset number, that is, the current light and shadow effect to be superimposed at a virtual position, and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, are superimposed based on the preset number, so that in the realistic light and shadow effect to be rendered that combines light from multiple directions, the light and shadow effects to be superimposed determined based on each image frame to be generated can be evenly mixed, which can avoid the light and shadow effect to be rendered being greatly affected by the light and shadow effects to be superimposed of some image frames to be generated, so that the light and shadow effect to be rendered is more realistic, and the rendering effect of the target scene based on the light and shadow effect to be rendered is better.
[0142] Furthermore, for each virtual position on the surface of the virtual object, the electronic device can record the superimposed light and shadow effects corresponding to the virtual position in the current activated light map at the corresponding map coordinates of the virtual position in the current activated light map according to the correspondence between the virtual position on the surface of the virtual object and the map coordinates in the current activated light map, so that the superimposed light and shadow effects corresponding to the current image frame to be generated can be recorded in the current activated light map. Then, the electronic device can adjust the current activated light map to an inactivated state to obtain the current inactivated light map; and adjust the initial inactivated light map to an activated state to obtain the current activated light map.
[0143] It is understandable that after obtaining the current inactivated light map that records the superimposed light and shadow effects corresponding to the current image frame to be generated, the electronic device can directly render the target scene based on the current inactivated light map and the attribute map representing the attributes of the virtual object itself in the target scene using the direct lighting model to obtain the current image frame to be generated. Exemplarily, when the map coordinates are UV coordinates, for each virtual position on the surface of the virtual object, the virtual position can uniquely correspond to a UV coordinate in the arranged light map (hereinafter referred to as the new UV coordinate), and the virtual position can also uniquely correspond to a UV coordinate in the attribute map (hereinafter referred to as the old UV coordinate). When the electronic device obtains the new UV coordinate, it can record the new UV coordinate and the old UV coordinate at the same time. When the target scene is subsequently rendered, for each virtual position, the superimposed light and shadow effects corresponding to the virtual position can be determined from the current inactivated light map based on the new UV coordinates, and the attribute information corresponding to the virtual position can be determined from the attribute map based on the old UV coordinates. Then, the superimposed light and shadow effects corresponding to the virtual position and the attribute information corresponding to the virtual position are used to render the virtual position to render the target scene.
[0144] Based on the above processing, electronic devices can create light maps to record light and shadow effects, and can manage these light and shadow effects in a unified and effective manner; and in subsequent rendering, light maps that record light and shadow effects can be directly used for rendering, which can further reduce the performance requirements for hardware devices in the real-time rendering process.
[0145] In some embodiments, the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map are consistent with the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, and are determined by arranging the bounding boxes of the virtual objects in the target scene based on a greedy algorithm.
[0146] That is, when the electronic device arranges the bounding boxes of virtual objects in the target scene and determines the mapping coordinates of the virtual positions of the surfaces of virtual objects in the target scene in each set of blank light maps, the bounding boxes of virtual objects in the target scene can be arranged based on a greedy algorithm. In this way, the created blank light maps can be fully utilized to reduce the number of light maps created, thereby achieving a more unified and effective management of the light and shadow effects involved in the present application.
[0147] In some embodiments, see Figure 6 , Figure 6 A flow chart of the light and shadow effect superposition process provided in an embodiment of the present application. The process may include the following steps:
[0148] S601: Initialize two light maps and mark one as active.
[0149] In this step, the two initialized lightmaps are the aforementioned embodiments, in which the electronic device creates two sets of blank lightmaps, arranges the bounding boxes of the virtual objects in the target scene, determines the mapping coordinates of the virtual positions of the surfaces of the virtual objects in the target scene in each set of blank lightmaps, and then activates any set of blank lightmaps to obtain the initial activated lightmaps. Correspondingly, the other set of inactivated blank lightmaps is the initial inactivated lightmap.
[0150] S602: Sampling directional light.
[0151] In this step, sampling directional light is to sample the illumination direction currently generated by the light source in the target scene in the aforementioned embodiment to obtain the current direction to be processed.
[0152] S603: Render the scene with directional light, and superimpose the rendering result and the output activation light map.
[0153] In this step, the scene is the target scene in the above embodiment, and the directional light used to render the scene is the light in the current direction to be processed in the above embodiment. The superimposed light and shadow effect corresponding to the last image frame obtained after the target scene in the above embodiment is updated, which is recorded in the activated light map, is output.
[0154] The electronic device will perform direct illumination rendering on the target scene according to the light in the current direction to be processed, and obtain the light and shadow effect corresponding to the current image frame to be generated of the target scene as the current light and shadow effect to be superimposed. And according to the pre-recorded mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current unactivated light map, determine the current light and shadow effect to be superimposed, and the light intensity at the same virtual position in the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated; superimpose the determined light intensities at the same virtual position to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated.
[0155] S604: Store to the activated light map.
[0156] In this step, the electronic device records the superimposed light and shadow effects corresponding to the current image frame to be generated in the current activated light map according to the pre-recorded mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map.
[0157] S605, swapping activation flags of two light maps.
[0158] In this step, the activation mark indicates the activation state of the light map in the above-mentioned embodiment. That is, after the electronic device records the superimposed light and shadow effects corresponding to the current image frame to be generated in the current activated light map, it adjusts the current activated light map to the inactive state, and adjusts the current inactive light map to the active state.
[0159] S606: Output activation light map.
[0160] In this step, the light and shadow effects recorded in the activated light map that is finally output are the light and shadow effects to be rendered in the aforementioned embodiment.
[0161] Based on the above processing, when the target scene is updated, for the current image frame to be generated, the electronic device will perform direct illumination rendering on the target scene based on the light in the current direction to be processed obtained by sampling, and obtain the current light and shadow effect to be superimposed. For each image frame to be generated, the amount of calculation can be reduced by reducing the number of light to be processed by sampling and avoiding the calculation of the light and shadow effect generated by each reflection of the light by direct illumination rendering. In addition, the superimposed light and shadow effect corresponding to the current image frame to be generated is obtained by superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, and the light and shadow effect to be used when generating the current image frame to be generated is obtained. That is, when each image frame is obtained, the light and shadow effect generated by the light in the direction to be processed obtained by sampling corresponding to the image frame itself, and the light and shadow effects of all image frames generated before the image frame after the target scene is updated, are combined to obtain the light and shadow effect used when obtaining the image frame. In this way, as the rendering process continues to advance, the image frame will be obtained based on the light and shadow effects generated by the light in the direction to be processed obtained by more and more sampling. It is understandable that when the target scene is updated to obtain a preset number of image frames, the generated preset number of image frames also combines the light and shadow effects produced by light from more directions, which is closer to the situation where there are light from more directions in the real scene, and the obtained light and shadow effects are more realistic. Rendering the target scene based on more realistic light and shadow effects can improve the realism of the rendered target scene. In the above process, the calculation of the light and shadow effects produced by a large number of lights can be distributed in a preset number of image frames, so the amount of calculation allocated when generating each image frame is very small, and it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time. In this way, the performance requirements for hardware devices will be relatively lower, and the performance requirements for hardware devices will be reduced on the premise of being able to obtain image frames of realistic scenes. In addition, since it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time, the time required to generate each image frame will be reduced accordingly, and real-time rendering can be well achieved.
[0162] In some embodiments, see Figure 7 , Figure 7 A schematic diagram of a scene rendering method provided in an embodiment of the present application. Figure 7 In the schematic diagram shown, the scene rendering method is implemented by a scattered light probability distribution module, a real-time mixing and overlay module, and a scene rendering module.
[0163] The scattered light probability distribution module is used to determine the probability distribution of the scattered light direction through the main light source in the scene, and perform directional light sampling according to the probability distribution, that is, in the aforementioned embodiment, the illumination direction currently generated by the light source in the target scene is sampled to obtain the current direction to be processed.
[0164] The real-time mixing and overlaying module is used to independently render the scene using a separate directional light source, integrate the UV map coordinates in the scene, obtain a light map for storing diffuse lighting information, and mix and overlay the light and shadow data rendered by the independent directional light on this map, so as to subsequently provide the light map in real time for the scene rendering module.
[0165] The use of a separate directional light source to independently render a scene is the same as in the aforementioned embodiment: performing direct illumination rendering on the target scene according to the light from the current direction to be processed.
[0166] The UV mapping coordinates in the integrated scene are as in the aforementioned embodiment: the bounding boxes of the virtual objects in the target scene are arranged to obtain the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map, and the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map.
[0167] The light map used to store diffuse lighting information is the inactive light map and the active light map in the aforementioned embodiment.
[0168] The light and shadow data rendered by the independent directional light are mixed and superimposed on this map, that is, in the aforementioned embodiment: the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated are superimposed to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated.
[0169] The scene rendering module is used to detect whether the target scene is updated, such as whether the position of the virtual object and the position of the light source in the scene move. When the target scene is detected to be updated, that is, when the light source or scene changes, sampling can be performed through the scattered light probability distribution module.
[0170] The scene rendering module is also used to select an inactivated light map as the light map input in the object real-time rendering material. Then the scene rendering is performed through any real-time rendering model that supports light maps. That is, based on the superimposed light and shadow effects corresponding to the current image frame to be generated, and the attribute map representing the attributes of the virtual object itself in the target scene in the aforementioned embodiment, the target scene is rendered using the direct lighting model to obtain the current image frame to be generated.
[0171] Based on the above processing, when the target scene is updated, for the current image frame to be generated, the electronic device will perform direct illumination rendering on the target scene based on the light in the current direction to be processed obtained by sampling, and obtain the current light and shadow effect to be superimposed. For each image frame to be generated, the amount of calculation can be reduced by reducing the number of light to be processed by sampling and avoiding the calculation of the light and shadow effect generated by each reflection of the light by direct illumination rendering. In addition, the superimposed light and shadow effect corresponding to the current image frame to be generated is obtained by superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, and the light and shadow effect to be used when generating the current image frame to be generated is obtained. That is, when each image frame is obtained, the light and shadow effect generated by the light in the direction to be processed obtained by sampling corresponding to the image frame itself, and the light and shadow effects of all image frames generated before the image frame after the target scene is updated, are combined to obtain the light and shadow effect used when obtaining the image frame. In this way, as the rendering process continues to advance, the image frame will be obtained based on the light and shadow effects generated by the light in the direction to be processed obtained by more and more sampling. It is understandable that when the target scene is updated to obtain a preset number of image frames, the generated preset number of image frames also combines the light and shadow effects produced by light from more directions, which is closer to the situation where there are light from more directions in the real scene, and the obtained light and shadow effects are more realistic. Rendering the target scene based on more realistic light and shadow effects can improve the realism of the rendered target scene. In the above process, the calculation of the light and shadow effects produced by a large number of lights can be distributed in a preset number of image frames, so the amount of calculation allocated when generating each image frame is very small, and it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time. In this way, the performance requirements for hardware devices will be relatively lower, and the performance requirements for hardware devices will be reduced on the premise of being able to obtain image frames of realistic scenes. In addition, since it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time, the time required to generate each image frame will be reduced accordingly, and real-time rendering can be well achieved.
[0172] It can be seen that since the scene rendering method provided by the present application has low performance requirements for hardware devices when rendering scenes, the present method can be applied to ordinary computers and can run smoothly in browser environments with relatively poor performance without the need to be equipped with high-performance hardware; by distributing the calculation of light and shadow effects generated by a large amount of light in a preset number of image frames, the rendering effect is gradually superimposed and presented as the image frames are rendered, which will not cause program blocking, making the user unaware of the rendering process, and naturally improving the user experience.
[0173] Moreover, compared with the existing method of pre-calculating lightmaps that is only applicable to fixed scenes, this solution can still obtain the superimposed light and shadow effects corresponding to the current image frame to be generated after the target scene is updated, and the light and shadow effects of the target scene can still be rendered later. This capability not only improves the longitude and intuitive performance of data visualization, but also enhances the efficiency and accuracy of the decision-making process, and promotes the intelligent and digital transformation of multiple fields such as industry, urban management, and medical care.
[0174] Based on the same inventive concept as the above-mentioned scene rendering method, the present application embodiment also provides a scene rendering device. Figure 8 , Figure 8 A structural diagram of a scene rendering device provided in an embodiment of the present application, the device includes:
[0175] The sampling module 801 is used to sample the illumination direction currently generated by the light source in the target scene when the target scene is updated, so as to obtain the current direction to be processed;
[0176] The first rendering module 802 is used to perform direct illumination rendering on the target scene according to the light in the current direction to be processed, and obtain the light and shadow effect corresponding to the image frame to be generated currently of the target scene as the current light and shadow effect to be superimposed; wherein the light and shadow effect to be superimposed includes: the light intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the light in the current direction to be processed;
[0177] The superposition module 803 is used to superimpose the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, so as to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated;
[0178] The second rendering module 804 is used to render the target scene using a direct lighting model based on the superimposed light and shadow effects corresponding to the current image frame to be generated and the attribute map representing the attributes of the virtual object itself in the target scene, to obtain the current image frame to be generated, and return to execute the step of sampling the lighting direction currently generated by the light source in the target scene to obtain the current direction to be processed, until a preset number of image frames are obtained after the target scene is updated.
[0179] Optionally, the sampling module 801 is specifically used to: generate a random number within a specified numerical range as a first random number; if the generated first random number is greater than the ambient scattered light probability weight, randomly generate a lighting direction in the target scene to obtain a current direction to be processed; wherein the ambient scattered light probability weight represents the reflectivity of the target scene; the ambient scattered light probability weight belongs to the specified numerical range; if the generated first random number is not greater than the ambient scattered light probability weight, perform random sampling based on the probability distribution of the direction of the incident light of the light source in the target scene to obtain the current direction to be processed.
[0180] Optionally, there are multiple first random numbers; the superposition module 803 is specifically used to: for each first random number, directly render the target scene according to the light in the direction to be processed obtained based on the first random number, to obtain the light and shadow effect of the image frame to be generated currently of the target scene for the first random number; calculate the average level of the light and shadow effects rendered using each first random number as the current light and shadow effect to be superimposed.
[0181] Optionally, the probability distribution is a normal distribution with the main direction of the incident light of the light source as the center and the scattering degree of the light source as the variance.
[0182] Optionally, the sampling module 801 is specifically used to: generate a random number in the range of 0 to 1 as a second random number; determine a direction representing a corresponding probability of the second random number in a normal distribution, and obtain a current direction to be processed.
[0183] Optionally, the device also includes: an acquisition module, which is used to execute, before the superposition module 803 executes superposition of the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, to obtain the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated from the current inactivated light map; the superposition module 803 is specifically used to: determine the light intensity at the same virtual position in the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map; superimpose the determined light intensities at the same virtual position to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated. The device also includes: a recording module, which is used to perform superposition of the current light and shadow effects to be superimposed and the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated in the superposition module 803 to obtain the superimposed light and shadow effects corresponding to the image frame to be generated, and then execute according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, record the superimposed light and shadow effects corresponding to the image frame to be generated in the current activated light map; adjust the current activated light map to an inactivated state, and adjust the current inactivated light map to an activated state; the second rendering module 804 is specifically used to: based on the current inactivated light map and the attribute map representing the attributes of the virtual object itself in the target scene, use the direct lighting model to render the target scene to obtain the image frame to be generated.
[0184] Optionally, the superposition module 803 is specifically used to: superimpose the light intensity at the same virtual position determined according to the first weight of the current light and shadow effect to be superimposed and the second weight of the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, so as to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; wherein the sum of the first weight and the second weight is 1, and the first weight is the reciprocal of the sum of the preset number and the specified positive integer.
[0185] Optionally, the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map are consistent with the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, and are determined by arranging the bounding boxes of the virtual objects in the target scene based on a greedy algorithm.
[0186] Optionally, the update of the target scene includes: an update of a virtual object in the target scene, and / or an update of a light source in the target scene; the update of the virtual object in the target scene includes at least one of the following: an update of the position of the virtual object in the target scene, an update of the shape of the virtual object in the target scene, and an update of the number of virtual objects in the target scene; the update of the light source in the target scene includes at least one of the following: an update of the type of the light source in the target scene, an update of the position of the light source in the target scene, an update of the illumination intensity of the light source in the target scene, and an update of the number of light sources in the target scene.
[0187] Optionally, the attribute map includes at least one of the following: a color map, a normal map, and a material map.
[0188] Optionally, the device also includes: a third rendering module, which is used to render the target scene using a direct lighting model to obtain image frames based on the superimposed light and shadow effects used when obtaining a preset number of image frames after the target scene is updated, and the attribute map, until the target scene is updated again.
[0189] Based on the scene rendering device provided by the embodiment of the present application, when the target scene is updated, for the current image frame to be generated, the electronic device will perform direct illumination rendering on the target scene based on the light in the current direction to be processed obtained by sampling, and obtain the current light and shadow effect to be superimposed. For each image frame to be generated, the number of light rays to be processed is reduced by sampling, and the light and shadow effect generated by each reflection of the light is avoided by direct illumination rendering, so that the amount of calculation can be reduced. In addition, the superimposed light and shadow effect corresponding to the current image frame to be generated is obtained by superimposing the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, and the light and shadow effect to be used when generating the current image frame to be generated is obtained. That is, when each image frame is obtained, the light and shadow effect generated by the light in the direction to be processed obtained by sampling corresponding to the image frame itself, and the light and shadow effects of all image frames generated before the image frame after the target scene is updated, are combined to obtain the light and shadow effect used when obtaining the image frame. In this way, as the rendering process continues to advance, the image frame will be obtained based on the light and shadow effects generated by the light in the direction to be processed obtained by more and more sampling. It is understandable that when the target scene is updated to obtain a preset number of image frames, the generated preset number of image frames also combines the light and shadow effects produced by light from more directions, which is closer to the situation where there are light from more directions in the real scene, and the obtained light and shadow effects are more realistic. Rendering the target scene based on more realistic light and shadow effects can improve the realism of the rendered target scene. In the above process, the calculation of the light and shadow effects produced by a large number of lights can be distributed in a preset number of image frames, so the amount of calculation allocated when generating each image frame is very small, and it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time. In this way, the performance requirements for hardware devices will be relatively lower, and the performance requirements for hardware devices will be reduced on the premise of being able to obtain image frames of realistic scenes. In addition, since it is not necessary to calculate the light and shadow effects produced by a large number of lights at the same time, the time required to generate each image frame will be reduced accordingly, and real-time rendering can be well achieved.
[0190] The present application also provides an electronic device, such as Fig. 9 As shown, it includes: a memory 901 for storing computer programs; a processor 902 for implementing the steps of any scene rendering method in the above embodiments when executing the program stored in the memory 901.
[0191] Furthermore, the control device may further include a communication bus and / or a communication interface, and the processor 902, the communication interface, and the memory 901 communicate with each other via the communication bus.
[0192] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0193] The communication interface is used for communication between the above electronic device and other devices.
[0194] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0195] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0196] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned scene rendering methods are implemented.
[0197] In another embodiment provided in the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any scene rendering method in the above embodiments.
[0198] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integration. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a solid-state hard disk (SSD), etc.
[0199] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0200] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, control device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0201] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A scene rendering method, characterized in that: The method comprises: When the target scene is updated, sampling the illumination direction currently generated by the light source in the target scene to obtain the current direction to be processed; Direct illumination rendering is performed on the target scene according to the light in the current direction to be processed, and a light and shadow effect corresponding to the image frame to be generated of the target scene is obtained as the current light and shadow effect to be superimposed; wherein the light and shadow effect to be superimposed includes: the light intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the light in the current direction to be processed; Superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; Based on the superimposed light and shadow effects corresponding to the current image frame to be generated, and the attribute map representing the attributes of the virtual object itself in the target scene, the target scene is rendered using a direct lighting model to obtain the current image frame to be generated, and the step of sampling the lighting direction currently generated by the light source in the target scene to obtain the current direction to be processed is returned to execute until a preset number of image frames are obtained after the target scene is updated.
2. The method according to claim 1, characterized in that: Sampling the illumination direction currently generated by the light source in the target scene to obtain the current direction to be processed includes: Generate a random number within a specified numerical range as a first random number; If the generated first random number is greater than the ambient scattered light probability weight, randomly generate a lighting direction in the target scene to obtain a current direction to be processed; wherein the ambient scattered light probability weight represents the reflectivity of the target scene; and the ambient scattered light probability weight belongs to the specified value range; If the generated first random number is not greater than the ambient scattered light probability weight, random sampling is performed based on the probability distribution representing the direction of the incident light of the light source in the target scene to obtain the current direction to be processed.
3. The method according to claim 2, characterized in that The first random number is multiple; The target scene is directly illuminated and rendered according to the light in the current direction to be processed, so as to obtain the light and shadow effect corresponding to the image frame to be generated currently of the target scene as the current light and shadow effect to be superimposed, including: For each first random number, directly illuminate and render the target scene according to the light in the direction to be processed obtained based on the first random number, to obtain a light and shadow effect of the image frame to be generated currently of the target scene for the first random number; An average level of the light and shadow effects rendered using the first random numbers is calculated as the current light and shadow effect to be superimposed.
4. The method according to claim 2, characterized in that: The probability distribution is a normal distribution with the main direction of the incident light of the light source as the center and the scattering degree of the light source as the variance.
5. The method according to claim 4, characterized in that The randomly sampling based on the probability distribution of the direction of the incident light of the light source in the target scene to obtain the current direction to be processed includes: Generate a random number in the range of 0 to 1 as the second random number; Determine a direction representing a corresponding probability of the second random number in a normal distribution, and obtain a current direction to be processed.
6. The method according to claim 1, characterized in that Before superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated, the method further includes: Obtaining, from the current inactivated light map, the superimposed light and shadow effects corresponding to the last image frame obtained after the target scene is updated; The superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated, includes: Determine the light intensity at the same virtual position in the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated according to the pre-recorded map coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map; superimpose the determined light intensities at the same virtual position to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; After superimposing the current light and shadow effect to be superimposed and the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated, the method further includes: According to the pre-recorded mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, the superimposed light and shadow effects corresponding to the current image frame to be generated are recorded in the current activated light map; the current activated light map is adjusted to an inactivated state, and the current inactivated light map is adjusted to an activated state; The method of rendering the target scene by using a direct illumination model based on the superimposed light and shadow effects corresponding to the current image frame to be generated and the attribute map representing the attributes of the virtual object itself in the target scene to obtain the current image frame to be generated includes: Based on the current inactivated light map and the attribute map representing the attributes of the virtual objects in the target scene, the target scene is rendered using a direct lighting model to obtain the current image frame to be generated.
7. The method according to claim 6, characterized in that The step of superimposing the determined light intensities at the same virtual position to obtain the superimposed light and shadow effects corresponding to the current image frame to be generated includes: According to the first weight of the current light and shadow effect to be superimposed and the second weight of the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, the determined light intensity at the same virtual position is superimposed to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; The sum of the first weight and the second weight is 1, and the first weight is the reciprocal of the sum of the preset number and the specified positive integer.
8. The method according to claim 6, characterized in that The mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current inactivated light map are consistent with the mapping coordinates of the virtual position of the surface of the virtual object in the target scene in the current activated light map, and are determined by arranging the bounding boxes of the virtual objects in the target scene based on a greedy algorithm.
9. The method according to claim 1, characterized in that: The target scene is updated including: a virtual object in the target scene is updated, and / or a light source in the target scene is updated; The updating of the virtual object in the target scene includes at least one of the following: the position of the virtual object in the target scene is updated, the shape of the virtual object in the target scene is updated, and the number of virtual objects in the target scene is updated; The updating of the light source in the target scene includes at least one of the following: the type of the light source in the target scene is updated, the position of the light source in the target scene is updated, the illumination intensity of the light source in the target scene is updated, and the number of the light sources in the target scene is updated.
10. The method according to claim 1, characterized in that The attribute map includes at least one of the following: a color map, a normal map, and a material map.
11. The method according to claim 1, characterized in that The method further comprises: Based on the superimposed light and shadow effects used when obtaining a preset number of image frames after the target scene is updated, and the attribute map, the target scene is rendered using a direct illumination model to obtain image frames until the target scene is updated again.
12. A scene rendering device, characterized in that: The device comprises: A sampling module, used for sampling the illumination direction currently generated by the light source in the target scene when the target scene is updated, to obtain the current direction to be processed; A first rendering module is used to perform direct illumination rendering on the target scene according to the light in the current direction to be processed, and obtain the light and shadow effect corresponding to the image frame to be generated currently of the target scene as the current light and shadow effect to be superimposed; wherein the light and shadow effect to be superimposed includes: the light intensity at each virtual position on the surface of the virtual object in the target scene under the illumination of the light in the current direction to be processed; A superposition module, used for superimposing the current light and shadow effect to be superimposed with the superimposed light and shadow effect corresponding to the last image frame obtained after the target scene is updated, to obtain the superimposed light and shadow effect corresponding to the current image frame to be generated; The second rendering module is used to render the target scene using a direct lighting model based on the superimposed light and shadow effects corresponding to the current image frame to be generated and the attribute map representing the attributes of the virtual object itself in the target scene, to obtain the current image frame to be generated, and return to execute the step of sampling the lighting direction currently generated by the light source in the target scene to obtain the current direction to be processed, until a preset number of image frames are obtained after the target scene is updated.
13. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-11 when executing a program stored in a memory.
