Rendering method and apparatus, electronic device, computer-readable storage medium, and computer program product
By determining the virtual visible light source and its screen-to-body ratio in a virtual scene, and combining batch rendering and chunked rendering techniques, the problem of low rendering frame rate in massive light source scenes is solved, and efficient light source rendering is achieved.
Patent Information
- Application Number
- PCT/CN2024/103126
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-09-06
- Filing Date
- 2024-07-02
- Publication Date
- 2025-03-13
AI Technical Summary
In multi-light light rendering, prior art such as Tiled based lighting and cluster based lighting algorithms require frequent update of the light source list of each screen chunk, resulting in a significant decrease in rendering frame rate, especially in massive light source scenarios.
By determining multiple virtual visible light sources and their screen-to-body ratios in the virtual scene, combined batch rendering is used to render light sources whose screen-to-body ratio is less than the threshold, and full-screen drawing is performed based on the light source list of each screen chunk, and the rendering results are merged to display the virtual scene.
This method can quickly render massive light sources in virtual scenes by reducing the calculation amount of block rendering and improving the efficiency of batch rendering, thereby significantly improving rendering efficiency.
Smart Images

Figure CN2024103126_13032025_PF_FP_ABST
Abstract
Description
Rendering method, device, electronic device, computer-readable storage medium, and computer program product CROSS-REFERENCE TO RELATED APPLICATIONS This application is based on the Chinese patent application with application number 202311141331.2 and application date September 6, 2023, and claims the priority of the above Chinese patent application. The entire content of the above Chinese patent application is hereby introduced into this application as a reference. Technical Field The present application relates to image processing technology, and in particular to a rendering method, device, electronic device, computer-readable storage medium, and computer program product. Background Art With the continuous development of image processing technology, users have higher and higher requirements for image quality. In many large virtual scenes, there are a large number of light sources, and each light source has a different degree of influence on each virtual model in the large virtual scene. Therefore, in order to improve the realism of the virtual scene, multi-light source lighting rendering has become a key point in image processing. In the related art, when performing illumination rendering with multiple light sources, tiled based lighting algorithms and cluster based lighting algorithms are usually used. Both the tiled based lighting algorithm and the cluster based lighting algorithm require dividing the screen into multiple blocks, and each screen block maintains a light source list. Updating the light source list of each screen block in a scene with a large number of light sources is a very time-consuming task, which will cause a significant drop in the rendering frame rate. Summary of the invention Embodiments of the present application provide a rendering method, device, electronic device, computer-readable storage medium, and computer program product, which can improve rendering efficiency. The technical solution of the embodiment of the present application is implemented as follows: The present application provides a rendering method, which is applied to an electronic device, and the method includes: Acquire virtual scene data to be rendered, determine multiple virtual visible light sources in the virtual scene based on the virtual scene data, and determine the screen ratio of each virtual visible light source; Performing batch rendering on a first virtual visible light source among the multiple virtual visible light sources to obtain a first rendering result, wherein a screen-to-body ratio of the first virtual visible light source is less than a preset screen-to-body ratio threshold; Determine a light source list for each screen block, wherein the light source list includes a second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold; Perform full-screen rendering based on the light source list of each screen block to obtain a second rendering result; The first drawing result and the second drawing result are combined to obtain a drawn virtual scene, and the virtual scene is displayed. The present application provides a rendering device, including: The first determining module is configured to obtain virtual scene data to be rendered, and determine based on the virtual scene data Multiple virtual visible light sources in a virtual scene, and determining a screen ratio of each virtual visible light source; A first rendering module is configured to perform batch rendering on a first virtual visible light source among the multiple virtual visible light sources to obtain a first rendering result, wherein a screen-to-body ratio of the first virtual visible light source is less than a preset screen-to-body ratio threshold; A second determining module is configured to determine a light source list for each screen segment, wherein the light source list includes a second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold; A second rendering module is configured to perform full-screen rendering based on the light source list of each screen block to obtain a second rendering result; The display module is configured to merge the first drawing result and the second drawing result to obtain a drawn virtual scene, and display the virtual scene. An embodiment of the present application provides an electronic device, the electronic device comprising: A memory for storing computer executable instructions; The processor is used to implement the rendering method provided in the embodiment of the present application when executing the computer executable instructions stored in the memory. An embodiment of the present application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing the rendering method provided in the embodiment of the present application when executed by a processor. An embodiment of the present application provides a computer program product, including a computer program or a computer executable instruction. When the computer program or the computer executable instruction is executed by a processor, the rendering method provided in the embodiment of the present application is implemented. The embodiments of the present application have the following beneficial effects: After obtaining the virtual scene data to be rendered, first, based on the virtual scene data, multiple virtual visible light sources in the virtual scene are determined, so as to ensure that only the visible light sources are rendered subsequently, which can reduce the amount and complexity of rendering processing data; and determine the screen-to-body ratio of each virtual visible light source, and then, for a first virtual visible light source whose screen-to-body ratio is less than a preset screen-to-body ratio threshold, batch rendering is performed on multiple first virtual visible light sources by calling a batch rendering and drawing command; for a second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold, a light source list for each screen block is determined, and the light source list only includes the second virtual visible light source, and then based on each screen block, a batch rendering and drawing command is called. That is to say, in an embodiment of the present application, a scheme combining batch drawing and block rendering is adopted. First, a batch drawing command is called once to complete the drawing of a large number of light sources whose screen-to-body ratio is less than the screen-to-body ratio threshold. While improving the rendering efficiency, it also greatly reduces the amount of calculation for block rendering. Then, block rendering is performed on the second virtual visible light source whose screen-to-body ratio is greater than the screen-to-body ratio threshold. That is, the second virtual visible light source in multiple screen blocks is rendered in parallel, which not only ensures the rendering effect of the second virtual visible light source, but also can quickly render a large number of light sources in the virtual scene, thereby improving the rendering efficiency. BRIEF DESCRIPTION OF THE DRAWINGS FIG1 is a schematic diagram of a network architecture of a rendering system 100 provided in an embodiment of the present application; FIG2 is a schematic diagram of the structure of a terminal 400 provided in an embodiment of the present application; FIG3A is a schematic diagram of an implementation flow of a rendering method provided in an embodiment of the present application; 3B is a schematic diagram of an implementation flow of determining a virtual visible light source and a screen ratio of the virtual visible light source provided in an embodiment of the present application; FIG4A is a schematic diagram of an implementation process of batch rendering and drawing of a first virtual visible light source provided by an embodiment of the present application; FIG4B is a schematic diagram of an implementation flow of determining a light source list for each screen block provided in an embodiment of the present application; FIG4C is a schematic diagram of a light source node in a light source list provided in an embodiment of the present application; FIG5 is a schematic diagram of an implementation process of performing full-screen rendering based on a light source list provided in an embodiment of the present application; FIG6A is a schematic diagram of an implementation flow of compressing and storing a light source list provided in an embodiment of the present application; FIG6B is another schematic diagram of compressing and storing a light source list provided by an embodiment of the present application; FIG7A is a lighting effect diagram of a city night scene from above an airplane provided in an embodiment of the present application; FIG7B is a dynamic light and shadow effect diagram of a vehicle traveling on a road provided by an embodiment of the present application; FIG7C is a night scene lighting effect diagram of the Digital Great Wall provided in an embodiment of the present application; FIG8 is a schematic diagram of another implementation flow of the rendering method provided in an embodiment of the present application; FIG9 is a schematic diagram showing the effects of performing long-distance light source rendering and short-distance light source rendering using the rendering method provided in an embodiment of the present application; FIG. 10 is a diagram showing the comparison between the rendering method provided in an embodiment of the present application and the cluster based lighting algorithm in the related art. DETAILED DESCRIPTION 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. In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be 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, 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. 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 fully or partially implemented 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. Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application. Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations. 1) Point light source refers to a light source that emits light uniformly from a point to the surrounding space. 2) Parallel light source refers to a light source that emits parallel and non-divergent light. 3) Spotlight is a central light source in the shape of a cone. The farther away from the light source, the larger the illuminated circular area will be. 4) Batch rendering generally refers to a method of combining multiple rendering tasks together. In the embodiment of the present application, batch rendering of multiple virtual light sources is to merge multiple virtual light sources together for rendering to improve rendering efficiency. 5) Full-screen drawing refers to drawing all screen blocks in the entire screen at once. 6) Frustum culling is a spatial culling technique that determines whether an object is visible based on the camera frustum. The frustum is a geometric representation of the camera's field of view, consisting of six planes that determine the area of space that the camera can see. When rendering each frame, the system checks whether all objects are completely within the camera's frustum or intersect with it. If the object is not within the frustum, it is culled. Frustum culling cannot cull objects that are within the frustum but are blocked by other objects. 7) Occlusion culling is a more advanced spatial culling technique that determines whether to render an object by detecting whether it is occluded by other objects. Specifically, occlusion culling pre-calculates the occlusion relationship of objects in the scene and builds a data structure to indicate which objects are visible from the current camera perspective, and culls invisible objects. 8) Light source attenuation coefficient is a parameter that describes the decrease in light source intensity as distance increases. It reflects the characteristic that light intensity gradually decreases as distance increases during propagation. The attenuation coefficient is usually used to calculate the light intensity of the light source at different distances, so as to consider the attenuation effect of the light source when designing a lighting system or performing lighting simulation. In order to better understand the rendering method provided in the embodiments of the present application, the Tiled based lighting algorithm and the cluster based lighting algorithm used for multi-light source rendering in the related art and their existing shortcomings are first explained. When implementing the Tiled based lighting algorithm, the screen space is first divided into 2D blocks in real time, and then the list of light sources affecting each block is calculated separately. Finally, each pixel is given a list of light sources according to the block to which it belongs for lighting rendering. When implementing the cluster based lighting algorithm, the screen space is first divided into 3D blocks in real time, and then the list of light sources affecting each block is calculated separately. Finally, each pixel is given a list of light sources according to the block to which it belongs for lighting rendering. Tiled based lighting algorithm and cluster based lighting algorithm only read G-buffer once and write color buffer once in the lighting rendering process, which is independent of the number of light sources. It can greatly reduce bandwidth consumption and increase the number of light sources on the same screen to several thousand. However, updating the light source list of each block in a scene with a large number of light sources is also a very time-consuming task. When the number of light sources in the scene reaches tens of thousands or even hundreds of thousands, the frame rate will drop significantly. The embodiments of the present application provide a rendering method, device, electronic device, computer-readable storage medium and computer program product, which can improve rendering efficiency. The following describes an exemplary application of the electronic device provided by the embodiments of the present application. The electronic device provided by the embodiments of the present application can be implemented as various types of user terminals such as laptop computers, tablet computers, desktop computers, set-top boxes, mobile devices (e.g., mobile phones, portable music players, personal digital assistants, dedicated messaging devices, portable gaming devices), smart phones, smart speakers, smart watches, smart TVs, and vehicle-mounted terminals. Below, an exemplary application when the device is implemented as a terminal will be described. Referring to FIG. 1 , FIG. 1 is a schematic diagram of a network architecture of a rendering system 100 provided in an embodiment of the present application. As shown in FIG. 1 , the rendering system 100 includes a server 200, a network 300, and a terminal 400. The terminal 400 is connected to the server 200 via the network 300. The network 300 may be a wide area network or a local area network, or a combination of the two. The terminal 400 is used to obtain virtual scene data from the server 200, wherein the virtual scene data may be virtual scene data in a game application, or virtual scene data of virtual reality or virtual scene data of augmented reality. The terminal 400 stores the virtual scene data in a local storage space, and then the terminal 400 determines multiple virtual visible light sources in the virtual scene based on the virtual scene data, and determines the screen ratio of each virtual visible light source, and then for the first virtual visible light source whose screen ratio is less than the preset screen ratio threshold, the multiple first virtual visible light sources are batch-rendered by calling the batch rendering command to obtain a first drawing result; for the second virtual visible light source whose screen ratio is greater than or equal to the screen ratio threshold, the light source list of each screen block is determined, and only the second virtual visible light source is included in the light source list, and then full-screen drawing is performed based on the light source list of each screen block to obtain a second drawing result, and the first drawing result and the second drawing result are merged to obtain a rendered virtual scene, and the rendered virtual scene is displayed on the graphical interface 410. When rendering a virtual scene, the terminal adopts a solution that combines batch drawing and block rendering. By calling a batch drawing command once, it completes the drawing of a large number of light sources whose screen-to-body ratio is less than the screen-to-body ratio threshold. This greatly reduces the amount of calculation for block rendering, making it possible to quickly render a large number of light sources in the virtual scene and improve rendering efficiency. In some embodiments, server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms. The terminal 400 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a vehicle-mounted terminal, etc., but is not limited thereto. The terminal and the server may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application. Referring to FIG. 2 , FIG. 2 is a schematic diagram of the structure of a terminal 400 provided in an embodiment of the present application. The terminal 400 shown in FIG. 2 includes: at least one processor 410, a memory 450, at least one network interface 420, and a user interface 430. The various components in the terminal 400 are coupled together via a bus system 440. It is understandable that the bus system 440 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, various buses are labeled as bus system 440 in FIG. 2 . The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc. The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls. The memory 450 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 450 may optionally include one or more storage devices that are physically remote from the processor 410. The memory 450 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 450 described in the embodiments of the present application is intended to include any suitable type of memory. In some embodiments, memory 450 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. Operating system 451, 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; A network communication module 452, used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.; a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., display screen, speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripherals and displaying content and information); The input processing module 454 is used to detect one or more user inputs or interactions from one of the one or more input devices 432 and translate the detected inputs or interactions. In some embodiments, the device provided in the embodiments of the present application can be implemented in software. FIG. 2 shows a rendering device 455 stored in a memory 450, which can be software in the form of a program and a plug-in, including the following software modules: a first determination module 4551, a first rendering module 4552, a second determination module 4553, a second rendering module 4554, and a display module 4555. 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. In other embodiments, the apparatus provided in the embodiments of the present application may be implemented in hardware. For example, the apparatus provided in the embodiments of the present application may be a processor in the form of a hardware decoding processor, which is programmed to execute the rendering method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor may be one or more application specific integrated circuits (ASIC), digital signal processors, or the like. (Digital Signal Processor, DSP), Programmable Logic Device (Programmable Logic Device, PLD), Complex Programmable Logic Device (Complex Programmable Logic Device, CPLD), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other electronic components. The rendering method provided in the embodiment of the present application will be described in conjunction with the exemplary application and implementation of the terminal provided in the embodiment of the present application. The following describes the rendering method provided by the embodiment of the present application. As mentioned above, the electronic device that implements the rendering method of the embodiment of the present application may be a terminal. Therefore, the execution subject of each step will not be repeatedly described below. Referring to FIG. 3A , FIG. 3A is a schematic diagram of an implementation flow of a rendering method provided in an embodiment of the present application, which will be described in conjunction with the steps shown in FIG. 3A , and the main body of the steps in FIG. 3A is a terminal. In step 101, virtual scene data to be rendered is obtained, and based on the virtual scene data, a plurality of virtual visible light sources in the virtual scene are determined, and the screen ratio of each virtual visible light source is determined. In some embodiments, the virtual scene data to be rendered may be virtual scene data in a game application, or virtual scene data of virtual reality or virtual scene data of augmented reality. Referring to FIG3B , step 101 may be implemented by the following steps 1011 to 1016 , which are described below in conjunction with FIG3B . In step 1011 , a plurality of virtual light sources existing in the virtual scene are determined based on the virtual scene data. In some embodiments, the virtual scene data includes object identifiers of each virtual object in the virtual scene, and location information of each virtual object. The virtual objects in the virtual scene include fixed and immovable objects, such as virtual buildings, virtual trees, etc., and may also include movable objects, such as virtual monsters, virtual vehicles, etc. The virtual object may also be a virtual light source, such as a fixed virtual street lamp, various virtual lamps in a virtual building, a headlamp or a flashlight worn on a virtual character, or a headlight of a virtual car. The object identifier of the virtual object can indicate the type and number of the virtual object. For example, when the virtual object is a virtual building, the object identifier of the virtual object may be building_1, building_2, etc., when the virtual object is a virtual tree, the object identifier may be tree_1, tree_2, and when the virtual object is a virtual light source, the object identifier may be light_1, light_2, etc. When step 1011 is implemented, the type of the virtual object may be determined from the virtual scene data based on the object identifier of the virtual object, and then based on the type of the virtual object, multiple virtual light sources existing in the virtual scene may be determined. In the embodiment of the present application, the virtual scene may include a large number of different types of virtual light sources, for example, point light sources, central light sources (spotlights), surface light sources, and the like. In step 1012, frustum culling and occlusion culling are performed on the multiple virtual light sources to obtain multiple virtual visible light sources in the virtual scene. Since the visible range of the camera in the three-dimensional scene is presented as a cone, which is similar to a prism, when an object in the three-dimensional space is within the six faces of the cone or intersects with any of the six faces of the cone, it means that the object is visible. On the contrary, when the object in the three-dimensional space is not within the six faces of the cone or does not intersect with any of the six faces of the cone, the object is invisible. The more times the computer renders the three-dimensional scene per second, the more coherent the rendered virtual scene will be. Therefore, reducing the amount of data drawn per frame is the key to accelerating the rendering of three-dimensional scenes in computer graphics. Therefore, it is necessary to perform cone culling and occlusion culling on multiple virtual light sources in the virtual scene. When performing frustum culling on multiple virtual light sources, the bounding volume of each virtual light source can be determined first, which can be a bounding sphere, an axis-aligned bounding box (AABB), or an oriented bounding box (OBB), and then it is determined whether the bounding volume of each virtual light source is inside the frustum or intersects with any side of the frustum. If the bounding volume of the virtual light source is inside the frustum or intersects with any side of the frustum, then it is determined that the virtual light source is within the visible range of the frustum and the virtual light source is not culled; if the bounding volume of the virtual light source is not inside the frustum and does not intersect with any side of the frustum, then it is determined that the virtual light source is not within the visible range of the frustum and the virtual light source is culled. Frustum culling simply means not rendering virtual light sources outside the camera's field of view. Virtual light sources that are blocked by other objects but are still within the field of view will not be culled. Obviously, virtual light sources blocked by other objects do not need to be rendered. Therefore, after performing frustum culling on multiple virtual light sources, occlusion culling can also be used to cull virtual light sources blocked by other objects, thereby further reducing the amount of rendering processing. When performing occlusion culling, software rasterization can be used to draw the entire depth map of the virtual scene to obtain the depth of each virtual object in the virtual scene, and then the depth size relationship between different virtual objects is used to determine the occlusion relationship between different virtual objects, thereby culling the occluded virtual light sources. In step 1013, the center coordinates and the radius of the enclosing sphere of the virtual visible light source in the camera space are obtained. In some embodiments, the vertex coordinates of the vertices of all elements in the set of basic geometric elements constituting the virtual visible light source in the camera space are first obtained. The various virtual objects constituting the virtual scene can be processed by triangulation to obtain multiple triangular facets. Therefore, the basic geometric elements constituting the virtual objects can be understood as triangular facets. Therefore, here, the vertex coordinates of the vertices of each three-sided facet that constitutes the virtual visible light source in the camera space are obtained; then the center coordinates of the enclosing sphere of the virtual visible light source are determined by the mean of the vertex coordinates of all elements in the camera space, wherein the enclosing sphere of the virtual visible light source is also the minimum sphere that can contain the virtual visible light source, and then based on the center coordinates of the enclosing sphere and the vertex coordinates of the vertices of each element, the distance from the center of the enclosing sphere to each vertex is determined, and the maximum distance is determined as the radius of the enclosing sphere. In some embodiments, when determining the vertex coordinates of all elements in the camera space, first obtain the absolute position coordinates of all original vertices in the set of basic geometric elements that constitute the virtual visible light source in the world space. The world space, also known as the world coordinate system, refers to the absolute coordinate system of the three-dimensional scene, and the positions of elements such as the camera are determined by this coordinate system; the camera space, also known as the camera coordinate system, refers to a camera coordinate system independent of the world coordinate system, which is formed by taking the camera position and the opposite direction of the line of sight as the positive direction of the Z axis and the axis in which the camera is pointing upward as the positive direction of the Y axis. Then, the rotation matrix from the world space to the camera space, the translation matrix, and the absolute position coordinates of each vertex are used to determine the vertex coordinates of each vertex in the camera space. In step 1014, a projection matrix from the camera space to the screen space is obtained, and a scaling factor is determined based on the projection matrix. The conversion from the camera coordinate system to the pixel coordinate system is a projection transformation. The projection matrix from the camera space to the pixel space (that is, the screen space) is determined based on the internal and external parameters of the camera. The internal parameters of the camera refer to the parameters related to the camera's own characteristics, such as the camera's field of view, focal length, pixel size, and the aspect ratio of the camera screen; the external parameters of the camera are the posture parameters of the camera in the world coordinate system, such as the camera's position, rotation direction, etc. Further, the projection matrix can be obtained by multiplying the camera's internal parameter matrix and external parameter matrix. In some embodiments, a preset projection matrix calculation function can also be used to determine the projection matrix. The scaling factor is the scaling factor of the size of the virtual visible light source in the camera space and the size in the screen space. When implementing the scaling factor determination based on the projection matrix, the proj_m in the first row and first column of the projection matrix can be first obtained.
[0000] element, and proj_m in the second row and second column
[0011] Elements, where proj_m
[0000] element represents the aspect ratio of the camera screen divided by The tangent value of proj_m
[0011] represents The reciprocal of the tangent value of , and the product of the maximum value of the two and a preset first weight value is determined as the scaling factor, and the first weight value is a rational number between 0 and 1, for example, it can be 0.5. It should be noted that the maximum value between the two is selected because the zoom factor determined by the maximum value is more conservative and more accurate than the zoom factor determined by the minimum value between the two. In step 1015, first size information of the virtual visible light source in the camera space is determined using the zoom factor, the radius of the bounding sphere, and the coordinates of the sphere center. In some embodiments, the product of the zoom factor and the radius of the enclosing sphere is first determined as the zoom radius, and then the distance between the center of the enclosing sphere and the origin is determined according to the coordinates of the center of the enclosing sphere. If the distance is greater than 1, the enclosing sphere is zoomed. The reciprocal of the distance is determined as the second weight value. If the distance is less than or equal to 1, the second weight value is determined to be 1, and the product of the second weight value and the scaling radius is determined as the first size information of the virtual visible light source in the camera space. The first size information may be the radius of the virtual visible light source. Exemplarily, the distance between the center of the enclosing sphere and the origin is 2, and the scaling radius is 3. Then, the second weight value is 0.5, and the first size information of the virtual visible light source in the camera space is 0.5*3, that is, 1.5. In step 1016, second size information of the screen presenting the virtual scene is obtained, and the screen ratio of the virtual visible light source is determined based on the first size information and the second size information. In some embodiments, the second size information of the screen may include the screen length and the screen width, and the product of the screen length and the screen width may be determined as the screen area. The first size information of the virtual visible light source in the camera space may be the radius of the virtual visible light source, so that the area of the virtual visible light source may be determined based on the area formula of a circle, and the area of the virtual visible light source may be divided by the screen area to obtain the screen ratio of the virtual visible light source. The screen ratio of the virtual visible light source is the ratio of the area of the virtual visible light source to the screen area, and the screen ratio of the virtual visible light source is a real number between 0 and 1. Exemplarily, the screen ratio of the virtual visible light source may be 0.02. Through the above steps 1011 to 1016, firstly, the virtual visible light source in the virtual scene is obtained through frustum culling and occlusion culling. In this way, the number of light source renderings can be reduced and the rendering efficiency can be improved under the premise of ensuring the authenticity of the rendered virtual scene. Then, the screen ratio of each virtual visible light source is determined, thereby providing the necessary data basis for rendering light sources with different screen ratios according to different rendering methods. Continuing to refer to FIG. 3A , the following description proceeds to step 101 . In step 102, batch rendering is performed on a first virtual visible light source among a plurality of virtual visible light sources to obtain a first rendering result. Among them, the screen-to-body ratio of the first virtual visible light source is less than a preset screen-to-body ratio threshold, and the screen-to-body ratio threshold is a real number between 0 and 1. Exemplarily, the screen-to-body ratio threshold may be 0.05. The first virtual visible light source whose screen-to-body ratio is less than the preset screen-to-body ratio threshold may be understood as a virtual light source with a smaller area in the distance. Batch rendering and drawing of the first virtual visible light source whose screen-to-body ratio is less than the screen-to-body ratio threshold is performed, that is, multiple first virtual visible light sources are merged together for rendering, which can reduce the number of renderings and rendering time, thereby improving rendering efficiency. In some embodiments, referring to FIG. 4A , step 102 may be implemented by the following steps 1021 to 1024, which are explained below in conjunction with FIG. 4A . In step 1021, first position information of a first virtual visible light source in the camera space, and a light source attenuation coefficient, a light source intensity, and an illumination angle of the first virtual visible light source are obtained. In some embodiments, the first position information of the first virtual visible light source in the camera space is obtained by rigidly transforming the first absolute position of the first virtual visible light source in the world space. The light source attenuation coefficient, light source intensity and illumination angle of the first virtual visible light source are obtained from a pre-set light source information table based on the light source ID after the light source ID of the first virtual visible light source is obtained from the virtual scene data. In the light source information table, information such as the light source type, light source attenuation coefficient, light source intensity, illumination angle, color value, etc. corresponding to each light source ID is stored. In step 1022, based on the first position information, the light source attenuation coefficient, and the light source intensity, the illumination coverage of the first virtual visible light source is determined. Since the light intensity decays as the distance from the light source increases, the light intensity becomes weaker as the distance from the light source increases. In some embodiments, when the light intensity at a position decays to 0, it means that the position is not within the coverage of the light source. When determining the light coverage range of the first virtual visible light source, first obtain the attenuation formula corresponding to the first virtual visible light source, and then use the attenuation formula to determine the distance between the position where the light intensity decays to 0 or the light intensity decays to a preset attenuation value (a numerical value close to 0) and the first virtual visible light source, and determine the light coverage range of the first virtual visible light source based on the calculated distance, the light source type of the first virtual visible light source, and the first position information. When determining the light coverage range of the first virtual visible light source based on the calculated distance, the light source type of the first virtual visible light source, and the first position information, if the light source type of the first virtual visible light source is a point light source, then the light coverage range of the first virtual visible light source is a circle centered on the first position information of the first virtual visible light source and centered on the distance. a circle with a distance as a radius; if the light source type of the first virtual visible light source is a spotlight, then the illumination angle of the first virtual visible light source also needs to be obtained. The illumination coverage of the first virtual visible light source is a sector with the first position information of the first virtual visible light source as the center and the distance as the radius. The position of the sector is determined by the illumination angle. Exemplarily, assuming that the light source type of the first virtual visible light source is a point light source, formula (1) is the attenuation formula corresponding to the first virtual visible light source: I′=I*e -μd (1); Among them, I is the intensity of the light source, μ is the attenuation coefficient of the light source, and d is the distance between the first virtual visible light source. The attenuation formula can be used to determine the distance between the position where the light source intensity attenuates to a preset attenuation value and the first virtual visible light source, and then the circular area with the first position information of the first virtual visible light source as the center and the distance as the radius is determined as the illumination coverage range of the first virtual visible light source. In step 1023, the light source color value of each pixel point of the first virtual visible light source within the illumination coverage range is determined. In some embodiments, the distance between the first virtual visible light source and each pixel point within the illumination coverage range is first determined, and then the illumination intensity value of each pixel point is determined using the attenuation formula corresponding to the first virtual visible light source (i.e., formula (1)), and the color value of the first virtual visible light source is obtained. The color value of the first virtual visible light source is multiplied by the illumination intensity value of each pixel point to obtain the light source color value of the first virtual visible light source at each pixel point. In step 1024, when the pixel point is located within the illumination coverage of at least two first virtual visible light sources, a first target color value of the pixel point is determined based on the light source color values of the at least two first virtual visible light sources at the pixel point. In some embodiments, when a pixel point is located within the illumination coverage range of at least two first virtual visible light sources, it indicates that at least two first virtual visible light sources affect the color of the pixel point. Therefore, the initial pixel value of the pixel point and the light source color values of the pixel point at least two first virtual visible light sources that affect the pixel point are accumulated to obtain the first target color value of the pixel point. For the first virtual visible light source whose screen-to-body ratio is less than the screen-to-body ratio threshold, the GPU Driven method can be used to package the drawing commands of the light source, call the DrawIndirect command, and perform batch drawing through the above steps 1021 to 1024. In this way, all the first virtual visible light sources with small areas can be drawn by calling the GPU Driven command once, which can reduce the amount of light source data for light source rendering using the light source list, thereby improving rendering efficiency. Continuing to refer to FIG. 3A , the following description proceeds to step 102 . In step 103, a light source list for each screen segment is determined. Among them, the light source list only includes the second virtual visible light sources whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold. In some embodiments, since there are a large number of real-time discrete point light sources or spotlights in the virtual scene, these light sources only affect a small area. When performing rendering, it is not necessary to consider all the light sources in the scene, only some of the light sources need to be considered, because an object is only affected by a part of the light sources. Based on this, the screen can be divided into multiple screen blocks according to a preset size, and a list of light sources for each screen block can be determined. Included in the light source list are light sources that will affect the screen block. For example, the screen can be divided into multiple screen blocks of size 16*16, and the screen can also be divided into 32*32 screen blocks. The size of the screen block can be adjusted according to actual needs. If the light source has a large impact range, a larger screen block can be divided. If the light source has a small impact range, a smaller screen block can be divided. In an embodiment of the present application, since the second virtual visible light source is a virtual visible light source whose screen ratio is greater than a preset screen ratio threshold, a larger screen block can be used, for example, a 32*32 screen block. In some embodiments, referring to FIG. 4B , step 103 may be implemented through the following steps 1031 to 1036 , which are described below in conjunction with FIG. 4B . In step 1031 , second position information of a second virtual visible light source in the camera space is determined. In some embodiments, firstly, a second absolute position of the second virtual visible light source in the world space is obtained, and then The second absolute position is rigidly transformed using a rotation matrix and a translation matrix from the world space to the camera space to obtain second position information of the second virtual visible light source in the camera space. In step 1032, the distance between the second virtual visible light source and the block bounding box of the screen block is determined, and if the distance is smaller than the light source radius of the second virtual visible light source, the light source type of the second virtual visible light source is obtained. In some embodiments, the screen segment is a plurality of segments into which a two-dimensional screen is divided according to a preset size, and the segment bounding box of the screen segment is a three-dimensional structure constructed according to a preset depth and the vertex coordinates of the four vertices of the screen segment. The distance between the second virtual visible light source and the segment bounding box of the screen segment can be determined by determining the center coordinates of the segment bounding box after determining the screen segment bounding box, and then determining the distance between the second virtual visible light source and the segment bounding box of the screen segment based on the second position information of the second virtual visible light source and the center coordinates of the segment bounding box. If the distance is less than the light source radius of the second virtual visible light source, it means that the second virtual visible light source may have an impact on the screen segment, and the light source type of the second virtual visible light source is obtained at this time. The light source type of the second virtual visible light source can be a point light source type, a spotlight type, etc. If the distance is greater than or equal to the light source radius of the second virtual visible light source, it means that the second virtual visible light source will not have an impact on the screen segment, and therefore the second virtual visible light source will not be added to the light source list corresponding to the screen segment, then continue to determine whether other second virtual visible light sources are to be added to the light source list corresponding to the screen segment, In step 1033, it is determined whether the light source type is a point light source type. If the light source type is a point light source type, go to step 1034 ; if the light source type is not a point light source type, go to step 1035 . In step 1034 , the second virtual visible light source is added to the light source list of the screen segment. In some embodiments, if the light source type of the second virtual visible light source is a point light source type, since the point light source is a light source that emits light uniformly from a point to the surrounding space, when the distance between the second virtual visible light source and the block bounding box of the screen block is less than the light source radius of the second virtual visible light source, it means that the second virtual visible light source will affect the screen block, and then the second virtual visible light source is added to the light source list of the screen block. In some embodiments, the light source list includes at least one light source node, and each light source node stores a current light source identifier and a previous light source identifier; because each screen block in the GPU traverses the second virtual visible light source in parallel to determine whether the second virtual visible light source is within the screen block, each light source node requires a link information (Link), which is used to represent the previous light source identifier of the current light source in the screen block. When the second virtual visible light source is the first light source node in the light source list, the light source identifier of the second virtual visible light source is added to the current light source identifier corresponding to the first light source node; and it is determined that the previous light source identifier of the first light source node is empty; when the second virtual visible light source is the Nth light source node in the light source list, the light source identifier of the second virtual visible light source is added to the current light source identifier corresponding to the Nth light source node; the current light source identifier corresponding to the N-1th light source node is added to the previous light source identifier corresponding to the Nth light source node, and N is an integer greater than 1. As shown in Figure 4C, light source 1 is the first light source in screen block 1, so the link information of light source 1 (that is, the previous light source identifier) is empty, light source 4 is the second light source in screen block 1, so the link information of light source 4 is the previous light source identifier, that is, 1, light source 5 is the third light source in screen block 1, so the link information of light source 5 is the previous light source identifier, that is, 4; similarly, light source 2 is the first light source in screen block 2, so the link information of light source 2 is empty, light source 3 is the second light source in screen block 2, so the link information of light source 3 is the previous light source identifier, that is, 2. In step 1035, if the light source type is a spotlight type, the light source direction and cone angle of the second virtual visible light source are obtained. In some embodiments, if the second light source is a spotlight type, since the spotlight type light source is different from a point light source that emits light uniformly to the surrounding space, the illumination range of the spotlight type light source is related to the light source direction and the cone angle. Therefore, it is necessary to obtain the light source direction and cone angle of the second virtual visible light source. When the light source type is a spotlight type, the light source direction and cone angle can be obtained from the attribute information of the second virtual visible light source. The light source direction and cone angle are set when the second virtual visible light source is created. The light source direction is used to characterize the direction of light irradiation, and the cone angle is used to control the degree of light beam diffusion. The larger the cone angle, the higher the degree of light beam diffusion. In step 1036 , when it is determined based on the light source direction and cone angle of the second virtual visible light source that the partition bounding box is within the coverage of the second virtual visible light source, the second virtual visible light source is added to the light source list of the screen partition. In some embodiments, after obtaining the light source direction and cone angle of the second virtual visible light source, the light source intensity and attenuation coefficient of the second virtual visible light source are obtained, and the attenuation formula of the second virtual visible light source is obtained. Based on the attenuation formula, light source intensity and attenuation coefficient of the second virtual visible light source, the distance information corresponding to the attenuation of the light intensity to a preset attenuation value is determined, thereby determining the coverage range of the second virtual visible light source based on the second position information, light source direction, cone angle and distance information of the second virtual visible light source, and then determining whether the block bounding box is within the coverage range of the second virtual visible light source. If it is determined that the block bounding box is within the coverage range of the second virtual visible light source, it means that the second virtual visible light source will affect the screen block, and therefore the second virtual visible light source is added to the light source list corresponding to the screen block. Through the above steps 1031 to 1036, after determining the second position information of the second virtual visible light source in the camera space, when it is determined that the second virtual visible light source may affect the pixel points in the screen block, it is further determined by the light source type of the second virtual visible light source whether to add the second virtual visible light source to the light source list corresponding to the screen block, thereby ensuring that the light sources saved in the light source list are all second virtual visible light sources that will affect the screen block, thereby ensuring the accuracy of the rendering results. Continuing to refer to FIG. 3A , the following description proceeds to step 103 . In step 104, full-screen rendering is performed based on the light source list of each screen block to obtain a second rendering result. In some embodiments, full screen rendering means completing the rendering of all screen blocks in the entire screen at once, that is, rendering multiple screen blocks in parallel. Referring to FIG5 , the following steps 1041 to 1043 are performed for each pixel to be rendered, so that full screen rendering is performed for the light source list of each screen block to obtain a rendered virtual scene, which is described below in conjunction with FIG5 . In step 1041, based on the position of the pixel, the screen block where the pixel is located is determined, and a list of light sources corresponding to the screen block is obtained. In some embodiments, since the screen blocks are obtained by dividing the screen according to a preset size, the screen blocks where the pixel points are located can be determined according to the preset size and the position of the pixel points. Then, after the position of the pixel point is known, assuming that the coordinates of the known pixel point are (x1, y1), Determine the number of rows corresponding to the screen block where the pixel is located, and Determine the number of columns corresponding to the screen block where the pixel point is located, where: It means that k is rounded up, so that the number of rows and columns corresponding to the screen block is determined, that is, the screen block where the pixel is located can be determined, and the light source list corresponding to the screen block is obtained. In step 1042, the light source color value of each second virtual visible light source at the pixel point is determined according to the light source type of each second virtual visible light source in the light source list. In some embodiments, the attenuation formula of each second virtual visible light source is obtained according to the light source type of each second virtual visible light source in the light source list, and the light source intensity and attenuation coefficient of each second virtual visible light source are obtained, and then the distance between the second virtual visible light source and each pixel point in the screen block is determined, so as to determine the light intensity of the second virtual visible light source at the pixel point based on the attenuation formula of the second virtual visible light source, the light source intensity, the attenuation coefficient and the calculated distance, and then the initial light source color value of the second virtual visible light source is obtained, and the product of the light intensity of the second virtual visible light source at the pixel point and the initial light source color value is determined as the pixel value of the second virtual visible light source at the pixel point. In step 1043, based on the light source color value of each second virtual visible light source at the pixel point, determine the pixel point The second destination color value. In some embodiments, since a pixel point in a screen block will be affected by each second virtual visible light source in the light source list corresponding to the screen block, it is necessary to accumulate the initial pixel value of the pixel point and the light source color value of each second virtual visible light source in the light source list at the pixel point to obtain the second target color value of the pixel point. In step 105, the first drawing result and the second drawing result are combined to obtain a drawn virtual scene, and the virtual scene is displayed. In some embodiments, the first drawing result is obtained by batch drawing of the first virtual visible light source whose screen-to-body ratio is less than a preset screen-to-body ratio threshold value, and the first drawing result includes the first target color value of each pixel within the illumination range of the first virtual visible light source. The first drawing result may also include the first target color value of each pixel not within the first virtual visible illumination range, and the first target color value is also the initial pixel value of each pixel. The second drawing result is obtained by full-screen drawing based on a light source list that only includes the second virtual light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold value, and the second drawing result includes the second target color value of each pixel. Therefore, in this step, the first drawing result and the second drawing result are merged, that is, the first target color value of each pixel in the first drawing result is superimposed with the second target color value of each pixel at the corresponding position in the second drawing result to obtain the third target pixel value of each pixel, and then the complete virtual scene is drawn, and the virtual scene is displayed. In the rendering method provided in the embodiment of the present application, after obtaining the virtual scene data to be rendered, first, based on the virtual scene data, multiple virtual visible light sources in the virtual scene are determined, and the screen-to-body ratio of each virtual visible light source is determined. Then, for the first virtual visible light source whose screen-to-body ratio is less than the preset screen-to-body ratio threshold, the multiple first virtual visible light sources are batch-drawn by calling the batch rendering and drawing command; for the second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold, a light source list for each screen block is determined, and only the second virtual visible light source is included in the light source list. Then, full-screen drawing is performed based on the light source list for each screen block, and the drawing results obtained from the two drawings are merged to obtain a rendered virtual scene. That is to say, in the embodiment of the present application, a scheme combining batch drawing and block rendering is adopted, and the drawing of a large number of light sources whose screen-to-body ratio is less than the screen-to-body ratio threshold is completed by calling a batch drawing command once, thereby greatly reducing the computational complexity of block rendering, so that the massive light sources in the virtual scene can be quickly rendered, thereby improving rendering efficiency. In some embodiments, after step 1036, steps 201 to 205 shown in FIG. 6A may be performed to compress and store the light source list of the screen blocks, which will be described below in conjunction with FIG. 6A. In step 201, the total number of first light sources corresponding to each screen block is determined, and the total number of second light sources of second virtual visible light sources to be rendered is determined. In some embodiments, since each light source node in the light source list stores the current light source identifier and the previous light source identifier, the light source list corresponding to each screen block can be traversed in reverse to obtain the total number of first light sources corresponding to each screen block, wherein the total number of first light sources refers to the total number of second virtual visible light sources included in the light source list corresponding to each screen block. Then, the total number of first light sources corresponding to each screen block is summed to obtain the total number of second light sources of the second virtual visible light source to be rendered. In step 202, a continuous memory space for storing a light source list is determined based on the total number of second light sources. In some embodiments, the memory space required to be occupied by each light source node in the light source list is first obtained, and then the total memory space required to store the light source list of all screen blocks is determined by multiplying the total number of second light sources by the memory space occupied by each light source node, and finally the continuous memory space corresponding to the total memory space size is obtained from the memory. Determining the continuous memory space means determining the starting address and the ending address of the continuous memory space. In step 203, based on the total number of first light sources corresponding to each screen block, a start index corresponding to each screen block is determined. In some embodiments, the starting index corresponding to the screen block, that is, the starting index of the light source list corresponding to the screen block in the continuous memory space. The starting index corresponding to the first screen block is 0, the starting index corresponding to the second screen block is the total number of first light sources corresponding to the first screen block, and the starting index corresponding to the third screen block is The sum of the total number of first light sources corresponding to 1 screen block and the second screen block, and so on. The starting index corresponding to the i-th screen block is the sum of the total number of first light sources corresponding to the first i-1 screen blocks, where i is an integer greater than 1. Exemplarily, assuming that the total number of first light sources corresponding to the first screen block is 20, the total number of first light sources corresponding to the second screen block is 30, and the total number of first light sources corresponding to the third screen block is 20, then the starting index corresponding to the first screen block is 0, the starting index corresponding to the second screen block is 20, the starting index corresponding to the third screen block is 20+30=50, and the starting index corresponding to the fourth screen block is 20+30+20=90. In step 204, the space occupation information of the light source list corresponding to each screen block in the continuous memory space is determined based on the total number of first light sources and the start index of each screen block. In some embodiments, the space occupation information of the light source list in the continuous memory space includes the starting storage address of the light source list in the continuous memory space. The space occupation information may also include the ending storage address of the light source list in the continuous memory space. Since the size of the memory space occupied by each light source node and the starting index corresponding to each screen block and the starting address of the continuous memory space are known, then based on the starting address of the continuous memory space + the size of the memory space occupied by each light source node multiplied by the starting index corresponding to each screen block, the starting storage address of the light source list corresponding to the screen block in the continuous memory space is obtained. In step 205, based on the space occupation information of each light source list in the continuous memory space, each second virtual visible light source in each light source list is stored in the continuous memory space. In some embodiments, the light source identifier of each second virtual visible light source in each light source list and the light source identifier of the previous second virtual visible light source can be stored in the continuous storage space in sequence based on the starting storage address included in the space occupancy information of the light source list in the continuous memory space. Figure 6B is another schematic diagram of compressed storage of the light source list provided in an embodiment of the present application. As shown in Figure 6B, after the starting index of each screen block is determined, the light source list corresponding to each screen block is stored in a continuous memory space based on the starting index of each screen block, thereby realizing compressed storage of the light source list and improving the utilization rate of the memory space. Through the above steps 201 to 205, the light source list of each screen block is stored in a continuous memory space. This not only improves the utilization rate of the memory space, but also when obtaining the light source list of each screen block, it can be read sequentially from the continuous memory space, which can reduce the time consumed in data reading and thus improve rendering efficiency. The following is an explanation of an exemplary application of an embodiment of the present application in a practical application scenario. The rendering method provided in the embodiment of the present application is mainly used in scenes such as electronic games, virtual reality, architectural design, animated films, etc. that require real-time rendering of large-scale dynamic light sources. When the virtual scene data is represented by an airplane flying over a city at night, the rendering method provided in the embodiment of the present application can be used to render the lighting effect of the city night view from the airplane as shown in Figure 7A. When the virtual scene data is represented by vehicles shuttling between the city roads at night, the rendering method provided in the embodiment of the present application can be used to render the dynamic light and shadow effect of vehicles shuttling between the roads as shown in Figure 7B. When the virtual scene data is represented by the lights on the Great Wall at night, the rendering method provided in the embodiment of the present application can be used to render the night scene lighting effect of the digital Great Wall as shown in Figure 7C. FIG8 is a schematic diagram of another implementation flow of the rendering method provided in an embodiment of the present application. The rendering method provided in an embodiment of the present application is described below in conjunction with FIG8 . In step 301 , a visible light source is obtained, and the size of the visible light source in the screen space is determined. In some embodiments, virtual scene data to be rendered is first obtained, and multiple light sources included in the virtual scene data to be rendered are determined. Then, frustum culling and occlusion culling are performed on the multiple light sources in the GPU to filter out visible light sources in the virtual scene, and the size of the visible light sources in the screen space is calculated. In step 302, for a small area light source, a GPU Driven method is used to draw the light source. The small area light source refers to a light source whose screen ratio is less than the screen ratio threshold. In some embodiments, the GPU Driven method can be used to package the drawing commands of the light source and call the indirect drawing (DrawIndirect) command. Multiple small-area light sources are batch-drawn. In implementation, the traditional method of drawing coverage by template testing can be avoided, and the illumination coverage of each small-area light source can be directly calculated by light source attenuation and angle. After determining the illumination coverage of the small-area light source, the drawing color value of each pixel within the illumination coverage is determined based on the light source attenuation coefficient, light source color, and light source intensity of each small-area light source. In step 303, for the large-area light source, a light source list for each screen block is determined. Among them, the light source list only includes large-area light sources. Large-area light sources are light sources whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold. In some embodiments, for large-area light sources in the vicinity, a tile based method can be used to calculate the light source list of each screen block. In implementation, for each screen block, all large-area light sources are traversed, the position of the large-area light source in the camera space is calculated, and then based on the position of the large-area light source in the camera space, the distance between the large-area light source and the block bounding box of each screen block is determined. If the distance is less than the radius of the large-area light source, it is considered that the large-area light source will affect the screen block. If the light source type of the large-area light source is a point light source, the large-area light source is directly added to the light source list of the screen block. If the light source type of the large-area light source is a spotlight, it is determined whether the block bounding box is within the illumination range of the spotlight according to the light source direction and cone angle of the spotlight. If the block bounding box is within the illumination range of the spotlight, the large-area light source is added to the light source list of the screen block. In some embodiments, the ID of the current light source and the link to the previous light source node are recorded in the light source list. After determining the light source list for each screen block, the light source list structure for each screen block is compressed. First, the light source list is traversed in reverse, the number of light sources in the screen block is calculated, the number of light sources in the screen block and the starting index corresponding to the light source list are saved, and then the storage range of the light source list in the continuous memory structure is determined based on the light source data in the screen block and the starting index corresponding to the light source list, and finally the light sources in the screen block are recorded in the continuous memory structure corresponding to the storage range. In step 304, a full-screen rendering is performed to render the light source of each screen block. In some embodiments, for each pixel, the screen block where the pixel is located is calculated, the light source list of the screen block is obtained, and then the light source list is traversed, and the diffuse reflection and highlight color values at the position are calculated according to the type of light source. All color values in the light source list are superimposed to obtain the second target color value of the pixel point, and finally the second target color value of the pixel point is output. Figure 9 is a schematic diagram of the effects of rendering long-distance light sources and short-distance light sources using the rendering method provided in an embodiment of the present application. Compared with the tile based lighting algorithm in the related art, in a performance test of a scene with 50,000 light sources, the rendering method provided in an embodiment of the present application, when combined with GPU Driven and Tiledbase, as shown in 901 in Figure 9, can increase the frame rate from 7 frames to 100 frames when rendering long-distance light sources. When overdraw is aggravated at short distances, the consumption of tile culling can be reduced due to the division of light sources and early culling (Culling), as shown in 902 in Figure 9, and the frame rate can also be increased from 9 frames to 54 frames. Figure 10 is a comparison effect diagram of the rendering method provided in the embodiment of the present application and the cluster based lighting algorithm in the related art. When the number of light sources reaches 50,000, as shown by 1001 in Figure 10, the rendering method provided in the embodiment of the present application, when combined with GPU Driven and Tiledbase, can achieve a frame rate of 100 frames per second. However, because the overhead of constructing a complex cluster light list is too large, as shown by 1002 in Figure 10, the frame rate of the cluster based lighting algorithm will drop significantly to 15 frames per second. The embodiment of the present application provides a rendering solution based on GPU Driven and block rendering, which combines the advantages of both to quickly render a large number of light sources in the scene. The entire process has almost no CPU overhead and CPU synchronization consumption. At the same time, since one CPU draw completes the drawing of all the large number of light sources in the mid- and long-range scenes, the GBuffer cache hit rate is greatly improved, thereby avoiding the bandwidth consumption of multiple drawing. It is understandable that in the embodiments of the present application, when virtual scene data and other related data are involved, when the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions. The following is a description of an exemplary structure of a rendering device 455 provided in an embodiment of the present application implemented as a software module. In some embodiments, as shown in FIG. 2 , the software module stored in the rendering device 455 of the memory 450 may include: The first determination module 4551 is configured to obtain virtual scene data to be rendered, determine multiple virtual visible light sources in the virtual scene based on the virtual scene data, and determine the screen-to-body ratio of each virtual visible light source; the first rendering module 4552 is configured to perform batch rendering and drawing on the first virtual visible light source whose screen-to-body ratio is less than a preset screen-to-body ratio threshold value among the multiple virtual visible light sources; the second determination module 4553 is configured to determine a light source list for each screen block, wherein the light source list only includes the second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold value; the second rendering module 4554 is configured to perform full-screen drawing based on the light source list for each screen block to obtain a second drawing result; the display module 4555 is configured to merge the first drawing result and the second drawing result to obtain a drawn virtual scene, and display the virtual scene. In some embodiments, the first determination module 4551 is further configured to: determine multiple virtual light sources existing in the virtual scene based on the virtual scene data; perform frustum culling and occlusion culling on the multiple virtual light sources to obtain multiple virtual visible light sources in the virtual scene. In some embodiments, the first determination module 4551 is further configured to: obtain the center coordinates and the radius of the enclosing sphere of the virtual visible light source in the camera space; obtain the projection matrix from the camera space to the screen space, and determine the scaling factor based on the projection matrix; use the scaling factor, the enclosing sphere radius and the center coordinates to determine the first size information of the virtual visible light source in the camera space; obtain the second size information of the screen presenting the virtual scene, and determine the screen-to-body ratio of the virtual visible light source based on the first size information and the second size information. In some embodiments, the first rendering module 4552 is also configured to: obtain the first position information of the first virtual visible light source in the camera space, as well as the light source attenuation coefficient, light source intensity and illumination angle of the first virtual visible light source; determine the illumination coverage range of the first virtual visible light source based on the first position information, light source attenuation coefficient, light source intensity and illumination angle; determine the light source color value of each pixel point of the first virtual visible light source within the illumination coverage range; when a pixel point is within the illumination coverage range of at least two first virtual visible light sources, determine the first target color value of the pixel point based on the light source color values of the at least two first virtual visible light sources at the pixel point. In some embodiments, the second determination module 4553 is also configured to: determine the second position information of the second virtual visible light source in the camera space; determine the distance between the second virtual visible light source and the block bounding box of the screen block, if the distance is less than the light source radius of the second virtual visible light source, obtain the light source type of the second virtual visible light source; if the light source type is a point light source, add the second virtual visible light source to the light source list of the screen block. In some embodiments, the second determination module 4553 is further configured to: if the light source type is a spotlight type, obtain the light source direction and cone angle of the second virtual visible light source; when it is determined based on the light source direction and cone angle of the second virtual visible light source that the block bounding box is within the coverage range of the second virtual visible light source, add the second virtual visible light source to the light source list of the screen block. In some embodiments, the light source list includes at least one light source node, and each light source node stores a current light source identifier and a previous light source identifier of the current light source identifier; the second determination module 4553 is also configured to: when the second virtual visible light source is the first light source node in the light source list, add the light source identifier of the second virtual visible light source to the current light source identifier corresponding to the first light source node; determine that the previous light source identifier of the first light source node is empty; when the second virtual visible light source is the Nth light source node in the light source list, add the light source identifier of the second virtual visible light source to the current light source identifier corresponding to the Nth light source node; add the current light source identifier corresponding to the N-1th light source node to the previous light source identifier corresponding to the Nth light source node. In some embodiments, the rendering device further includes: a third determining module configured to determine the screen blocks. A fourth determining module is configured to determine a continuous memory space for storing a light source list based on the total number of the second light sources; a fifth determining module is configured to determine a starting index corresponding to each screen block based on the total number of first light sources corresponding to each screen block; a sixth determining module is configured to determine space occupancy information of a light source list corresponding to each screen block in the continuous memory space based on the total number of first light sources and the starting index of each screen block; a storage module is configured to store the second virtual visible light sources in each light source list in the continuous memory space based on the space occupancy information of each light source list in the continuous memory space. In some embodiments, the second rendering module 4554 is also configured to: perform the following operations for each pixel to be rendered: determine the screen block where the pixel is located based on the position of the pixel, and obtain a list of light sources corresponding to the screen block; determine the light source color value of each second virtual visible light source at the pixel according to the light source type of each second virtual visible light source in the light source list; and determine the second target color value of the pixel by using the light source color value of each second virtual visible light source at the pixel. In some embodiments, the display module 4555 is also configured to obtain a first target color value for each pixel from the first drawing result, and obtain a second target color value for each pixel from the second drawing result; for each pixel, superimpose the first target color value and the second target color value of the pixel to obtain a third target color value of the pixel; and use the third target color value of each pixel to draw a virtual scene. The embodiment of the present application provides a computer program product, which includes a computer program or a computer executable instruction, and the computer program or the computer executable instruction is stored in a computer-readable storage medium. The processor of the electronic device reads the computer executable instruction from the computer-readable storage medium, and the processor executes the computer executable instruction, so that the electronic device performs the rendering method described in the embodiment of the present application. An embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, wherein computer-executable instructions or computer programs are stored. When the computer-executable instructions or computer programs are executed by a processor, the processor will execute the rendering method provided by the embodiment of the present application, for example, the rendering method shown in Figures 3A and 8. In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories. In some embodiments, computer executable instructions 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. As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file storing other programs or data, such as 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 (e.g., files storing one or more modules, subroutines, or code portions). As an example, computer executable instructions 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. The above is only an embodiment of the present application and is 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. A rendering method, applied to an electronic device, comprising: Determining multiple virtual visible light sources in the virtual scene based on the virtual scene data to be rendered, and determining a screen ratio of each virtual visible light source; Performing batch rendering on a first virtual visible light source among the multiple virtual visible light sources to obtain a first rendering result, wherein a screen-to-body ratio of the first virtual visible light source is less than a preset screen-to-body ratio threshold; Determine a light source list for each screen block, wherein the light source list includes a second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold; Perform full-screen rendering based on the light source list of each screen block to obtain a second rendering result; The first drawing result and the second drawing result are combined to obtain a drawn virtual scene, and the virtual scene is displayed.
2. The method according to claim 1, wherein: The step of determining a plurality of virtual visible light sources in a virtual scene based on virtual scene data to be rendered comprises: Based on the virtual scene data, determining a plurality of virtual light sources existing in the virtual scene; The multiple virtual light sources are subjected to frustum culling and occlusion culling to obtain multiple virtual visible light sources in the virtual scene.
3. The method according to claim 2, wherein: The determining the screen ratio of each virtual visible light source includes: Obtain the center coordinates and radius of the bounding sphere of the virtual visible light source in the camera space; Obtain a projection matrix from world space to camera space, and determine a scaling factor based on the projection matrix; Determine first size information of the virtual visible light source in the camera space by using the zoom factor, the radius of the bounding sphere and the coordinates of the sphere center; Second size information of a screen presenting a virtual scene is obtained, and based on the first size information and the second size information, a screen-to-body ratio of the virtual visible light source is determined.
4. The method according to any one of claims 1 to 3, wherein: The batch rendering and drawing of the first virtual visible light source among the multiple virtual visible light sources includes: Acquire first position information of the first virtual visible light source in the camera space, and a light source attenuation coefficient and a light source intensity of the first virtual visible light source; Determine a lighting coverage range of the first virtual visible light source based on the first position information, the light source attenuation coefficient, and the light source intensity; Determine the light source color value of each pixel point of the first virtual visible light source within the illumination coverage range; When a pixel point is located within the illumination coverage of at least two first virtual visible light sources, a first target color value of the pixel point is determined based on light source color values of the at least two first virtual visible light sources at the pixel point.
5. The method according to any one of claims 1 to 3, wherein: The step of determining a light source list for each screen block includes: Determining second position information of a second virtual visible light source in the camera space; Determining a distance between the second virtual visible light source and a block bounding box of a screen block; If the distance is less than the light source radius of the second virtual visible light source, acquiring the light source type of the second virtual visible light source; If the light source type is a point light source, the second virtual visible light source is added to the light source list of the screen segment.
6. The method according to claim 5, wherein: The step of determining a light source list for each screen block includes: If the light source type is a spotlight type, obtaining the light source direction and cone angle of the second virtual visible light source; When it is determined that the partition bounding box is within the coverage range of the second virtual visible light source based on the light source direction and cone angle of the second virtual visible light source, the second virtual visible light source is added to the light source list of the screen partition.
7. The method according to claim 5 or 6, wherein: The light source list includes at least one light source node, each of which stores a current light source identifier and a light source identifier previous to the current light source identifier; The step of adding the second virtual visible light source to the light source list of the screen segment comprises: When the second virtual visible light source is the first light source node in the light source list, adding the light source identifier of the second virtual visible light source to the current light source identifier corresponding to the first light source node; Determine that the previous light source identifier of the first light source node is empty; When the second virtual visible light source is the Nth light source node in the light source list, adding the light source identifier of the second virtual visible light source to the current light source identifier corresponding to the Nth light source node, where N is an integer greater than 1; The current light source identifier corresponding to the N-1th light source node is added to the previous light source identifier corresponding to the Nth light source node.
8. The method according to claim 7, wherein: The method further comprises: Determine the total number of first light sources corresponding to each screen block, and determine the total number of second light sources of the second virtual visible light sources to be rendered; Determine a continuous memory space for storing a light source list based on the total number of the second light sources; Determining a starting index corresponding to each screen block based on the total number of first light sources corresponding to each screen block; Determine the space occupation information of the light source list corresponding to each screen block in the continuous memory space based on the total number of first light sources and the starting index of each screen block; Based on the space occupation information of each light source list in the continuous memory space, the second virtual visible light source in each light source list is stored in the continuous memory space.
9. The method according to claim 1, wherein: The performing full-screen rendering based on the light source list of each screen block includes: For each pixel to be rendered, do the following: Based on the position of the pixel point, determine the screen block where the pixel point is located, and obtain a list of light sources corresponding to the screen block; Determine the light source color value of each second virtual visible light source at the pixel point according to the light source type of each second virtual visible light source in the light source list; Based on the light source color values of each second virtual visible light source at the pixel point, a second target color value of the pixel point is determined.
10. The method according to any one of claims 1 to 3, wherein: The step of merging the first drawing result and the second drawing result to obtain a drawn virtual scene includes: Acquire a first target color value of each pixel point from the first drawing result, and acquire a second target color value of each pixel point from the second drawing result; For each pixel, superimpose the first target color value and the second target color value of the pixel to obtain a third target color value of the pixel; A virtual scene is drawn using the third target color value of each pixel.
11. A rendering device, comprising: A first determination module is configured to obtain virtual scene data to be rendered, determine a plurality of virtual visible light sources in the virtual scene based on the virtual scene data, and determine a screen ratio of each virtual visible light source; A first rendering module is configured to perform batch rendering on a first virtual visible light source among the multiple virtual visible light sources to obtain a first rendering result, wherein a screen-to-body ratio of the first virtual visible light source is less than a preset screen-to-body ratio threshold; A second determining module is configured to determine a light source list for each screen segment, wherein the light source list includes a second virtual visible light source whose screen-to-body ratio is greater than or equal to the screen-to-body ratio threshold; A second rendering module is configured to perform full-screen rendering based on the light source list of each screen block to obtain a second rendering result; The display module is configured to merge the first drawing result and the second drawing result to obtain a drawn virtual scene, and display the virtual scene.
12. An electronic device, comprising: A memory for storing computer executable instructions; A processor, configured to implement the rendering method according to any one of claims 1 to 10 when executing the computer executable instructions stored in the memory.
13. A computer-readable storage medium storing computer-executable instructions or a computer program, wherein the computer-executable instructions or the computer program, when executed by a processor, implement the rendering method according to any one of claims 1 to 10.
14. A computer program product, comprising computer executable instructions or a computer program, wherein the computer executable instructions or the computer program, when executed by a processor, implements the rendering method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Light source sampling weight determination method for multi-light source scene rendering and related equipment
CN114549730A
Method and system for eliminating point light source
CN116188653A
Picture rendering method based on multiple light sources and related equipment
CN116310052A
Rendering method, device and equipment and computer readable storage medium
CN116883572A
3D rendering method and apparatus
US20170193690A1