Shadow rendering method and device
By filtering and categorizing visible objects in three-dimensional scenes, the method addresses redundant shadow rendering, achieving efficient and accurate shadow effects.
Patent Information
- Application Number
- CN202411421653.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2024-12-20
AI Technical Summary
Existing shadow rendering methods in three-dimensional scenes incur redundant overhead due to rendering shadows for invisible objects, affecting efficiency.
A method that filters out visible objects from initial objects based on light source information and virtual camera parameters, classifies them into categories, and performs shadow rendering accordingly to avoid redundant rendering.
Accurately renders shadows while improving efficiency by avoiding invisible object rendering and multiple renderings of the same object, enhancing the realism and performance of three-dimensional scenes.
Smart Images

Figure CN119169172A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of computer technology, and more particularly to a shadow rendering method and device. Background Art
[0002] With the development of computer technology, the application of three-dimensional scenes has gradually replaced the application of traditional two-dimensional scenes. Whether it is film and television works or game screens, the use of three-dimensional scenes has become more and more frequent. Shadow rendering is an indispensable part of three-dimensional scenes. Shadow rendering refers to the process of simulating the shadow effect produced when an object in the real world is illuminated by a light source during the rendering of a three-dimensional object. The existence of shadows greatly enhances the realism of the scene and makes the scene look more natural.
[0003] Currently, the graphics processing unit (GPU) usually renders shadows for all objects in the scene to ensure the comprehensiveness of shadow rendering. However, some objects are invisible from the camera perspective, and shadow rendering for these objects results in a lot of redundant overhead in the rendering process, which affects the efficiency of shadow rendering. Therefore, an efficient shadow rendering solution is urgently needed. Summary of the invention
[0004] In view of this, an embodiment of the present specification provides a shadow rendering method. One or more embodiments of the present specification also relate to a shadow rendering device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.
[0005] According to a first aspect of an embodiment of this specification, a shadow rendering method is provided, comprising: Obtaining a shadow rendering request of a target screen, wherein the shadow rendering request carries multiple initial objects, light source information of the target screen, and virtual camera parameters; According to the light source information and the virtual camera parameters, a target object is selected from the multiple initial objects, wherein the target object is a visible object in the target picture; Classify the target object to obtain the object category of the target object; According to the object category, shadow rendering is performed on the target object in the target picture to obtain a shadow rendering result.
[0006] According to a second aspect of an embodiment of this specification, a shadow rendering device is provided, comprising: An acquisition module is configured to acquire a shadow rendering request of a target picture, wherein the shadow rendering request carries a plurality of initial objects, light source information of the target picture, and virtual camera parameters; A screening module is configured to screen out a target object from a plurality of initial objects according to light source information and virtual camera parameters, wherein the target object is a visible object in a target picture; A classification module is configured to classify the target object and obtain an object category of the target object; The rendering module is configured to perform shadow rendering on the target object in the target picture according to the object category to obtain a shadow rendering result.
[0007] According to a third aspect of an embodiment of this specification, a computing device is provided, including: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer program / instructions are executed by the processor, the steps of the shadow rendering method provided in the first aspect are implemented.
[0008] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores a computer program / instruction, and when the computer program / instruction is executed by a processor, the steps of the shadow rendering method provided in the first aspect are implemented.
[0009] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instruction, which, when executed by a processor, implements the steps of the shadow rendering method provided in the first aspect above.
[0010] A shadow rendering method provided by an embodiment of the present specification includes: obtaining a shadow rendering request of a target screen, wherein the shadow rendering request carries multiple initial objects, light source information of the target screen, and virtual camera parameters; filtering out a target object from multiple initial objects according to the light source information and virtual camera parameters, wherein the target object is a visible object in the target screen; classifying the target object to obtain an object category of the target object; and performing shadow rendering on the target object in the target screen according to the object category to obtain a shadow rendering result. By filtering out the visible target object in the target screen from multiple initial objects, redundant rendering of invisible objects and multiple rendering of the same object are avoided. Through one shadow rendering request, shadow classification rendering is performed based on the object category to obtain shadow rendering results of all target objects, thereby achieving accurate shadow rendering and further improving shadow rendering efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 is a flowchart of a shadow rendering method provided by an embodiment of this specification; Figure 2 is a flow chart of a shadow rendering method based on directional light provided by an embodiment of this specification; Figure 3 is a flowchart of a shadow rendering method based on local light provided by an embodiment of this specification; Figure 4 is a process flow chart of a shadow rendering method provided by an embodiment of the present specification; Figure 5 is an architecture diagram of a shadow rendering system provided by an embodiment of this specification; Figure 6 is a structural schematic diagram of a shadow rendering device provided by an embodiment of this specification; Figure 7 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0012] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0013] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0014] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0015] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data 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 countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0016] First, the terms involved in one or more embodiments of this specification are explained.
[0017] Core processor (CPU, Central Processing Unit): The core processor is one of the main hardware of the computer, responsible for executing instructions in the computer program, controlling and coordinating the work of various parts of the system.
[0018] Graphics Processing Unit (GPU): A graphics processor can also be called a display core, visual processor, or display chip. It is a microprocessor that specializes in performing image and graphics-related calculations on personal computers, workstations, game consoles, and some mobile devices (such as tablets, smartphones, etc.).
[0019] Application Programming Interface (API): A set of predefined functions that allows applications and developers to access a set of routines based on certain software or hardware without having to access the source code or understand the details of the internal working mechanism.
[0020] Indirect Rendering: is an advanced technology used in computer graphics that allows applications to specify rendering commands and parameters through a buffer instead of directly calling the rendering function in the graphics API. This method can greatly improve the efficiency of drawing a large number of geometric bodies or instantiated objects, because by setting up a large number of rendering operations at one time and then executing all commands through a call, it can reduce API overhead and improve performance.
[0021] Cascaded Shadow Maps (CSM): is a technique used in computer graphics to improve the effect of shadow mapping, especially when dealing with large scenes with both near and far objects. Traditional shadow mapping technology encounters a problem when dealing with objects of different distances, that is, the resolution of the shadow map is fixed, which causes distant objects and nearby objects to share the same resolution, resulting in the loss of shadow details of nearby objects, the so-called "perspective aliasing" phenomenon. In order to improve this situation, cascaded shadow technology was introduced. Cascaded shadow technology divides the scene into several levels (cascades), each with its own shadow map and corresponding resolution. Usually, these levels are divided according to certain rules along the line of sight from the camera's perspective, so that each level can use different resolutions according to its distance from the camera. Levels closer to the camera use higher resolutions, while levels farther from the camera use lower resolutions.
[0022] Shadow Rendering: It is a technique in computer graphics that simulates the shadow effect caused by the light source being blocked. In 3D graphics rendering, the addition of shadows can make the scene look more realistic and have depth. The goal of shadow rendering technology is to determine which surface areas are blocked by other objects and should not be directly exposed to light.
[0023] A 3D (Three-Dimensional) scene is a virtual environment built in a three-dimensional space. This environment consists of multiple three-dimensional models and can be created, rendered, and interacted with through computer graphics technology. 3D scenes are widely used in game development, film production, architectural design, engineering design, medical simulation, virtual reality, augmented reality, and other fields.
[0024] Bounding Box: It is a concept commonly used in computer graphics, computer vision, and game development. It refers to a rectangle or cube (rectangle in two-dimensional space, cube or axis-aligned bounding box in three-dimensional space) that is used to approximately enclose one or a group of objects. During the rendering process, if the bounding box of an object is not within the current viewport, the entire object can be quickly excluded from the rendering, thereby saving computing resources.
[0025] In computer graphics, shadow rendering is an integral part of 3D scenes. However, in highly complex scenes, shadow rendering often consumes a lot of computing resources. Especially when using a game development engine for development, the commonly used indirect rendering interface is used to render GPU-clipped data. Since the CPU cannot accurately know the list of objects clipped by the GPU, it can only pass a large bounding box to ensure that all objects can be rendered. This causes each light and cascade shadow that casts a shadow to intersect with the object's bounding box, resulting in a large amount of redundant shadow rendering overhead, which affects performance. In addition, each object that needs to render a shadow may be drawn repeatedly multiple times, adding unnecessary computing burden.
[0026] In order to solve the above problems, the embodiments of this specification propose an indirect rendering shadow optimization solution. By modifying the rendering pipeline, the visible target objects in the target picture are screened out from multiple initial objects according to the light source information and virtual camera parameters, thereby avoiding redundant rendering of invisible objects and multiple renderings of the same object. Through a shadow rendering request, shadow classification rendering is performed based on the object category to obtain the shadow rendering results of all target objects, thereby achieving accurate shadow rendering and further improving the shadow rendering efficiency.
[0027] It is worth noting that the shadow rendering method proposed in the embodiments of this specification can be executed by the terminal device, or can be executed jointly by the CPU and GPU in the terminal device. The execution subject of the shadow rendering method is selected according to the actual situation, and the embodiments of this specification do not impose any restrictions on this. Next, taking the CPU and GPU jointly executing the shadow rendering method as an example, the shadow rendering method is described in detail.
[0028] In this specification, a shadow rendering method is provided. This specification also relates to a shadow rendering device, a computing device, a computer-readable storage medium and a computer program product, which are described in detail one by one in the following embodiments.
[0029] See also Figure 1 , Figure 1 A flowchart of a shadow rendering method provided by an embodiment of the present specification is shown, which specifically includes the following steps: Step 102: Obtain a shadow rendering request of a target picture, wherein the shadow rendering request carries a plurality of initial objects, light source information of the target picture, and virtual camera parameters.
[0030] It should be noted that the target screen refers to the image that is finally presented on the screen, and can also be understood as the screen frame that the user sees on the display. The target screen is composed of the results of a series of rendering operations, including various elements such as background, foreground, special effects, lighting, and shadows. The target screen can be a screen in different scenes, such as a target game screen in a game scene, or a target live screen in a live scene. The specific selection is based on the actual situation, and the embodiments of this specification do not make any restrictions on this.
[0031] A shadow rendering request refers to a series of instructions or requests issued to add a shadow effect to a target page. A shadow rendering request may include a variety of information, such as resolution, multiple initial objects, light source information of the target screen, and parameters of a virtual camera. An initial object refers to an object in the target screen to be shadow rendered. The initial object includes a target object visible in the target screen and an object invisible in the target screen. Taking a game scene as an example, the initial object may be a stone, a tree, a box, a building, and the like in the target game screen. The light source information of the target screen refers to the correlation information of the screen light source used to simulate the lighting effect when rendering the shadow in the target page. The light source information includes, but is not limited to, the light source position, the light source type, the light source shadow distance, and the light source color, which are selected according to the actual situation, and the embodiments of this specification do not impose any restrictions on this. The shadow rendering request may be one or more. If the shadow rendering request is multiple, the target object of each shadow rendering request may be screened out from the multiple initial objects carried by the shadow rendering request in parallel according to the light source information and virtual camera parameters carried by each shadow rendering request.
[0032] Virtual camera parameters refer to parameters used to simulate the characteristics of a real camera. Virtual camera parameters determine the viewing angle, clarity, exposure and other characteristics of the target page. Virtual camera parameters include but are not limited to the camera position, camera shadow distance, near clipping plane and far clipping plane of the virtual camera. The selection is made according to the actual situation, and the embodiments of this specification do not impose any restrictions on this. Among them, the near clipping plane refers to the closest visible distance to the virtual camera, and objects less than this distance will not be visible. The far clipping plane refers to the farthest visible distance from the virtual camera, and objects greater than this distance will not be visible.
[0033] In actual applications, there are many ways to obtain a shadow rendering request for a target screen, which are selected according to actual conditions, and the embodiments of this specification do not impose any restrictions on this. In one possible implementation of this specification, the GPU can receive a shadow rendering request for a target screen sent by the CPU. In another possible implementation of this specification, the GPU can read a shadow rendering request from a request cache queue, wherein the request cache queue includes candidate shadow rendering requests sent by multiple CPUs.
[0034] Step 104: Filter out a target object from a plurality of initial objects according to the light source information and the virtual camera parameters, wherein the target object is a visible object in the target picture.
[0035] It should be noted that the target object refers to an object that can appear in the target screen, that is, an object that is finally presented on the screen, and can also be understood as an object that the user can see on the display. The number of target objects can be one or more, which is selected according to actual conditions, and this specification embodiment does not impose any limitation on this.
[0036] In practical applications, there are many ways to filter out the target object from multiple initial objects based on the light source information and virtual camera parameters. The specific selection depends on the actual situation, and the embodiments of this specification do not impose any restrictions on this. In one possible implementation of this specification, the light source spherical bounding box and the light source shadow polyhedron of the light source of the picture can be determined according to the light source shadow distance; the camera shadow cone in the target picture can be determined according to the virtual camera parameters; the target object can be filtered out from multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron and the camera shadow cone. In another possible implementation of this specification, the visible space of the target picture can be determined according to the light source information and virtual camera parameters; the initial object whose object position is located in the visible space of the picture is determined as the target object.
[0037] Step 106: Classify the target object to obtain the object category of the target object.
[0038] It should be noted that classifying the target object refers to the process of classifying the target object into a predefined category. Object category refers to a set of predefined labels or categories in the object classification task, which are used to describe the type of object. Each object category represents a specific type of object. Object categories can be classified according to the light source type of the picture light source, or according to the object material of the target object. Object categories include local lighting objects, directional lighting objects, natural material objects (such as stone, wood), building material objects (such as bricks, concrete), man-made material objects (such as plastic, rubber), etc.
[0039] In practical applications, there are many ways to classify the target object, which can be selected according to the actual situation, and the embodiments of this specification do not impose any restrictions on this. In one possible implementation of this specification, the target object can be input into a category recognition model to obtain the object category of the target object, wherein the category recognition model refers to a neural network model with object category recognition capability. The category recognition model can be a pre-trained large model, or it can be a deep learning model trained based on multiple sample objects and the sample object categories of each of the multiple sample objects.
[0040] In another possible implementation of the present specification, the light source information includes the light source type of the picture light source; the above-mentioned classification of the target object to obtain the object category of the target object may include the following steps: Classify the target object according to the light source type to obtain an initial object category of the target object; According to the object material of the target object, the target objects having the same initial object category are classified to obtain the object category of the target object.
[0041] It should be noted that the light source type refers to a set of predefined labels or categories in the light source classification task, which are used to describe the type of light source. Light source types include but are not limited to directional light types and local light types. Object material refers to a set of properties applied to the surface of a 3D object, which defines how the object reflects light, displays color, and interacts with other surfaces. The initial object category refers to the result of classifying the target object according to the light source type, and the object category refers to the result of reclassifying the initial object category according to the object material.
[0042] In practical applications, when classifying target objects according to the light source type, target objects with the same light source type can be classified into the same initial object category. When classifying target objects with the same initial object category according to the object material of the target objects, target objects with the same initial object category and the same object material can be classified into the same object category, thereby obtaining the object category of the target object.
[0043] Exemplarily, it is assumed that the target objects include stone 1, stone 2, plastic, and bricks. The light source type corresponding to stone 1 and stone 2 is a directional light type, and the light source type corresponding to plastic and bricks is a local light type. According to the light source type, when classifying the above four target objects, the initial object categories of stone 1 and stone 2 are determined to be directional lighting objects, and the initial object categories of plastic and bricks are local lighting types. Then, according to the object material of the target object, the object category of stone 1 and stone 2 is determined to be a directional lighting object of natural material, the object category of plastic is determined to be a local lighting object of man-made material, and the object category of brick is determined to be a local lighting object of building material.
[0044] By applying the solution of the embodiments of this specification, the target objects are first coarsely classified according to the light source type, and then finely classified using the object material and the result of the coarse classification, so that the object category of the target object is more refined and accurate.
[0045] Step 108: According to the object category, shadow rendering is performed on the target object in the target picture to obtain a shadow rendering result.
[0046] It should be noted that the shadow rendering result refers to an image or data generated by the shadow rendering method that reflects the shadow effect produced when the light source of the screen is blocked by the target object. For example, the shadow rendering result can be a target rendering screen including the target object and the shadow effect of the target object under the light source of the screen, and the shadow rendering result can also be a target rendering object including the shadow rendering effect. The selection is made according to the actual situation, and the embodiments of this specification do not impose any limitation on this.
[0047] In actual applications, according to the object category, the target object is shadow-rendered in the target screen, and there are many ways to obtain the shadow rendering result. The specific selection is based on the actual situation, and the embodiments of this specification do not impose any restrictions on this. In one possible implementation of this specification, the shadow rendering engine can be directly called to perform shadow rendering on the target object in the target screen according to the object category to obtain the shadow rendering result. In another possible implementation of this specification, a shadow rendering program corresponding to the object category can be obtained, and the target object is shadow-rendered in the target screen according to the shadow rendering program to obtain the shadow rendering result.
[0048] By applying the solution of the embodiments of the present specification, visible target objects in the target screen are screened out from multiple initial objects, thereby avoiding redundant rendering of invisible objects and multiple renderings of the same object. Through a shadow rendering request, shadow classification rendering is performed based on the object category to obtain the shadow rendering results of all target objects, thereby achieving precise shadow rendering and further improving the shadow rendering efficiency.
[0049] In one or more embodiments of the present specification, performing shadow rendering on the target object in the target picture according to the object category to obtain the shadow rendering result may include the following steps: Get the shadow rendering parameters corresponding to the object category; According to the shadow rendering parameters, parallel shadow rendering is performed on target objects of the same object category to obtain shadow rendering results.
[0050] It should be noted that the shadow rendering parameters of the target object refer to values related to the image light source, object material, object quantity, environmental factors, and rendering settings. The shadow rendering parameters are used to determine the appearance of the shadow.
[0051] In actual applications, there are many ways to obtain shadow rendering parameters corresponding to object categories, which are selected according to actual conditions, and the embodiments of this specification do not limit this. In one possible implementation of this specification, the shadow rendering parameters corresponding to the object category can be read from a database. In another possible implementation of this specification, the shadow rendering parameters corresponding to the object category sent by the user can be received.
[0052] Furthermore, after obtaining the shadow rendering parameters corresponding to the object category, the target objects can be rendered one by one using the shadow rendering parameters. Since the shadow rendering parameters correspond to the object category, the target objects of the same object category have the same shadow rendering parameters, and the target objects of the same object category can be shadow rendered in parallel according to the shadow rendering parameters to obtain the shadow rendering results.
[0053] By applying the solution of the embodiments of this specification, the shadow rendering efficiency is improved by performing parallel shadow rendering on target objects of the same object category according to the shadow rendering parameters corresponding to the object category.
[0054] In an optional embodiment of the present specification, the light source information includes the light source shadow distance and the light source type of the picture light source; the above-mentioned screening out the target object from the multiple initial objects according to the light source information and the virtual camera parameters may include the following steps: According to the light source shadow distance, determine the light source spherical bounding box and light source shadow polyhedron of the light source in the picture; According to the virtual camera parameters, determine the camera shadow frustum in the target image; A target object is screened out from multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum.
[0055] It should be noted that the light source shadow distance refers to the maximum distance at which the screen light source can produce effective shadows. The light source shadow distance determines the range of shadows cast by the screen light source in the scene, affecting the shadow effect and rendering performance in the scene. Beyond the light source shadow distance, the shadow will no longer be calculated or displayed. In computer graphics, in order to optimize the rendering process and improve performance, the light source spherical bounding box (Bounding Sphere) and light source shadow polyhedron (Shadow Frustum) can be used to describe the influence range of the light source, which helps to determine which objects will be affected by the light source, and only render necessary target objects during the rendering process to avoid rendering unnecessary objects.
[0056] The light source spherical bounding box is a sphere that is used to approximate the effective influence range of the light source. The light source spherical bounding box is determined based on the position of the light source in the picture and the distance of the light source shadow. The light source spherical bounding box can be used to quickly exclude objects that are not within the influence range of the light source in the picture. If an object (or its bounding box) is completely outside the light source spherical bounding box, then the object will not be affected by the light source and no shadow calculation is required for it, thereby improving rendering efficiency.
[0057] The light source shadow polyhedron is used to describe the effective range of the shadow cast by the light source in the picture. Through the light source shadow polyhedron, you can determine the objects within the shadow projection range of the light source. Only objects within the light source shadow polyhedron will be shadowed. Compared with the light source spherical bounding box, the light source shadow polyhedron can more accurately describe the influence range of the light source in the picture.
[0058] The Camera Frustum is a 3D geometry that defines the area that the camera can see in 3D space. This area is usually a frustum, and its shape depends on the camera's projection mode (orthogonal or perspective).
[0059] In practical applications, when determining the light source spherical bounding box and light source shadow polyhedron of the screen light source according to the light source shadow distance, if the screen light source is a directional light, each level of the directional light cascade can be determined, thereby generating a light source spherical bounding box and light source shadow polyhedron for each level of the cascade. For the light source spherical bounding box, a light source spherical bounding box can be created with the light source position as the center and the light source shadow distance of the screen light source as the radius. For the light source shadow polyhedron, the light source shadow cone can be determined based on the light source shadow example, and the light source shadow cone and the camera shadow cone are intersected, and the overlapping part is the light source shadow polyhedron.
[0060] By applying the solution of the embodiments of this specification, by calculating the spherical bounding box of the light source, the light source shadow polyhedron and the camera shadow cone, and further combining the screening strategy corresponding to the light source type, the target object is screened out from multiple initial objects, and different screening strategies are adopted for different picture light sources, so that the screening process is more matched with the target picture, and the accuracy of the target object is improved.
[0061] In one or more embodiments of the present specification, the virtual camera parameters include the camera position and camera shadow distance of the virtual camera; the above-mentioned determination of the camera shadow frustum in the target picture according to the virtual camera parameters may include the following steps: Calculate the camera shadow frustum in the target image based on the camera position and the camera shadow distance.
[0062] It should be noted that the virtual camera is an abstract tool used to simulate the behavior of a real camera. It helps the rendering engine determine the viewing angle and projection method of objects in the scene. The camera position refers to the exact coordinates of the virtual camera in 3D space. The camera position determines the camera's viewing angle, that is, the direction the camera "looks". In a three-dimensional coordinate system, the camera position can be represented by a three-dimensional vector C=(x,y,z). The camera shadow distance can be understood as the camera's field of view, which refers to the range of the scene that the camera can capture.
[0063] In practical applications, when calculating the camera shadow frustum in the target image according to the camera position and the camera shadow distance, the boundary corner points of the camera shadow frustum can be calculated according to the camera shadow distance and the camera position, and the calculated boundary corner points are used to determine the six planes of the camera shadow frustum, where the six planes include two side planes, a top plane, a bottom plane, a near clipping plane, and a far clipping plane parallel to the near clipping plane but located at the shadow distance. Finally, the camera shadow frustum can be constructed through these six planes.
[0064] By applying the solution of the embodiment of this specification, the camera shadow frustum in the target image is calculated according to the camera position and the camera shadow distance, thereby improving the accuracy of the camera shadow frustum.
[0065] In an optional embodiment of the present specification, taking the light source type including the directional light type as an example, the above-mentioned screening out the target object from multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron and the camera shadow cone may include the following steps: When the light source type is a directional light type, obtaining object positions of a plurality of initial objects respectively; According to the light source space of the picture light source, the object position is spatially transformed to obtain the target object position; A target object is selected from multiple initial objects according to the target object position, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum.
[0066] It should be noted that directional light can be called parallel light or sun light, which is a type of light source used in computer graphics and real-world lighting models. Directional light emits light from an infinite distance, and all light rays are parallel to each other. Directional light simulates a distant light source such as the sun, whose light rays are almost parallel when they reach the surface of the earth. The object position of the initial object refers to the position of the initial object in the world coordinate system in the three-dimensional scene, that is, the position information of the initial object before any spatial transformation. The light source space of the screen light source refers to the coordinate space under the light source reference system. For directional light, the light source space usually refers to the viewpoint coordinate system (Light-Space) of the light source, in which all light rays emitted from the light source are parallel, and the position of the light source is assumed to be infinite. The target object position refers to the position of the initial object in the light source space after the spatial position transformation. For example, when the initial object is transformed from the world coordinate system to the light source space, the object position of the initial object is transformed to a new coordinate system. This new position is the target object position.
[0067] In actual applications, there are multiple ways to obtain the object position of each initial object, which can be selected according to the actual situation. The embodiments of this specification do not limit this. In one possible implementation of this specification, the object positions of multiple initial objects can be obtained through an application engine. In another possible implementation of this specification, the object list of multiple initial objects can be traversed to obtain the object position stored in the object list.
[0068] Furthermore, for a directional light type screen light source, the light source position can be assumed to be infinite, so the camera position and the light source direction can be used to construct a view matrix, where the view matrix is used to transform points in the world coordinate system into the light source reference system. Next, the orthogonal projection matrix can be used as the projection matrix, and the view matrix and the projection matrix can be merged to form a light source space transformation matrix. Finally, the light source space transformation matrix is used to transform the object position of each initial object from the world coordinate system to the light source space to obtain the target object position.
[0069] By applying the solution of the embodiments of this specification, the target coordinate system is obtained by converting the object position of the initial object from the world coordinate system to the light source space, so that the target object can be accurately screened out from multiple initial objects based on the target object position, the light source spherical bounding box, the light source shadow polyhedron and the camera shadow cone, thereby improving the accuracy of object screening.
[0070] In an optional embodiment of the present specification, the above-mentioned screening out the target object from multiple initial objects according to the position of the target object, the light source spherical bounding box, the light source shadow polyhedron and the camera shadow frustum may include the following steps: Determine the shadow boundary of the light source space based on the camera shadow frustum; According to the position of the target object, a candidate object is screened out from multiple initial objects, wherein the candidate object is located within the range of the spherical bounding box of the light source; According to the shadow boundary and the light source shadow polyhedron, a target object is screened out from the candidate objects, wherein the target object is located within the range of the shadow boundary and the light source shadow polyhedron.
[0071] It should be noted that the shadow boundary refers to the boundary of the area in the light source space where the light source of the picture can cast a shadow. The shadow boundary limits which objects need to participate in the shadow calculation. When determining the shadow boundary of the light source space based on the camera shadow frustum, the camera shadow frustum can be intersected with the light source space, and the shadow boundary of the light source space can be determined based on the intersection result.
[0072] In practical applications, after determining the shadow boundary of the light source space according to the camera shadow frustum, the spherical bounding box can be used to eliminate the initial objects whose target object positions are outside the horizontal (x-axis) and vertical (y-axis) directions to obtain candidate objects. Then, the spherical bounding box is used to eliminate the candidate objects whose vertical (z-axis) range is outside the shadow boundary, and the light source shadow polyhedron is used to accurately crop the candidate objects. During cropping, as long as the candidate object is outside a certain surface, it will be eliminated and the target object can be obtained.
[0073] By applying the solution of the embodiments of this specification, the initial objects whose target object positions are outside the horizontal and vertical axis directions and the objects outside the vertical axis range of the directional light sphere are eliminated, and then the light source shadow polyhedron is used to accurately crop the objects, so that the target object can be accurately obtained.
[0074] See also Figure 2 , Figure 2 A flowchart of a shadow rendering method based on directional light provided by an embodiment of the specification is shown, which specifically includes: converting the object bounding boxes of multiple initial objects to the light source space, and performing elimination judgment on the multiple initial objects in the light source space: judging whether the horizontal and vertical axis directions of the initial object are visible in the light source spherical bounding box, if not, eliminating the initial object; if visible, calculating the shadow boundary of the object bounding box in the light source space. Then, judging whether the vertical axis direction of the eliminated initial object is visible in the light source spherical bounding box, if not, eliminating the initial object; if visible, judging whether the eliminated initial object is visible within the shadow boundary, if not, eliminating the initial object; if visible, determining whether the eliminated initial object is visible within the shadow boundary, if not, eliminating the initial object; if visible, determining the final eliminated initial object as the target object.
[0075] In an optional embodiment of the present specification, taking the light source type including the local light type as an example, the above-mentioned screening out the target object from multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron and the camera shadow cone may include the following steps: In the case where the light source type is a local light type, a candidate object is screened out from a plurality of initial objects according to a spherical bounding box of the light source, wherein the candidate object is located in the spherical bounding box of the light source; Cross-merge the light source shadow polyhedron and the camera shadow frustum to obtain the target shadow frustum; According to the target shadow frustum, a target object is screened out from the candidate objects, wherein the target object is within the range of the target shadow frustum.
[0076] It should be noted that local light refers to a type of light source whose range of action is within a certain area around it. Unlike directional light, the effect of local light is limited, and only produces lighting effects on a group of objects nearby.
[0077] In practical applications, when selecting candidate objects from multiple initial objects based on the light source spherical bounding box, the initial objects whose object positions are outside the light source spherical bounding box are first clipped to obtain candidate objects. Then, the light source shadow polyhedron and the camera shadow cone are cross-merged to obtain a more accurate target shadow cone, and finally, the candidate objects whose object positions are outside the target shadow cone are clipped to obtain the target object.
[0078] By applying the solution of the embodiments of this specification, the initial object is first quickly spherically clipped through the light source request bounding box, so that the initial object that is impossible to produce a shadow can be quickly eliminated, and the light source shadow polyhedron and the camera shadow cone are further intersected to obtain a more accurate target shadow cone, so that irrelevant initial objects can be eliminated, thereby improving the accuracy of the target object.
[0079] See also Figure 3 , Figure 3 A flowchart of a shadow rendering method based on local light provided by an embodiment of the present specification is shown, which specifically includes: obtaining object bounding boxes of multiple initial objects, judging whether the initial objects are visible in the light source spherical bounding box, and if not, eliminating the initial objects; if visible, cross-merging the light source shadow polyhedron and the camera shadow cone to obtain a target shadow cone; then, judging whether the eliminated initial objects are visible in the target shadow cone, and if not, eliminating the initial objects; if visible, determining the initial objects finally eliminated as the target objects.
[0080] See also Figure 4 , Figure 4 The flowchart of a shadow rendering method provided by an embodiment of the present specification is shown. The shadow rendering process can render multiple initial objects in parallel, that is, traverse all initial objects in parallel and traverse all shadow rendering requests. When processing each shadow rendering request, determine the light source type of the screen light source. When the light source type is a directional light type, execute the following steps: Figure 2 The directional light shadow rendering method shown in FIG. 1 selects a visible target object from multiple initial objects; when the light source type is a local light type, the following is performed: Figure 3 The local light shadow rendering method shown in the figure selects visible target objects from multiple initial objects. After selecting the target objects, the target objects can be classified. When classifying, they can be classified by light source type first, and then classified by object material to obtain the object category of the target object; finally, according to the object category, the target object is shadow rendered in the target screen to obtain the shadow rendering result.
[0081] See also Figure 5 , Figure 5An architecture diagram of a shadow rendering system provided by an embodiment of the present specification is shown, and the shadow rendering system includes a GPU and a CPU; The CPU is used to determine the camera shadow cone according to the virtual camera parameters; determine the light source spherical bounding box and light source shadow polyhedron of the screen light source according to the light source shadow distance; pass the camera shadow cone, light source spherical bounding box and light source shadow polyhedron to the GPU; initiate all shadow requests for the GPU to uniformly screen the target objects; initiate GPU screening result classification; request the GPU to perform shadow rendering according to the shadow rendering request and object material; The GPU is used to screen all initial objects in parallel based on the light source type; perform object shadow clipping; perform target object classification; and perform shadow rendering.
[0082] The scheme of the embodiments of the present specification is applied to screen out the light source spherical bounding boxes and light source shadow polyhedrons of all lights that need to be projected, and then these parameters are passed into the GPU for object screening and classification, and then classified rendering is performed for each shadow atlas and shadow request, so that each target object that needs to render a shadow is accurately screened, and there is no problem of multiple object drawing and useless drawing; and each shadow rendering request only needs to be processed once to get all the results, first the object bounding box is quickly clipped by the light source spherical bounding box, and then the light source shadow polyhedron and the camera shadow cone are merged to obtain the target shadow cone for fast clipping, which greatly improves the clipping efficiency; even if the picture light source outside the lens casts a shadow into the lens, the correct shadow rendering and clipping effect can be obtained.
[0083] Corresponding to the above method embodiment, this specification also provides a shadow rendering device embodiment. Figure 6 FIG. 2 shows a schematic diagram of a shadow rendering device provided by an embodiment of the present specification. Figure 6 As shown, the device comprises: An acquisition module 602 is configured to acquire a shadow rendering request of a target picture, wherein the shadow rendering request carries a plurality of initial objects, light source information of the target picture, and virtual camera parameters; A screening module 604 is configured to screen a target object from a plurality of initial objects according to the light source information and the virtual camera parameters, wherein the target object is a visible object in the target picture; The classification module 606 is configured to classify the target object and obtain an object category of the target object; The rendering module 608 is configured to perform shadow rendering on the target object in the target picture according to the object category to obtain a shadow rendering result.
[0084] Optionally, the light source information includes the light source shadow distance and light source type of the light source in the picture; the screening module 604 is further configured to determine the light source spherical bounding box and the light source shadow polyhedron of the light source in the picture according to the light source shadow distance; determine the camera shadow cone in the target picture according to the virtual camera parameters; and screen out the target object from multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron and the camera shadow cone.
[0085] Optionally, the light source type includes a directional light type; the screening module 604 is further configured to respectively obtain the object positions of multiple initial objects when the light source type is a directional light type; perform spatial transformation on the object position according to the light source space of the picture light source to obtain the target object position; and screen out the target object from the multiple initial objects according to the target object position, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow cone.
[0086] Optionally, the screening module 604 is further configured to determine the shadow boundary of the light source space based on the camera shadow cone; screen out candidate objects from multiple initial objects based on the target object position, wherein the candidate objects are located within the range of the light source spherical bounding box; and screen out the target object from the candidate objects based on the shadow boundary and the light source shadow polyhedron, wherein the target object is located within the range of the shadow boundary and the light source shadow polyhedron.
[0087] Optionally, the light source type includes a local light type; the screening module 604 is further configured to, when the light source type is a local light type, screen out candidate objects from multiple initial objects based on the light source spherical bounding box, wherein the candidate objects are located in the light source spherical bounding box; cross-merge the light source shadow polyhedron and the camera shadow cone to obtain a target shadow cone; and screen out a target object from the candidate objects based on the target shadow cone, wherein the target object is located within the range of the target shadow cone.
[0088] Optionally, the virtual camera parameters include the camera position and camera shadow distance of the virtual camera; the screening module 604 is further configured to calculate the camera shadow frustum in the target image according to the camera position and the camera shadow distance.
[0089] Optionally, the light source information includes the light source type of the picture light source; the classification module 606 is further configured to classify the target object according to the light source type to obtain an initial object category of the target object; and classify the target objects with the same initial object category according to the object material of the target object to obtain the object category of the target object.
[0090] Optionally, the rendering module 608 is configured to obtain shadow rendering parameters corresponding to the object category; and perform parallel shadow rendering on target objects of the same object category according to the shadow rendering parameters to obtain shadow rendering results.
[0091] By applying the scheme of the embodiments of this specification, the shadow rendering device screens out visible target objects in the target picture from multiple initial objects, thereby avoiding redundant rendering of invisible objects and multiple renderings of the same object. Through a shadow rendering request, shadow classification rendering is performed based on the object category to obtain the shadow rendering results of all target objects, thereby achieving precise shadow rendering and further improving the shadow rendering efficiency.
[0092] The above is a schematic scheme of a shadow rendering device of this embodiment. It should be noted that the technical scheme of the shadow rendering device and the technical scheme of the shadow rendering method described above are of the same concept, and the details not described in detail in the technical scheme of the shadow rendering device can be referred to the description of the technical scheme of the shadow rendering method described above.
[0093] Figure 7 The block diagram of a computing device provided by an embodiment of the present specification is shown. The components of the computing device 700 include but are not limited to a memory 710 and a processor 720. The processor 720 is connected to the memory 710 via a bus 730, and the database 750 is used to store data.
[0094] The computing device 700 also includes an access device 740 that enables the computing device 700 to communicate via one or more networks 760. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 740 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world microwave interconnection access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0095] In one embodiment of the present specification, the above components of the computing device 700 and Figure 7 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 7 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0096] The computing device 700 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 700 may also be a mobile or stationary server.
[0097] The processor 720 is used to execute a computer program / instruction, and the computer program / instruction, when executed by the processor, implements the steps of the above-mentioned shadow rendering method.
[0098] The above is a schematic solution of a computing device of this embodiment. It should be noted that the technical solution of the computing device and the technical solution of the above shadow rendering method belong to the same concept, and the details not described in detail in the technical solution of the computing device can be referred to the description of the technical solution of the above shadow rendering method.
[0099] An embodiment of the present specification further provides a computer-readable storage medium storing a computer program / instruction, which implements the steps of the above-mentioned shadow rendering method when executed by a processor.
[0100] The above is a schematic solution of a computer-readable storage medium of this embodiment. It should be noted that the technical solution of the storage medium and the technical solution of the above shadow rendering method belong to the same concept, and the details not described in detail in the technical solution of the storage medium can be referred to the description of the technical solution of the above shadow rendering method.
[0101] An embodiment of the present specification also provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned shadow rendering method when executed by a processor.
[0102] The above is a schematic solution of a computer program product of this embodiment. It should be noted that the technical solution of the computer program product and the technical solution of the above shadow rendering method belong to the same concept, and the details not described in detail in the technical solution of the computer program product can be referred to the description of the technical solution of the above shadow rendering method.
[0103] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0104] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0105] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0106] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0107] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is only limited by the claims and their full scope and equivalents.
Claims
1. A shadow rendering method, characterized in that: include: Obtaining a shadow rendering request of a target picture, wherein the shadow rendering request carries a plurality of initial objects, light source information of the target picture, and virtual camera parameters; Filtering a target object from the multiple initial objects according to the light source information and the virtual camera parameters, wherein the target object is a visible object in the target picture; Classifying the target object to obtain an object category of the target object; According to the object category, shadow rendering is performed on the target object in the target picture to obtain a shadow rendering result.
2. The method according to claim 1, characterized in that: The light source information includes the light source shadow distance and light source type of the picture light source; The step of selecting a target object from the plurality of initial objects according to the light source information and the virtual camera parameters includes: Determining a light source spherical bounding box and a light source shadow polyhedron of the picture light source according to the light source shadow distance; Determining a camera shadow frustum in the target image according to the virtual camera parameters; A target object is screened out from the multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum.
3. The method according to claim 2, characterized in that The light source type includes a directional light type; The step of selecting a target object from the multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum includes: When the light source type is the directional light type, respectively acquiring the object positions of the multiple initial objects; According to the light source space of the picture light source, spatially transform the object position to obtain the target object position; A target object is screened out from the multiple initial objects according to the target object position, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum.
4. The method according to claim 3, characterized in that Filtering out a target object from the multiple initial objects according to the position of the target object, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum includes: Determining a shadow boundary of the light source space according to the camera shadow frustum; According to the position of the target object, a candidate object is screened out from the multiple initial objects, wherein the candidate object is located within the range of the light source spherical bounding box; A target object is screened out from the candidate objects according to the shadow boundary and the light source shadow polyhedron, wherein the target object is located within the range of the shadow boundary and the light source shadow polyhedron.
5. The method according to claim 2, characterized in that: The light source type includes a local light type; The step of selecting a target object from the multiple initial objects according to the light source type, the light source spherical bounding box, the light source shadow polyhedron, and the camera shadow frustum includes: In the case where the light source type is the local light type, screening out candidate objects from the multiple initial objects according to the light source spherical bounding box, wherein the candidate objects are located in the light source spherical bounding box; Cross-merge the light source shadow polyhedron and the camera shadow frustum to obtain a target shadow frustum; A target object is screened out from the candidate objects according to the target shadow frustum, wherein the target object is located within the range of the target shadow frustum.
6. The method according to claim 2, characterized in that The virtual camera parameters include the camera position and camera shadow distance of the virtual camera; The step of determining the camera shadow frustum in the target image according to the virtual camera parameters includes: A camera shadow frustum in the target image is calculated according to the camera position and the camera shadow distance.
7. The method according to claim 1, characterized in that The light source information includes the light source type of the picture light source; The step of classifying the target object to obtain the object category of the target object includes: Classifying the target object according to the light source type to obtain an initial object category of the target object; The target objects having the same category as the initial object are classified according to the object material of the target object to obtain the object category of the target object.
8. The method according to claim 1, characterized in that The step of performing shadow rendering on the target object in the target picture according to the object category to obtain a shadow rendering result includes: Obtaining shadow rendering parameters corresponding to the object category; According to the shadow rendering parameters, parallel shadow rendering is performed on the target objects of the same object category to obtain a shadow rendering result.
9. A shadow rendering device, characterized in that: include: An acquisition module is configured to acquire a shadow rendering request of a target picture, wherein the shadow rendering request carries a plurality of initial objects, light source information of the target picture, and virtual camera parameters; A screening module is configured to screen out a target object from the multiple initial objects according to the light source information and the virtual camera parameters, wherein the target object is a visible object in the target picture; A classification module is configured to classify the target object to obtain an object category of the target object; The rendering module is configured to perform shadow rendering on the target object in the target picture according to the object category to obtain a shadow rendering result.
10. A computing device, characterized in that include: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer program / instructions are executed by the processor, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that: It stores a computer program / instruction, which implements the steps of the method described in any one of claims 1 to 8 when executed by a processor.
12. A computer program product, characterized in that The method comprises a computer program / instruction which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 8.
Citation Information
Cited By
Navigation interface rendering method, mobile device and storage medium
CN120994285A
