Search

CN-121999189-A - Environment reflection correction method and system based on 3D graphics rendering

CN121999189ACN 121999189 ACN121999189 ACN 121999189ACN-121999189-A

Abstract

The invention belongs to the technical field of 3D rendering, and discloses an environment reflection correction method and system based on 3D graphics rendering, wherein the method comprises the following steps: world coordinates of a target vertex and a camera are obtained through a vertex shader, a sight line direction vector is obtained through normalization processing, then the sight line direction is judged through calculating a dot product of the vector and a vertex normal vector, a reflecting direction is determined in a targeted mode and is transmitted to the pixel shader, and back surface environment sampling errors are avoided from the root. The vertex reflection direction vector is interpolated based on the same primitive, the reflection direction of each pixel point can be accurately obtained, the reflection effect is ensured to be attached to the actual surface characteristic of the model, and correction is completed by sampling the environment reflection value and combining illumination calculation. According to the method, the true reduction degree and immersion sense of the 3D scene are greatly improved, the reliability and stability of the rendering effect are enhanced, and better visual experience is brought to users.

Inventors

  • FANG BO
  • TANG LUYAO
  • DU JING

Assignees

  • 武汉微派网络科技有限公司

Dates

Publication Date
20260508
Application Date
20251205

Claims (10)

  1. 1. The method for correcting the environment reflection based on the 3D graphic rendering is characterized by comprising the following steps of: In a vertex shader of 3D rendering, world coordinates of a target vertex and world coordinates of a camera are obtained; normalizing the difference value between the world coordinates of the target vertex and the world coordinates of the camera to obtain a sight line direction vector, and obtaining the dot product of the sight line direction vector and the vertex normal vector corresponding to the target vertex; Judging whether the dot product is larger than zero, if not, determining the reflecting direction according to the sight line direction vector and the target vertex normal vector, and transmitting the reflecting direction to the pixel shader; Interpolation processing is carried out on the reflection direction vector corresponding to each vertex based on the same primitive, so that the reflection direction vector of each pixel point in the primitive is obtained; And obtaining a corresponding environment reflection value based on the reflection direction vector sampling of each pixel point, and performing illumination calculation based on the environment reflection value to complete the environment reflection correction of 3D graphic rendering.
  2. 2. The 3D graphics rendering-based ambient reflection correction method according to claim 1, wherein the normalizing the difference between the world coordinates of the vertex and the world coordinates of the camera to obtain the line-of-sight direction vector is specifically: In a 3D rendered vertex shader, target vertex world coordinates World coordinates with camera Is of the difference vector of (2) The method comprises the following steps: ; invoking vector normalization functions in 3D rendering domain For a pair of Performing normalization processing to obtain a vector with a length of 1 to obtain a line-of-sight direction vector 。
  3. 3. The method for correcting environmental reflection based on 3D graphics rendering according to claim 2, wherein the obtaining a dot product of the line-of-sight direction vector and a vertex normal vector corresponding to the target vertex is specifically: in a 3D rendered vertex shader, based on normalized gaze direction vectors Simultaneously obtaining a vertex normal vector N which is predefined by a target vertex and has completed normalization processing; Vector dot product operation function through 3D graphics rendering domain The dot product value of the sight line direction vector V and the vertex normal vector N is calculated, specifically: ; wherein the dot product value The value range of (1) is [ -1,1], which represents the cosine value of the included angle between the line of sight direction and the normal of the vertex; When (when) When the included angle between the sight line direction vector and the vertex normal vector corresponding to the target vertex is smaller than 90 degrees, the sight line direction faces the front of the vertex normal; When (when) When the included angle between the sight line direction vector and the vertex normal vector corresponding to the target vertex is larger than 90 degrees, the sight line direction is towards the back of the vertex normal.
  4. 4. The method for correcting reflection of environment based on 3D graphics rendering according to claim 3, wherein the determining the reflection direction according to the line-of-sight direction vector and the target vertex normal vector is specifically: When (when) At the time, the normalized sight direction vector As a reflection direction vector The forced reflection direction points to the front surface, so that the sampling of the back surface environment is avoided; When (when) When reflecting direction vector The method comprises the following steps: 。
  5. 5. The method for correcting environmental reflection based on 3D graphic rendering of claim 4 wherein the interpolation of the reflection direction vectors corresponding to each vertex based on the same primitive to obtain the reflection direction vector of each pixel in the primitive comprises a line segment and a polygon, and when the primitive is a line segment, the vertex shader will reflect the reflection direction vector in the same primitive Transmitting the pixel data to a pixel shader, and interpolating the pixel shader, wherein the pixel shader is used for calculating the reflection direction vector of the pixel point according to the position weight of the pixel point in the pixel point by taking the reflection direction vector corresponding to the vertex of the pixel point as a reference ; When there are line segments with vertices A and B, the pixel point C is at any position of the line segment, and the total length of the line segment AB is set as The distance from the pixel point C to the point A is Then the location weight coefficient Is that ; The reflection direction vector of pixel point C The method comprises the following steps: ; Wherein, the Is the a-vertex reflection direction vector, Is the B vertex reflection direction vector, and (1-t) is the weight of the A vertex reflection direction vector, The weight of the reflection direction vector of the B vertex; When the primitive is a polygon, when a plurality of vertexes are graphics, the barycentric coordinates of the pixel point P in the polygon are ; ,( ) Wherein, the The weights of the direction vectors are reflected for the A1 vertex, The weights of the direction vectors are reflected for the A2 vertex, The weight of the reflection direction vector of the An vertex; is the A1 vertex reflection direction vector, Is the A2 vertex reflection direction vector, Is An vertex reflection direction vector.
  6. 6. The method for correcting the environment reflection based on the 3D graphics rendering of claim 5, wherein the corresponding environment reflection value is obtained by sampling the reflection direction vector based on each pixel point, specifically, invoking the environment map resource preloaded in the 3D rendering scene, taking the interpolation reflection direction as the sampling coordinate of the environment map, performing texture sampling operation on the environment map, obtaining the environment reflection color information corresponding to the sampling coordinate in the environment map, and taking the environment reflection color information as the environment reflection value of the pixel.
  7. 7. The method for correcting the environment reflection based on the 3D graphics rendering according to claim 5, wherein the corresponding environment reflection value is obtained by sampling the reflection direction vector based on each pixel point, specifically, a group of basis functions and corresponding coefficients are used in advance to represent the environment reflection in the 3D graphics rendering, the reflection direction vector of each pixel point obtained by interpolation is used as the parameters of the group of basis functions and the corresponding coefficients, the environment reflection color information corresponding to the reflection direction vector is calculated, and the environment reflection color information is used as the environment reflection value of the pixel.
  8. 8. The method for correcting environmental reflection based on 3D graphics rendering according to claim 7, wherein the using a set of basis functions and corresponding coefficients to represent environmental reflection uses the interpolated reflection direction vector of each pixel as the parameters of the set of basis functions and corresponding coefficients, calculates environmental reflection color information corresponding to the reflection direction vector, and uses the environmental reflection color information as the environmental reflection value of the pixel, specifically: adopting spherical harmonic function as basic function, and recording as a group of basic functions Wherein n is the number of basis functions, performing global sampling on the environment reflection of the target scene, and setting coefficients The basis function is calculated Sum coefficient of Pre-storing the color into rendering resources, and calculating the environment reflection color, wherein the color is as follows: 。
  9. 9. The method for correcting the environment reflection based on the 3D graphic rendering according to claim 8, wherein the method for correcting the environment reflection based on the 3D graphic rendering is characterized in that the method for correcting the environment reflection based on the environment reflection value is characterized in that the method for correcting the environment reflection based on the 3D graphic rendering is realized by carrying out illumination calculation based on a physical rendering PBR algorithm.
  10. 10. An ambient reflection correction system based on 3D graphics rendering, comprising: the acquisition module acquires world coordinates of the target vertex and world coordinates of the camera in the vertex shader of the 3D rendering; The normalization module performs normalization operation on the difference value between the world coordinates of the target vertex and the world coordinates of the camera to obtain a sight direction vector, and obtains a dot product of the sight direction vector and a vertex normal vector corresponding to the target vertex; The judging module judges whether the dot product is larger than zero, if not, the reflecting direction is determined according to the sight line direction vector and the target vertex normal vector, and the reflecting direction is transmitted to the pixel shader; The interpolation module is used for carrying out interpolation processing on the reflection direction vector corresponding to each vertex based on the same primitive to obtain the reflection direction vector of each pixel point in the primitive; And the calculation module is used for sampling the reflection direction vector of each pixel point to obtain a corresponding environment reflection value, and carrying out illumination calculation based on the environment reflection value to complete the environment reflection correction of the 3D graphic rendering.

Description

Environment reflection correction method and system based on 3D graphics rendering Technical Field The invention belongs to the technical field of 3D rendering, and relates to an environment reflection correction method and system based on 3D graphics rendering. Background In the field of 3D graphics rendering, vertex normal interpolation and normal sampling environment mapping are key technologies for realizing restoration of real visual texture, and are widely used for scenes such as game development, design visualization and the like. The vertex normal interpolation can realize smooth texture of the role skin, the car body and the like by defining the normal line of the attaching curved surface for the vertex and linearly interpolating the pixel normal line. The normal line sampling environment mapping is used for extracting color superposition illumination by pre-storing 360-degree environment colors and taking pixel normal lines as sampling coordinates, simulating environment reflection of metal and glass and improving reality. But there is a problem in that the vertex normal interpolation may deviate the interpolation normal of a part of the pixels from the actual direction of the model, resulting in erroneous sampling of the reflected light from the back surface. Therefore, a need exists for an apparatus that can effectively solve the problem of abnormal mapping of the sampling environment. Disclosure of Invention The invention aims to solve the problems that in the prior art, interpolation normals of partial pixels possibly deviate from the actual direction of a model, so that metal plane reflection sky and the like appear in a sampling environment map, and provides an environment reflection correction method and system based on 3D graphics rendering. In order to achieve the purpose, the invention is realized by adopting the following technical scheme: An environmental reflection correction method based on 3D graphics rendering, comprising: In a vertex shader of 3D rendering, world coordinates of a target vertex and world coordinates of a camera are obtained; normalizing the difference value between the world coordinates of the target vertex and the world coordinates of the camera to obtain a sight line direction vector, and obtaining the dot product of the sight line direction vector and the vertex normal vector corresponding to the target vertex; Judging whether the dot product is larger than zero, if not, determining the reflecting direction according to the sight line direction vector and the target vertex normal vector, and transmitting the reflecting direction to the pixel shader; Interpolation processing is carried out on the reflection direction vector corresponding to each vertex based on the same primitive, so that the reflection direction vector of each pixel point in the primitive is obtained; And obtaining a corresponding environment reflection value based on the reflection direction vector sampling of each pixel point, and performing illumination calculation based on the environment reflection value to complete the environment reflection correction of 3D graphic rendering. The invention further improves that: Further, the normalizing operation is performed on the difference between the world coordinates of the vertex and the world coordinates of the camera to obtain a line-of-sight direction vector, which specifically includes: In a 3D rendered vertex shader, target vertex world coordinates World coordinates with cameraIs of the difference vector of (2)The method comprises the following steps: invoking vector normalization functions in 3D rendering domain For a pair ofPerforming normalization processing to obtain a vector with a length of 1 to obtain a line-of-sight direction vector。 Further, the obtaining a dot product of the sight line direction vector and the vertex normal vector corresponding to the target vertex specifically includes: in a 3D rendered vertex shader, based on normalized gaze direction vectors Simultaneously obtaining a vertex normal vector N which is predefined by a target vertex and has completed normalization processing; Vector dot product operation function through 3D graphics rendering domain The dot product value of the sight line direction vector V and the vertex normal vector N is calculated, specifically: wherein the dot product value The value range of (1) is [ -1,1], which represents the cosine value of the included angle between the line of sight direction and the normal of the vertex; When (when) When the included angle between the sight line direction vector and the vertex normal vector corresponding to the target vertex is smaller than 90 degrees, the sight line direction faces the front of the vertex normal; When (when) When the included angle between the sight line direction vector and the vertex normal vector corresponding to the target vertex is larger than 90 degrees, the sight line direction is towards the back of the vertex normal. Further, the