CN110097627B - Method and device for treating fog effect - Google Patents

Method and device for treating fog effect Download PDF

Info

Publication number
CN110097627B
CN110097627B CN201910239648.7A CN201910239648A CN110097627B CN 110097627 B CN110097627 B CN 110097627B CN 201910239648 A CN201910239648 A CN 201910239648A CN 110097627 B CN110097627 B CN 110097627B
Authority
CN
China
Prior art keywords
fog
attenuation factor
color
height
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910239648.7A
Other languages
Chinese (zh)
Other versions
CN110097627A (en
Inventor
范羽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN201910239648.7A priority Critical patent/CN110097627B/en
Publication of CN110097627A publication Critical patent/CN110097627A/en
Application granted granted Critical
Publication of CN110097627B publication Critical patent/CN110097627B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/003D [Three Dimensional] image rendering
    • G06T15/50Lighting effects
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02ATECHNOLOGIES FOR ADAPTATION TO CLIMATE CHANGE
    • Y02A90/00Technologies having an indirect contribution to adaptation to climate change
    • Y02A90/10Information and communication technologies [ICT] supporting adaptation to climate change, e.g. for weather forecasting or climate simulation

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Graphics (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)

Abstract

The embodiment of the invention provides a fog effect processing method and device, which are characterized in that a distance attenuation factor and a height attenuation factor of an object are obtained; obtaining an attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor; obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera; obtaining a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist; obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object; and obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high fog, thereby improving the fog effect.

Description

Method and device for treating fog effect
Technical Field
The embodiment of the invention relates to the field of computer graphics, in particular to a fog effect processing method and device.
Background
The fog effect is extremely important in game development, and particularly in a three-dimensional game scene with strong practicality, a good environmental atmosphere can be manufactured.
At present, in game development, the main research points of fog effect are a fog effect attenuation curve and a fog effect and original scene object mixing mode. The mainstream mobile terminal fog effect solutions include linear fog, exponential fog and the like. The linear fog has high running efficiency, and can interpolate a distant object to a specific color according to the distance. The fog effect mixing scheme mainly comprises linear interpolation, wherein a scene original object and fog effect colors are mixed through an interpolation factor, and when the distance is longer, the color of a pixel point is more biased to the fog effect color; the closer the distance, the more the color of the pixel point is biased to the color of the original object.
However, using the existing linear fog attenuation factor, the fog effect is achieved through a linear interpolation mode, so that a fog effect is easy to cause, and the fog effect is poor.
Disclosure of Invention
The embodiment of the invention provides a fog effect processing method and device, which are used for improving the fog effect.
In a first aspect, an embodiment of the present invention provides a method for treating fog effects, including:
acquiring a distance attenuation factor and a height attenuation factor of an object;
obtaining an attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor;
obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera;
obtaining a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist;
obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object;
and obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high-altitude fog.
Further, the acquiring the distance attenuation factor and the height attenuation factor of the object includes:
acquiring a distance attenuation factor of the object according to the distance difference between the vertex position of the object and the camera position;
and acquiring the height attenuation factor of the object according to the height of the vertex of the object in world space.
Further, the obtaining the distance attenuation factor of the object according to the distance difference between the vertex position and the camera position of the object includes:
according to the formula
Figure GDA0004241640560000021
Acquiring a linear attenuation factor of the object;
where linear_fac is the Linear attenuation factor of the object, distance is the distance between the vertex position and the camera position of the object, fog_begin is the distance between the position of the start of fog and the camera position, fog_end is the distance between the position of the end of fog and the camera position, 0.0f is floating point number 0,1.0f is floating point number 1, the function of the clamp (value, min, max) functions to limit the value of the input value to the range of [ min, max ], and if the value of value is between the value of min and the value of max, return the value of value; if the value of value is greater than the value of max, returning the value of max; if the value of value is less than the value of min, returning the value of min;
obtaining a distance attenuation factor of the object according to the formula dist_fac=pow (max (1-exp (-linear_fac) 0), 1.2 f);
wherein Dist_fac is the distance attenuation factor of the object, linear_fac is the Linear attenuation factor of the object, 1.2f is floating point number 1.2, exp (x) function functions to return an exponential function value based on e and exponential with x, max (x, y) function functions to return the maximum of x, y, and pow (x, y) function functions to return the y-th power of x.
Further, the obtaining the height attenuation factor of the object according to the height of the vertex of the object in world space comprises:
according to the formula
Figure GDA0004241640560000022
A height attenuation factor of the object is acquired,
where fog_height_current is the Height attenuation factor of the object, pos_world is the Height of the object in world space, fog_height_begin is the Height of the position where the Height Fog starts in world space, and fog_height_end is the Height of the position where the Height Fog ends in world space.
Further, the step of obtaining an exponential high-altitude fog attenuation factor according to the distance attenuation factor and the high-altitude attenuation factor comprises the following steps:
according to the formula fog_current=fog_height_current_dist_fac, the attenuation factor of the exponential high-intensity mist is obtained,
where fog_count is the attenuation factor of the exponential Height haze, fog_height_count is the Height attenuation factor of the object, and dist_fac is the distance attenuation factor of the object.
Further, the method for obtaining the attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the view angle of the camera comprises the following steps:
obtaining a direction vector of the target parallel light according to the formula light_dir_n=light_dir_dir_scan_pow;
wherein light_dir_n is a direction vector of the target parallel light, light_dir is a direction vector of the parallel light, dir_scan_pow is a scattering range of the parallel light;
obtaining a direction vector of a view angle of the camera according to the formula ray_dir=normal (pos_world_xyz-u_camera_position;
wherein ray_dir is a direction vector of a view angle of the camera, pos_world. Xyz is coordinates of the object in world space, and u_camera_position. Xyz is coordinates of the camera in world space; the function of the normal (x) function is to normalize the input vector x;
according to the formula sun_amout=aperture (dot (light_dir_n)). Dist_fac, the attenuation factor of the directional scattering mist is obtained;
where sun_amout is the attenuation factor of the directional scattering mist, ray_dir is the direction vector of the view angle of the camera, light_dir_n is the direction vector of the target parallel light, dist_fac is the distance attenuation factor of the object, the function of dot (x, y) is to return the dot product of the two vectors x and y, and the function of the saturation (x) is to limit the input value x to between [ 01 ].
Further, the obtaining the target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist comprises the following steps:
according to the formula final_scanner_color=lerp (atm_inscator, dir_inscator, sun_amounto), the target color of the directional scattering mist is obtained,
wherein final_scatter_color is the target color of the directional scattering mist, atm os_indicator is the initial color of the atmospheric mist, dir_indicator is the initial color of the directional scattering mist, sun_current is the attenuation factor of the directional scattering mist, the function of lerp (a, b, t) is to interpolate between colors a and b by t, t is a value between 0 and 1, and color a is returned when t is 0; the color b is returned when t is 1.
Further, obtaining a target color of the index-height mist according to the attenuation factor of the index-height mist and the color of the object, including:
according to the formula final_height_fog=lerp (raw_color, fog_color, fog_current), the target color of the exponential high haze is obtained,
wherein final_height_fog is the target color of the index-height Fog, raw_color is the color of the object, fog_color is the color of the index-height Fog, and fog_current is the attenuation factor of the index-height Fog.
Further, the obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high fog comprises the following steps:
according to color_with_fog=final_height_fog+final_color_color, the target haze color of the object is obtained,
wherein color_with_fog is the target haze color of the object, final_height_fog is the target color of the exponential height haze, and final_color is the target color of the directional scattering haze.
In a second aspect, an embodiment of the present invention provides an apparatus for treating fog effects, including:
the acquisition module is used for acquiring the distance attenuation factor and the height attenuation factor of the object;
the processing module is used for obtaining the attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor;
the processing module is also used for obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera;
the processing module is further used for obtaining the target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist;
the processing module is further used for obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object;
the processing module is further used for obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high-altitude fog.
In a third aspect, an embodiment of the present invention provides an electronic terminal, which is characterized by including a memory and a processor, where the processor executes program instructions in the memory, and is configured to implement a method for processing fog effects in any one of the first aspects.
In a fourth aspect, an embodiment of the present invention provides a storage medium, where the storage medium is configured to store a computer program, where the computer program is configured to implement a method for processing fog effects according to any one of the first aspects.
The method and the device for processing the fog effect provided by the embodiment of the invention acquire the distance attenuation factor and the height attenuation factor of the object; obtaining an attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor; obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera; obtaining a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist; obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object; according to the target color of the directional scattering fog and the target color of the index high fog, the target fog effect color of the object is obtained, and as the fog effects of the index high fog, the atmosphere fog and the directional scattering fog are considered, the distance attenuation factor and the height attenuation factor are considered when the colors of the index high fog and the atmosphere fog are obtained, so that the fog effect is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions of the prior art, the drawings that are needed in the embodiments or the description of the prior art will be briefly described below, it will be obvious that the drawings in the following description are some embodiments of the present invention, and that other drawings can be obtained according to these drawings without inventive effort to a person skilled in the art.
FIG. 1 is a schematic flow chart of a method for treating fog effects according to an embodiment of the present invention;
FIG. 2 is a flow chart of another method for treating mist effect according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an apparatus for treating fog effects according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic terminal according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The terms "first," "second," "third," "fourth" and the like in the description and in the claims and in the above drawings, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented, for example, in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
According to the embodiment of the invention, the fog effects of the index high-altitude fog, the atmospheric fog and the directional scattering fog are considered, and meanwhile, when the colors of the index high-altitude fog and the atmospheric fog are obtained, the distance attenuation factor and the height attenuation factor are considered, so that the fog effect is improved.
The technical scheme of the invention is described in detail below by specific examples. The following embodiments may be combined with each other, and some embodiments may not be repeated for the same or similar concepts or processes.
Fig. 1 is a flow chart of a method for treating fog effect according to an embodiment of the present invention, as shown in fig. 1, the method of the present embodiment may include:
s101, acquiring a distance attenuation factor and a height attenuation factor of the object.
In general, the more distant an object is from the camera position, the more severely it is affected by fog. Meanwhile, the fog effect has a certain relation with the height of the object in the world space, and the density of the fog is higher as the object is closer to the ground, the influence of the fog effect is more serious.
S102, obtaining the attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor.
The attenuation factor of the exponential high-altitude fog is related to the distance and the altitude, and is obtained through the distance attenuation factor and the altitude attenuation factor.
S103, obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera.
The directional scattering fog refers to a part of parallel light affecting fog effect, wherein the parallel light refers to sunlight, lamplight of a street lamp and the like.
S104, obtaining the target color of the directional scattering fog according to the initial color of the atmospheric fog, the initial color of the directional scattering fog and the attenuation factor of the directional scattering fog.
The initial color of the atmospheric fog and the initial color of the directional scattering fog are adjustable interface parameters of the fog effect system. Atmospheric haze is an optical phenomenon of Rayleigh scattering, and directional scattering haze is mainly part of sunlight affecting fog effect.
S105, obtaining the target color of the index-height fog according to the attenuation factor of the index-height fog and the color of the object.
S106, obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high-altitude fog.
In general, the fogging effect is divided into three parts: index high haze, atmospheric haze, directional scattering haze. And obtaining the target fog color of the object according to the fog colors of the three parts and the color of the object.
In the embodiment, the distance attenuation factor and the height attenuation factor of the object are obtained; obtaining an attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor; obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera; obtaining a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist; obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object; according to the target color of the directional scattering fog and the target color of the index high fog, the target fog effect color of the object is obtained, and the combination of the fog effect colors of the index high fog, the atmosphere fog and the directional scattering fog and the object color is considered to obtain the target fog effect color of the object, and meanwhile, when the colors of the index high fog and the atmosphere fog are obtained, the distance attenuation factor and the height attenuation factor are considered, so that the fog effect is improved.
Fig. 2 is a flow chart of another method for treating fog effects according to an embodiment of the present invention, and fig. 2 is a description of a specific implementation of the method shown in fig. 1 based on the embodiment shown in fig. 1, as shown in fig. 2:
s201, acquiring a distance attenuation factor of the object according to the distance difference between the vertex position of the object and the camera position.
One possible implementation is as follows:
and (3) acquiring a linear attenuation factor of the object according to the formula (1), and then acquiring a distance attenuation factor of the object according to the linear attenuation factor of the object and the formula (2).
Equation (1) is a conventional equation for linear mist, as follows:
Figure GDA0004241640560000081
where linear_fac is the Linear attenuation factor of the object, distance is the distance difference between the vertex position and the camera position of the object, fog_begin is the distance between the position where fog starts and the camera position, fog_end is the distance between the position where fog ends and the camera position, 0.0f is floating point number 0,1.0f is floating point number 1, the function of the clamp (value, min, max) functions to limit the value of the input value to the range of [ min, max ], and if the value of the value is between the value of min and the value of max, the value of the value is returned; if the value of value is greater than the value of max, returning the value of max; if the value of value is less than the value of min, the value of min is returned. fog_begin, fog_end are interface parameters that the fog effect system can adjust.
Equation (2) remaps the linear attenuation factor using the exponential fog equation as follows:
Dist_fac=pow(max(1-exp(-Linear_fac*2),0),1.2f) (2)
wherein Dist_fac is a distance attenuation factor of an object, linear_fac is a Linear attenuation factor of the object obtained according to formula (1), 1.2f is a floating point number 1.2, exp (x) functions are used for returning an exponential function value with e as a base and x as an index, max (x, y) functions are used for returning the maximum value in x, y, and pow (x, y) functions are used for returning the y-th power of x.
S202, acquiring a height attenuation factor of the object according to the height of the vertex of the object in world space.
One possible implementation is: the height attenuation factor of the object is obtained according to the following formula (3).
Figure GDA0004241640560000082
Equation (3) is also a conventional equation for linear fog. Where fog_height_current is the Height attenuation factor of the object, pos_world. Y is the Height of the object in world space, fog_height_begin is the Height of the position where the Height Fog starts in world space, and fog_height_end is the Height of the position where the Height Fog ends in world space. The fog_height_begin and the fog_height_end are interface parameters which can be adjusted by the fog effect system.
S203, obtaining the attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the altitude attenuation factor.
One possible implementation is: the height attenuation factor of the object is obtained according to the following formula (4).
Fog_amount=Fog_Height_amount*Dist_fac (4)
Where Fog_current is the attenuation factor of the exponential Height haze, fog_height_current is the Height attenuation factor of the object, dist_fac is the distance attenuation factor of the object.
S204, obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera.
One possible implementation is as follows:
obtaining a direction vector of the target parallel light according to a formula (5); obtaining a direction vector of a view angle of the camera according to a formula (6); and (3) obtaining the attenuation factor of the directional scattering mist according to the formula (7).
Equation (5) is shown below:
light_dir_n=light_dir*dir_scatter_pow (5)
where light_dir_n is the direction vector of the target parallel light, light_dir is the direction vector of the parallel light, dir_scan_pow is the scattering range of the parallel light. dir_scanner_pow is an interface parameter that the fog system can adjust.
Equation (6) is shown below:
ray_dir=normalize(pos_world.xyz-u_camera_position.xyz) (6)
where ray_dir is the direction vector of the view angle of the camera, pos_world. Xyz is the coordinates of the object in world space, and u_camera_position. Xyz is the coordinates of the camera in world space; the function of the normal (x) function is to normalize the input vector x.
Equation (7) is shown below:
sun_amout=saturate(dot(ray_dir,light_dir_n))*Dist_fac (7)
where sun_amout is the attenuation factor of the directional scattering mist, ray_dir is the direction vector of the view angle of the camera, light_dir_n is the direction vector of the target parallel light, dist_fac is the distance attenuation factor of the object, the function of dot (x, y) is to return the dot product of the two vectors x and y, and the function of saturation (x) is to limit the input value x between [ 01 ].
S205, obtaining the target color of the directional scattering fog according to the initial color of the atmospheric fog, the initial color of the directional scattering fog and the attenuation factor of the directional scattering fog.
One possible implementation is: the target color of the directional scattering mist is obtained according to the following formula (8).
final_scatter_color=lerp(atmos_inscatter,dir_inscattering,sun_amount) (8)
Wherein final_scatter_color is the target color of the directional scattering mist, atm_indicator is the initial color of the atmospheric mist, dir_indicator is the initial color of the directional scattering mist, sun_amont is the attenuation factor of the directional scattering mist, the function of lerp (a, b, t) is to interpolate between colors a and b by t, t is a value between 0 and 1, and color a is returned when t is 0; the color b is returned when t is 1. atm_ inscatter, dir _metering is an interface parameter that the mist effect system can adjust.
S206, obtaining the target color of the index-height fog according to the attenuation factor of the index-height fog and the color of the object.
One possible implementation is: the target color of the exponential high haze is obtained according to the following formula (9).
Final_height_fog=lerp(raw_color,fog_color,Fog_amount) (9)
Wherein final_height_fog is the target color of the index-height Fog, raw_color is the color of the object, fog_color is the color of the index-height Fog, and fog_current is the attenuation factor of the index-height Fog. fog_color is an interface parameter that the fog effect system can adjust.
S207, obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high-altitude fog.
One possible implementation is: the target haze color of the object is obtained according to the following formula (10).
color_with_fog=Final_height_fog+final_scatter_color (10)
Wherein color_with_fog is the target haze color of the object, final_height_fog is the target color of the index-height haze, and final_color_color is the target color of the directional scattering haze.
In the embodiment, the distance attenuation factor of the object is obtained according to the distance difference between the vertex position of the object and the camera position; acquiring a height attenuation factor of the object according to the height of the vertex of the object in world space; obtaining an attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor; obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera; obtaining a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist; obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object; according to the target color of the directional scattering fog and the target color of the index high fog, the target fog effect color of the object is obtained, and as the three fog effect colors of the index high fog, the atmosphere fog and the directional scattering fog are considered, the distance attenuation factor and the height attenuation factor are considered when the colors of the index high fog and the atmosphere fog are obtained, so that the fog effect is improved.
Fig. 3 is a schematic structural diagram of a device for treating mist effect according to an embodiment of the present invention, and as shown in fig. 3, the device in an embodiment of the present invention includes an obtaining module 301 and a processing module 302.
The acquiring module 301 is configured to acquire a distance attenuation factor and a height attenuation factor of an object;
the processing module 302 is configured to obtain an attenuation factor of the exponential high fog according to the distance attenuation factor and the high attenuation factor; the processing module 302 is further configured to obtain an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the viewing angle of the camera; the processing module 302 is further configured to obtain a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist, and the attenuation factor of the directional scattering mist; the processing module 302 is further configured to obtain a target color of the exponential high fog according to the attenuation factor of the exponential high fog and the color of the object; the processing module 302 is further configured to obtain a target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index height fog.
Optionally, the obtaining module 301 is specifically configured to:
obtaining a distance attenuation factor of the object according to the distance difference between the vertex position of the object and the camera position;
and acquiring the height attenuation factor of the object according to the height of the vertex of the object in world space.
Optionally, the obtaining module 301 is specifically configured to:
according to the formula
Figure GDA0004241640560000111
Acquiring a linear attenuation factor of an object;
where linear_fac is the Linear attenuation factor of the object, distance is the distance between the vertex position of the object and the camera position, fog_begin is the distance between the position where fog begins and the camera position, fog_end is the distance between the position where fog ends and the camera position, 0.0f is floating point number 0,1.0f is floating point number 1, the function of the clamp (value, min, max) functions to limit the value of the input value to the range of [ min, max ], and if the value of the value is between the value of min and the value of max, the value of the value is returned; if the value of value is greater than the value of max, returning the value of max; if the value of value is less than the value of min, returning the value of min;
obtaining a distance attenuation factor of the object according to the formula dist_fac=pow (max (1-exp (-linear_fac) 0, 1.2 f);
wherein Dist_fac is the distance attenuation factor of the object, linear_fac is the Linear attenuation factor of the object, 1.2f is the floating point number 1.2, exp (x) function functions to return an exponential function value based on e and exponential on x, max (x, y) function functions to return the maximum of x, y, and pow (x, y) function functions to return the y-th power of x.
Optionally, the obtaining module 301 is specifically configured to:
according to the formula
Figure GDA0004241640560000112
A height attenuation factor of the object is acquired,
where fog_height_current is the Height attenuation factor of the object, pos_world. Y is the Height of the object in world space, fog_height_begin is the Height of the position where the Height Fog starts in world space, and fog_height_end is the Height of the position where the Height Fog ends in world space.
Optionally, the obtaining module 301 is specifically configured to:
according to the formula fog_current=fog_height_current_dist_fac, the attenuation factor of the exponential high-intensity mist is obtained,
where Fog_current is the attenuation factor of the exponential Height haze, fog_height_current is the Height attenuation factor of the object, dist_fac is the distance attenuation factor of the object.
Optionally, the processing module 302 is specifically configured to:
obtaining a direction vector of the target parallel light according to the formula light_dir_n=light_dir_dir_scan_pow;
wherein light_dir_n is a direction vector of the target parallel light, light_dir is a direction vector of the parallel light, dir_scan_pow is a scattering range of the parallel light;
obtaining a direction vector of a view angle of the camera according to the formula ray_dir=normal (pos_world_xyz-u_camera_position;
where ray_dir is the direction vector of the view angle of the camera, pos_world. Xyz is the coordinates of the object in world space, and u_camera_position. Xyz is the coordinates of the camera in world space; the function of the normal (x) function is to normalize the input vector x;
according to the formula sun_amout=aperture (dot (light_dir_n)). Dist_fac, the attenuation factor of the directional scattering mist is obtained;
where sun_amout is the attenuation factor of the directional scattering mist, ray_dir is the direction vector of the view angle of the camera, light_dir_n is the direction vector of the target parallel light, dist_fac is the distance attenuation factor of the object, the function of dot (x, y) is to return the dot product of the two vectors x and y, and the function of saturation (x) is to limit the input value x between [ 01 ].
Optionally, the processing module 302 is specifically configured to:
according to the formula final_scanner_color=lerp (atm_inscator, dir_inscator, sun_amounto), the target color of the directional scattering mist is obtained,
wherein final_scatter_color is the target color of the directional scattering mist, atm_indicator is the initial color of the atmospheric mist, dir_indicator is the initial color of the directional scattering mist, sun_amont is the attenuation factor of the directional scattering mist, the function of lerp (a, b, t) is to interpolate between colors a and b by t, t is a value between 0 and 1, and color a is returned when t is 0; the color b is returned when t is 1.
Optionally, the processing module 302 is specifically configured to:
according to the formula final_height_fog=lerp (raw_color, fog_color, fog_current), the target color of the exponential high haze is obtained,
wherein final_height_fog is the target color of the index-height Fog, raw_color is the color of the object, fog_color is the color of the index-height Fog, and fog_current is the attenuation factor of the index-height Fog.
Optionally, the processing module 302 is specifically configured to:
according to color_with_fog=final_height_fog+final_color_color, the target haze color of the object is obtained,
wherein color_with_fog is the target haze color of the object, final_height_fog is the target color of the index-height haze, and final_color_color is the target color of the directional scattering haze.
The apparatus of this embodiment may be used to implement the technical solutions shown in fig. 1 and fig. 2 in the embodiments of the present invention, and its implementation principle and technical effects are similar, and are not described here again.
Fig. 4 is a schematic structural diagram of an electronic terminal according to an embodiment of the present invention, and as shown in fig. 4, the electronic terminal according to an embodiment of the present invention includes a processor 401 and a memory 402. The memory 402 is used for storing program instructions, and the processor 401 is used for reading the program instructions in the memory 402 and executing the method according to the program instructions in the memory 402.
The electronic terminal provided in this embodiment may execute the technical solutions shown in fig. 1 and fig. 2 in the embodiments of the present invention, and the implementation principle and the beneficial effects are similar, and are not described herein again.
The embodiment of the present invention further provides a storage medium, where the storage medium is used to store a computer program, where the computer program is used to implement the technical solutions shown in fig. 1 and fig. 2 in the embodiment of the present invention, and the implementation principle and beneficial effects are similar, and are not described herein again.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the method embodiments described above may be performed by hardware associated with program instructions. The foregoing program may be stored in a computer readable storage medium. The program, when executed, performs steps including the method embodiments described above; and the aforementioned storage medium includes: various media that can store program code, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the invention.

Claims (10)

1. A method of treating misting comprising:
acquiring a distance attenuation factor and a height attenuation factor of an object;
obtaining an attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor;
obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera;
obtaining a target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist;
obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object;
obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high-altitude fog;
the acquiring the distance attenuation factor and the height attenuation factor of the object comprises the following steps:
acquiring a distance attenuation factor of the object according to the distance difference between the vertex position of the object and the camera position;
acquiring a height attenuation factor of the object according to the height of the vertex of the object in world space;
the obtaining the distance attenuation factor of the object according to the distance difference between the vertex position and the camera position of the object comprises the following steps:
according to the formula
Figure FDA0004150488520000011
Acquiring a linear attenuation factor of the object;
where linear_fac is the Linear attenuation factor of the object, distance is the distance between the vertex position and the camera position of the object, fog_begin is the distance between the position of the start of fog and the camera position, fog_end is the distance between the position of the end of fog and the camera position, 0.0f is floating point number 0,1.0f is floating point number 1, the function of the clamp (value, min, max) functions to limit the value of the input value to the range of [ min, max ], and if the value of value is between the value of min and the value of max, return the value of value; if the value of value is greater than the value of max, returning the value of max; if the value of value is less than the value of min, returning the value of min;
obtaining a distance attenuation factor of the object according to the formula dist_fac=pow (max (1-exp (-linear_fac) 0), 1.2 f);
wherein Dist_fac is the distance attenuation factor of the object, linear_fac is the Linear attenuation factor of the object, 1.2f is floating point number 1.2, exp (x) function functions to return an exponential function value based on e and exponential with x, max (x, y) function functions to return the maximum of x, y, and pow (x, y) function functions to return the y-th power of x.
2. The method of claim 1, wherein the obtaining the height attenuation factor of the object based on the height of the vertex of the object in world space comprises:
according to the formula
Figure FDA0004150488520000021
A height attenuation factor of the object is acquired,
where fog_height_current is the Height attenuation factor of the object, pos_world is the Height of the object in world space, fog_height_begin is the Height of the position where the Height Fog starts in world space, and fog_height_end is the Height of the position where the Height Fog ends in world space.
3. The method of claim 2, wherein said deriving an exponential high haze attenuation factor from said distance attenuation factor and said height attenuation factor comprises:
according to the formula fog_current=fog_height_current_dist_fac, the attenuation factor of the exponential high-intensity mist is obtained,
where fog_count is the attenuation factor of the exponential Height haze, fog_height_count is the Height attenuation factor of the object, and dist_fac is the distance attenuation factor of the object.
4. A method according to claim 3, wherein the deriving the attenuation factor of the directional scattering mist from the direction vector of the parallel light and the direction vector of the viewing angle of the camera comprises:
obtaining a direction vector of the target parallel light according to the formula light_dir_n=light_dir_dir_scan_pow;
wherein light_dir_n is a direction vector of the target parallel light, light_dir is a direction vector of the parallel light, dir_scan_pow is a scattering range of the parallel light;
obtaining a direction vector of a view angle of the camera according to the formula ray_dir=normal (pos_world_xyz-u_camera_position;
wherein ray_dir is a direction vector of a view angle of the camera, pos_world. Xyz is coordinates of the object in world space, and u_camera_position. Xyz is coordinates of the camera in world space; the function of the normal (x) function is to normalize the input vector x;
according to the formula sun_amout=aperture (dot (light_dir_n)). Dist_fac, the attenuation factor of the directional scattering mist is obtained;
where sun_amout is the attenuation factor of the directional scattering mist, ray_dir is the direction vector of the view angle of the camera, light_dir_n is the direction vector of the target parallel light, dist_fac is the distance attenuation factor of the object, the function of dot (x, y) is to return the dot product of the two vectors x and y, and the function of the saturation (x) is to limit the input value x to between [ 01 ].
5. The method of claim 4, wherein the deriving the target color of the directionally-scattered mist from the initial color of the atmospheric mist, the initial color of the directionally-scattered mist, and the attenuation factor of the directionally-scattered mist comprises:
according to the formula final_scanner_color=lerp (atm_inscator, dir_inscator, sun_amounto), the target color of the directional scattering mist is obtained,
wherein final_scatter_color is the target color of the directional scattering mist, atm os_indicator is the initial color of the atmospheric mist, dir_indicator is the initial color of the directional scattering mist, sun_current is the attenuation factor of the directional scattering mist, the function of lerp (a, b, t) is to interpolate between colors a and b by t, t is a value between 0 and 1, and color a is returned when t is 0; the color b is returned when t is 1.
6. The method of claim 5, wherein said deriving a target color of the index-of-height mist from the attenuation factor of the index-of-height mist and the color of the object comprises:
according to the formula final_height_fog=lerp (raw_color, fog_color, fog_current), the target color of the exponential high haze is obtained,
wherein final_height_fog is the target color of the index-height Fog, raw_color is the color of the object, fog_color is the color of the index-height Fog, and fog_current is the attenuation factor of the index-height Fog.
7. The method of claim 6, wherein said deriving a target fog effect color for said object from said target color of said directionally-scattered fog and said target color of said exponential height fog comprises:
according to color_with_fog=final_height_fog+final_color_color, the target haze color of the object is obtained,
wherein color_with_fog is the target haze color of the object, final_height_fog is the target color of the exponential height haze, and final_color is the target color of the directional scattering haze.
8. An apparatus for treating misting, comprising:
the acquisition module is used for acquiring the distance attenuation factor and the height attenuation factor of the object;
the processing module is used for obtaining the attenuation factor of the exponential high-altitude fog according to the distance attenuation factor and the high attenuation factor;
the processing module is also used for obtaining an attenuation factor of the directional scattering fog according to the direction vector of the parallel light and the direction vector of the visual angle of the camera;
the processing module is further used for obtaining the target color of the directional scattering mist according to the initial color of the atmospheric mist, the initial color of the directional scattering mist and the attenuation factor of the directional scattering mist;
the processing module is further used for obtaining a target color of the index high-altitude fog according to the attenuation factor of the index high-altitude fog and the color of the object;
the processing module is further used for obtaining the target fog effect color of the object according to the target color of the directional scattering fog and the target color of the index high-altitude fog;
the acquisition module is specifically used for acquiring a distance attenuation factor of the object according to the distance difference between the vertex position and the camera position of the object; acquiring a height attenuation factor of the object according to the height of the vertex of the object in world space;
the acquisition module is particularly adapted to the fact that,
according to the formula
Figure FDA0004150488520000041
Acquiring a linear attenuation factor of the object; where Linear_fac is the Linear attenuation factor of the object, distance is the distance between the object's vertex position and camera position, fog_begin is the distance between the position of the fog start and camera position, fog_end is the distance between the position of the fog end and camera position, 0.0f is the floating point number 0,1.0f is the floating point number 1, clamp (value, min, max) function functions to limit the value of the input value to [ min, max]Within the range, if the value of value is between the value of min and the value of max, the value of value is returned; if the value of value is greater than the value of max, returning the value of max; if the value of value is less than the value of min, returning the value of min;
obtaining a distance attenuation factor of the object according to the formula dist_fac=pow (max (1-exp (-linear_fac) 0), 1.2 f); wherein Dist_fac is the distance attenuation factor of the object, linear_fac is the Linear attenuation factor of the object, 1.2f is floating point number 1.2, exp (x) function functions to return an exponential function value based on e and exponential with x, max (x, y) function functions to return the maximum of x, y, and pow (x, y) function functions to return the y-th power of x.
9. An electronic terminal, comprising:
comprising a memory and a processor executing program instructions in said memory for implementing a method of treatment of mist effects according to any of the claims 1-7.
10. A storage medium storing a computer program for implementing the method of treatment of mist effect according to any one of claims 1 to 7.
CN201910239648.7A 2019-03-27 2019-03-27 Method and device for treating fog effect Active CN110097627B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910239648.7A CN110097627B (en) 2019-03-27 2019-03-27 Method and device for treating fog effect

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910239648.7A CN110097627B (en) 2019-03-27 2019-03-27 Method and device for treating fog effect

Publications (2)

Publication Number Publication Date
CN110097627A CN110097627A (en) 2019-08-06
CN110097627B true CN110097627B (en) 2023-06-27

Family

ID=67443239

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910239648.7A Active CN110097627B (en) 2019-03-27 2019-03-27 Method and device for treating fog effect

Country Status (1)

Country Link
CN (1) CN110097627B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112950483B (en) * 2019-12-11 2023-07-21 福建天晴数码有限公司 Deep fog effect processing method and system based on mobile game platform

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7046243B1 (en) * 2000-11-21 2006-05-16 Microsoft Corporation Rendering volumetric fog and other gaseous phenomena
CN106384376B (en) * 2016-08-30 2019-03-01 北京像素软件科技股份有限公司 Mist imitates analogy method and device

Also Published As

Publication number Publication date
CN110097627A (en) 2019-08-06

Similar Documents

Publication Publication Date Title
US11386528B2 (en) Denoising filter
KR101964611B1 (en) Varying effective resolution by screen location in graphics processing by approximating projection of vertices onto curved viewport
CN106683100B (en) Image segmentation defogging method and terminal
CN104038699B (en) The reminding method of focusing state and filming apparatus
CN108830923B (en) Image rendering method and device and storage medium
CN105847703A (en) Image processing method and electronic device
CN109979008A (en) A kind of point cloud band division methods based on attribute
US8314797B1 (en) Method and apparatus for irradiance computation in 3-D computer graphics
CN113658316B (en) Rendering method and device of three-dimensional model, storage medium and computer equipment
CN114862725B (en) Method and device for realizing motion perception fuzzy special effect based on optical flow method
CN105023252A (en) Method and system for enhancement processing of beautified image and shooting terminal
CN110097627B (en) Method and device for treating fog effect
CN116168091A (en) Image processing method, apparatus, computer device and computer program product
Gautron Real-time ray-traced ambient occlusion of complex scenes using spatial hashing
CN105809622B (en) The automatic drafting method of insecure area automatic identification and Safe firing zone figure
CN116468838B (en) Regional resource rendering method, system, computer and readable storage medium
CN113052923A (en) Tone mapping method, tone mapping apparatus, electronic device, and storage medium
CN104123748A (en) Screen space point light source based method for achieving real-time dynamic shadows
CN107945202B (en) Image segmentation method and device based on adaptive threshold value and computing equipment
CN108280887B (en) Shadow map determination method and device
CN114170367B (en) Method, apparatus, storage medium, and device for infinite-line-of-sight pyramidal heatmap rendering
CN105574818B (en) Depth-of-field rendering method and device
CN112819929A (en) Water surface rendering method and device, electronic equipment and storage medium
Yaping et al. The recognition and enhancement of traffic sign for the computer-generated image
CN118096989A (en) Scene rendering method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant