Fog effect rendering method and device, electronic equipment and computer readable storage medium

By calculating and cumulating the light intensity attenuation value and external scattered light intensity between the target point and the direction light in the game scene, the problem of fog transition stiffness in the existing technology is solved, and a more realistic and natural fog rendering effect is achieved. .

CN119425076APending Publication Date: 2025-02-14NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411659019.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

When the prior art generates fog effects in game scenes, there is a clear boundary between the shallow scene and the deep scene, which makes the transition stiff and leads to distortion of the fog effect.

Method used

By determining multiple target points in the game scene, calculating the first distance and fog concentration between each target point and directional light, calculating the light intensity attenuation value of directional light, calculating the incident light intensity and outscattered light intensity, and cumulative these Values ​​to generate a more realistic fog rendering effect.

Benefits of technology

The generated fog effect is more in line with physical characteristics, and the transition is natural, which improves the authenticity of fog effect and reduces the overall calculation amount.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119425076A_ABST
    Figure CN119425076A_ABST
Patent Text Reader

Abstract

The invention provides a fog effect rendering method and device, electronic equipment and a computer readable storage medium, the method is applied to a game scene, and the game scene comprises a uniform medium and directional light; the method comprises the following steps: determining a plurality of target points from a light path between a to-be-rendered position in a uniform medium and a virtual camera; calculating a first distance from the position of the target point to the directional light; calculating a first attenuation value from the light intensity of the directional light to the target point according to the first distance and the fog concentration; calculating the incident light intensity of the target point according to the first attenuation value and the light intensity; according to the incident light intensity and the energy distribution of the target point in the direction pointing to the virtual camera, calculating the external scattering light intensity of the target point in the direction pointing to the virtual camera; and calculating an accumulated value of the external scattering light intensity of all the target points on the light path to obtain a fog effect rendering parameter, so that the game picture shot by the virtual camera presents a corresponding fog effect rendering effect. Through the method, the authenticity of the fog effect is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a fog effect rendering method, device, electronic device, and computer-readable storage medium. Background Art

[0002] With the continuous improvement of game technology, the visual effects of game scenes have gradually become an important criterion for judging games. Fog effect is a commonly used visual effect in games. In special game scenes where the brightness of a uniform medium in a game scene gradually darkens from top to bottom (such as underwater game scenes), more realistic visual effects are required, among which fog effect is the most important part. In such special game scenes, the fog effect is mainly manifested in the effect of gradually darkening brightness when looking into the distance. For example, the fog effect of an underwater game scene is mainly manifested in the effect of gradually darkening brightness from shallow water to deep water.

[0003] At present, the fog effect is generally calculated by interpolating the fog color according to the depth of the uniform medium in the game scene (such as the depth of water). The fog effect generated in this way has a clear boundary between the shallow scene and the deep scene (such as the shallow water and the deep water), and the transition is abrupt, resulting in distorted fog effect. Summary of the invention

[0004] In view of this, the purpose of the present application is to provide a fog effect rendering method, device, electronic device and computer-readable storage medium to improve the realism of fog effect rendering in a special game scene where the brightness of a uniform medium in the game scene gradually darkens from top to bottom.

[0005] In a first aspect, an embodiment of the present application provides a fog effect rendering method, which is applied to a game scene, wherein the game scene includes a uniform medium and directional light, and the method includes:

[0006] In response to a virtual camera in the game scene being located in the uniform medium, a plurality of target points are determined on a light path from a position to be rendered in the uniform medium to the virtual camera; wherein corresponding fog concentrations are preset at different positions in the uniform medium;

[0007] For each of the target points, calculating a first distance between the position of the target point and the directional light;

[0008] Calculating a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value;

[0009] Calculating the incident light intensity of the target point according to the first attenuation value and the light intensity;

[0010] Calculate the intensity of outward scattered light in the direction of the virtual camera from the target point according to the incident light intensity and the energy distribution in the direction of the virtual camera from the target point;

[0011] The cumulative value of the outward scattered light intensity of all the target points on the optical path is calculated, and the cumulative value is used as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

[0012] In a second aspect, an embodiment of the present application further provides a fog effect rendering device, which is applied to a game scene, wherein the game scene includes a uniform medium and directional light, and the device includes:

[0013] A determination module, configured to determine a plurality of target points on a light path from a rendering position in the homogeneous medium to the virtual camera in response to the virtual camera in the game scene being located in the homogeneous medium; wherein corresponding fog concentrations are preset at different positions in the homogeneous medium;

[0014] A first calculation module, used for calculating, for each of the target points, a first distance between the position of the target point and the directional light;

[0015] A second calculation module is used to calculate a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value;

[0016] A third calculation module, used for calculating the incident light intensity of the target point according to the first attenuation value and the light intensity;

[0017] A fourth calculation module, configured to calculate the intensity of outward scattered light in a direction from the target point to the virtual camera according to the incident light intensity and the energy distribution in the direction from the target point to the virtual camera;

[0018] The fifth calculation module is used to calculate the cumulative value of the outward scattered light intensity of all the target points on the optical path, and use the cumulative value as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

[0019] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps in any possible implementation of the first aspect above are performed.

[0020] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in any possible implementation of the first aspect described above are executed.

[0021] The fog rendering method, device, electronic device and computer-readable storage medium provided by the embodiments of the present application, wherein the method is applied to a game scene, wherein the game scene includes a uniform mechanism and directional light; when a virtual camera in the game scene enters a uniform medium, multiple target points are determined on the optical path from the position to be rendered in the uniform medium to the virtual camera; wherein corresponding fog concentrations are preset at different positions in the uniform medium; for each target point, a first distance between the position of the target point and the directional light is calculated; according to the first distance and the fog concentration, a first attenuation value of the light intensity of the directional light to the target point is calculated; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value; according to the first attenuation value and the light intensity, the incident light intensity of the target point is calculated; according to the incident light intensity and the energy distribution in the direction of the target point pointing to the virtual camera, the outward scattered light intensity of the target point pointing to the virtual camera is calculated; the cumulative value of the outward scattered light intensity of all target points on the optical path is calculated, and the cumulative value is used as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect. In this embodiment, by considering the scattering of light, the generated fog effect is more in line with physical characteristics, so that the generated fog effect is more realistic. At the same time, in this embodiment, through the preset fog concentration, directional light intensity and other parameters, the theoretically real fog effect rendering parameters are gradually derived, which is conducive to reducing the overall calculation amount.

[0022] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0024] Figure 1 A fog rendering effect diagram obtained by using the prior art method provided in an embodiment of the present application is shown;

[0025] Figure 2 A flow chart of a fog effect rendering method provided by an embodiment of the present application is shown;

[0026] Figure 3A schematic diagram showing the position of a virtual camera, a position to be rendered, a light path, and a target point provided in an embodiment of the present application;

[0027] Figure 4 A fog rendering effect diagram obtained by using the method of this embodiment provided in the embodiment of the present application is shown;

[0028] Figure 5 A schematic diagram of the structure of a fog effect rendering device provided in an embodiment of the present application is shown;

[0029] Figure 6 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0030] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme 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. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can be implemented out of sequence, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.

[0031] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0032] In the prior art, when the fog effect is calculated by interpolating the fog color according to the depth of the uniform medium (such as the depth of water) in the game scene, the visibility of each position to be rendered in the game scene is calculated according to the following formula:

[0033] f 1 =e -density×d1

[0034] Where density represents the preset fog density, d1 represents the distance between the position to be rendered and the virtual camera, and f 1Indicates the visibility of the position to be rendered.

[0035] Next, set a fog color and the visibility f of the position to be rendered. 1 A mixture can roughly simulate the fog effect. Specifically, the fog color and visibility f are calculated by the following formula 1 Make a mix:

[0036] finalcolor=color×f 1 +fogcolor×(1-f 1 )

[0037] Among them, color represents the color of the position to be rendered, fogcolor represents the fog color, and finalcolor represents the fog effect of the position to be rendered.

[0038] In the prior art, in a special game scene where the brightness of a uniform medium gradually darkens from top to bottom (e.g., an underwater game scene), the fog color of a shallow scene (e.g., a shallow water scene) is generally set to white, and the fog color of a deep scene (e.g., a deep water scene) is generally set to black. Figure 1 As shown, this will cause the generated fog effect to have an obvious boundary between the shallow scene and the deep scene (such as the shallow water and the deep water), and the transition will be abrupt, resulting in distortion of the fog effect.

[0039] Based on this, the embodiments of the present application provide a fog effect rendering method, device, electronic device, and computer-readable storage medium. By considering the scattering of light, the generated fog effect is more in line with physical properties, thereby making the generated fog effect more realistic. At the same time, by fixing parameters such as fog concentration and light intensity of virtual light sources, theoretically realistic fog effect rendering parameters are gradually derived, which is conducive to reducing the overall amount of calculation.

[0040] It should be noted that the term "including" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features. The method involved in the present application can be applied to any game that includes fog rendering, and the specific games and game types are not specifically limited here.

[0041] The fog effect rendering method in one embodiment of the present application may be run on a terminal device, wherein the terminal device may be a mobile terminal device.

[0042] To facilitate understanding of this embodiment, a fog rendering method disclosed in the embodiment of this application is first described in detail. The method is applied to a game scene, which includes a uniform medium and directional light, such as Figure 2 As shown, the fog effect rendering method includes steps S101-S106; specifically:

[0043] S101: In response to a virtual camera in a game scene being located in a uniform medium, a plurality of target points are determined on a light path from a position to be rendered in the uniform medium to the virtual camera; wherein corresponding fog concentrations are preset at different positions in the uniform medium;

[0044] S102: For each target point, calculating a first distance between the position of the target point and the directional light;

[0045] S103: Calculating a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value;

[0046] S104: Calculating the incident light intensity of the target point according to the first attenuation value and the light intensity;

[0047] S105: Calculating the intensity of outward scattered light in the direction from the target point to the virtual camera according to the incident light intensity and the energy distribution in the direction from the target point to the virtual camera;

[0048] S106: Calculate the cumulative value of the outward scattered light intensity of all target points on the light path, and use the cumulative value as a fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents a corresponding fog rendering effect.

[0049] In step S101, a graphical user interface is provided through a terminal device, and the content displayed by the graphical user interface includes part or all of the game scene. The virtual camera is in the game scene, and the game scene displayed by the graphical user interface is determined by the position of the virtual camera in the game scene when the virtual camera captures part or all of the game scene, and the current acquisition angle of the virtual camera. The position of the virtual camera in the game scene and the acquisition angle of the virtual camera are determined by the user. The user can change the game scene displayed in the graphical user interface by changing the position of the virtual camera in the game scene and the acquisition angle of the virtual camera.

[0050] In this embodiment, the game scene includes a uniform medium and directional light, and may also include a virtual character. The virtual character in the game scene can perform virtual actions in the uniform medium. The virtual character may be a character controlled by a player, and the player may control the virtual character to perform virtual actions in the game scene. Virtual actions include moving, squatting, turning, etc. Usually, the virtual camera is located on the virtual character, and the player controls the virtual character to perform virtual actions such as moving and turning in the game scene to change the game scene captured by the virtual camera, thereby changing the content of the game screen displayed in the graphical user interface.

[0051] The optical path between the position to be rendered and the virtual camera refers to the line connecting the position to be rendered to the position of the virtual camera, and the optical path contains multiple target points. Figure 3 As shown, the position to be rendered is Figure 3 The position of the midpoint P, the position of the virtual camera is Figure 3 The position of the cam in the image, the optical path refers to Figure 3 The line connecting the position of the cam and the position of point P. The target points included in this optical path are P 1 , P 2 , P 3 ......P n ,......P m , m>n, Figure 3 Only P is shown n .

[0052] The game scene includes homogeneous media, which refers to media with uniform density that allows light beams to pass through in a straight line.

[0053] In a possible implementation, the uniform medium is a liquid medium; the game scene is a liquid game scene. In a specific embodiment, the liquid medium is water, and the liquid game scene is an underwater game scene. Exemplarily, the water can be sea water, lake water, etc.

[0054] In this embodiment, corresponding fog concentrations are preset at different positions in the uniform medium, and the value range of the fog concentration is (0, 1). The greater the fog concentration, the thicker the fog, and the smaller the fog concentration, the thinner the fog.

[0055] In step S102, the directional light is a parallel light with a consistent light direction, which is often used to simulate sunlight. In this embodiment, the directional light is emitted by a virtual light source, which is located in the game scene. Usually, the virtual light source is a virtual sunlight source.

[0056] In this embodiment, the brightness of the uniform medium gradually dims from top to bottom. The top and bottom of the uniform medium are determined by the position of the virtual light source in the game scene. Usually, the part close to the virtual light source is the top, and the part far from the virtual light source is the bottom. Figure 3 As shown, when the game scene is a liquid game scene (such as an underwater game scene), the uniform medium is a liquid medium (such as seawater), the liquid plane (such as sea level) is closest to the virtual light source, so the liquid plane (sea level) is up, and the liquid bottom (such as the seabed) is farthest from the virtual light source, so the liquid bottom (such as the seabed) is down. At this time, the brightness of the liquid medium in the underwater game scene gradually darkens from the sea level to the seabed.

[0057] In step S103, the first attenuation value of the light intensity of the directional light to the target point can represent the visibility at the target point. The first attenuation value is positively correlated with the visibility, wherein the larger the first distance and the fog density, the smaller the first attenuation value and the lower the visibility; conversely, the smaller the first distance and the fog density, the larger the first attenuation value and the higher the visibility.

[0058] In step S104, since there is a certain distance between the virtual light source and the target point, the light intensity of the directional light provided by the virtual light source irradiating the target point will be attenuated to a certain extent. Therefore, in this embodiment, the incident light intensity of the target point can be calculated based on the first attenuation value at the target point and the pre-set light intensity of the directional light.

[0059] In step S105, the incident light at the target point is outwardly scattered, and the outwardly scattered light at the target point is scattered in all directions. In this embodiment, only the outwardly scattered light intensity in the direction of the target point pointing to the virtual camera needs to be calculated.

[0060] In step S106, after calculating the outward scattered light intensity at each target point on the light path corresponding to the position to be rendered, the cumulative value of the outward scattered light intensity of all target points on the light path is calculated by integration, and the cumulative value is used as the fog rendering parameter of the position to be rendered, so as to present the corresponding fog rendering effect on the game screen captured by the virtual camera.

[0061] In this embodiment, by considering the scattering of light, the generated fog effect is more in line with physical characteristics, so that the rendered fog effect is more realistic. At the same time, in this embodiment, by presetting parameters such as fog concentration and light intensity of virtual light sources, theoretically realistic fog effect rendering parameters are gradually derived, which is conducive to reducing the overall calculation amount.

[0062] In a possible implementation, when the uniform medium is a liquid medium and the game scene is a liquid game scene, step S102 may be performed according to the following steps:

[0063] According to the height of the liquid plane of the liquid game scene, the distance between the position of the virtual camera and the liquid plane of the liquid game scene, the second distance from the target point to the virtual camera, the unit vector from the target point to the virtual camera, the unit vector from the target point to the virtual light source, and the upward unit vector perpendicular to the liquid plane, the first distance between the position of the target point and the position where the directional light shines on the liquid plane is calculated; the virtual light source is used to provide directional light.

[0064] In this embodiment, the first distance may be calculated specifically according to the following formula:

[0065]

[0066] Among them, sundistance represents the first distance between the position of the target point and the position where the directional light shines on the liquid plane; oceanheight represents the height of the liquid plane of the liquid game scene; camerapos.y represents the distance between the position of the virtual camera and the liquid plane of the liquid game scene; s represents the second distance from the target point to the virtual camera; view represents the unit vector from the target point to the virtual camera; up is the unit vector pointing upward perpendicular to the liquid plane, usually (0,1,0); sundirection represents the unit vector from the target point to the virtual light source; dot is the dot product of the vectors.

[0067] In this embodiment, when the liquid game scene is an underwater game scene, the liquid plane height refers to the sea level height, and the liquid plane may be the sea level.

[0068] In a possible implementation manner, the fog concentration in the uniform medium is a preset constant value, and the preset fog concentrations at different positions in the uniform medium are equal. Step S103 may be performed according to the following steps:

[0069] S1031: Calculate the product of the first distance and the fog concentration to obtain a first value.

[0070] S1032: Performing a power operation using the negative of the first value as the exponent of the base e to obtain a first attenuation value from the virtual light source to the target point.

[0071] In this embodiment, the first attenuation value of the target point can be calculated according to the following formula:

[0072] f 2 =e -density×d2

[0073] Where density represents the preset fog density, d2 represents the first distance, and f 2 Indicates the first attenuation value of the target point.

[0074] In a possible implementation, when executing step S104, specifically: the product of the first attenuation value and the light intensity is calculated to obtain the incident light intensity of the target point.

[0075] In this embodiment, the incident light intensity at the target point can be calculated according to the following formula:

[0076] Incident light intensity = sunlight × f 2

[0077] Among them, sunlight is the intensity of sunlight.

[0078] In a possible implementation, when executing step S105, specifically: the product of the incident light intensity and the energy distribution in the direction of the target point pointing to the virtual camera is calculated to obtain the outward scattered light intensity in the direction of the target point pointing to the virtual camera.

[0079] In this embodiment, the intensity of the outward scattered light from the target point in the direction of the virtual camera can be calculated according to the following formula:

[0080] outscatter = incident light intensity × P(θ)

[0081] Among them, outscatter is the outscattering light intensity in the direction of the target point to the virtual camera; P(θ) is the energy distribution in the direction of the target point to the virtual camera; Figure 3 As shown, θ is the angle between the line connecting the target point and the virtual camera and the line connecting the target point and the virtual light source.

[0082] In a possible implementation, the fog effect rendering parameters are only rendering parameters related to the fog effect, and in the game scene, each position to be rendered corresponds to its own original color. In this embodiment, before rendering the position to be rendered, the color rendering parameters of the position to be rendered need to be determined. Therefore, after executing step S106 to calculate the cumulative value of the outward scattered light intensity of all target points on the light path and using the cumulative value as the fog effect rendering parameter of the position to be rendered, the following steps S1061-S1063 can also be performed:

[0083] S1061: Calculate the product of the third distance from the position to be rendered to the virtual camera and the fog density to obtain a second value.

[0084] S1062: Performing a power operation using the negative of the second value as the exponent of the base e to obtain a second attenuation value of the position to be rendered.

[0085] S1063: Calculate the product of the second attenuation value and the original color value of the position to be rendered to obtain a color rendering parameter of the position to be rendered.

[0086] In step S1061 , the position to be rendered and the position of the virtual camera are determined, so the third distance between the position to be rendered and the position of the virtual camera can be determined.

[0087] In step S1062, the second attenuation value of the position to be rendered may be calculated according to the following formula:

[0088] f 3 =e -density×d3

[0089] Where density represents the preset fog density, d3 represents the third distance, and f 3Indicates the second falloff value of the position to be rendered.

[0090] In step S1063, the product of the second attenuation value of the position to be rendered and the original color value of the position to be rendered is calculated to obtain the color rendering parameter of the position to be rendered.

[0091] In a possible implementation, after the fog rendering parameters and the color rendering parameters of the position to be rendered are calculated, when step S106 is executed so that the game screen captured by the virtual camera presents the corresponding fog rendering effect, the following steps S1064-S1065 may be specifically performed:

[0092] S1064: Calculate the sum of the color rendering parameter and the fog effect rendering parameter of the position to be rendered, and obtain the target rendering parameter of the position to be rendered;

[0093] S1065: Render the position to be rendered using the target rendering parameters so that the game screen at the position to be rendered captured by the virtual camera presents corresponding fog rendering effects and color rendering effects, and the fog rendering effects and color rendering effects at the position to be rendered are displayed on the graphical user interface.

[0094] In this embodiment, the color rendering parameter and the fog effect rendering parameter can be represented by RGB color values, so the obtained target rendering parameter is also an RGB color value.

[0095] like Figure 4 As shown, a fog effect diagram obtained by rendering in the manner of this embodiment is shown. It can be seen that the fog effect obtained in the manner of this embodiment has a natural transition from the shallow scene to the deep scene, which is beneficial to improving the authenticity of the fog effect.

[0096] Based on the same technical concept, the embodiment of the present application also provides a fog effect rendering device, which is applied to a game scene. The game scene includes a uniform medium and directional light, such as Figure 5 As shown, the device comprises:

[0097] The determination module 501 is used for determining a plurality of target points on a light path from a position to be rendered in the homogeneous medium to the virtual camera in response to the virtual camera in the game scene being located in the homogeneous medium; wherein corresponding fog concentrations are preset at different positions in the homogeneous medium;

[0098] A first calculation module 502 is used to calculate, for each target point, a first distance between the position of the target point and the directional light;

[0099] A second calculation module 503 is used to calculate a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value;

[0100] A third calculation module 504, configured to calculate the incident light intensity of the target point according to the first attenuation value and the light intensity;

[0101] A fourth calculation module 505, configured to calculate the intensity of outward scattered light in a direction from the target point to the virtual camera according to the incident light intensity and the energy distribution in a direction from the target point to the virtual camera;

[0102] The fifth calculation module 506 is used to calculate the cumulative value of the outward scattered light intensity of all the target points on the optical path, and use the cumulative value as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

[0103] In an optional embodiment, the uniform medium is a liquid medium; and the game scene is a liquid game scene.

[0104] In an optional implementation manner, when the first calculation module 502 is used to calculate, for each target point, a first distance between the position of the target point and the directional light, it is specifically used to:

[0105] According to the height of the liquid plane of the liquid game scene, the distance between the position of the virtual camera and the liquid plane of the liquid game scene, the second distance from the target point to the virtual camera, the unit vector from the target point to the virtual camera, the unit vector from the target point to the virtual light source, and the upward unit vector perpendicular to the liquid plane, calculate the first distance between the position of the target point and the position where the directional light shines on the liquid plane; the virtual light source is used to provide the directional light.

[0106] In an optional implementation, the preset fog concentrations at different positions in the homogeneous medium are equal; when the second calculation module 503 is used to calculate the first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration, it is specifically used to:

[0107] Calculating the product of the first distance and the fog concentration to obtain a first value;

[0108] A power operation is performed using the negative of the first value as the exponent of the base e to obtain a first attenuation value of the light intensity of the directional light to the target point.

[0109] In an optional implementation, when the third calculation module 504 is used to calculate the incident light intensity of the target point according to the first attenuation value and the light intensity, it is specifically used to:

[0110] The product of the first attenuation value and the light intensity is calculated to obtain the incident light intensity of the target point.

[0111] In an optional implementation, the fourth calculation module 505, when used to calculate the intensity of the outward scattered light in the direction of the target point pointing to the virtual camera according to the incident light intensity and the energy distribution in the direction of the target point pointing to the virtual camera, is specifically used to:

[0112] The product of the incident light intensity and the energy distribution in the direction from the target point to the virtual camera is calculated to obtain the outward scattered light intensity in the direction from the target point to the virtual camera.

[0113] In an optional implementation, after the fifth calculation module 506 is used to calculate the cumulative value of the outward scattered light intensity of all the target points on the light path and use the cumulative value as the fog effect rendering parameter of the position to be rendered, it is further used to:

[0114] Calculate the product of a third distance from the position to be rendered to the virtual camera and the fog concentration to obtain a second value;

[0115] Performing a power operation using the negative of the second value as the exponent of the base e to obtain a second attenuation value of the position to be rendered;

[0116] The product of the second attenuation value and the original color value of the position to be rendered is calculated to obtain a color rendering parameter of the position to be rendered.

[0117] In an optional implementation, when the fifth calculation module 506 is used to make the game screen captured by the virtual camera present a corresponding fog rendering effect, it is specifically used to:

[0118] Calculating the sum of the color rendering parameter and the fog effect rendering parameter of the position to be rendered to obtain the target rendering parameter of the position to be rendered;

[0119] The target rendering parameters are used to render the position to be rendered so that the game screen at the position to be rendered captured by the virtual camera presents corresponding fog rendering effects and color rendering effects, and the fog rendering effects and color rendering effects at the position to be rendered are displayed on a graphical user interface.

[0120] Based on the above-mentioned fog effect rendering device provided by the embodiment of the present application, when the virtual camera in the game scene enters the uniform medium, multiple target points are determined on the optical path from the position to be rendered in the uniform medium to the virtual camera; wherein, corresponding fog concentrations are preset at different positions in the uniform medium; for each target point, the first distance between the position of the target point and the directional light is calculated; according to the first distance and the fog concentration, the first attenuation value of the light intensity of the directional light to the target point is calculated; wherein, the first distance and the fog concentration are both negatively correlated with the first attenuation value; according to the first attenuation value and the light intensity, the incident light intensity of the target point is calculated; according to the incident light intensity and the energy distribution in the direction of the virtual camera of the target point, the outward scattered light intensity of the target point in the direction of the virtual camera is calculated; the cumulative value of the outward scattered light intensity of all target points on the optical path is calculated, and the cumulative value is used as the fog effect rendering parameter of the position to be rendered, so that the game screen shot by the virtual camera presents the corresponding fog effect rendering effect. In this embodiment, by considering the scattering of light, the generated fog effect is more in line with the physical characteristics, so that the generated fog effect is more realistic. At the same time, in this embodiment, theoretically realistic fog effect rendering parameters are gradually derived through preset parameters such as fog concentration and intensity of directional light, which is beneficial to reducing the overall calculation amount.

[0121] Based on the same inventive concept, the present application also provides an electronic device corresponding to the above-mentioned fog effect rendering method, which is applied to a game scene, wherein the game scene includes a uniform medium and directional light. Since the principle of solving the problem by the electronic device in the embodiment of the present application is similar to the above-mentioned fog effect rendering method in the embodiment of the present application, the implementation of the electronic device can refer to the implementation of the above-mentioned fog effect rendering method, and the repeated parts will not be repeated.

[0122] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application includes: a processor 601, a memory 602 and a bus 603, wherein the memory 602 stores machine-readable instructions executable by the processor 601. When the electronic device runs the above-mentioned information processing method, the processor 601 communicates with the memory 602 through the bus 603, and the processor 601 executes the machine-readable instructions. When the processor 601 executes the machine-readable instructions, the following steps are implemented, specifically:

[0123] In response to a virtual camera in the game scene being located in the uniform medium, a plurality of target points are determined on a light path from a position to be rendered in the uniform medium to the virtual camera; wherein corresponding fog concentrations are preset at different positions in the uniform medium;

[0124] For each of the target points, calculating a first distance between the position of the target point and the directional light;

[0125] Calculating a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value;

[0126] Calculating the incident light intensity of the target point according to the first attenuation value and the light intensity;

[0127] Calculate the intensity of outward scattered light in the direction of the virtual camera from the target point according to the incident light intensity and the energy distribution in the direction of the virtual camera from the target point;

[0128] The cumulative value of the outward scattered light intensity of all the target points on the optical path is calculated, and the cumulative value is used as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

[0129] In an optional embodiment, the uniform medium is a liquid medium; and the game scene is a liquid game scene.

[0130] In an optional implementation manner, when the processor 601 is used to calculate, for each of the target points, the first distance between the position of the target point and the directional light, it is specifically used to:

[0131] According to the height of the liquid plane of the liquid game scene, the distance between the position of the virtual camera and the liquid plane of the liquid game scene, the second distance from the target point to the virtual camera, the unit vector from the target point to the virtual camera, the unit vector from the target point to the virtual light source, and the upward unit vector perpendicular to the liquid plane, calculate the first distance between the position of the target point and the position where the directional light shines on the liquid plane; the virtual light source is used to provide the directional light.

[0132] In an optional implementation, the preset fog concentrations at different positions in the uniform medium are equal; when the processor 601 is used to calculate the first attenuation value of the light intensity to the target point according to the first distance and the fog concentration, it is specifically used to:

[0133] Calculating the product of the first distance and the fog concentration to obtain a first value;

[0134] A power operation is performed using the negative of the first value as the exponent of the base e to obtain a first attenuation value of the light intensity of the directional light to the target point.

[0135] In an optional implementation, when the processor 601 is used to calculate the incident light intensity of the target point according to the first attenuation value and the light intensity, it is specifically used to:

[0136] The product of the first attenuation value and the light intensity is calculated to obtain the incident light intensity of the target point.

[0137] In an optional implementation, when the processor 601 is used to calculate the intensity of the outward scattered light in the direction of the target point pointing to the virtual camera according to the incident light intensity and the energy distribution in the direction of the target point pointing to the virtual camera, it is specifically used to:

[0138] The product of the incident light intensity and the energy distribution in the direction from the target point to the virtual camera is calculated to obtain the outward scattered light intensity in the direction from the target point to the virtual camera.

[0139] In an optional implementation, after the processor 601 is used to calculate the cumulative value of the outward scattered light intensity of all the target points on the light path to use the cumulative value as the fog effect rendering parameter of the position to be rendered, it is further used to:

[0140] Calculate the product of a third distance from the position to be rendered to the virtual camera and the fog concentration to obtain a second value;

[0141] Performing a power operation using the negative of the second value as the exponent of the base e to obtain a second attenuation value of the position to be rendered;

[0142] The product of the second attenuation value and the original color value of the position to be rendered is calculated to obtain a color rendering parameter of the position to be rendered.

[0143] In an optional implementation, when the processor 601 is used to make the game screen captured by the virtual camera present a corresponding fog rendering effect, it is specifically used to:

[0144] Calculating the sum of the color rendering parameter and the fog effect rendering parameter of the position to be rendered to obtain the target rendering parameter of the position to be rendered;

[0145] The target rendering parameters are used to render the position to be rendered so that the game screen at the position to be rendered captured by the virtual camera presents corresponding fog rendering effects and color rendering effects, and the fog rendering effects and color rendering effects at the position to be rendered are displayed on a graphical user interface.

[0146] Through the above-mentioned electronic device provided by the embodiment of the present application, when the virtual camera in the game scene enters a uniform medium, multiple target points are determined on the optical path from the position to be rendered in the uniform medium to the virtual camera; wherein, corresponding fog concentrations are preset at different positions in the uniform medium; for each target point, the first distance between the position of the target point and the directional light is calculated; according to the first distance and the fog concentration, the first attenuation value of the light intensity of the directional light to the target point is calculated; wherein, the first distance and the fog concentration are both negatively correlated with the first attenuation value; according to the first attenuation value and the light intensity, the incident light intensity of the target point is calculated; according to the incident light intensity and the energy distribution in the direction of the virtual camera of the target point, the outward scattered light intensity of the target point in the direction of the virtual camera is calculated; the cumulative value of the outward scattered light intensity of all target points on the optical path is calculated, and the cumulative value is used as the fog effect rendering parameter of the position to be rendered, so that the game screen shot by the virtual camera presents the corresponding fog effect rendering effect. In this embodiment, by considering the scattering of light, the generated fog effect is more in line with the physical characteristics, so that the generated fog effect is more realistic. At the same time, in this embodiment, theoretically realistic fog effect rendering parameters are gradually derived through preset parameters such as fog concentration and intensity of directional light, which is beneficial to reducing the overall calculation amount.

[0147] Based on the same inventive concept, an embodiment of the present application further provides a computer-readable storage medium, which is applied to a game scene, wherein the game scene includes a uniform medium and a directional light, and a computer program is stored on the computer-readable storage medium, and the computer program is executed when a processor is running, and the processor performs the following steps:

[0148] In response to a virtual camera in the game scene being located in the uniform medium, a plurality of target points are determined on a light path from a position to be rendered in the uniform medium to the virtual camera; wherein corresponding fog concentrations are preset at different positions in the uniform medium;

[0149] For each of the target points, calculating a first distance between the position of the target point and the directional light;

[0150] Calculating a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value;

[0151] Calculating the incident light intensity of the target point according to the first attenuation value and the light intensity;

[0152] Calculate the intensity of outward scattered light in the direction of the virtual camera from the target point according to the incident light intensity and the energy distribution in the direction of the virtual camera from the target point;

[0153] The cumulative value of the outward scattered light intensity of all the target points on the optical path is calculated, and the cumulative value is used as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

[0154] In an optional embodiment, the uniform medium is a liquid medium; and the game scene is a liquid game scene.

[0155] In an optional implementation manner, when the processor is used to calculate, for each of the target points, a first distance between a position of the target point and the directional light, the processor is specifically used to:

[0156] According to the height of the liquid plane of the liquid game scene, the distance between the position of the virtual camera and the liquid plane of the liquid game scene, the second distance from the target point to the virtual camera, the unit vector from the target point to the virtual camera, the unit vector from the target point to the virtual light source, and the upward unit vector perpendicular to the liquid plane, calculate the first distance between the position of the target point and the position where the directional light shines on the liquid plane; the virtual light source is used to provide the directional light.

[0157] In an optional implementation, the preset fog concentrations at different positions in the uniform medium are equal; when the processor is used to calculate the first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration, it is specifically used to:

[0158] Calculating the product of the first distance and the fog concentration to obtain a first value;

[0159] A power operation is performed using the negative of the first value as the exponent of the base e to obtain a first attenuation value of the light intensity of the directional light to the target point.

[0160] In an optional implementation, when the processor is used to calculate the incident light intensity of the target point according to the first attenuation value and the light intensity, it is specifically used to:

[0161] The product of the first attenuation value and the light intensity is calculated to obtain the incident light intensity of the target point.

[0162] In an optional implementation, when the processor is used to calculate the intensity of the outward scattered light in the direction of the target point pointing to the virtual camera according to the incident light intensity and the energy distribution in the direction of the target point pointing to the virtual camera, it is specifically used to:

[0163] The product of the incident light intensity and the energy distribution in the direction from the target point to the virtual camera is calculated to obtain the outward scattered light intensity in the direction from the target point to the virtual camera.

[0164] In an optional implementation, after the processor is used to calculate the cumulative value of the outward scattered light intensity of all the target points on the light path to use the cumulative value as the fog effect rendering parameter of the position to be rendered, it is further used to:

[0165] Calculate the product of a third distance from the position to be rendered to the virtual camera and the fog concentration to obtain a second value;

[0166] Performing a power operation using the negative of the second value as the exponent of the base e to obtain a second attenuation value of the position to be rendered;

[0167] The product of the second attenuation value and the original color value of the position to be rendered is calculated to obtain a color rendering parameter of the position to be rendered.

[0168] In an optional implementation, when the processor is used to make the game screen captured by the virtual camera present a corresponding fog rendering effect, it is specifically used to:

[0169] Calculating the sum of the color rendering parameter and the fog effect rendering parameter of the position to be rendered to obtain the target rendering parameter of the position to be rendered;

[0170] The target rendering parameters are used to render the position to be rendered so that the game screen at the position to be rendered captured by the virtual camera presents corresponding fog rendering effects and color rendering effects, and the fog rendering effects and color rendering effects at the position to be rendered are displayed on a graphical user interface.

[0171] Through the above-mentioned computer-readable storage medium provided by the embodiment of the present application, when the virtual camera in the game scene enters the uniform medium, multiple target points are determined on the optical path from the position to be rendered in the uniform medium to the virtual camera; wherein, corresponding fog concentrations are preset at different positions in the uniform medium; for each target point, the first distance between the position of the target point and the directional light is calculated; according to the first distance and the fog concentration, the first attenuation value of the light intensity of the directional light to the target point is calculated; wherein, the first distance and the fog concentration are both negatively correlated with the first attenuation value; according to the first attenuation value and the light intensity, the incident light intensity of the target point is calculated; according to the incident light intensity and the energy distribution in the direction of the virtual camera of the target point, the outward scattered light intensity of the target point in the direction of the virtual camera is calculated; the cumulative value of the outward scattered light intensity of all target points on the optical path is calculated, and the cumulative value is used as the fog effect rendering parameter of the position to be rendered, so that the game screen shot by the virtual camera presents the corresponding fog effect rendering effect. In this embodiment, by considering the scattering of light, the generated fog effect is more in line with the physical characteristics, so that the generated fog effect is more realistic. At the same time, in this embodiment, theoretically realistic fog effect rendering parameters are gradually derived through preset parameters such as fog concentration and intensity of directional light, which is beneficial to reducing the overall calculation amount.

[0172] In an embodiment of the present application, the computer-readable storage medium can also execute other machine-readable instructions when run by the processor to execute the fog effect rendering method as described in other embodiments. For the specific steps and principles of the fog effect rendering method, please refer to the description of the method side embodiment, which will not be repeated here.

[0173] In the several embodiments provided in the present application, it should be understood that the disclosed methods, devices, electronic devices and computer-readable storage media can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or modules can be electrical, mechanical or other forms.

[0174] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0175] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0176] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or in other words, the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0177] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A fog effect rendering method, characterized in that: Applied in a game scene, the game scene includes a uniform medium and directional light, and the method includes: In response to a virtual camera in the game scene being located in the uniform medium, a plurality of target points are determined on a light path from a position to be rendered in the uniform medium to the virtual camera; wherein corresponding fog concentrations are preset at different positions in the uniform medium; For each of the target points, calculating a first distance between the position of the target point and the directional light; Calculating a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value; Calculating the incident light intensity of the target point according to the first attenuation value and the light intensity; Calculate the intensity of outward scattered light in the direction of the virtual camera from the target point according to the incident light intensity and the energy distribution in the direction of the virtual camera from the target point; The cumulative value of the outward scattered light intensity of all the target points on the optical path is calculated, and the cumulative value is used as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

2. The method according to claim 1, characterized in that: The uniform medium is a liquid medium; and the game scene is a liquid game scene.

3. The method according to claim 2, characterized in that: The step of calculating, for each of the target points, a first distance between the position of the target point and the directional light includes: According to the height of the liquid plane of the liquid game scene, the distance between the position of the virtual camera and the liquid plane of the liquid game scene, the second distance from the target point to the virtual camera, the unit vector from the target point to the virtual camera, the unit vector from the target point to the virtual light source, and the upward unit vector perpendicular to the liquid plane, calculate the first distance between the position of the target point and the position where the directional light shines on the liquid plane; the virtual light source is used to provide the directional light.

4. The method according to claim 1, characterized in that: The preset fog concentrations at different positions in the uniform medium are equal; and the first attenuation value of the light intensity of the directional light to the target point is calculated according to the first distance and the fog concentration, including: Calculating the product of the first distance and the fog concentration to obtain a first value; A power operation is performed using the negative of the first value as the exponent of the base e to obtain a first attenuation value of the light intensity of the directional light to the target point.

5. The method according to claim 1, characterized in that: The calculating the incident light intensity of the target point according to the first attenuation value and the light intensity includes: The product of the first attenuation value and the light intensity is calculated to obtain the incident light intensity of the target point.

6. The method according to claim 1, characterized in that: The step of calculating the intensity of the outward scattered light in the direction of the virtual camera pointed by the target point according to the incident light intensity and the energy distribution in the direction of the virtual camera pointed by the target point comprises: The product of the incident light intensity and the energy distribution in the direction from the target point to the virtual camera is calculated to obtain the outward scattered light intensity in the direction from the target point to the virtual camera.

7. The method according to claim 4, characterized in that: After calculating the cumulative value of the outward scattered light intensity of all the target points on the light path and using the cumulative value as a fog effect rendering parameter of the position to be rendered, the method further includes: Calculate the product of a third distance from the position to be rendered to the virtual camera and the fog concentration to obtain a second value; Performing a power operation using the negative of the second value as the exponent of the base e to obtain a second attenuation value of the position to be rendered; The product of the second attenuation value and the original color value of the position to be rendered is calculated to obtain a color rendering parameter of the position to be rendered.

8. The method according to claim 7, characterized in that: The method of making the game screen shot by the virtual camera present a corresponding fog rendering effect includes: Calculating the sum of the color rendering parameter and the fog effect rendering parameter of the position to be rendered to obtain the target rendering parameter of the position to be rendered; The target rendering parameters are used to render the position to be rendered so that the game screen at the position to be rendered captured by the virtual camera presents corresponding fog rendering effects and color rendering effects, and the fog rendering effects and color rendering effects at the position to be rendered are displayed on a graphical user interface.

9. A fog effect rendering device, characterized in that: Applied in a game scene, the game scene includes a uniform medium and directional light; the device includes: A determination module, configured to determine a plurality of target points on a light path from a position to be rendered in the homogeneous medium to the virtual camera in response to the virtual camera in the game scene being located in the homogeneous medium; wherein corresponding fog concentrations are preset at different positions in the homogeneous medium; A first calculation module, used for calculating, for each of the target points, a first distance between the position of the target point and the directional light; A second calculation module is used to calculate a first attenuation value of the light intensity of the directional light to the target point according to the first distance and the fog concentration; wherein the first distance and the fog concentration are both negatively correlated with the first attenuation value; A third calculation module, used for calculating the incident light intensity of the target point according to the first attenuation value and the light intensity; A fourth calculation module, configured to calculate the intensity of outward scattered light in a direction from the target point to the virtual camera according to the incident light intensity and the energy distribution in the direction from the target point to the virtual camera; The fifth calculation module is used to calculate the cumulative value of the outward scattered light intensity of all the target points on the optical path, and use the cumulative value as the fog rendering parameter of the position to be rendered, so that the game screen captured by the virtual camera presents the corresponding fog rendering effect.

10. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the method as claimed in any one of claims 1 to 8 are performed.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are executed.

Citation Information

Cited By

  • Warning fog rendering method and device, medium and product

    CN120884892A