Method, device, equipment and storage medium for realizing fog effect

By calculating the concentration and density of fog, determining the height and distance factors, and controlling the color components of fog effect, the problem of lack of layering of exponentially high fog in the UE engine is solved, and the details and artistic expression of fog effect are achieved.

CN114255184BActive Publication Date: 2025-01-14BEIJING PERFECT WORLD SOFTWARE TECH DEV CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111552651.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-17
Publication Date
2025-01-14
Estimated Expiration
2041-12-17

AI Technical Summary

Technical Problem

In the prior art, the exponentially high fog achieved by the UE engine leads to excessive fog effect in distant objects in large world scenarios, lacking a sense of layering, and it is difficult for artists to adjust the fog effect, and the color control is single, and there is a lack of artistic expression.

Method used

By obtaining the positional relationship between the target point, camera and fog effect starting height, calculate the concentration and density of fog, determine the height factor and distance factor, control the fog effect color component, ensure that the distance factor does not exceed the height factor, and achieve fog effect layering and detail expression.

Benefits of technology

It improves the sense of layering and detailed performance of fog effect, simplifies the fog effect adjustment process, provides quantitative standards, facilitates art debugging, and ensures significant differences in fog effect between close-up and long-range.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114255184B_ABST
    Figure CN114255184B_ABST
Patent Text Reader

Abstract

The present application relates to a method, device, equipment and storage medium for realizing fog effect, the method comprising: obtaining the positional relationship among a target point, a camera and a starting height of the fog effect, and obtaining the concentration of fog and the density of fog based on the positional relationship; determining a height factor based on the density of fog and the concentration of fog; wherein the height factor is positively correlated with the density of fog and the concentration of fog; determining a distance factor based on the height factor, the length of the vector from the target point to the camera and the distance component of the preset fog effect concentration, the maximum value of the distance factor not exceeding the height factor; obtaining the basic fog effect color component of the target point, and mixing the basic color of the target point and the basic fog effect color component based on the distance factor to obtain the color of the target point. The above scheme is used to solve the problem that the high fog expression lacks a sense of hierarchy and that it is difficult for artists to adjust the fog effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of virtual reality technology, and in particular to a method, device, equipment and storage medium for realizing fog effect. Background Art

[0002] Traditional fog effect solutions include: linear fog and exponential fog implemented by the Unity engine, and exponential height fog implemented by the UE engine.

[0003] Exponential height fog, also known as height fog, requires calculating the fog density factor, concentration factor, and distance factor, and finally multiplying the three factors together. The fog density is the index of the height difference between the camera and the fog, the fog concentration is the fitting of the object height index, and the distance factor is an exponential operation on the distance, that is, the higher the camera, the lower the density, the higher the object position, the lower the concentration, and the farther the distance, the greater the concentration.

[0004] In large-scale scenes using height fog, objects far away often have very strong fog effects. For example, although the mountain is very high, the distance factor causes the fog effect at the peak to be the maximum, which is inconsistent with both the real-world and artistic performance. Since height fog is a combination of distance and height, it is difficult for artists to adjust it during use. Often a scene needs to be adjusted repeatedly for a long time, and the adjustment process needs to be repeated after each scene change. There is no quantifiable standard. In addition, the color control of height fog depends only on the color value parameter, resulting in the same fog effect in the near and far views, lacking a sense of hierarchy. Summary of the invention

[0005] The present application provides a fog effect realization method, apparatus, device and storage medium, which are used to solve the problem that the exponential height fog expression realized by the UE engine lacks a sense of hierarchy, and it is difficult for artists to adjust the fog effect.

[0006] In a first aspect, an embodiment of the present application provides a method for realizing a fog effect, including:

[0007] Obtaining the positional relationship among the target point, the camera, and the fog effect starting height, and obtaining the fog concentration and the fog density based on the positional relationship; wherein the increase rate of the fog density decreases as the height difference between the camera and the fog effect starting height increases;

[0008] Determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog;

[0009] Determine a distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration, wherein the maximum value of the distance factor does not exceed the height factor; and

[0010] The basic fog effect color component of the target point is obtained, and based on the distance factor, the basic color of the target point and the basic fog effect color component are mixed to obtain the color of the target point.

[0011] Optionally, the acquiring the positional relationship among the target point, the camera and the fog effect starting height, and acquiring the fog concentration and the fog density based on the positional relationship, includes:

[0012] Obtain the distance component of the vector from the target point to the camera in the vertical direction, and determine the ratio of the distance component to the length of the vector;

[0013] Determining the concentration of fog based on the length ratio and the height component of the preset fog effect concentration; and

[0014] The height difference between the camera and the starting height of the fog effect is obtained, and the density of the fog is determined based on the height difference and the height component of the preset fog effect concentration.

[0015] Optionally, the determining the height factor based on the density of the fog and the concentration of the fog includes:

[0016] A first product of the density of the fog and the concentration of the fog is obtained as the height factor.

[0017] Optionally, determining the fog concentration based on the length ratio and a height component of a preset fog effect concentration includes:

[0018] Obtaining a second product of the length ratio and the height component of the preset fog effect concentration;

[0019] Using the negative of the second product as an exponent and the first preset value as a base to obtain a first exponential power; and

[0020] A first difference between 1 and the first exponential power is obtained, and a ratio of the first difference to the second product is determined as the concentration of the fog.

[0021] Optionally, determining the density of the fog based on the height difference and a height component of a preset fog effect concentration includes:

[0022] Obtaining a third product of the height difference and the height component of the preset fog effect concentration;

[0023] Using the negative number of the third product as an exponent and the second preset value as a base to obtain a second exponential power; and

[0024] The second exponential power is determined as the density of the fog.

[0025] Optionally, determining the distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration includes:

[0026] Obtain a second difference between the length of the vector from the target point to the camera and the fog effect starting distance;

[0027] Obtaining a fourth product of the second difference and the distance component of the preset fog effect concentration;

[0028] Using the negative number of the fourth product as an exponent and the third preset value as a base to obtain a third exponential power;

[0029] Obtaining a third difference between 1 and the third exponential power; and

[0030] According to the third difference, an interpolation operation is performed between 0 and the height factor to obtain the distance factor.

[0031] Optionally, obtaining a basic fog effect color component of the target point includes:

[0032] Based on the relative position relationship between the vector and the fog effect starting distance, and the preset fog effect color, obtaining a first fog effect color component; and

[0033] The angle between the vector and the sun direction is obtained, and according to the angle, an interpolation operation is performed between the first fog effect color component and the sun fog effect color to obtain a second fog effect color component, and the second fog effect color component is used as the basic fog effect color component.

[0034] Optionally, acquiring the first fog effect color component based on the relative position relationship between the vector and the fog effect starting distance, and a preset fog effect color, includes:

[0035] Obtaining a first-layer fog effect starting distance and a second-layer fog effect starting distance; wherein the first-layer fog effect starting distance is the fog effect starting distance;

[0036] Based on the relationship between the vector, the starting distance of the first layer of fog effect, and the starting distance of the second layer of fog effect, obtaining a first layer of fog effect proportion; and

[0037] According to the proportion of the first layer of fog effect, an interpolation operation is performed between the second layer of fog effect color and the first layer of fog effect color to obtain a first fog effect color component.

[0038] Optionally, the mixing, based on the distance factor, the basic color of the target point and the basic fog effect color component to obtain the color of the target point includes:

[0039] The distance factor is used as a first coefficient, and the difference between 1 and the distance factor is used as a second coefficient;

[0040] Obtaining a first product of the first coefficient and the basic fog effect color component;

[0041] Obtaining a second product of the second coefficient and the basic color of the target point; and

[0042] The sum of the first product and the second product is used as the color of the target point.

[0043] In a second aspect, an embodiment of the present application provides a fog effect realization device, including:

[0044] The first processing module is used to obtain the positional relationship between the target point, the camera and the fog effect starting height, and based on the positional relationship, obtain the fog concentration and the fog density; wherein the increase rate of the fog density decreases as the height difference between the camera and the fog effect starting height increases;

[0045] A second processing module, configured to determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog;

[0046] a third processing module, configured to determine a distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration, wherein a maximum value of the distance factor does not exceed the height factor; and

[0047] The fourth processing module is used to obtain the basic fog effect color component of the target point, and based on the distance factor, mix the basic color of the target point and the basic fog effect color component to obtain the color of the target point.

[0048] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a communication bus, wherein the processor and the memory communicate with each other via the communication bus;

[0049] The memory is used to store a computer program; and

[0050] The processor is used to execute the program stored in the memory to implement the fog effect realization method described in the first aspect.

[0051] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the method for realizing the fog effect described in the first aspect is implemented.

[0052] The above-mentioned technical scheme provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application obtains the concentration of fog and the density of fog based on the positional relationship among the target point, the camera and the starting height of the fog effect, and the rate of increase of the density of fog decreases with the increase of the height difference between the camera and the starting height of the fog effect; the height factor is determined based on the density of fog and the concentration of fog, so that the height factor is positively correlated with the density of fog and the concentration of fog; when determining the distance factor based on the height factor, the length of the vector from the target point to the camera and the distance component of the preset fog effect concentration, the maximum value of the distance factor is limited to a range not exceeding the height factor; based on the distance factor, the basic color of the target point and the basic fog effect color component are mixed to obtain the color of the target point.

[0053] By controlling the distance factor used for mixing fog effects not to exceed the height factor, the height factor is used as the maximum concentration scale in the height direction, which facilitates the debugging of fog effects. In addition, since the height factor is positively correlated with the density of fog, the height factor decreases as the height difference between the camera and the starting height of the fog effect increases, thereby improving the layering of the fog effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0055] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0056] Figure 1 A schematic diagram of the system architecture used in the fog effect realization method in the embodiment of the present application;

[0057] Figure 2 This is a flow chart of the fog effect realization method in the embodiment of the present application;

[0058] Figure 3 Schematic diagram of the relative positions of various parameters in the embodiments of the present application;

[0059] Figure 4 This is a schematic diagram of the effect of adding fog effect to the virtual scene in the embodiment of the present application;

[0060] Figure 5 This is a schematic diagram of the effect of exponential height fog implemented by the UE engine in an embodiment of the present application;

[0061] Figure 6This is a schematic diagram of the structure of the fog effect realization device in the embodiment of the present application;

[0062] Figure 7 Schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0063] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0064] In order to solve the problem that the exponential height fog achieved by the UE engine lacks a sense of hierarchy and that it is difficult for artists to adjust the fog effect, a fog effect implementation method is provided in each embodiment of the present application. The fog effect achieved by this method can be applied to volumetric fog, and the fog effect is reflected in the color of each pixel in the virtual picture, such as the brightness value of the pixel. This method can be implemented using the UE engine or other animation engines, and is not limited to the specific animation engine used here.

[0065] The fog effect realization method provided in the embodiment of the present application can be applied to Figure 1 In the hardware environment composed of the terminal 10 and the server 11 shown in FIG. Figure 1 As shown, the server 11 is connected to the terminal 10 via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for the server 11. The above-mentioned network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the terminal 10 is not limited to a PC (Personal Computer), a mobile phone, a tablet computer, etc.

[0066] The fog effect implementation method of the embodiment of the present application can be executed by the server 11, or by the terminal 10, or by both the server 11 and the terminal 10. The terminal 10 executes the fog effect implementation method of the embodiment of the present application, or the client installed thereon.

[0067] Based on the same concept, the fog effect realization method provided in the embodiment of the present application is as follows: Figure 2 As shown, it mainly includes the following steps:

[0068] Step 201, obtain the positional relationship between the target point, the camera and the starting height of the fog effect, and based on the positional relationship, obtain the concentration of the fog and the density of the fog; wherein the increase rate of the density of the fog decreases as the height difference of the camera relative to the starting height of the fog effect increases.

[0069] The target point refers to any one or a group of pixels in the virtual image to which fog effect needs to be added.

[0070] The camera refers to the viewpoint position of the virtual image where the fog effect needs to be added.

[0071] The fog effect starting height may be a pre-configured fog effect parameter.

[0072] In a specific embodiment, the positional relationship among the target point, the camera and the fog effect starting height is obtained, and the concentration and density of the fog is obtained based on the positional relationship, including: obtaining the distance component of the vector from the target point to the camera in the vertical direction, and determining the ratio of the distance component to the length of the vector; determining the concentration of the fog based on the length ratio and the height component of the preset fog effect concentration; and obtaining the height difference of the camera relative to the fog effect starting height, and determining the density of the fog based on the height difference and the height component of the preset fog effect concentration. Figure 3 As shown, point A represents the target point, point B represents the position of the camera, the component of the AB vector in the vertical axis (y-axis) direction is used as the distance component AO of the vector in the vertical direction, and the height difference of the camera B relative to the starting height y1 of the fog effect is represented as C.

[0073] Based on the distance component of the vector from the target point to the camera in the vertical direction, the fog effect density is determined so that the determined fog effect density can reflect the height of the target point. In addition, based on the height difference of the camera relative to the starting height of the fog effect, the fog density is determined so that the determined fog effect density can reflect the position of the camera in the fog effect.

[0074] In a specific embodiment, determining the fog concentration based on the length ratio and the height component of the preset fog effect concentration includes: obtaining a second product of the length ratio and the height component of the preset fog effect concentration; using the negative of the second product as an exponent and a first preset value as a base to obtain a first exponential power; and obtaining a first difference between 1 and the first exponential power, and determining the ratio of the first difference to the second product as the fog concentration.

[0075] The calculation function of fog concentration is expressed as:

[0076]

[0077] Wherein, y represents the concentration of fog, x represents the length ratio, f represents the height component of the preset fog effect concentration, and 2 is the first preset value. It should be noted that 2 is used as the base here only as an example, and other values ​​can also be used as the base. Calculating the fog concentration by fitting the function can simplify the calculation process and improve the rendering efficiency of the fog effect during the rendering process.

[0078] In a specific embodiment, determining the density of the fog based on the height difference and the height component of the preset fog effect concentration includes: obtaining a third product of the height difference and the height component of the preset fog effect concentration; using the negative of the third product as an exponent and a second preset value as a base to obtain a second exponential power; and determining the second exponential power as the density of the fog.

[0079] Among them, the height component of the preset fog effect concentration is a parameter of the pre-configured fog effect.

[0080] The second preset value may be e. It should be noted that taking e as the base here is only an example, and other values ​​may also be used as the base.

[0081] Step 202: Determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog.

[0082] In a specific embodiment, determining the height factor based on the density of the fog and the concentration of the fog includes: obtaining a first product of the density of the fog and the concentration of the fog as the height factor.

[0083] Among them, if the distance component of the vector from the target point to the camera in the vertical direction accounts for zero in the length of the vector, the fog density is equal to 1; if the length ratio is not equal to zero, the fog density is greater than zero and less than 1. The length ratio is equal to zero, that is, the vector from the target point to the camera is in the horizontal direction, and there is no vertical component, that is, when the target point and the camera are at the same height position, the height factor is equal to the density of the fog, and the height factors are the same at the same height position.

[0084] Specifically, assuming that the target point is represented by worldPos, the position coordinates of the target point are represented by worldPos.xyz, the position coordinates of the camera are represented by WorldSpaceCameraPos, the starting height of the fog effect is represented by FogInfo.y, and the vector from the unmarked point to the camera is represented by viewDir, then the vector from the target point to the camera can be expressed as the formula:

[0085] viewDir=worldPos.xyz-WorldSpaceCameraPos;

[0086] The length of the vector from the target point to the camera is expressed as dist, and the formula is expressed as:

[0087] dist = length (viewDir), where length is a function used to calculate the length of a vector. If the value of dist obtained by this function is greater than 0, the target point should fall within the camera's viewing cone.

[0088] The vertical distance component of the vector from the target point to the camera is represented as viewDir.y, and the ratio of the distance component to the length of the vector from the target point to the camera is represented as viewDirY, which is expressed as:

[0089] viewDirY = viewDir.y / dist;

[0090] Assume that the height factor is defined as heightFogFactor, and the function used to calculate the height factor is expressed as ComputeHeightFactor(). The calling parameter of the function is viewDirY, which is expressed as:

[0091] heightFogFactor = saturate(ComputeHeightFactor(viewDirY)); saturate(x) is used to constrain the value of x to the range of 0 to 1, that is, to constrain the value of the height factor to the range of 0 to 1;

[0092] The implementation of the ComputeHeightFactor(viewDirY) function is as follows:

[0093] Assume that the height component of fog effect concentration is represented by FogInfo.w. If FogInfo.w is equal to 0, then exit the function. That is, in this case, there is no height component of fog effect concentration, and there is no difference in fog effect at height, and no need to continue calculation.

[0094] If FogInfo.w is not equal to 0, define the height difference between the camera and the starting height of the fog effect as height = max(0, WorldSpaceCameraPos.y-FogInfo.y) / 300.0; where 300 is the sparse factor, which thins the unit from 1 to 300. Other sparse factors can also be used as needed;

[0095] Define the density of fog heightFogFactor1 = exp(-FogInfo.w*height), where exp represents exponential operation, through which the rate of change of fog density tends to be flat as the height difference increases;

[0096] When viewDirY is equal to 0, that is, when the viewing angle is horizontal, the maximum concentration of fog is 1, and the height factor heightFogFactor = the density of fog heightFogFactor1;

[0097] When viewDirY is not equal to 0, that is, when the viewing angle is not horizontal, the concentration of fog is expressed as follows:

[0098] (1-exp(-FogInfo.w*viewDirY)) / (FogInfo.w*viewDirY); the concentration of fog changes exponentially with the height of viewDirY;

[0099] In this case, the height factor heightFogFactor = heightFogFactor1*(1-exp(-FogInfo.w*viewDirY)) / (FogInfo.w*viewDirY), that is, the density of fog*the concentration of fog;

[0100] return heightFogFactor; the ComputeHeightFactor(viewDirY) function runs to the end.

[0101] The height factor calculated by this process changes exponentially with the vertical height of the target point.

[0102] Step 203, determining a distance factor based on the height factor, the length of the vector from the target point to the camera, and the distance component of the preset fog effect concentration, wherein the maximum value of the distance factor does not exceed the height factor.

[0103] In a specific embodiment, the distance factor is determined based on the height factor, the length of the vector from the target point to the camera, and the distance component of the preset fog effect concentration, including: obtaining a second difference between the length of the vector from the target point to the camera and the starting distance of the fog effect; obtaining a fourth product of the second difference and the distance component of the preset fog effect concentration; using the negative of the fourth product as the exponent and the third preset value as the base to obtain a third exponential power; obtaining a third difference between 1 and the third exponential power; and performing an interpolation operation between 0 and the height factor according to the third difference to obtain the distance factor.

[0104] Among them, the distance component of the fog effect concentration and the fog effect starting distance are pre-configured fog effect parameters.

[0105] Specifically, assuming that the distance component of the fog effect concentration is FogInfo.z, the distance factor is represented by distanceFogFactor, and the fog effect starting distance is represented by FogInfo.x, the calculation process of the distance factor is as follows:

[0106] dist=max(dist-FogInfo.x,0) / 300.0; This calculation is mainly to obtain the effective vector length starting from the fog effect starting distance in the vector distance from the target point to the camera;

[0107] distanceFogFactor=lerp(0,heightFogFactor,1-exp(-FogInfo.z*dist));

[0108] Among them, lerp is the interpolation function.

[0109] In the process of calculating the distance factor, the height factor is used as the maximum concentration scale of the fog effect at the vertical height. For example, at an altitude of 100 meters, the fog concentration at this height is calculated to be 0.8 according to the parameter variable. Then, the concentration of the fog effect increases from 0 to 0.8 from near to far in the vertical distance and then shows a decaying trend. The fog effect concentration can be controlled by controlling the distance factor, avoiding the problem that the exponential height fog achieved by the UE engine has too large a fog effect intensity at a distance, which affects the fog effect concentration at both height and distance, making it easier for art staff to control the fog effect concentration.

[0110] In this embodiment, the effect of distance is simulated by using a transmission function, so that the distance factor can conform to the attenuation mode of light, rather than being linear, so that a more realistic fog effect can be simulated by the distance factor. In the calculation process of the distance factor, the height factor is used to limit the maximum value of the distance factor, so that the distance factor does not continue to increase with the increase of the height of the target point, so that the fog effect based on the distance factor can be more layered, and the fog effects of the near view and the far view are different.

[0111] Step 204 , obtaining a basic fog effect color component of the target point, and mixing the basic color of the target point and the basic fog effect color component based on the distance factor to obtain the color of the target point.

[0112] In a specific embodiment, obtaining the basic fog effect color component of the target point includes: obtaining a first fog effect color component based on the relative position relationship between the vector and the fog effect starting distance, and a preset fog effect color; and obtaining the angle between the vector and the sun direction, and performing an interpolation operation between the first fog effect color component and the sun fog effect color according to the angle to obtain a second fog effect color component, and using the second fog effect color component as the basic fog effect color component.

[0113] Sun direction refers to the direction of the sun that is pre-configured in the virtual scene.

[0114] Among them, in order to enrich the sense of hierarchy of fog effect color, two layers of fog effect can be set, the first layer of fog effect is used as the basic fog, and the second layer of fog effect highlights the sense of hierarchy on the basis of the first layer of fog effect, referred to as bilinear fog. Specifically, based on the relative position relationship between the vector and the fog effect starting distance, and the preset fog effect color, the first fog effect color component is obtained, including: obtaining the first layer of fog effect starting distance, and the second layer of fog effect starting distance; based on the relationship between the vector, the first layer of fog effect starting distance and the second layer of fog effect starting distance, the first layer of fog effect proportion is obtained; and according to the first layer of fog effect proportion, the second layer of fog effect color and the first layer of fog effect color are interpolated to obtain the first fog effect color component. The first layer of fog effect starting distance is the fog effect starting distance.

[0115] Assuming that the starting distance of the first layer of fog effect is represented by FogInfo.x, and the starting distance of the second layer of fog effect is represented by SecondStart, the calculation process of the first layer of fog effect ratio nearFogFactor is expressed as follows:

[0116] nearFogFactor=saturate((SecondStart-dist) / (SecondStart-FogInfo.x));

[0117] Wherein, dist = length (viewDir); saturate refers to a saturation operation, which is used to constrain the range between 0 and 1;

[0118] Assuming that the first fog effect color is represented by FirstFogColor and the second fog effect color is represented by SecondFogColor, the calculation process of the first fog effect color component fogColor is expressed as follows:

[0119] fogColor=lerp(SecondFogColor, FirstFogColor, fogFactor.y).

[0120] Assume that the second fog color component is represented by distanceFogColor, the sun fog color is represented by SunFogColor, the sun direction is represented by lightDir, and the angle between the vector from the target point to the camera and the sun direction is represented by lightFactor. The calculation process of the angle is expressed as follows:

[0121] lightFactor = saturate(-dot(viewDir, lightDir)); saturate refers to the saturation operation, which is used to constrain the range between 0 and 1; dot means dot multiplication operation;

[0122] The calculation process of the second fog effect color component is expressed as:

[0123] distanceFogColor=lerp(fogColor,SunFogColor,pow(lightFactor,8));

[0124] Among them, lerp represents interpolation operation, and pow represents exponential operation, which is used to calculate the 8th power of lightFactor. The exponential operation is used to achieve the purpose of attenuation to reduce the difference in the interpolation process. It should be noted that 8 can be adjusted to other values ​​as needed.

[0125] In a specific embodiment, the basic color of the target point and the basic fog effect color component are mixed based on the distance factor to obtain the color of the target point, including: taking the distance factor as the first coefficient, and taking the difference between 1 and the distance factor as the second coefficient; obtaining a first product of the first coefficient and the basic fog effect color component; obtaining a second product of the second coefficient and the basic color of the target point; and taking the sum of the first product and the second product as the color of the target point.

[0126] Assuming that the color of the target point obtained by mixing is represented as output, and the base color of the target point is represented as color, the calculation process of mixing is expressed as:

[0127] output=color*(1-distanceFogFactor)+distanceFogColor*distanceFogFactor.

[0128] Based on the implementation process described above, the effect of adding fog effect to the virtual scene is as follows: Figure 4 Compared with the exponential height fog implemented by UE engine, the effect is as follows Figure 5 As shown, it can be seen that in the fog effect achieved by the fog effect implementation method provided in the embodiment of the present application, the distant scenery has more details, has obvious changes in the vertical direction, and has a more three-dimensional and layered feel, rather than a single fog effect with the densest fog at the highest position.

[0129] The method provided in the embodiment of the present application obtains the concentration of fog and the density of fog based on the positional relationship among the target point, the camera and the starting height of the fog effect. The rate of increase of the density of fog decreases with the increase of the height difference between the camera and the starting height of the fog effect. The height factor is determined based on the density of fog and the density of fog, so that the height factor is positively correlated with the density of fog and the concentration of fog. When determining the distance factor based on the height factor, the length of the vector from the target point to the camera and the distance component of the preset fog effect concentration, the maximum value of the distance factor is limited to a range not exceeding the height factor. Based on the distance factor, the basic color of the target point and the basic fog effect color component are mixed to obtain the color of the target point.

[0130] By controlling the distance factor used for mixing fog effects not to exceed the height factor, the height factor is used as the maximum concentration scale in the height direction, which facilitates the debugging of fog effects. In addition, since the height factor is positively correlated with the density of fog, the height factor decreases as the height difference between the camera and the starting height of the fog effect increases, thereby improving the layering of the fog effect.

[0131] Based on the same concept, a fog effect realization device is provided in the embodiment of the present application. The specific implementation of the device can be found in the description of the method embodiment part, and the repeated parts will not be repeated. Figure 6 As shown, the device mainly includes:

[0132] The first processing module 601 is used to obtain the positional relationship between the target point, the camera and the fog effect starting height, and based on the positional relationship, obtain the fog concentration and the fog density; wherein the increase rate of the fog density decreases as the height difference between the camera and the fog effect starting height increases;

[0133] A second processing module 602 is used to determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog;

[0134] A third processing module 603 is used to determine a distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration, wherein the maximum value of the distance factor does not exceed the height factor; and

[0135] The fourth processing module 604 is used to obtain the basic fog effect color component of the target point, and mix the basic color of the target point and the basic fog effect color component based on the distance factor to obtain the color of the target point.

[0136] Based on the same concept, an electronic device is also provided in the embodiment of the present application, such as Figure 7As shown, the electronic device mainly includes: a processor 701, a memory 702 and a communication bus 703, wherein the processor 701 and the memory 702 communicate with each other through the communication bus 703. The memory 702 stores a program that can be executed by the processor 701, and the processor 701 executes the program stored in the memory 702 to implement the following steps:

[0137] Obtaining the positional relationship among the target point, the camera, and the fog effect starting height, and obtaining the fog concentration and the fog density based on the positional relationship; wherein the increase rate of the fog density decreases as the height difference between the camera and the fog effect starting height increases;

[0138] Determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog;

[0139] Determine a distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration, wherein the maximum value of the distance factor does not exceed the height factor; and

[0140] The basic fog effect color component of the target point is obtained, and based on the distance factor, the basic color of the target point and the basic fog effect color component are mixed to obtain the color of the target point.

[0141] The communication bus 703 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus 703 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0142] The memory 702 may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Alternatively, the memory may also be at least one storage device located away from the processor 701.

[0143] The above-mentioned processor 701 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc., and can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0144] In another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed on a computer, the computer executes the fog effect realization method described in the above embodiment.

[0145] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instruction is loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instruction is transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integration. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape, etc.), an optical medium (e.g., a DVD) or a semiconductor medium (e.g., a solid-state hard disk), etc.

[0146] It should be noted that, in this article, 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 such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0147] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for realizing fog effect, comprising: Obtaining the positional relationship among the target point, the camera, and the fog effect starting height, and obtaining the fog concentration and the fog density based on the positional relationship; wherein the increase rate of the fog density decreases as the height difference between the camera and the fog effect starting height increases; Determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog; Determine a distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration, wherein the maximum value of the distance factor does not exceed the height factor; and The basic fog effect color component of the target point is obtained, and based on the distance factor, the basic color of the target point and the basic fog effect color component are mixed to obtain the color of the target point.

2. The method for realizing fog effect according to claim 1, characterized in that: The obtaining of the positional relationship among the target point, the camera and the fog effect starting height, and obtaining the fog concentration and the fog density based on the positional relationship, includes: Obtain the distance component of the vector from the target point to the camera in the vertical direction, and determine the ratio of the distance component to the length of the vector; Determining the concentration of fog based on the length ratio and the height component of the preset fog effect concentration; and The height difference between the camera and the starting height of the fog effect is obtained, and the density of the fog is determined based on the height difference and the height component of the preset fog effect concentration.

3. The method for realizing fog effect according to claim 1, characterized in that: The determining of the height factor based on the density of the fog and the concentration of the fog comprises: A first product of the density of the fog and the concentration of the fog is obtained as the height factor.

4. The method for realizing fog effect according to claim 2, characterized in that: The determining of the fog concentration based on the length ratio and the height component of the preset fog effect concentration includes: Obtaining a second product of the length ratio and the height component of the preset fog effect concentration; Using the negative of the second product as an exponent and the first preset value as a base to obtain a first exponential power; and A first difference between 1 and the first exponential power is obtained, and a ratio of the first difference to the second product is determined as the concentration of the fog.

5. The method for realizing fog effect according to claim 2, characterized in that: The step of determining the density of fog based on the height difference and the height component of the preset fog effect concentration includes: Obtaining a third product of the height difference and the height component of the preset fog effect concentration; Using the negative number of the third product as an exponent and the second preset value as a base to obtain a second exponential power; and The second exponential power is determined as the density of the fog.

6. The method for realizing fog effect according to any one of claims 1 to 5, characterized in that: The determining of the distance factor based on the height factor, the length of the vector from the target point to the camera, and the distance component of the preset fog effect concentration includes: Obtain a second difference between the length of the vector from the target point to the camera and the fog effect starting distance; Obtaining a fourth product of the second difference and the distance component of the preset fog effect concentration; Using the negative number of the fourth product as an exponent and the third preset value as a base to obtain a third exponential power; Obtaining a third difference between 1 and the third exponential power; and According to the third difference, an interpolation operation is performed between 0 and the height factor to obtain the distance factor.

7. The method for realizing fog effect according to any one of claims 1 to 5, characterized in that: The obtaining of the basic fog effect color component of the target point includes: Based on the relative position relationship between the vector and the fog effect starting distance, and the preset fog effect color, obtaining a first fog effect color component; and The angle between the vector and the sun direction is obtained, and according to the angle, an interpolation operation is performed between the first fog effect color component and the sun fog effect color to obtain a second fog effect color component, and the second fog effect color component is used as the basic fog effect color component.

8. The method for realizing fog effect according to claim 7, characterized in that: The obtaining a first fog effect color component based on the relative position relationship between the vector and the fog effect starting distance and a preset fog effect color includes: Obtaining a first-layer fog effect starting distance and a second-layer fog effect starting distance; wherein the first-layer fog effect starting distance is the fog effect starting distance; Based on the relationship between the vector, the starting distance of the first layer of fog effect, and the starting distance of the second layer of fog effect, obtaining a first layer of fog effect proportion; and According to the proportion of the first layer of fog effect, an interpolation operation is performed between the second layer of fog effect color and the first layer of fog effect color to obtain a first fog effect color component.

9. The method for realizing fog effect according to any one of claims 1 to 5, characterized in that: The step of mixing the basic color of the target point and the basic fog effect color component based on the distance factor to obtain the color of the target point includes: The distance factor is used as a first coefficient, and the difference between 1 and the distance factor is used as a second coefficient; Obtaining a first product of the first coefficient and the basic fog effect color component; Obtaining a second product of the second coefficient and the basic color of the target point; and The sum of the first product and the second product is used as the color of the target point.

10. A fog effect realization device, comprising: The first processing module is used to obtain the positional relationship between the target point, the camera and the fog effect starting height, and based on the positional relationship, obtain the fog concentration and the fog density; wherein the increase rate of the fog density decreases as the height difference between the camera and the fog effect starting height increases; A second processing module, configured to determine a height factor based on the density of the fog and the concentration of the fog; wherein the height factor is positively correlated with the density of the fog and the concentration of the fog; a third processing module, configured to determine a distance factor based on the height factor, the length of the vector from the target point to the camera, and a distance component of a preset fog effect concentration, wherein a maximum value of the distance factor does not exceed the height factor; and The fourth processing module is used to obtain the basic fog effect color component of the target point, and based on the distance factor, mix the basic color of the target point and the basic fog effect color component to obtain the color of the target point.

11. An electronic device, comprising: A processor, a memory and a communication bus, wherein the processor and the memory communicate with each other via the communication bus; The memory is used to store a computer program; and The processor is used to execute the program stored in the memory to implement the fog effect realization method according to any one of claims 1 to 9.

12. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the fog effect realization method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Haze monitoring method based on computer vision

    CN103218622A

  • Open GL-based atomization method and system

    CN106023294A