WO2024093610A1 - 阴影渲染方法、装置、电子设备及可读存储介质 - Google Patents

阴影渲染方法、装置、电子设备及可读存储介质 Download PDF

Info

Publication number
WO2024093610A1
WO2024093610A1 PCT/CN2023/123331 CN2023123331W WO2024093610A1 WO 2024093610 A1 WO2024093610 A1 WO 2024093610A1 CN 2023123331 W CN2023123331 W CN 2023123331W WO 2024093610 A1 WO2024093610 A1 WO 2024093610A1
Authority
WO
WIPO (PCT)
Prior art keywords
scene
virtual object
level
projection
range
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2023/123331
Other languages
English (en)
French (fr)
Inventor
朱洪川
姚巍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology (Shenzhen) Co Ltd
Original Assignee
Tencent Technology (Shenzhen) Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology (Shenzhen) Co Ltd filed Critical Tencent Technology (Shenzhen) Co Ltd
Priority to EP23884542.4A priority Critical patent/EP4553777A4/en
Publication of WO2024093610A1 publication Critical patent/WO2024093610A1/zh
Priority to US18/885,221 priority patent/US12675946B2/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/00—Three-dimensional [3D] image rendering
    • G06T15/50—Lighting effects
    • G06T15/60—Shadow generation
    • A—HUMAN NECESSITIES
    • A63—SPORTS; GAMES; AMUSEMENTS
    • A63F—CARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00—Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/50—Controlling the output signals based on the game progress
    • A63F13/52—Controlling the output signals based on the game progress involving aspects of the displayed game scene
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/00—Three-dimensional [3D] image rendering
    • G06T15/005—General purpose rendering architectures
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/00—Three-dimensional [3D] image rendering
    • G06T15/50—Lighting effects
    • G06T15/80—Shading
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00—Image analysis
    • G06T7/50—Depth or shape recovery
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00—Indexing scheme for image analysis or image enhancement
    • G06T2207/10—Image acquisition modality
    • G06T2207/10028—Range image; Depth image; 3D point clouds
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2215/00—Indexing scheme for image rendering
    • G06T2215/12—Shadow map, environment map

Definitions

  • the embodiments of the present application relate to the field of image rendering technology, and in particular to a shadow rendering method, device, electronic device, and readable storage medium.
  • the shadow map of the virtual object can be stored on a disk.
  • the shadow map of the virtual object can be read from the disk, and the shadow of the virtual object can be rendered in the virtual scene by loading the shadow map of the virtual object.
  • the present application provides a shadow rendering method, device, electronic device and readable storage medium, which can reduce the occupancy of storage resources, improve the performance of shadows and the realism of virtual scenes, and the technical solution includes the following contents.
  • a shadow rendering method is provided, the method being performed by an electronic device, the method comprising:
  • the scene range corresponding to the first level is a range of a first visible scene included in the virtual scene or a local range in the first visible scene
  • any first level among the plurality of first levels based on a scene range corresponding to the any first level, determining a first virtual object corresponding to the any first level, the first virtual object being a virtual object whose shadow is within the scene range corresponding to the any first level;
  • the first projected depth map corresponding to any one of the first levels, the first projected depth map being used to describe distances between a plurality of first vertices and a light source, the plurality of first vertices being vertices on a surface of the first virtual object facing the light source;
  • the shadows in the first visible scene are rendered based on the first projected depth map.
  • a shadow rendering device comprising:
  • a determination module configured to determine scene ranges corresponding to a plurality of first levels, wherein the scene range corresponding to the first level is a range of a first visible scene included in a virtual scene or a local range in the first visible scene;
  • the determining module is further configured to determine, for any first level among the plurality of first levels, a first virtual object corresponding to the any first level based on a scene range corresponding to the any first level, the first virtual object being a virtual object whose shadow is within the scene range corresponding to the any first level;
  • the determination module is further used to determine, based on the first virtual object, a first projected depth map corresponding to any one of the first levels, the first projected depth map being used to describe distances between a plurality of first vertices and a light source, the plurality of first vertices being vertices on a surface of the first virtual object facing the light source;
  • a rendering module is used to render the shadow in the first visible scene based on the first projected depth map.
  • an electronic device comprising a processor and a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor so that the electronic device
  • the sub-device implements any of the shadow rendering methods described above.
  • a non-volatile computer-readable storage medium wherein at least one computer program is stored in the non-volatile computer-readable storage medium, and the at least one computer program is loaded and executed by a processor to enable an electronic device to implement any of the above-mentioned shadow rendering methods.
  • a computer program is also provided.
  • the computer program is at least one, and the at least one computer program is loaded and executed by a processor to enable an electronic device to implement any of the above-mentioned shadow rendering methods.
  • a computer program product is also provided, wherein at least one computer program is stored in the computer program product, and the at least one computer program is loaded and executed by a processor to enable an electronic device to implement any of the above shadow rendering methods.
  • the scene range corresponding to the first level is the range of the first visual scene included in the virtual scene or the local range in the first visual scene, which is equivalent to determining the scene range corresponding to each first level in real time according to the first visual scene during the operation of the virtual scene.
  • the first virtual objects corresponding to each first level are determined by the scene range corresponding to each first level, and the projection depth maps corresponding to each first level are determined based on the first virtual objects corresponding to each first level, so as to achieve the real-time determination of the global range of the first visual scene and the projection depth maps corresponding to each local range during the operation of the virtual scene.
  • the occupancy of storage resources can be reduced.
  • the shadows in the first visual scene are rendered by the projection depth maps corresponding to the global range of the first visual scene and each local range, which is conducive to improving the performance effect of the shadows and the fidelity of the virtual scene on the basis of achieving real-time update of the shadows.
  • FIG1 is a schematic diagram of an implementation environment of a shadow rendering method provided in an embodiment of the present application.
  • FIG2 is a flow chart of a shadow rendering method provided by an embodiment of the present application.
  • FIG3 is a schematic diagram of a viewing cone provided in an embodiment of the present application.
  • FIG4 is a schematic diagram of a first level provided by an embodiment of the present application.
  • FIG5 is a schematic diagram of a projection provided by an embodiment of the present application.
  • FIG6 is a schematic diagram of a projection and a bounding box of the projection provided in an embodiment of the present application.
  • FIG. 7 is a schematic diagram of the relationship between a reference projection range of a virtual object and a first projection range of a first level provided by an embodiment of the present application;
  • FIG8 is a schematic diagram of a projected depth map provided in an embodiment of the present application.
  • FIG9 is a schematic diagram of determining a projected depth map provided in an embodiment of the present application.
  • FIG10 is a schematic diagram of the relationship between a first visible scene and a projected depth map provided in an embodiment of the present application
  • FIG11 is a flowchart of a method for rendering a first visual scene provided in an embodiment of the present application.
  • FIG12 is a schematic diagram of a first visible scene without shadows provided in an embodiment of the present application.
  • FIG13 is a schematic diagram of a first visible scene with a shadow provided in an embodiment of the present application.
  • FIG14 is a schematic diagram of the structure of a shadow rendering device provided in an embodiment of the present application.
  • FIG15 is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application.
  • FIG. 16 is a schematic diagram of the structure of a server provided in an embodiment of the present application.
  • FIG1 is a schematic diagram of an implementation environment of a shadow rendering method provided in an embodiment of the present application.
  • the implementation environment includes a terminal device 101 and a server 102.
  • the shadow rendering method in the embodiment of the present application can be executed by the terminal device 101, or by the server 102, or by the terminal device 101 and the server 102 together.
  • the terminal device 101 may be a smart phone, a game console, a desktop computer, a tablet computer, a laptop computer, a smart TV, a smart car device, a smart voice interaction device, a smart home appliance, etc.
  • the server 102 may be a server, Or it can be a server cluster composed of multiple servers, or it can be any one of a cloud computing platform and a virtualization center, which is not limited in the embodiments of the present application.
  • the server 102 can be connected to the terminal device 101 through a wired network or a wireless network.
  • the server 102 can have functions such as data processing, data storage, and data transmission and reception, which are not limited in the embodiments of the present application.
  • the number of terminal devices 101 and servers 102 is not limited, and can be one or more.
  • the shadow map of the virtual object is read from the disk, and the shadow of the virtual object is rendered in the virtual scene by loading the shadow map of the virtual object.
  • the embodiment of the present application provides a shadow rendering method, which can be applied in the above implementation environment, can reduce the occupancy of storage resources, and improve the shadow performance effect in the visual scene.
  • a shadow rendering method provided by the embodiment of the present application shown in Figure 2 as an example, for the convenience of description, the terminal device 101 or server 102 that executes the shadow rendering method in the embodiment of the present application is referred to as an electronic device, and the method can be executed by an electronic device.
  • the method includes the following steps.
  • Step 201 determining a plurality of scene ranges corresponding to the first level, wherein the scene range corresponding to the first level is a range of a first visible scene included in the virtual scene or a local range in the first visible scene.
  • step 201 In order to facilitate understanding of step 201, the technical terms involved are first explained and illustrated below.
  • Virtual scenes are scenes built using 3D modeling technology and are applicable to multiple industries.
  • 3D modeling technology is often used to build game maps containing objects such as trees, houses, lakes, cliffs, etc., and the game maps are virtual scenes.
  • 3D modeling technology can be used to build indoor scenes containing objects such as desks, wardrobes, electrical appliances, and kitchen utensils, and the indoor scenes are also virtual scenes.
  • the visible scene refers to the portion of the virtual scene that is within the viewing cone when the virtual scene is photographed by a camera.
  • the view frustum is the cone range of a visible area with the coordinate origin as the optical center in the camera coordinate system. It has 6 surfaces, namely the upper surface, lower surface, left surface, right surface, near surface and far surface. Objects within the view frustum are objects that can be photographed by the camera, while objects outside the view frustum are objects that cannot be photographed by the camera. Electronic devices can cut out objects outside the view frustum and only render objects within the view frustum. It is understandable that when cutting an object, the entire object can be cut out, or a part of the object can be cut out. By cutting out objects outside the view frustum, the content that needs to be rendered is reduced and the rendering performance is improved.
  • Figure 3 is a schematic diagram of a viewing cone provided by an embodiment of the present application.
  • the viewing cone is a cone range with a total of 6 surfaces. The part of the object outside the viewing cone is cut off to obtain a cropped object, and the cropped object is located inside the viewing cone.
  • the shadows in the visual scene need to be re-rendered.
  • the visual scene and the shadows in the visual scene are updated together.
  • the shadows in the visual scene also need to be changed due to the presence of different virtual objects in different visual scenes.
  • the visual scene after the shadow update is recorded as the first visual scene, and the visual scene before the shadow update is recorded as the second visual scene.
  • the electronic device needs to obtain the scene ranges corresponding to the multiple first levels obtained after dividing the first visual scene.
  • One first level corresponds to one scene range.
  • the scene range corresponding to any first level is the range of the first visual scene or the range of a local scene in the first visual scene.
  • the level can also be called a hierarchy or a grade.
  • the level can be represented by the range size, or the level can be divided by the range size.
  • the range sizes of different levels are different, but the center point (or center of gravity) can be the same.
  • the range size of the first level as X the scene range corresponding to the first level is the scene range with a range size of X.
  • the embodiment of the present application is not limited to the division method of the first visual scene.
  • the first visual scene is divided according to implementation method A1 or implementation method A2.
  • the center point of a hierarchy is the geometric center of the scene range corresponding to the hierarchy
  • the center of gravity of a hierarchy is the point where the scene range corresponding to the hierarchy is acted upon by gravity.
  • the embodiments of the present application do not limit the method for determining the center point of a hierarchy and the center of gravity of a hierarchy. All embodiments of the present application are applicable to both the center point and the center of gravity, that is, the two can be interchanged in all embodiments.
  • step 201 includes: evenly dividing the first visible scene into a plurality of local scenes of the same area and shape, and the range of a local scene or the range of the first visible scene is a scene range corresponding to a first level.
  • step 201 includes: obtaining the range size of each first level; for any first level, based on the reference point of the first visible scene and the range size of any first level, determining the scene range corresponding to any first level in the first visible scene.
  • multiple first levels can be regarded as levels with an upper and lower hierarchical relationship.
  • the range size of the previous first level is smaller than the range size of the next first level.
  • the position of the virtual object in the first visual scene can be used as the reference point of the first visual scene, or the center point or center of gravity of the first visual scene can be used as the reference point of the first visual scene.
  • the reference point of the first visual scene is used as the center point or center of gravity of any first level, and the first visual scene is divided based on the range size of the first level, and the range of the divided local scene is the scene range corresponding to the first level.
  • the scene range corresponding to the first level is a scene range with a side length of 32 meters centered on the position of the virtual object
  • the scene range corresponding to the second level is a scene range with a side length of 64 meters centered on the position of the virtual object, and so on.
  • the electronic device can store the scene range corresponding to each first level.
  • the electronic device can store the center point (or center of gravity) of the scene range corresponding to the first level and the range size of the first level.
  • the electronic device can store the coordinates of each point of the rectangle, or the electronic device can store the four boundaries of the rectangle (the storage code is shown below) to store the scene range corresponding to the first level.
  • the center point of each first level is the reference point of the first visible scene, so the center point of each first level is the same, or the center of gravity of each first level is the reference point of the first visible scene, so the center of gravity of each first level is the same. Since the range size of the previous first level is smaller than the range size of the next first level, the scene ranges corresponding to the multiple first levels can be regarded as a group of scene ranges with gradually increasing range sizes.
  • a clip map refers to a set of data with the same center point or the same center of gravity, but the coverage range is doubled level by level, and the data includes but is not limited to maps.
  • the data can be a local scene of a virtual scene.
  • the scene range corresponding to multiple first levels is a set of scenes with the same center point or the same center of gravity, and the range size is doubled level by level. Based on this, the scene range corresponding to each first level is also called a Clipmap.
  • Figure 4 is a schematic diagram of a first level provided in an embodiment of the present application.
  • (1) in Figure 4 shows the range size of the first level 0 to the first level 3 having an upper and lower hierarchical relationship, and the range size of the previous first level is smaller than the range size of the next first level.
  • (2) in Figure 4 shows a top view of the range size of the first level 0 to the first level 3, and the four range sizes from the inside to the outside are the range sizes of the first level 0 to the first level 3 respectively.
  • step 201 includes: in response to satisfying a shadow update condition, determining scene ranges corresponding to a plurality of first levels, wherein satisfying the shadow update condition includes at least one of cases B1 to B3.
  • Case B1 The virtual object moves in the virtual scene.
  • a virtual object is an object modeled by three-dimensional modeling technology.
  • the embodiment of the present application does not limit the appearance of the virtual object.
  • the virtual object can be in the form of a person, an animal, a cartoon, etc.
  • a virtual object can be controlled by a user or by a computer program. For example, in a game scene, the user controls the game character and the computer program controls the game monster. Both the game character and the game monster are virtual objects.
  • the electronic device determines that the shadow update condition is met. In this case, the shadow in the visible scene needs to be updated.
  • the visible scene is updated with the movement of the virtual object, thereby causing the shadow in the visible scene to be updated accordingly.
  • step 201 when the virtual object moves in the virtual scene, the movement information of the virtual object and the scene ranges corresponding to the multiple second levels are obtained, the scene range corresponding to the second level is the range of the second visual scene included in the virtual scene or the local range in the second visual scene, the first visual scene is the visual scene after the virtual object moves, and the second visual scene is the visual scene before the virtual object moves; for any second level, based on the movement information of the virtual object and the scene range corresponding to any second level, the second movement amplitude of the virtual object relative to any second level is determined; in response to the existence of a target level among the multiple second levels, it is determined that the shadow update condition is met, and the target movement amplitude of the virtual object relative to the target level is greater than the movement threshold.
  • the electronic device can obtain the movement information of the virtual object.
  • the movement information of the virtual object is the trajectory of the virtual object's movement, including multiple trajectory points. Any trajectory point corresponds to a three-dimensional coordinate and a time, the three-dimensional coordinate of the trajectory point represents the position of the trajectory point in the virtual scene, and the time of the trajectory point represents the time when the virtual object arrives at the trajectory point.
  • the movement information of the virtual object includes at least one of the moving starting point, moving direction, moving distance, and moving end point.
  • the visual scene may be updated as the virtual object moves.
  • the visual scene before the virtual object moves is the visual scene before the update, also called the second visual scene;
  • the visual scene after the virtual object moves is the visual scene after the update, also called the first visual scene.
  • the second visual scene is divided into scene ranges corresponding to multiple second levels, one second level corresponds to one scene range, there are multiple second levels, and there are also multiple scene ranges.
  • the electronic device can directly obtain the scene ranges corresponding to each second level.
  • the content of the scene range corresponding to any second level is similar to the content of the scene range corresponding to any first level, which can be seen in the description of implementation methods A1 and A2, and will not be repeated here.
  • first level in the plurality of first levels that has the same range size as any second level.
  • range sizes of the plurality of first levels in a hierarchical relationship and the range sizes of the plurality of second levels in a hierarchical relationship are sequentially the same.
  • the moving distance of the virtual object can be determined based on the movement information of the virtual object.
  • the moving distance of the virtual object can be determined based on the first and last track points of the multiple track points included in the moving track of the virtual object, or the moving distance of the virtual object can be extracted from the movement information of the virtual object.
  • the ratio between the moving distance of the virtual object and the range size of the scene range corresponding to any second level can be calculated, and the ratio is used as the movement amplitude of the virtual object relative to the second level. If there is a target level among the multiple second levels, and the movement amplitude of the virtual object relative to the target level is greater than the movement threshold, the electronic device determines that the shadow update condition is met.
  • the movement amplitude of the virtual object relative to the second level is referred to as the second movement amplitude
  • the movement amplitude of the virtual object relative to the target level is referred to as the target movement amplitude. That is, the electronic device can determine multiple second movement amplitudes. If a second movement amplitude is greater than the movement threshold, the second level corresponding to the second movement amplitude is the target level. The target level is the second movement amplitude, and the second movement amplitude is the target movement amplitude. If the target level exists, the electronic device determines that the shadow update condition is met. That is, if the second movement amplitude exists and is greater than the movement threshold, the electronic device determines that the shadow update condition is met.
  • the embodiment of the present application does not limit the content of the moving threshold.
  • the moving threshold is manually determined data. Since the second moving amplitude is the ratio between the moving distance of the virtual object and the range size of the scene range corresponding to the second level, the moving threshold is also a ratio, for example, the moving threshold is 10%.
  • Shadows are closely related to lighting.
  • the electronic device can determine that the shadow update conditions are met. Changes in the lighting of the virtual scene include changes in the direction of the lighting in the virtual scene, changes in the distance between the lighting and the virtual object in the virtual scene, etc. For example, changing a point light source into a parallel light will cause the lighting direction to change, or the distance between the point light source and the virtual object in the virtual scene will become smaller.
  • initializing the virtual scene may be setting the virtual scene to a default state. For example, when starting a game, the electronic device may initialize the virtual scene. When initializing the virtual scene, since it is necessary to render virtual objects and shadows of virtual objects in the virtual scene, the electronic device may determine that the shadow update condition is satisfied.
  • Step 202 for any first level among the multiple first levels, based on the scene range corresponding to any first level, determine a first virtual object corresponding to any first level, where the first virtual object is a virtual object whose shadow is within the scene range corresponding to any first level.
  • the virtual object since light has the characteristic of rectilinear propagation, when light encounters an opaque virtual object, a dark area will be formed because it cannot pass through the virtual object.
  • the dark area is the shadow of the virtual object.
  • the virtual object is the first virtual object corresponding to the first level.
  • the first level corresponds to at least one first virtual object.
  • step 202 includes steps 2021 to 2023.
  • Step 2021 Obtain a reference projection range of a plurality of virtual objects in the virtual scene in a first projection coordinate system.
  • the multiple virtual objects in the virtual scene may be all virtual objects in the virtual scene, or may be some virtual objects selected from all virtual objects in the virtual scene, and the selected virtual objects may be referred to as candidate virtual objects corresponding to any first level.
  • the following describes a method for determining a candidate virtual object corresponding to any first level.
  • the method further includes: expanding the scene range corresponding to any first level based on the expansion parameter to obtain a reference range corresponding to any first level; and selecting a plurality of virtual objects within the reference range.
  • the extension parameter may be an extension ratio, and the extension ratio is greater than 1.
  • the range size of the scene range corresponding to the first level is multiplied by the extension ratio to obtain the range size of the reference range corresponding to the first level.
  • the extension parameter may be an extended scene range. In this case, the scene range corresponding to the first level is added to the extended scene range to obtain the reference range corresponding to the first level.
  • a virtual object located within a reference range corresponding to any first level is selected from all virtual objects in the virtual scene, and the selected virtual object is used as a candidate virtual object corresponding to the first level.
  • the candidate virtual objects corresponding to the first level are also the multiple virtual objects in the virtual scene mentioned in step 2021.
  • any virtual object in the virtual scene is projected into the first projection coordinate system to obtain a reference projection range of the virtual object in the first projection coordinate system.
  • the reference projection range of the virtual object in the first projection coordinate system is referred to as the reference projection range of the virtual object.
  • the reference projection range of the virtual object is used to describe the projection of the virtual object in the first projection coordinate system.
  • the first projection coordinate system is used to define the first projection space, and the reference projection range of the virtual object is equivalent to the reference projection range of the virtual object on the projection plane of the first projection space.
  • the light source in the first projection space can be average light, point light source, etc. The embodiment of the present application does not limit the projection method of the virtual object.
  • step 2021 includes steps C1 to C3.
  • Step C1 for any virtual object, determine the bounding box of any virtual object.
  • virtual objects may be irregular in shape and relatively complex in structure, while bounding boxes are regular in shape and relatively simple in structure, by determining the bounding box of the virtual object, the complex three-dimensional structure corresponding to the virtual object is simplified to a simple three-dimensional structure corresponding to the bounding box, thereby reducing the amount of data and structural complexity, and providing a basis for simplifying subsequent data processing.
  • the triangular mesh data of a virtual object is often used to describe the virtual object.
  • the triangular mesh data of a virtual object includes data of multiple vertices, and the data of any vertex includes the identifier of the vertex, the three-dimensional coordinates of the vertex in the virtual scene coordinate system, the identifiers of other vertices connected to the vertex, etc.
  • the bounding box of the virtual object can be determined by the triangular mesh data of the virtual object.
  • the bounding box of the virtual object is the smallest geometric body that can enclose the virtual object, wherein the geometric body can be a hexahedron, a cylinder, a sphere, etc.
  • the virtual scene coordinate system includes a horizontal axis (i.e., an x-axis), a vertical axis (i.e., a y-axis), and a vertical axis (i.e., a z-axis).
  • the smallest vertex in the horizontal axis, the largest vertex in the horizontal axis, the smallest vertex in the vertical axis, the largest vertex in the vertical axis, the smallest vertex in the vertical axis, and the largest vertex in the vertical axis can be determined from the triangular mesh data of the virtual object.
  • Six planes can be determined using these six vertices, thereby obtaining the smallest hexahedron surrounding the virtual object, that is, obtaining the bounding box of the virtual object.
  • the principal component analysis (PCA) method can be used to analyze the triangular mesh data of the virtual object to determine the directions of the three coordinate axes, the lengths of the three sides, the coordinates of the center point and other information. Determining this information is equivalent to determining the bounding box of the virtual object.
  • PCA principal component analysis
  • the PCA method can be used to find a set of mutually orthogonal coordinate axes in three-dimensional space to obtain the directions of the three coordinate axes of the bounding box of the virtual object.
  • the direction of the first coordinate axis satisfies that the variance of each projected vertex is the largest when each vertex corresponding to the virtual object is projected after the coordinate axis;
  • the direction of the second coordinate axis satisfies that the variance of each projected vertex is the largest when each vertex corresponding to the virtual object is projected after the coordinate axis in a plane orthogonal to the first coordinate axis;
  • the direction of the third coordinate axis satisfies that the variance of each projected vertex is the largest when each vertex corresponding to the virtual object is projected after the coordinate axis in a plane orthogonal to the first two coordinate axes.
  • the coordinates of the center point of the virtual object can be obtained by averaging the three-dimensional coordinates of each vertex corresponding to the virtual object, and the coordinates of the center point of the virtual object are used as the coordinates of the center point of the bounding box of the virtual object.
  • the lengths of the three sides of the bounding box of the virtual object are determined based on the distribution of each vertex corresponding to the virtual object on the three coordinate axes.
  • Step C2 determining first projection information of any virtual object based on the bounding box, where the first projection information is used to describe the projection of the bounding box in the first projection coordinate system.
  • the data volume of the bounding box of the virtual object is smaller than the data volume of the virtual object, and the three-dimensional structure of the bounding box of the virtual object is simpler than the three-dimensional structure of the virtual object. Therefore, compared with the data describing the projection of the virtual object in the first projection coordinate system, the first projection information of the virtual object is determined by the bounding box of the virtual object, which realizes the determination of the approximate projection range of the virtual object based on a small amount of data and a simple three-dimensional structure, improves the processing speed, and is conducive to improving the rendering efficiency.
  • the bounding box of any virtual object in the virtual scene is projected into the first projection coordinate system to obtain the projection of the bounding box of the virtual object in the first projection coordinate system, thereby obtaining the first projection information of the virtual object.
  • the bounding box of the virtual object includes multiple vertices, the bounding box of the virtual object can be described by the coordinates of each vertex in the virtual scene coordinate system.
  • the coordinates of each vertex in the virtual scene coordinate system are converted into the coordinates of each vertex in the first projection coordinate system to obtain the first projection information of the virtual object.
  • the projection of the bounding box of the virtual object in the first projection coordinate system is equivalent to the projection of the virtual object on the projection plane of the first projection space.
  • Figure 5 is a schematic diagram of a projection provided by an embodiment of the present application.
  • the light source in the projection space is parallel light.
  • the bounding box of the virtual object in the virtual scene is projected onto the projection surface of the projection space to obtain the projection of the bounding box of the virtual object on the projection surface.
  • Figure 6 is a schematic diagram of a projection and a projected bounding box provided by an embodiment of the present application.
  • the left side of Figure 6 shows the projection of the bounding box of the virtual object, which is the projection of the bounding box of the virtual object on the projection surface of the projection space.
  • Step C3 determining a reference projection range of any virtual object based on the first projection information.
  • the first projection information of the virtual object is determined as a reference projection range of the virtual object in the first projection coordinate system.
  • the reference projection range of the virtual object in the first projection coordinate system is used to describe the bounding box of the virtual object in the first projection coordinate system. Projection in a projected coordinate system.
  • step C3 includes: determining second projection information of any virtual object based on the first projection information, the second projection information being used to describe a bounding box of a projection of the bounding box in the first projection coordinate system; and determining the second projection information as a reference projection range of any virtual object.
  • the projection may be an irregular shape with a relatively complex structure
  • the bounding box is a regular shape with a relatively simple structure
  • the bounding box of the virtual object includes a plurality of vertices
  • the first projection information of the virtual object may include the coordinates of each vertex in the first projection coordinate system.
  • the first projection coordinate system is a three-dimensional coordinate system, including a horizontal axis, a vertical axis, and a vertical axis, wherein the coordinates of each vertex in the first projection coordinate system correspond to the same vertical axis value, and therefore, each vertex is located on a plane perpendicular to the vertical axis in the first projection coordinate system.
  • the vertex with the smallest horizontal axis, the vertex with the largest horizontal axis, the vertex with the smallest vertical axis, and the vertex with the largest vertical axis can be determined from the plurality of vertices. Since a bounding box can be determined based on these four vertices, the coordinates of these four vertices in the first projection coordinate system can be used as the second projection information of the virtual object, so as to use the second projection information of the virtual object to describe the bounding box of the virtual object in the first projection coordinate system. Among them, see FIG. 6, the right side of FIG. 6 shows the bounding box of the projection of the bounding box of the virtual object, which is the projection of the bounding box of the virtual object in the first projection coordinate system.
  • the second projection information of any virtual object can be determined as the reference projection range of the virtual object in the first projection coordinate system.
  • the reference projection range of the virtual object in the first projection coordinate system is used to describe the bounding box of the virtual object projected in the first projection coordinate system.
  • the bounding box of the virtual object projected in the first projection coordinate system is a rectangle.
  • the reference projection range of the virtual object can be the coordinates of four vertices, or the four boundaries of the rectangle, etc.
  • Step 2022 Determine a first projection range of any first level in the first projection coordinate system based on a scene range corresponding to any first level.
  • the scene range corresponding to the first level is a local range in the first visible scene
  • the scene range corresponding to the first level is relative to the virtual scene coordinate system.
  • the reference projection range of the virtual object is relative to the first projection coordinate system
  • the first projection range of the first level in the first projection coordinate system can be determined based on the scene range corresponding to any first level, so that the first projection range corresponding to the first level and the reference projection range of the virtual object are placed in the same coordinate system for subsequent processing.
  • the scene range corresponding to any first level is projected into the first projection coordinate system to obtain the projection of the scene range corresponding to the first level in the first projection coordinate system, thereby obtaining the first projection range of the first level in the first projection coordinate system.
  • the scene range corresponding to the first level is a rectangle.
  • the coordinates of each vertex of the rectangle in the virtual scene coordinate system can be converted into the coordinates of each vertex in the first projection coordinate system, or the boundaries of the rectangle in the virtual scene coordinate system can be converted into the boundaries in the first projection coordinate system to obtain the first projection range of the first level in the first projection coordinate system.
  • Step 2023 For any virtual object, if the reference projection range of any virtual object and the first projection range overlap, then any virtual object is determined as the first virtual object.
  • the reference projection range of any virtual object in the first projection coordinate system is used to describe the approximate projection area of the virtual object in the first projection coordinate system
  • the first projection range of any first level in the first projection coordinate system is used to describe the projection of the scene range corresponding to the first level in the first projection coordinate system. Therefore, it can be determined whether the reference projection range of any virtual object in the first projection coordinate system and the first projection range of any first level in the first projection coordinate system are contained.
  • the reference projection range of any virtual object in the first projection coordinate system When the reference projection range of any virtual object in the first projection coordinate system is fully or partially included in the first projection range of any first level in the first projection coordinate system, it means that the reference projection range of the virtual object in the first projection coordinate system and the first projection range of the first level in the first projection coordinate system intersect, and the virtual object will be projected on the corresponding level in the first level. Therefore, the virtual object can be determined as the first virtual object corresponding to the first level.
  • Figure 7 is a schematic diagram of the relationship between a reference projection range of a virtual object and a first projection range of a first level provided in an embodiment of the present application.
  • Figure 7 shows four first-level first projection ranges, which are the first to fourth first-level first projection ranges from the inside to the outside, and also shows the reference projection ranges of nine virtual objects.
  • the first projection range of the first first level intersects with the reference projection ranges of the two virtual objects, and the first virtual objects corresponding to the first first level are two virtual objects.
  • the first virtual objects corresponding to the second first level are three virtual objects; the first virtual objects corresponding to the third first level are five virtual objects; and the first virtual objects corresponding to the fourth first level are nine virtual objects.
  • any first level corresponds to at least one first virtual object
  • a virtual object list can be created for any first level.
  • the virtual object list corresponding to any first level includes identification information of each first virtual object corresponding to the first level, and the corresponding first virtual object can be found through any identification information.
  • the embodiment of the present application determines whether the virtual object is the first virtual object corresponding to the first level by determining the intersection relationship between the projection of the scene range corresponding to the first level and the projection of the bounding box of the virtual object.
  • the bounding box of the virtual object is a simple three-dimensional structure, and the projection of the bounding box has a smaller amount of data and a simpler structure;
  • the scene range corresponding to the first level is also a simple structure, and its projection has a smaller amount of data and a simpler structure. Therefore, compared with directly judging whether the virtual object is within the viewing cone, the embodiment of the present application can quickly judge whether the virtual object is the first virtual object corresponding to the first level based on a simple structure and a smaller amount of data, thereby improving computing performance.
  • Step 203 Based on the first virtual object, determine a first projected depth map corresponding to any first level, where the first projected depth map is used to describe the distances between a plurality of first vertices and the light source, where the plurality of first vertices are vertices on the surface of the first virtual object facing the light source.
  • the projection depth map corresponding to the first level can be determined based on the light source in the second projection space and the first virtual object corresponding to any first level.
  • the projection depth map corresponding to any first level is referred to as the first projection depth map.
  • the first virtual object corresponding to any first level can be rendered along the illumination direction of the light source in the second projection space to obtain the distance between each vertex on the surface of the first virtual object facing the light source and the light source.
  • the distance between any vertex and the light source is also referred to as the projection depth value of the vertex
  • the first projection depth map includes the projection depth values of each first vertex (i.e., the vertices on the surface of the first virtual object facing the light source).
  • the projection depth map corresponding to a first level records the projection depth value within a certain range.
  • the projection depth map corresponding to the first first level (recorded as Level0) records the projection depth value within 32 meters
  • the projection depth map corresponding to the second first level (recorded as Level1) records the projection depth value within 64 meters
  • the projection depth map corresponding to the third first level (recorded as Level2) records the projection depth value within 128 meters, and so on, until the maximum range size.
  • the projected depth maps corresponding to each first level can be considered as an atlas.
  • a Render Texture object can be configured to save the atlas. Please refer to Figure 8, which shows a projected depth map corresponding to the first level on the left side and an atlas on the right side, which includes six projected depth maps corresponding to the first level.
  • the projected depth map shown on the left side of Figure 8 is a projected depth map in the atlas shown on the right side of Figure 8.
  • step 203 includes steps 2031 to 2034 .
  • Step 2031 determining the three-dimensional projection coordinates of each vertex of the first virtual object in the second projection coordinate system based on the three-dimensional scene coordinates of each vertex of the first virtual object in the virtual scene coordinate system.
  • the three-dimensional coordinates of the vertex in the virtual scene coordinate system are referred to as the three-dimensional scene coordinates of the vertex
  • the three-dimensional coordinates of the vertex in the second projection coordinate system are referred to as the three-dimensional projection coordinates of the vertex.
  • the three-dimensional scene coordinates of each vertex of the first virtual object corresponding to any first level can be converted to the three-dimensional projection coordinates of each vertex of the first virtual object corresponding to the first level.
  • the embodiment of the present application does not limit the above conversion relationship.
  • Step 2032 Determine an adjustment coefficient based on a scene range corresponding to any first level and a resolution of the first projected depth map.
  • the ratio of the range size of the scene range corresponding to any first level to the resolution of the projected depth map corresponding to the first level is used as an adjustment coefficient, or the comparison value is subjected to at least one calculation such as weighted, logarithmic, exponential, etc. to obtain the adjustment coefficient.
  • Step 2033 adjust the three-dimensional projection coordinates of each vertex of the first virtual object based on the adjustment coefficient to obtain the adjusted three-dimensional projection coordinates of each vertex of the first virtual object.
  • the three-dimensional coordinates of the vertex adjusted in the second projection coordinate system are referred to as the three-dimensional projection coordinates of the vertex after adjustment.
  • the three-dimensional projection coordinates of the vertex can be used as the dividend, and the adjustment coefficient can be used as the divisor.
  • the quotient can be obtained, and the quotient is multiplied by the adjustment coefficient to obtain the three-dimensional projection coordinates of the vertex after adjustment.
  • an embodiment of the present application adjusts the three-dimensional projection coordinates of the vertex according to the three-dimensional coordinate adjustment code as shown below to obtain adjusted three-dimensional projection coordinates, thereby realizing rounding and alignment of the three-dimensional coordinates by pixels when converting the second projection coordinate system and the virtual scene coordinate system.
  • meterPerPixel represents the adjustment coefficient.
  • Mathf.Floor is a function that represents the search for the maximum integer, where the maximum integer found is less than or equal to the specified floating-point value, so Mathf.Floor(pos.x/meterPerPixel) represents the quotient.
  • Mathf.Floor(pos.x/meterPerPixel) represents the quotient.
  • Similar adjustments are made to the vertical axis value pos.y and the vertical axis value pos.z.
  • the adjusted three-dimensional projection coordinates of the vertex include the adjusted horizontal axis value pos.x, the adjusted vertical axis value pos.y and the adjusted vertical axis value pos.z.
  • Step 2034 determine a first projection depth map based on the three-dimensional projection coordinates of the light source in the second projection coordinate system and the adjusted three-dimensional projection coordinates of each vertex of the first virtual object.
  • the three-dimensional coordinates of the light source in the virtual scene coordinate system are referred to as the three-dimensional scene coordinates of the light source
  • the three-dimensional coordinates of the light source in the second projection coordinate system are referred to as the three-dimensional projection coordinates of the light source.
  • the three-dimensional coordinates of the reference point in the virtual scene coordinate system are referred to as the three-dimensional scene coordinates of the reference point
  • the three-dimensional coordinates of the reference point adjusted in the virtual scene coordinate system are referred to as the three-dimensional scene coordinates of the reference point adjusted.
  • the three-dimensional coordinates of the reference point in the second projection coordinate system are referred to as the three-dimensional projection coordinates of the reference point, and the three-dimensional coordinates of the reference point adjusted in the second projection coordinate system are referred to as the three-dimensional projection coordinates of the reference point adjusted.
  • the three-dimensional scene coordinates of the reference point can be used as the three-dimensional scene coordinates of the light source, and the three-dimensional scene coordinates of the light source can be converted into the three-dimensional scene coordinates of the light source.
  • the three-dimensional scene coordinates of the reference point can be converted into the three-dimensional projection coordinates of the reference point.
  • the three-dimensional projection coordinates of the reference point are adjusted to obtain the adjusted three-dimensional projection coordinates of the reference point.
  • the adjusted three-dimensional projection coordinates of the reference point are converted into the adjusted three-dimensional scene coordinates of the reference point.
  • the three-dimensional scene coordinates of the light source are set to the adjusted three-dimensional scene coordinates of the reference point.
  • the three-dimensional scene coordinates of the light source are converted into three-dimensional projection coordinates of the light source, and the three-dimensional projection coordinates of each vertex of the first virtual object corresponding to any first level are adjusted based on the three-dimensional projection coordinates of the light source and the three-dimensional projection coordinates of each vertex of the first virtual object corresponding to any first level are determined.
  • the first projected depth map corresponding to the level is determined.
  • the distance between the vertex and the light source can be calculated using the three-dimensional projection coordinates of the light source and the adjusted three-dimensional projection coordinates of the vertex, and the distance is also the projection depth value of the vertex.
  • the projection depth values of each first vertex are selected from the projection depth values of each vertex, thereby obtaining the first projection depth map corresponding to the first level.
  • the first vertex is the vertex on the surface of the first virtual object facing the light source, and the first projection depth map records the projection depth values of each first vertex of the first virtual object corresponding to the first level.
  • the adjusted three-dimensional projection coordinates of each first vertex are determined from the adjusted three-dimensional projection coordinates of each vertex of the first virtual object corresponding to any first level.
  • the distance between each first vertex and the light source is determined by the adjusted three-dimensional projection coordinates of each first vertex and the three-dimensional projection coordinates of the light source, thereby obtaining the first projection depth map corresponding to any first level.
  • step 2034 includes: adjusting the three-dimensional projection coordinates of the light source based on the adjustment coefficient to obtain the adjusted three-dimensional projection coordinates of the light source, and determining the first projection depth map based on the adjusted three-dimensional projection coordinates of the light source and the adjusted three-dimensional projection coordinates of each vertex of the first virtual object.
  • the method for adjusting the three-dimensional projection coordinates of the light source can be seen in the description of step 2033, which will not be repeated here.
  • the three-dimensional projection coordinates of the light source can be used as the dividend, and the adjustment coefficient can be used as the divisor.
  • the quotient can be obtained, and the quotient is multiplied by the adjustment coefficient to obtain the three-dimensional projection coordinates of the light source after adjustment.
  • the three-dimensional projection coordinates after the light source is adjusted are determined according to steps E1 to E8 as shown below.
  • Step E1 obtaining the three-dimensional scene coordinates Pos of the reference point, wherein the reference point may be the center point or the center of gravity of any scene range corresponding to the first level.
  • Step E2 obtaining the rotation matrix lightMatrix of the light source, where the rotation matrix includes the illumination direction of the light source and the initialization coordinates of the light source.
  • Step E3 converting Pos to PosInLight, where PosInLight is the three-dimensional projection coordinate of the reference point.
  • Step E5 using the inverse matrix of lightMatrix to convert PosInLight to PosInWorld, where PosInWorld is the three-dimensional scene coordinate after the reference point is adjusted.
  • Step E6 assigning PosInWorld to the initialization coordinates of the light source in lightMatrix.
  • Step E6 is equivalent to adjusting the initialization coordinates of the light source to PosInWorld, that is, the three-dimensional scene coordinates of the light source are set to PosInWorld.
  • Step E7 calculating the inverse matrix lightMatrixInverse of lightMatrix. Step E7 is equivalent to converting the three-dimensional scene coordinates of the light source into the three-dimensional projection coordinates of the light source, and the illumination direction of the light source remains unchanged.
  • Step E8 using PositionAlignment to align the coordinate values in lightMatrixInverse to obtain the final projection matrix.
  • PositionAlignment is the three-dimensional coordinate adjustment code mentioned above. Therefore, step E8 is equivalent to adjusting the three-dimensional projection coordinates of the light source to obtain the adjusted three-dimensional projection coordinates of the light source.
  • the distance between the vertex and the light source can be calculated using the adjusted three-dimensional projection coordinates of the light source and the adjusted three-dimensional projection coordinates of the vertex, and the distance is also the projection depth value of the vertex.
  • the projection depth value of each first vertex can be used to obtain the first projection depth map corresponding to the first level.
  • the adjusted three-dimensional projection coordinates of each first vertex are determined from the adjusted three-dimensional projection coordinates of each vertex of the first virtual object corresponding to any first level.
  • the distance between each first vertex and the light source is determined by the adjusted three-dimensional projection coordinates of each first vertex and the adjusted three-dimensional projection coordinates of the light source, thereby obtaining the first projection depth map corresponding to any first level.
  • the 3D coordinate adjustment code is used to adjust the 3D projection coordinates of the vertices and light sources to obtain the adjusted 3D projection coordinates, which realizes the conversion of the 3D coordinates in pixels when the second projection coordinate system and the virtual scene coordinate system are converted. Rounding and aligning. Due to the alignment operation, when the first visual scene is transformed, for example, the first visual scene is rotated or translated, the shadow of a virtual object in the first visual scene before the transformation can be made the same as the shadow of the virtual object in the first visual scene after the transformation, that is, the shadow does not shake when the first visual scene is transformed, thereby improving the authenticity of the first visual scene.
  • step 203 includes steps 2035 to 2036.
  • the above steps 2031 to 2034 use the shadows of all virtual objects in the scene range corresponding to any first level to directly project the first projection depth map corresponding to the first level, which belongs to the global update method.
  • Steps 2035 to 2036 are based on the local update method to determine the first projection depth map corresponding to the first level. The following describes each step of steps 2035 to 2036 in detail.
  • Step 2035 for any first level, in response to the relevant movement amplitude of the virtual object relative to the relevant level being greater than the movement threshold, obtain a relevant projection depth map corresponding to the relevant level, the relevant level being a second level having a scene range having the same size as the scene range corresponding to any first level, the relevant projection depth map being used to describe the distance between a plurality of second vertices and the light source, the plurality of second vertices being respectively vertices on the surface of a third virtual object corresponding to the relevant level facing the light source, the third virtual object being a virtual object whose shadow is within the scene range corresponding to the relevant level.
  • the second level in the plurality of second levels that has the same range size as any first level, and the second level is recorded as a related level of the first level.
  • the above has described the related content of the second level and the method for determining the movement range of the virtual object relative to the second level, which will not be repeated here.
  • the content of the projected depth map corresponding to the second level is similar to the content of the projected depth map corresponding to the first level, which will not be repeated here.
  • the projection depth map corresponding to each second level is stored in the cache of the electronic device, which is convenient for the subsequent direct use of the projection depth map corresponding to the second level or partial update of the projection depth map corresponding to the second level, so as to reduce the performance overhead of the graphics processing unit (Graphics Processing Unit).
  • the movement amplitude of the virtual object relative to the relevant level is called the relevant movement amplitude
  • the relevant projection depth map corresponding to the relevant level is called the relevant projection depth map.
  • the relevant projection depth map can be obtained.
  • the projection depth map corresponding to each second level can also be regarded as an atlas, and the projection depth map corresponding to each first level is obtained by updating the atlas.
  • the atlas before the update is called the second atlas
  • the second atlas includes the projection depth maps corresponding to each second level.
  • the updated atlas is called the first atlas, and the first atlas includes the projection depth maps corresponding to each first level.
  • the relevant projection depth map can be copied from the second atlas.
  • Step 2036 Determine a first projected depth map based on the first virtual object and the associated projected depth map.
  • the projected depth map corresponding to the related level can be updated based on the first virtual object corresponding to the first level to obtain the projected depth map corresponding to the first level.
  • the projected depth map corresponding to the related level is copied from the second atlas, and the projected depth map corresponding to the first level is copied back to the second atlas to update the second atlas and obtain the first atlas.
  • step 2036 includes steps D1 to D3.
  • Step D1 based on the relevant movement amplitude, the relevant projected depth map is sheared to obtain a sheared projected depth map.
  • the level before the movement i.e., the related level
  • the level after the movement i.e., the first level
  • the projected depth map corresponding to the related level may contain the projected depth values corresponding to all or part of the first virtual object corresponding to the first level. Based on this, based on the movement amplitude of the virtual object relative to the related level, the projected depth map corresponding to the related level is cut so that the cut projected depth map retains the same projected depth value corresponding to both the related level and the first level.
  • the movement amplitude of the virtual object relative to the relevant level is a ratio.
  • the map corresponding to the ratio is cut out from the projected depth map corresponding to the relevant level to obtain a cut projected depth map.
  • Step D2 determining a second virtual object corresponding to any first level from the first virtual objects, the second virtual object being a virtual object whose shadow is within a remaining range corresponding to any first level, the remaining range being the range of the remaining scene in the scene corresponding to any first level excluding the local scene corresponding to the cut projected depth map.
  • the clipped projected depth map corresponds to a local scene within the scene range corresponding to any first level, and the range of the remaining scenes except the local scene within the scene range corresponding to the first level is recorded as the remaining range corresponding to the first level.
  • the scene range corresponding to the first level includes the range of the local scene and the range of the remaining scene.
  • the first virtual object corresponding to the first level is used as the second virtual object corresponding to the first level.
  • the first level corresponds to at least one second virtual object.
  • step D2 includes steps D21 to D23.
  • Step D21 determining a reference projection range of the first virtual object in the first projection coordinate system.
  • the implementation of step D21 is similar to that of step 2021, and will not be described in detail here.
  • Step D22 based on the remaining range, determine the second projection range of any first level in the first projection coordinate system.
  • the implementation of step D22 is similar to the implementation of step 2022, which will not be repeated here.
  • Step D23 if the reference projection range of the first virtual object and the second projection range intersect, the first virtual object is determined as the second virtual object.
  • the implementation of step D23 is similar to that of step 2023, and will not be described in detail herein.
  • Step D3 determining a first projected depth map based on the second virtual object and the cut projected depth map.
  • the shadow of any second virtual object corresponding to the first level is within the remaining scene corresponding to the first level, and the clipped projected depth map describes the projection depth value of the virtual object with the shadow in the local scene. Therefore, the second virtual object corresponding to the first level and the clipped projected depth map can correspond to all virtual objects whose shadows are within the scene range corresponding to the first level, so that based on the second virtual object corresponding to the first level and the clipped projected depth map, the projected depth map corresponding to the first level can be determined.
  • step D3 includes step D31 to step D32.
  • Step D31 based on the second virtual object, determine a supplementary map corresponding to any first level, the supplementary map is used to describe the distance between multiple third vertices and the light source, and any third vertex is a vertex on the surface of the second virtual object facing the light source.
  • step D31 is similar to that of step 203, and will not be described in detail here.
  • Step D32 splicing the supplementary map and the cut projected depth map to obtain a first projected depth map.
  • the supplementary map corresponding to any first level is spliced at the opposite end of the shearing line of the sheared projected depth map to obtain the projected depth map corresponding to the first level. For example, 10% of the bottom of the projected depth map corresponding to the relevant level is cut off. At this time, the lower edge line of the sheared projected depth map is the shearing line.
  • the supplementary map corresponding to the first level can be spliced at the upper edge line of the sheared projected depth map to obtain the projected depth map corresponding to the first level.
  • the image size of the temporary image is the same as the image size of the projected depth map corresponding to any first level.
  • part of the content of the temporary image is the cut projected depth map, and the other part is blank.
  • the cut projected depth map can be copied to a temporary image first. Then, based on any second virtual object corresponding to the first level, the supplementary map corresponding to the first level is written into a blank space of the temporary image, so as to determine the supplementary map corresponding to the first level and splice the supplementary map corresponding to the first level with the cut projected depth map to obtain the projected depth map corresponding to the first level.
  • Figure 9 is a schematic diagram of determining a projected depth map provided by an embodiment of the present application.
  • the left side of Figure 9 shows a schematic diagram after copying the cut projected depth map to a temporary image.
  • the blank space accounts for 10% of the temporary image.
  • the schematic diagram shown on the right side of Figure 9 is obtained.
  • the content of the temporary image is the projected depth map corresponding to the first level.
  • the projected depth map corresponding to the relevant level can be cut, and the supplementary map corresponding to the first level can be determined.
  • the shadow rendering method of the embodiment of the present application further includes step 2037 , and step 2037 is performed before step 204 .
  • Step 2037 In response to the relevant movement amplitude being not greater than the movement threshold, determining the relevant projected depth map as the first projected depth map.
  • the relevant level is the level before the virtual object moves
  • any first level is the level after the virtual object moves.
  • the movement amplitude of the virtual object relative to the relevant level is not greater than the movement threshold
  • the content in the scene range corresponding to the level before the virtual object moves and the content in the scene range corresponding to the level after the virtual object moves change slightly and can be ignored.
  • Shadow Map there is a shadow rendering scheme of Shadow Map.
  • the virtual object can be used as the target object.
  • the projection depth map corresponding to the first level is projected by using the local update method of the projection depth map, which reduces the amount of calculation and improves the calculation efficiency; on the other hand, when the movement amplitude of the virtual object relative to the relevant level is not greater than the movement threshold, the projection depth map remains unchanged.
  • the embodiment of the present application can not update the projection depth map when only the camera direction is changed (for example, the camera is rotated but the camera position remains unchanged) and the movement amplitude of the virtual object is small (which can correspond to the small movement amplitude of the camera), thereby achieving the effect of not updating the shadow and reducing the rendering overhead.
  • Step 204 Render shadows in the first visible scene based on the first projected depth map.
  • the projection depth map corresponding to the first level records the projection depth value of the virtual object of the shadow within the scene range corresponding to the first level, and multiple scene ranges corresponding to the first levels constitute the first visible scene. Therefore, the shadow in the first visible scene can be rendered through the projection depth maps corresponding to the multiple first levels.
  • step 204 includes steps 2041 to 2044 .
  • Step 2041 for any fourth vertex, determine a first distance between any fourth vertex and the light source, where any fourth vertex is a vertex on a surface of a virtual object in the first visible scene facing the camera.
  • the three-dimensional coordinates of the fourth vertex in the virtual scene coordinate system are referred to as the three-dimensional scene coordinates of the fourth vertex
  • the three-dimensional coordinates of the fourth vertex in the second projection coordinate system are referred to as the three-dimensional projection coordinates of the fourth vertex.
  • the electronic device can obtain the three-dimensional scene coordinates of any fourth vertex, and map the three-dimensional scene coordinates of the fourth vertex to the three-dimensional projection coordinates of the fourth vertex.
  • the first distance between the fourth vertex and the light source is calculated using the three-dimensional projection coordinates of the fourth vertex and the three-dimensional projection coordinates of the light source.
  • the three-dimensional projection coordinates of the fourth vertex can be adjusted based on the adjustment coefficient to obtain the adjusted three-dimensional projection coordinates of the fourth vertex.
  • the distance between the fourth vertex and the light source is calculated using the adjusted three-dimensional projection coordinates of the fourth vertex and the three-dimensional projection coordinates of the light source, and the distance can be recorded as the first distance.
  • the adjustment method of the three-dimensional coordinates of the fourth vertex can be seen in the description of steps 2031 to 2033, and the implementation principles of the two are similar, which will not be repeated here.
  • the three-dimensional projection coordinates of the light source can be adjusted based on the adjustment coefficient to obtain the adjusted three-dimensional projection coordinates of the light source.
  • the first distance between the fourth vertex and the light source is calculated using the adjusted three-dimensional projection coordinates of the light source and the three-dimensional projection coordinates of the fourth vertex, or using the adjusted three-dimensional projection coordinates of the light source and the adjusted three-dimensional projection coordinates of the fourth vertex.
  • the adjustment method of the three-dimensional coordinates of the light source can be seen in the description of step 2034. The implementation principles of the two are similar and will not be repeated here.
  • Step 2042 determine a reference level from the plurality of first levels, wherein any fourth vertex is a vertex on a virtual object within a scene range corresponding to the reference level.
  • the scene range corresponding to any first level is a local range in the first visible scene
  • any fourth vertex is a vertex on a virtual object in the first visible scene. Therefore, based on the three-dimensional scene coordinates of the fourth vertex, at least one candidate level can be determined from multiple first levels, and the fourth vertex is a vertex on a virtual object within the scene range corresponding to any candidate level. Since multiple first levels can be regarded as levels with a hierarchical relationship, and the range size of the previous first level in the multiple first levels is smaller than the range size of the next first level, the top level can be determined from at least one candidate level, and the top level can be used as a reference level to determine the projected depth map corresponding to the reference level.
  • (1) of Fig. 4 shows first level 0 to first level 3 having an upper and lower hierarchical relationship.
  • the reference level is the uppermost level, that is, first level 1.
  • Step 2043 Determine a second distance between the first vertex corresponding to any fourth vertex and the light source from the projected depth map corresponding to the reference level.
  • the first vertex corresponding to the fourth vertex is determined from each first vertex, wherein the fourth vertex and its corresponding first vertex are on the same ray, that is, the light source, the fourth vertex, and the first vertex corresponding to the fourth vertex are on the same straight line.
  • the distance between the first vertex corresponding to any fourth vertex and the light source can be determined based on the projection depth map corresponding to the reference level, and this distance can be recorded as the second distance.
  • Figure 10 is a schematic diagram of the relationship between a first visible scene and a projected depth map provided in an embodiment of the present application.
  • the left side of Figure 10 shows the first visible scene, which includes each fourth vertices facing the camera; the right side of Figure 10 shows the first atlas, which includes the projected depth maps corresponding to each first level.
  • the first vertex corresponding to the fourth vertex can be determined in the first atlas (i.e., the end point of the arrow in Figure 10), thereby obtaining the distance between the first vertex corresponding to the fourth vertex and the light source, that is, the projected depth value of the first vertex corresponding to the fourth vertex.
  • Step 2044 In response to the first distance being greater than the second distance, a shadow is rendered at the position of any fourth vertex.
  • the fourth vertex is a vertex on the surface of the virtual object facing the camera, and the first vertex is a vertex on the surface of the virtual object facing the light source.
  • the first distance is greater than the second distance, it means that the camera can see the fourth vertex, but the light source cannot illuminate the fourth vertex.
  • the fourth vertex should be in the shadow, so the electronic device renders the shadow at the location of the fourth vertex.
  • the first distance is not greater than the second distance, it means that the camera can see the fourth vertex, and the light source can also illuminate the fourth vertex.
  • the fourth vertex should be illuminated, so the electronic device can calculate the illumination information and render the illumination at the location of the fourth vertex based on the illumination information.
  • the electronic device can render shadows or lighting at any fourth vertex facing the camera in the first visible scene, thereby rendering the first visible scene and the shadows in the first visible scene.
  • the first virtual object corresponding to the first level includes a dynamic virtual object and a static virtual object.
  • the projection depth map corresponding to the first level in step 203 includes both the projection depth value of the first vertex in the dynamic virtual object and the projection depth value of the first vertex in the static virtual object.
  • the dynamic virtual objects and static virtual objects included in the first virtual object corresponding to the first level are separated.
  • the projected depth map corresponding to the first level includes the projected depth map corresponding to the dynamic virtual object corresponding to the first level and the projected depth map corresponding to the static virtual object corresponding to the first level.
  • the projected depth map corresponding to the dynamic virtual object corresponding to the first level includes the projected depth value of the first vertex in the dynamic virtual object;
  • the projected depth map corresponding to the static virtual object corresponding to the first level includes the projected depth value of the first vertex in the static virtual object.
  • the first object (such as Render Texture) can be used to store the projected depth map corresponding to the static virtual object corresponding to the first level
  • the second object (such as Pre Object) can be used to store the projected depth map corresponding to the dynamic virtual object corresponding to the first level, thereby realizing a dynamic and static separation storage solution.
  • Data including but not limited to data for analysis, data for storage, data for display, etc.
  • signals are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant regions.
  • the virtual scenes and movement information of virtual objects involved in this application are all obtained with full authorization.
  • the scene range corresponding to the first level is a local range in the first visible scene included in the virtual scene, which is equivalent to determining the scene range corresponding to each first level in real time according to the first visible scene during the operation of the virtual scene.
  • the first virtual objects corresponding to each first level are determined by the scene range corresponding to each first level, and the projection depth maps corresponding to each first level are determined based on the first virtual objects corresponding to each first level, so as to achieve the real-time determination of the projection depth maps corresponding to each local range in the first visible scene during the operation of the virtual scene.
  • Figure 11 is a flowchart of a rendering method of a first visual scene provided by an embodiment of the present application, and the flowchart includes S1 to S21.
  • the first visible scene is the scene after the virtual object moves, and the scene before the virtual object moves can be recorded as a second visible scene.
  • the first first level is recorded as the i-th first level.
  • S8 is executed without determining the projected depth map corresponding to the i-th first level.
  • the virtual object list corresponding to the ith first level includes each first virtual object corresponding to the ith first level.
  • S11 is executed to determine the projection depth map corresponding to the ith first level.
  • the projection depth map corresponding to the ith first level is directly determined based on the virtual object list corresponding to the ith first level.
  • S13 determining the supplementary map corresponding to the i-th first level in the temporary image, so that the temporary image includes a map obtained by splicing the cut projected depth map and the supplementary map corresponding to the i-th first level.
  • S13 is to determine each second virtual object corresponding to the i-th first level from the virtual object list corresponding to the i-th first level, and determine the supplementary map corresponding to the i-th first level in the temporary image based on each second virtual object corresponding to the i-th first level.
  • S16 is executed to regard the i+1-th first level as the i-th first level. Then, a loop is executed starting from S7 until the i-th first level is the last first level.
  • the loop ends, and the projection depth map corresponding to each first level can be obtained.
  • S17 is executed to determine the vertices on the surface of the virtual object in the first visible scene facing the camera.
  • S20 determining whether to render shadows at the vertices.
  • S20 is determining whether to render shadows at the vertices based on the projected depth map corresponding to the reference level and the vertices on the surface of the virtual object in the first visible scene facing the camera.
  • the rendering result is rendering shadows at the vertices; if the result is determined not to render shadows at the vertices, the rendering result is rendering illumination at the vertices.
  • the shadows in the first visible scene can be rendered.
  • the projection depth map corresponding to each first level is determined in real time according to the movement of the virtual object in the virtual scene, which can reduce the occupancy of storage resources and improve the shadow rendering performance. Rendering the shadows in the first visible scene through the projection depth map corresponding to each first level is conducive to improving the performance of the shadows, supporting a larger range of high-quality shadow effects, and providing strong support for the production of large world scenes.
  • Shadow Map and Cascaded Shadow Map are two shadow rendering schemes in the related art
  • Shadow Cache is the shadow rendering scheme shown in FIG11.
  • Shadow Cache has a larger viewing distance, fewer draw calls, and a higher frame rate. Therefore, the shadow rendering scheme shown in Figure 11 has better rendering performance and can support full-scene shadow rendering of large world scenes with ultra-long viewing distances.
  • Figure 12 is a schematic diagram of a first visible scene without shadows provided by an embodiment of the present application
  • Figure 13 is a schematic diagram of a first visible scene with shadows provided by an embodiment of the present application.
  • Figure 13 is rendered according to the shadow rendering scheme shown in Figure 11. It can be seen from Figures 12 and 13 that the embodiment of the present application can render shadows in the first visible scene to improve the fidelity of the first visible scene.
  • the embodiments of the present application can reduce the performance overhead of the central processing unit (CPU) and the graphics processing unit (Graphics Processing Unit), have wide hardware compatibility, and are suitable for computers, mobile phones, game consoles and other hardware devices with GPUs, and have low requirements for hardware devices.
  • CPU central processing unit
  • GPU graphics processing unit
  • FIG14 is a schematic diagram of the structure of a shadow rendering device provided in an embodiment of the present application. As shown in FIG14 , the device includes:
  • a determination module 1401 is used to determine scene ranges corresponding to a plurality of first levels, where the scene range corresponding to the first level is a range of a first visible scene included in the virtual scene or a local range in the first visible scene;
  • the determination module 1401 is further configured to determine, for any first level among the plurality of first levels, a first virtual object corresponding to any first level based on a scene range corresponding to any first level, wherein the first virtual object corresponding to the first level is a virtual object whose shadow is within the scene range corresponding to any first level;
  • the determination module 1401 is further used to determine, based on the first virtual object, a first projected depth map corresponding to any first level, the first projected depth map being used to describe distances between a plurality of first vertices and the light source, the plurality of first vertices being vertices on a surface of the first virtual object facing the light source;
  • the rendering module 1402 is configured to render shadows in the first visible scene based on the first projected depth map.
  • the determining module 1401 is configured to determine a plurality of The scene range corresponding to one level
  • Meeting the shadow update condition includes at least one of the following: the virtual object moves in the virtual scene; the lighting of the virtual scene changes; and the virtual scene is initialized.
  • the device further includes:
  • an acquisition module configured to acquire movement information of the virtual object and a plurality of scene ranges corresponding to the second level when the virtual object moves in the virtual scene, wherein the scene range corresponding to the second level is a range of a second visual scene included in the virtual scene or a local range in the second visual scene, wherein the first visual scene is a visual scene after the virtual object moves, and the second visual scene is a visual scene before the virtual object moves;
  • the determination module 1401 is further configured to determine, for any second level, a second movement amplitude of the virtual object relative to any second level based on the movement information of the virtual object and the scene range corresponding to any second level;
  • the determination module 1401 is further configured to determine, in response to the existence of a target level in the plurality of second levels, that a shadow update condition is satisfied and that a target movement amplitude of the virtual object relative to the target level is greater than a movement threshold.
  • the determination module 1401 is used to obtain the range size of each first level; for any first level, based on the reference point of the first visual scene and the range size of any first level, determine the scene range corresponding to any first level in the first visual scene.
  • the determination module 1401 is used to obtain a reference projection range of multiple virtual objects in a virtual scene in a first projection coordinate system; based on a scene range corresponding to any first level, determine a first projection range of any first level in the first projection coordinate system; for any virtual object, if the reference projection range of any virtual object and the first projection range intersect, then any virtual object is determined as a first virtual object.
  • the device further includes:
  • An extension module used to extend the scene range corresponding to any first level based on the extension parameter to obtain a reference range corresponding to any first level
  • the selection module is used to select multiple virtual objects located within a reference range.
  • the determination module 1401 is used to determine, for any virtual object, a bounding box of any virtual object; based on the bounding box, determine first projection information of any virtual object, where the first projection information is used to describe the projection of the bounding box in a first projection coordinate system; and determine a reference projection range of any virtual object system based on the first projection information.
  • the determination module 1401 is used to determine second projection information of any virtual object based on the first projection information, the second projection information is used to describe the bounding box of the projection of the bounding box in the first projection coordinate system; and the second projection information is determined as the reference projection range of any virtual object.
  • the determination module 1401 is used to determine the three-dimensional projection coordinates of each vertex of the first virtual object in the second projection coordinate system based on the three-dimensional scene coordinates of each vertex of the first virtual object in the virtual scene coordinate system; determine the adjustment coefficient based on the scene range corresponding to any first level and the resolution of the first projection depth map; adjust the three-dimensional projection coordinates of each vertex of the first virtual object based on the adjustment coefficient to obtain the adjusted three-dimensional projection coordinates of each vertex of the first virtual object; determine the first projection depth map based on the three-dimensional projection coordinates of the light source in the second projection coordinate system and the adjusted three-dimensional projection coordinates of each vertex of the first virtual object.
  • the determination module 1401 is used to adjust the three-dimensional projection coordinates of the light source based on the adjustment coefficient to obtain the adjusted three-dimensional projection coordinates of the light source; and determine the first projection depth map based on the adjusted three-dimensional projection coordinates of the light source and the adjusted three-dimensional projection coordinates of each vertex of the first virtual object.
  • the determination module 1401 is used to obtain, for any first level, a relevant projected depth map corresponding to the relevant level in response to a relevant movement amplitude of the virtual object relative to the relevant level being greater than a movement threshold, the relevant level being a second level whose scene range size is the same as that of the scene range corresponding to any first level, the relevant projected depth map being used to describe the distance between multiple second vertices and the light source, the multiple second vertices being respectively vertices on a surface of a third virtual object corresponding to the relevant level facing the light source, the third virtual object being a virtual object whose shadow is within the scene range corresponding to the relevant level; and determining the first projected depth map based on the first virtual object and the relevant projected depth map.
  • the determination module 1401 is configured to determine the relevant projection depth based on the relevant movement amplitude.
  • the image is cut to obtain a cut projected depth map; a second virtual object corresponding to any first level is determined from the first virtual object, the second virtual object is a virtual object whose shadow is within a remaining range corresponding to any first level, and the remaining range is the range of the remaining scene in the scene corresponding to any first level except the local scene corresponding to the cut projected depth map; based on the second virtual object and the cut projected depth map, the first projected depth map is determined.
  • the determination module 1401 is used to determine a reference projection range of the first virtual object in the first projection coordinate system; based on the remaining range, determine a second projection range of any first level in the first projection coordinate system; if the reference projection range and the second projection range of the first virtual object intersect, the first virtual object is determined as the second virtual object.
  • a determination module 1401 is used to determine a supplementary map corresponding to any first level based on the second virtual object, where the supplementary map is used to describe the distances between multiple third vertices and the light source, and the multiple third vertices are respectively the vertices on the surface of the second virtual object facing the light source; the supplementary map and the cut projected depth map are spliced to obtain a first projected depth map.
  • the determination module 1401 is further configured to determine the relevant projected depth map as the first projected depth map in response to the relevant movement amplitude being not greater than the movement threshold.
  • the rendering module 1402 is used to determine, for any fourth vertex, a first distance between any fourth vertex and a light source, where any fourth vertex is a vertex on a surface of a virtual object in the first visible scene facing the camera; determine a reference level from multiple first levels, where any fourth vertex is a vertex on a virtual object within the scene range corresponding to the reference level; determine a second distance between a first vertex corresponding to any fourth vertex and the light source from a projected depth map corresponding to the reference level; and in response to the first distance being greater than the second distance, render a shadow at the position of any fourth vertex.
  • the scene range corresponding to the first level in the above-mentioned device is a local range in the first visible scene included in the virtual scene, which is equivalent to determining the scene range corresponding to each first level in real time according to the first visible scene during the operation of the virtual scene.
  • the first virtual objects corresponding to each first level are determined by the scene range corresponding to each first level, and the projection depth maps corresponding to each first level are determined based on the first virtual objects corresponding to each first level, so as to achieve the real-time determination of the projection depth maps corresponding to each local range in the first visible scene during the operation of the virtual scene.
  • the device provided in FIG. 14 above only uses the division of the above functional modules as an example when implementing its functions.
  • the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
  • the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.
  • FIG15 shows a block diagram of a terminal device 1500 provided by an exemplary embodiment of the present application.
  • the terminal device 1500 includes: a processor 1501 and a memory 1502 .
  • the processor 1501 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc.
  • the processor 1501 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array).
  • the processor 1501 may also include a main processor and a coprocessor.
  • the main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.
  • the processor 1501 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen.
  • the processor 1501 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
  • AI Artificial Intelligence
  • the memory 1502 may include one or more computer-readable storage media, which may be non-transitory.
  • the memory 1502 may also include high-speed random access memory and non-volatile memory, such as one or more Disk storage device, flash memory storage device.
  • the non-transitory computer-readable storage medium in the memory 1502 is used to store at least one computer program, and the at least one computer program is used to be executed by the processor 1501 to implement the shadow rendering method provided in the method embodiment of the present application.
  • the terminal device 1500 may optionally further include: a display screen 1505 .
  • the display screen 1505 is used to display a UI (User Interface).
  • the UI may include graphics, text, icons, videos, and any combination thereof.
  • the display screen 1505 also has the ability to collect touch signals on the surface or above the surface of the display screen 1505.
  • the touch signal can be input as a control signal to the processor 1501 for processing.
  • the display screen 1505 can also be used to provide virtual buttons and/or virtual keyboards, also known as soft buttons and/or soft keyboards.
  • the display screen 1505 can be one, which is set on the front panel of the terminal device 1500; in other embodiments, the display screen 1505 can be at least two, which are respectively set on different surfaces of the terminal device 1500 or are folded; in other embodiments, the display screen 1505 can be a flexible display screen, which is set on the curved surface or folded surface of the terminal device 1500. Even, the display screen 1505 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen.
  • the display screen 1505 can be made of materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), etc. Exemplarily, the first visible scene, the shadow in the first visible scene, etc. are displayed through the display screen 1505.
  • FIG. 15 does not limit the terminal device 1500 and may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.
  • FIG16 is a schematic diagram of the structure of the server provided in the embodiment of the present application.
  • the server 1600 may have relatively large differences due to different configurations or performances, and may include one or more processors 1601 and one or more memories 1602, wherein the one or more memories 1602 store at least one computer program, and the at least one computer program is loaded and executed by the one or more processors 1601 to implement the shadow rendering method provided in the above-mentioned various method embodiments.
  • the processor 1601 is a CPU.
  • the server 1600 may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output.
  • the server 1600 may also include other components for implementing device functions, which will not be described in detail here.
  • a non-volatile computer-readable storage medium in which at least one computer program is stored.
  • the at least one computer program is loaded and executed by a processor to enable an electronic device to implement any of the above-mentioned shadow rendering methods.
  • the above-mentioned non-volatile computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.
  • a computer program is also provided.
  • the computer program is at least one, and the at least one computer program is loaded and executed by a processor to enable an electronic device to implement any of the above-mentioned shadow rendering methods.
  • a computer program product is further provided.
  • the computer program product stores at least one computer program, and the at least one computer program is loaded and executed by a processor to enable an electronic device to implement any of the above-mentioned shadow rendering methods.

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Graphics (AREA)
  • Multimedia (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Processing Or Creating Images (AREA)

Abstract

阴影渲染方法、装置、电子设备及可读存储介质,属于图像渲染技术领域。方法包括:确定多个第一层级对应的场景范围(201);对于多个第一层级中的任一个第一层级,基于任一个第一层级对应的场景范围,确定任一个第一层级对应的第一虚拟物体(202);基于任一个第一层级对应的第一虚拟物体,确定任一个第一层级对应的投影深度贴图,任一个第一层级对应的投影深度贴图用于描述多个第一顶点与光源之间的距离(203);基于多个第一层级对应的投影深度贴图,渲染第一可视场景中的阴影(204)。本申请在降低存储资源的占用情况的同时,还可以实时更新阴影,提高阴影的表现效果和虚拟场景的逼真度。

Description

阴影渲染方法、装置、电子设备及可读存储介质
本申请要求于2022年11月03日提交的申请号为202211368766.6、发明名称为“阴影渲染方法、装置、电子设备及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及图像渲染技术领域,特别涉及一种阴影渲染方法、装置、电子设备及可读存储介质。
背景技术
电影、游戏等行业对图像渲染技术的要求越来越高,不仅期望在虚拟场景中渲染出虚拟物体,还期望在虚拟场景中渲染出虚拟物体的阴影,从而提高在光照条件下虚拟场景的逼真度。
相关技术中,需要预先在不同光照条件下烘焙出虚拟物体的阴影,以图像的形式存储虚拟物体的阴影,这张图像可以称为虚拟物体的阴影贴图。各个虚拟物体的阴影贴图可以存储在磁盘上。当需要渲染出某一个虚拟物体的阴影时,可以从磁盘中读取该虚拟物体的阴影贴图,通过加载该虚拟物体的阴影贴图实现在虚拟场景中渲染出该虚拟物体的阴影。
发明内容
本申请提供了一种阴影渲染方法、装置、电子设备及可读存储介质,可以降低存储资源的占用情况,提高阴影的表现效果和虚拟场景的逼真度,所述技术方案包括如下内容。
一方面,提供了一种阴影渲染方法,所述方法由电子设备执行,所述方法包括:
确定多个第一层级对应的场景范围,所述第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者所述第一可视场景中的局部范围;
对于所述多个第一层级中的任一个第一层级,基于所述任一个第一层级对应的场景范围,确定所述任一个第一层级对应的第一虚拟物体,所述第一虚拟物体是其阴影在所述任一个第一层级对应的场景范围内的虚拟物体;
基于所述第一虚拟物体,确定所述任一个第一层级对应的第一投影深度贴图,所述第一投影深度贴图用于描述多个第一顶点与光源之间的距离,所述多个第一顶点分别是所述第一虚拟物体面向所述光源的表面上的顶点;
基于所述第一投影深度贴图,渲染所述第一可视场景中的所述阴影。
另一方面,提供了一种阴影渲染装置,所述装置包括:
确定模块,用于确定多个第一层级对应的场景范围,所述第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者所述第一可视场景中的局部范围;
所述确定模块,还用于对于所述多个第一层级中的任一个第一层级,基于所述任一个第一层级对应的场景范围,确定所述任一个第一层级对应的第一虚拟物体,所述第一虚拟物体是其阴影在所述任一个第一层级对应的场景范围内的虚拟物体;
所述确定模块,还用于基于所述第一虚拟物体,确定所述任一个第一层级对应的第一投影深度贴图,所述第一投影深度贴图用于描述多个第一顶点与光源之间的距离,所述多个第一顶点分别是所述第一虚拟物体面向所述光源的表面上的顶点;
渲染模块,用于基于所述第一投影深度贴图,渲染所述第一可视场景中的所述阴影。
另一方面,提供了一种电子设备,所述电子设备包括处理器和存储器,所述存储器中存储有至少一条计算机程序,所述至少一条计算机程序由所述处理器加载并执行,以使所述电 子设备实现上述任一所述的阴影渲染方法。
另一方面,还提供了一种非易失性计算机可读存储介质,所述非易失性计算机可读存储介质中存储有至少一条计算机程序,所述至少一条计算机程序由处理器加载并执行,以使电子设备实现上述任一所述的阴影渲染方法。
另一方面,还提供了一种计算机程序,所述计算机程序为至少一条,所述至少一条计算机程序由处理器加载并执行,以使电子设备实现上述任一种阴影渲染方法。
另一方面,还提供了一种计算机程序产品,所述计算机程序产品中存储有至少一条计算机程序,所述至少一条计算机程序由处理器加载并执行,以使电子设备实现上述任一种阴影渲染方法。
本申请提供的技术方案中,第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者第一可视场景中的局部范围,相当于在运行虚拟场景的过程中,实时根据第一可视场景确定各个第一层级对应的场景范围。通过各个第一层级对应的场景范围确定各个第一层级对应的第一虚拟物体,以基于各个第一层级对应的第一虚拟物体确定各个第一层级对应的投影深度贴图,实现了在虚拟场景的运行过程中,实时确定第一可视场景的全局范围和各个局部范围对应的投影深度贴图。相较于确定并存储虚拟场景中各个虚拟物体的阴影贴图来说,可以降低存储资源的占用情况。通过第一可视场景的全局范围和各个局部范围对应的投影深度贴图来渲染第一可视场景中的阴影,在实现实时更新阴影的基础上,还有利于提高阴影的表现效果,提高虚拟场景的逼真度。
附图说明
图1是本申请实施例提供的一种阴影渲染方法的实施环境示意图;
图2是本申请实施例提供的一种阴影渲染方法的流程图;
图3是本申请实施例提供的一种视锥体的示意图;
图4是本申请实施例提供的一种第一层级的示意图;
图5是本申请实施例提供的一种投影的示意图;
图6是本申请实施例提供的一种投影和投影的包围框的示意图;
图7是本申请实施例提供的一种虚拟物体的参考投影范围和第一层级的第一投影范围之间的关系示意图;
图8是本申请实施例提供的一种投影深度贴图的示意图;
图9是本申请实施例提供的一种投影深度贴图的确定示意图;
图10是本申请实施例提供的一种第一可视场景和投影深度贴图的关系示意图;
图11是本申请实施例提供的一种第一可视场景的渲染方法的流程图;
图12是本申请实施例提供的一种不带有阴影的第一可视场景的示意图;
图13是本申请实施例提供的一种具有阴影的第一可视场景的示意图;
图14是本申请实施例提供的一种阴影渲染装置的结构示意图;
图15是本申请实施例提供的一种终端设备的结构示意图;
图16是本申请实施例提供的一种服务器的结构示意图。
具体实施方式
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
图1是本申请实施例提供的一种阴影渲染方法的实施环境示意图,如图1所示,该实施环境包括终端设备101和服务器102。其中,本申请实施例中的阴影渲染方法可以由终端设备101执行,也可以由服务器102执行,或者由终端设备101和服务器102共同执行。
终端设备101可以是智能手机、游戏主机、台式计算机、平板电脑、膝上型便携计算机、智能电视、智能车载设备、智能语音交互设备、智能家电等。服务器102可以为一台服务器, 或者为多台服务器组成的服务器集群,或者为云计算平台和虚拟化中心中的任意一种,本申请实施例对此不加以限定。服务器102可以与终端设备101通过有线网络或无线网络进行通信连接。服务器102可以具有数据处理、数据存储以及数据收发等功能,在本申请实施例中不加以限定。终端设备101和服务器102的数量不受限制,可以是一个或多个。
随着图像渲染技术的不断发展,各行各业对图像渲染技术的要求也越来越高。在渲染光照条件下的虚拟场景时,不仅要求渲染出虚拟物体,还要求渲染出虚拟物体的阴影,以提高虚拟场景的逼真度。
相关技术中,需要预先确定虚拟场景中所有虚拟物体的阴影贴图,并将各个虚拟物体的阴影贴图存储在磁盘上。当需要渲染出某一个虚拟物体的阴影时,从磁盘中读取该虚拟物体的阴影贴图,通过加载该虚拟物体的阴影贴图实现在虚拟场景中渲染出该虚拟物体的阴影。
由于虚拟物体的数量非常多,因此,需要大量的存储资源来存储各个虚拟物体的阴影贴图,导致存储资源占用较多。
本申请实施例提供了一种阴影渲染方法,该方法可应用于上述实施环境中,可以降低存储资源的占用情况,提高可视场景中的阴影表现效果。以图2所示的本申请实施例提供的一种阴影渲染方法的流程图为例,为便于描述,将执行本申请实施例中的阴影渲染方法的终端设备101或者服务器102称为电子设备,该方法可以由电子设备来执行。如图2所示,该方法包括如下步骤。
步骤201,确定多个第一层级对应的场景范围,第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者第一可视场景中的局部范围。
为了便于理解步骤201,下面先对涉及的技术用语进行解释和说明。
虚拟场景是通过三维建模技术搭建的场景,适用于多个行业。例如,在游戏行业中,常通过三维建模技术搭建出包含树木、房屋、湖泊、悬崖等物体的游戏地图,该游戏地图即为虚拟场景。又如,在室内设计行业,可以通过三维建模技术搭建出包含书桌、衣柜、电器、厨具等物体的室内场景,该室内场景也为虚拟场景。
通常情况下,电子设备不会显示完整的虚拟场景,而是显示虚拟场景的一部分,电子设备显示的这部分虚拟场景称为可视场景。可视场景是指利用相机拍摄虚拟场景时位于视锥体内的虚拟场景部分。
视锥体是在相机坐标系下以坐标原点为光心的一块可视区域的椎体范围,共有6个表面,分别为上表面、下表面、左表面、右表面、近表面和远表面。位于视锥体内的物体是相机可以拍摄到的物体,而位于视锥体外的物体是相机不可以拍摄到的物体。电子设备可以将位于视锥体外的物体裁剪掉,只对位于视锥体内的物体进行渲染。可以理解的是,对一个物体进行裁剪时,可以裁剪掉整个物体,也可以裁剪该物体的一部分。通过裁剪掉位于视锥体外的物体,减少了需要渲染的内容,提高了渲染性能。
请参见图3,图3是本申请实施例提供的一种视锥体的示意图。如图3所示,视锥体是一个椎体范围,共有6个表面。将物体位于视锥体外的部分裁剪掉,得到裁剪后的物体,而裁剪后的物体位于视锥体内。
一般情况下,当可视场景中的阴影发生更新时,需要重新渲染可视场景中的阴影。例如,照射可视场景的光源的方向改变时,可视场景中的阴影会随之更新,此时,需要重新渲染可视场景中的阴影。在一种可能的实现方式中,可视场景和可视场景中的阴影一起更新,例如,当可视场景发生改变时,由于不同的可视场景中存在不同的虚拟物体,导致了可视场景中的阴影也需要改变。为了区分阴影更新前的可视场景和阴影更新后的可视场景,将阴影更新后的可视场景记为第一可视场景,将阴影更新前的可视场景记为第二可视场景。
可以理解的是,当可视场景需要发生更新时,第一可视场景和第二可视场景不同,且第一可视场景中的阴影和第二可视场景中的阴影不同;当可视场景不需要发生更新时,第一可视场景和第二可视场景相同,但第一可视场景中的阴影和第二可视场景中的阴影可能不同。
电子设备需要获取对第一可视场景进行划分后得到的多个第一层级对应的场景范围,一个第一层级对应一个场景范围,第一层级有多个,场景范围也有多个。这种情况下,任一个第一层级对应的场景范围是第一可视场景的范围或者第一可视场景中局部场景的范围。层级也可以称为层次、等级,层级可通过范围尺寸来表示,或者说,层级可通过范围尺寸来划分,不同层级的范围尺寸不同,但中心点(或重心点)可以相同。以第一层级的范围尺寸是X为例,第一层级对应的场景范围即为范围尺寸为X的场景范围。本申请实施例不限定于第一可视场景的划分方式,示例性地,按照实现方式A1或者实现方式A2来对第一可视场景进行划分。
可以理解的是,层级的中心点是层级对应的场景范围的几何中心,而层级的重心点是层级对应的场景范围受重力作用的点,本申请实施例不对层级的中心点、层级的重心点的确定方式做限定。本申请所有的实施例对于中心点和重心点二者均成立,即所有实施例中二者可以互换。
在实现方式A1中,步骤201包括:将第一可视场景均匀地划分为多个面积、形状相同的局部场景,一个局部场景的范围或者第一可视场景的范围为一个第一层级对应的场景范围。
在实现方式A2中,步骤201包括:获取各个第一层级的范围尺寸;对于任一个第一层级,基于第一可视场景的参考点和任一个第一层级的范围尺寸,在第一可视场景中确定任一个第一层级对应的场景范围。
本申请实施例中,多个第一层级可以视作具有上下层级关系的层级。其中,多个第一层级中上一个第一层级的范围尺寸小于下一个第一层级的范围尺寸。可以将虚拟对象在第一可视场景的位置作为第一可视场景的参考点,或者将第一可视场景的中心点或者重心点等作为第一可视场景的参考点。将第一可视场景的参考点作为任一个第一层级的中心点或者重心点,基于该第一层级的范围尺寸对第一可视场景进行划分,划分出的局部场景的范围为该第一层级对应的场景范围。
例如,第一个第一层级对应的场景范围是以虚拟对象的位置为中心,边长为32米的场景范围,第二个第一层级对应的场景范围是以虚拟对象的位置为中心,边长为64米的场景范围,以此类推。
电子设备可以存储各个第一层级对应的场景范围。可选地,对于任一个第一层级,电子设备可以存储该第一层级对应的场景范围的中心点(或者重心点)和该第一层级的范围尺寸。当该第一层级对应的场景范围为矩形时,电子设备可以存储矩形各个点的坐标,或者电子设备可以存储矩形的四个边界(存储代码如下所示),以存储该第一层级对应的场景范围。
可选地,各个第一层级的中心点均是第一可视场景的参考点,因此,各个第一层级的中心点相同,或者,各个第一层级的重心点均是第一可视场景的参考点,因此,各个第一层级的重心点相同。由于上一个第一层级的范围尺寸小于下一个第一层级的范围尺寸,因此,多个第一层级对应的场景范围可以视作一组范围尺寸逐渐增大的场景范围。
可选地,剪辑贴图(Clipmap)指的是一组具有相同中心点或者相同重心点,但是覆盖范围逐级翻倍的数据,该数据包括但不限于贴图,例如,该数据可以是虚拟场景的局部场景。当下一个第一层级的范围尺寸是上一个第一层级的范围尺寸的两倍时,这种情况下,多个第一层级对应的场景范围是一组具有相同中心点或者相同重心点,范围尺寸逐级翻倍的场景,基于此,各个第一层级对应的场景范围也被称为Clipmap。
请参见图4,图4是本申请实施例提供的一种第一层级的示意图。图4中的(1)示出了具有上下层级关系的第一层级0至第一层级3的范围尺寸,上一个第一层级的范围尺寸小于下一个第一层级的范围尺寸。图4中的(2)示出了第一层级0至第一层级3的范围尺寸的俯视图,从内到外的四个范围尺寸分别为第一层级0至第一层级3的范围尺寸。
在一种可能的实现方式中,步骤201包括:响应于满足阴影更新条件,确定多个第一层级对应的场景范围,满足阴影更新条件包括情况B1至情况B3中的至少一项。
情况B1,虚拟对象在虚拟场景中移动。
虚拟对象是通过三维建模技术建模出的对象。本申请实施例不对虚拟对象的外形等做限定,示例性地,虚拟对象可以为人物形态、动物形态、卡通形态等。虚拟对象可以由用户控制,也可以由计算机程序控制。例如,在游戏场景中,由用户控制游戏角色,由计算机程序控制游戏怪物,游戏角色和游戏怪物均属于虚拟对象。
当电子设备确定虚拟对象在虚拟场景中移动时,电子设备确定满足阴影更新条件,这种情况下,需要对可视场景中的阴影进行更新。在一种可能的实现方式中,虚拟对象在虚拟场景中移动时,可视场景会随着虚拟对象的移动而发生更新,从而导致可视场景中的阴影也随之更新。
可选地,在步骤201之前还可以执行如下步骤:当虚拟对象在虚拟场景中移动时,获取虚拟对象的移动信息和多个第二层级对应的场景范围,第二层级对应的场景范围是虚拟场景包括的第二可视场景的范围或者第二可视场景中的局部范围,第一可视场景是虚拟对象移动后的可视场景,第二可视场景是虚拟对象移动前的可视场景;对于任一个第二层级,基于虚拟对象的移动信息和任一个第二层级对应的场景范围,确定虚拟对象相对于任一个第二层级的第二移动幅度;响应于多个第二层级中存在目标层级,则确定满足阴影更新条件,虚拟对象相对于目标层级的目标移动幅度大于移动阈值。
当电子设备确定虚拟对象在虚拟场景中移动时,电子设备可以获取到虚拟对象的移动信息。可选地,虚拟对象的移动信息是虚拟对象移动的轨迹,包括多个轨迹点。任一个轨迹点对应一个三维坐标和一个时间,轨迹点的三维坐标表征该轨迹点在虚拟场景中的位置,轨迹点的时间表征虚拟对象到达该轨迹点的时间。或者,虚拟对象的移动信息包括移动起点、移动方向、移动距离和移动终点等至少一项。
本申请实施例中,可视场景可能会随着虚拟对象的移动而发生更新。虚拟对象移动前的可视场景即为更新前的可视场景,也称第二可视场景;虚拟对象移动后的可视场景即为更新后的可视场景,也称第一可视场景。
第二可视场景被划分为多个第二层级对应的场景范围,一个第二层级对应一个场景范围,第二层级为多个,场景范围也有多个。电子设备可以直接获取各个第二层级对应的场景范围。任一个第二层级对应的场景范围的内容与任一个第一层级对应的场景范围的内容类似,可以见实现方式A1、A2的描述,在此不再赘述。
需要说明的是,多个第一层级中存在与任一个第二层级的范围尺寸相同的第一层级。也就是说,具有上下层级关系的多个第一层级的范围尺寸和具有上下层级关系的多个第二层级的范围尺寸依次对应相同。
本申请实施例中,基于虚拟对象的移动信息可以确定虚拟对象的移动距离,例如,基于虚拟对象的移动轨迹包括的多个轨迹点中的第一个轨迹点和最后一个轨迹点,确定虚拟对象的移动距离,或者,从虚拟对象的移动信息中提取出虚拟对象的移动距离。之后,可以计算虚拟对象的移动距离和任一个第二层级对应的场景范围的范围尺寸之间的比值,将该比值作为虚拟对象相对于该第二层级的移动幅度。若多个第二层级中存在目标层级,而虚拟对象相对于目标层级的移动幅度大于移动阈值,则电子设备确定满足阴影更新条件。
为了便于描述,将虚拟对象相对于该第二层级的移动幅度简称为第二移动幅度,将虚拟对象相对于目标层级的移动幅度简称为目标移动幅度。也就是说,电子设备可以确定多个第二移动幅度。如果一个第二移动幅度大于移动阈值,则该第二移动幅度对应的第二层级为目 标层级,该第二移动幅度为目标移动幅度。如果存在目标层级,则电子设备确定满足阴影更新条件。即,如果存在第二移动幅度大于移动阈值,则电子设备确定满足阴影更新条件。
本申请实施例不对移动阈值的内容做限定。示例性地,移动阈值是人工确定的数据。由于第二移动幅度是虚拟对象的移动距离和该第二层级对应的场景范围的范围尺寸之间的比值,因此,移动阈值也是一个比值,例如,移动阈值为10%。
情况B2,虚拟场景的光照发生改变。
当光照在不透光的物体上时,由于物体遮住了光的传播,导致光不能穿过物体而形成阴影区域,由此原理可知,阴影与光照息息相关。当虚拟场景的光照发生改变时,电子设备可以确定满足阴影更新条件。虚拟场景的光照发生改变包括虚拟场景中光照的方向发生改变、虚拟场景中光照与虚拟物体的距离发生改变等,例如,将点光源变成平行光会导致光照方向发生改变,或者虚拟场景中点光源与虚拟物体的距离变小等。
情况B3,初始化虚拟场景。
在本申请实施例提供的方法中,初始化虚拟场景可以是将虚拟场景设置为默认状态的场景,例如,在开始一局游戏时,电子设备可以初始化虚拟场景。当初始化虚拟场景时,由于需要渲染虚拟场景中的虚拟物体以及虚拟物体的阴影等,因此,电子设备可以确定满足阴影更新条件。
步骤202,对于多个第一层级中的任一个第一层级,基于任一个第一层级对应的场景范围,确定任一个第一层级对应的第一虚拟物体,第一虚拟物体是其阴影在任一个第一层级对应的场景范围内的虚拟物体。
本申请实施例中,由于光线具有直线传播的特性,因此,当光线遇到不透光的虚拟物体时会因不能穿过虚拟物体而形成一个暗区,该暗区即为虚拟物体的阴影。可选地,对于虚拟场景中的任一个虚拟物体,若该虚拟物体的阴影全部或者部分在该第一层级对应的场景范围内,则该虚拟物体为该第一层级对应的第一虚拟物体。第一层级对应至少一个第一虚拟物体。
在一种可能的实现方式中,步骤202包括步骤2021至步骤2023。
步骤2021,获取虚拟场景中多个虚拟物体在第一投影坐标系的参考投影范围。
可选地,虚拟场景中的多个虚拟物体可以是虚拟场景中所有的虚拟物体,也可以是从虚拟场景中所有的虚拟物体中挑选出的部分虚拟物体,这部分挑选出的虚拟物体可以称为任一个第一层级对应的候选虚拟物体。下面介绍任一个第一层级对应的候选虚拟物体的确定方式。
示例性地,在步骤2021之前还包括:基于扩展参数对任一个第一层级对应的场景范围进行扩展,得到任一个第一层级对应的参考范围;挑选位于参考范围内的多个虚拟物体。
本申请实施例不对扩展参数做限定。示例性地,扩展参数可以是扩展比例,且扩展比例大于1,这种情况下,第一层级对应的场景范围的范围尺寸乘以扩展比例,可以得到该第一层级对应的参考范围的范围尺寸。或者,扩展参数可以是扩展的场景范围,这种情况下,第一层级对应的场景范围加上扩展的场景范围,得到该第一层级对应的参考范围。
接着,从虚拟场景中的所有虚拟物体中选择位于任一个第一层级对应的参考范围内的虚拟物体,将选择出的虚拟物体作为该第一层级对应的候选虚拟物体,第一层级对应的候选虚拟物体也是步骤2021提及的虚拟场景中的多个虚拟物体。
接着,基于第一投影空间中的光源,将虚拟场景中的任一个虚拟物体投影到第一投影坐标系中,得到该虚拟物体在第一投影坐标系的参考投影范围。为了便于描述,将虚拟物体在第一投影坐标系的参考投影范围简称为虚拟对象的参考投影范围。这种情况下,虚拟物体的参考投影范围用于描述该虚拟物体在第一投影坐标系中的投影。第一投影坐标系用于定义第一投影空间,虚拟物体的参考投影范围相当于该虚拟物体在第一投影空间的投影面上的参考投影范围。第一投影空间中的光源可以是平均光、点光源等。本申请实施例不对虚拟物体的投影方式做限定。
可选地,步骤2021包括步骤C1至步骤C3。
步骤C1,对于任一个虚拟物体,确定任一个虚拟物体的包围盒。
由于虚拟物体可能是不规则的形状,结构相对复杂,而包围盒是规则的形状,结构相对简单,因此,通过确定虚拟物体的包围盒,将虚拟物体对应的复杂三维结构简化为包围盒对应的简单三维结构,从而降低数据量和结构复杂度,为后续数据处理的简化提供了基础。
在三维建模技术领域中,常用虚拟物体的三角网格数据来描述该虚拟物体。虚拟物体的三角网格数据包括多个顶点的数据,任一个顶点的数据包括该顶点的标识、该顶点在虚拟场景坐标系中的三维坐标、与该顶点连接的其他顶点的标识等。可以通过虚拟物体的三角网格数据来确定虚拟物体的包围盒,虚拟物体的包围盒是能够包围虚拟物体的最小几何体,其中,几何体可以是六面体、圆柱、球等。
可选地,虚拟场景坐标系包括横轴(即x轴)、纵轴(即y轴)和竖轴(即z轴)。可以从虚拟物体的三角网格数据中确定横轴最小的顶点、横轴最大的顶点、纵轴最小的顶点、纵轴最大的顶点、竖轴最小的顶点和竖轴最大的顶点。利用这六个顶点可以确定六个平面,从而得到包围虚拟物体的最小六面体,即得到虚拟物体的包围盒。
或者,可以采用主成分分析(Principal Component Analysis,PCA)的方法,对虚拟物体的三角网格数据进行分析,确定出三个坐标轴的方向、三个边的长度、中心点的坐标等信息,确定出这些信息相当于确定出虚拟物体的包围盒。
可以采用PCA的方法从三维空间中寻找一组相互正交的坐标轴,以得到虚拟物体的包围盒的三个坐标轴的方向。第一个坐标轴的方向满足使虚拟物体对应的各个顶点投影在该坐标轴之后,各个投影后的顶点的方差最大;第二个坐标轴的方向满足在与第一个坐标轴正交的平面中且使虚拟物体对应的各个顶点投影在该坐标轴之后,各个投影后的顶点的方差最大;第三个坐标轴的方向满足在与前两个坐标轴正交的平面中且使虚拟物体对应的各个顶点投影在该坐标轴之后,各投影后的顶点的方差最大。对虚拟物体对应的各个顶点的三维坐标求平均,可以得到虚拟物体的中心点的坐标,并将虚拟物体的中心点的坐标作为虚拟物体的包围盒的中心点的坐标。虚拟物体的包围盒的三个边的长度是基于虚拟物体对应的各个顶点在三个坐标轴上的分布来确定的。
步骤C2,基于包围盒,确定任一个虚拟物体的第一投影信息,第一投影信息用于描述包围盒在第一投影坐标系中的投影。
可以理解的是,虚拟物体的包围盒的数据量要小于虚拟物体的数据量,且虚拟物体的包围盒的三维结构比虚拟物体的三维结构简单。因此,与描述虚拟物体在第一投影坐标系中的投影的数据相比,通过虚拟物体的包围盒,确定虚拟物体的第一投影信息,实现了基于较少的数据量和简单的三维结构,确定出虚拟物体的大致投影范围,提高了处理速度,有利于提高渲染效率。
基于第一投影空间中的光源,将虚拟场景中的任一个虚拟物体的包围盒投影到第一投影坐标系中,得到该虚拟物体的包围盒在第一投影坐标系中的投影,从而得到该虚拟物体的第一投影信息。由于虚拟物体的包围盒包括多个顶点,因此,可以用各个顶点在虚拟场景坐标系中的坐标来描述虚拟物体的包围盒。可选地,将各个顶点在虚拟场景坐标系中的坐标转化为各个顶点在第一投影坐标系中的坐标,得到虚拟物体的第一投影信息。
由于第一投影坐标系用于定义第一投影空间,因此,该虚拟物体的包围盒在第一投影坐标系中的投影,相当于该虚拟物体在第一投影空间的投影面上的投影。
请参见图5,图5是本申请实施例提供的一种投影的示意图。在本示例中,投影空间中的光源为平行光。基于平行光,将虚拟场景中虚拟物体的包围盒投影到投影空间的投影面上,得到虚拟物体的包围盒在投影面上的投影。请参见图6,图6是本申请实施例提供的一种投影和投影的包围框的示意图,图6的左侧示出了虚拟物体的包围盒的投影,该投影是虚拟物体的包围盒在投影空间的投影面上的投影。
步骤C3,基于第一投影信息确定任一个虚拟物体的参考投影范围。
可选地,将虚拟物体的第一投影信息确定为虚拟物体在第一投影坐标系的参考投影范围。这种情况下,虚拟物体在第一投影坐标系的参考投影范围用于描述虚拟物体的包围盒在第一 投影坐标系中的投影。
可选地,步骤C3包括:基于第一投影信息确定任一个虚拟物体的第二投影信息,第二投影信息用于描述包围盒在第一投影坐标系中的投影的包围框;将第二投影信息确定为任一个虚拟物体的参考投影范围。
通过描述虚拟物体的包围盒在第一投影坐标系中的投影的包围框,由于投影可能是不规则的形状,结构相对复杂,而包围框是规则的形状,结构相对简单,因此,可以实现将投影对应的复杂二维结构简化为包围框对应的简单二维结构,从而降低数据量和结构复杂度,为后续数据处理的简化提供了基础。
本申请实施例中,虚拟物体的包围盒包括多个顶点,虚拟物体的第一投影信息可以包括各个顶点在第一投影坐标系中的坐标。第一投影坐标系为三维坐标系,包括横轴、纵轴和竖轴,其中,各个顶点在第一投影坐标系中的坐标对应相同的竖轴的值,因此,各个顶点在第一投影坐标系中位于与竖轴垂直的平面上。可以从多个顶点中确定横轴最小的顶点、横轴最大的顶点、纵轴最小的顶点和纵轴最大的顶点。由于基于这四个顶点可以确定出一个包围框,因此,可以将这四个顶点在第一投影坐标系中的坐标作为虚拟物体的第二投影信息,以利用虚拟物体的第二投影信息来描述虚拟物体的包围盒在第一投影坐标系中的投影的包围框。其中,可以参见图6,图6的右侧示出了虚拟物体的包围盒的投影的包围框,该投影是虚拟物体的包围盒在第一投影坐标系中的投影。
接着,可以将任一个虚拟物体的第二投影信息确定为该虚拟物体在第一投影坐标系的参考投影范围,这种情况下,虚拟物体在第一投影坐标系的参考投影范围用于描述该虚拟物体的包围盒在第一投影坐标系中的投影的包围框。可选地,虚拟物体的包围盒在第一投影坐标系中的投影的包围框为一个矩形,这种情况下,虚拟物体的参考投影范围可以是四个顶点的坐标,或者是矩形的四个边界等。
步骤2022,基于任一个第一层级对应的场景范围,确定任一个第一层级在第一投影坐标系的第一投影范围。
由于第一层级对应的场景范围是第一可视场景中的局部范围,因此,第一层级对应的场景范围是相对于虚拟场景坐标系而言的。又由于虚拟物体的参考投影范围是相对于第一投影坐标系而言的,因此,可以基于任一个第一层级对应的场景范围,确定该第一层级在第一投影坐标系的第一投影范围,以将第一层级对应的第一投影范围和虚拟物体的参考投影范围置于同一坐标系进行后续处理。
基于第一投影空间中的光源,将任一个第一层级对应的场景范围投影到第一投影坐标系中,得到该第一层级对应的场景范围在第一投影坐标系中的投影,从而得到该第一层级在第一投影坐标系的第一投影范围。
可选地,第一层级对应的场景范围为矩形。可以将矩形各个顶点在虚拟场景坐标系中的坐标转化为各个顶点在第一投影坐标系中的坐标,或者,可以将矩形在虚拟场景坐标系中的各个边界转化为在第一投影坐标系中的各个边界,得到第一层级在第一投影坐标系的第一投影范围。
步骤2023,对于任一个虚拟物体,若任一个虚拟物体的参考投影范围和第一投影范围有交叉,则将任一个虚拟物体确定为第一虚拟物体。
本申请实施例中,任一个虚拟物体在第一投影坐标系的参考投影范围用于描述虚拟物体在第一投影坐标系上大致的投影区域,而任一个第一层级在第一投影坐标系的第一投影范围用于描述第一层级对应的场景范围在第一投影坐标系中的投影,因此,可以确定任一个虚拟物体在第一投影坐标系的参考投影范围和任一个第一层级在第一投影坐标系的第一投影范围是否有包含现象。
当任一个虚拟物体在第一投影坐标系的参考投影范围全部或者部分包含在任一个第一层级在第一投影坐标系的第一投影范围时,说明该虚拟物体在第一投影坐标系的参考投影范围和该第一层级在第一投影坐标系的第一投影范围有交叉,虚拟物体会投影在该第一层级对应 的场景范围内,因此,可以将该虚拟物体确定为该第一层级对应的第一虚拟物体。
请参见图7,图7是本申请实施例提供的一种虚拟物体的参考投影范围和第一层级的第一投影范围之间的关系示意图。其中,图7示出了四个第一层级的第一投影范围,从内到外分别为第一个至第四个第一层级的第一投影范围,图7还示出了九个虚拟物体的参考投影范围。
由图7可知,第一个第一层级的第一投影范围与两个虚拟物体的参考投影范围有交叉,则第一个第一层级对应的第一虚拟物体为两个虚拟物体。相类似地,第二个第一层级对应的第一虚拟物体为三个虚拟物体;第三个第一层级对应的第一虚拟物体为五个虚拟物体;第四个第一层级对应的第一虚拟物体为九个虚拟物体。
由于任一个第一层级对应至少一个第一虚拟物体,因此,可以为任一个第一层级创建一个虚拟物体列表。任一个第一层级对应的虚拟物体列表包含该第一层级对应的各个第一虚拟物体的标识信息,通过任一个标识信息可以找到对应的第一虚拟物体。
本申请实施例是通过确定第一层级对应的场景范围的投影与虚拟物体的包围盒的投影之间的交叉关系,来确定虚拟物体是否为第一层级对应的第一虚拟物体。一方面,与虚拟物体相比,虚拟物体的包围盒是简单的三维结构,包围盒的投影的数据量较小、结构更简单;另一方面,与视锥体相比,第一层级对应的场景范围也是简单的结构,其投影的数据量较小、结构更简单。因此,与直接判断虚拟物体是否在视锥体内相比,本申请实施例可以基于简单的结构、较小的数据量来快速判断虚拟物体是否为第一层级对应的第一虚拟物体,提高了计算性能。
步骤203,基于第一虚拟物体,确定任一个第一层级对应的第一投影深度贴图,第一投影深度贴图用于描述多个第一顶点与光源之间的距离,多个第一顶点分别是第一虚拟物体面向光源的表面上的顶点。
在一种可能的实现方式中,可以基于第二投影空间中的光源和任一个第一层级对应的第一虚拟物体,确定该第一层级对应的投影深度贴图。为了便于描述,将任一个第一层级对应的投影深度贴图简称为第一投影深度贴图。可选地,可以沿着第二投影空间中光源的光照方向渲染任一个第一层级对应的第一虚拟物体,得到该第一虚拟物体面向光源的表面上的各个顶点与光源之间的距离。任一个顶点与光源之间的距离也称为该顶点的投影深度值,该第一投影深度贴图中包括各个第一顶点(即第一虚拟物体面向光源的表面上的顶点)的投影深度值。
由于各个第一层级对应不同的范围尺寸,因此,一个第一层级对应的投影深度贴图记录一定范围内的投影深度值。比如,第一个第一层级(记为Level0)对应的投影深度贴图记录32米内的投影深度值,第二个第一层级(记为Level1)对应的投影深度贴图记录64米内的投影深度值,第三个第一层级(记为Level2)对应的投影深度贴图记录128米内的投影深度值,以此类推,直到最大的范围尺寸为止。
可以将各个第一层级对应的投影深度贴图视作图集。可以配置一个纹理渲染(Render Texture)对象,利用该对象保存图集。请参见图8,图8左侧示出了一个第一层级对应的投影深度贴图,右侧示出了一个图集,该图集包括六个第一层级对应的投影深度贴图。图8左侧所示的投影深度贴图是图8右侧所示的图集中的一个投影深度贴图。
在一种可能的实现方式中,步骤203包括步骤2031至步骤2034。
步骤2031,基于第一虚拟物体的各个顶点在虚拟场景坐标系中的三维场景坐标,确定第一虚拟物体的各个顶点在第二投影坐标系中的三维投影坐标。
为了便于描述,将顶点在虚拟场景坐标系中的三维坐标简称为顶点的三维场景坐标,将顶点在第二投影坐标系中的三维坐标简称为顶点的三维投影坐标。可以基于虚拟场景坐标系和第二投影坐标系的转换关系,将任一个第一层级对应的第一虚拟物体的各个顶点的三维场景坐标,转换为该第一层级对应的第一虚拟物体的各个顶点的三维投影坐标。本申请实施例不对上述转换关系做限定。
步骤2032,基于任一个第一层级对应的场景范围和第一投影深度贴图的分辨率,确定调整系数。
可选地,将任一个第一层级对应的场景范围的范围尺寸与该第一层级对应的投影深度贴图的分辨率的比值,将比值作为调整系数,或者,对比值进行加权、对数、指数等至少一种计算,得到调整系数。
步骤2033,基于调整系数调整第一虚拟物体的各个顶点的三维投影坐标,得到第一虚拟物体的各个顶点调整后的三维投影坐标。
为了便于描述,将顶点在第二投影坐标系中调整后的三维坐标简称为顶点调整后的三维投影坐标。对于任一个第一层级对应的第一虚拟物体的任一个顶点,可以将该顶点的三维投影坐标作为被除数,将调整系数作为除数,按照“被除数÷除数=商……余数”的计算公式,可以得到商,将商乘以调整系数,得到该顶点调整后的三维投影坐标。
可选地,本申请实施例是按照如下所示的三维坐标调整代码,来对顶点的三维投影坐标进行调整,得到调整后的三维投影坐标,从而实现在第二投影坐标系和虚拟场景坐标系进行转换时,将三维坐标按照像素来取整对齐。
其中,meterPerPixel表征调整系数。顶点的三维投影坐标包括横轴的值pos.x、纵轴的值pos.y和竖轴的值pos.z。pos.x=Mathf.Floor(pos.x/meterPerPixel)*meterPerPixel表征横轴的值pos.x除以调整系数得到的商再乘以调整系数,得到调整后的横轴的值pos.x。其中,Mathf.Floor是表征查找最大整数的函数,其中,查找到的最大整数小于或者等于指定的浮点值,因此,Mathf.Floor(pos.x/meterPerPixel)表征商。基于与pos.x同样的原理,对纵轴的值pos.y、竖轴的值pos.z也做相类似的调整。顶点调整后的三维投影坐标包括调整后的横轴的值pos.x、调整后的纵轴的值pos.y、调整后的竖轴的值pos.z。
步骤2034,基于光源在第二投影坐标系中的三维投影坐标和第一虚拟物体的各个顶点调整后的三维投影坐标,确定第一投影深度贴图。
可选地,为便于描述,将光源在虚拟场景坐标系中的三维坐标简称为光源的三维场景坐标,将光源在第二投影坐标系中的三维坐标简称为光源的三维投影坐标。将参考点在虚拟场景坐标系中的三维坐标简称为参考点的三维场景坐标,将该参考点在虚拟场景坐标系中调整后的三维坐标简称为参考点调整后的三维场景坐标。将参考点在第二投影坐标系中的三维坐标简称为参考点的三维投影坐标,将参考点在第二投影坐标系中调整后的三维坐标简称为参考点调整后的三维投影坐标。
可以将参考点的三维场景坐标作为光源的三维场景坐标,将光源的三维场景坐标转化为光源的三维场景坐标。或者,可以将该参考点的三维场景坐标转化为该参考点的三维投影坐标。基于调整系数,调整该参考点的三维投影坐标,得到该参考点调整后的三维投影坐标。将该参考点调整后的三维投影坐标转化为该参考点调整后的三维场景坐标。设置光源的三维场景坐标为该参考点调整后的三维场景坐标。
接着,将光源的三维场景坐标转化为光源的三维投影坐标,以基于光源的三维投影坐标和任一个第一层级对应的第一虚拟物体的各个顶点调整后的三维投影坐标,确定任一个第一 层级对应的第一投影深度贴图。
示例性地,对于任一个第一层级对应的第一虚拟物体的任一个顶点,可以利用光源的三维投影坐标和该顶点调整后的三维投影坐标,计算出该顶点与光源之间的距离,该距离也为该顶点的投影深度值。通过计算各个顶点的投影深度值,从各个顶点的投影深度值中选择各个第一顶点的投影深度值,从而得到该第一层级对应的第一投影深度贴图。其中,第一顶点是第一虚拟物体面向光源的表面上的顶点,第一的投影深度贴图中记录有该第一层级对应的第一虚拟物体的各个第一顶点的投影深度值。
或者,从任一个第一层级对应的第一虚拟物体的各个顶点调整后的三维投影坐标中,确定各个第一顶点调整后的三维投影坐标。通过各个第一顶点调整后的三维投影坐标和光源的三维投影坐标,确定各个第一顶点与光源之间的距离,从而得到任一个第一层级对应的第一投影深度贴图。
可选地,步骤2034包括:基于调整系数调整光源的三维投影坐标,得到光源调整后的三维投影坐标,基于光源调整后的三维投影坐标和第一虚拟物体的各个顶点调整后的三维投影坐标,确定第一投影深度贴图。
本申请实施例中,对光源的三维投影坐标进行调整的方式可以见步骤2033的描述,在此不再赘述。简单来说,可以将光源的三维投影坐标作为被除数,将调整系数作为除数,按照“被除数÷除数=商……余数”的计算公式,可以得到商,将商乘以调整系数,得到光源调整后的三维投影坐标。
本申请实施例中,按照如下所示的步骤E1至E8来确定光源调整后的三维投影坐标。
步骤E1,获取参考点的三维场景坐标Pos,其中,参考点可以是任一个第一层级对应的场景范围的中心点或者重心点。
步骤E2,获取光源的旋转矩阵lightMatrix,该旋转矩阵包括光源的光照方向和光源的初始化坐标。
步骤E3,将Pos转换为PosInLight,其中,PosInLight是参考点的三维投影坐标。
步骤E4,PosInLight=PositionAlignment(PosInLight),其中,PositionAlignment是上文提及的三维坐标调整代码。因此,步骤E4相当于对参考点的三维投影坐标进行调整,得到参考点调整后的三维投影坐标。
步骤E5,利用lightMatrix的逆矩阵将PosInLight转换为PosInWorld,其中,PosInWorld是参考点调整后的三维场景坐标。
步骤E6,将PosInWorld赋值给lightMatrix中光源的初始化坐标。步骤E6相当于将光源的初始化坐标调整为PosInWorld,也就是说,光源的三维场景坐标设置成PosInWorld。
步骤E7,计算lightMatrix的逆矩阵lightMatrixInverse。步骤E7相当于将光源的三维场景坐标转换为光源的三维投影坐标,且光源的光照方向不变。
步骤E8,使用PositionAlignment对齐lightMatrixInverse中的坐标值,得到最终的投影矩阵。其中,PositionAlignment是上文提及的三维坐标调整代码。因此,步骤E8相当于对光源的三维投影坐标进行调整,得到光源调整后的三维投影坐标。
接着,对于任一个第一层级对应的第一虚拟物体的任一个顶点,可以利用光源调整后的三维投影坐标和该顶点调整后的三维投影坐标,计算出该顶点与光源之间的距离,该距离也为该顶点的投影深度值。通过计算各个顶点的投影深度值,可以利用各个第一顶点的投影深度值得到该第一层级对应的第一投影深度贴图。
或者,从任一个第一层级对应的第一虚拟物体的各个顶点调整后的三维投影坐标中,确定各个第一顶点调整后的三维投影坐标。通过各个第一顶点调整后的三维投影坐标和光源调整后的三维投影坐标,确定各个第一顶点与光源之间的距离,从而得到任一个第一层级对应的第一投影深度贴图。
通过三维坐标调整代码,来对顶点、光源的三维投影坐标进行调整,得到调整后的三维投影坐标,实现了在第二投影坐标系和虚拟场景坐标系进行转换时,将三维坐标按照像素来 取整对齐。由于进行了对齐操作,使得第一可视场景变换时,例如,旋转第一可视场景、平移第一可视场景,均可以使变换前的第一可视场景中某个虚拟物体的阴影与变换后的第一可视场景中这个虚拟物体的阴影相同,也就是达到第一可视场景变换而阴影不抖动的效果,提高第一可视场景的真实性。
在一种可能的实现方式中,步骤203包括步骤2035至步骤2036。其中,上述步骤2031至步骤2034是利用阴影在任一个第一层级对应的场景范围内的所有虚拟物体,直接投影得到该第一层级对应的第一投影深度贴图,属于全局更新的方式。而步骤2035至步骤2036是基于局部更新的方式,确定第一层级对应的第一投影深度贴图。下面详细描述步骤2035至步骤2036的各个步骤。
步骤2035,对于任一个第一层级,响应于虚拟对象相对于相关层级的相关移动幅度大于移动阈值,获取相关层级对应的相关投影深度贴图,相关层级是场景范围的尺寸与任一个第一层级对应的场景范围的尺寸相同的第二层级,相关投影深度贴图用于描述多个第二顶点与光源之间的距离,多个第二顶点分别是相关层级对应的第三虚拟物体面向光源的表面上的顶点,第三虚拟物体是其阴影在相关层级对应的场景范围内的虚拟物体。
本申请实施例中,多个第二层级中存在与任一个第一层级的范围尺寸相同的第二层级,将该第二层级记为该第一层级的相关层级。其中,上文已描述了第二层级的相关内容、虚拟对象相对于第二层级的移动幅度的确定方式,在此不再赘述。此外,第二层级对应的投影深度贴图的内容和第一层级对应的投影深度贴图的内容相类似,在此不再赘述。
其中,电子设备的缓存中存储有各个第二层级对应的投影深度贴图,便于后续直接使用第二层级对应的投影深度贴图或者对第二层级对应的投影深度贴图进行局部更新,以降低图形处理器(Graphics Processing Unit)的性能开销。
为了便于描述,将虚拟对象相对于相关层级的移动幅度称为相关移动幅度,将相关层级对应的相关投影深度贴图称为相关投影深度贴图。当相关移动幅度大于移动阈值时,可以获取相关投影深度贴图。可选地,各个第二层级对应的投影深度贴图也可视作图集,通过对该图集进行更新得到各个第一层级对应的投影深度贴图。为便于描述,将更新前的图集称为第二图集,第二图集包括各个第二层级对应的投影深度贴图,将更新后的图集称为第一图集,第一图集包括各个第一层级对应的投影深度贴图。当相关移动幅度大于移动阈值时,可以从第二图集中拷贝出相关投影深度贴图。
步骤2036,基于第一虚拟物体和相关投影深度贴图,确定第一投影深度贴图。
由于第一层级和相关层级对应相同的范围尺寸,因此,可以基于第一层级对应的第一虚拟物体,对相关层级对应的投影深度贴图进行更新,得到第一层级对应的投影深度贴图。可选地,从第二图集中拷贝出相关层级对应的投影深度贴图,将第一层级对应的投影深度贴图拷贝回第二图集,以实现更新第二图集,得到第一图集。
在一种可能的实现方式中,步骤2036包括步骤D1至步骤D3。
步骤D1,基于相关移动幅度,对相关投影深度贴图进行剪切,得到剪切后的投影深度贴图。
当虚拟对象相对于相关层级移动时,移动前的层级(即相关层级)和移动后的层级(即第一层级)可能对应相同的内容。也就是说,相关层级对应的投影深度贴图可能包含第一层级对应的全部或者部分第一虚拟物体对应的投影深度值。基于此,基于虚拟对象相对于相关层级的移动幅度,剪切相关层级对应的投影深度贴图,以使剪切后的投影深度贴图保留相关层级和第一层级二者共同对应的相同的投影深度值。
可选地,虚拟对象相对于相关层级的移动幅度为一个比值,这种情况下,从相关层级对应的投影深度贴图中剪切掉这个比值对应的贴图,得到剪切后的投影深度贴图。
步骤D2,从第一虚拟物体中确定出任一个第一层级对应的第二虚拟物体,第二虚拟物体是其阴影在任一个第一层级对应的剩余范围内的虚拟物体,剩余范围是任一个第一层级对应的场景中除剪切后的投影深度贴图对应的局部场景之外剩余场景的范围。
剪切后的投影深度贴图对应任一个第一层级对应的场景范围内的局部场景,该第一层级对应的场景范围内除该局部场景之外剩余场景的范围记为该第一层级对应的剩余范围。也就是说,第一层级对应的场景范围包括局部场景的范围和剩余场景的范围。当该第一层级对应的第一虚拟物体的阴影在该第一层级对应的剩余范围内,则将该第一层级对应的第一虚拟物体作为该第一层级对应的第二虚拟物体。其中,第一层级对应至少一个第二虚拟物体。
可选地,步骤D2包括步骤D21至步骤D23。
步骤D21,确定第一虚拟物体在第一投影坐标系的参考投影范围。其中,步骤D21的实现方式与步骤2021的实现方式相类似,在此不再赘述。
步骤D22,基于剩余范围,确定任一个第一层级在第一投影坐标系的第二投影范围。其中,步骤D22的实现方式与步骤2022的实现方式相类似,在此不再赘述。
步骤D23,若第一虚拟物体的参考投影范围和第二投影范围有交叉,则将第一虚拟物体确定为第二虚拟物体。其中,步骤D23的实现方式与步骤2023的实现方式相类似,在此不再赘述。
步骤D3,基于第二虚拟物体和剪切后的投影深度贴图,确定第一投影深度贴图。
可以理解的是,任一个第一层级对应的第二虚拟物体的阴影在该第一层级对应的剩余场景内,而剪切后的投影深度贴图描述了阴影在该局部场景内的虚拟物体的投影深度值。因此,该第一层级对应的第二虚拟物体和剪切后的投影深度贴图可以对应阴影在该第一层级对应的场景范围内的所有虚拟物体,使得基于该第一层级对应的第二虚拟物体和剪切后的投影深度贴图,可以确定出该第一层级对应的投影深度贴图。
可选地,步骤D3包括步骤D31至步骤D32。
步骤D31,基于第二虚拟物体,确定任一个第一层级对应的补充贴图,补充贴图用于描述多个第三顶点与光源之间的距离,任一个第三顶点是第二虚拟物体面向光源的表面上的顶点。
可以理解的是,步骤D31的实现原理与步骤203的实现原理相类似,在此不再赘述。
步骤D32,将补充贴图和剪切后的投影深度贴图进行拼接,得到第一投影深度贴图。
将任一个第一层级对应的补充贴图拼接在剪切后的投影深度贴图的剪切线的对端,得到该第一层级对应的投影深度贴图。例如,将相关层级对应的投影深度贴图的下方剪去10%,此时剪切后的投影深度贴图的下方边缘线为剪切线,可以将第一层级对应的补充贴图拼接在剪切后的投影深度贴图的上方边缘线,得到该第一层级对应的投影深度贴图。
可选地,获取空白的临时图片,临时图片的图片尺寸与任一个第一层级对应的投影深度贴图的图片尺寸相同。将剪切后的投影深度贴图拷贝至临时图片中,此时,临时图片的一部分内容为剪切后的投影深度贴图,另一部分内容是空白的。将该第一层级对应的补充贴图拷贝至临时图片的空白处,以实现将该第一层级对应的补充贴图和剪切后的投影深度贴图进行拼接,此时,临时图片不存在空白处,临时图片的内容为第一层级对应的投影深度贴图。
可选地,可以先将剪切后的投影深度贴图拷贝至临时图片中。接着,基于任一个第一层级对应的第二虚拟物体,在临时图片的空白处写入该第一层级对应的补充贴图,以实现确定该第一层级对应的补充贴图的同时,将该第一层级对应的补充贴图和剪切后的投影深度贴图进行拼接,得到第一层级对应的投影深度贴图。
请参见图9,图9是本申请实施例提供的一种投影深度贴图的确定示意图。图9的左侧示出了将剪切后的投影深度贴图拷贝至临时图片后的示意图,此时,临时图片存在空白处,例如,该空白处占临时图片的10%。通过在临时图片的空白处写入该第一层级对应的补充贴图,得到图9右侧所示的示意图,此时,临时图片的内容为第一层级对应的投影深度贴图。
本申请实施例中,当虚拟对象相对于相关层级的移动幅度大于移动阈值时,可以理解为虚拟对象移动前的层级所对应的场景范围中的内容与虚拟对象移动后的层级所对应的场景范围中的内容变化较大。这种情况下,可以对相关层级对应的投影深度贴图进行剪切,并确定出第一层级对应的补充贴图,通过将第一层级对应的补充贴图和剪切后的投影深度贴图进行 拼接,得到第一层级对应的投影深度贴图。通过这种投影深度贴图的局部更新方式,可以避免重新投影出第一层级对应的投影深度贴图和相关层级对应的投影深度贴图中相同的部分,而仅投影出不同的部分,从而降低了计算量,提高了计算效率。
在一种可能的实现方式中,本申请实施例的阴影渲染方法还包括步骤2037,且步骤2037是在步骤204之前执行。
步骤2037,响应于相关移动幅度不大于移动阈值,则将相关投影深度贴图,确定为第一投影深度贴图。
本申请实施例中,相关层级是虚拟对象移动前的层级,任一个第一层级为虚拟对象移动后的层级。当虚拟对象相对于相关层级的移动幅度不大于移动阈值时,虚拟对象移动前的层级所对应的场景范围中的内容与虚拟对象移动后的层级所对应的场景范围中的内容变化较小,可以忽略不计。通过将相关层级对应的投影深度贴图,确定为该第一层级对应的投影深度贴图,避免了重新投影出第一层级对应的投影深度贴图,从而降低了计算量,且虚拟对象移动前的层级对应的场景范围中的阴影和虚拟对象移动后的层级对应的场景范围中的阴影相同。
目前,存在阴影地图(Shadow Map)的阴影渲染方案,当相机位置、相机方向发生改变时,需要判断虚拟物体与视锥体的关系。当虚拟物体的全部或者部分在视锥体内时,可以将该虚拟物体作为目标物体。确定目标物体对应的深度投影贴图,以利用目标物体对应的深度投影贴图渲染阴影。因此,Shadow Map是每当相机位置、相机方向发生改变,均需要重新投影出深度投影贴图。而对于本申请实施例,一方面,当虚拟对象相对于相关层级的移动幅度大于移动阈值时,采用投影深度贴图的局部更新方式投影出第一层级对应的投影深度贴图,降低了计算量,提高了计算效率;另一方面,当虚拟对象相对于相关层级的移动幅度不大于移动阈值时,投影深度贴图不变,与Shadow Map相比,本申请实施例可以在仅改变相机方向(例如,旋转相机但相机位置不变)、虚拟对象的移动幅度较小(可以对应为相机的移动幅度较小)的情况下,不更新投影深度贴图,从而实现不更新阴影的效果,降低渲染开销。
步骤204,基于第一投影深度贴图,渲染第一可视场景中的阴影。
第一层级对应的投影深度贴图中记录了阴影在第一层级对应的场景范围内的虚拟物体的投影深度值,而多个第一层级对应的场景范围构成了第一可视场景,因此,通过多个第一层级对应的投影深度贴图,可以渲染出第一可视场景中的阴影。
在一种可能的实现方式中,步骤204包括步骤2041至步骤2044。
步骤2041,对于任一个第四顶点,确定任一个第四顶点与光源之间的第一距离,任一个第四顶点是第一可视场景内的虚拟物体面向相机的表面上的顶点。
为便于描述,将第四顶点在虚拟场景坐标系中的三维坐标简称为第四顶点的三维场景坐标,将第四顶点在第二投影坐标系中的三维坐标简称为第四顶点的三维投影坐标。本申请实施例中,电子设备可以获取任一个第四顶点的三维场景坐标,并将该第四顶点的三维场景坐标映射为该第四顶点的三维投影坐标。通过获取光源的三维投影坐标,利用该第四顶点的三维投影坐标和光源三维投影坐标,计算得到该第四顶点与光源之间的第一距离。
可选地,可以基于调整系数对该第四顶点的三维投影坐标进行调整,得到该第四顶点调整后的三维投影坐标。利用该第四顶点调整后的三维投影坐标和光源的三维投影坐标,计算得到该第四顶点与光源之间的距离,该距离可以记为第一距离。其中,第四顶点的三维坐标的调整方式可以见步骤2031至步骤2033的描述,二者实现原理相类似,在此不再赘述。
可选地,可以基于调整系数对光源的三维投影坐标进行调整,得到光源调整后的三维投影坐标。利用光源调整后的三维投影坐标和第四顶点的三维投影坐标,或者,利用光源调整后的三维投影坐标和第四顶点调整后的三维投影坐标,计算得到该第四顶点与光源之间的第一距离。其中,光源的三维坐标的调整方式可以见步骤2034的描述,二者实现原理相类似,在此不再赘述。
步骤2042,从多个第一层级中确定参考层级,任一个第四顶点是参考层级对应的场景范围内的虚拟物体上的顶点。
任一个第一层级对应的场景范围是第一可视场景中的局部范围,而任一个第四顶点是第一可视场景中虚拟物体上的顶点,因此,可以基于该第四顶点的三维场景坐标,从多个第一层级中确定出至少一个候选层级,且该第四顶点是任一个候选层级对应的场景范围内的虚拟物体上的顶点。由于多个第一层级可以视作具有上下层级关系的层级,且多个第一层级中上一个第一层级的范围尺寸小于下一个第一层级的范围尺,因此,可以从至少一个候选层级中确定最上面的层级,将最上面的层级作为参考层级,以确定出参考层级对应的投影深度贴图。
例如,在图4的(1)中示出了具有上下层级关系的第一层级0至第一层级3。候选层级包括第一层级1至第一层级3时,参考层级为最上面的层级,即第一层级1。
步骤2043,从参考层级对应的投影深度贴图中确定任一个第四顶点对应的第一顶点与光源之间的第二距离。
本申请实施例中,在确定参考层级对应的投影深度贴图时,需要确定出各个第一顶点(调整后的)的三维投影坐标,从而确定出各个第一顶点与光源之间的距离,得到参考层级对应的投影深度贴图。基于此,基于光源(调整后的)的三维投影坐标和任一个第四顶点(调整后的)的三维投影坐标,从各个第一顶点中确定该第四顶点对应的第一顶点,其中,第四顶点与其对应的第一顶点在同一根光线上,也就是说,光源、第四顶点以及第四顶点对应的第一顶点在同一条直线上。
由于参考层级对应的投影深度贴图描述了各个第一顶点与光源之间的距离,因此,可以基于参考层级对应的投影深度贴图,确定任一个第四顶点对应的第一顶点与光源之间的距离,该距离可以记为第二距离。
请参见图10,图10是本申请实施例提供的一种第一可视场景和投影深度贴图的关系示意图。图10的左侧示出了第一可视场景,第一可视场景中包括面向相机的各个第四顶点;图10的右侧示出了第一图集,第一图集包括各个第一层级对应的投影深度贴图。由图10可知,针对面向相机的任一个第四顶点(即图10中箭头的起点),可以在第一图集中确定出该第四顶点所对应的第一顶点(即图10中箭头的终点),从而得到第四顶点所对应的第一顶点与光源之间的距离,即第四顶点所对应的第一顶点的投影深度值。
步骤2044,响应于第一距离大于第二距离,则在任一个第四顶点的位置处渲染阴影。
第四顶点是虚拟物体面向相机的表面上的顶点,第一顶点是虚拟物体面向光源的表面上的顶点。当第一距离大于第二距离时,说明相机可以看到第四顶点,而光源无法照射到第四顶点,这种情况下,第四顶点应为阴影处,因此,电子设备在第四顶点的位置处渲染阴影。当第一距离不大于第二距离时,说明相机可以看到第四顶点,而光源也可以照射到第四顶点,这种情况下,第四顶点应为光照处,因此,电子设备可以计算出光照信息,并基于光照信息在第四顶点的位置处渲染光照。
通过这种方式,电子设备可以在第一可视场景中面向相机的任一个第四顶点出渲染阴影或者光照,从而渲染出第一可视场景以及第一可视场景中的阴影。
本申请实施例中,第一层级对应的第一虚拟物体包括动态的虚拟物体和静态的虚拟物体,这种情况下,步骤203中的第一层级对应的投影深度贴图既包括动态的虚拟物体中第一顶点的投影深度值,也包括静态的虚拟物体中第一顶点的投影深度值。
可选地,将第一层级对应的第一虚拟物体所包括的动态的虚拟物体和静态的虚拟物体分离。这种情况下,第一层级对应的投影深度贴图包括第一层级对应的动态的虚拟物体所对应的投影深度贴图和第一层级对应的静态的虚拟物体所对应的投影深度贴图。第一层级对应的动态的虚拟物体所对应的投影深度贴图包括动态的虚拟物体中第一顶点的投影深度值;第一层级对应的静态的虚拟物体所对应的投影深度贴图包括静态的虚拟物体中第一顶点的投影深度值。可以利用第一对象(例如Render Texture)来存储第一层级对应的静态的虚拟物体所对应的投影深度贴图,利用第二对象(例如Pre Object)来存储第一层级对应的动态的虚拟物体所对应的投影深度贴图,从而实现动静分离的存储方案。
需要说明的是,本申请所涉及的信息(包括但不限于用户设备信息、用户个人信息等)、 数据(包括但不限于用于分析的数据、存储的数据、展示的数据等)以及信号,均为经用户授权或者经过各方充分授权的,且相关数据的收集、使用和处理需要遵守相关地区的相关法律法规和标准。例如,本申请中涉及到的虚拟场景、虚拟对象的移动信息等都是在充分授权的情况下获取的。
上述方法中,第一层级对应的场景范围是虚拟场景包括的第一可视场景中的局部范围,相当于在运行虚拟场景的过程中,实时根据第一可视场景确定各个第一层级对应的场景范围。通过各个第一层级对应的场景范围确定各个第一层级对应的第一虚拟物体,以基于各个第一层级对应的第一虚拟物体确定各个第一层级对应的投影深度贴图,实现了在虚拟场景的运行过程中,实时确定第一可视场景中的各个局部范围对应的投影深度贴图。相较于确定并存储虚拟场景中各个虚拟物体的阴影贴图来说可以降低存储资源的占用情况。通过第一可视场景中的各个局部范围对应的投影深度贴图来渲染第一可视场景中的阴影,有利于提高阴影的表现效果,提高虚拟场景的逼真度。
上述从方法步骤的角度阐述了本申请实施例的阴影渲染方法,下面结合图11来系统地描述该方法。请参见图11,图11是本申请实施例提供的一种第一可视场景的渲染方法的流程图,该流程图包括S1至S21。
S1,实时监测虚拟对象在虚拟场景中的移动。
S2,确定第一可视场景。第一可视场景是虚拟对象移动后的场景,虚拟对象移动前的场景可以记为第二可视场景。
S3,确定多个第一层级对应的场景范围。其中,各个第一层级对应的场景范围是对第一可视场景进行划分得到的。
S4,实时监测虚拟场景中光源方向的改变。
S5,确定虚拟物体的包围盒的投影。
S6,确定虚拟对象的包围盒的投影的包围框。
接着,从多个第一层级的第一个第一层级开始,将第一个第一层级记为第i个第一层级。
S7,确定包围框是否与第i个第一层级对应的场景范围的投影有交叉。
若无交叉,则执行S8,不需要确定第i个第一层级对应的投影深度贴图。
若有交叉,则执行S9至S14。
S9,确定第i个第一层级对应的虚拟物体列表。第i个第一层级对应的虚拟物体列表包括第i个第一层级对应的各个第一虚拟物体。
S10,确定是否局部更新。这里是指第i个第一层级对应的投影深度贴图是否局部更新。
若不需要局部更新,则执行S11,确定第i个第一层级对应的投影深度贴图。此处是基于第i个第一层级对应的虚拟物体列表,直接确定出第i个第一层级对应的投影深度贴图。
若需要局部更新,则执行S12至S14。
S12,对第i个第二层级对应的投影深度贴图进行剪切并拷贝至临时图片。
S13,在临时图片中确定第i个第一层级对应的补充贴图,使得临时图片中包括剪切后的投影深度贴图和第i个第一层级对应的补充贴图拼接后得到的贴图。其中,S13是从第i个第一层级对应的虚拟物体列表中确定出第i个第一层级对应的各个第二虚拟物体,基于第i个第一层级对应的各个第二虚拟物体,在临时图片中确定第i个第一层级对应的补充贴图。
S14,拷贝临时图片得到第i个第一层级对应的投影深度贴图。
接着,执行S11或者S14之后执行S15,确定第i个第一层级是否为最后一个第一层级。
若第i个第一层级不是最后一个第一层级,则执行S16,将第i+1个第一层级视作第i个第一层级。接着,从S7开始执行循环,直至第i个第一层级是最后一个第一层级为止。
若第i个第一层级是最后一个第一层级,则循环结束,可以得到各个第一层级对应的投影深度贴图。
接下来,执行S17,确定第一可视场景内的虚拟物体面向相机的表面上的顶点。
S18,确定参考层级。其中,参考层级是多个第一层级中的一个第一层级。
S19,采样参考层级对应的投影深度贴图。
S20,确定是否在顶点处渲染阴影。其中,S20是基于参考层级对应的投影深度贴图和第一可视场景内的虚拟物体面向相机的表面上的顶点,确定是否在顶点处渲染阴影。
S21,输出渲染结果。其中,若确定结果为在顶点处渲染阴影,则渲染结果是在顶点处渲染阴影;若确定结果为不在顶点处渲染阴影,则渲染结果是在顶点处渲染光照。
通过上述方式,可以渲染第一可视场景中的阴影。本申请实施例是在虚拟场景的运行过程中,根据虚拟对象在虚拟场景中的运动,实时确定各个第一层级对应的投影深度贴图,可以降低存储资源的占用情况,提升阴影渲染性能。通过各个第一层级对应的投影深度贴图来渲染第一可视场景中的阴影,有利于提高阴影的表现效果,支持更大范围的高质量阴影效果,为制作大世界场景提供了有力支持。
本申请实施例中,利用相关技术中的两种阴影渲染方案和图11所示的阴影渲染方案来分别渲染第一可视场景中的阴影,得到了如下表1所示的统计数据。其中,阴影地图(Shadow Map)和级联阴影地图(Cascaded Shadow Map,CSM)是相关技术中的两种阴影渲染方案,阴影缓存(Shadow Cache)是图11所示的阴影渲染方案。
表1
由表1可知,Shadow Cache的视距更大,绘制调用(Draw Call)的数量更少,帧率更高,因此,图11所示的阴影渲染方案的渲染性能更好,可支持大世界场景超远视距的全场景阴影渲染。
请参见图12和图13,图12是本申请实施例提供的一种不带有阴影的第一可视场景的示意图,图13是本申请实施例提供的一种具有阴影的第一可视场景的示意图。其中,图13是按照图11所示的阴影渲染方案渲染得到的。由图12和图13可知,本申请实施例可以在第一可视场景中渲染阴影,提高第一可视场景的逼真度。
由于本申请实施例具有计算量较小、所需存储资源较少的优势,因此,本申请实施例能降低中央处理器(Central Processing Unit,CPU)和图形处理器(Graphics Processing Unit)的性能开销,具有广泛的硬件兼容性,适用于电脑、手机、游戏机等具有GPU的硬件设备,且对硬件设备的要求较低。
图14所示为本申请实施例提供的一种阴影渲染装置的结构示意图,如图14所示,该装置包括:
确定模块1401,用于确定多个第一层级对应的场景范围,第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者所述第一可视场景中的局部范围;
确定模块1401,还用于对于多个第一层级中的任一个第一层级,基于任一个第一层级对应的场景范围,确定任一个第一层级对应的第一虚拟物体,第一层级对应的第一虚拟物体是其阴影在任一个第一层级对应的场景范围内的虚拟物体;
确定模块1401,还用于基于第一虚拟物体,确定任一个第一层级对应的第一投影深度贴图,第一投影深度贴图用于描述多个第一顶点与光源之间的距离,多个第一顶点分别是第一虚拟物体面向光源的表面上的顶点;
渲染模块1402,用于基于第一投影深度贴图,渲染第一可视场景中的阴影。
在一种可能的实现方式中,确定模块1401,用于响应于满足阴影更新条件,确定多个第 一层级对应的场景范围;
满足阴影更新条件包括以下至少一项:虚拟对象在虚拟场景中移动;虚拟场景的光照发生改变;初始化虚拟场景。
在一种可能的实现方式中,装置还包括:
获取模块,用于当虚拟对象在虚拟场景中移动时,获取虚拟对象的移动信息和多个第二层级对应的场景范围,第二层级对应的场景范围是虚拟场景包括的第二可视场景的范围或者第二可视场景中的局部范围,第一可视场景是虚拟对象移动后的可视场景,第二可视场景是虚拟对象移动前的可视场景;
确定模块1401,还用于对于任一个第二层级,基于虚拟对象的移动信息和任一个第二层级对应的场景范围,确定虚拟对象相对于任一个第二层级的第二移动幅度;
确定模块1401,还用于响应于多个第二层级中存在目标层级,则确定满足阴影更新条件,虚拟对象相对于目标层级的目标移动幅度大于移动阈值。
在一种可能的实现方式中,确定模块1401,用于获取各个第一层级的范围尺寸;对于任一个第一层级,基于第一可视场景的参考点和任一个第一层级的范围尺寸,在第一可视场景中确定任一个第一层级对应的场景范围。
在一种可能的实现方式中,确定模块1401,用于获取虚拟场景中多个虚拟物体在第一投影坐标系的参考投影范围;基于任一个第一层级对应的场景范围,确定任一个第一层级在第一投影坐标系的第一投影范围;对于任一个虚拟物体,若任一个虚拟物体的参考投影范围和第一投影范围有交叉,则将任一个虚拟物体确定为第一虚拟物体。
在一种可能的实现方式中,装置还包括:
扩展模块,用于基于扩展参数对任一个第一层级对应的场景范围进行扩展,得到任一个第一层级对应的参考范围;
挑选模块,用于挑选位于参考范围内的多个虚拟物体。
在一种可能的实现方式中,确定模块1401,用于对于任一个虚拟物体,确定任一个虚拟物体的包围盒;基于包围盒,确定任一个虚拟物体的第一投影信息,第一投影信息用于描述包围盒在第一投影坐标系中的投影;基于第一投影信息确定任一个虚拟物体系的参考投影范围。
在一种可能的实现方式中,确定模块1401,用于基于第一投影信息确定任一个虚拟物体的第二投影信息,第二投影信息用于描述包围盒在第一投影坐标系中的投影的包围框;将第二投影信息确定为任一个虚拟物体的参考投影范围。
在一种可能的实现方式中,确定模块1401,用于基于第一虚拟物体的各个顶点在虚拟场景坐标系中的三维场景坐标,确定第一虚拟物体的各个顶点在第二投影坐标系中的三维投影坐标;基于任一个第一层级对应的场景范围和第一投影深度贴图的分辨率,确定调整系数;基于调整系数调整第一虚拟物体的各个顶点的三维投影坐标,得到第一虚拟物体的各个顶点调整后的三维投影坐标;基于光源在第二投影坐标系中的三维投影坐标和第一虚拟物体的各个顶点调整后的三维投影坐标,确定第一投影深度贴图。
在一种可能的实现方式中,确定模块1401,用于基于调整系数调整光源的三维投影坐标,得到光源调整后的三维投影坐标;基于光源调整后的三维投影坐标和第一虚拟物体的各个顶点调整后的三维投影坐标,确定第一投影深度贴图。
在一种可能的实现方式中,确定模块1401,用于对于任一个第一层级,响应于虚拟对象相对于相关层级的相关移动幅度大于移动阈值,获取相关层级对应的相关投影深度贴图,相关层级是场景范围的尺寸与任一个第一层级对应的场景范围的尺寸相同的第二层级,相关投影深度贴图用于描述多个第二顶点与光源之间的距离,多个第二顶点分别是相关层级对应的第三虚拟物体面向光源的表面上的顶点,第三虚拟物体是其阴影在相关层级对应的场景范围内的虚拟物体;基于第一虚拟物体和相关投影深度贴图,确定第一投影深度贴图。
在一种可能的实现方式中,确定模块1401,用于基于相关移动幅度,对相关投影深度贴 图进行剪切,得到剪切后的投影深度贴图;从第一虚拟物体中确定出任一个第一层级对应的第二虚拟物体,第二虚拟物体是其阴影在任一个第一层级对应的剩余范围内的虚拟物体,剩余范围是任一个第一层级对应的场景中除剪切后的投影深度贴图对应的局部场景之外剩余场景的范围;基于第二虚拟物体和剪切后的投影深度贴图,确定第一投影深度贴图。
在一种可能的实现方式中,确定模块1401,用于确定第一虚拟物体在第一投影坐标系的参考投影范围;基于剩余范围,确定任一个第一层级在第一投影坐标系的第二投影范围;若第一虚拟物体的参考投影范围和第二投影范围有交叉,则将第一虚拟物体确定为第二虚拟物体。
在一种可能的实现方式中,确定模块1401,用于基于第二虚拟物体,确定任一个第一层级对应的补充贴图,补充贴图用于描述多个第三顶点与光源之间的距离,多个第三顶点分别是第二虚拟物体面向光源的表面上的顶点;将补充贴图和剪切后的投影深度贴图进行拼接,得到第一投影深度贴图。
在一种可能的实现方式中,确定模块1401,还用于响应于相关移动幅度不大于移动阈值,则将相关投影深度贴图,确定为第一投影深度贴图。
在一种可能的实现方式中,渲染模块1402,用于对于任一个第四顶点,确定任一个第四顶点与光源之间的第一距离,任一个第四顶点是第一可视场景内的虚拟物体面向相机的表面上的顶点;从多个第一层级中确定参考层级,任一个第四顶点是参考层级对应的场景范围内的虚拟物体上的顶点;从参考层级对应的投影深度贴图中确定任一个第四顶点对应的第一顶点与光源之间的第二距离;响应于第一距离大于第二距离,则在任一个第四顶点的位置处渲染阴影。
上述装置中第一层级对应的场景范围是虚拟场景包括的第一可视场景中的局部范围,相当于在运行虚拟场景的过程中,实时根据第一可视场景确定各个第一层级对应的场景范围。通过各个第一层级对应的场景范围确定各个第一层级对应的第一虚拟物体,以基于各个第一层级对应的第一虚拟物体确定各个第一层级对应的投影深度贴图,实现了在虚拟场景的运行过程中,实时确定第一可视场景中的各个局部范围对应的投影深度贴图。相较于确定并存储虚拟场景中各个虚拟物体的阴影贴图来说可以降低存储资源的占用情况。通过第一可视场景中的各个局部范围对应的投影深度贴图来渲染第一可视场景中的阴影,有利于提高阴影的表现效果,提高虚拟场景的逼真度。
应理解的是,上述图14提供的装置在实现其功能时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将设备的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的装置与方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
图15示出了本申请一个示例性实施例提供的终端设备1500的结构框图。该终端设备1500包括有:处理器1501和存储器1502。
处理器1501可以包括一个或多个处理核心,比如4核心处理器、8核心处理器等。处理器1501可以采用DSP(Digital Signal Processing,数字信号处理)、FPGA(Field-Programmable Gate Array,现场可编程门阵列)、PLA(Programmable Logic Array,可编程逻辑阵列)中的至少一种硬件形式来实现。处理器1501也可以包括主处理器和协处理器,主处理器是用于对在唤醒状态下的数据进行处理的处理器,也称CPU(Central Processing Unit,中央处理器);协处理器是用于对在待机状态下的数据进行处理的低功耗处理器。在一些实施例中,处理器1501可以集成有GPU(Graphics Processing Unit,图像处理器),GPU用于负责显示屏所需要显示的内容的渲染和绘制。一些实施例中,处理器1501还可以包括AI(Artificial Intelligence,人工智能)处理器,该AI处理器用于处理有关机器学习的计算操作。
存储器1502可以包括一个或多个计算机可读存储介质,该计算机可读存储介质可以是非暂态的。存储器1502还可包括高速随机存取存储器,以及非易失性存储器,比如一个或多个 磁盘存储设备、闪存存储设备。在一些实施例中,存储器1502中的非暂态的计算机可读存储介质用于存储至少一个计算机程序,该至少一个计算机程序用于被处理器1501所执行以实现本申请中方法实施例提供的阴影渲染方法。
在一些实施例中,终端设备1500还可选包括有:显示屏1505。
显示屏1505用于显示UI(User Interface,用户界面)。该UI可以包括图形、文本、图标、视频及其它们的任意组合。当显示屏1505是触摸显示屏时,显示屏1505还具有采集在显示屏1505的表面或表面上方的触摸信号的能力。该触摸信号可以作为控制信号输入至处理器1501进行处理。此时,显示屏1505还可以用于提供虚拟按钮和/或虚拟键盘,也称软按钮和/或软键盘。在一些实施例中,显示屏1505可以为一个,设置在终端设备1500的前面板;在另一些实施例中,显示屏1505可以为至少两个,分别设置在终端设备1500的不同表面或呈折叠设计;在另一些实施例中,显示屏1505可以是柔性显示屏,设置在终端设备1500的弯曲表面上或折叠面上。甚至,显示屏1505还可以设置成非矩形的不规则图形,也即异形屏。显示屏1505可以采用LCD(Liquid Crystal Display,液晶显示屏)、OLED(Organic Light-Emitting Diode,有机发光二极管)等材质制备。示例性地,第一可视场景、第一可视场景中的阴影等通过显示屏1505显示。
本领域技术人员可以理解,图15中示出的结构并不构成对终端设备1500的限定,可以包括比图示更多或更少的组件,或者组合某些组件,或者采用不同的组件布置。
图16为本申请实施例提供的服务器的结构示意图,该服务器1600可因配置或性能不同而产生比较大的差异,可以包括一个或多个处理器1601和一个或多个的存储器1602,其中,该一个或多个存储器1602中存储有至少一条计算机程序,该至少一条计算机程序由该一个或多个处理器1601加载并执行以实现上述各个方法实施例提供的阴影渲染方法,示例性的,处理器1601为CPU。当然,该服务器1600还可以具有有线或无线网络接口、键盘以及输入输出接口等部件,以便进行输入输出,该服务器1600还可以包括其他用于实现设备功能的部件,在此不做赘述。
在示例性实施例中,还提供了一种非易失性计算机可读存储介质,该非易失性计算机可读存储介质中存储有至少一条计算机程序,该至少一条计算机程序由处理器加载并执行,以使电子设备实现上述任一种阴影渲染方法。
可选地,上述非易失性计算机可读存储介质可以是只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、只读光盘(Compact Disc Read-Only Memory,CD-ROM)、磁带、软盘和光数据存储设备等。
在示例性实施例中,还提供了一种计算机程序,该计算机程序为至少一条,该至少一条计算机程序由处理器加载并执行,以使电子设备实现上述任一种阴影渲染方法。
在示例性实施例中,还提供了一种计算机程序产品,该计算机程序产品中存储有至少一条计算机程序,该至少一条计算机程序由处理器加载并执行,以使电子设备实现上述任一种阴影渲染方法。
应当理解的是,在本文中提及的“多个”是指两个或两个以上。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。字符“/”一般表示前后关联对象是一种“或”的关系。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
以上所述仅为本申请的示例性实施例,并不用以限制本申请,凡在本申请的原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。

Claims (21)

  1. 一种阴影渲染方法,其中,所述方法由电子设备执行,所述方法包括:
    确定多个第一层级对应的场景范围,所述第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者所述第一可视场景中的局部范围;
    对于所述多个第一层级中的任一个第一层级,基于所述任一个第一层级对应的场景范围,确定所述任一个第一层级对应的第一虚拟物体,所述第一虚拟物体是其阴影在所述任一个第一层级对应的场景范围内的虚拟物体;
    基于所述第一虚拟物体,确定所述任一个第一层级对应的第一投影深度贴图,所述第一投影深度贴图用于描述多个第一顶点与光源之间的距离,所述多个第一顶点分别是所述第一虚拟物体面向所述光源的表面上的顶点;
    基于所述第一投影深度贴图,渲染所述第一可视场景中的所述阴影。
  2. 根据权利要求1所述的方法,其中,所述确定多个第一层级对应的场景范围,包括:
    响应于满足阴影更新条件,确定多个第一层级对应的场景范围;
    所述满足阴影更新条件包括以下至少一项:
    虚拟对象在所述虚拟场景中移动;所述虚拟场景的光照发生改变;初始化所述虚拟场景。
  3. 根据权利要求1或2所述的方法,其中,所述方法,还包括:
    当虚拟对象在所述虚拟场景中移动时,获取所述虚拟对象的移动信息和多个第二层级对应的场景范围,所述第二层级对应的场景范围是虚拟场景包括的第二可视场景的范围或者所述第二可视场景中的局部范围,所述第一可视场景是所述虚拟对象移动后的可视场景,所述第二可视场景是所述虚拟对象移动前的可视场景;
    对于任一个第二层级,基于所述虚拟对象的移动信息和所述任一个第二层级对应的场景范围,确定所述虚拟对象相对于所述任一个第二层级的第二移动幅度;
    响应于所述多个第二层级中存在目标层级,则确定满足所述阴影更新条件,所述虚拟对象相对于所述目标层级的目标移动幅度大于移动阈值。
  4. 根据权利要求1所述的方法,其中,所述确定多个第一层级对应的场景范围,包括:
    获取各个第一层级的范围尺寸;
    对于任一个第一层级,基于所述第一可视场景的参考点和所述任一个第一层级的范围尺寸,在所述第一可视场景中确定所述任一个第一层级对应的场景范围。
  5. 根据权利要求1至4任一项所述的方法,其中,所述基于所述任一个第一层级对应的场景范围,确定所述任一个第一层级对应的第一虚拟物体,包括:
    获取所述虚拟场景中多个虚拟物体在第一投影坐标系的参考投影范围;
    基于所述任一个第一层级对应的场景范围,确定所述任一个第一层级在所述第一投影坐标系的第一投影范围;
    对于任一个虚拟物体,若所述任一个虚拟物体的参考投影范围和所述第一投影范围有交叉,则将所述任一个虚拟物体确定为所述第一虚拟物体。
  6. 根据权利要求5所述的方法,其中,所述获取所述虚拟场景中多个虚拟物体在第一投影坐标系的参考投影范围之前,还包括:
    基于扩展参数对所述任一个第一层级对应的场景范围进行扩展,得到所述任一个第一层级对应的参考范围;
    挑选位于所述参考范围内的多个虚拟物体。
  7. 根据权利要求5所述的方法,其中,所述获取所述虚拟场景中多个虚拟物体在第一投影坐标系的参考投影范围,包括:
    对于所述任一个虚拟物体,确定所述任一个虚拟物体的包围盒;
    基于所述包围盒,确定所述任一个虚拟物体的第一投影信息,所述第一投影信息用于描述所述包围盒在所述第一投影坐标系中的投影;
    基于所述第一投影信息确定所述任一个虚拟物体的参考投影范围。
  8. 根据权利要求7所述的方法,其中,所述基于所述第一投影信息确定所述任一个虚拟物体的参考投影范围,包括:
    基于所述第一投影信息确定所述任一个虚拟物体的第二投影信息,所述第二投影信息用于描述所述包围盒在所述第一投影坐标系中的投影的包围框;
    将所述第二投影信息确定为所述任一个虚拟物体的参考投影范围。
  9. 根据权利要求1至8任一项所述的方法,其中,所述基于所述第一虚拟物体,确定所述任一个第一层级对应的第一投影深度贴图,包括:
    基于所述第一虚拟物体的各个顶点在虚拟场景坐标系中的三维场景坐标,确定所述第一虚拟物体的各个顶点在第二投影坐标系中的三维投影坐标;
    基于所述任一个第一层级对应的场景范围和所述第一投影深度贴图的分辨率,确定调整系数;
    基于所述调整系数调整所述第一虚拟物体的各个顶点的三维投影坐标,得到所述第一虚拟物体的各个顶点调整后的三维投影坐标;
    基于所述光源在所述第二投影坐标系中的三维投影坐标和所述第一虚拟物体的各个顶点调整后的三维投影坐标,确定所述第一投影深度贴图。
  10. 根据权利要求9所述的方法,其中,所述基于所述光源在所述第二投影坐标系中的三维投影坐标和所述第一虚拟物体的各个顶点调整后的三维投影坐标,确定所述第一投影深度贴图,包括:
    基于所述调整系数调整所述光源的三维投影坐标,得到所述光源调整后的三维投影坐标;
    基于所述光源调整后的三维投影坐标和所述第一虚拟物体的各个顶点调整后的三维投影坐标,确定所述第一投影深度贴图。
  11. 根据权利要求1至8任一项所述的方法,其中,所述基于所述第一虚拟物体,确定所述任一个第一层级对应的第一投影深度贴图,包括:
    对于任一个第一层级,响应于虚拟对象相对于相关层级的相关移动幅度大于移动阈值,获取所述相关层级对应的相关投影深度贴图,所述相关层级是场景范围的尺寸与所述任一个第一层级对应的场景范围的尺寸相同的第二层级,所述相关投影深度贴图用于描述多个第二顶点与所述光源之间的距离,所述多个第二顶点分别是所述相关层级对应的第三虚拟物体面向所述光源的表面上的顶点,所述第三虚拟物体是其阴影在所述相关层级对应的场景范围内的虚拟物体;
    基于所述第一虚拟物体和所述相关投影深度贴图,确定所述第一投影深度贴图。
  12. 根据权利要求11所述的方法,其中,所述基于所述第一虚拟物体和所述相关投影深度贴图,确定所述第一投影深度贴图,包括:
    基于所述相关移动幅度,对所述相关投影深度贴图进行剪切,得到剪切后的投影深度贴图;
    从所述第一虚拟物体中确定出所述任一个第一层级对应的第二虚拟物体,所述第二虚拟物体是其阴影在所述任一个第一层级对应的剩余范围内的虚拟物体,所述剩余范围是所述任一个第一层级对应的场景中除所述剪切后的投影深度贴图对应的局部场景之外剩余场景的范围;
    基于所述第二虚拟物体和所述剪切后的投影深度贴图,确定所述第一投影深度贴图。
  13. 根据权利要求12所述的方法,其中,所述从所述第一虚拟物体中确定出所述任一个第一层级对应的第二虚拟物体,包括:
    确定所述第一虚拟物体在第一投影坐标系的参考投影范围;
    基于所述剩余范围,确定所述任一个第一层级在所述第一投影坐标系的第二投影范围;
    若所述第一虚拟物体的参考投影范围和所述第二投影范围有交叉,则将所述第一虚拟物体确定为所述第二虚拟物体。
  14. 根据权利要求12所述的方法,其中,所述基于所述第二虚拟物体和所述剪切后的投影深度贴图,确定所述第一投影深度贴图,包括:
    基于所述第二虚拟物体,确定所述任一个第一层级对应的补充贴图,所述补充贴图用于描述多个第三顶点与所述光源之间的距离,所述多个第三顶点分别是所述第二虚拟物体面向所述光源的表面上的顶点;
    将所述补充贴图和所述剪切后的投影深度贴图进行拼接,得到所述第一投影深度贴图。
  15. 根据权利要求11所述的方法,其中,所述方法还包括:
    响应于所述相关移动幅度不大于所述移动阈值,则将所述相关投影深度贴图,确定为所述第一投影深度贴图。
  16. 根据权利要求1至15任一项所述的方法,其中,所述基于所述第一投影深度贴图,渲染所述第一可视场景中的所述阴影,包括:
    对于任一个第四顶点,确定所述任一个第四顶点与所述光源之间的第一距离,所述任一个第四顶点是所述第一可视场景内的虚拟物体面向相机的表面上的顶点;
    从所述多个第一层级中确定参考层级,所述任一个第四顶点是所述参考层级对应的场景范围内的虚拟物体上的顶点;
    从所述参考层级对应的投影深度贴图中确定所述任一个第四顶点对应的第一顶点与所述光源之间的第二距离;
    响应于所述第一距离大于所述第二距离,则在所述任一个第四顶点的位置处渲染所述阴影。
  17. 一种阴影渲染装置,其中,所述装置包括:
    确定模块,用于确定多个第一层级对应的场景范围,所述第一层级对应的场景范围是虚拟场景包括的第一可视场景的范围或者所述第一可视场景中的局部范围;
    所述确定模块,还用于对于所述多个第一层级中的任一个第一层级,基于所述任一个第一层级对应的场景范围,确定所述任一个第一层级对应的第一虚拟物体,所述第一虚拟物体是其阴影在所述任一个第一层级对应的场景范围内的虚拟物体;
    所述确定模块,还用于基于所述第一虚拟物体,确定所述任一个第一层级对应的第一投影深度贴图,所述第一投影深度贴图用于描述多个第一顶点与光源之间的距离,所述多个第一顶点分别是所述第一虚拟物体面向所述光源的表面上的顶点;
    渲染模块,用于基于所述第一投影深度贴图,渲染所述第一可视场景中的所述阴影。
  18. 一种电子设备,其中,所述电子设备包括处理器和存储器,所述存储器中存储有至少一条计算机程序,所述至少一条计算机程序由所述处理器加载并执行,以使所述电子设备实现如权利要求1至16任一所述的阴影渲染方法。
  19. 一种非易失性计算机可读存储介质,其中,所述非易失性计算机可读存储介质中存储有至少一条计算机程序,所述至少一条计算机程序由处理器加载并执行,以使电子设备实现如权利要求1至16任一所述的阴影渲染方法。
  20. 一种计算机程序产品,其中,所述计算机程序产品中存储有至少一条计算机程序,所述至少一条计算机程序由处理器加载并执行,以使电子设备实现如权利要求1至16任一所述的阴影渲染方法。
  21. 一种计算机程序,其中,所述计算机程序为至少一条,至少一条计算机程序由处理器加载并执行,以使电子设备实现如权利要求1至16任一所述的阴影渲染方法。
PCT/CN2023/123331 2022-11-03 2023-10-08 阴影渲染方法、装置、电子设备及可读存储介质 Ceased WO2024093610A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP23884542.4A EP4553777A4 (en) 2022-11-03 2023-10-08 SHADOW RENDERING METHOD AND APPARATUS, ELECTRONIC DEVICE AND READABLE STORAGE MEDIA
US18/885,221 US12675946B2 (en) 2022-11-03 2024-09-13 Shadow rendering method and apparatus, electronic device, and readable storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211368766.6A CN116993897A (zh) 2022-11-03 2022-11-03 阴影渲染方法、装置、电子设备及可读存储介质
CN202211368766.6 2022-11-03

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US18/885,221 Continuation US12675946B2 (en) 2022-11-03 2024-09-13 Shadow rendering method and apparatus, electronic device, and readable storage medium

Publications (1)

Publication Number Publication Date
WO2024093610A1 true WO2024093610A1 (zh) 2024-05-10

Family

ID=88527191

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/123331 Ceased WO2024093610A1 (zh) 2022-11-03 2023-10-08 阴影渲染方法、装置、电子设备及可读存储介质

Country Status (4)

Country Link
US (1) US12675946B2 (zh)
EP (1) EP4553777A4 (zh)
CN (1) CN116993897A (zh)
WO (1) WO2024093610A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118379419A (zh) * 2024-06-24 2024-07-23 网易(杭州)网络有限公司 虚拟对象模型的处理方法、装置、计算机设备及存储介质

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20260179272A1 (en) * 2024-12-23 2026-06-25 Motorola Mobility Llc Managing virtual background image lighting for realistic video communication sessions

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180276878A1 (en) * 2017-03-24 2018-09-27 Mz Ip Holdings, Llc System and method for rendering shadows for a virtual environment
CN111105491A (zh) * 2019-11-25 2020-05-05 腾讯科技(深圳)有限公司 场景渲染方法、装置、计算机可读存储介质和计算机设备
CN112215936A (zh) * 2020-10-16 2021-01-12 广州虎牙科技有限公司 图像渲染方法、装置、电子设备及存储介质
CN113256781A (zh) * 2021-06-17 2021-08-13 腾讯科技(深圳)有限公司 虚拟场景的渲染和装置、存储介质及电子设备
US11232628B1 (en) * 2020-11-10 2022-01-25 Weta Digital Limited Method for processing image data to provide for soft shadow effects using shadow depth information

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012083508A1 (zh) * 2010-12-24 2012-06-28 中国科学院自动化研究所 互联网上复杂场景真实感快速绘制方法
US9646413B2 (en) * 2014-08-27 2017-05-09 Robert Bosch Gmbh System and method for remote shadow rendering in a 3D virtual environment
CN109993823B (zh) * 2019-04-11 2022-11-25 腾讯科技(深圳)有限公司 阴影渲染方法、装置、终端及存储介质
CN111489430B (zh) * 2020-04-08 2024-03-01 网易(杭州)网络有限公司 游戏的光影数据处理方法、装置以及游戏设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180276878A1 (en) * 2017-03-24 2018-09-27 Mz Ip Holdings, Llc System and method for rendering shadows for a virtual environment
CN111105491A (zh) * 2019-11-25 2020-05-05 腾讯科技(深圳)有限公司 场景渲染方法、装置、计算机可读存储介质和计算机设备
CN112215936A (zh) * 2020-10-16 2021-01-12 广州虎牙科技有限公司 图像渲染方法、装置、电子设备及存储介质
US11232628B1 (en) * 2020-11-10 2022-01-25 Weta Digital Limited Method for processing image data to provide for soft shadow effects using shadow depth information
CN113256781A (zh) * 2021-06-17 2021-08-13 腾讯科技(深圳)有限公司 虚拟场景的渲染和装置、存储介质及电子设备

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4553777A4

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118379419A (zh) * 2024-06-24 2024-07-23 网易(杭州)网络有限公司 虚拟对象模型的处理方法、装置、计算机设备及存储介质

Also Published As

Publication number Publication date
US20250014268A1 (en) 2025-01-09
EP4553777A1 (en) 2025-05-14
US12675946B2 (en) 2026-07-07
EP4553777A4 (en) 2026-02-11
CN116993897A (zh) 2023-11-03

Similar Documents

Publication Publication Date Title
KR101086570B1 (ko) 동적 윈도우 구조
RU2360284C2 (ru) Компонующий администратор окон рабочего стола
US20140267228A1 (en) Mapping augmented reality experience to various environments
WO2024027237A1 (zh) 渲染的优化方法、电子设备和计算机可读存储介质
US7561156B2 (en) Adaptive quadtree-based scalable surface rendering
CN113900797B (zh) 基于虚幻引擎的三维倾斜摄影数据处理方法、装置及设备
US20250371799A1 (en) Illumination Rendering Methods and Systems
JP2023529790A (ja) フロアプランを生成するための方法、装置およびプログラム
US20250014268A1 (en) Shadow rendering method and apparatus, electronic device, and readable storage medium
US11967030B2 (en) Method, device and computer program product for manipulating virtual bounding volumes
CN107392990B (zh) 渲染3d场景的全局照明
US20240203030A1 (en) 3d model rendering method and apparatus, electronic device, and storage medium
US12002165B1 (en) Light probe placement for displaying objects in 3D environments on electronic devices
CN110930497B (zh) 一种全局光照相交加速方法、装置及计算机存储介质
WO2025055518A1 (zh) 虚拟画面的生成方法、装置、电子设备、计算机可读存储介质及计算机程序产品
CN118807200A (zh) 体积云的绘制方法、装置、电子设备及程序产品
EP4459558B1 (en) Rendering method and apparatus, and device and storage medium
JP2003115055A (ja) 画像生成装置
US10643395B2 (en) Real-time spatial authoring in augmented reality using additive and subtractive modeling
CN116777731A (zh) 软光栅化的方法、装置、设备、介质及程序产品
WO2019231668A1 (en) Casting shadows using silhouettes
WO2025050797A1 (zh) 一种渲染方法、装置、电子设备、计算机可读存储介质及计算机程序产品
WO2024244640A1 (zh) 模型接缝修复方法、装置、设备和介质
CN115761106A (zh) 信息处理方法、装置、存储介质以及电子装置
HK40100926A (zh) 阴影渲染方法、装置、电子设备及可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23884542

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 2023884542

Country of ref document: EP

ENP Entry into the national phase

Ref document number: 2023884542

Country of ref document: EP

Effective date: 20250207

WWP Wipo information: published in national office

Ref document number: 2023884542

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE