Fog effect generation method and device, equipment and storage medium
By obtaining the depth map and world coordinates of the target scene, combining the rendering methods of screen and sky textures, realistic fog effects are generated, which solves the problem of unrealistic fog effects in 3D scenes in the existing technology, and realizes the saving of computing resources and flexible adjustment of fog effects.
Patent Information
- Application Number
- CN202510411447.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-08-01
AI Technical Summary
In the prior art, the fog effect generated by 2D scenes lacks three-dimensional spatial range adjustment, and it is impossible to generate realistic fog effect effects in 3D scenes.
By obtaining the depth map of the target scene, the screen space normalized coordinates determine the depth value and world coordinates of each pixel point, combined with the preset fog effect range, the pixel points are rendered in the form of screen texture, mixed rendering and sky texture to generate realistic fog effect.
Realize realistic fog effect generation in 3D scenes, reduces the consumption of computing resources, and can flexibly adjust the fog effect range and concentration, which is suitable for fog effect restoration in animation and games.
Smart Images

Figure CN120411275A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the technical field of 3D modeling. Specifically, the present application relates to a fog effect generation method, apparatus, device, and storage medium. Background Art
[0002] The fog effect generates a fog effect in a 3D scene. This effect can not only restore the foggy weather effect but also be used to obscure objects, reduce the units displayed in the picture, and achieve the effect of saving computing resources. In the related art, generally, some planar fog effects are generated through 3D software.
[0003] In the related art, the fog effect generated for a 2D scene does not have the function of adjusting the three-dimensional spatial range, does not produce a gradient effect with the models in the 3D scene, and the generated fog effect is not realistic enough. Summary of the Invention
[0004] Embodiments of the present application provide a fog effect generation method, apparatus, device, and storage medium, aiming to generate a realistic and restored fog effect.
[0005] In a first aspect of the embodiments of the present application, a fog effect generation method is provided. The method includes: Obtain a depth map corresponding to the target scene; Obtain the depth value of each pixel point from the depth map through the normalized coordinates in screen space; Determine the world coordinates of each pixel point according to the depth value; Obtain the pixel value of the screen image texture and the pixel value of the background sky texture through the normalized coordinates in screen space; Determine the rendering method corresponding to the pixel point according to the relationship between the world coordinates of each pixel point and the preset fog effect range; Render the pixel point corresponding to the screen image texture pixel value and the background sky texture pixel value to obtain the fog effect corresponding to the target scene.
[0006] Optionally, before obtaining the depth map corresponding to the target scene, the method further includes: Obtain the scene data corresponding to the target scene, where the scene data at least includes the screen image texture, the background sky texture, the inner radius value of the fog effect, the outer radius value of the fog effect, and the screen image depth map texture.
[0007] Optionally, the step of obtaining the depth value of each pixel point from the depth map through the normalized coordinates in screen space includes: Determine the position of each pixel point in the depth map through the normalized coordinates in screen space; Sample each of the pixel points to obtain the depth value of the pixel point.
[0008] Optionally, the determining of the world coordinates of each pixel point according to the depth value includes: Obtain the homogeneous coordinates of the built-in screen pixels within the rendering pipeline, where the homogeneous coordinates are obtained based on the depth value; Obtain the corresponding four-dimensional data point through the homogeneous coordinates, the camera projection, and the inverse matrix of the field of view matrix; Divide the four-dimensional data point by the perspective projection auxiliary component of the four-dimensional data point to obtain the world coordinates corresponding to the pixel point.
[0009] Optionally, the obtaining of the pixel value of the screen image texture and the pixel value of the background sky texture through the normalized coordinates in the screen space includes: Determine the pixel position of the screen image texture and the pixel position of the background sky texture according to the normalized coordinates in the screen space; Sample the pixel according to the pixel position of the screen image texture and the pixel position of the background sky texture to obtain the pixel value of the screen image texture and the pixel value of the background sky texture.
[0010] Optionally, the determining of the rendering method corresponding to the pixel point according to the relationship between the world coordinates of each pixel point and a preset fog effect range includes: When the distance between the world coordinates of the pixel point and the camera is less than the inner circle radius value of the fog effect, determine that the rendering method of the pixel is screen texture rendering; When the distance between the world coordinates of the pixel point and the camera is greater than the inner circle radius value of the fog effect and less than the outer circle radius value of the fog effect, determine that the rendering method of the pixel is mixed rendering; When the distance between the world coordinates of the pixel point and the camera is greater than the outer circle radius of the fog effect, determine that the rendering method of the pixel is sky texture rendering.
[0011] Optionally, the rendering of the pixel in a corresponding manner through the pixel value of the screen image texture and the pixel value of the background sky texture to obtain the fog effect corresponding to the target scene includes: When the rendering method corresponding to the pixel point is screen texture rendering, use the pixel value at the corresponding position in the screen texture image as the pixel value of the pixel point; When the rendering method corresponding to the pixel point is mixed rendering, obtain the pixel value of the pixel point according to the pixel value of the screen image texture and the pixel value of the background sky texture through a preset mixing formula; When the rendering method corresponding to the pixel point is sky texture rendering, the pixel value at the corresponding position of the background sky texture is used as the pixel value of the pixel point.
[0012] The second aspect of the embodiments of the present application provides a fog effect generation device, and the device includes: A depth map acquisition module, configured to acquire a depth map corresponding to a target scene; A depth value acquisition module, configured to acquire the depth value of each pixel point from the depth map through the normalized coordinates in screen space; A world coordinate determination module, configured to determine the world coordinate of each pixel point according to the depth value; A pixel value sampling module, configured to acquire the pixel value of the screen picture texture and the pixel value of the background sky texture through the normalized coordinates in screen space; A rendering method determination module, configured to determine the rendering method corresponding to the pixel point according to the relationship between the world coordinate of each pixel point and a preset fog effect range; A pixel point rendering module, configured to perform corresponding rendering on the pixel point through the pixel value of the screen picture texture and the pixel value of the background sky texture, to obtain the fog effect corresponding to the target scene.
[0013] Optionally, the device further includes: A scene data acquisition module, configured to acquire the scene data corresponding to the target scene, where the scene data at least includes the screen picture texture, the background sky texture, the inner radius value of the fog effect, the outer radius value of the fog effect, and the screen picture depth map texture.
[0014] Optionally, the depth value acquisition module includes: A first pixel point position acquisition sub-module, configured to determine the position of each pixel point in the depth map through the normalized coordinates in screen space; A first pixel point sampling sub-module, configured to sample each pixel point to obtain the depth value of the pixel point.
[0015] Optionally, the world coordinate determination module includes: A homogeneous coordinate determination sub-module, configured to acquire the homogeneous coordinates of the built-in screen pixels in the rendering pipeline, where the homogeneous coordinates are obtained according to the depth value; A data point acquisition sub-module, configured to obtain a corresponding four-dimensional data point through the homogeneous coordinates, the camera projection, and the inverse matrix of the field of view matrix; A world coordinate determination sub-module, configured to divide the four-dimensional data point by the perspective projection auxiliary component of the four-dimensional data point to obtain the world coordinate corresponding to the pixel point.
[0016] Optionally, the pixel value sampling module includes: A second pixel point position acquisition sub-module, configured to determine the pixel positions of the screen image texture and the background sky texture according to the normalized coordinates in the screen space; A second pixel point sampling sub-module, configured to sample the pixel according to the pixel positions of the screen image texture and the background sky texture, and obtain the pixel values of the screen image texture and the background sky texture.
[0017] Optionally, the rendering method determination module includes: A first rendering method determination sub-module, configured to determine that the rendering method of the pixel is screen texture rendering when the distance between the world coordinate of the pixel point and the camera is less than the inner circle radius value of the fog effect; A second rendering method determination sub-module, configured to determine that the rendering method of the pixel is hybrid rendering when the distance between the world coordinate of the pixel point and the camera is greater than the inner circle radius value of the fog effect and less than the outer circle radius value of the fog effect; A third rendering method determination sub-module, configured to determine that the rendering method of the pixel is sky texture rendering when the distance between the world coordinate of the pixel point and the camera is greater than the outer circle radius of the fog effect.
[0018] Optionally, the pixel point rendering module includes: A first pixel point rendering sub-module, configured to use the pixel value at the corresponding position in the screen texture image as the pixel value of the pixel point when the rendering method corresponding to the pixel point is screen texture rendering; A second pixel point rendering sub-module, configured to obtain the pixel value of the pixel point according to the pixel value of the screen image texture and the pixel value of the background sky texture through a preset blending formula when the rendering method corresponding to the pixel point is hybrid rendering; A third pixel point rendering sub-module, configured to use the pixel value at the corresponding position of the background sky texture as the pixel value of the pixel point when the rendering method corresponding to the pixel point is sky texture rendering.
[0019] A third aspect of the embodiments of the present application provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in the first aspect of the present application is implemented.
[0020] A fourth aspect of the embodiments of the present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the method described in the first aspect of the present application are implemented.
[0021] Adopt the fog effect generation method provided by this application to obtain the depth map corresponding to the target scene; obtain the depth value of each pixel point from the depth map through the normalized coordinates in screen space; determine the world coordinates of each pixel point according to the depth value; obtain the pixel value of the screen picture texture and the pixel value of the background sky texture through the normalized coordinates in screen space; determine the rendering method corresponding to the pixel point according to the relationship between the world coordinates of each pixel point and the preset fog effect range; Render the pixel point correspondingly through the pixel value of the screen picture texture and the pixel value of the background sky texture to obtain the fog effect corresponding to the target scene.
[0022] In this application, by obtaining the depth map of the target scene, the world coordinates of each pixel in the target scene are deduced inversely, and then according to the relationship between each pixel and the preset fog effect range, the rendering method of the pixel is determined. Furthermore, according to the pixel values of the screen picture texture and the sky texture collected, each pixel is rendered correspondingly, and the relationship between the fog effect and each object in the screen is realistically established. The fog effect range can be adjusted based on the actual physical environment in the scene, and a real fog effect is generated in the target scene. Description of the Drawings
[0023] In order to more clearly illustrate the technical solutions of the embodiments of this application, the drawings required to be used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0024] Figure 1 It is a simulated driving scene diagram proposed in an embodiment of this application; Figure 2 It is a fog effect diagram proposed in an embodiment of this application; Figure 3 It is a spatial thick fog effect diagram proposed in an embodiment of this application; Figure 4 It is a spatial thin fog effect diagram proposed in an embodiment of this application; Figure 5 It is a schematic diagram of the fog effect generation process proposed in an embodiment of this application; Figure 6 It is a flowchart of the fog effect generation method proposed in an embodiment of this application; Figure 7 It is a flowchart of the fog effect algorithm proposed in an embodiment of this application; Figure 8 It is a schematic diagram of the spatial fog effect controller proposed in an embodiment of this application; Figure 9It is a schematic diagram of a fog effect generation device proposed in an embodiment of the present application; Figure 10 It is a schematic diagram of an electronic device proposed in an embodiment of the present application. Specific embodiments
[0025] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0026] When displaying some simulated scenes on the screen, it is necessary to restore the foggy weather effect in the scene, or in the case of too many objects in the scene, it is necessary to block some distant objects through the fog effect to save the computing resources consumed in processing the picture. The fog effect is generally made through 3D software such as (unity), etc. In some scenes, such as Figure 1 as shown Figure 1 is a simulated driving scene diagram proposed in an embodiment of the present application, Figure 1 in which is a picture without spatial fog effect, and there are many objects on both sides of the road to be displayed, such as Figure 2 as shown Figure 2 is a fog effect rendering diagram proposed in an embodiment of the present application, such as Figure 2 as shown, by generating the fog effect, some distant objects can be blocked, the number of displayed objects can be reduced, and the foggy weather effect can also be restored. As Figure 3 as shown Figure 3 is a spatial thick fog rendering diagram proposed in an embodiment of the present application. In the figure, most of the objects are blocked by generating thick fog, greatly reducing the calculation amount. As Figure 4 as shown Figure 4 is a spatial light fog rendering diagram proposed in an embodiment of the present application. A small amount of fog effect blocks distant objects to a certain extent. The fog effect proposed in the present application can be set through the spatial fog effect controller in the software, for example, by controlling the outer radius and inner radius of the fog effect, etc.
[0027] Refer to Figure 5 Figure 5 is a schematic diagram of the fog effect generation process proposed in an embodiment of the present application, such as Figure 5 As shown, first obtain the global depth map, then construct the world coordinate values of each pixel point based on the depth map, then obtain the distance values of the fog effect (the farthest and the nearest values), and then determine whether the world coordinates of the pixel point are within the fog effect range. When the world coordinates are within the fog effect range, render the corresponding pixel points through the texture of the sky in the scene graph and the texture of the objects in the picture. When the world coordinates are not within the fog effect range, use the original texture to render the pixel points. Finally, output the corresponding pixel values on the screen to generate the fog effect. The following is a detailed description of this process: Reference Figure 6 , Figure 6 is a flowchart of a fog effect generation method proposed in an embodiment of the present application. As Figure 6 shown, it specifically includes the following steps: S11: Obtain the depth map corresponding to the target scene.
[0028] In this embodiment, the target scene is the scene where the fog effect needs to be generated. The depth map is a two-dimensional image that records the distance information between the objects in the scene and the sensor or camera through pixel values. Its core feature is to compress the three-dimensional space information into a two-dimensional plane. The depth map stores the depth information of each pixel in the form of a two-dimensional matrix, representing the distance from the object surface to the camera, usually saved in floating-point or integer form.
[0029] In this embodiment, establish the image of the target scene through 3D modeling software, and then establish the depth map of the target scene according to the depth information in the target scene image.
[0030] In this embodiment, there is a virtual camera in the 3D modeling software. Take this virtual camera as the observation point of the scene. According to the distance of each pixel point in the 3D scene from the virtual camera, normalize the distance to obtain the depth of the pixel, and then add the depth information to each pixel to construct the depth map corresponding to the scene.
[0031] Exemplarily, when simulating a driving scene, obtain the image of the target scene where the car is driving on the road surface. At this time, according to the distance between the camera and each object in the scene, determine the depth value of each pixel, and then obtain the depth value of the driving picture.
[0032] In this embodiment, obtaining the depth map of the target scene is beneficial to inversely deduce the world coordinates of each pixel using the depth information during the subsequent fog effect generation, and then determine whether fog effect rendering is required.
[0033] S12: Obtain the depth value of each pixel point from the depth map through the normalized coordinates in screen space.
[0034] In this embodiment, the normalized coordinates (UV coordinates) in screen space are a coordinate system used in computer graphics to accurately map a two-dimensional texture onto the surface of a three-dimensional model. It consists of the horizontal direction U and the vertical direction V, forming a two-dimensional plane coordinate system for positioning pixel positions on the texture image.
[0035] In this embodiment, through the normalized coordinates in screen space, the position of each pixel in the target scene is determined, and then each pixel is sampled to obtain the depth value of each pixel from the depth map. The specific steps include: S12-1: Determine the position of each pixel point in the depth map through the normalized coordinates in screen space.
[0036] In this embodiment, after the depth map of the target scene is established, it is placed in the normalized coordinate system of screen space. Then, each pixel point in the depth map has a corresponding normalized coordinate in screen space, that is, according to the normalized coordinates in screen space, the position of each pixel in the depth map can be determined.
[0037] Exemplarily, the coordinate value of one pixel point being (0, 1) means that the horizontal coordinate of this coordinate is 0 and the vertical coordinate is 1.
[0038] S12-2: Sample each pixel point to obtain the depth value of the pixel point.
[0039] In this embodiment, after determining the position of each pixel in the depth map in the normalized coordinate system of screen space, each pixel is sampled at the corresponding position to obtain the depth value of the pixel.
[0040] Exemplarily, the depth value d = 1.5m corresponding to the pixel coordinate (u = 320, v = 240) means that this point is 1.5 meters away from the camera.
[0041] In this embodiment, sampling the depth map through the normalized coordinate system in screen space to obtain the depth value of each pixel point is conducive to constructing the world coordinates of each pixel.
[0042] S13: Determine the world coordinates of each pixel point according to the depth value.
[0043] In this embodiment, the world coordinate system (World Coordinate System, WCS) is the global benchmark for describing the positions of all objects in a three-dimensional scene. The origin and the directions of the coordinate axes are fixed and unchanged, and are used to uniformly identify the absolute positions of all objects in the scene. The world coordinate system is not affected by the rotation or translation of the object itself. Even if the object undergoes a transformation, its world coordinates are still calculated based on the global origin.
[0044] In this embodiment, after obtaining the depth value of each pixel in the picture of the target scene, the world coordinates of each pixel are determined according to the depth value. The specific steps include: S13-1: Obtain the homogeneous coordinates of the built-in screen pixels in the rendering pipeline, where the homogeneous coordinates are obtained according to the depth value.
[0045] In this embodiment, the rendering pipeline is the whole process in computer graphics of converting 3D model data into 2D screen pixels. It defines the data flow and processing steps from the original geometric data to the final image, and is the core framework of real-time rendering, game engines, and 3D software. The homogeneous coordinates NDC (Normalized Device Coordinates) are the standardized coordinates after projection transformation, and the coordinate ranges of all visible objects are compressed into the cube [-1, 1]³ (OpenGL) or [0,1]³ (DirectX).
[0046] In this embodiment, the rendering pipeline includes the data flow and processing steps from the original geometric data to the final image. In the rendering pipeline, the homogeneous coordinates of the screen pixels can be obtained, and the homogeneous coordinates are obtained from the pixel depth value.
[0047] Exemplarily, NDC is the homogeneous coordinate (4D vector), such as (x_ndc, y_ndc, z_ndc, 1), used to represent the position after projection, and the fourth dimension (w) is usually 1. Among them, z_ndc is obtained from the depth value.
[0048] S13-2: Obtain the corresponding four-dimensional data point through the homogeneous coordinate, camera projection, and the inverse matrix of the field of view matrix.
[0049] In this embodiment, the camera projection is to project the camera coordinates into the NDC space (including perspective or orthogonal transformation), and the field of view matrix is the matrix that converts the world coordinates into the camera coordinate system (i.e., the coordinates under the camera view).
[0050] In this embodiment, after obtaining the homogeneous coordinates of each pixel point, the corresponding four-dimensional data point is obtained according to the homogeneous coordinate, camera projection, and the inverse matrix of the field of view matrix.
[0051] Exemplarily, the world coordinate is equal to the homogeneous coordinate × the view matrix × the inverse matrix of the projection matrix.
[0052] S13-3: Divide the four-dimensional data point by the perspective projection auxiliary component of the four-dimensional data point to obtain the world coordinate corresponding to the pixel point.
[0053] In this embodiment, the perspective projection auxiliary component is the fourth component W of homogeneous coordinates. In the projection transformation, this component may not be 1 (for example, perspective projection will introduce scaling of the W component). In this case, normalization is required to reflect the true world coordinates.
[0054] In this embodiment, after obtaining the four-dimensional data point, divide the four-dimensional data point by its perspective projection auxiliary component, that is, the fourth component, to obtain the world coordinates corresponding to the pixel point.
[0055] In this embodiment, by restoring the world coordinates of each pixel in the target scene image through the depth value, and then determining the position of each pixel in the world coordinate system, it is beneficial to quickly render each pixel.
[0056] S14: Obtain the pixel value of the screen image texture and the pixel value of the background sky texture through the normalized coordinates in the screen space.
[0057] In this embodiment, the pixel value of the screen image texture is the true pixel value of each object in the screen image, and the pixel value of the background sky texture is the true pixel value of the sky in the background of the screen image.
[0058] In this embodiment, after obtaining the depth map of the target scene, according to the normalized coordinates in the screen space, obtain the pixel value of the screen image texture and the pixel value of the background sky texture. The specific steps include: S14-1: Determine the pixel position of the screen image texture and the pixel position of the background sky texture according to the normalized coordinates in the screen space.
[0059] In this embodiment, after obtaining the scene image, place the scene image in the normalized coordinate system of the screen space, and then determine the coordinate value of each pixel in the scene image. According to this coordinate value, the pixel position of the screen image texture and the pixel position of the background sky texture in the scene image can be determined.
[0060] Exemplarily, in a vehicle driving scene image, the screen image texture is the texture of objects such as vehicles, roads, and buildings on the screen, and the background sky texture is the texture of the distant sky in the scene image.
[0061] S14-2: Sample the pixel according to the pixel position of the screen image texture and the pixel position of the background sky texture to obtain the pixel value of the screen image texture and the pixel value of the background sky texture.
[0062] In this embodiment, after determining the pixel position of the screen image texture and the pixel position of the background sky texture, sample each pixel in the image to obtain the pixel value of the screen image texture and the pixel value of the background sky texture.
[0063] In this embodiment, obtaining the pixel values of the screen image texture and the pixel values of the background sky texture is the basis for subsequent rendering, which is conducive to restoring the real fog effect.
[0064] S15: Determine the rendering method corresponding to each pixel point according to the relationship between the world coordinates of each pixel point and the preset fog effect range.
[0065] In this embodiment, the fog effect range refers to the range covered by the fog effect in the scene image. The rendering method refers to how to render each pixel point.
[0066] In this embodiment, after obtaining the world coordinates of each pixel, the distance between the world coordinates of each pixel and the virtual camera can be determined. By comparing the relationship between this distance and the preset fog effect range, the rendering method corresponding to the pixel point can be determined. When the distance between the world coordinates and the virtual camera is less than the inner radius of the fog effect, the pixel point is directly rendered using the screen image texture. When the distance between the world coordinates and the virtual camera is greater than the inner radius of the fog effect and less than the outer radius of the fog effect, the corresponding pixel point is rendered using a hybrid rendering method to reflect the fog effect. When the distance between the world coordinates and the virtual camera is greater than the outer radius of the fog effect, the corresponding pixel point is rendered using the background sky texture. The specific steps include: S15-1: When the distance between the world coordinates of the pixel point and the camera is less than the inner radius value of the fog effect, determine that the rendering method of the pixel is screen texture rendering.
[0067] In this embodiment, screen texture rendering is to use the original pixel values on the screen to render the corresponding pixel points, ensuring the restored display of objects.
[0068] In this embodiment, when the distance between the world coordinates of the pixel and the camera is less than the inner radius value of the fog effect, it means that the corresponding pixel point is not covered by the fog range. At this time, the pixel point is directly rendered using the screen texture rendering method.
[0069] For example, the distance between the world coordinates of a certain pixel and the camera is 10m, and the inner radius value of the fog effect is 20m. At this time, the pixel is rendered using the screen texture rendering method.
[0070] S15-2: When the distance between the world coordinates of the pixel point and the camera is greater than the inner radius value of the fog effect and less than the outer radius value of the fog effect, determine that the rendering method of the pixel is hybrid rendering.
[0071] In this embodiment, hybrid rendering is to use the background sky texture and the screen image texture to hybridly render a pixel point.
[0072] In this embodiment, when the distance between the world coordinates of a pixel and the camera is greater than the inner radius value of the fog effect and less than the outer radius value of the fog effect, it indicates that the pixel is within the fog effect range. At this time, a hybrid rendering method is used for rendering to reflect that the position of the pixel is covered by the fog.
[0073] For example, the distance between the world coordinates of a certain pixel and the camera is 30m, the inner radius value of the fog effect is 20m, and the outer radius value is 50m. At this time, the hybrid rendering method is used to render this pixel.
[0074] S15-3: When the distance between the world coordinates of the pixel and the camera is greater than the outer radius of the fog effect, determine that the rendering method of the pixel is sky texture rendering.
[0075] In this embodiment, sky texture rendering is used to render the pixels in the scene image whose distance exceeds the maximum range of the fog effect.
[0076] In this embodiment, when the distance between the world coordinates of a pixel and the camera is greater than the outer radius of the fog effect, it indicates that the pixel is at the far end in the image, and the sky texture is directly used for rendering.
[0077] For example, the distance between the world coordinates of a certain pixel and the camera is 60m, and the outer radius value of the fog effect is 50m. At this time, the sky texture rendering method is used to render this pixel.
[0078] In this embodiment, by determining the distance between the world coordinates and the camera, it is judged whether a pixel needs to be rendered, ensuring that each pixel in the target scene can be rendered according to the range of the fog effect, and the range of the fog effect can also be flexibly adjusted to ensure the restoration of the real fog effect.
[0079] S16: Render the pixel according to the pixel value of the screen image texture and the pixel value of the background sky texture to obtain the fog effect corresponding to the target scene.
[0080] In this embodiment, after determining the rendering method corresponding to each pixel, the pixels at the corresponding positions are rendered through the pixel value of the screen image texture and the pixel value of the background sky texture. Among them, the pixels outside the fog effect range restore the original pixel values in the scene image, and the pixels within the fog effect range are rendered using the hybrid rendering method to generate the corresponding fog effect, and then the fog effect corresponding to the target scene can be obtained. The specific steps include: S16-1: When the rendering method corresponding to the pixel is screen texture rendering, use the pixel value at the corresponding position in the screen texture image as the pixel value of the pixel.
[0081] In this embodiment, when the rendering method corresponding to a pixel is screen texture rendering, it indicates that the pixel is not within the fog effect range. At this time, the pixel value at the corresponding position in the screen texture image is used as the pixel value of this pixel.
[0082] Exemplarily, the rendering method corresponding to a pixel is screen texture rendering. At this time, the pixel value sampled from the screen image texture is directly rendered to this pixel.
[0083] S16-2: When the rendering method corresponding to the pixel is hybrid rendering, according to a preset blending formula, the pixel value of the pixel is obtained based on the pixel value of the screen image texture and the pixel value of the background sky texture.
[0084] In this embodiment, when the rendering method corresponding to a pixel is hybrid rendering, it indicates that the pixel is within the fog effect range. At this time, according to a preset blending formula, calculations are performed based on the pixel value of the screen image texture and the pixel value of the background sky texture to obtain the pixel value of this pixel.
[0085] In this embodiment, the blending formula is expressed as: Pixel value = Screen texture pixel value × (1 - value) + Sky texture pixel value × (value).
[0086] Where value is a proportional value, value = (length - Inner circle radius) / (Outer circle radius - Inner circle radius), and length is the distance value from the world coordinate of the pixel to the position of the view end point.
[0087] In this embodiment, using this blending formula for calculation can make the fog effect transparency of pixels closer to the camera a little higher, and the fog effect transparency of pixels farther from the camera lower, thereby restoring a realistic fog effect.
[0088] S16-3: When the rendering method corresponding to the pixel is sky texture rendering, the pixel value at the corresponding position of the background sky texture is used as the pixel value of this pixel.
[0089] In this embodiment, when the rendering method corresponding to a pixel is sky texture rendering, it indicates that the position of this pixel is outside the fog effect range and very far from the camera. At this time, the pixel value at the corresponding position of the background sky texture is used as the pixel value of this pixel.
[0090] Exemplarily, the rendering method corresponding to a pixel is sky texture rendering. At this time, the pixel value sampled from the corresponding position of the background sky texture is directly rendered to this pixel.
[0091] In this embodiment, different rendering methods are adopted for pixel points at different positions to obtain the final image, and then a realistic fog effect is restored in the 3D scene.
[0092] In another embodiment of the present application, before obtaining the depth map corresponding to the target scene, the method further includes: S21: Obtain the scene data corresponding to the target scene, where the scene data at least includes the screen frame texture, the background sky texture, the inner radius value of the fog effect, the outer radius value of the fog effect, and the screen frame depth map texture.
[0093] In this embodiment, the screen frame depth map texture is a frame texture carrying depth information. The inner radius of the fog effect and the outer radius of the fog effect define the range of the fog effect.
[0094] In this embodiment, before obtaining the panoramic depth map, first obtain the scene data corresponding to the target scene, where the scene data at least includes the screen frame texture, the background sky texture, the inner radius of the fog effect, the outer radius of the fog effect, and the screen frame depth map texture. Among them, the screen frame texture, the background sky texture, and the screen frame depth map are the inherent data in the generated target scene and can be directly read through 3D software. The inner radius of the fog effect and the outer radius of the fog effect can be custom-designed according to the needs of the designer.
[0095] In this embodiment, by obtaining the scene data corresponding to the target scene, it provides data support for the subsequent generation of the fog effect. When the range of the fog effect changes, the new fog effect radius value can also be read at any time, and then the range of the fog effect can be adjusted at any time to ensure the display effect of the fog effect.
[0096] In another embodiment of the present application, refer to Figure 7 , Figure 7 is the flowchart of the fog effect algorithm proposed in an embodiment of the present application. This figure details the algorithm for generating the fog effect. As Figure 7 shown, the input data includes the screen frame texture, the background sky texture, the inner radius value, the outer radius value, and the screen frame depth map texture. According to the uv value of each pixel, obtain the depth value of each pixel point from the depth map. According to the depth value, calculate the world coordinates of each pixel point, then sample the pixel values of the screen texture and the pixel values of the sky texture, use the distance from the world coordinates of each pixel point to the camera to determine whether rendering is required, render each pixel point using the corresponding rendering method, and finally output the value of each pixel point on the screen to obtain the final image.
[0097] Refer to Figure 8 , Figure 8 is the schematic diagram of the spatial fog effect controller proposed in an embodiment of the present application. As Figure 8As shown, the inner radius and outer radius of the fog effect can be set by oneself, so as to adjust the range of the fog effect.
[0098] In the above embodiments of the present application, through the depth map of the scene, the world coordinates of each pixel point are obtained, and then each pixel point is rendered correspondingly according to the range of the fog effect, so as to obtain a smoothly transitioning fog effect, and the range of the fog effect can be flexibly adjusted, and the concentration of the fog can be flexibly manufactured and changed. In some scenes that restore the natural fog effect, such as animations and games, the realistic foggy weather effect can be well restored. In the fields of intelligent driving and intelligent navigation, the redundant objects in the image except the road can be blocked to save computing resources and better allocate the resources of the processor to achieve a better navigation effect.
[0099] Based on the same inventive concept, an embodiment of the present application provides a fog effect generating device. Refer to Figure 9 , Figure 9 FIG. Figure 9 is a schematic diagram of a fog effect generating device 900 proposed in an embodiment of the present application. As shown, the device includes: A depth map acquisition module 901, configured to acquire a depth map corresponding to a target scene; A depth value acquisition module 902, configured to acquire the depth value of each pixel point from the depth map through the normalized coordinates in screen space; A world coordinate determination module 903, configured to determine the world coordinates of each pixel point according to the depth value; A pixel value sampling module 904, configured to acquire the pixel value of the screen image texture and the pixel value of the background sky texture through the normalized coordinates in screen space; A rendering method determination module 905, configured to determine the rendering method corresponding to the pixel point according to the relationship between the world coordinates of each pixel point and a preset fog effect range;
[0100] Optionally, the device further includes: A scene data acquisition module, configured to acquire scene data corresponding to the target scene, where the scene data at least includes the screen image texture, the background sky texture, the inner radius value of the fog effect, the outer radius value of the fog effect, and the screen image depth map texture.
[0101] Optionally, the depth value acquisition module includes: A first pixel point position acquisition sub-module, configured to determine the position of each pixel point in the depth map through the normalized coordinates in screen space; The first pixel sampling sub-module is used to sample each of the pixel points to obtain the depth value of the pixel points.
[0102] Optionally, the world coordinate determination module includes: The homogeneous coordinate determination sub-module is used to obtain the homogeneous coordinates of the built-in screen pixels in the rendering pipeline, and the homogeneous coordinates are obtained according to the depth value; The data point acquisition sub-module is used to obtain the corresponding four-dimensional data points through the homogeneous coordinates, the camera projection, and the inverse matrix of the field of view matrix; The world coordinate determination sub-module is used to divide the four-dimensional data points by the perspective projection auxiliary component of the four-dimensional data points to obtain the world coordinates corresponding to the pixel points.
[0103] Optionally, the pixel value sampling module includes: The second pixel point position acquisition sub-module is used to determine the pixel positions of the screen image texture and the background sky texture according to the normalized coordinates in the screen space; The second pixel point sampling sub-module is used to sample the pixel according to the pixel positions of the screen image texture and the background sky texture to obtain the pixel values of the screen image texture and the background sky texture.
[0104] Optionally, the rendering method determination module includes: The first rendering method determination sub-module is used to determine that the rendering method of the pixel is screen texture rendering when the distance between the world coordinates of the pixel point and the camera is less than the inner fog radius value; The second rendering method determination sub-module is used to determine that the rendering method of the pixel is hybrid rendering when the distance between the world coordinates of the pixel point and the camera is greater than the inner fog radius value and less than the outer fog radius value; The third rendering method determination sub-module is used to determine that the rendering method of the pixel is sky texture rendering when the distance between the world coordinates of the pixel point and the camera is greater than the outer fog radius.
[0105] Optionally, the pixel point rendering module includes: The first pixel point rendering sub-module is used to use the pixel value at the corresponding position in the screen texture image as the pixel value of the pixel point when the rendering method corresponding to the pixel point is screen texture rendering; The second pixel point rendering sub-module is used to obtain the pixel value of the pixel point through a preset blending formula according to the pixel value of the screen image texture and the pixel value of the background sky texture when the rendering method corresponding to the pixel point is hybrid rendering; The third pixel rendering sub-module is configured to use the pixel value at the corresponding position of the background sky texture as the pixel value of the pixel when the rendering method corresponding to the pixel is sky texture rendering.
[0106] Based on the same inventive concept, another embodiment of the present application provides a readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the fog effect generation method as described in any of the above embodiments of the present application.
[0107] Based on the same inventive concept, another embodiment of the present application provides an electronic device Figure 10 is a schematic diagram of an electronic device 1000 proposed in an embodiment of the present application, including a memory 1002, a processor 1001, and a computer program stored on the memory and executable on the processor. When the processor executes, it implements the fog effect generation method as described in any of the above embodiments of the present application.
[0108] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For the relevant parts, refer to the partial description of the method embodiment.
[0109] Each embodiment in this specification is described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other.
[0110] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application can take the form of completely hardware embodiments, completely software embodiments, or embodiments combining software and hardware aspects. Moreover, the embodiments of the present application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.
[0111] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of processes and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing terminal devices to generate a machine, so that the instructions executed by the processors of the computer or other programmable data processing terminal devices generate a device for implementing the specified functions in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0112] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufacture including an instruction device that implements the functions specified in one process or a plurality of processes and / or one block or a plurality of blocks in the flow. Figure 1 one process or a plurality of processes and / or Figure 1 one block or a plurality of blocks.
[0113] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device, such that a series of operation steps are executed on the computer or other programmable terminal device to produce a computer-implemented process. Thus, the instructions executed on the computer or other programmable terminal device provide steps for implementing the functions specified in one process or a plurality of processes and / or one block or a plurality of blocks in the flow. Figure 1 one process or a plurality of processes and / or Figure 1 one block or a plurality of blocks.
[0114] Although the preferred embodiments of the embodiments of the present application have been described, those skilled in the art can make additional changes and modifications once they learn the basic creative concepts. Therefore, the appended claims are intended to be construed to include the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0115] Finally, it should also be noted that in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or terminal device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or terminal device. Without further limitation, an element defined by the statement "comprising one..." does not exclude the presence of additional identical elements in the process, method, article or terminal device comprising the element.
[0116] The above has provided a detailed introduction to the fog effect generation method, device, equipment and storage medium provided by the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation on the present application.
Claims
1. A method for generating a fog effect, characterized in that, The method includes: Obtaining a depth map corresponding to the target scene; Obtaining the depth value of each pixel point from the depth map through the normalized coordinates in screen space; Determining the world coordinates of each pixel point according to the depth value; Obtaining the pixel values of the screen image texture and the pixel values of the background sky texture through the normalized coordinates in screen space; Determining the rendering method corresponding to each pixel point according to the relationship between the world coordinates of each pixel point and a preset fog effect range; Rendering the pixel point in a corresponding manner through the pixel values of the screen image texture and the pixel values of the background sky texture to obtain the fog effect corresponding to the target scene.
2. The fog effect generation method according to claim 1, wherein Before obtaining the depth map corresponding to the target scene, the method further includes: Obtaining the scene data corresponding to the target scene, where the scene data at least includes the screen image texture, the background sky texture, the inner radius value of the fog effect, the outer radius value of the fog effect, and the screen image depth map texture.
3. The fog effect generation method according to claim 1, characterized in that The step of obtaining the depth value of each pixel point from the depth map through the normalized coordinates in screen space includes: Determining the position of each pixel point in the depth map through the normalized coordinates in screen space; 4. The fog effect generation method according to claim 1, wherein Sampling each pixel point to obtain the depth value of the pixel point. The step of determining the world coordinates of each pixel point according to the depth value includes: Obtaining the homogeneous coordinates of the built-in screen pixels in the rendering pipeline, where the homogeneous coordinates are obtained according to the depth value; Obtaining a corresponding four-dimensional data point through the homogeneous coordinates, the camera projection, and the inverse matrix of the view matrix; 5. The fog effect generation method according to claim 1, characterized in that Dividing the four-dimensional data point by the perspective projection auxiliary component of the four-dimensional data point to obtain the world coordinates corresponding to the pixel point. The step of obtaining the pixel values of the screen image texture and the pixel values of the background sky texture through the normalized coordinates in screen space includes: Determining the pixel position of the screen image texture and the pixel position of the background sky texture according to the normalized coordinates in screen space; 6. The fog effect generation method according to claim 1, wherein Sampling the pixel according to the pixel position of the screen image texture and the pixel position of the background sky texture to obtain the pixel values of the screen image texture and the pixel values of the background sky texture. The step of determining the rendering method corresponding to each pixel point according to the relationship between the world coordinates of each pixel point and a preset fog effect range includes: When the distance between the world coordinates of the pixel point and the camera is less than the inner radius value of the fog effect, determining that the rendering method of the pixel is screen texture rendering; When the distance between the world coordinates of the pixel point and the camera is greater than the inner radius value of the fog effect and less than the outer radius value of the fog effect, determining that the rendering method of the pixel is hybrid rendering; 7. The fog effect generation method according to claim 1, wherein When the distance between the world coordinates of the pixel point and the camera is greater than the outer radius of the fog effect, determining that the rendering method of the pixel is sky texture rendering. The step of rendering the pixel in a corresponding manner through the pixel values of the screen image texture and the pixel values of the background sky texture to obtain the fog effect corresponding to the target scene includes: When the rendering method corresponding to the pixel point is screen texture rendering, the pixel value at the corresponding position in the screen texture image is used as the pixel value of the pixel point; When the rendering method corresponding to the pixel point is hybrid rendering, the pixel value of the pixel point is obtained by a preset blending formula based on the pixel value of the screen image texture and the pixel value of the background sky texture; When the rendering method corresponding to the pixel point is sky texture rendering, the pixel value at the corresponding position in the background sky texture is used as the pixel value of the pixel point.
8. A fog effect generating device, characterized in that, The device includes: A depth map acquisition module, configured to acquire a depth map corresponding to a target scene; A depth value acquisition module, configured to acquire the depth value of each pixel point from the depth map through the normalized coordinates in screen space; A world coordinate determination module, configured to determine the world coordinate of each pixel point according to the depth value; A pixel value sampling module, configured to acquire the pixel value of the screen image texture and the pixel value of the background sky texture through the normalized coordinates in screen space; A rendering method determination module, configured to determine the rendering method corresponding to the pixel point according to the relationship between the world coordinate of each pixel point and a preset fog effect range; A pixel point rendering module, configured to perform corresponding rendering on the pixel point through the pixel value of the screen image texture and the pixel value of the background sky texture, to obtain the fog effect corresponding to the target scene.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.