Rendering method, device, electronic device and storage medium of three-dimensional virtual scene
By optimizing ray tracing in the UE4 game engine, including continuing to track the refractive direction at the translucent material virtual object, the problem of the translucent material object in the virtual mirror is black, and a more realistic rendering effect is achieved.
Patent Information
- Application Number
- CN202111558149.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-12-17
AI Technical Summary
In the scene where the UE4 game engine performs real-time ray tracing rendering, the virtual object made of translucent material in the virtual mirror appears black, which violates the real physical imaging rules, resulting in poor user visual experience.
Starting from the preset virtual viewpoint, a line of sight is projected at the target position on the surface of the target virtual object to be colored in the three-dimensional virtual scene, and the above line of sight is ray-tracked. Whenever a virtual object with a translucent material is tracked, the line of sight is projected in the reflection and refractive directions each time a virtual object is tracked, and ray tracing continues until the virtual light source is tracked. The coloring result at the target position is determined based on the surface information at each collision position generated during ray tracing.
By completing the tracking of the refractive direction in the game engine, the display of translucent material virtual objects can be brought close to the real effect in the scene rendered by real-time ray tracing, and the user's visual experience can be improved.
Smart Images

Figure CN114241112B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computers, and in particular to a rendering method, device, electronic device and storage medium for a three-dimensional virtual scene. Background Art
[0002] In the computer field, ray tracing is widely used in computer games and animation, television and DVD production, and film products. At present, with the improvement of graphics card hardware performance and the industry's proposal of the ray tracing DXR API application programming interface specification, real-time ray tracing rendering processes have been implemented in some game engines, such as the Unreal engine.
[0003] However, in the scene of real-time ray tracing rendering by the UE4 (Unreal Engine 4) game engine, virtual objects with semi-transparent materials in the virtual mirror (such as glass cups, glass balls, etc.) will appear black (see the effect). Figure 1 ), which obviously does not conform to the real physical imaging law, resulting in poor user experience of the rendering results of virtual objects with translucent materials in virtual scenes. Summary of the invention
[0004] In view of this, in order to solve the above-mentioned technical problems, the embodiments of the present invention provide a method, device, electronic device and storage medium for rendering a three-dimensional virtual scene.
[0005] In a first aspect, an embodiment of the present invention provides a method for rendering a three-dimensional virtual scene, comprising:
[0006] Starting from a preset virtual viewpoint, a line of sight is projected to a target position, wherein the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, and the material attribute of the target virtual object is a semi-transparent material;
[0007] Performing ray tracing on the sight line, and each time tracing a virtual object of a semi-transparent material in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing stops when tracing a virtual light source;
[0008] The shading result at the target position is determined according to the surface information at each collision position generated during the ray tracing process.
[0009] In a possible implementation, the method further includes:
[0010] After a reflected line of sight is projected along the corresponding reflection direction, the current reflected line of sight is used as a tracking line of sight to continue ray tracing until the virtual light source is tracked and the ray tracing is stopped.
[0011] In a possible implementation, the performing ray tracing on the line of sight includes:
[0012] Starting from the target position, projecting a reflected line of sight along the reflection direction of the line of sight at the target position, and projecting a refracted line of sight along the refraction direction of the line of sight at the target position;
[0013] The current reflected line of sight and the refracted line of sight are respectively used as tracking lines for ray tracing.
[0014] In a possible implementation, determining the shading result at the target position according to the surface information at each collision position generated during the ray tracing process includes:
[0015] For each collision position generated during the ray tracing process, determining a refraction component and a reflection component according to surface information at the collision position;
[0016] Performing weighted summation of the refraction component and the reflection component at each collision position generated during the ray tracing process according to their corresponding weighting coefficients;
[0017] The coloring result at the target position is determined according to the weighted summation result.
[0018] In a possible implementation, according to the order of tracing, the weighted coefficients corresponding to the collision positions generated during the ray tracing process tend to decrease.
[0019] In a second aspect, an embodiment of the present invention provides another method for rendering a three-dimensional virtual scene, comprising:
[0020] Starting from a preset virtual viewpoint, a line of sight is projected to a target position, where the target position is any position on a virtual mirror surface in a three-dimensional virtual scene;
[0021] Performing ray tracing on the sight line, each time when tracing a virtual glass object in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual glass object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing stops when tracing a virtual light source;
[0022] The shading result at the target position is determined according to the surface information at each collision position generated during the ray tracing process.
[0023] In a possible implementation, the method further includes:
[0024] After a reflected line of sight is projected along the corresponding reflection direction, the current reflected line of sight is used as a tracking line of sight to continue ray tracing until the virtual light source is tracked and the tracing is stopped.
[0025] In a possible implementation, the performing ray tracing on the line of sight includes:
[0026] Starting from the target position, projecting a reflection line of sight along a corresponding reflection direction, and projecting a refraction line of sight along a corresponding refraction direction;
[0027] The current reflected line of sight and the refracted line of sight are respectively used as tracking lines for ray tracing.
[0028] In a third aspect, an embodiment of the present invention provides a rendering device for a three-dimensional virtual scene, comprising:
[0029] A projection module, used to project a line of sight from a preset virtual viewpoint to a target position, wherein the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene;
[0030] A tracking module, configured to perform ray tracing on the sight line, and each time a virtual object of a semi-transparent material in the three-dimensional virtual scene is tracked, a reflection sight line is projected along a corresponding reflection direction and a refraction sight line is projected along a corresponding refraction direction from a collision position of the current tracking sight line on the virtual object, and the current refraction sight line is used as the tracking sight line to continue ray tracing until the tracking is stopped when a virtual light source is tracked;
[0031] The shading module is used to determine the shading result at the target position according to the surface information at each collision position generated during the ray tracing process.
[0032] In a fourth aspect, an embodiment of the present invention provides another three-dimensional virtual scene rendering device, comprising:
[0033] A projection module, used to project a line of sight from a preset virtual viewpoint to a target position, wherein the target position is any position on a virtual mirror surface in a three-dimensional virtual scene;
[0034] A tracking module, configured to perform ray tracing on the sight line, and each time a virtual glass object in the three-dimensional virtual scene is tracked, a reflection sight line is projected along a corresponding reflection direction and a refraction sight line is projected along a corresponding refraction direction from a collision position of the current tracking sight line on the virtual glass object, and the current refraction sight line is used as the tracking sight line to continue ray tracing until the tracking is stopped when a virtual light source is tracked;
[0035] The shading module is used to determine the shading result at the target position according to the surface information at each collision position generated during the ray tracing process.
[0036] In a fifth aspect, an embodiment of the present invention provides an electronic device, comprising: a processor and a memory, wherein the processor is used to execute a rendering program of a three-dimensional virtual scene stored in the memory to implement the rendering method of a three-dimensional virtual scene described in any one of the first aspect or the second aspect.
[0037] In a sixth aspect, an embodiment of the present invention provides a storage medium, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the rendering method of a three-dimensional virtual scene described in any one of the first aspect or the second aspect.
[0038] The technical solution provided by the embodiment of the present invention projects a line of sight from a preset virtual viewpoint to a target position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, performs ray tracing on the line of sight, and each time a virtual object of a semi-transparent material in the three-dimensional virtual scene is traced, a reflection line of sight is projected along a corresponding reflection direction from a collision position of the current tracking line of sight on the virtual object, and a refraction line of sight is projected along a corresponding refraction direction, and ray tracing is continued using the current refraction line of sight as the tracking line of sight until the tracking is stopped when the virtual light source is tracked, and the coloring result at the target position is determined based on the surface information at each collision position generated during the ray tracing process, and because the tracing of the refraction direction is not stopped after the first reflection and the second virtual object of the semi-transparent material is tracked, it can be achieved that in a scene where a game engine performs real-time ray tracing rendering, the display of the semi-transparent material virtual object in the target virtual object of the semi-transparent material can be close to the real effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A schematic diagram of ray tracing rendering effect in the prior art;
[0040] Figure 2 is a ray tracing path graph in the prior art;
[0041] Figure 3A schematic diagram of a ray tracing rendering effect achieved by applying an embodiment of the present invention;
[0042] Figure 4 A flowchart of an embodiment of a method for rendering a three-dimensional virtual scene provided by an embodiment of the present invention;
[0043] Figure 5 A schematic diagram of a ray tracing scene provided by an embodiment of the present invention;
[0044] Figure 6 A flowchart of another method for rendering a three-dimensional virtual scene provided by an embodiment of the present invention;
[0045] Figure 7 A block diagram of an embodiment of a three-dimensional virtual scene rendering device provided by an embodiment of the present invention;
[0046] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] As can be seen from the above description, in the prior art, in a scene where a game engine performs real-time ray tracing rendering, a virtual object made of semi-transparent material (such as a glass cup, a glass ball, etc.) in a virtual mirror will appear black. The reason for this is that in a scene where a game engine performs real-time ray tracing, after tracing the second virtual object made of semi-transparent material after the first reflection, the refraction direction is lost. For ease of understanding, the following figure is shown: Figure 2 Graph of example ray tracing paths. Figure 2 In the figure, the right side indicates the direction of refraction, and the left side indicates the direction of reflection.
[0049] In this regard, the present invention provides a rendering method for a three-dimensional virtual scene, in which the tracking of the refraction direction after tracking the virtual object of the second translucent material after the first reflection is completed.
[0050] The rendering method of the three-dimensional virtual scene provided by the embodiment of the present invention can realize that in the scene where the game engine performs real-time ray tracing rendering, the display of the virtual object of the semi-transparent material in the virtual mirror can be close to the real effect. The specific effect is as follows: Figure 3 shown.
[0051] The rendering method of the three-dimensional virtual scene provided by the present invention is further explained below with reference to specific embodiments in conjunction with the accompanying drawings, and the embodiments do not constitute a limitation on the embodiments of the present invention.
[0052] See also Figure 4 , is a flow chart of an embodiment of a method for rendering a three-dimensional virtual scene provided by an embodiment of the present invention. Figure 4 As shown, the process may include the following steps:
[0053] Step 401: Starting from a preset virtual viewpoint, a line of sight is projected to a target position, where the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, and the material attribute of the target virtual object is a semi-transparent material.
[0054] Step 402, ray tracing is performed on the above-mentioned line of sight. Each time a virtual object of a semi-transparent material in a three-dimensional virtual scene is traced, a reflection line of sight is projected along the corresponding reflection direction from the collision position of the current tracking line of sight on the virtual object, and a refraction line of sight is projected along the corresponding refraction direction. The current refraction line of sight is used as the tracking line of sight to continue ray tracing until the virtual light source is tracked and the tracing is stopped.
[0055] The following is a unified description of step 401 and step 402:
[0056] In the field of computer graphics rendering, the above-mentioned preset virtual viewpoint usually refers to a camera lens.
[0057] In an exemplary application scenario, the target virtual object to be colored may include a virtual mirror, and the virtual object of the translucent material may include a virtual glass object, for example Figure 1 or Figure 2 The virtual glass shown in .
[0058] According to the law of conservation of energy, energy conservation must be ensured when emitting branch rays, such as reflected rays and refracted rays. At present, game engines mainly control energy conservation in the ray tracing process by calculating the Fresnel coefficient and surface opacity in the Fresnel phenomenon. At this time, it is necessary to pay attention to the variable of path throughput. It has been found through research that the change of the variable of path throughput is mainly concentrated on the refraction branch. Therefore, the embodiment of the present invention proposes that when tracing the virtual object of the second translucent material after the first reflection, continue to recursively trace the refracted direction.
[0059] The following takes this exemplary application scenario as an example, and combines Figure 5 The schematic diagram of the ray tracing scene used as an example explains the specific implementation of step 401 and step 402:
[0060] Combination Figure 5 First, from the preset virtual viewpoint ( Figure 5 Starting from the camera lens shown in the example in ), a line of sight is projected to position a on the virtual mirror (that is, position a is taken as the above-mentioned target position) (for the convenience of description, Figure 5 The example is line of sight 1), and ray tracing is performed on line of sight 1.
[0061] Specifically, ray tracing of sight line 1 includes: when tracing to position a, starting from position a, projecting a reflected sight line along the reflection direction of sight line 1 at position a (for convenience of description, Figure 5 The example is a reflected line of sight 2), and a refracted line of sight is projected along the refraction direction of line of sight 1 at position a (for ease of description, Figure 5 In the example, the refracted line of sight 2 is used. Further, the current reflected line of sight (i.e., reflected line of sight 2) and the refracted line of sight (i.e., refracted line of sight 2) are respectively used as the tracing lines to continue ray tracing.
[0062] Afterwards, according to the description in the above step 402, in the process of performing ray tracing on the reflected line of sight 2 and the refracted line of sight 2 respectively, if a virtual object of a translucent material (hereinafter referred to as the material attributes of the virtual object are all translucent materials) is traced, starting from the collision position of the tracing line of sight (reflected line of sight 2 and / or refracted line of sight 2) on the virtual object, a reflected line of sight is projected along the corresponding reflection direction, and a refracted line of sight is projected along the corresponding refraction direction, and the current refracted line of sight is used as the tracing line of sight to continue ray tracing until the tracing stops when the virtual light source is traced.
[0063] For example, if Figure 5 As shown, it is assumed that ray tracing is performed on the reflected sight line 2 and the refracted sight line 2, and they are traced to the virtual objects 1 and 2 of the semi-transparent material respectively. Then for the reflected sight line 2, starting from the collision position b of the reflected sight line 2 on the virtual object 1, a reflected ray is projected along the corresponding reflection direction (for the convenience of description, Figure 5 The example is a reflected line of sight 3), and a refracted line of sight is projected along the corresponding refraction direction (for ease of description, Figure 5 Similarly, for refracted sight line 2, starting from the collision position c of refracted sight line 2 on virtual object 2, a reflected ray is projected along the corresponding reflection direction (for convenience of description, Figure 5 The example is a reflected line of sight 4), and a refracted line of sight is projected along the corresponding refraction direction (for ease of description, Figure 5 The example in FIG. 3 is a refracted line of sight 32).
[0064] After that, the refracted sight line 31 and the refracted sight line 32 are used as the tracking sight lines to continue ray tracing. Assume that the refracted sight line 31 and the refracted sight line 32 are traced to the virtual light source and the virtual object 3 respectively. Then for the refracted sight line 31, the tracing is stopped; and for the refracted sight line 32, a reflected ray is projected along the corresponding reflection direction from the collision position d of the refracted sight line 32 on the virtual object 3 (for the convenience of description, Figure 5 The example is a reflected line of sight 5), and a refracted line of sight is projected along the corresponding refraction direction (for ease of description, Figure 5 The example in FIG. 4 is a refracted line of sight 41).
[0065] After that, the refracted sight line 41 is used as the tracking sight line to continue ray tracing. Assuming that the refracted sight line 41 is ray traced and the virtual light source is traced, the ray tracing will be stopped at this time. At this point, the ray tracing process ends.
[0066] Assume that the refracted sight line 41 is traced to the virtual object ( Figure 5 (not shown), then continue to start from the collision position of the refracted sight line 41 on the virtual object, and project a reflected light ray ( Figure 5 ), and project a refracted line of sight along the corresponding refraction direction ( Figure 5 The refracted sight line is used as the tracking sight line to continue ray tracing until the virtual light source is tracked.
[0067] It can be seen that each time a surface of a virtual object is tracked, it is tracked once in the corresponding reflection direction, and recursively tracked in the corresponding refraction direction until the virtual light source is tracked.
[0068] Step 403: Determine the shading result at the target position according to the surface information at each collision position generated during the ray tracing process.
[0069] Optionally, the above surface information includes but is not limited to: material and texture.
[0070] In one embodiment, the specific implementation of step 403 may include: for each collision position generated during the ray tracing process, determining the refraction component and the reflection component according to the surface information at the collision position, weightedly summing the refraction component and the reflection component at each collision position generated during the ray tracing process according to their respective corresponding weighting coefficients, and determining the shading result at the target position according to the weighted summation result.
[0071] Among them, optionally, according to the order of tracing, the weighting coefficients corresponding to the collision positions generated in the ray tracing process tend to decrease.
[0072] Optionally, the weighted coefficient corresponding to the collision position depends on the opacity coefficient of the material at the collision position.
[0073] Combination Figure 5 For example, the shading result C at the target position a can be calculated by the following formula:
[0074] C=k1E a_reflection +k2E b_refraction +k3E a_refraction +k4E c_refraction +k5E d_refraction +k6E b_reflection +k7E c_reflection +k8E d_reflection +...
[0075] In the above formula, E a_reflection represents the reflection component of line of sight 1 at collision position a, E b_refraction represents the refraction component of the reflected line 2 at the collision position b, E a_refraction represents the refraction component of line of sight 1 at collision position a, E c_refraction represents the refraction component of the refracted line 2 at the collision position c, E d_refraction represents the refraction component of the refracted line of sight 32 at the collision position d, E b_reflection represents the reflected component of the reflected line 2 at the collision position b, E c_refrection represents the reflected component of the refracted line 2 at the collision position c, E d_reflection represents the reflection component of the refracted line of sight 32 at the collision position d.
[0076] k i Represents the weighting coefficient.
[0077] It should be noted that in the above formula, except for E b_refraction In addition, the weighting coefficients corresponding to each other refraction component (such as k3, k4, k5) are negative numbers. That is, starting from the first surface traced, tracing the refraction direction has the effect of reducing the light intensity of the shading result at the position to be shaded on the first surface.
[0078] The technical solution provided by the embodiment of the present invention projects a line of sight from a preset virtual viewpoint to a target position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, performs ray tracing on the line of sight, and each time a virtual object of a semi-transparent material in the three-dimensional virtual scene is traced, a reflection line of sight is projected along a corresponding reflection direction from a collision position of the current tracking line of sight on the virtual object, and a refraction line of sight is projected along a corresponding refraction direction, and ray tracing is continued using the current refraction line of sight as the tracking line of sight until the tracking is stopped when the virtual light source is tracked, and the coloring result at the target position is determined based on the surface information at each collision position generated during the ray tracing process, and since the tracing of the refraction direction is not stopped after the first reflection and the second virtual object of the semi-transparent material is tracked, it can be achieved that in a scene where a game engine performs real-time ray tracing rendering, the display of the semi-transparent material virtual object in the target virtual object can be close to the real effect.
[0079] In addition, it can be seen from the above description that the change of the variable of path throughput is mainly concentrated on the refraction branch, not all concentrated on the refraction branch. Therefore, as an optional implementation method, in the above Figure 4 In the described ray tracing process, after tracing to the virtual object of the second translucent material after the first reflection, the reflection direction can also be recursively traced.
[0080] Specifically, each time a virtual object of a translucent material in a three-dimensional virtual scene is tracked, a reflected line of sight is projected along the corresponding reflection direction starting from the collision position of the current tracking line of sight on the virtual object, and the current reflected line of sight is used as the tracking line of sight to continue ray tracing until the virtual light source is tracked and the tracking is stopped.
[0081] In this optional implementation, the specific implementation of the above step 403 also includes: for each collision position generated during the ray tracing process, determining the reflection component according to the surface information at the collision position, weighted summing the reflection components at each of the collision positions generated during the ray tracing process according to their respective corresponding weighting coefficients, and jointly determining the shading result at the target position based on the weighted sum results of the refraction component and the reflection component.
[0082] Through this processing, the character result at the target position can be made more accurate.
[0083] It should be noted that since the change of the variable path throughput is mainly concentrated on the refraction branch, the reflection branch has a smaller impact on the path throughput, but recursively tracing the reflection branch will take up a lot of computing resources. Therefore, in the embodiment of the present invention, after the first reflection, after tracing the second virtual object of the semi-transparent material, retaining the tracing of the refraction direction and stopping the tracing of the reflection direction is a preferred implementation method, which is also a comprehensive consideration of the final rendering effect and rendering performance. It can be seen that the application Figure 4 The process shown can take into account both rendering performance and rendering effect.
[0084] See also Figure 6 , is a flow chart of another embodiment of a method for rendering a three-dimensional virtual scene provided by an embodiment of the present invention. Figure 6 As shown, the process may include the following steps:
[0085] Step 601: Starting from a preset virtual viewpoint, a line of sight is projected to a target position, where the target position is any position on a virtual mirror surface in a three-dimensional virtual scene.
[0086] Step 602: perform ray tracing on the line of sight. Each time a virtual glass object in the three-dimensional virtual scene is traced, a reflection line of sight is projected along a corresponding reflection direction from the collision position of the current tracking line of sight on the virtual glass object, and a refraction line of sight is projected along a corresponding refraction direction. The current refraction line of sight is used as the tracking line of sight to continue ray tracing until the virtual light source is tracked and the tracing is stopped.
[0087] Step 603: Determine the shading result at the target position according to the surface information at each collision position generated during the ray tracing process.
[0088] Figure 6 The process shown is Figure 4 The process shown corresponds to a rendering process of a three-dimensional virtual scene implemented in a specific application scenario. In the specific application scenario, the target virtual object is a virtual mirror, and the virtual object of the translucent material is a virtual glass object.
[0089] In this application scenario, by applying the technical solution provided by the embodiment of the present invention, it is possible to achieve a scene in which the game engine performs real-time ray tracing rendering, in which the display of the virtual glass object in the virtual mirror can be close to the real effect, so that the game engine can have a more realistic game screen performance for game players; at the same time, game artists can also arbitrarily add virtual glass objects (including dynamic virtual glass objects) in front of the virtual mirror of the three-dimensional virtual scene.
[0090] As for Figure 6 For the specific implementation of the process shown, please refer to the above Figure 4 The description in the process shown will not be repeated here.
[0091] See also Figure 7 , is a block diagram of an embodiment of a rendering device for a three-dimensional virtual scene provided by an embodiment of the present invention. Figure 7 As shown, the device may include: a projection module 71, a tracking module 72 and a coloring module 73.
[0092] The projection module 71 is used to project a line of sight from a preset virtual viewpoint to a target position, where the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene; or to project a line of sight from a preset virtual viewpoint to a target position, where the target position is any position on a virtual mirror surface in a three-dimensional virtual scene;
[0093] A tracking module 72 is used to perform ray tracing on the sight line, and each time a virtual object of a semi-transparent material in the three-dimensional virtual scene is tracked, a reflection sight line is projected along a corresponding reflection direction from a collision position of the current tracking sight line on the virtual object, and a refraction sight line is projected along a corresponding refraction direction, and the current refraction sight line is used as the tracking sight line to continue ray tracing until the virtual light source is tracked; or a tracking module is used to perform ray tracing on the sight line, and each time a virtual glass object in the three-dimensional virtual scene is tracked, a reflection sight line is projected along a corresponding reflection direction from a collision position of the current tracking sight line on the virtual glass object, and a refraction sight line is projected along a corresponding refraction direction, and the current refraction sight line is used as the tracking sight line to continue ray tracing until the virtual light source is tracked and the tracking is stopped;
[0094] The shading module 73 is used to determine the shading result at the target position according to the surface information at each collision position generated during the ray tracing process.
[0095] In a possible implementation, the tracking module 72 is further configured to:
[0096] After a reflected line of sight is projected along the corresponding reflection direction, the current reflected line of sight is used as a tracking line of sight to continue ray tracing until the virtual light source is tracked and the tracing is stopped.
[0097] In a possible implementation, the tracking module 72 is further configured to:
[0098] Starting from the target position, a reflected line of sight is projected along the reflection direction of the line of sight at the target position, and a refracted line of sight is projected along the refraction direction of the line of sight at the target position; the current reflected line of sight and the refracted line of sight are respectively used as tracking lines for ray tracing.
[0099] In a possible implementation, the coloring module 73 includes (not shown in the figure):
[0100] A first determination submodule, configured to determine, for each collision position generated during the ray tracing process, a refraction component and a reflection component according to surface information at the collision position;
[0101] A summing submodule, used for weighted summing the refraction component and the reflection component at each collision position generated in the ray tracing process according to their corresponding weighting coefficients;
[0102] The second determination submodule is used to determine the coloring result at the target position according to the weighted summation result.
[0103] In a possible implementation, according to the order of tracing, the weighted coefficients corresponding to the collision positions generated during the ray tracing process tend to decrease.
[0104] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, Figure 8 The electronic device 800 shown includes: at least one processor 801, a memory 802, at least one network interface 804 and other user interfaces 803. The various components in the electronic device 800 are coupled together via a bus system 805. It is understood that the bus system 805 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 805 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 805 is not described in detail. Figure 8 Various buses are labeled as bus system 805 .
[0105] The user interface 803 may include a display, a keyboard or a pointing device (eg, a mouse, a trackball), a touch pad or a touch screen.
[0106] It can be understood that the memory 802 in the embodiment of the present invention can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DRRAM). The memory 802 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0107] In some implementations, the memory 802 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 8021 and an application program 8022 .
[0108] The operating system 8021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application program 8022 includes various application programs, such as a media player (MediaPlayer), a browser (Browser), etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present invention can be included in the application program 8022.
[0109] In the embodiment of the present invention, by calling the program or instruction stored in the memory 802, specifically, the program or instruction stored in the application 8022, the processor 801 is used to execute the method steps provided by each method embodiment, for example, including:
[0110] Starting from a preset virtual viewpoint, a line of sight is projected to a target position, wherein the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, and the material attribute of the target virtual object is a semi-transparent material;
[0111] Performing ray tracing on the sight line, and each time tracing a virtual object of a semi-transparent material in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing stops when tracing a virtual light source;
[0112] The shading result at the target position is determined according to the surface information at each collision position generated during the ray tracing process.
[0113] or,
[0114] Starting from a preset virtual viewpoint, a line of sight is projected to a target position, where the target position is any position on a virtual mirror surface in a three-dimensional virtual scene;
[0115] Performing ray tracing on the sight line, each time when tracing a virtual glass object in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual glass object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing stops when tracing a virtual light source;
[0116] The shading result at the target position is determined according to the surface information at each collision position generated during the ray tracing process.
[0117] The method disclosed in the above embodiment of the present invention can be applied to the processor 801, or implemented by the processor 801. The processor 801 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 801 or the instruction in the form of software. The above processor 801 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 802, and the processor 801 reads the information in the memory 802 and completes the steps of the above method in combination with its hardware.
[0118] It is understood that the embodiments described herein can be implemented by hardware, software, firmware, middleware, microcode or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application or a combination thereof.
[0119] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0120] The electronic device provided in this embodiment may be Figure 8The electronic device shown in FIG. 1 may perform the following steps: Figure 4 and Figure 6 All steps of the rendering method of the three-dimensional virtual scene in Figure 4 and Figure 6 For details, please refer to the technical effects of the rendering method of the three-dimensional virtual scene in Figure 4 and Figure 6 For the sake of brevity, the relevant description is not repeated here.
[0121] The embodiment of the present invention also provides a storage medium (computer-readable storage medium). The storage medium here stores one or more programs. The storage medium may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above-mentioned types of memory.
[0122] When one or more programs in the storage medium can be executed by one or more processors, the above-mentioned three-dimensional virtual scene rendering method executed on the electronic device side is implemented.
[0123] The processor is used to execute a rendering program of a three-dimensional virtual scene stored in the memory to implement the following steps of a rendering method of a three-dimensional virtual scene executed on the electronic device side:
[0124] Starting from a preset virtual viewpoint, a line of sight is projected to a target position, wherein the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, and the material attribute of the target virtual object is a semi-transparent material;
[0125] Performing ray tracing on the sight line, and each time tracing a virtual object of a semi-transparent material in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing stops when tracing a virtual light source;
[0126] The shading result at the target position is determined according to the surface information at each collision position generated during the ray tracing process.
[0127] or,
[0128] Starting from a preset virtual viewpoint, a line of sight is projected to a target position, where the target position is any position on a virtual mirror surface in a three-dimensional virtual scene;
[0129] Performing ray tracing on the sight line, each time when tracing a virtual glass object in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual glass object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing stops when tracing a virtual light source;
[0130] The shading result at the target position is determined according to the surface information at each collision position generated during the ray tracing process.
[0131] The professionals should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0132] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0133] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for rendering a three-dimensional virtual scene, characterized in that: include: Starting from a preset virtual viewpoint, a line of sight is projected to a target position, wherein the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene, and the material attribute of the target virtual object is a semi-transparent material; Performing ray tracing on the sight line, each time tracing a virtual object of a semi-transparent material in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing is stopped when a virtual light source is traced; after the first reflection, after tracing a second virtual object of a semi-transparent material, retaining the tracing of the refraction direction, and stopping the tracing of the reflection direction; Determine a shading result at the target position according to surface information at each collision position generated during ray tracing; Determining the shading result at the target position according to the surface information at each collision position generated during the ray tracing process includes: For each collision position generated during the ray tracing process, determining a refraction component and a reflection component according to surface information at the collision position; Performing weighted summation of the refraction component and the reflection component at each collision position generated during the ray tracing process according to their corresponding weighting coefficients; The coloring result at the target position is determined according to the weighted summation result.
2. The method according to claim 1, characterized in that: The performing ray tracing on the sight line includes: Starting from the target position, projecting a reflected line of sight along the reflection direction of the line of sight at the target position, and projecting a refracted line of sight along the refraction direction of the line of sight at the target position; The current reflected line of sight and the refracted line of sight are respectively used as tracking lines for ray tracing.
3. The method according to claim 1, characterized in that According to the order of tracing, the weighted coefficients corresponding to the collision positions generated during the ray tracing process tend to decrease.
4. A method for rendering a three-dimensional virtual scene, characterized in that: include: Starting from a preset virtual viewpoint, a line of sight is projected to a target position, where the target position is any position on a virtual mirror surface in a three-dimensional virtual scene; Performing ray tracing on the sight line, each time when tracing to a virtual glass object in the three-dimensional virtual scene, starting from the collision position of the current tracing sight line on the virtual glass object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracing sight line, until tracing is stopped when a virtual light source is traced; after the first reflection, after tracing to a second virtual glass object, retaining the tracing of the refraction direction, and stopping the tracing of the reflection direction; Determine a shading result at the target position according to surface information at each collision position generated during ray tracing; Determining the shading result at the target position according to the surface information at each collision position generated during the ray tracing process includes: For each collision position generated during the ray tracing process, determining a refraction component and a reflection component according to surface information at the collision position; Performing weighted summation of the refraction component and the reflection component at each collision position generated during the ray tracing process according to their corresponding weighting coefficients; The coloring result at the target position is determined according to the weighted summation result.
5. The method according to claim 4, characterized in that The performing ray tracing on the sight line includes: Starting from the target position, projecting a reflection line of sight along a corresponding reflection direction, and projecting a refraction line of sight along a corresponding refraction direction; The current reflected line of sight and the refracted line of sight are respectively used as tracking lines for ray tracing.
6. A three-dimensional virtual scene rendering device, characterized in that: include: A projection module, used to project a line of sight from a preset virtual viewpoint to a target position, wherein the target position is any position on the surface of a target virtual object to be colored in a three-dimensional virtual scene; A tracking module, for performing ray tracing on the sight line, and each time a virtual object of a semi-transparent material in the three-dimensional virtual scene is tracked, starting from the collision position of the current tracking sight line on the virtual object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracking sight line, until the tracking is stopped when the virtual light source is tracked; after the first reflection, after tracking the second virtual object of the semi-transparent material, retaining the tracking of the refraction direction, and stopping the tracking of the reflection direction; A shading module, used for determining a shading result at the target position according to the surface information at each collision position generated during the ray tracing process; Determining the shading result at the target position according to the surface information at each collision position generated during the ray tracing process includes: For each collision position generated during the ray tracing process, determining a refraction component and a reflection component according to surface information at the collision position; Performing weighted summation of the refraction component and the reflection component at each collision position generated during the ray tracing process according to their corresponding weighting coefficients; The coloring result at the target position is determined according to the weighted summation result.
7. A rendering device for a three-dimensional virtual scene, characterized in that: include: A projection module, used to project a line of sight from a preset virtual viewpoint to a target position, wherein the target position is any position on a virtual mirror surface in a three-dimensional virtual scene; A tracking module, for performing ray tracing on the sight line, and each time a virtual glass object in the three-dimensional virtual scene is tracked, starting from the collision position of the current tracking sight line on the virtual glass object, projecting a reflection sight line along the corresponding reflection direction, and projecting a refraction sight line along the corresponding refraction direction, and continuing to perform ray tracing using the current refraction sight line as the tracking sight line, until the tracking is stopped when the virtual light source is tracked; after the first reflection, after tracking the second virtual glass object, retaining the tracking of the refraction direction, and stopping the tracking of the reflection direction; A shading module, used for determining a shading result at the target position according to the surface information at each collision position generated during the ray tracing process; Determining the shading result at the target position according to the surface information at each collision position generated during the ray tracing process includes: For each collision position generated during the ray tracing process, determining a refraction component and a reflection component according to surface information at the collision position; Performing weighted summation of the refraction component and the reflection component at each collision position generated during the ray tracing process according to their corresponding weighting coefficients; The coloring result at the target position is determined according to the weighted summation result.
8. An electronic device, characterized in that: include: A processor and a memory, wherein the processor is used to execute a rendering program of a three-dimensional virtual scene stored in the memory to implement the rendering method of a three-dimensional virtual scene according to any one of claims 1 to 3 or 4 to 5.
9. A storage medium, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the rendering method of a three-dimensional virtual scene described in any one of claims 1 to 3 or 4 to 5.
Citation Information
Patent Citations
Dynamic scene rendering acceleration method based on light path multiplexing
CN113298925A