Shadow rendering method and apparatus, electronic device, and readable storage medium
View Patent ↗A shadow rendering method is performed by an electronic device. The method includes: determining scene ranges corresponding to a plurality of first levels, each scene range being a first visible scene range of a virtual scene corresponding to a respective one of the plurality of first levels; for a respective one of the plurality of first levels: determining a first virtual item whose shadow is present in a first visible scene range corresponding to the first level; determining a first projection depth map corresponding to the first level based on the first virtual item, the first projection depth map being configured for describing distances between a light source and a plurality of first vertices on a surface of the first virtual item facing the light source; and rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map.
1 . A shadow rendering method performed by an electronic device, the method comprising: determining scene ranges corresponding to a plurality of first levels, each scene range being a first visible scene range of a virtual scene corresponding to a respective one of the plurality of first levels; for a respective one of the plurality of first levels: determining a first virtual item whose shadow is present in a first visible scene range corresponding to the first level, further including: obtaining reference projection ranges of a plurality of virtual items in the virtual scene in a first projection coordinate system; determining a first projection range of the first level in the first projection coordinate system based on the scene range corresponding to the first level; and determining a virtual item as the first virtual item when the reference projection range of the virtual item and the first projection range intersect; determining a first projection depth map corresponding to the first level based on the first virtual item, the first projection depth map being configured for describing distances between a light source and a plurality of first vertices on a surface of the first virtual item facing the light source; and rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map.
2 . The method according to claim 1 , wherein the determining scene ranges corresponding to a plurality of first levels comprises:
determining the scene ranges corresponding to the plurality of first levels in response to a shadow update condition being satisfied; and
the shadow update condition being satisfied comprises at least one of the following:
a virtual object moves in the virtual scene; illumination of the virtual scene changes; and the virtual scene is initialized.
3 . The method according to claim 1 , wherein the determining scene ranges corresponding to a plurality of first levels comprises:
obtaining a range size of each first level; and
determining, for any first level, a scene range corresponding to the first level in the first visible scene based on a reference point of the first visible scene and the range size of the first level.
4 . The method according to claim 1 , wherein the method further comprises: before obtaining the reference projection ranges of the plurality of virtual items in the virtual scene in the first projection coordinate system: expanding the scene range corresponding to the first level based on an expansion parameter, to obtain a reference range corresponding to the first level; and selecting a plurality of virtual items located in the reference range.
5 . The method according to claim 1 , wherein the determining a first projection depth map corresponding to the first level based on the first virtual item comprising:
determining three-dimensional projection coordinates of vertices of the first virtual item in a second projection coordinate system based on three-dimensional scene coordinates of the vertices of the first virtual item in a virtual scene coordinate system;
determining an adjustment coefficient based on the scene range corresponding to the first level and a resolution of the first projection depth map;
adjusting the three-dimensional projection coordinates of the vertices of the first virtual item based on the adjustment coefficient, to obtain adjusted three-dimensional projection coordinates of the vertices of the first virtual item; and
determining the first projection depth map based on three-dimensional projection coordinates of the light source in the second projection coordinate system and the adjusted three-dimensional projection coordinates of the vertices of the first virtual item.
6 . The method according to claim 1 , wherein the determining a first projection depth map corresponding to the first level based on the first virtual item comprises:
obtaining, for any first level, in response to a related movement amplitude of a virtual object relative to a related level being greater than a movement threshold, a related projection depth map corresponding to the related level, the related level being a second level whose scene range is of a same size as a scene range corresponding to the first level, the related projection depth map being configured for describing distances between a plurality of second vertices and the light source, the plurality of second vertices being each a vertex on a surface of a third virtual item corresponding to the related level facing the light source, and the third virtual item being a virtual item whose shadow is within a scene range corresponding to the related level; and
determining the first projection depth map based on the first virtual item and the related projection depth map.
7 . The method according to claim 1 , wherein the rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map comprises:
determining a first distance between the light source and each of a plurality of candidate vertexes on a surface of a virtual item in the first visible scene facing a camera;
determining, from the plurality of first levels, a reference level corresponding to each candidate vertex;
determining, among the plurality of candidate vertexes, a second distance between the light source and a first vertex from a projection depth map corresponding to the reference level corresponding to the first vertex; and
rendering the shadow at a position of each of the plurality of vertexes in response to the first distance of the candidate being greater than the second distance.
8 . An electronic device, comprising a processor and a memory, the memory storing at least one computer program, and the at least one computer program, when loaded and executed by the processor, causing the electronic device to implement a shadow rendering met hod including: determining scene ranges corresponding to a plurality of first levels, each scene range being a first visible scene range of a virtual scene corresponding to a respective one of the plurality of first levels; for a respective one of the plurality of first levels: determining a first virtual item whose shadow is present in a first visible scene range corresponding to the first level, further including: obtaining reference projection ranges of a plurality of virtual items in the virtual scene in a first projection coordinate system; determining a first projection range of the first level in the first projection coordinate system based on the scene range corresponding to the first level; and determining a virtual item as the first virtual item when the reference projection range of the virtual item and the first projection range intersect; determining a first projection depth map corresponding to the first level based on the first virtual item, the first projection depth map being configured for describing distances between a light source and a plurality of first vertices on a surface of the first virtual item facing the light source; and rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map.
9 . The electronic device according to claim 8 , wherein the determining scene ranges corresponding to a plurality of first levels comprises:
determining the scene ranges corresponding to the plurality of first levels in response to a shadow update condition being satisfied; and
the shadow update condition being satisfied comprises at least one of the following:
a virtual object moves in the virtual scene; illumination of the virtual scene changes; and the virtual scene is initialized.
10 . The electronic device according to claim 8 , wherein the determining scene ranges corresponding to a plurality of first levels comprises:
obtaining a range size of each first level; and
determining, for any first level, a scene range corresponding to the first level in the first visible scene based on a reference point of the first visible scene and the range size of the first level.
11 . The electronic device according to claim 8 , wherein the determining a first projection depth map corresponding to the first level based on the first virtual item comprising:
determining three-dimensional projection coordinates of vertices of the first virtual item in a second projection coordinate system based on three-dimensional scene coordinates of the vertices of the first virtual item in a virtual scene coordinate system;
determining an adjustment coefficient based on the scene range corresponding to the first level and a resolution of the first projection depth map;
adjusting the three-dimensional projection coordinates of the vertices of the first virtual item based on the adjustment coefficient, to obtain adjusted three-dimensional projection coordinates of the vertices of the first virtual item; and
determining the first projection depth map based on three-dimensional projection coordinates of the light source in the second projection coordinate system and the adjusted three-dimensional projection coordinates of the vertices of the first virtual item.
12 . The electronic device according to claim 8 , wherein the determining a first projection depth map corresponding to the first level based on the first virtual item comprises:
obtaining, for any first level, in response to a related movement amplitude of a virtual object relative to a related level being greater than a movement threshold, a related projection depth map corresponding to the related level, the related level being a second level whose scene range is of a same size as a scene range corresponding to the first level, the related projection depth map being configured for describing distances between a plurality of second vertices and the light source, the plurality of second vertices being each a vertex on a surface of a third virtual item corresponding to the related level facing the light source, and the third virtual item being a virtual item whose shadow is within a scene range corresponding to the related level; and
determining the first projection depth map based on the first virtual item and the related projection depth map.
13 . The electronic device according to claim 8 , wherein the rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map comprises:
determining a first distance between the light source and each of a plurality of candidate vertexes on a surface of a virtual item in the first visible scene facing a camera;
determining, from the plurality of first levels, a reference level corresponding to each candidate vertex;
determining, among the plurality of candidate vertexes, a second distance between the light source and a first vertex from a projection depth map corresponding to the reference level corresponding to the first vertex; and
rendering the shadow at a position of each of the plurality of vertexes in response to the first distance of the candidate being greater than the second distance.
14 . A non-transitory computer-readable storage medium, having at least one computer program stored therein, and the at least one computer program, when loaded and executed by a processor of an electronic device, cause the electronic device to implement a shadow rendering method including: determining scene ranges corresponding to a plurality of first levels, each scene range being a first visible scene range of a virtual scene corresponding to a respective one of the plurality of first levels; for a respective one of the plurality of first levels: determining a first virtual item whose shadow is present in a first visible scene range corresponding to the first level, further including: obtaining reference projection ranges of a plurality of virtual items in the virtual scene in a first projection coordinate system; determining a first projection range of the first level in the first projection coordinate system based on the scene range corresponding to the first level; and determining a virtual item as the first virtual item when the reference projection range of the virtual item and the first projection range intersect; determining a first projection depth map corresponding to the first level based on the first virtual item, the first projection depth map being configured for describing distances between a light source and a plurality of first vertices on a surface of the first virtual item facing the light source; and rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map.
15 . The non-transitory computer-readable storage medium according to claim 14 , wherein the determining a first projection depth map corresponding to the first level based on the first virtual item comprising:
determining three-dimensional projection coordinates of vertices of the first virtual item in a second projection coordinate system based on three-dimensional scene coordinates of the vertices of the first virtual item in a virtual scene coordinate system;
determining an adjustment coefficient based on the scene range corresponding to the first level and a resolution of the first projection depth map;
adjusting the three-dimensional projection coordinates of the vertices of the first virtual item based on the adjustment coefficient, to obtain adjusted three-dimensional projection coordinates of the vertices of the first virtual item; and
determining the first projection depth map based on three-dimensional projection coordinates of the light source in the second projection coordinate system and the adjusted three-dimensional projection coordinates of the vertices of the first virtual item.
16 . The non-transitory computer-readable storage medium according to claim 14 , wherein the determining a first projection depth map corresponding to the first level based on the first virtual item comprises:
obtaining, for any first level, in response to a related movement amplitude of a virtual object relative to a related level being greater than a movement threshold, a related projection depth map corresponding to the related level, the related level being a second level whose scene range is of a same size as a scene range corresponding to the first level, the related projection depth map being configured for describing distances between a plurality of second vertices and the light source, the plurality of second vertices being each a vertex on a surface of a third virtual item corresponding to the related level facing the light source, and the third virtual item being a virtual item whose shadow is within a scene range corresponding to the related level; and
determining the first projection depth map based on the first virtual item and the related projection depth map.
17 . The non-transitory computer-readable storage medium according to claim 14 , wherein the rendering the shadow of the first virtual item in the first visible scene range based on the first projection depth map comprises:
determining a first distance between the light source and each of a plurality of candidate vertexes on a surface of a virtual item in the first visible scene facing a camera;
determining, from the plurality of first levels, a reference level corresponding to each candidate vertex;
determining, among the plurality of candidate vertexes, a second distance between the light source and a first vertex from a projection depth map corresponding to the reference level corresponding to the first vertex; and
rendering the shadow at a position of each of the plurality of vertexes in response to the first distance of the candidate being greater than the second distance.