Photon mapping and path tracing based rendering method, device, equipment and medium
By employing a rendering method based on photon allocation and path tracing, and utilizing photon maps and initial ray values for path tracing, the issues of rendering efficiency and quality are resolved, resulting in highly efficient and high-quality rendering effects.
Patent Information
- Application Number
- CN202411593748.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2044-11-08
AI Technical Summary
Existing technologies in photon mapping and path tracing rendering methods struggle to improve rendering quality while maintaining rendering efficiency, especially when dealing with complex scenes where rendering times are long.
By acquiring light source and object information from the scene file, a photon allocation algorithm is used to determine photon allocation information, a photon map is generated, and the initial values of light rays are determined based on the photon map for path tracing. Pixel accumulation is then performed in conjunction with light color records to achieve efficient rendering.
While ensuring rendering efficiency, it improves rendering quality, effectively simulating global illumination and complex lighting effects to generate high-quality rendered images.
Smart Images

Figure CN119722890B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a rendering method and device based on photon mapping and path tracing, a computer device and a storage medium. BACKGROUND
[0002] Offline rendering refers to a rendering process in computer graphics that does not rely on real-time performance, and is usually used to generate high-quality images or animations. It can improve the visual effect of images as much as possible without considering the rendering time.
[0003] Photon mapping and path tracing are two commonly used methods in offline rendering. Photon mapping is a rendering method based on photons, which generates a rendered image by tracking the path of real photons. This method has efficient global illumination modeling capabilities and is suitable for handling complex indirect lighting effects. However, in some scenarios, photon mapping may not effectively simulate the propagation of light, resulting in lower rendering quality. Path tracing is a rendering technique based on the Monte Carlo method, which simulates the propagation and reflection of light by tracking the path of light rays in the scene. It can be used to simulate various lighting effects, including global illumination, shadows, and specular reflection. However, rendering through path tracing is slow, especially when dealing with complex scenes, which requires a long rendering time. Therefore, how to improve rendering quality while ensuring rendering efficiency has become a problem to be solved. SUMMARY
[0004] The present application provides a rendering method and device based on photon mapping and path tracing, a computer device and a storage medium to improve rendering quality while ensuring rendering efficiency.
[0005] In a first aspect, the present application provides a rendering method based on photon mapping and path tracing, which comprises:
[0006] Obtain light source information and object information in a scene file, and analyze the light source information and the object information based on a preset photon distribution algorithm to determine photon distribution information;
[0007] Based on the photon distribution information, control photon propagation, record photon path information, and generate a photon mapping image based on the photon path information;
[0008] Based on the photon mapping image, determine the initial value of the light ray, and emit the light ray based on the initial value of the light ray for path tracing to obtain light ray color records;
[0009] Based on the light ray color records, perform pixel accumulation to obtain a target rendering image.
[0010] In a second aspect, the present application also provides a rendering device based on photon mapping and path tracing, the device comprising:
[0011] a photon distribution information determination module, configured to acquire light source information and object information in a scene file, and analyze the light source information and the object information based on a preset photon distribution algorithm to determine photon distribution information;
[0012] a photon mapping diagram generation module, configured to control photon propagation based on the photon distribution information, record photon path information, and generate a photon mapping diagram based on the photon path information;
[0013] a ray color record obtaining module, configured to determine a ray initial value based on the photon mapping diagram, emit a ray based on the ray initial value for path tracing, and obtain a ray color record;
[0014] a target rendering image obtaining module, configured to perform pixel accumulation based on the ray color record to obtain a target rendering image.
[0015] In a third aspect, the present application also provides a computer device, comprising a memory and a processor; the memory is configured to store a computer program; the processor is configured to execute the computer program and implement the rendering method based on photon mapping and path tracing as described above when executing the computer program.
[0016] In a fourth aspect, the present application also provides a computer readable storage medium, which stores a computer program, and the computer program makes the processor implement the rendering method based on photon mapping and path tracing as described above when executed by the processor.
[0017] The application discloses a rendering method and device based on photon mapping and path tracking, a computer device and a storage medium. Light source information and object information in a scene file are acquired, and the light source information and the object information are analyzed based on a preset photon distribution algorithm to determine photon distribution information. Based on the photon distribution information, photon propagation is controlled, photon path information is recorded, and a photon mapping diagram is generated based on the photon path information. Based on the photon mapping diagram, initial values of light rays are determined, path tracking is performed based on the initial values of the light rays, and light ray color records are obtained. Pixel accumulation is performed based on the light ray color records to obtain a target rendering image. The application first distributes photons according to the light source information and the object information, uses photon mapping to quickly simulate global illumination, obtains a photon mapping diagram, reduces unnecessary photon tracking, and improves the efficiency of obtaining the photon mapping diagram. Then, initial values of light rays are determined according to the photon mapping diagram, path tracking is performed on the light rays emitted based on the initial values of the light rays, the propagation and reflection of the light rays can be effectively simulated, and a target rendering image is obtained. The rendering is realized by combining photon mapping and path tracking, the rendering efficiency is ensured, and the rendering quality is improved. BRIEF DESCRIPTION OF DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.
[0019] Figure 1 is a first embodiment schematic flow chart of a rendering method based on photon mapping and path tracking provided by an embodiment of the application;
[0020] Figure 2 is a second embodiment schematic flow chart of a rendering method based on photon mapping and path tracking provided by an embodiment of the application;
[0021] Figure 3 is a second embodiment schematic flow chart of a rendering method based on photon mapping and path tracking provided by an embodiment of the application;
[0022] Figure 4 is a schematic block diagram of a rendering device based on photon mapping and path tracking provided by an embodiment of the application;
[0023] Figure 5 is a structural schematic block diagram of a computer device provided by an embodiment of the application. DETAILED DESCRIPTION
[0024] With reference to the drawings, the technical solutions in the embodiments of the present application will be clearly and completely described below, obviously, the described embodiments are some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work belong to the protection scope of the present application.
[0025] The flowcharts shown in the drawings are only illustrative, not necessarily including all the contents and operations / steps, and not necessarily executed in the described order. For example, some operations / steps can also be decomposed, combined or partially merged, so that the actual execution order may be changed according to the actual situation.
[0026] It should be understood that the terms used in the specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and the appended claims of the present application, unless otherwise clear from the context, the singular forms "a", "an" and "the" are intended to include the plural forms.
[0027] It should also be understood that the term "and / or" used in the specification and the appended claims of the present application means any combination of one or more of the associated listed items and all possible combinations, and includes these combinations.
[0028] Embodiments of the present application provide a rendering method and device based on photon mapping and path tracing, a computer device and a storage medium. The rendering method based on photon mapping and path tracing can be applied to a server. First, photons are distributed according to light source information and object information, global illumination is simulated quickly by using photon mapping, a photon mapping diagram is obtained, unnecessary photon tracking is reduced, and the efficiency of obtaining the photon mapping diagram is improved. Then, the initial value of a light ray is determined according to the photon mapping diagram, and the path of the light ray emitted based on the initial value of the light ray is tracked, which can effectively simulate the propagation and reflection of the light ray and obtain a target rendering image. The rendering is realized by combining photon mapping and path tracing, which improves the rendering quality while ensuring the rendering efficiency. The server can be a standalone server or a server cluster.
[0029] Some embodiments of the present application will be described in detail below with reference to the drawings. The following embodiments and features in the embodiments can be combined with each other without conflict.
[0030] Please refer to Figure 1 , Figure 1Is an embodiment of the present application provides a kind of based on photon mapping and path tracking rendering method schematic flow chart.The rendering method based on photon mapping and path tracking can be applied in server, first, according to light source information and object information, photon is distributed, utilizes photon mapping, quickly simulates global illumination, obtains photon mapping chart, reduces unnecessary photon tracking, improves the efficiency of obtaining photon mapping chart.Then, according to the initial value of light ray determined by photon mapping chart, the light ray based on the initial value of light ray is tracked, and the propagation and reflection of light ray can be effectively simulated, and target rendering image is obtained.Combined with photon mapping and path tracking to realize rendering, while guaranteeing rendering efficiency, the rendering quality is improved.
[0031] As Figure 1 The rendering method based on photon mapping and path tracking specifically includes steps S101 to S104.
[0032] S101, obtain light source information and object information in scene file, and based on the preset photon distribution algorithm, the light source information and the object information are analyzed, and the photon distribution information is determined;
[0033] In one embodiment, the scene file is parsed to obtain detailed information of the scene, including light source information of the scene and object information in the scene. The scene file can be a file used to describe and store three-dimensional scene data in the fields of computer graphics, three-dimensional modeling, animation production and game development, which contains all the information required for building and rendering three-dimensional scenes.
[0034] Specifically, the object information includes the geometric information of the object, such as vertex, face, normal, etc., and the material properties of the object, such as reflectivity, transmittance, roughness, etc. Specifically, the light source information includes the position, type (point light source, parallel light, spotlight, etc.) and attributes (color, intensity) of each light source.
[0035] In one embodiment, the photon distribution algorithm can be stored in an intelligent photon management system. When the light source information and object information of the scene are obtained, the intelligent photon management system is called to determine the distribution of photons according to the characteristics of the light source and the object by using the photon distribution algorithm, to adjust the photon density in different regions of the scene, and to obtain the photon distribution information.
[0036] For example, for the area directly irradiated by strong light or the surface of the object with high reflectivity or high refractive material, more photons are allocated to capture complex lighting effects and ensure sufficient lighting details; while for the shadow area or the background far from the viewpoint, the number of photons is reduced to save computing resources.
[0037] S102, control photon propagation based on the photon distribution information, record photon path information, and generate a photon map based on the photon path information;
[0038] Further, the step S102 includes: based on the photon distribution information, controlling photon propagation, and based on a preset photon mapping algorithm, the object information and the light source information, performing photon mapping to obtain the photon path information; based on the photon path information, pre-computing to obtain pre-computed data of photon hit positions; and based on the photon path information and the pre-computed data, generating the photon map.
[0039] In one embodiment, the photon distribution information can include the number of photons, the incident direction and other information. Photons are emitted from the light source or a predetermined photon emission position according to the photon distribution information, and propagate towards the target direction. The path of the photons in the scene is tracked until they hit the surface of the object or reach a preset number of propagation times. When the photons hit the surface of the object, the position, incident direction and energy of the photons and other information are recorded. The intersection information of all photons and the object is collected to form the photon path information.
[0040] In one embodiment, based on the photon path information, the normal direction and radiance (energy of the photons) of the photon hit position are pre-computed and recorded. The photon path information and the pre-computed data are stored in the photon map, including the position, direction, color and energy of the photons.
[0041] The photon map can be used to simulate the global lighting effect in the scene, including indirect lighting and caustics.
[0042] In another embodiment, during the photon mapping process, multiple nodes can also be set up, and each photon is tracked and related calculations are performed to achieve parallel processing and improve efficiency.
[0043] In the above embodiment, the pre-computed data is obtained by pre-computing based on the photon path information. In the subsequent path tracking rendering process, the pre-computed data in the photon map can be directly used to speed up the related calculations when the light intersects with the object, thereby improving the rendering efficiency. Moreover, the photon mapping technology can effectively simulate complex lighting effects, thereby improving the rendering quality.
[0044] S103, based on the photon map, determine the initial value of the light ray, and emit the light ray based on the initial value of the light ray to perform path tracking to obtain light ray color records;
[0045] In one embodiment, the origin of the light ray is obtained, which is usually the position of the camera. For each origin of the light ray, the distance between it and all the photons in the photon map is calculated. The photon with the shortest distance to the origin is selected as the target photon, and the incident direction of the target photon is taken as the initial direction of the light ray, and the color of the target photon is taken as the initial color of the light ray.
[0046] In one embodiment, a light ray is emitted from the origin of the light ray according to the initial value of the light ray. The path of the light ray in the scene is tracked, and it is determined whether the light ray intersects with an object. When the light ray intersects with an object, the interaction between the light ray and the object is determined, including reflection, refraction or absorption of the light ray. At each point where the light ray intersects with the object, the color of the light ray at the point is calculated to generate a light ray color record.
[0047] Further, the initial value of the light ray includes the initial direction of the light ray and the initial color of the light ray, and the initial value of the light ray is determined based on the photon map, including: obtaining the origin of the light ray; calculating the distance between each photon in the photon map and the origin of the light ray, and selecting the photon with the shortest distance as the target photon; obtaining the incident direction and color information of the target photon, and taking the incident direction as the initial direction of the light ray and the color information as the initial color of the light ray.
[0048] In one embodiment, the origin of the light ray is usually the position of the camera, or more specifically, the center of the camera lens or the center of the pixel.
[0049] A pre-generated photon map is loaded, and for each origin of the light ray, the Euclidean distance between it and all the photons in the photon map is calculated. Among all the calculated distances, the smallest distance is found, and the corresponding photon is determined as the target photon.
[0050] The incident direction and color information of the target photon are obtained from the photon map. The incident direction of the target photon is taken as the initial direction of the light ray emitted from the origin of the light ray. The color information of the target photon is taken as the initial color of the light ray.
[0051] In one embodiment, the energy of the target photon can also be taken as the initial energy of the light ray.
[0052] S104, pixel accumulation is performed based on the light ray color record to obtain a target rendering image.
[0053] Further, the step S104 includes: obtaining the position information of each pixel of the image to be rendered in the scene file; based on the position information and the light ray color record, obtaining the light ray color and energy value of at least one light ray corresponding to each pixel; based on the energy value, weighting and accumulating at least one light ray color of each pixel to obtain the target rendering image.
[0054] In one embodiment, the scene file is parsed to obtain the geometry data of all objects in the scene and the camera settings, and a three-dimensional scene graph is constructed. For each pixel in the image to be rendered, its position in the three-dimensional scene graph is determined. Specifically, the two-dimensional pixel coordinates can be converted into three-dimensional world coordinates through the projection matrix and view matrix of the camera.
[0055] The weight is calculated according to the energy value of each light ray. The higher the energy value, the greater the contribution of the corresponding light ray color to the pixel color, i.e. the higher the weight of the light ray color.
[0056] For each pixel, all light rays passing through the pixel are found according to its position information and light ray path information, and the corresponding light ray colors of all light rays are obtained from the light ray color record. All light ray colors passing through the pixel are weighted according to their corresponding weights of energy values, and then the weighted color values are accumulated to obtain the final color of the pixel. Complex lighting effects, including direct lighting, indirect lighting, reflection and refraction, can be effectively simulated, thereby producing high-quality rendering results.
[0057] The final color values of all pixels are synthesized to form the target rendering image. In order to improve the image quality, anti-aliasing processing is performed on the image to smooth the pixel edges and reduce visual noise.
[0058] Please refer to Figure 2 , Figure 2 is a schematic flowchart of a rendering method based on photon mapping and path tracing provided by an embodiment of the present application. The rendering method based on photon mapping and path tracing can be applied in a server, can effectively analyze the scene for lighting and objects, and determine photon distribution information based on a photon distribution algorithm. It can allocate more photons to areas with strong light irradiation or surfaces with high reflective materials to ensure sufficient lighting details, reduce the number of photons in shadow areas to save computing resources and computing amount, and improve rendering quality and efficiency.
[0059] As shown in Figure 2 , the rendering method based on photon mapping and path tracing specifically includes steps S201 to S203.
[0060] S201, performing scene lighting analysis on the scene file to obtain the light source information;
[0061] S202, performing object geometry analysis and object material property analysis on the scene file to obtain the object information;
[0062] S203, based on the photon distribution algorithm, analyzing the light source information and the object information to determine at least one scene area and the photon density of each scene area, and obtaining the photon distribution information.
[0063] In one embodiment, the lighting conditions in the scene file are analyzed to obtain light source information, including the location, type (point light, parallel light, spotlight, etc.), intensity, and color of all light sources. For light sources with attenuation, their attenuation parameters are recorded to calculate the reduction in light intensity with distance.
[0064] In one embodiment, the geometric shape and material properties of objects in the scene file are analyzed to obtain object information. This may include the object's 3D model data, such as vertices, edges, and faces; the normal information of the object's surface; and the object's surface material properties, such as reflectivity, transmissivity, and roughness.
[0065] In one embodiment, a photon allocation algorithm is used to determine the photon density of different scene areas based on light source and object information.
[0066] In a specific embodiment, the photon allocation algorithm divides the 3D scene map corresponding to the scene file into multiple regions based on light source information and object information. Then, based on the light source intensity, object material properties, and scene geometry of each region, it calculates the photon density and photon distribution pattern (e.g., uniform distribution or distribution based on a specific pattern) of each region. The photon density and distribution pattern of the storage grid regions are used to obtain photon allocation information.
[0067] In the above embodiments, lighting and object analysis of the scene can be effectively performed, and photon allocation information can be determined based on the photon allocation algorithm. More photons can be allocated to areas with strong light or surfaces with highly reflective materials to ensure sufficient lighting details, while reducing the number of photons in shadow areas to save computing resources and computational load, thereby improving rendering quality and efficiency.
[0068] Please see Figure 3 , Figure 3 This is a schematic flowchart illustrating a rendering method based on photon mapping and path tracing, provided in an embodiment of this application. This rendering method, based on photon mapping and path tracing, can be applied to servers to accurately reflect the physical behavior of light rays in a 3D scene through path tracing, thereby generating high-quality rendered images. Using pre-calculated data from the photon map avoids extensive real-time computation, improving rendering efficiency.
[0069] like Figure 3 As shown, the rendering method based on photon mapping and path tracing specifically includes steps S301 to S305.
[0070] S301. Emit light based on the initial light value and perform path tracing on the light;
[0071] S302, when the intersection of the light ray and the object in the scene is tracked, pre-computed data of the intersection point is obtained based on the photon map;
[0072] S303, based on the pre-computed data, the object information and the light source information, the light ray color of the light ray at the intersection point and the interaction relationship between the light ray and the object surface are determined;
[0073] S304, when the interaction relationship is reflection or refraction, the current tracking depth is updated, and the energy value of the refracted light ray or the reflected light ray is calculated based on the pre-computed data and the object information;
[0074] S305, when the current tracking depth is greater than the preset tracking depth threshold and / or the energy value is less than the preset energy threshold, the tracking is stopped, the light ray color of each intersection point is obtained, and the light ray color record is generated.
[0075] In one embodiment, the light rays are emitted from the camera or the light source according to the initial value of the light rays, and their paths in the scene are tracked.
[0076] In one embodiment, when the light ray intersects with the object, the photon map is queried to obtain the pre-computed data of the intersection point, such as the position of the photon hit, the normal direction and the radiance.
[0077] In one embodiment, the color of the light ray at the intersection point is calculated in combination with the material properties of the object, the color of the light source and the pre-computed data of the photon map. For example, for the object surface with diffuse reflection properties, the diffuse reflection color of the object surface is multiplied by the incident light ray color to obtain the light ray color at the intersection point.
[0078] According to the material properties of the object (such as reflection, refraction or absorption) and the incident angle of the light ray, the interaction relationship between the light ray and the object surface is determined. The interaction relationship includes reflection, refraction and absorption.
[0079] If the interaction relationship between the light ray and the object surface is reflection or refraction, the current tracking depth is updated. According to the BRDF (Bidirectional Reflectance Distribution Function) of the object, the pre-computed data of the photon map and the light source information, the energy value of the new reflected light ray or refracted light ray is calculated.
[0080] The update of the current tracking depth can be that a fixed value is added to the initial value of the tracking depth each time the light ray is emitted or refracted on the object surface. For example, the initial value of the tracking depth can be 1, and when the light ray is emitted or refracted on the object surface, 1 is added to the initial value, i.e. the current tracking depth is 2.
[0081] At each intersection of the ray with an object, the tracing depth and energy value are updated. The tracing is stopped when the current tracing depth is equal to or greater than the tracing depth threshold and / or the energy value is less than the energy threshold. The ray color of all intersection points is collected to generate a ray color record.
[0082] In another embodiment, if the interaction of the ray with the object surface is absorption, the tracing of the ray is stopped.
[0083] In another embodiment, if the ray encounters a surface with high reflectivity, multiple new reflected rays can be generated. The path tracing and related calculations for each reflected ray can be performed by multiple nodes simultaneously to achieve parallel processing and improve efficiency.
[0084] In the above embodiments, the physical behavior of the ray in the three-dimensional scene is accurately reflected by path tracing, thereby generating a high-quality rendered image. The use of pre-computed data in the photon map avoids a large amount of real-time calculation, improving rendering efficiency.
[0085] Further, after the step S304, the method further comprises: when the current tracing depth is not greater than the tracing depth threshold and the energy value is greater than or equal to the energy threshold, calculating a refraction direction and a ray color of the refracted ray or a reflection direction and a ray color of the reflected ray based on the pre-computed data, the object information, and the light source information; performing path tracing on the refracted ray or the reflected ray based on the refraction direction or the reflection direction, and updating the current tracing depth and the energy value when the refracted ray or the reflected ray intersects with an object surface, and recording the ray color of each intersection point.
[0086] In one embodiment, if the current tracing depth is less than a preset tracing depth threshold and the energy value is greater than or equal to a preset energy threshold, the path tracing of the reflected ray or the refracted ray is continued.
[0087] The tracing depth threshold is used to limit the maximum number of reflections and refractions of the ray in the scene, to control the rendering time and the calculation complexity. The energy threshold is used to ensure that the contribution of the ray to the final pixel color is significant, avoiding tracing rays with too low energy and little effect on the image.
[0088] The direction and color of the reflected or refracted ray can be calculated using a physical model. Specifically, for the refracted ray, the refraction angle can be calculated using Snell's law, and the color of the refracted ray can be determined according to the material properties of the object and the color of the light source. For the reflected ray, the reflection angle can be calculated according to the incident angle and the normal direction in the pre-computed data, and the color of the reflected ray can be determined according to the material properties of the object and the color of the light source.
[0089] In one embodiment, the path of the light ray is continued to be tracked along the calculated reflection or refraction direction. Each time the light ray is reflected or refracted, the current tracking depth is increased. The energy value of the light ray is updated according to the material properties (e.g. reflectance and transmittance) of the object and the propagation distance of the light ray. Generally, the energy of the light ray will decay with each reflection or refraction. If the interaction between the light ray and the surface of the object is absorption, the path tracking of the light ray is stopped.
[0090] At each time the light ray intersects with an object, the color of the light ray at the intersection point is calculated and recorded. Until the tracking depth exceeds a threshold value or the energy of the light ray is below a threshold value, the path tracking of the light ray is stopped and the color record of the light ray is obtained.
[0091] In the above embodiment, the rendering algorithm of path tracking can simulate the complex propagation path of the light ray in the three-dimensional scene, including light absorption and multiple reflections and refractions, so as to generate a realistic rendering image and improve the rendering quality. The pre-computed data in the photon mapping map is used to avoid a large amount of real-time calculation and improve the rendering efficiency.
[0092] Please refer to Figure 4 , Figure 4 An embodiment of the present application provides a schematic block diagram of a rendering device based on photon mapping and path tracking, which is used to execute the aforementioned rendering method based on photon mapping and path tracking. Wherein, the rendering device based on photon mapping and path tracking can be configured in a server.
[0093] As shown in Figure 4 , the rendering device based on photon mapping and path tracking 400 comprises:
[0094] A photon distribution information determination module is configured to acquire light source information and object information in a scene file, and analyze the light source information and the object information based on a preset photon distribution algorithm to determine photon distribution information.
[0095] A photon mapping map generation module is configured to control photon propagation based on the photon distribution information, record photon path information, and generate a photon mapping map based on the photon path information.
[0096] A light ray color record acquisition module is configured to determine a light ray initial value based on the photon mapping map, emit a light ray for path tracking based on the light ray initial value, and acquire a light ray color record.
[0097] A target rendering image acquisition module is configured to perform pixel accumulation based on the light ray color record to acquire a target rendering image.
[0098] Further, the photon distribution information determination module comprises:
[0099] The light source information obtaining unit is configured to perform scene lighting analysis on the scene file to obtain the light source information.
[0100] The object information obtaining unit is configured to perform object geometry analysis and object material characteristic analysis on the scene file to obtain the object information.
[0101] The photon distribution information obtaining unit is configured to analyze the light source information and the object information based on the photon distribution algorithm to determine at least one scene region and a photon density of each scene region, and obtain the photon distribution information.
[0102] Further, the target rendered image obtaining module comprises:
[0103] The position information obtaining unit is configured to obtain position information of each pixel of the image to be rendered in the scene file.
[0104] The ray color obtaining unit is configured to obtain a ray color and an energy value of at least one ray corresponding to each pixel based on the position information and the ray color record.
[0105] The color weighted accumulation unit is configured to perform weighted accumulation on at least one ray color of each pixel based on the energy value to obtain the target rendered image.
[0106] Further, the photon map generating module comprises:
[0107] The photon path information obtaining unit is configured to control photon propagation based on the photon distribution information, and perform photon mapping based on a preset photon mapping algorithm, the object information and the light source information to obtain the photon path information.
[0108] The pre-computation data obtaining unit is configured to perform pre-computation based on the photon path information to obtain pre-computation data of a photon hit position.
[0109] The photon map obtaining unit is configured to generate the photon map based on the photon path information and the pre-computation data.
[0110] Further, the ray color record obtaining module comprises:
[0111] The path tracing unit is configured to emit a ray based on the ray initial value, and perform path tracing on the ray.
[0112] The pre-computation data obtaining unit is configured to obtain pre-computation data of an intersection point based on the photon map when the ray intersects with an object in the scene is traced.
[0113] An action relationship determining unit is configured to determine the ray color of the ray at the intersection point and the action relationship between the ray and the object surface based on the pre-computed data, the object information, and the light source information;
[0114] An energy value calculating unit is configured to update the current tracking depth and calculate the energy value of the refracted ray or the reflected ray based on the pre-computed data and the object information when the action relationship is reflection or refraction.
[0115] A ray color record generating unit is configured to stop tracking and obtain the ray color of each intersection point and generate the ray color record when the current tracking depth is greater than a preset tracking depth threshold and / or the energy value is less than a preset energy threshold.
[0116] Further, the ray color record obtaining module further includes:
[0117] A ray color calculating unit is configured to calculate the refraction direction and the ray color of the refracted ray or the reflection direction and the ray color of the reflected ray based on the pre-computed data, the object information, and the light source information when the current tracking depth is not greater than the tracking depth threshold and the energy value is greater than or equal to the energy threshold.
[0118] A path tracking unit is configured to track the path of the refracted ray or the reflected ray based on the reflection direction or the refraction direction, and update the current tracking depth and the energy value and record the ray color of each intersection point when the refracted ray or the reflected ray intersects with the object surface.
[0119] Further, the ray initial value includes a ray initial direction and a ray initial color, and the ray color record obtaining module includes:
[0120] A ray starting point obtaining unit is configured to obtain a ray starting point.
[0121] A target photon determining unit is configured to calculate the distance between each photon in the photon map and the ray starting point and determine the photon with the smallest distance as the target photon.
[0122] A ray initial color information determining unit is configured to obtain the incident direction and the color information of the target photon, determine the incident direction as the ray initial direction, and determine the color information as the ray initial color.
[0123] It should be noted that, for the convenience and brevity of description, the specific working processes of the above-described device and modules can refer to the corresponding processes in the foregoing method embodiments, which will not be described herein.
[0124] The apparatus described above can be implemented in the form of a computer program which can run on the computer device as shown in Figure 5 .
[0125] Please refer to Figure 5 , Figure 5 is a structural schematic block diagram of a computer device provided by an embodiment of the present application. The computer device can be a server.
[0126] Please refer to Figure 5 , the computer device comprises a processor, a memory and a network interface connected through a system bus, wherein the memory can comprise a non-volatile storage medium and an internal memory.
[0127] The non-volatile storage medium can store an operating system and a computer program. The computer program comprises program instructions which, when executed, can cause the processor to perform any one of the rendering methods based on photon mapping and path tracing.
[0128] The processor is used to provide computing and control capabilities to support the operation of the entire computer device.
[0129] The internal memory provides an environment for the execution of the computer program in the non-volatile storage medium, which, when executed by the processor, can cause the processor to perform any one of the rendering methods based on photon mapping and path tracing.
[0130] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art can understand that Figure 5 the structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can comprise more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0131] It should be understood that the processor can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
[0132] In one embodiment, the processor is configured to run a computer program stored in the memory to implement the following steps:
[0133] obtain light source information and object information in a scene file, and analyze the light source information and the object information based on a preset photon distribution algorithm to determine photon distribution information;
[0134] based on the photon distribution information, control photon propagation, record photon path information, and generate a photon map based on the photon path information;
[0135] based on the photon map, determine an initial value of a light ray, emit a light ray based on the initial value of the light ray for path tracing, and obtain a light ray color record;
[0136] based on the light ray color record, accumulate pixels to obtain a target rendering image.
[0137] In one embodiment, when the processor implements obtaining light source information and object information in a scene file, and analyzing the light source information and the object information based on a preset photon distribution algorithm to determine photon distribution information, the processor is configured to implement:
[0138] perform scene lighting analysis on the scene file to obtain the light source information;
[0139] perform object geometry analysis and object material property analysis on the scene file to obtain the object information;
[0140] based on the photon distribution algorithm, analyze the light source information and the object information to determine at least one scene region and the photon density of each scene region, and obtain the photon distribution information.
[0141] In one embodiment, when the processor implements obtaining a target rendering image based on the light ray color record, the processor is configured to implement:
[0142] obtain position information of each pixel of a to-be-rendered image in the scene file;
[0143] based on the position information and the light ray color record, obtain the light ray color and energy value of at least one light ray corresponding to each pixel;
[0144] based on the energy value, weight and accumulate at least one light ray color of each pixel to obtain the target rendering image.
[0145] In one embodiment, when the processor implements controlling photon propagation based on the photon distribution information, recording photon path information, and generating a photon map based on the photon path information, the processor is configured to implement:
[0146] based on the photon distribution information, control photon propagation, and based on a preset photon mapping algorithm, the object information, and the light source information, perform photon mapping to obtain the photon path information;
[0147] based on the photon path information, perform pre-computation to obtain pre-computation data of photon hit positions;
[0148] based on the photon path information and the pre-computation data, generate the photon mapping graph.
[0149] In one embodiment, when the processor implements path tracing based on the initial value of the light ray to emit a light ray to obtain a light ray color record, it is used to implement:
[0150] emit a light ray based on the initial value of the light ray, and perform path tracing on the light ray;
[0151] when the intersection of the light ray and the object in the scene is tracked, based on the photon mapping graph, obtain the pre-computation data of the intersection point;
[0152] based on the pre-computation data, the object information, and the light source information, determine the light ray color of the light ray at the intersection point and the interaction relationship of the light ray and the object surface;
[0153] when the interaction relationship is reflection or refraction, update the current tracking depth, and based on the pre-computation data, the object information, calculate the energy value of the refracted light ray or the reflected light ray;
[0154] when the current tracking depth is greater than a preset tracking depth threshold and / or the energy value is less than a preset energy threshold, stop tracking, and obtain the light ray color of each intersection point to generate the light ray color record.
[0155] In one embodiment, after the processor implements updating the current tracking depth when the interaction relationship is reflection or refraction, and calculating the energy value of the refracted light ray or the reflected light ray based on the pre-computation data and the object information, it is also used to implement:
[0156] when the current tracking depth is not greater than the tracking depth threshold and the energy value is greater than or equal to the energy threshold, calculate the refraction direction and light ray color of the refracted light ray or the reflection direction and light ray color of the reflected light ray based on the pre-computation data, the object information, and the light source information;
[0157] Based on the reflection direction or the refraction direction, path tracking is performed on the refracted light ray or the reflected light ray, and when the refracted light ray or the reflected light ray intersects with an object surface, the current tracking depth and the energy value are updated, and the light ray color of each intersection point is recorded.
[0158] In one embodiment, the light ray initial value includes a light ray initial direction and a light ray initial color, and the processor, when determining the light ray initial value based on the photon map, is configured to:
[0159] Obtaining a light ray starting point;
[0160] Calculating distances between each photon in the photon map and the light ray starting point, and taking a photon with a minimum distance as a target photon;
[0161] Obtaining an incident direction and color information of the target photon, and taking the incident direction as the light ray initial direction and the color information as the light ray initial color.
[0162] Embodiments of the present application also provide a computer readable storage medium, which stores a computer program, and the computer program includes program instructions. The processor executes the program instructions to implement any one of the rendering methods based on photon mapping and path tracking provided by the embodiments of the present application.
[0163] The computer readable storage medium can be an internal storage unit of the computer device, for example, a hard disk or a memory of the computer device. The computer readable storage medium can also be an external storage device of the computer device, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc.
[0164] The above merely illustrates the specific implementation of the present application, but the protection scope of the present application is not limited to this. Any person skilled in the art can easily think of various equivalent modifications or replacements within the technical range disclosed by the present application, and these modifications or replacements should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A rendering method based on photon mapping and path tracing, characterized in that, The method comprises the following steps: acquiring light source information and object information in a scene file, and analyzing the light source information and the object information based on a preset photon distribution algorithm to determine photon distribution information; based on the photon distribution information, controlling photon propagation, recording photon path information, and generating a photon map based on the photon path information; based on the photon map, determining an initial value of a light ray, and emitting a light ray based on the initial value of the light ray to perform path tracking to obtain a light ray color record; based on the light ray color record, performing pixel accumulation to obtain a target rendering image; wherein, based on the initial value of the light ray, a light ray is emitted to perform path tracking to obtain a light ray color record, which comprises: based on the initial value of the light ray, a light ray is emitted, and the light ray is tracked; when the light ray intersects with an object in the scene is tracked, based on the photon map, precomputed data of the intersection point is acquired; based on the precomputed data, the object information and the light source information, the light ray color of the light ray at the intersection point and the interaction relationship between the light ray and the object surface are determined; when the interaction relationship is reflection or refraction, the current tracking depth is updated, and the energy value of the refracted light ray or the reflected light ray is calculated based on the precomputed data and the object information; when the current tracking depth is greater than a preset tracking depth threshold and / or the energy value is less than a preset energy threshold, the tracking is stopped, and the light ray color of each intersection point is acquired to generate the light ray color record.
2. The rendering method based on photon mapping and path tracing according to claim 1, wherein, The method comprises the following steps: performing scene lighting analysis on the scene file to obtain the light source information; performing object geometric structure analysis and object material property analysis on the scene file to obtain the object information; based on the photon distribution algorithm, the light source information and the object information are analyzed to determine at least one scene region and the photon density of each scene region to obtain the photon distribution information.
3. The rendering method based on photon mapping and path tracing according to claim 1, wherein, The method comprises the following steps: acquiring the position information of each pixel of the image to be rendered in the scene file; based on the position information and the light ray color record, the light ray color and the energy value of at least one light ray corresponding to each pixel are acquired; based on the energy value, at least one light ray color of each pixel is weighted and accumulated to obtain the target rendering image.
4. The rendering method based on photon mapping and path tracing according to claim 1, wherein, The method comprises the following steps: based on the photon distribution information, controlling photon propagation, and based on a preset photon mapping algorithm, the object information and the light source information, performing photon mapping to obtain the photon path information; based on the photon path information, precomputing is performed to obtain precomputed data of photon hit positions; based on the photon path information and the precomputed data, the photon map is generated.
5. The rendering method based on photon mapping and path tracing according to claim 1, wherein, The method further comprises the following steps of: updating the current tracking depth when the action relationship is reflection or refraction, and calculating an energy value of the refracted light or the reflected light based on the pre-computed data and the object information; calculating a refraction direction and a light color of the refracted light or a reflection direction and a light color of the reflected light based on the pre-computed data, the object information and the light source information when the current tracking depth is not greater than the tracking depth threshold and the energy value is greater than or equal to the energy threshold; 6. The photon mapping and path tracing based rendering method of any one of claims 1 to 5, wherein, tracking the path of the refracted light or the reflected light based on the refraction direction or the reflection direction, and updating the current tracking depth and the energy value when the refracted light or the reflected light intersects with an object surface, and recording the light color of each intersection point. The light initial value comprises a light initial direction and a light initial color, and the method of determining the light initial value based on the photon mapping map comprises the following steps of: obtaining a light departure point; calculating the distance between each photon in the photon mapping map and the light departure point, and taking the photon with the minimum distance as a target photon; 7. A rendering apparatus based on photon mapping and path tracing, characterized by obtaining the incident direction and color information of the target photon, and taking the incident direction as the light initial direction and the color information as the light initial color. The method comprises the following steps of: a photon distribution information determination module is configured to obtain light source information and object information in a scene file, analyze the light source information and the object information based on a preset photon distribution algorithm, and determine photon distribution information; a photon mapping map generation module is configured to control photon propagation based on the photon distribution information, record photon path information, and generate a photon mapping map based on the photon path information; a light color record obtaining module is configured to determine a light initial value based on the photon mapping map, emit a light based on the light initial value, track the path of the light, and obtain a light color record; a target rendering image obtaining module is configured to perform pixel accumulation based on the light color record, and obtain a target rendering image; The light color record obtaining module comprises: a path tracking unit is configured to emit a light based on the light initial value, and track the path of the light; a pre-computed data obtaining unit is configured to obtain pre-computed data of an intersection point based on the photon mapping map when the light intersects with an object in a scene; an action relationship determination unit is configured to determine the light color of the light at the intersection point and the action relationship between the light and an object surface based on the pre-computed data, the object information and the light source information; an energy value calculation unit is configured to update the current tracking depth when the action relationship is reflection or refraction, and calculate an energy value of the refracted light or the reflected light based on the pre-computed data and the object information; 8. A computer device, comprising: a light color record generation unit is configured to stop tracking when the current tracking depth is greater than a preset tracking depth threshold and / or the energy value is less than a preset energy threshold, obtain the light color of each intersection point, and generate the light color record. The computer device comprises a memory and a processor; the memory is configured to store a computer program; The processor is configured to execute the computer program and implement the rendering method based on photon mapping and path tracing according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to implement the rendering method based on photon mapping and path tracing according to any one of claims 1 to 6.
Citation Information
Patent Citations
Image rendering method and device, equipment and storage medium
CN114782613A
Image rendering method and related equipment thereof
CN117351134A