Shielding elimination method and device, equipment and storage medium
By combining the calculation shader and the rasterization pipeline, occlusion removal test and rasterization processing are carried out, the problem of high calculation consumption in the existing technology is solved, the efficiency and accuracy of occlusion removal are improved, and the efficiency of graphic drawing is improved.
Patent Information
- Application Number
- CN202411193468.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-31
AI Technical Summary
In the prior art, calculation consumption is high during the occlusion removal process, resulting in low efficiency.
By calling the calculation shader, the depth map of the virtual scene is tested, and the rasterization pipeline is used to rasterize the bounding box, update the culling results, reduce multi-level hierarchical map generation, and make full use of the hardware units and software of the graphics processor. The rasterization processing capability of the unit.
Improve the efficiency of occlusion and removal, ensure the accuracy of the results, reduce unnecessary graphic drawing, and improve graphic drawing efficiency.
Smart Images

Figure CN119228948A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of rendering technology, and in particular to an occlusion culling method, device, equipment and storage medium. Background Art
[0002] In the field of computer graphics, such as games, virtual reality (VR) and augmented reality (AR), before drawing, it is necessary to perform occlusion culling on virtual objects in the virtual scene to remove the occluded virtual objects. In the subsequent drawing process, the occluded virtual objects do not need to be drawn.
[0003] In the related art, the occluded virtual object is determined by performing two occlusion culling tests through a computing shader. However, in this method, a multi-level layer map of the depth map needs to be drawn twice, which consumes a lot of calculation. Summary of the invention
[0004] The present application provides an occlusion culling method, device, equipment and storage medium to solve the technical problem of high computational consumption in the occlusion culling process in the related art.
[0005] The technical solution of this application is implemented as follows:
[0006] The present application provides an occlusion culling method, comprising: calling a compute shader to perform a culling test on virtual objects in the virtual scene at time point t+1 according to a depth map of the virtual scene at time point t, and obtaining a first culling result, wherein the first culling result indicates a first virtual object determined to be occluded and a second virtual object determined to be visible in the culling test; t is a positive integer; performing depth drawing on the second virtual object to obtain an initial depth map of the virtual scene at time point t+1; calling a rasterization pipeline to perform rasterization processing on the bounding box according to bounding box information of the bounding box of each virtual object and the initial depth map, and obtaining a rasterization result of the bounding box, wherein the rasterization result indicates a visibility result of the bounding box; updating the first culling result according to the visibility result, and obtaining a second culling result of the virtual scene at time point t+1, wherein in the second culling result, the visibility result indicates that the first virtual object enclosed by the visible bounding box is determined to be visible, and the visibility result indicates that the second virtual object enclosed by the invisible bounding box is determined to be occluded.
[0007] The present application provides an occlusion culling device, including: a culling test module, a first depth map drawing module, a rasterization processing module and a culling result update module. The culling test module is used to call a compute shader to perform a culling test on a virtual object in the virtual scene at time point t+1 according to the depth map of the virtual scene at time point t, and obtain a first culling result, wherein the first culling result indicates the first virtual object determined to be occluded and the second virtual object determined to be visible in the culling test; t is a positive integer; the first depth map drawing module is used to perform depth drawing on the second virtual object to obtain the initial depth map of the virtual scene at time point t+1; the rasterization processing module is used to call the rasterization pipeline to update the depth map of each virtual object according to the package size of each virtual object; The module comprises a culling result updating module, which is used to update the first culling result according to the visibility result, and obtain a second culling result of the virtual scene at time point t+1, wherein in the second culling result, the first virtual object enclosed by the visible bounding box indicated by the visibility result is determined to be visible, and the second virtual object enclosed by the invisible bounding box indicated by the visibility result is determined to be occluded.
[0008] In one possible implementation, the rasterization processing module includes a geometry processing submodule, a rasterization submodule, and a visibility determination submodule. The geometry processing submodule is used to perform geometry processing on the vertices of the bounding box according to the bounding box information of each virtual object, and obtain the texture coordinates of the vertices of the bounding box and the depth values corresponding to the vertices on the bounding box; the rasterization submodule is used to perform rasterization according to the texture coordinates of the vertices of the bounding box and the corresponding depth values, and determine the multiple fragments corresponding to the bounding box; the fragments include pixel coordinates and fragment depth values; the visibility determination submodule is used to determine the visibility result of the bounding box according to the depth values of the pixels corresponding to the pixel coordinates in the multiple fragments corresponding to the bounding box in the initial depth map and the fragment depth values in the fragments.
[0009] In one possible implementation, the bounding box is a directional bounding box.
[0010] In one possible implementation, the visibility determination submodule is further used to determine, among the multiple fragments corresponding to the bounding box, the first fragment whose pixel coordinates have a depth value that is not less than the corresponding fragment depth value in the initial depth map; if the number of the first fragments exceeds a quantity threshold, determine that the visibility result of the bounding box indicates that the bounding box is visible; and if the number of the first fragments does not exceed the quantity threshold, determine that the visibility result of the bounding box indicates that the bounding box is invisible.
[0011] In one possible implementation, a pixel shader is deployed on a rasterization pipeline; in the rasterization process, the write switch of the initial depth map is in a closed state; the device also includes: a shading module, which is used to use the pixel shader to perform pixel shading on the pixels corresponding to the first fragment in the initial depth map.
[0012] In one possible implementation, the occlusion culling device also includes a first writing module, which is used to write a visibility mark in a storage position corresponding to each virtual object in the first buffer based on the first culling result, and the visibility mark includes a first mark indicating visible and a second mark indicating occluded; the culling result updating module is also used to modify the visibility mark of the first virtual object in the first buffer to the first mark when there is a visibility result of a bounding box indicating a visible first virtual object; and to modify the visibility mark of the second virtual object in the first buffer to the second mark when there is a visibility result of a bounding box indicating an occluded second virtual object; wherein the visibility mark stored in the first buffer after modification serves as the second culling result of the virtual scene at time point t+1.
[0013] In one possible implementation, a vertex shader and a pixel shader are deployed in the rasterization pipeline; the occlusion culling device also includes a second writing module, which is used to write object data of the virtual object into the vertex shader; the object data includes bounding box information of the bounding box of the virtual object and the object identifier of the virtual object; the culling result update module is also used to obtain the object identifier of the first virtual object from the vertex shader by the pixel shader when the pixel shader performs pixel shading on the first fragment in the first virtual object in the initial depth map, and based on the object identifier of the first virtual object, modify the visibility mark of the first virtual object in the first buffer to the first mark.
[0014] In one possible implementation, the occlusion culling device also includes a first parameter assembly module and a second depth map drawing module, the first parameter assembly module being used to perform indirect drawing parameter assembly for a first target virtual object based on the second culling result, the first target virtual object being the first virtual object surrounded by a bounding box that is visible as indicated by a visibility result; the second depth map drawing module being used to perform depth drawing for the first target virtual object in the initial depth map based on the indirect drawing parameters of the first target virtual object, to obtain a depth map of the virtual scene at time point t+1.
[0015] In one possible implementation, the occlusion culling device also includes a second parameter assembly module and a scene graph drawing module; the second parameter assembly module is used to perform indirect drawing parameter assembly for the virtual objects indicated as visible in the second culling result to obtain scene indirect drawing parameters; the scene graph drawing module is used to perform scene drawing according to the scene indirect drawing parameters to obtain a scene image of the virtual scene at time point t+1.
[0016] In one possible implementation, the first elimination result also includes an indirect drawing parameter of the second virtual object; the first depth map drawing module is further used to perform depth drawing according to the indirect drawing parameter of the second virtual object to obtain an initial depth map of the virtual scene at time point t+1.
[0017] In one possible implementation, the culling test module is further used to sample the depth map of the virtual scene at time point t step by step to obtain a hierarchical map of the depth map of the virtual scene at time point t at multiple levels; project the vertices of the bounding boxes of each virtual object in the virtual scene at time point t+1 to the screen space to obtain the size of the pixels covered by the bounding box in the screen space; determine, in the hierarchical map at the multiple levels, a target hierarchical map having the smallest size difference between the size of a unit pixel and the size of the pixels covered by the bounding box in the screen space; determine the target pixels corresponding to the vertices of the bounding box in the target hierarchical map; and determine the first culling test result based on the depth values of the vertices of the bounding box and the depth values of the target pixels corresponding to the vertices of the bounding box in the target hierarchical map.
[0018] The present application provides an electronic device, including one or more processors, a memory, and one or more programs; the one or more programs are stored in the memory and configured to be executed by the processor to implement the above method.
[0019] The present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the above method is executed when the computer program is executed by a processor.
[0020] The present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. A processor of an electronic device obtains the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device executes the above method.
[0021] This application has the following beneficial effects:
[0022] The present application provides an occlusion culling method, device, equipment and storage medium. First, based on the depth map of the virtual scene at time point t, a culling test is performed on the virtual objects in the virtual scene at time point t+1 to obtain a first culling result, and depth drawing is performed based on the first virtual object indicated as visible in the first culling result to obtain the initial depth map of the virtual scene at time point t+1, and a rasterization pipeline is called to rasterize the bounding box according to the bounding box information of each virtual object and the initial depth map to obtain the rasterization result of the bounding box, and the first culling result is updated according to the rasterization result of the bounding box to obtain the second culling result of the virtual scene at time point t+1. The method realizes two occlusion cullings using a compute shader and a rasterization pipeline to ensure the accuracy of the obtained second culling result. Moreover, since the rasterization pipeline is called to rasterize the bounding box, the rasterization processing capabilities of the hardware units and software units in the graphics processor used to implement rasterization processing can be fully utilized. In this way, there is no need to generate layer maps at multiple levels twice. Moreover, relatively speaking, the shader in the rasterization pipeline is more efficient than the computing shader. Therefore, using the rasterization pipeline for secondary occlusion culling can improve the overall efficiency of occlusion culling.
[0023] In addition, in the related art, in order to improve the efficiency of occlusion culling by the compute shader, the compute shader usually transforms the axis-aligned bounding box of the virtual object to the screen space to determine the visibility result of the bounding box. However, in the actual process, the axis-aligned bounding box occupies a larger space, and there are more gaps between the axis-aligned bounding box of the virtual object and the virtual object, which will cause the accuracy of the occlusion culling result obtained by the compute shader to be low. In the present application, the processing performance of the rasterization pipeline for different types of bounding boxes is equivalent. The bounding box for rasterization processing can be the directional bounding box of the virtual object, and the directional bounding box can more accurately express the space occupied by the virtual object; therefore, the visibility result of the directional bounding box obtained by calling the rasterization pipeline is more accurate, which can ensure that the second culling result of the virtual scene at the time point t+1 is more accurate. Furthermore, it can also solve the problem of large amount of subsequent graphics drawing caused by determining the occluded virtual object as visible, reduce unnecessary subsequent graphics drawing, and thus improve the efficiency of graphics drawing. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 It is a schematic diagram of the structure of an electronic device suitable for executing the method of the present application;
[0026] Figure 2 It is a flowchart of the occlusion culling method provided in an embodiment of the present application;
[0027] Figure 3 yes Figure 2 A schematic diagram of the process of step S110 in one embodiment;
[0028] Figure 4 yes Figure 2 A schematic diagram of the process of step S130 in one embodiment;
[0029] Figure 5 is a schematic diagram of an initial depth image at time point t+1 provided in an embodiment of the present application;
[0030] Figure 6 is a schematic diagram of an image composed of multiple fragments obtained by rasterizing a bounding box provided by an embodiment of the present application;
[0031] Figure 7 yes Figure 6 The visibility judgment result of each fragment among the multiple fragments shown;
[0032] Figure 8 is a flowchart of an occlusion culling method provided by another embodiment of the present application;
[0033] Fig. 9 is a schematic diagram of a first buffer zone provided in an embodiment of the present application;
[0034] Fig.10 is a schematic diagram of obtaining a modified first buffer zone provided in an embodiment of the present application;
[0035] Fig.11 is a flowchart of an occlusion culling method provided by another embodiment of the present application;
[0036] Fig.12 is a schematic diagram of a second buffer zone and a third buffer zone provided in an embodiment of the present application;
[0037] Fig.13 is a schematic diagram of obtaining a modified second buffer zone and a modified third buffer zone provided in an embodiment of the present application;
[0038] Fig.14 It is a flowchart of a drawing process of an initial depth map provided in an embodiment of the present application;
[0039] Fig.15 is a flowchart of an occlusion culling method provided by another embodiment of the present application;
[0040] Fig.16 is a flowchart of a process for drawing a depth map based on the parameters in the modified third buffer provided by an embodiment of the present application;
[0041] Fig.17 is a flowchart of an occlusion culling method provided by another embodiment of the present application;
[0042] Fig.18 It is a flowchart of performing scene drawing based on the parameters in the modified second buffer and the modified third buffer provided by an embodiment of the present application;
[0043] Fig.19 It is a flowchart of drawing a depth map and a scene graph at time point t+1 provided by an embodiment of the present application;
[0044] Fig. 20 is a scene diagram of a game scene provided in an embodiment of the present application;
[0045] Fig.21 is a schematic diagram of a rasterized image obtained by rasterizing a virtual object and a bounding box of the virtual object respectively, provided in an embodiment of the present application;
[0046] Fig. 22 It is a schematic diagram of a culling mark of a game scene provided in an embodiment of the present application. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0048] In the following description, reference is made to "some embodiments", which describes a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. In the following description, reference is made to the term "multiple" to mean at least two.
[0049] In the following description, the terms "first\second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0051] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0052] The following explains the terms used in this application.
[0053] The depth map layer map, also known as the depth map mip map or the depth map multi-level gradual distance map (mipmap), is a map of different resolutions obtained by sampling based on the depth map. In other words, the depth map layer map is usually a plurality of maps of different resolutions, which is a version of the depth map with a gradually reduced resolution. Since a layer map of the depth map corresponds to one level, the resolutions of layer maps at different levels are different.
[0054] The bounding box of a virtual object: refers to a simple geometric body that completely encloses the virtual object. The shape of the bounding box is not limited, for example, it can be a cuboid, a sphere, etc. The bounding box of a virtual object can be used to approximately replace the virtual object. For example, the position of the virtual object's bounding box in the virtual scene can be used to replace the position of the virtual object in the virtual scene. The bounding box of a virtual object can be an axis-aligned bounding box, a directional bounding box, or a bounding sphere, etc., where the axis-aligned bounding box of a virtual object refers to the smallest hexahedron that encloses the virtual object and whose sides are parallel to the coordinate axes; the directional bounding box of a virtual object refers to the smallest cuboid that encloses the virtual object, and the direction of the cuboid is any direction; the bounding sphere of a virtual object refers to the smallest sphere that encloses the virtual object.
[0055] A virtual scene refers to a digital, interactive three-dimensional environment created using computer technology and software systems. This environment can imitate various scenes in the real world, or it can be a completely fictitious, fantasy space that transcends reality. A virtual scene can contain virtual objects, light sources, etc. The virtual object can be at least one of a virtual character, a virtual animal, and a virtual item. Taking the virtual scene displayed (or provided) on the game client when the game is running as an example, the virtual scene can be a simulated environment scene of the real world, a semi-simulated and semi-fictitious three-dimensional environment scene, or a purely fictitious three-dimensional environment scene. A virtual scene can be any one of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, and a three-dimensional virtual scene.
[0056] See also Figure 1 , Figure 1 It is a schematic diagram of the architecture of an electronic device for executing an occlusion culling method provided in an embodiment of the present application.
[0057] Figure 1 The electronic devices shown may include but are not limited to terminal devices or servers: terminal devices may be but are not limited to mobile phones, tablet computers, laptop computers, PDAs, mobile Internet devices (MIDs), intelligent voice interaction devices, vehicle terminals, roadside devices, aircraft, wearable devices, smart home appliances, etc. The server may be a single server, or a server cluster consisting of multiple servers, or any one of a cloud computing platform and a virtualization center, which is not limited in the embodiments of the present application. As long as it can be used to execute the occlusion culling method of the present application.
[0058] The electronic device provided in the embodiment of the present application may include a central processing unit 110 (CPU, Central Processing Unit) and a graphics processor 120 (GPU, Graphics Processing Unit), a memory 150 and at least one network interface 130. The various components in the electronic device are coupled together through a bus system 140. It is understood that the bus system 140 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 140 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, in Figure 1 Various buses are labeled as bus system 140 .
[0059] The central processing unit 110 is one of the core components of a computer system. It is responsible for executing instructions in computer programs and coordinating and controlling various operations of the computer. The CPU is usually composed of one or more processing cores, each of which can process instruction streams and data.
[0060] The graphics processor 120 is a processor specially designed for processing graphics and image-related calculations. The GPU is mainly used for computer graphics rendering. It has many parallel processing units, each of which can execute the same instructions but process different data. The graphics processor is usually also equipped with a large-capacity video memory for storing and processing textures, vertex and pixel data required for graphics rendering. It also provides a dedicated graphics processing pipeline, including vertex processing, geometry processing, rasterization and pixel processing stages.
[0061] The memory 150 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 150 may optionally include one or more storage devices that are physically remote from the processor 110.
[0062] The memory 150 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 250 described in the embodiment of the present application is intended to include any suitable type of memory.
[0063] In some embodiments, the memory 150 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0064] Operating system 151, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0065] A network communication module 152, used to reach other electronic devices via one or more (wired or wireless) network interfaces 130, exemplary network interfaces 130 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0066] In some embodiments, the occlusion removal device provided in the embodiments of the present application can be implemented in a software manner. Figure 1The occlusion culling device 155 stored in the memory 150 is shown, which can be software in the form of a program and a plug-in, etc., and includes the following software modules: a culling test module 1551, a first depth map drawing module 1552, a rasterization processing module 1553, and a culling result update module 1554. These modules are logical, and therefore can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0067] exist Figure 1 On this basis, the occlusion culling method provided by the embodiment of the present application will be described below in combination with the exemplary application and implementation of the electronic device provided by the embodiment of the present application.
[0068] like Figure 2 As shown, an embodiment of the present application provides an occlusion culling method, which can be applied to an electronic device, and the electronic device may include a processor and a graphics processor.
[0069] The occlusion culling method provided in this application can be applied in the fields of movies, games, animations or short videos, and occlusion culling tests are performed on virtual objects in virtual scenes involved in the above fields. Virtual objects in virtual scenes are models of objects presented in virtual scenes, such as various furniture, plants, rocks, animals, virtual characters in games, virtual props, etc.
[0070] The method includes steps S110 - S140 .
[0071] Step S110: calling a compute shader to perform a culling test on virtual objects in the virtual scene at time point t+1 according to the depth map of the virtual scene at time point t, and obtaining a first culling result.
[0072] The first culling result indicates the first virtual object determined to be occluded and the second virtual object determined to be visible in the culling test; t is a positive integer.
[0073] Compute shaders are programs that run on the graphics processor and are used to perform general computing tasks. They can implement general computing logic, but they do not participate in the graphics rendering process. In other words, compute shaders are not limited by the rendering pipeline on the GPU. The rendering pipeline includes the rasterization pipeline, so compute shaders are not part of the rasterization pipeline.
[0074] The depth map of the virtual scene at time point t refers to the depth map obtained by viewing the virtual scene at time point t through a virtual camera, and the pixel value of each pixel in the depth map is the depth value.
[0075] It is worth mentioning that in the present application, time point t and time point t+1 are used to define the chronological relationship of time points, that is, time point t is before time point t+1, and are not used as time points to define time point t+1 as the next time unit of time point t (such as the next second or the next minute, etc.).
[0076] In one possible implementation, the time interval between time t and time t+1 is determined according to the drawing frame rate, or in other words, is determined by the drawing interval. For example, the texture drawn for the virtual scene at time t is the previous frame of the texture drawn for the virtual scene at time t+1. Textures include the depth map and scene map finally drawn for the virtual scene at each time in this application.
[0077] The culling test in this application refers to determining, from a virtual scene, virtual objects that are obscured and virtual objects that can be seen (ie, visible virtual objects) from the perspective of a virtual camera.
[0078] It is worth mentioning that virtual objects in the same virtual scene may change at different times, such as the position of virtual objects in the virtual scene, the virtual objects contained in the virtual scene, the posture of movable virtual objects in the virtual scene, etc. Since time t and time t+1 are two adjacent times, the time interval between them is very small, so the difference between the virtual scene at time t and the virtual scene at time t+1 is small, and correspondingly, the visibility (visible or blocked) of the same virtual object in the virtual scene at time t and the visibility in the virtual scene at time t+1 is small. Therefore, the depth map of the virtual scene at time point t can be used as the data basis for judging the visibility of virtual objects in the virtual scene at time point t+1.
[0079] In the present application, for virtual objects in the virtual scene at time point t+1, the virtual object determined to be occluded in the culling test is referred to as the first virtual object, and the virtual object determined to be visible in the culling test is referred to as the second virtual object.
[0080] In one possible implementation, see Figure 3 , the above step S110 may be to call the compute shader to execute the following steps S111 to S115:
[0081] Step S111: sampling the depth map of the virtual scene at time point t level by level to obtain a layered map of the depth map of the virtual scene at time point t at multiple levels.
[0082] The depth map of the virtual scene at time point t can be downsampled step by step to obtain layer maps at multiple levels. It is worth mentioning that the pixel value of each pixel in the layer map at each level is also a depth value. Compared with the depth map of the virtual scene at time point t, the resolution of the layer map (that is, the number of pixels therein) is different from the resolution of the depth map of the virtual scene at time point t. Correspondingly, the size of a single pixel in the layer maps of different levels and the size of a single pixel in the depth map of the virtual scene at time point t are also different.
[0083] The step-by-step sampling refers to using the layer map obtained by the previous sampling as the basis for the next sampling. In a specific embodiment, the number of layer maps required (assuming it is N) and the resolution reduction coefficient can be pre-set, and then the resolution is downsampled step by step according to the resolution reduction coefficient until N layer maps are obtained, where N is a positive integer greater than 1, and N can be set according to actual needs, for example, N is 4, 5, 6, etc. It is worth mentioning that the larger N is, the more times sampling is required, and correspondingly, the more computing resources are consumed.
[0084] For example, taking the resolution reduction coefficient equal to 1 / 2 as an example, the depth map of the virtual scene at time point t can be sampled according to the resolution reduction coefficient to obtain the layer map at the first level, wherein the resolution of the layer map at the first level is 1 / 2 of the depth map of the virtual scene at time point t; then, according to the resolution reduction coefficient, the layer map at the first level is sampled to obtain the layer map at the second level, and the resolution of the layer map at the second level is 1 / 2 of the resolution of the layer map at the first level; then, according to the resolution reduction coefficient, the layer map at the second level is sampled to obtain the layer map at the third level, and the resolution of the layer map at the third level is 1 / 2 of the resolution of the layer map at the second level, and so on, until the number of layer maps obtained meets the preset requirements. In each sampling process, the pixel values of the pixel in the input map and the surrounding pixels are linearly filtered to determine the pixel value of the corresponding pixel in the output layer map.
[0085] Step S112: Projecting the vertices of the bounding box of each virtual object in the virtual scene at time point t+1 to the screen space to obtain the size of the pixels covered by the bounding box in the screen space.
[0086] Among them, the bounding box data of the bounding box of each virtual object in the virtual scene at time point t+1 can be pre-loaded into the GPU along with the model data of the virtual object, so that the computation shader in the GPU performs a culling test based on the bounding box data of the bounding box of each virtual object in the virtual scene at time point t+1 and the model data of the virtual object. Furthermore, the camera data of the virtual camera in the virtual scene at time point t+1 can also be loaded into the GPU for subsequent projection transformation, and the camera data includes the coordinate information of the virtual camera in the virtual scene, the viewing angle information of the virtual camera, the camera parameters of the virtual camera, etc.
[0087] The bounding box data of the bounding box may include vertex information of each vertex of the bounding box, and the vertex information includes at least the coordinates of the vertex in the three-dimensional coordinate system of the virtual scene; when the bounding box is a cuboid, the vertices of the bounding box are the 8 vertices of the cuboid.
[0088] The model data of the virtual object may include vertex information of each vertex on the three-dimensional model of the virtual object, and may also include posture information of the virtual object, etc.
[0089] By projecting the vertices of the bounding boxes of each virtual object in the virtual scene at time point t+1 to the screen space, the pixels mapped by the vertices of the bounding boxes of each virtual object in the virtual scene at time point t+1 can be determined. Furthermore, the pixel area surrounded by the pixels mapped by all the vertices of the bounding box of a virtual object in the virtual scene at time point t+1 can be used as the pixels covered by the bounding box in the screen space. In other words, the pixels covered by the bounding box in the screen space are actually a bounded pixel area with the pixels mapped by all the vertices of the bounding box as the boundary. Therefore, the size of the pixels covered by the bounding box in the screen space is the size of the bounded pixel area with the pixels mapped by all the vertices of the bounding box as the boundary.
[0090] In some embodiments, the bounding box of the virtual object may be an axis-aligned bounding box, which is aligned with the coordinate axes of the world coordinate system. The computational shader may project the axis-aligned bounding box of the virtual object to the screen space with less computational effort than projecting the vertices on the virtual object's directional bounding box to the screen space, which can reduce the computational effort of the culling test. However, in this way, since the axis-aligned bounding box of the virtual object is larger than the directional bounding box of the virtual object, there may be culling errors, that is, the visible virtual object is mistakenly identified as an obscured virtual object.
[0091] Step S113: among the layer maps at multiple levels, determine a target layer map having the smallest size difference between the size of a unit pixel and the size of pixels covered by the bounding box in the screen space.
[0092] That is to say, among the layer maps at multiple levels, the layer map whose unit pixel size is closest to the size of the pixels covered by the bounding box in the screen space is used as the target layer map.
[0093] Step S114: Determine the target pixels corresponding to the vertices of the bounding box in the target layer map.
[0094] The target pixels corresponding to the vertices of the bounding box in the target hierarchy map can be determined based on the texture coordinates of the vertices of the bounding box. That is, the pixel whose pixel distance ratio of the pixel coordinates in the target hierarchy map relative to the origin in the target hierarchy map is equal to the texture coordinates of the vertices of the bounding box can be determined as the target pixels corresponding to the vertices of the bounding box in the target hierarchy map. It is worth mentioning that the horizontal coordinate and the vertical coordinate in the texture coordinates of the vertices of the bounding box are both values between 0 and 1. Therefore, the horizontal coordinate and the vertical coordinate in the texture coordinates of the vertices of the bounding box can be used as the horizontal pixel distance ratio and the vertical pixel distance ratio, respectively, to determine the target pixels corresponding to the vertices of the bounding box in the target hierarchy map.
[0095] Since there are multiple vertices on the bounding box, the target pixel corresponding to each vertex on the bounding box in the target hierarchical map can be determined respectively.
[0096] Step S115: Determine a first culling test result according to the depth values of the vertices of the bounding box and the depth values of the target pixels corresponding to the vertices of the bounding box in the target hierarchical map.
[0097] The depth values of the vertices of the bounding box are determined in the process of projecting the vertices of the bounding box into the screen space.
[0098] In some embodiments, since there are multiple vertices of the bounding box, if different vertices of the bounding box correspond to different target pixels in the target hierarchical map, the target pixel with the smallest depth value in the target hierarchical map can be determined. For ease of description, the target pixel with the smallest depth value in the target hierarchical map is referred to as the target reference pixel. On this basis, the minimum value among the depth values of the multiple vertices of the bounding box can be compared with the depth value of the target reference pixel in the target hierarchical map. If the minimum value among the depth values of the multiple vertices of the bounding box does not exceed the depth value of the target reference pixel, it is determined that the virtual object enclosed by the bounding box is visible. Conversely, if the minimum value among the depth values of the multiple vertices of the bounding box exceeds the depth value of the target reference pixel, it can be determined that the virtual object enclosed by the bounding box is obscured.
[0099] In some embodiments, the depth value of each vertex of the bounding box can be compared with the depth value of the target pixel corresponding to the vertex in the target hierarchical map. If there is a vertex in the bounding box whose depth value does not exceed the depth value of the corresponding target pixel in the target hierarchical map, it can be determined that the virtual object enclosed by the bounding box is visible; otherwise, it is determined that the virtual object enclosed by the bounding box is obscured.
[0100] For each virtual object in the virtual scene at time point t+1, its visibility result in the culling test can be determined according to the above process, and the visibility result is used to indicate whether it is determined to be visible or obscured in the culling test; then, the visibility results of all virtual objects in the virtual scene at time point t+1 in the culling test are combined to obtain the first culling test result.
[0101] In the above embodiment, the bounding box of each virtual object in the virtual scene at time point t+1 is projected into the screen space, and then the depth value comparison is performed, without projecting each virtual object in the virtual scene at time point t+1 into the screen space. Compared with the virtual object, the bounding box of the virtual object is a simple geometric body, and the number of vertices on the bounding box is relatively small compared to the number of vertices of the virtual object. Therefore, using the pixels covered by the bounding box of the virtual object projected into the screen space instead of the pixels covered by the virtual object projected into the screen space can greatly reduce the amount of calculation, save computing resources, and improve the efficiency of the culling test.
[0102] In some embodiments, in step S110, a compute shader may be called to perform the following steps A1-A2, which are described in detail as follows:
[0103] Step A1, projecting the vertices of the bounding box of each virtual object in the virtual scene at time point t+1 to the screen space, and determining the pixel coordinates of the pixels mapped by the vertices of the bounding box and the depth values of the vertices of the bounding box.
[0104] The camera data of the virtual camera in the virtual scene and the bounding box information of each virtual object in the virtual scene at time point t+1 can be used to project the vertices of the bounding box of each virtual object in the virtual scene at time point t+1 to the clipping space.
[0105] The clipping space is a transformed space, which is a regular cube in the clipping space (e.g., a cube from -1 to 1). When the bounding box of the virtual object in the virtual scene at time point t+1 is converted to the clipping space and the spatial coordinates of the target point of the bounding box in the clipping space are obtained, the virtual objects in the virtual scene that are completely outside the virtual camera's frustum are implicitly culled. Therefore, only objects that have passed the clipping and are within the virtual camera's frustum are subsequently tested for occlusion culling.
[0106] Specifically, the process of culling virtual objects completely outside the viewing cone of the virtual camera in the virtual scene may be as follows: determine the viewing cone of the virtual camera in the target virtual scene at time point t+1. Based on the position information of the viewing cone of the virtual camera in the target virtual scene and the position information of each virtual object in the target virtual scene at time point t+1 (reflected by the vertex position information of the vertices on the virtual object), determine whether at least one vertex located in the viewing cone of the light source on the virtual object at time point t+1 is located in the viewing cone. For the virtual object with at least one vertex in the viewing cone, an occlusion culling test needs to be performed; conversely, if all vertices on the virtual object are located outside the viewing cone of the camera, it can be determined that the virtual object is not in the viewing cone at time point t+1, and the virtual object that is not in the viewing cone at time point t+1 is culled, so there is no need to perform subsequent occlusion culling tests.
[0107] Step A2, determining a first culling test result according to the depth values of the pixel coordinates of the pixels mapped by the vertices of the bounding box in the depth map at the corresponding time point t and the depth values of the vertices of the bounding box.
[0108] In some embodiments, since the bounding box has multiple vertices, if the depth value of a vertex of the bounding box does not exceed the depth value of the pixel coordinates of the pixel point mapped by it in the depth map at time point t, it can be determined that the virtual object enclosed by the bounding box is visible; otherwise, it is determined that the virtual object enclosed by the bounding box is obscured.
[0109] In the above embodiment, the bounding box of each virtual object in the virtual scene at time point t+1 is projected into the screen space, and then the depth value comparison is performed, without projecting each virtual object in the virtual scene at time point t+1 into the screen space. Compared with the virtual object, the bounding box of the virtual object is a simple geometric body, and the number of vertices on the bounding box is relatively small compared to the number of vertices of the virtual object. Therefore, using the pixels covered by the bounding box of the virtual object projected into the screen space instead of the pixels covered by the virtual object projected into the screen space can greatly reduce the amount of calculation, save computing resources, and improve the efficiency of the culling test.
[0110] Step S120: performing depth rendering on the second virtual object to obtain an initial depth map of the virtual scene at time point t+1.
[0111] That is, at the time point t+1, the initial depth map of the virtual scene only presents the depth values of the virtual objects that are determined to be visible in the culling test and projected into the screen space.
[0112] In some embodiments, since the drawing application provides an indirect drawing command, the drawing parameters can be read from the buffer on the GPU through the indirect drawing command, and then drawing can be performed without the CPU sending drawing commands to the GPU multiple times, which can reduce the data exchange between the CPU and the GPU. Based on this, in the above culling test process of step S110, a buffer can also be created on the GPU in advance, and then the calculation shader can write the drawing parameters of the first virtual object determined to be visible by the culling test into the buffer. Among them, the drawing parameters of the first virtual object written into the buffer of the GPU are indirect drawing parameters. In this case, in addition to outputting the first culling test result, the above culling test process also includes the indirect drawing parameters of the second virtual object. Therefore, the GPU can read the indirect drawing parameters of the second virtual object to perform depth drawing on the second virtual object to obtain the initial depth map of the virtual scene at time point t+1.
[0113] The indirect drawing parameters of the second virtual object may include the number of vertices, vertex index offset, vertex data offset, and instance offset of the second virtual object, the number of instances to be drawn, etc., wherein the number of vertices refers to the number of vertices on the virtual object; the vertex index offset is used to indicate the starting position of the vertex index data (which refers to the data of the vertex information used to index the vertex), the vertex data offset is used to indicate the starting position of the vertex data (i.e., data related to the vertex, such as the vertex information mentioned above, such as position, depth, texture coordinates, etc.); the instance offset is used to indicate the starting position of the instance to be drawn for the virtual object. The number of instances to be drawn in the indirect drawing parameters output by the culling test process is the number of the second virtual object.
[0114] In step S120, the rendering pipeline on the GPU may be called to execute the indirect rendering command based on the indirect rendering parameters of the second virtual object to obtain the initial depth map of the virtual scene at time point t+1. In the process of depth rendering by the rendering pipeline, the projection of each vertex on the second virtual object to the screen space is calculated, and the depth value of the vertex is drawn to the mapped pixel as the pixel value of the corresponding pixel.
[0115] Step S130: calling the rasterization pipeline to perform rasterization processing on the bounding box according to the bounding box information of the bounding box of each virtual object and the initial depth map, and obtaining the rasterization result of the bounding box.
[0116] Among them, the rasterization result indicates the visibility result of the bounding box.
[0117] Although the difference between the virtual scene at time t and the virtual scene at time t+1 is small, the visibility (visible or occluded) of the same virtual object in the virtual scene at time t cannot fully represent its visibility in the virtual scene at time t+1. Therefore, there may be virtual objects that are mistakenly identified as occluded in the first culling result, and there may also be virtual objects that are mistakenly identified as visible. Therefore, in this application, in order to ensure the accuracy of the occlusion culling result, the bounding box is rasterized according to the rasterization pipeline to obtain the rasterization result of the bounding box, so as to subsequently use the rasterization result of the bounding box to correct the first culling result.
[0118] The bounding box information includes vertex information of vertices on the bounding box (eg, coordinates of the vertices in the three-dimensional coordinate system of the virtual scene, etc.).
[0119] The rasterization pipeline runs on the GPU and is the core component of the rendering pipeline for implementing rasterization. The rendering pipeline includes both the hardware operations provided by the GPU to convert three-dimensional graphics data (such as the vertex information of the vertices on the bounding box above) into two-dimensional images, and the software used for graphics drawing on the GPU to manage and control the operation of the hardware rendering pipeline.
[0120] The processing performed by the rasterization pipeline is performed by hardware units in the graphics processing unit (GPU) (eg, some hardware that implements rasterization) and is supported by software such as drivers, shader programs, and graphics application programming interfaces (APIs).
[0121] The process of rasterizing the bounding box of a virtual object in the rasterization pipeline includes the geometry processing stage and the rasterization stage. Figure 4 The above step S130 may specifically be to call the rasterization pipeline to execute steps S132-S136 for the bounding box of each virtual object.
[0122] Step S132: According to the bounding box information of the bounding box of each virtual object, the vertices of the bounding box are geometrically processed to obtain the texture coordinates of the vertices of the bounding box and the depth values corresponding to the vertices on the bounding box.
[0123] Among them, geometric processing of the vertices of the bounding box refers to converting the vertices of the bounding box from the model space to the screen space. This process involves three stages: coordinate transformation, depth calculation, and texture coordinate calculation.
[0124] The coordinate transformation stage refers to the transformation of vertices using the model view matrix and the projection matrix. Specifically, the model view matrix can be used to transform the vertices of the bounding box in the model space to the view space to obtain the coordinates of the vertices of the bounding box in the view space; in this process, the absolute positions of the vertices of the bounding box are not changed, but the coordinate system of the vertices of the bounding box is changed from the model coordinate system to the world coordinate system. Afterwards, the vertices in the view space are transformed to the clipping space based on the projection matrix to obtain the coordinates of the vertices of the bounding box in the clipping space. In the clipping space, the coordinates of the vertices of the bounding box in the clipping space are normalized to a specific range, such as a cube of [-1,1] or [0,1]. If the vertices of a bounding box exceed this range, it means that part or all of the virtual objects in the bounding box will not be rendered. The depth calculation stage refers to performing perspective division on the coordinates of the vertices of the bounding box in the clipping space to normalize the homogeneous components of the vertices of the bounding box in the clipping space coordinates to obtain the normalized device coordinates of the vertices of the bounding box, so as to extract the depth values of the vertices of the bounding box from the normalized device coordinates.
[0125] The texture coordinate calculation stage refers to performing viewport transformation on the normalized device coordinates of the vertices of the bounding box so as to project them from the clipping coordinate system to the screen coordinate system to obtain the texture coordinates of the vertices of the bounding box.
[0126] Step S134: performing rasterization according to the texture coordinates of the vertices of the bounding box and the corresponding depth values, and determining a plurality of fragments corresponding to the bounding box; the fragments include pixel coordinates and fragment depth values.
[0127] In step S132, it is involved to assemble the vertices on the bounding box into primitives, and a primitive can be a triangle primitive formed by connecting three vertices. In step S134, light deletion can be performed according to the texture coordinates of each vertex in the primitive and the corresponding depth value, that is, determine which pixels a primitive covers in the screen space, and use the vertex information of the three vertices in the primitive to interpolate the pixels in the pixel area covered by the primitive to obtain multiple fragments corresponding to the bounding box. One fragment corresponds to one pixel in the screen space, but the fragment also includes more information than the pixel, such as the vertex color of the fragment, and vertex related information output from the geometry stage, such as the normal of the vertex, texture coordinates, etc.
[0128] Among them, the fragment depth value of the fragment corresponding to the vertex of the bounding box is the depth value corresponding to the vertex of the bounding box; the fragment depth values of other fragments (for the convenience of description, they are called intermediate fragments) among the multiple fragments corresponding to the bounding box except the fragment corresponding to the vertex can be obtained by weighted calculation based on the depth values of the three vertices in the primitive corresponding to the intermediate fragment, and the weight of each vertex is determined according to the position of the fragment mapped by the pixel coordinates of the intermediate fragment relative to the vertex.
[0129] In one possible implementation, the fragment depth value of the intermediate fragment can be obtained as follows: for any target fragment among the multiple intermediate fragments, the depth influence weight of each vertex in the target primitive on the target fragment can be determined according to the distance between the pixel coordinates of the target fragment and the pixel coordinates corresponding to each vertex in the target primitive to which it belongs, and the depth influence weight of each vertex in the target primitive on the target fragment and the rasterized depth value corresponding to each vertex are weightedly summed to obtain the fragment depth value of the target fragment.
[0130] Exemplarily, the three vertices of the target primitive are P1, P2 and P3, the distance between the pixel point of the target fragment and the pixel point corresponding to vertex P1 is d1, the distance between the pixel points corresponding to vertex P2 is d2, and the distance between the pixel points corresponding to vertex P3 is d3. The depth influence weight of vertex P1 on the target fragment is W1=d1 / (d1+d2+d3), the depth influence weight of vertex P2 on the target fragment is W2=d2 / (d1+d2+d3), and the depth influence weight of vertex P3 on the target fragment is W3=d3 / (d1+d2+d3).
[0131] For ease of description, the fragments mapped by the vertices of the bounding box are called reference fragments; the fragment depth value of the intermediate fragment can be obtained in the following way: for any target fragment in the intermediate fragment, based on the pixel distance between the target fragment and the reference fragment mapped by the three vertices in the target primitive corresponding to the target fragment, determine the depth influence weight of each reference fragment on the target fragment; according to the depth influence weight of each reference fragment on the target fragment, perform weighted summation on the depth values of multiple reference fragments to obtain the fragment depth value of the target fragment.
[0132] Step S136: Determine the visibility result of the bounding box according to the depth values of the pixels corresponding to the pixel coordinates in the multiple fragments corresponding to the bounding box in the initial depth map and the depth values of the fragments in the fragments.
[0133] Specifically, for each fragment, the fragment depth value of the fragment is compared with the depth value of the corresponding pixel position in the initial depth map. If the fragment depth value of a fragment is less than or equal to the depth value of the corresponding pixel position in the initial depth map (i.e., the pixel position indicated by the pixel coordinates in the fragment), it means that the fragment is visible. If the depth value of the fragment is greater than the depth value of the corresponding pixel position in the initial depth map, it means that the fragment is occluded. Furthermore, the visibility result of the bounding box can be determined based on the visibility of multiple fragments corresponding to the bounding box, and the visibility result of the bounding box is used to indicate whether the bounding box is visible or occluded.
[0134] By adopting the above steps S132-S136, since the bounding box is simpler and easier to process than a complex 3D model, the bounding box vertices are converted into texture coordinates and depth values, and then rasterized. The fragments generated during the rasterization process contain pixel coordinates and depth values. By comparing the depth values of these fragments with the corresponding pixel depth values in the initial depth map, the visibility of the fragments can be quickly determined, and then the visibility of the bounding box can be determined based on the visibility of the fragments. In addition, during the execution of steps S132-S136, since the rasterization pipeline is called to rasterize the bounding box, the rasterization processing capabilities of the hardware units and software units used to implement rasterization processing in the graphics processor can be fully utilized. In this way, there is no need to generate multiple hierarchical maps twice, and, relatively speaking, the shader in the rasterization pipeline is more efficient than the processing of the compute shader. Therefore, using the rasterization pipeline for secondary occlusion culling can improve the efficiency of occlusion culling as a whole.
[0135] In one possible implementation, the above step S136 may be: if among the multiple fragments corresponding to the bounding box, determine the first fragment whose pixel coordinates in the initial depth map have a depth value that is not less than the corresponding fragment depth value; if the number of the first fragments exceeds a quantity threshold, determine that the visibility result of the bounding box indicates that the bounding box is visible; if the number of the first fragments does not exceed the quantity threshold, determine that the visibility result of the bounding box indicates that the bounding box is invisible.
[0136] In some embodiments, the quantity threshold may be set according to actual needs, for example, the same quantity threshold may be set for different bounding boxes. Of course, different quantity thresholds may also be set.
[0137] In some embodiments, a fragment ratio may be set, and then the fragment ratio is multiplied by the number of fragments corresponding to each bounding box to obtain a number threshold of the bounding box.
[0138] In one possible implementation, if different bounding boxes are set with the same quantity threshold, for example, all are 1, the above-mentioned step S136 may be: if among the multiple fragments corresponding to the bounding box, there is a first fragment whose pixel coordinates in the initial depth map have a depth value that is not less than the corresponding fragment depth value, the visibility result of the bounding box is determined to indicate that the bounding box is visible; if the first fragment does not exist among the multiple fragments corresponding to the bounding box, the visibility result of the bounding box is determined to indicate that the bounding box is invisible.
[0139] By adopting the above-mentioned method for determining the visibility of the bounding box, since each fragment corresponds to a pixel position, when the visibility of the bounding box is determined based on the visibility of multiple fragments corresponding to the bounding box, a pixel-level judgment of the visibility of the bounding box is achieved. At the same time, the obscured part and the visible part of the bounding box can be specifically determined, and finally the visibility of the bounding box is determined according to the pixel-level judgment result, thereby improving the accuracy of the bounding box visibility judgment.
[0140] In one possible implementation, a pixel shader is deployed on the rasterization pipeline; in the rasterization process, the write switch of the initial depth map is in a closed state; if the number of first fragments exceeds the number threshold, after determining that the visibility result of the bounding box indicates that the bounding box is visible, the method further includes:
[0141] The pixel shader performs pixel shading on the pixel corresponding to the first fragment in the initial depth map. It can be understood that since the write switch of the initial depth map is in the off state, even if the pixel shader performs pixel shading, the depth value corresponding to the enclosing will not be written into the initial depth map.
[0142] In the rasterization process, the writing switch of the initial depth map is turned off, so that in the rasterization stage, only the visibility of the bounding box is determined without updating the initial depth map.
[0143] For example, if the initial depth map of the virtual scene at time point t+1 is as follows Figure 5 As shown, the initial depth map stores the depth value of each pixel, and the rasterization pipeline is called to rasterize the bounding box of virtual object A and the bounding box of virtual object B according to the texture coordinates of the vertices of the bounding box and the corresponding depth values, and obtain multiple fragments corresponding to the bounding box of virtual object A and the bounding box of virtual object B, such as Figure 6 As shown, the rasterized image of the bounding box of virtual object A is the set of pixel points covered by multiple fragments corresponding to the bounding box of virtual object A in the initial depth map, and the rasterized image of the bounding box of virtual object B is the set of pixel points covered by multiple fragments corresponding to the bounding box of virtual object B in the initial depth map.
[0144] For ease of understanding, assuming that the write switch of the initial depth map is turned on, for virtual object A, according to the depth values of the pixels corresponding to the pixel coordinates in the multiple fragments corresponding to the bounding box of virtual object A in the initial depth map and the depth values of the fragments in the fragments, it is determined that there is a visible first fragment among the multiple fragments corresponding to the bounding box of virtual object A. At this time, the pixel points covered by the first fragment in the initial depth map are visible. Figure 7The green area in the middle is the set of pixels covered by the first fragment in the initial depth map, and the red area is the set of pixels covered by the invisible fragment in the initial depth map. For virtual object B, according to the depth values of the pixels corresponding to the pixel coordinates in the multiple fragments corresponding to the bounding box of virtual object B in the initial depth map and the depth values of the fragments in the fragments, it can be determined that the first fragment does not exist in the multiple fragments corresponding to the bounding box of virtual object B, that is, the red area is the set of pixels covered by the invisible fragment in the initial depth map.
[0145] Step S140: According to the visibility result, the first culling result is updated to obtain a second culling result of the virtual scene at time point t+1.
[0146] Among them, in the second elimination result, the first virtual object enclosed by the bounding box indicated by the visibility result is determined to be visible, and the second virtual object enclosed by the bounding box indicated by the visibility result is determined to be blocked.
[0147] Specifically, updating the first culling result may include: for the first virtual object determined as being occluded in the culling test by the first culling result, if there is a bounding box of the target first virtual object in the first virtual object, and after rasterization processing, a rasterization result indicating that the bounding box is visible is obtained, then the visibility result of the target first virtual object in the first culling result is adjusted to be visible, that is, the first virtual object enclosed by the visible bounding box indicated by the visibility result in the second culling result is visible. If there is a bounding box of the target second virtual object in the second virtual object, and after rasterization processing, a rasterization result indicating that the bounding box is occluded is obtained, then the visibility result of the target first virtual object in the first culling result is adjusted to be occluded, that is, the second virtual object enclosed by the occluded bounding box indicated by the visibility result in the second culling result is occluded.
[0148] In the related art, occlusion culling is implemented by computing shaders, and the process of implementing occlusion culling includes: using the depth map of the virtual scene at time t (for the sake of ease of description, it is called the previous frame depth map) for sampling to obtain the layered maps of the depth map of the previous frame at multiple levels; judging the visibility of virtual objects in the virtual scene at time t+1 according to the layered maps of the depth map of the previous frame at multiple levels, and obtaining the initial occlusion culling result; then drawing the depth map of the virtual scene at time t+1 according to the initial occlusion culling result (it is called the current frame depth map), and then sampling the current frame depth map to obtain the layered maps of the current frame depth map at multiple levels, and judging the visibility of virtual objects in the virtual scene at time t+1 through the layered maps of the current frame depth map at multiple levels, and obtaining the occlusion culling result of the virtual scene at time t. It can be seen from the above that the processing involves generating layer maps at multiple levels twice, the calculation consumption of the entire occlusion culling is large, and the efficiency of occlusion culling is not high.
[0149] By adopting the occlusion culling method of the present application, first, based on the depth map of the virtual scene at time point t, a culling test is performed on the virtual objects in the virtual scene at time point t+1 to obtain a first culling result, and depth drawing is performed based on the first virtual object indicated as visible in the first culling result to obtain an initial depth map of the virtual scene at time point t+1, and the rasterization pipeline is called to rasterize the bounding box according to the bounding box information and the initial depth map of the bounding box of each virtual object to obtain a rasterization result of the bounding box, and the first culling result is updated according to the rasterization result of the bounding box to obtain a second culling result of the virtual scene at time point t+1. The occlusion culling is performed twice using a compute shader and a rasterization pipeline to ensure the accuracy of the obtained second culling result. Moreover, since the rasterization pipeline is called to rasterize the bounding box, the rasterization processing capabilities of the hardware units and software units in the graphics processor used to implement rasterization processing can be fully utilized. In this way, there is no need to generate layer maps at multiple levels twice. Moreover, relatively speaking, the shader in the rasterization pipeline is more efficient than the computing shader. Therefore, using the rasterization pipeline for secondary occlusion culling can improve the overall efficiency of occlusion culling.
[0150] In addition, in the related art, in order to improve the efficiency of occlusion culling by the compute shader, the compute shader usually transforms the axis-aligned bounding box of the virtual object to the screen space to determine the visibility result of the bounding box. However, in the actual process, the axis-aligned bounding box occupies a larger space, and there are more gaps between the axis-aligned bounding box of the virtual object and the virtual object, which will cause the accuracy of the occlusion culling result obtained by the compute shader to be low. In the present application, the processing performance of the rasterization pipeline for different types of bounding boxes is equivalent. The bounding box for rasterization processing can be the directional bounding box of the virtual object, and the directional bounding box can more accurately express the space occupied by the virtual object; therefore, the visibility result of the directional bounding box obtained by calling the rasterization pipeline is more accurate, which can ensure that the second culling result of the virtual scene at the time point t+1 is more accurate. Furthermore, it can also solve the problem of large amount of subsequent graphics drawing caused by determining the occluded virtual object as visible, reduce unnecessary subsequent graphics drawing, and thus improve the efficiency of graphics drawing.
[0151] See also Figure 8 As shown, before step S130, the method further includes:
[0152] Step S150: Based on the first elimination result, a visibility mark is written into a storage location corresponding to each virtual object in the first buffer, where the visibility mark includes a first mark indicating visible and a second mark indicating blocked.
[0153] The first mark and the second mark can be letters, numbers, symbols or character strings, etc., any information that can indicate visibility; for example, the first mark can be the number 1 indicating visibility, and the second mark can be the number 0 indicating obscuration.
[0154] The first buffer is a buffer set in the GPU, and the storage locations corresponding to the virtual objects may be random or arranged according to a certain rule. For example, the storage locations corresponding to the virtual objects may be determined according to the sorting order of the object identifiers of the virtual objects, the storage locations corresponding to the virtual objects may also be determined according to the elimination test order of the virtual objects, and the storage locations corresponding to the virtual objects may also be determined according to the first elimination result (for example, the storage location corresponding to the first virtual object is the storage location pointed to by the first offset interval, and the storage location corresponding to the second virtual object is the storage location pointed to by the second offset interval). Different storage locations in the first buffer may correspond to different offset values. For example, the offset value corresponding to the i-th storage location is i-1, and the offset interval indicates at least two consecutive storage locations. If an offset interval is [0, i), the storage locations pointed to by the offset interval include the first storage location, the second storage location, ..., the i-th storage location. The first offset interval and the second offset interval are offset intervals in which there is no same storage location. Exemplarily, the first offset interval may be [0, i), and the second offset interval may be [i, j), wherein i and j are positive integers respectively, and j is greater than i.
[0155] For example, Fig. 9 As shown, when the storage position corresponding to each virtual object can be determined according to the sorting order of the object identifiers of each virtual object, if there are multiple virtual objects (e.g., X, where X is a positive integer), the object identifiers of the multiple virtual objects are obj0, obj1, obj2, ..., objX, wherein in the first test result, the virtual objects indicated by obj0 and objX are visible, and the virtual objects indicated by obj1 and obj2 are blocked, then the object identifier of the virtual object corresponding to the first storage position is obj0, and its stored visibility mark is the first mark (i.e., 1), the object identifier of the virtual object corresponding to the second storage position is obj1, and its stored visibility mark is the second mark (i.e., 0), the object identifier of the virtual object corresponding to the third storage position is obj2, and its stored visibility mark is the second mark (i.e., 0), the object identifier of the virtual object corresponding to the nth storage position is objn-1, where n is an integer not greater than X; the object identifier of the virtual object corresponding to the X-1th storage position is objX, and its stored visibility mark is the first mark (i.e., 1).
[0156] Exemplarily, when the storage position corresponding to each virtual object is determined according to the first elimination result, if the number of first virtual objects is K1 and the number of second virtual objects is K2, the first offset interval can be [0, K1), and each offset value in the first offset interval corresponds to a first virtual object; the second offset interval can be [K1, K1+K2), and each offset value in the second offset interval corresponds to a second virtual object, wherein an offset value points to a storage position in the first buffer.
[0157] The above step S140 includes:
[0158] Step S142: If there is a first virtual object whose visibility result of the bounding box indicates that it is visible, modify the visibility flag of the first virtual object in the first buffer to the first flag.
[0159] Step S144: If the visibility result of the bounding box indicates that there is a second virtual object that is blocked, modify the visibility flag of the second virtual object in the first buffer to a second flag.
[0160] The visibility mark stored in the modified first buffer is used as the second culling result of the virtual scene at time point t+1.
[0161] Exemplarily, based on the first elimination result, after the visibility mark is written in the storage location corresponding to each virtual object in the first buffer, the visibility mark of the first virtual object determined to be occluded is 0 (i.e., the second mark), and the visibility mark of the virtual object determined to be visible is 1 (i.e., the first mark).
[0162] If there is a visibility result of a bounding box indicating a visible first virtual object, it means that the first virtual object is determined to be occluded in the first culling result. Accordingly, the visibility mark stored in the storage position corresponding to the first virtual object in the first buffer based on the first culling result is the second mark 0. Since it is determined to be visible after rasterization processing, at this time, the visibility mark of the first virtual object in the first buffer is modified from the second mark 0 to the first mark 1 to indicate that the first virtual object is a visible virtual object. If there is a visibility result of a bounding box indicating an occluded first virtual object, it means that the second virtual object is determined to be visible in the first culling result. Accordingly, the visibility mark stored in the storage position corresponding to the second virtual object in the first buffer based on the first culling result is the first mark 1. Since it is determined to be occluded after rasterization processing, at this time, the visibility mark of the second virtual object in the first buffer is modified from the first mark 1 to the second mark 0 to indicate that the second virtual object is an occluded virtual object.
[0163] exist Fig. 9On the basis of, if the virtual object indicated by the object identifier obj1 is determined to be visible after rasterization processing, and the virtual object indicated by the object identifier objX is determined to be blocked after rasterization processing, then the modified buffer obtained by modifying the modification method of the first buffer according to the above modification is as follows Fig.10 shown. Fig.10 The visibility mark stored in the modified buffer shown is the second culling result of the virtual scene at time point t+1.
[0164] After writing the visibility mark in the storage location corresponding to each virtual object in the first buffer based on the first culling result, the graphics processor can use its parallel processing capability to call multiple threads, each thread can independently perform the rasterization processing in the aforementioned step S130 on one or more virtual objects to obtain the rasterization results of each virtual object, and modify the visibility mark of the virtual object stored in the first buffer based on the rasterization result to ultimately obtain the second culling result of the virtual scene at time point t+1.
[0165] In addition, after obtaining the second culling result of the virtual scene at time point t+1, it is possible to directly reference the visibility mark of each virtual object cached in the first buffer in subsequent processing (such as image rendering or depth map drawing) to determine whether it is necessary to load the data of the visible virtual object from the memory without directly loading all virtual object-related data, thereby reducing the use of memory bandwidth and achieving efficient use of the cache.
[0166] In one possible implementation, a vertex shader and a pixel shader are deployed in the rasterization pipeline; before executing step S130, the method further includes: writing object data of the virtual object into the vertex shader; the object data includes bounding box information of the bounding box of the virtual object and an object identifier of the virtual object.
[0167] Among them, the vertex shader is a component in the rasterization pipeline, responsible for processing vertex data, such as accepting and transforming the position and texture coordinates of the vertex, converting the vertex data into a format suitable for rasterization and passing it to the pixel shader; the pixel shader is another component in the rasterization pipeline, responsible for calculating the color and depth values of each pixel, and performing depth testing.
[0168] By writing the object data of the virtual object into the vertex shader, the vertex shader can perform the above step S130 to perform geometric transformation and rasterization processing on the bounding box according to the object data of the virtual object.
[0169] The above-mentioned step S142 includes: if the pixel shader performs pixel shading on the first fragment in the first virtual object in the initial depth map, the pixel shader obtains the object identifier of the first virtual object from the vertex shader, and based on the object identifier of the first virtual object, modifies the visibility mark of the first virtual object in the first buffer to the first mark.
[0170] If the pixel shader performs pixel shading on the first fragment in the first virtual object in the initial depth map, it means that the first fragment is visible, and the virtual object corresponding to the first fragment is also visible.
[0171] See also Fig.11 As shown, in another possible implementation, the method further includes:
[0172] Step S160: Based on the first elimination result, a second mark indicating that the first virtual object is blocked is written into a storage position corresponding to each first virtual object in the second buffer, and a first mark indicating that the second virtual object is visible is written into a storage position corresponding to each second virtual object in the third buffer.
[0173] For the description of the first mark and the second mark, please refer to the description of the aforementioned step S150, which will not be repeated here.
[0174] For example, see Fig.12 As shown, if there are multiple virtual objects (e.g., X, where X is a positive integer), each virtual object corresponds to an object identifier that is identified in the multiple virtual objects, namely obj0, obj1, obj2, ..., objX, wherein in the first test result, the virtual objects indicated by obj0 and objX are blocked (i.e., the virtual objects indicated by obj0 and objX are the first virtual objects), and the virtual objects indicated by obj1 and obj2 are visible (i.e., the virtual objects indicated by obj1 and obj2 are the second virtual objects), then the visibility mark (second mark, 0) of the first virtual object is stored in the second buffer, and the visibility mark (first mark, 1) of the second virtual object is stored in the third buffer, and the second buffer and the third buffer are obtained as shown in FIG. Fig.12 As shown, the object identifier of the virtual object corresponding to the first storage position of the second buffer is obj1, and its stored visibility mark is the second mark (i.e., 0), and the object identifier of the virtual object corresponding to the second storage position is obj2, and its stored visibility mark is also the second mark (i.e., 0); the object identifier of the virtual object corresponding to the first storage position in the third buffer is obj0, and its stored visibility mark is the first mark (i.e., 1), and the object identifier of the virtual object corresponding to the second storage position is objX, and its stored visibility mark is the first mark (i.e., 1).
[0175] The above step S140 includes:
[0176] Step S146: If there is a first virtual object whose visibility result of the bounding box indicates that it is visible, modify the second mark of the first virtual object in the second buffer to the first mark.
[0177] Step S148: If the visibility result of the bounding box indicates that there is a second virtual object that is blocked, modify the first mark of the second virtual object in the third buffer to a second mark.
[0178] exist Fig.12 On the basis of, if the virtual object indicated by the object identifier obj1 is determined to be visible after rasterization processing, and the virtual object indicated by the object identifier objX is determined to be blocked after rasterization processing, then the second buffer and the third buffer are modified according to the above modification method to obtain the modified second buffer and the third buffer as shown in FIG. Fig.13 shown. Fig.13 The visibility mark stored in the modified buffer shown is the second culling result of the virtual scene at time point t+1.
[0179] It is worth mentioning that Fig.14 As shown, after obtaining the first culling result and based on the first culling result, writing a first mark indicating visible in the storage position corresponding to each first virtual object in the second buffer, and writing a second mark indicating blocked in the storage position corresponding to each first virtual object in the third buffer, the above step S120 can also be, based on the second virtual object stored in the third buffer, performing parameter assembly to obtain indirect drawing parameters of the second virtual object, performing depth drawing according to the indirect drawing parameters of the second virtual object, and obtaining the initial depth map of the virtual scene at time point t+1.
[0180] In one possible implementation, Fig.15 As shown, the method further includes the following steps S210-S220:
[0181] Step S210: Based on the second culling result, assembling indirect rendering parameters for the first target virtual object, where the first target virtual object refers to the first virtual object enclosed by the bounding box indicated to be visible by the visibility result.
[0182] Among them, assembling indirect drawing parameters for a virtual object refers to preparing and organizing the necessary parameters for rendering a virtual object so that the GPU can perform indirect drawing operations; specifically, for the first target virtual object, an indirect drawing command can be assigned to each virtual object, and then the relevant drawing parameters can be filled in the indirect drawing command to obtain the indirect drawing parameters of the virtual object. The filled drawing parameters can be the number of vertices, vertex index offset, vertex data offset, and instance offset, etc.
[0183] The indirect rendering parameters of each first target virtual object may be stored in a buffer, such as a depth update buffer.
[0184] In one possible implementation, the above step S210 may be to assemble indirect drawing parameters of the virtual object corresponding to the target storage position of the modified first buffer to obtain scene indirect drawing parameters, wherein the target storage position in the first buffer is a storage position storing the first mark among multiple storage positions pointed to by the first offset interval in the first buffer.
[0185] In another possible implementation, if the visibility mark of the first virtual object is stored in the second buffer, the visibility mark of the second virtual object is stored in the third buffer, and the first visibility result is updated according to the rasterization result to obtain the second culling result, then the above step S210 may be to assemble parameters of the second virtual object corresponding to the storage location where the first mark is stored in the modified third buffer to obtain indirect drawing parameters of each visible first virtual object.
[0186] Step S220: Based on the indirect rendering parameters of the first target virtual object, depth rendering is performed for the first target virtual object in the initial depth map to obtain a depth map of the virtual scene at time point t+1.
[0187] There may be virtual objects in the initial depth map that are actually occluded but drawn. Subsequently, based on the indirect drawing parameters of the first target virtual object, after depth drawing is performed for the first target virtual object in the initial depth map, the virtual objects that are actually occluded but drawn may be covered.
[0188] If after occlusion culling, the rasterization pipeline is called only for the first virtual object that is occluded in the first culling result, and the bounding box is rasterized according to the bounding box information of each virtual object and the initial depth map, and the second virtual object that is determined to be visible in the first culling result does not need to be rasterized. Fig.16 As shown, after obtaining the modified second buffer, parameters of the first virtual object corresponding to the storage position storing the first mark 1 in the modified second buffer are assembled to obtain indirect drawing parameters of each visible first virtual object, and based on the indirect drawing parameters of the first target virtual object, depth drawing is performed for the first target virtual object in the initial depth map to obtain the depth map of the virtual scene at time point t+1.
[0189] Wherein, when depth drawing is performed for the first target virtual object in the initial depth map based on the indirect drawing parameters of the first target virtual object, the GPU may perform the following steps according to the indirect drawing parameters of the first target virtual object: call the vertex shader to convert the vertices of the first target virtual object to the clipping space according to the indirect drawing instructions of the first target virtual object in the depth drawing buffer, clip the vertices that are not in the frustum, call the pixel shader and convert the remaining vertices into pixels (fragments) in the screen space, and for each fragment, compare the fragment depth value in the fragment with the depth value of the corresponding pixel in the initial depth map. If the fragment depth value is less than or equal to the depth value of the corresponding pixel in the initial depth map (depending on the setting of the depth test function), then update the depth value of the corresponding pixel in the initial depth map area to achieve depth drawing for the first target virtual object, and obtain the depth map of the virtual scene at time point t+1.
[0190] Since only the virtual objects indicated as visible in the first culling result are drawn in the initial depth map at time point t+1, and the first target virtual object is the virtual object indicated as occluded in the first culling result and indicated as culled in the rasterization culling result, it is not drawn in the initial depth map. By performing depth drawing for the first target virtual object in the initial depth map based on the indirect drawing parameters of the first target virtual object, invalid drawing of objects that have been drawn and are occluded or not within the viewing cone can be reduced, thereby improving drawing efficiency, reducing the amount of data that needs to be transmitted during the drawing process, and reducing memory bandwidth consumption.
[0191] In another possible implementation, after obtaining the second culling result, indirect rendering parameters may be assembled for the virtual objects indicated as visible in the second culling result to obtain depth indirect rendering parameters; depth rendering is performed according to the depth indirect rendering parameters to obtain a depth map of the virtual scene at time point t+1. The specific rendering process may refer to the process of drawing the initial chromaticity map of the virtual scene at time point t+1 in the aforementioned embodiment, which will not be described in detail here.
[0192] In one possible implementation, see Fig.17 , the method further comprises:
[0193] Step S230: assembling indirect rendering parameters for the virtual objects indicated as visible in the second culling result to obtain scene indirect rendering parameters.
[0194] The scene indirect rendering parameters may include indirect rendering parameters of each visible virtual object indicated in the second proposed result.
[0195] The scene indirect drawing parameters may be stored in a buffer, such as a scene drawing parameter buffer.
[0196] In one possible implementation, if a visibility mark is written into a storage location corresponding to each virtual object in the first buffer based on the first visibility result, and the visibility mark in the first buffer is modified according to the rasterization result, then the above step S230 may be to assemble indirect drawing parameters of the virtual object corresponding to the storage location storing the first mark in the modified first buffer to obtain the scene indirect drawing parameters.
[0197] In another possible implementation, if the visibility mark of the first virtual object in the first visibility result is stored in the second buffer, and the visibility mark of the second virtual object is stored in the third buffer, and after the first visibility result is updated according to the rasterization result to obtain the second culling result, the parameters of the virtual objects corresponding to the storage locations storing the first mark in the modified second buffer and the modified third buffer can be assembled to obtain the scene indirect drawing parameters.
[0198] Step S240: performing scene rendering according to the scene indirect rendering parameters to obtain a scene image of the virtual scene at time point t+1.
[0199] like Fig.18 As shown, it shows a schematic diagram showing that after obtaining the modified second buffer and the modified third buffer, parameters of the virtual objects corresponding to the storage locations storing the first mark in the modified second buffer and the modified third buffer are assembled to obtain scene indirect drawing parameters, and scene drawing is performed based on the scene indirect drawing parameters to obtain a scene image of the virtual scene at time point t+1.
[0200] Specifically, for each visible virtual object, the vertices of the virtual object are converted to the clipping space according to the indirect drawing parameters of the visible virtual object, the vertices that are not within the viewing frustum are clipped, and the remaining vertices after clipping are converted into pixels (fragments) in the screen space. For each fragment, a depth test can be performed on the fragment, and color calculation, texture sampling, lighting calculation and other processing can be performed on the fragment that passes the depth test to generate the color value of the fragment, and the scene image of the virtual scene at time point t+1 is obtained according to the color value of each pixel.
[0201] Among them, if the indirect drawing parameters of each visible virtual object are stored in the scene drawing parameter buffer, the GPU can automatically execute the drawing commands in the indirect drawing parameters to render multiple virtual objects in the depth buffer and generate a scene image according to the indirect drawing parameters of the virtual objects in the scene drawing buffer after executing an API (Application Programming Interface) call.
[0202] By adopting the above steps S230-S240, since the visibility results of each virtual object indicated in the second culling result are more accurate, when the scene is subsequently drawn only according to the indirect drawing parameters of the visible virtual objects indicated in the second culling result, the invalid drawing of objects that are blocked or not in the frustum is reduced, and the drawing efficiency is improved. It can also reduce the amount of data that needs to be transmitted during the drawing process, and reduce the consumption of memory bandwidth.
[0203] See also Fig.19 In the embodiment of the present application, after obtaining the first culling result and writing the first mark indicating visible in the storage position corresponding to each first virtual object in the second buffer based on the first culling result, and writing the second mark indicating blocked in the storage position corresponding to each first virtual object in the third buffer, the second buffer and the third buffer are modified based on the rasterization culling result of step S130, and the first virtual object corresponding to the storage position storing the first mark (e.g., 1) in the second buffer can be parameter assembled to obtain the indirect drawing parameters of each visible first virtual object, and the first target virtual object can be depth drawn in the initial depth map based on the indirect drawing parameters of the first target virtual object to obtain the depth map of the virtual scene at the time point t+1. And the virtual objects corresponding to the storage positions storing the first mark (e.g., 1) in the modified second buffer and the modified third buffer can be parameter assembled to obtain the scene indirect drawing parameters, and the scene can be drawn based on the scene indirect drawing parameters to obtain the scene image of the virtual scene at the time point t+1.
[0204] This solution can be used in game rendering to optimize the GPU-Driven rendering pipeline. For example, in a high-density vegetation scene in a game, there are hundreds of thousands of instances that need to be drawn simultaneously, and the GPU-Driven rendering pipeline is often used at this time. This solution can optimize the overall performance of the GPU-Driven pipeline by optimizing the efficiency and performance of culling at this time.
[0205] like Fig. 20 As shown, an image of a scene in a game is shown exemplarily, in which there are a large number of small plants (flowers, grass, etc.), wherein the virtual object C is Fig. 20 These objects occupy a small area in the scene, but if the conventional solution is used to obtain the first culling result based on the compute shader occlusion culling, since only the axis-aligned bounding box can be used for culling, and the axis-aligned bounding box is too large compared to the virtual object it encloses, this will cause a lot of objects that could have been culled to pass the culling test (that is, the virtual object is actually occluded, but is determined to be a visible object during the culling test because the bounding box is too large and visible).
[0206] After the present solution is enabled, during the secondary culling process, the rasterization process can be performed on a bounding box in any direction (ie, a directional bounding box). Fig.21 A diagram of a virtual object C can be rasterized to obtain a rasterized image of the virtual object C ( Fig.21 The rasterized image of the small plant is not specifically shown, but only indicated by an ellipse). Fig.21 FIG. B in FIG. 1 can also be used to rasterize the axis-aligned bounding box of the virtual object to obtain a rasterized image of the axis-aligned bounding box of the virtual object C, and to rasterize the directional bounding box of the virtual object to obtain a rasterized image of the directional bounding box of the virtual object C. It can be seen that since the directional bounding box is used to represent the boundary that can tightly surround the virtual object in space, and contains a small number of vertices, it is suitable for the culling test of this scheme, and the size of the directional bounding box is smaller than the axis-aligned bounding box, and the shape of the directional bounding box is more suitable for the virtual object, when the rasterization pipeline is called to rasterize the directional bounding box according to the bounding box information and the initial depth map of the directional bounding box of each virtual object, the visibility result of the directional bounding box can accurately reflect the visibility of the virtual object in the bounding box. This allows the virtual objects that are determined to be visible due to the use of the axis-aligned bounding box, but the virtual objects they enclose are actually occluded, to be culled, such as Fig. 22 As shown in the figure, a scene in the game is shown, the bounding box of the object is drawn, and its culling results are marked by color. Green is an object that is indicated as visible by both the first culling result and the rasterization result; red is an object that is indicated as invisible by both the first culling result and the rasterization result; blue is an object that is indicated as visible in the first culling result but is determined to be invisible after rasterization. This solution only enables GPU Driven rendering for vegetation in the project, so only trees, flowers, etc. are marked in the figure.
[0207] It can be seen that the solution of this application greatly reduces the number of objects and triangles required to be drawn compared to the conventional solution. For example, in a game scene, compared with the traditional culling solution based on compute shaders, the comparison results shown in Table 1 can be obtained:
[0208] Conventional solution This solution (based on rasterization culling) Visible objects 9443 6500(↓31%) Number of triangles 1.5M 1.2M(↓20%) Scene drawing GPU time (ms) 6.61 6.42
[0209] As can be seen from Table 1, compared with the conventional solution, the number of objects drawn by the GPU is reduced by 31%, the total number of drawn triangles is reduced by 20%, and the time consumption of scene drawing is also reduced.
[0210] The following is a description of an exemplary structure of an occlusion removal device provided in an embodiment of the present application implemented as a software module. In some embodiments, Figure 1As shown, the software modules stored in the occlusion culling device 155 of the memory may include: a culling test module 1551 , a first depth map drawing module 1552 , a rasterization processing module 1553 and a culling result updating module 1554 .
[0211] The culling test module 1551 is used to call the compute shader to perform a culling test on the virtual object in the virtual scene at time point t+1 according to the depth map of the virtual scene at time point t, and obtain a first culling result, wherein the first culling result indicates the first virtual object determined to be blocked and the second virtual object determined to be visible in the culling test; t is a positive integer; the first depth map drawing module 1552 is used to perform depth drawing on the second virtual object to obtain an initial depth map of the virtual scene at time point t+1; the rasterization processing module 1553 is used to call the rasterization pipeline according to The bounding box information and the initial depth map of the bounding box of each virtual object are used to rasterize the bounding box to obtain a rasterization result of the bounding box, and the rasterization result indicates the visibility result of the bounding box; a culling result update module 1554 is used to update the first culling result according to the visibility result to obtain a second culling result of the virtual scene at time point t+1, wherein in the second culling result, the visibility result indicates that the first virtual object enclosed by the visible bounding box is determined to be visible, and the visibility result indicates that the second virtual object enclosed by the invisible bounding box is determined to be obscured.
[0212] In one possible implementation, the rasterization processing module 1553 includes a geometry processing submodule, a rasterization submodule, and a visibility determination submodule. The geometry processing submodule is used to perform geometry processing on the vertices of the bounding box according to the bounding box information of the bounding box of each virtual object, and obtain the texture coordinates of the vertices of the bounding box and the depth values corresponding to the vertices on the bounding box; the rasterization submodule is used to perform rasterization according to the texture coordinates of the vertices of the bounding box and the corresponding depth values, and determine the multiple fragments corresponding to the bounding box; the fragments include pixel coordinates and fragment depth values; the visibility determination submodule is used to determine the visibility result of the bounding box according to the depth values of the pixels corresponding to the pixel coordinates in the multiple fragments corresponding to the bounding box in the initial depth map and the fragment depth values in the fragments.
[0213] In one possible implementation, the bounding box is a directional bounding box.
[0214] In one possible implementation, the visibility determination submodule is further used to determine, among the multiple fragments corresponding to the bounding box, the first fragment whose pixel coordinates in the initial depth map have a depth value that is not less than the corresponding fragment depth value; if the number of the first fragments exceeds a quantity threshold, determining that the visibility result of the bounding box indicates that the bounding box is visible; and if the number of the first fragments does not exceed the quantity threshold, determining that the visibility result of the bounding box indicates that the bounding box is invisible.
[0215] In one possible implementation, a pixel shader is deployed on the rasterization pipeline; during the rasterization process, the write switch of the initial depth map is in a closed state; the device also includes: a shading module, which is used to use the pixel shader to perform pixel shading on the pixel corresponding to the first fragment in the initial depth map.
[0216] In one possible implementation, the occlusion culling device 155 also includes a first writing module, which is used to write a visibility mark in a storage position corresponding to each virtual object in the first buffer based on the first culling result, and the visibility mark includes a first mark indicating visibility and a second mark indicating occluded; the culling result updating module 1554 is also used to modify the visibility mark of the first virtual object in the first buffer to the first mark when there is a visibility result of the bounding box indicating a visible first virtual object; and to modify the visibility mark of the second virtual object in the first buffer to the second mark when there is a visibility result of the bounding box indicating an occluded second virtual object; wherein the visibility mark stored in the first buffer after modification serves as the second culling result of the virtual scene at time point t+1.
[0217] In one possible implementation, a vertex shader and a pixel shader are deployed in the rasterization pipeline; the occlusion culling device 155 also includes a second writing module for writing object data of the virtual object into the vertex shader; the object data includes bounding box information of the bounding box of the virtual object and the object identifier of the virtual object; the culling result update module 1554 is also used for, when the pixel shader performs pixel shading for the first fragment in the first virtual object in the initial depth map, the pixel shader obtains the object identifier of the first virtual object from the vertex shader, and based on the object identifier of the first virtual object, modifies the visibility mark of the first virtual object in the first buffer to the first mark.
[0218] In one embodiment, the occlusion culling device 155 also includes a first parameter assembly module and a second depth map drawing module. The first parameter assembly module is used to perform indirect drawing parameter assembly for the first target virtual object based on the second culling result. The first target virtual object refers to the first virtual object surrounded by the visible bounding box indicated by the visibility result; the second depth map drawing module is used to perform depth drawing for the first target virtual object in the initial depth map based on the indirect drawing parameters of the first target virtual object, so as to obtain a depth map of the virtual scene at time point t+1.
[0219] In one possible implementation, the occlusion culling device 155 also includes a second parameter assembly module and a scene graph drawing module; the second parameter assembly module is used to assemble indirect drawing parameters for the visible virtual objects indicated in the second culling result to obtain scene indirect drawing parameters; the scene graph drawing module is used to perform scene drawing according to the scene indirect drawing parameters to obtain a scene image of the virtual scene at time point t+1.
[0220] In one possible implementation, the first elimination result also includes indirect drawing parameters of the second virtual object; the first depth map drawing module is further used to perform depth drawing according to the indirect drawing parameters of the second virtual object to obtain an initial depth map of the virtual scene at time point t+1.
[0221] In one possible implementation, the culling test module 1551 is also used to sample the depth map of the virtual scene at time point t step by step to obtain a layered map of the depth map of the virtual scene at time point t at multiple levels; project the vertices of the bounding box of each virtual object in the virtual scene at time point t+1 to the screen space to obtain the size of the pixels covered by the bounding box in the screen space; in the layered map at multiple levels, determine a target layered map with the smallest size difference between the size of a unit pixel and the size of the pixels covered by the bounding box in the screen space; determine the target pixels corresponding to the vertices of the bounding box in the target layered map; and determine a first culling test result based on the depth values of the vertices of the bounding box and the depth values of the target pixels corresponding to the vertices of the bounding box in the target layered map.
[0222] The embodiment of the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. A processor of an electronic device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device performs the occlusion culling method provided in the embodiment of the present application.
[0223] An embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the processor will execute the occlusion culling method provided by the embodiment of the present application.
[0224] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.
[0225] In some embodiments, a computer program may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0226] As an example, a computer program may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (for example, files storing one or more modules, subroutines, or code portions).
[0227] As an example, a computer program may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.
[0228] The above are only embodiments of the present application and are not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. An occlusion culling method, characterized in that: include: Calling a compute shader to perform a culling test on a virtual object in the virtual scene at time point t+1 according to the depth map of the virtual scene at time point t, and obtaining a first culling result, wherein the first culling result indicates a first virtual object determined to be obscured and a second virtual object determined to be visible in the culling test; t is a positive integer; Performing depth rendering on the second virtual object to obtain an initial depth map of the virtual scene at time point t+1; Calling a rasterization pipeline to perform rasterization processing on the bounding box of each virtual object according to the bounding box information of the bounding box and the initial depth map, and obtaining a rasterization result of the bounding box, wherein the rasterization result indicates a visibility result of the bounding box; According to the visibility result, the first culling result is updated to obtain a second culling result of the virtual scene at time point t+1, wherein in the second culling result, the visibility result indicates that the first virtual object enclosed by the visible bounding box is determined to be visible, and the visibility result indicates that the second virtual object enclosed by the invisible bounding box is determined to be occluded.
2. The method according to claim 1, characterized in that The calling of the rasterization pipeline performs rasterization processing on the bounding box according to the bounding box information of each virtual object and the initial depth map to obtain the rasterization result of the bounding box, including: The rasterization pipeline is called to perform the following steps for the bounding box of each virtual object: According to the bounding box information of the bounding box of each virtual object, the vertices of the bounding box are geometrically processed to obtain the texture coordinates of the vertices of the bounding box and the depth values corresponding to the vertices on the bounding box; Rasterizing is performed according to the texture coordinates of the vertices of the bounding box and the corresponding depth values, to determine a plurality of fragments corresponding to the bounding box; the fragments include pixel coordinates and fragment depth values; The visibility result of the bounding box is determined according to the depth values of pixels corresponding to the pixel coordinates in the plurality of fragments corresponding to the bounding box in the initial depth map and the fragment depth values in the fragments.
3. The method according to claim 2, characterized in that The bounding box is a directional bounding box.
4. The method according to claim 2, characterized in that: The determining the visibility result of the bounding box according to the depth values of the pixels corresponding to the pixel coordinates in the plurality of fragments corresponding to the bounding box in the initial depth map and the fragment depth values in the fragments comprises: If among the multiple fragments corresponding to the bounding box, determine the first fragment whose pixel coordinate has a depth value not less than the corresponding fragment depth value in the initial depth map; If the number of the first fragments exceeds a number threshold, determining the visibility result of the bounding box indicates that the bounding box is visible; If the number of the first fragments does not exceed the number threshold, determining the visibility of the bounding box indicates that the bounding box is not visible.
5. The method according to claim 4, characterized in that A pixel shader is deployed on the rasterization pipeline; in the rasterization process, the write switch of the initial depth map is in a closed state; If the number of the first fragments exceeds the number threshold, after determining that the visibility result of the bounding box indicates that the bounding box is visible, the method further includes: The pixel shader performs pixel shading on the pixel corresponding to the first fragment in the initial depth map.
6. The method according to claim 2, characterized in that Before calling the rasterization pipeline to perform rasterization processing on the bounding box according to the bounding box information of each virtual object and the initial depth map to obtain the rasterization result of the bounding box, the method further includes: Based on the first elimination result, writing a visibility mark in a storage location corresponding to each virtual object in the first buffer, the visibility mark including a first mark indicating visible and a second mark indicating blocked; The updating of the first culling result according to the visibility result to obtain a second culling result of the virtual scene at time point t+1 includes: If there is a first virtual object whose visibility result of the bounding box indicates that it is visible, modifying the visibility flag of the first virtual object in the first buffer to a first flag; If there is a second virtual object whose visibility result of the bounding box indicates being blocked, modifying the visibility flag of the second virtual object in the first buffer to a second flag; The visibility mark stored in the first buffer after modification is used as the second culling result of the virtual scene at the time point t+1.
7. The method according to claim 6, characterized in that Vertex shaders and pixel shaders are deployed in the rasterization pipeline; Before calling the rasterization pipeline to perform rasterization processing on the bounding box according to the bounding box information of each virtual object and the initial depth map to obtain the rasterization result of the bounding box, the method further includes: Writing object data of the virtual object into the vertex shader; the object data includes bounding box information of the bounding box of the virtual object and an object identifier of the virtual object; If the visibility result of the bounding box indicates that the first virtual object is visible, modifying the visibility mark of the first virtual object in the first buffer to the first mark includes: If the pixel shader performs pixel shading on the first fragment in the first virtual object in the initial depth map, the pixel shader obtains the object identifier of the first virtual object from the vertex shader, and based on the object identifier of the first virtual object, modifies the visibility flag of the first virtual object in the first buffer to a first flag.
8. The method according to any one of claims 1 to 7, characterized in that After the first elimination result is updated according to the visibility result to obtain a second elimination result of the virtual scene at time point t+1, the method further includes: Based on the second culling result, assembling indirect rendering parameters for a first target virtual object, where the first target virtual object refers to a first virtual object enclosed by a bounding box that is visible as indicated by the visibility result; Based on the indirect rendering parameters of the first target virtual object, depth rendering is performed for the first target virtual object in the initial depth map to obtain a depth map of the virtual scene at time point t+1.
9. The method according to any one of claims 1 to 7, characterized in that After the first elimination result is updated according to the visibility result to obtain a second elimination result of the virtual scene at time point t+1, the method further includes: Assembling indirect rendering parameters for the virtual objects indicated as visible in the second culling result to obtain scene indirect rendering parameters; The scene is rendered according to the scene indirect rendering parameters to obtain a scene image of the virtual scene at time point t+1.
10. The method according to any one of claims 1 to 7, characterized in that The first culling result also includes indirect drawing parameters of the second virtual object; The performing depth rendering on the second virtual object to obtain an initial depth map of the virtual scene at time point t+1 includes: Depth rendering is performed according to the indirect rendering parameters of the second virtual object to obtain an initial depth map of the virtual scene at time point t+1.
11. The method according to claim 1, characterized in that: The calling of the compute shader performs a culling test on the virtual objects in the virtual scene at time point t+1 according to the depth map of the virtual scene at time point t to obtain a first culling result, including: Calling a compute shader performs the following steps: Sampling the depth map of the virtual scene at time point t level by level to obtain a layered map of the depth map of the virtual scene at time point t at multiple levels; Projecting the vertices of the bounding box of each virtual object in the virtual scene at time point t+1 to the screen space to obtain the size of the pixels covered by the bounding box in the screen space; Determine, among the layer maps under the multiple layers, a target layer map having the smallest size difference between a size of a unit pixel and a size of pixels covered by the bounding box in the screen space; Determine the target pixels corresponding to the vertices of the bounding box in the target hierarchical map; The first culling test result is determined according to the depth values of the vertices of the bounding box and the depth values of the target pixels corresponding to the vertices of the bounding box in the target hierarchical map.
12. An occlusion culling device, characterized in that: include: A culling test module is used to call a computing shader to perform a culling test on a virtual object in the virtual scene at time point t+1 according to a depth map of the virtual scene at time point t, and obtain a first culling result, wherein the first culling result indicates a first virtual object determined to be obscured and a second virtual object determined to be visible in the culling test; t is a positive integer; A first depth map drawing module, used for performing depth drawing on the second virtual object to obtain an initial depth map of the virtual scene at time point t+1; A rasterization processing module, used for calling a rasterization pipeline to perform rasterization processing on the bounding box of each virtual object according to the bounding box information of the bounding box and the initial depth map, so as to obtain a rasterization result of the bounding box, wherein the rasterization result indicates a visibility result of the bounding box; A culling result updating module is used to update the first culling result according to the visibility result to obtain a second culling result of the virtual scene at time point t+1, wherein in the second culling result, the first virtual object enclosed by the visible bounding box indicated by the visibility result is determined to be visible, and the second virtual object enclosed by the invisible bounding box indicated by the visibility result is determined to be occluded.
13. An electronic device, characterized in that: include: one or more processors; Memory; One or more computer programs, wherein the one or more computer programs are stored in the memory and configured to be executed by the one or more processors, the one or more computer programs being configured to execute the method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program can be called by a processor to execute the method according to any one of claims 1 to 11.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 11 are implemented.