Method and apparatus for rendering weather in virtual environment, device, medium and program
View Patent ↗This application discloses a method and apparatus for rendering weather in a virtual environment, a device, a medium and a program, belonging to the art of image processing. The method includes the following steps: acquiring at least one weather map of a weather scene in a virtual environment ( 201 ); removing a first weather map from the at least one weather map to obtain a remaining second weather map ( 202 ); and rendering the weather scene in the virtual environment according to the second weather map ( 203 ). This method reduces the frequency of map sampling by reducing the number of weather maps, and improves the performance of a terminal when running an application program supporting the virtual environment.
1 . A method for rendering weather in a virtual environment, applied to a computer device, the method comprising:
acquiring at least two weather maps of a weather scene in the virtual environment, the at least two weather maps representing the weather scene in multiple dimensions;
removing, in response to a first weather map from the at least two weather maps comprising a weather map outside a field of view of a current virtual character in the virtual environment, the first weather map from the at least two weather maps so that a second weather map of the same weather scene remains, wherein removing the first weather map is configured to reduce a frequency of map sampling, and wherein the weather map outside the field of view of the current virtual character comprises:
a first raindrop map in front of the field of view of the current virtual character but beyond a preset distance of the current virtual character when the weather scene comprises a raindrop effect; or
a first scattering map at a sky height higher than a specified height, and the first scattering map being an image representing a light scattering effect in a sky in the virtual environment, when the weather scene comprises a sky light and shadow effect; and
rendering the weather scene according to the second weather map.
2 . The method according to claim 1 , wherein the rendering the weather scene according to the second weather map comprises:
when the weather scene comprises the raindrop effect, acquiring a map layer divided in a line of sight direction of the current virtual character;
adding a second raindrop map into the map layer, the second raindrop map comprising a raindrop map in front of the field of view of the current virtual character and within the preset distance of the current virtual character, raindrop depth information being stored in a channel of the second raindrop map, the raindrop depth information used to represent a distance between the current virtual character and the second raindrop map, a positive correlation being comprised between the raindrop depth information and raindrop size; and
rendering raindrops with the raindrop size matching the raindrop depth information in a rain scene.
3 . The method according to claim 2 , the method further comprising:
when the current virtual character is located in an indoor environment, acquiring depth information of a shelter element, the depth information obtained from a perspective of looking down at the virtual environment, the shelter element used to provide the indoor environment for the current virtual character; and
deleting part of the second raindrop map according to the depth information of the shelter element and depth information corresponding to the current virtual character, the part of the second raindrop map referring to the second raindrop map blocked by the shelter element in front of the field of view of the current virtual character.
4 . The method according to claim 2 , wherein the current virtual character corresponds to a camera model;
the method further comprising:
acquiring an initial position and a photographing position, the initial position being a position where a water spray firstly appears on a ground of the virtual environment, the photographing position being a position where the camera model is located, the water spray used to characterize water spray generated when the raindrops fall down to the ground of the virtual environment;
calculating an ith cycle position at a time of generating the water spray for an ith time according to the initial position and the photographing position, i being a positive integer;
acquiring a position offset parameter, the position offset parameter used to represent an offset position when the water spray is cyclically generated;
calculating an (i+1)th cycle position at the time of generating the water spray for an (i+1)th time according to the position offset parameter and the ith cycle position; and
repeating operations of generating cycle position of the water spray until the rain scene is switched.
5 . The method according to claim 1 , wherein the rendering the weather scene according to the second weather map comprises:
when the weather scene comprises the sky light and shadow effect, processing a second scattering map corresponding to the sky to obtain a processed rendering map, a resolution of the processed rendering map being lower than a resolution of the second scattering map, the second scattering map comprising a scattering map at a sky height lower than a specified height; and
rendering a lighting scene corresponding to the sky of the virtual environment according to the processed rendering map.
6 . The method according to claim 1 , the method further comprising:
when the weather scene comprises a cloud effect, acquiring at least two first texture cloud maps, the first texture cloud maps comprising two-dimensional cloud images with gray scales, the at least two first texture cloud maps obtained after pixel points in a reference texture cloud map are offset along different directions, the reference texture cloud map comprising two-dimensional cloud images under a non-lighting condition;
mixing the at least two first texture cloud maps according to weights corresponding to channels of the first texture cloud maps to obtain a second texture cloud map; and
rendering clouds under changing light according to the second texture cloud map.
7 . The method according to claim 1 , wherein the current virtual character corresponds to a particle distribution box, the particle distribution box is divided into m*n sub distribution boxes, the current virtual character is located in the particle distribution box, m and n are positive integers, each sub distribution box corresponds to a particle emitter, and the particle distribution box is configured to simulate the weather scene represented by particles through the particle emitter;
the method further comprising:
when the current virtual character moves to an edge position of a bounding range corresponding to the particle distribution box, acquiring a moving direction of the current virtual character; and
moving a layer of sub distribution box farthest from the current virtual character along the moving direction to a position in front of and adjacent to a nearest layer of sub distribution box, the nearest layer of sub distribution box being located in front of the field of view of the current virtual character and having a shortest distance from the current virtual character.
8 . The method according to claim 1 , the method further comprising:
acquiring a first parameter, a second parameter, a third parameter and a fourth parameter, the first parameter used to represent a map parameter corresponding to a first weather scene, the second parameter used to represent a map parameter corresponding to a second weather scene, the third parameter used to represent a corresponding transition coefficient during a switching of time period, the fourth parameter used to represent a corresponding transition coefficient during the switching between two weather scenes;
obtaining a corresponding screen rendering parameter during the switching between the weather scenes according to the first parameter, the second parameter, the third parameter and the fourth parameter; and
rendering a transition screen when first weather scene is switched to the second weather scene according to the corresponding screen rendering parameter.
9 . The method according to claim 8 , wherein the rendering a transition screen when the first weather scene is switched to the second weather scene according to the corresponding screen rendering parameter comprises:
updating and calculating the corresponding screen rendering parameter at a preset time interval; and
rendering the transition screen when the first weather scene is switched to the second weather scene according to the corresponding screen rendering parameter.
10 . An apparatus for rendering weather in a virtual environment, the apparatus comprising:
a memory storing a plurality of instructions; and
a processor configured to execute the plurality of instructions, and upon execution of the plurality of instructions, is configured to:
acquire at least two weather maps of a weather scene in the virtual environment, the at least two weather maps representing the weather scene in multiple dimensions;
remove, in response to a first weather map from the at least two weather maps comprising a weather map outside a field of view of a current virtual character in the virtual environment, the first weather map from the at least two weather maps so that a second weather map of the same weather scene remains, wherein removing a first weather map is configured to reduce a frequency of map sampling, and wherein the weather map outside the field of view of the current virtual character comprises:
a first raindrop map in front of the field of view of the current virtual character but beyond a preset distance of the current virtual character when the weather scene comprises a raindrop effect; or
a first scattering map at a sky height higher than a specified height, and the first scattering map being an image representing a light scattering effect in a sky in the virtual environment, when the weather scene comprises a sky light and shadow effect; and
render the weather scene according to the second weather map.
11 . The apparatus according to claim 10 , wherein the processor, upon execution of the plurality of instructions, is further configured to:
when the weather scene comprises the raindrop effect, acquire a map layer divided in a line of sight direction of the current virtual character;
add a second raindrop map into the map layer, the second raindrop map comprising a raindrop map in front of the field of view of the current virtual character and within the preset distance of the current virtual character, raindrop depth information being stored in a channel of the second raindrop map, the raindrop depth information used to represent a distance between the current virtual character and the second raindrop map, a positive correlation being comprised between the raindrop depth information and raindrop size; and
render raindrops with the raindrop size matching the raindrop depth information in a rain scene.
12 . The apparatus according to claim 11 , wherein the plurality of instructions, upon execution of the plurality of instructions, is further configured to:
when the current virtual character is located in an indoor environment, acquire depth information of a shelter element, the depth information obtained from a perspective of looking down at the virtual environment, the shelter element used to provide the indoor environment for the current virtual character; and
delete part of the second raindrop map according to the depth information of the shelter element and depth information corresponding to the current virtual character, the part of the second raindrop map referring to the second raindrop map blocked by the shelter element in front of the field of view of the current virtual character.
13 . The apparatus according to claim 11 , wherein the current virtual character corresponds to a camera model;
acquire an initial position and a photographing position, the initial position being a position where a water spray firstly appears on a ground of the virtual environment, the photographing position being a position where the camera model is located, the water spray used to characterize water spray generated when the raindrops fall down to the ground of the virtual environment;
calculate an ith cycle position at a time of generating the water spray for an ith time according to the initial position and the photographing position, i being a positive integer;
acquire a position offset parameter, the position offset parameter used to represent an offset position when the water spray is cyclically generated;
calculate an (i+1)th cycle position at the time of generating the water spray for an (i+1)th time according to the position offset parameter and the ith cycle position, and repeat generation of cycle position of the water spray until the rain scene is switched.
14 . The apparatus according to claim 10 , wherein the processor, upon execution of the plurality of instructions, is further configured to:
when the weather scene comprises the sky light and shadow effect, process a second scattering map corresponding to the sky to obtain a processed rendering map, a resolution of the processed rendering map being lower than a resolution of the second scattering map, the second scattering map comprising a scattering map at a sky height lower than a specified height; and
render a lighting scene corresponding to the sky of the virtual environment according to the processed rendering map.
15 . The apparatus according to claim 10 , wherein the processor, upon execution of the plurality of instructions, is further configured to:
when the weather scene comprises a cloud effect, acquire at least two first texture cloud maps, the first texture cloud maps comprising two-dimensional cloud images with gray scales, the at least two first texture cloud maps being obtained after pixel points in a reference texture cloud map are offset along different directions, the reference texture cloud map comprising two-dimensional cloud images under a non-lighting condition;
mix the at least two first texture cloud maps according to weights corresponding to channels of the first texture cloud maps to obtain a second texture cloud map; and
render clouds under changing light according to the second texture cloud map.
16 . A non-transitory computer readable storage medium storing a plurality of instructions executable by a processor, wherein the plurality of instructions, upon execution by the processor, is configured to cause the processor to:
acquire at least two weather maps of a weather scene in a virtual environment, the at least two weather maps representing the weather scene in multiple dimensions, the at least two weather maps representing the weather scene in multiple dimensions;
remove, in response to a first weather map from the at least two weather maps comprising a weather map outside a field of view of a current virtual character in the virtual environment, the first weather map from the at least two weather maps so that a second weather map of the same weather scene remains, wherein removing a first weather map is configured to reduce a frequency of map sampling, and wherein the weather map outside the field of view of the current virtual character comprises:
a first raindrop map in front of the field of view of the current virtual character but beyond a preset distance of the current virtual character when the weather scene comprises a raindrop effect; or
a first scattering map at a sky height higher than a specified height, and the first scattering map being an image representing a light scattering effect in a sky in the virtual environment, when the weather scene comprises a sky light and shadow effect; and
render the weather scene according to the second weather map.
17 . The non-transitory computer readable storage medium according to claim 16 , the plurality of instructions, upon execution by the processor, is further configured to cause the processor to:
when the weather scene comprises a cloud effect, acquire at least two first texture cloud maps, the first texture cloud maps comprising two-dimensional cloud images with gray scales, the at least two first texture cloud maps being obtained after pixel points in a reference texture cloud map are offset along different directions, the reference texture cloud map comprising two-dimensional cloud images under a non-lighting condition;
mix the at least two first texture cloud maps according to weights corresponding to channels of the first texture cloud maps to obtain a second texture cloud map; and
render clouds under changing light according to the second texture cloud map.