Rendering method and electronic device
By rendering the shadow in the shadow map based on the number of pixel points and/or depth values in the target area, the problem of insufficient shadow changes in the shadow area is solved, and a more realistic and approximate rendering effect is achieved.
Patent Information
- Application Number
- PCT/CN2024/120077
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-20
- Filing Date
- 2024-09-20
- Publication Date
- 2025-04-03
AI Technical Summary
Existing 3D rendering technology is difficult to achieve smooth and soft changes in shadows in shadow areas, resulting in the shadow rendering effect not being realistic enough.
By determining the target area in the shadow map, the shadow is rendered according to the number and/or depth values of pixel points in the target area, so that the shadow changes of adjacent pixel points in the shadow area are more smooth and soft.
Improves the smoothness and softness of pixels in the shadowed area in the virtual scene, and enhances the fidelity and anti-aliasing of the rendering effect.
Smart Images

Figure CN2024120077_03042025_PF_FP_ABST
Abstract
Description
Rendering method and electronic device
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to Chinese Patent Application No. 202311292708.4, filed with the State Intellectual Property Office of the People's Republic of China on September 28, 2023, entitled "3D Object Rendering Method," the entire contents of which are incorporated herein by reference. This application claims priority to Chinese Patent Application No. 202311765737.8, filed with the State Intellectual Property Office of the People's Republic of China on December 20, 2023, entitled "A Rendering Method and Electronic Device," the entire contents of which are incorporated herein by reference. Technical Field
[0003] The present application relates to the field of terminal technology, and in particular to a rendering method and electronic device. Background Art
[0004] Three-dimensional (3D) rendering technology involves rendering 3D models based on their data (such as object geometry and surface material) and lighting data (including light source position and intensity). The resulting 3D model approximates real-world objects under the same lighting conditions, giving viewers an immersive experience that feels like the real world. For example, 3D games generally attract players with realistic graphics, making high-fidelity rendering of 3D models a technology constantly sought after by application developers.
[0005] Summary of the Invention
[0006] Embodiments of the present application provide a rendering method and an electronic device for improving the rendering fidelity of a 3D model.
[0007] In a first aspect, a rendering method is provided. The method includes: an electronic device determines a shadow map of a virtual scene based on the position of a light source in a virtual scene to be rendered, and the shadow map includes depth information of pixels illuminated by the light source in the virtual scene. The electronic device determines a target area in the shadow map based on a first pixel in the virtual scene, where the first pixel is located in a shadow area in the virtual scene, where the shadow area is an area not illuminated by the light source in the virtual scene, and the target area includes a second pixel, where the projection of the second pixel in the shadow area corresponds to the first pixel. The electronic device renders the shadow of the first pixel based on the number and / or depth value of pixels in the target area.
[0008] In an embodiment of the present application, an electronic device can render a shadow in a shadow area of a virtual scene to enhance the realism of the virtual scene. Moreover, the shadow of a pixel (e.g., a first pixel) in the shadow area is determined based on the number of pixels and / or depth value in the area (i.e., the target area) where the pixel (e.g., a second pixel) corresponding to the pixel is located on the shadow map. The same principle can be applied to the shadow of each pixel in the shadow area. In this way, the shadow changes of two adjacent pixels in the shadow area will not be too abrupt, but will be relatively smooth, soft, and have strong anti-aliasing properties. For example, there are adjacent pixels 1 and 2 in the shadow area. Pixel 1 corresponds to pixel 3 on the shadow map, and pixel 2 corresponds to pixel 4 on the shadow map. The shadow of pixel 1 is determined based on the number of pixels and / or depth value in area 1 (the target area where pixel 3 is located) on the shadow map, and the shadow of pixel 2 is determined based on the number of pixels and / or depth value in area 2 (the target area where pixel 4 is located) on the shadow map. Since pixel 1 and pixel 2 are adjacent, area 1 and area 2 overlap on the shadow map. Therefore, the shadow of pixel 1 determined based on the number of pixels and / or depth value in area 1 is not too abrupt and is relatively soft compared to the shadow of pixel 2 determined based on the number of pixels and / or depth value in area 2.
[0009] In one possible design, the electronic device renders the shadow of a first pixel based on the number of pixels and / or depth values in the target area, including: determining a first value based on the number of pixels and / or depth values in the target area; rendering the shadow of the first pixel based on a ratio between the first value and a second value, where the second value is a default value or is determined based on the first depth value of the first pixel.
[0010] In an embodiment of the present application, the shadow of a pixel (e.g., a first pixel) within a shadow region of a virtual scene is determined based on the number of pixels and / or depth value within the region (i.e., the target region) where the pixel corresponding to the pixel (e.g., a second pixel) on the shadow map is located. The same principle can be applied to the shadow of each pixel within the shadow region. In this way, the shadow changes between two adjacent pixels within the shadow region are not too abrupt, but rather are relatively smooth and soft.
[0011] In one possible design, the first value includes: the total number of pixels in the target area; or the average depth value of all pixels in the target area; or the sum of the depth values of all pixels in the target area.
[0012] In an embodiment of the present application, the shadow of a pixel point (for example, a first pixel point) in a shadow area in a virtual scene is determined based on the number of pixels and / or depth value in the area (i.e., the target area) where the pixel point (for example, a second pixel point) corresponding to the pixel point on the shadow map is located, thereby improving the smoothness and softness of the shadow of the pixel point in the shadow area in the virtual scene.
[0013] In one possible design, the second value is determined based on the first depth value of the first pixel, including: the second value is the total number of pixels in the virtual scene whose depth values are less than the first depth value; or, the second value is the average depth value of all pixels in the virtual scene whose depth values are less than the first depth value; or, the second value is the sum of the depth values of all pixels in the virtual scene whose depth values are less than the first depth value.
[0014] In an embodiment of the present application, the shadow of a pixel point (for example, a first pixel point) in a shadow area in a virtual scene is determined based on the number of pixels and / or depth values in the area (i.e., the target area) where the pixel point (for example, a second pixel point) corresponding to the pixel point on the shadow map is located, and the first depth value of the first pixel point, thereby improving the smoothness and softness of the shadow of the pixel point in the shadow area in the virtual scene.
[0015] In one possible design, the electronic device renders the shadow of the first pixel based on the number of pixels and / or the depth value of the pixel in the target area, including: determining the shadow value corresponding to the number of pixels in the target area based on a first correspondence between the number of pixels and the shadow value; and / or determining the shadow value corresponding to the depth value of the pixel in the target area based on a second correspondence between the depth value of the pixel and the shadow value; and rendering the shadow of the first pixel based on the shadow value.
[0016] Optionally, if according to the first correspondence, the shadow value corresponding to the number of pixels in the target area is determined to be A; according to the second correspondence, the shadow value corresponding to the depth value of the pixels in the target area is determined to be B, then according to the shadow value, rendering the shadow of the first pixel may include: rendering the shadow of the first pixel according to the average value or weighted average value of A and B.
[0017] In one possible design, the target area includes: an area centered on the second pixel and with a first size as a radius, where the first size is a default value or is determined based on the size of the light source and / or the depth difference between the first pixel and the second pixel.
[0018] In some examples, the first size may have other names, such as filter kernel size. In embodiments of the present application, the filter kernel size may be determined based on the size of the light source and / or the depth difference between the first pixel and the second pixel, thereby improving the accuracy of the filter kernel size and, in turn, improving the accuracy of the target area and the accuracy of the shadow.
[0019] In one possible design, the target area includes: an area centered on the second pixel point and with a first size as a radius, the first size is equal to c times the second size, c is a positive number, the second size is a default value or is determined based on the size of the light source and / or the depth difference between the first pixel point and the second pixel point, and the value of c is a default value or is determined based on the ambient brightness of the virtual scene and / or the user's perspective.
[0020] In other examples, the second size may have other names, for example, filter kernel size. The first size is equal to c times the filter kernel size. In an embodiment of the present application, the filter kernel size may be determined based on the size of the light source and / or the depth difference between the first pixel and the second pixel. The value of c is related to the ambient brightness of the virtual scene and / or the user's perspective. The filter kernel size and c determined in this way are more accurate, thereby improving the accuracy of the target area and the accuracy of the shadow.
[0021] In one possible design, the rendering method further includes: the electronic device determining a first shading point on a 3D model to be rendered in a virtual scene, where the first shading point is any shading point on the 3D model. The electronic device obtains a diffuse color component and a specular lighting component of the first shading point. The electronic device obtains a lighting rendering result for the first shading point based on the diffuse color component and the specular lighting component.
[0022] In an embodiment of the present application, the lighting rendering result of a shading point in a virtual scene includes a diffuse color component and a specular lighting component, thereby improving the realism of the lighting rendering of the virtual scene.
[0023] In one possible design, the electronic device obtains the diffuse reflection color component and the specular illumination component of the first shading point, including: determining the diffuse reflection color component corresponding to the first shading point in a third correspondence relationship based on the number of the first shading point, where the third correspondence relationship is the correspondence between the number of each shading point and the diffuse reflection color component; determining the specular illumination component corresponding to the first shading point in a fourth correspondence relationship based on the number of the first shading point, where the fourth correspondence relationship is the correspondence between the number of each shading point and the specular illumination component.
[0024] In an embodiment of the present application, the diffuse color component and specular lighting component of each shading point on the 3D model can be pre-calculated and stored. When the 3D model needs to be rendered, the stored diffuse color component and specular lighting component of each shading point are used for rendering to improve efficiency.
[0025] In one possible design, the lighting rendering result of the first shading point includes a linear combination of a diffuse color component and a specular lighting component.
[0026] In an embodiment of the present application, the lighting rendering result of a shading point in a virtual scene includes a linear combination of a diffuse color component and a specular lighting component, thereby improving the realism of the lighting rendering of the virtual scene.
[0027] In a second aspect, an electronic device is provided. The electronic device includes a 3D application and a rendering engine. The rendering engine is located in an application package of the 3D application or in an operating system of the electronic device. The 3D application is configured to display a virtual scene on a display screen of the electronic device. The rendering engine is configured to execute the method provided in the first aspect.
[0028] In a third aspect, an electronic device is provided. The electronic device includes a 3D application client. The 3D application client is configured to send rendering instructions to a 3D application server and receive rendering results returned by the 3D application server. The 3D application server includes a rendering engine, or the 3D application server is installed in a cloud server and can call the rendering engine in the cloud server. The rendering engine is configured to execute the method provided in the first aspect.
[0029] In a fourth aspect, a cloud server is provided. The cloud server includes a 3D application server. The 3D application server includes a rendering engine, or the cloud server includes a rendering engine that can be called by the 3D application server. The rendering engine is configured to execute the method provided in the first aspect.
[0030] In a fifth aspect, an electronic device is further provided, comprising:
[0031] a processor, a memory, and one or more programs;
[0032] Among them, one or more programs are stored in the memory, and the one or more programs include instructions. When the instructions are executed by the processor, the electronic device executes the method steps provided in the first aspect above.
[0033] In a sixth aspect, a computer-readable storage medium is also provided, which is used to store a computer program. When the computer program runs on a computer, it enables the computer to execute the method provided in the first aspect above.
[0034] In a seventh aspect, a computer program product is provided, comprising a computer program, which, when run on a computer, enables the computer to execute the method provided in the first aspect above.
[0035] In the eighth aspect, a chip system is also provided, which is coupled to a memory in an electronic device and is used to call a computer program stored in the memory and execute the technical solution of the first aspect of the embodiment of the present application. In the embodiment of the present application, "coupling" refers to the direct or indirect combination of two components with each other.
[0036] For the technical effects that can be achieved in the above-mentioned second to eighth aspects, please refer to the description of the technical effects that can be achieved by the corresponding design scheme in the above-mentioned first aspect, and this application will not repeat them here. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] FIG1 is a schematic structural diagram of an electronic device provided in one embodiment of the present application;
[0038] FIG2 is a schematic diagram of a flow chart of a rendering method provided in an embodiment of the present application;
[0039] FIG3 is a schematic diagram of a dough sheet provided in one embodiment of the present application;
[0040] FIG4 is a schematic diagram of filter kernel sizes provided in one embodiment of the present application;
[0041] FIG5 is another structural diagram of an electronic device provided in one embodiment of the present application;
[0042] FIG6 is a schematic diagram of a page node provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] Below, some terms used in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0044] The at least one involved in the embodiments of the present application includes one or more; wherein, more than one means greater than or equal to two. In addition, it should be understood that, in the description of this specification, words such as "first" and "second" are only used for the purpose of distinguishing the description, and cannot be understood as expressing or implying relative importance, nor can they be understood as expressing or implying order. For example, the first area and the second area do not represent the importance of the two or the order of the two, but are only for distinguishing the description. In the embodiments of the present application, "and / or" is only a description of the association relationship, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the objects related to each other are in an "or" relationship.
[0045] References to "one embodiment," "in some examples," or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of this specification. Thus, phrases such as "in one embodiment," "in some embodiments," "in some other embodiments," "in some further embodiments," "in some examples," and "in other examples" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0046] As used in this specification, the terms “when” or “after” may be interpreted to mean “if” or “after” or “in response to determining that” or “in response to detecting that”, depending on the context. Similarly, the phrases “upon determining that” or “if (stated condition or event) is detected” may be interpreted to mean “if it is determined that” or “in response to determining that” or “upon detecting (stated condition or event)” or “in response to detecting (stated condition or event)”, depending on the context.
[0047] The rendering method provided in the embodiment of the present application is applicable to electronic devices. Exemplarily, the electronic device may be a portable device such as a mobile phone, a tablet computer, a laptop computer, or a wearable device such as a watch or a bracelet, or a virtual reality (VR) device, an augmented reality (AR) device, a mixed reality (MR) device, etc. In short, the embodiment of the present application does not limit the specific type of electronic device. One possible scenario is that an electronic device (for example, a mobile phone) may include a 3D application, and the 3D application may be rendered using the rendering method provided in the embodiment of the present application. The 3D application may be a system application or a third-party application of an electronic device, for example, it may include a 3D game application, a VR / AR application, a 3D movie, etc., which is not limited in the embodiment of the present application.
[0048] Figure 1 shows a schematic diagram of the hardware structure of an electronic device. As shown in Figure 1, the electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0049] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors. The controller may serve as the nerve center and command center of the electronic device. The controller may generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution. The processor 110 may also include memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a high-speed cache memory. This memory may store instructions or data that have just been used or are being recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces the processor 110's waiting time, and thus improves system efficiency. Optionally, the rendering method provided in the embodiment of the present application can be executed by the processor 110.
[0050] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0051] The wireless communication function of the electronic device can be implemented using antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, a modem processor, and a baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antenna can be used in conjunction with a tuning switch.
[0052] The display screen 194 is used to display the display interface of the application, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device may include one or more display screens 194.
[0053] The electronic device 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor, etc. Among them, the ISP is used to process the data fed back by the camera 193.
[0054] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes the instructions stored in the internal memory 121 to execute various functional applications and data processing of the electronic device.
[0055] It is understood that the components shown in FIG1 do not constitute a specific limitation on the electronic device. The electronic device in the embodiment of the present application may include more or fewer components than those shown in FIG1. In addition, the combination / connection relationship between the components in FIG1 can also be adjusted and modified.
[0056] The rendering method provided by the embodiments of the present application is described below with reference to the accompanying drawings.
[0057] Please refer to Figure 2, which is a flowchart of a rendering method provided in one embodiment of the present application. The process may include two parts: one is lighting rendering, which includes S201 to S203 in Figure 2; the other is shadow rendering, which includes S204 to S206 in Figure 2.
[0058] As shown in FIG2 , the process includes:
[0059] S201, obtaining relevant information of the virtual scene.
[0060] One possible scenario is that after an electronic device launches a 3D application, it displays the interface of the 3D application, which includes a virtual scene. Therefore, after the electronic device launches the 3D application, it obtains relevant information about the virtual scene. Another possible method is that the electronic device obtains relevant information about the virtual scene from the resources of the 3D application. Optionally, the resources of the 3D application can be located in the application package of the 3D application in the electronic device or in the application server of the 3D application, which is not limited in the embodiments of the present application.
[0061] In some examples, a virtual scene includes a light source and one or more three-dimensional (3D) models to be rendered. Optionally, the light source can be a point light source, a line light source, or a surface light source, etc., which is not limited in the embodiments of the present application. Considering that the light source in a real scene is generally a surface light source, the embodiments of the present application are mainly described as a surface light source.
[0062] In some examples, virtual scene-related information includes light source data and data for one or more 3D models to be rendered. The light source data may include the position, intensity, shape, and size of the light source. The data for the 3D model to be rendered may include the position, size, and pose of the 3D model in the virtual scene, as well as the mesh division, mesh numbering, and the geometric and material parameters of the meshes. The details about meshes will be discussed later.
[0063] It should be understood that in a real scene, a light source (for example, the sun) generates light. After the light generated by the light source contacts the surface of a real object, at least one of refraction, reflection, or diffuse reflection will occur at the point of contact, and then enter the user's eyes, so that the user can see the real object under the light. In order to be close to the real scene, the ideal virtual scene is that the light source generates light. After the light generated by the light source contacts the surface of the 3D model, at least one of refraction, reflection, or diffuse reflection will occur at the point of contact, and then enter the user's eyes. In order to show this virtual scene to the user as much as possible, the electronic device can render lighting on the 3D model.
[0064] In order to improve the rendering fineness, the embodiment of the present application can divide the surface of the 3D model to be rendered into a certain number of tiny planes. These planes are also called facets (also known as grids or other names), which can be arbitrary polygons, such as triangles, quadrilaterals, spheres, hemispheres, etc. A facet can be understood as a rendering unit on a 3D model, and the rendering of each facet on the 3D model is completed when the 3D model is rendered. Optionally, different 3D models may have different ways of dividing facets. For example, 3D models with different shapes may have different shapes and numbers of facets. It is understandable that the size of the facets can be set as needed. The higher the accuracy requirement for the rendered image, the smaller the size of the facets can be set.
[0065] The relevant information of the virtual scene obtained by the electronic device in S201 includes: the facet division of the 3D model to be rendered, the facet number, the geometric parameters and material parameters of the facet, etc. Among them, the facet division situation may include, for example, the number and position of the facets. The facet number is used to uniquely identify the facet. The geometric parameters of the facet are used to describe the shape and size of the facet. For example, as shown in Figure 3, taking the facet as a hemisphere as an example, the hemisphere can be divided into multiple directions according to the polar angle θ and the azimuth angle α. Each direction can be expressed as (θ, α) in the hemispherical coordinate system, where 0≤θ≤90 and 0≤α<360. The material parameters of the facet can be used to describe the material characteristics of the facet. Exemplarily, the material of the facet may include: transparent material, opaque material, smooth material, rough material, etc. Optionally, the material parameters of the facet can be expressed by a texture map. Among them, the texture map can be understood as a 2D image, which includes pixel information, such as red, green, and blue (RGB) colors. These pixel information are also called textures. The pixel information (i.e., texture) on the texture map can be mapped to the 3D model. One possible mapping method is that the surface of the 3D model can be unfolded into a 2D plane. The unfolding method can be, for example, UV unfolding, which will not be described in detail in the embodiments of the present application. Mapping a pixel value (e.g., color value) on the map at different positions on the unfolded 2D plane is equivalent to pasting a picture on the surface of the 3D model, so it is called a texture map. Optionally, a 3D model can correspond to a map, and each face on the 3D model can correspond to an image block on this map. Alternatively, a 3D model can correspond to multiple maps. For example, a 3D model includes N faces, N is a positive integer, each face corresponds to a map, and so on. The embodiments of the present application are not limited thereto.
[0066] S202 , calculating the diffuse color component and the specular lighting component of each shading point on the 3D model to be rendered based on the relevant information of the virtual scene.
[0067] For ease of understanding, let's first briefly explain the shading point. Continuing with the example of a patch shown in Figure 3, after the light generated by the light source contacts the surface of the patch, diffuse reflection occurs at the contact point to produce reflected light. When the reflected light enters the user's eyes, the color of this contact point on the patch is seen. Therefore, the point where the light contacts the patch can be understood as a shading point. For a patch, the number of contact points between the light and the patch can be one or more, so a patch can include one or more shading points. For example, p1, p2, and p3 in Figure 3 are three different shading points.
[0068] In an embodiment of the present application, the lighting rendering result of a shading point may include a diffuse color component and a specular lighting component. For example, the rendering result of a shading point includes a linear or nonlinear combination of the diffuse color component and the specular lighting component. Exemplarily, the rendering equation of a shading point may include: L = L diff +L spec (1)
[0069] Among them, L refers to the lighting rendering result of the shading point, L diff Refers to the diffuse color component of this shading point, L spec Refers to the specular lighting component. Optionally, the above formula can also be transformed into L = AL diff +BL spec , where A and B are coefficients and can be pre-configured.
[0070] The following describes the diffuse color component (L diff ) and the specular lighting component (L spec ) determination process.
[0071] 1. The process of determining the diffuse color component of the shading point.
[0072] In the embodiment of the present application, the diffuse reflection color component of the shading point can satisfy the following formula:
[0073] where θ represents the latitude coordinate (e.g., the polar angle θ in Figure 3), represents the longitude coordinate (for example, the azimuth angle α in FIG3 ), l represents the frequency band, and m represents the degree of spherical harmonics. A0=pi, A1=2*pi / 3, A2=pi / 4, and pi can be a fixed value. For light source The plotted values, for example, in The light intensity. is a spherical harmonic function and can be expressed as the following function:
[0074] Among them, θ represents the latitude coordinate, represents the longitude coordinate, l represents the frequency band, and m represents the degree of spherical harmonics. is the Legendre polynomial, is the normalized coefficient. For example, The following formula (4) can be satisfied. The following formula (5) can be satisfied
[0075] Therefore, the spherical harmonic functions is a polynomial, and in some examples, spherical harmonic functions can be used The diffuse color component is approximately expressed by the first n terms of , that is, the diffuse color component L is obtained by taking the first n terms and substituting them into the above formula (2). diff For example, when n=9, we only need to use the first 9 terms of the spherical harmonic function and put them into formula (2) to get the diffuse color component L of the shading point. diff .
[0076] In other examples, the diffuse color component can be expressed using the first n terms of the spherical harmonic function to obtain a result, and then the diffuse color component can be expressed again using the first m terms of the spherical harmonic function to obtain another result. The final result can be a linear or nonlinear combination of the two results, for example, the final result can be the sum, average, weighted average, etc. of the two results.
[0077] For example, the first 3, first 5, first 7, first 9, first 11, and first 13 terms of the spherical harmonic function are used to express the diffuse color component once. For example, expressing the diffuse color component through the first 3 terms will result in a result expressed as L3, expressing the diffuse color component through the first 5 terms will result in a result expressed as L5, expressing the diffuse color component through the first 7 terms will result in a result expressed as L7, expressing the diffuse color component through the first 9 terms will result in a result expressed as L9, and expressing the diffuse color component through the first 11 terms will result in a result expressed as L 11 , expressing the diffuse color component through the first 13 items will give a result, expressed as L 13 Therefore, the final diffuse color component can be expressed as: L diff =∑ρ i L i i=3,5,7,9,11,13 (6)
[0078] Among them, ρ i Is the influencing factor coefficient, which can be pre-configured as an empirical value. L3 is the result obtained by expressing the diffuse color component through the first three items, and the others are similar.
[0079] 2. Specular illumination component of the shading point (L spec ) determination process.
[0080] It should be noted that in the traditional rendering process, only the diffuse color component is considered, and the specular lighting component is not considered. In the embodiment of the present application, it is taken into account that in a real scene, when light hits the surface of an object, specular lighting may also be generated. For example, for an object with a certain glossy material (for example, a metal material), specular lighting will be generated when light hits the surface of the object. Therefore, in order to improve the rendering fidelity, in the embodiment of the present application, the specular lighting component L of the shading point is also calculated. spe .
[0081] Optionally, the specular lighting component L spe Satisfies the following formula:
[0082] Among them, k g is the specular reflection coefficient, which can be between 0 and 1 and can be pre-set. F is the Fresnel term, R(w i , w0) is the object roughness measurement function, θ represents the latitude coordinate, w i is the angle between the incident light and the pixel normal, L m (w i ) is in w i The intensity of incident light in this direction.
[0083] S203 , obtaining a lighting rendering result of the shading point according to the diffuse reflection color component and the specular lighting component of the shading point.
[0084] For example, the lighting rendering result of a shading point can be obtained by using the above formula (1). The same principle can be used for each shading point to obtain the lighting rendering result of each shading point. A patch can include multiple shading points, and the lighting rendering result of each shading point is obtained, that is, the lighting rendering result of the patch is obtained. A 3D model can include multiple patches, and the lighting rendering result of each patch is obtained, that is, the lighting rendering result of the 3D model is obtained.
[0085] In some examples, the diffuse color component and the specular lighting component of each shading point can be stored for subsequent use (this process is also called a pre-calculation process), for example, as shown in Table 1 below.
[0086] Table 1
[0087] Therefore, if the electronic device needs to display the same virtual scene again, it only needs to read the specular lighting component and diffuse color component of the shading point from Table 1 above to obtain the lighting rendering result of the shading point, which is highly efficient. Optionally, for static lighting, the diffuse color component and specular lighting component of the shading point can be stored in a pre-calculated manner. For dynamic lighting, the diffuse color component and specular lighting component of the shading point can be calculated in real time.
[0088] The above S201 to S203 are used to illustrate the lighting rendering process, and the following S204 to S206 are used to illustrate the shadow rendering process.
[0089] To facilitate understanding, the principle of shadow generation in the virtual scene is first explained. When there is a light source in the virtual scene, each 3D model in the scene may be illuminated by the light source. With the light source as the center, any space blocked by an occluder is a shadow space. The occluder is also called an obstacle. The part in the shadow space can be understood as a shadow receiver, and the surface facing the light source will have the shadow of the obstacle. Therefore, it is necessary to render a shadow in this part (the part in the shadow space). For example, please refer to Figure 4, which is a schematic diagram of a shadow principle. In Figure 4, due to the occlusion of the obstacle, a part of the ground is located in the shadow space, and this part needs to be rendered with a shadow (that is, the shadow of the obstacle). Therefore, S204 to S206 below are used to illustrate the shadow rendering process.
[0090] S204: Calculate the size of the shadow filter kernel according to the light source size and the occlusion distance.
[0091] It is understandable that before S204 , the electronic device may determine the light source size and the shielding distance.
[0092] In some examples, the electronic device may determine the size of the light source in a manner that: as described above, in S201, the electronic device obtains relevant information about the virtual scene, including the size of the light source. For example, if the light source is a surface light source, the size of the light source is the area of the surface light source, which can be expressed as S light That is, the virtual scene information obtained by the electronic device in S201 includes the size S of the light source. light .
[0093] In some examples, the occlusion distance includes the depth difference between the shadow receiver and the obstacle. For the shadow receiver, please refer to the previous description. It should be noted that, with the light source as the center, the farther the object is from the light source, the greater the depth, and the closer the object is to the light source, the smaller the depth. Exemplarily, continuing with Figure 4 as an example, the way in which the electronic device determines the occlusion distance may include: determining the depth value of the shadow receiver (Receiver), expressed as dreceiver, determining the depth value of the obstacle (Blocker), expressed as dbloker, and determining the depth difference between the depth value of the shadow receiver and the depth value of the obstacle as the occlusion distance, expressed as dreceiver-dbloker.
[0094] It should be noted that, before this, the depth of the shadow receiver dreceiver and the depth value of the obstacle dbloker need to be determined.
[0095] One possible way is to draw a shadow map with the center of the light source as the perspective, and then determine the depth of the shadow receiver dreceiver and / or the depth of the obstacle dbloker based on the shadow map. Drawing a shadow map with the center of the light source as the perspective may include: setting a camera (such as a depth camera) at the center of the light source, and obtaining a depth image of one or more pixels in the virtual scene through the camera, i.e., a shadow map. It can be simply understood that when viewing the virtual scene from the center of the light source as the perspective, the pixels that can be seen are the pixels that can receive light, and the pixels that cannot be seen are the pixels in the shadow area. Therefore, the shadow map records the depth of the pixels that can be seen when the center of the light source is used as the perspective.
[0096] Therefore, one possible approach is to use the average depth of all pixels in the virtual scene, excluding those on the shadow map, as the depth dreceiver of the shadow receiver. Of course, the depth dreceiver of the shadow receiver can also be determined in other ways, which are not limited in this embodiment of the application.
[0097] Optionally, after obtaining the shadow map, the electronic device may determine an average depth of all pixels in the shadow map as dbloker. Alternatively, the electronic device may filter out some pixels in the shadow map, where the average depth of these pixels is dbloker. The filtered pixels include pixels in the shadow map whose depth values are less than dreceiver.
[0098] After obtaining the light source size and occlusion distance, the electronic device can calculate the size of the shadow filter kernel based on the light source size and occlusion distance (i.e., S204). The shadow filter kernel is used to determine a search area in the shadow map. The pixels within the search area can be used to determine the shadow values of the pixels within the shadow area, so it is called a shadow filter kernel. The size of the shadow filter kernel is the size of the search area, and the specific method will be described later.
[0099] One possible implementation is to store the correspondence between the light source size, the occlusion distance, and the shadow filter kernel size in the electronic device, and determine the size of the shadow filter kernel based on the correspondence. For example, the correspondence is shown in Table 2 below:
[0100] Table 2
[0101] Optionally, the above correspondence relationship (eg, Table 2 above) may be pre-stored in the electronic device. Determining the size of the shadow filter kernel using the above correspondence relationship is relatively efficient.
[0102] Another possible implementation is, continuing with FIG4 as an example, the electronic device can calculate the size of the shadow filter kernel according to the light source size and the occlusion distance. For example, the calculation method includes: S penumbra =(d receiver -d blocker )S light / d blocker
[0103] Among them, S penumbra is the size of the shadow filter kernel. S light Indicates the light source size, d receiver Indicates the depth value of the shadow recipient, d blocker Indicates the depth value of the occluder.
[0104] S205 , determining the shadow value of the pixel point located in the shadow area in the virtual scene according to the size of the shadow filter kernel.
[0105] Optionally, before S205, the step of determining pixels in the virtual scene that are within the shadow area may be further included. In one possible implementation, the electronic device determines that all pixels in the virtual scene, excluding pixels on the shadow map, are pixels within the shadow area.
[0106] The electronic device may determine the shadow value of each pixel in the shadow area according to the size of the shadow filter kernel, including but not limited to the following methods:
[0107] Method 1: The electronic device stores a correspondence between the filter kernel size and the shadow value of the pixel point. Based on the correspondence, the shadow value of the pixel point can be determined.
[0108] Other methods may include: taking the first pixel point in the shadow area as an example, the first pixel point can be any pixel point in the shadow area. The electronic device determines the second pixel point in the shadow map, and the second pixel point corresponds to the first pixel point. The correspondence here can be understood as that the shadow (or projection) generated by the second pixel point is located on the first pixel point in the shadow area. With the second pixel point as the center and Spenumbra or c*Spenumbra as the radius, a search area is determined on the shadow map, and the search area may include multiple pixel points. The electronic device determines the shadow value of the first pixel point based on the number of pixels and / or depth values in the search area, including but not limited to the following methods:
[0109] Method 2: The electronic device determines the total number of all pixels in the search area as number a. The electronic device may also determine the total number of all pixels in the virtual scene having a depth value less than depth value 1 (the depth value of the first pixel) as number b, and determine a ratio of number a to number b, where the ratio is the shadow value of the first pixel.
[0110] Method three: The electronic device determines that the total depth value of all pixels in the search area is depth value 2, and determines that the total depth value of all pixels in the virtual scene whose depth value is less than depth value 1 (the depth value of the first pixel) is depth value 3, and determines the ratio of depth value 2 to depth value 3, which is the shadow value of the first pixel.
[0111] Method 4: The electronic device determines that the average depth value of all pixels in the search area is depth value 4, and determines that the average depth value of all pixels in the virtual scene whose depth value is less than depth value 1 (the depth value of the first pixel) is depth value 5, and determines the ratio of depth value 4 to depth value 5, which is the shadow value of the first pixel.
[0112] In the above, the search area is a circle, and the radius of the circle is Spenumbra or c*Spenumbra. It should be noted that the search area can also be other shapes, such as a square, and the side length of the square is Spenumbra or c*Spenumbra. In short, the embodiment of the present application does not limit the shape of the search area.
[0113] Optionally, the above method involves a parameter c. In the embodiment of the present application, c can be a fixed value, or a dynamically changeable value. Taking the dynamic change of c as an example, one possible implementation method is that the electronic device can determine the value of c based on the ambient brightness of the virtual scene. For example, if the environment is brighter, the value of c is larger, and if the environment is darker, the value of c is smaller. Among them, the ambient brightness of the virtual scene is positively correlated with the intensity and / or area of the light source. Another possible method is that the electronic device can determine the value of c based on the user's perspective. It can be understood that the ambient brightness perceived by the user is different at different perspectives, so the value of c is different. For example, the electronic device stores the correspondence between each perspective and the value of c. Based on the correspondence, the value of c corresponding to the current perspective can be determined, and then the search area is determined according to the value of c.
[0114] S206 , obtaining a shadow rendering result of the pixel point according to the shadow value of the pixel point in the shadow area.
[0115] Optionally, after obtaining the shadow value of each pixel in the shadow area, the shadow value of the pixel may be smoothed, for example, by performing Gaussian blur processing, to make the shadow smoother and more realistic.
[0116] In some examples, the shadow value of each pixel in the shadow area can be stored for subsequent use (this process is also called a pre-calculation process), for example, stored as Table 3 below.
[0117] Table 3
[0118] Therefore, if the electronic device needs to display the same virtual scene again, it only needs to read the shadow value of the pixel from the above Table 2 to obtain the shadow rendering result of the pixel.
[0119] The rendering method provided in the embodiment of the present application can be implemented by a rendering engine. For example, the rendering engine may include software code for implementing the rendering method provided in the embodiment of the present application.
[0120] One possible scenario is that a 3D application is installed in the mobile phone. The application package of the 3D application includes a rendering engine for rendering the 3D model using the rendering method provided in the embodiment of the present application.
[0121] Another possible scenario is that the rendering engine can also be built into the mobile phone's operating system, that is, the mobile phone's operating system can use the rendering method provided in the embodiments of this application to render the 3D model. To save memory, if the mobile phone's operating system includes a rendering engine, the 3D application application package may not include the rendering engine.
[0122] Another possible scenario is that the 3D application installed in the mobile phone belongs to a 3D application client, and the developer of the 3D application not only provides a 3D application client, but also provides a 3D application server. The 3D application server can be located on a cloud server. The 3D application server may include a rendering engine for rendering the 3D model using the rendering method provided in the embodiment of the present application. Taking the 3D application as an example, the game developer of the game application provides a game application client and a game application server. The game application client is provided to the user through the Internet (for example, an application store) for downloading and installing on the user terminal (for example, a mobile phone). The game application server is located in the cloud server. The game application server includes a rendering engine.
[0123] Optionally, when the rendering engine is located in the 3D application server, the 3D application client may not include the rendering engine.
[0124] In the case where the rendering engine is located on the 3D application server, one possible implementation is that after the mobile phone launches the 3D application client and receives a user input operation, the mobile phone sends the user input instruction to the 3D application server. In response to the user input instruction, the 3D application server calls the rendering engine on the 3D application server, uses the rendering method provided in the embodiment of the application to generate a rendering result, and then sends the rendering result to the 3D client on the mobile phone for display to the user. This method reduces the rendering task on the mobile phone side and can avoid lag.
[0125] As mentioned above, the rendering engine can be located in the 3D application server, and the 3D application server can be located on the cloud server. Generally speaking, the 3D application server is provided by the 3D application developer, and the cloud server is provided by the cloud service provider. For example, the 3D application developer rents a cloud server from the cloud service provider to install the 3D application server. Therefore, there is also a possible situation, that is, the cloud server provided by the cloud service provider includes a rendering engine for implementing the rendering method provided in the embodiment of the present application. It can be understood that the rendering engine is provided by the cloud service provider. In this way, the 3D application developer does not need to develop a rendering engine, that is, the 3D application server provided by the 3D application developer may not include a rendering engine.
[0126] The following describes the rendering process of the rendering engine by taking the example of integrating the rendering engine into the operating system of a mobile phone.
[0127] For example, see Figure 5, which shows a schematic diagram of the software structure of an electronic device according to one embodiment of the present application. The software structure of an electronic device is a layered structure. A layered architecture divides the software into several layers, each with distinct roles and divisions of labor. Layers communicate with each other via software interfaces.
[0128] As shown in Figure 5, the application layer may include a series of application packages. For example, 3D applications may include 3D game applications, VR / AR applications, etc.
[0129] The application framework layer includes a 3D rendering service that can call the rendering engine. One possible implementation is that when a 3D application in the application layer requires rendering, it can call the rendering engine through the 3D rendering service. For example, a 3D application can call the 3D rendering service through an API (not shown in the figure), which in turn calls the rendering engine through the 3D rendering service. Therefore, this API can be understood as a communication bridge between the application in the application layer and the 3D rendering service.
[0130] The rendering engine can include three parts: engine API module, engine feature module, and engine core module.
[0131] The engine API module includes one or more API interfaces, which can be understood as the entry point for the upper layer (e.g., the application framework layer) to call the rendering engine. For example, the 3D rendering service in the application framework layer calls the rendering engine through the engine API module.
[0132] The engine feature modules include a material module, a lighting / shadow module, and a rendering pipeline, etc. Among them, the material module includes material texture maps, which are used to render material effects on the surface of the 3D model, as described above. The lighting / shadow module includes lighting rendering parameters and shadow rendering parameters. The lighting rendering parameters are, for example, Table 1 mentioned above, which includes the diffuse color component and the specular lighting component of each shading point on the 3D model, which are used to render lighting effects on the surface of the 3D model. The shadow rendering parameters are, for example, Table 3 mentioned above, which includes the shadow value of each pixel in the shadow area of the virtual scene, which is used to render shadow effects on the surface of the 3D model. Among them, the process of determining the lighting rendering parameters can be found in S201 to S203 in Figure 2, and the process of determining the shadow rendering parameters can be found in S204 to S206 in Figure 2. The rendering pipeline is used to transmit rendering commands to the application layer.
[0133] The engine core includes: a resource management module for managing resources in 3D applications, such as the model identifier of each 3D model, as well as the face number, shading point number, pixel number in the shadow area, etc. on the 3D model.
[0134] The hardware layer includes various hardware, such as GPU, which is used to render 3D models.
[0135] It should be noted that, in FIG5 , the rendering engine is shown as being located between the application framework layer and the hardware layer. In practice, the rendering engine can also be located in other layers. For example, the rendering engine can also be located in the application layer or the application framework layer.
[0136] The following is an illustrative description of the rendering process provided in the embodiment of the present application in conjunction with Figures 5 and 6.
[0137] (1) The 3D application in the application layer is started. Optionally, a possible implementation method is that after the 3D application is started, an application root node and a page manager can be created. The application root node can be understood as the total node of the 3D application, and all nodes of the application can be mounted as child nodes under the root node, where different child nodes can correspond to different interfaces. The page manager can manage different interfaces. For example, the page manager can determine the display information contained in each interface. It can be understood that an interface can include 2D components or 3D components. For example, an interface has an area displaying 3D components and another area displaying 2D components. Optionally, a 3D component can include one or more 3D models. A 2D component can include 2D images, text, etc. If an interface includes a 3D component, it is necessary to render the 3D component based on the resources of the 3D component. The resources of the 3D component can be understood as the resources required for the 3D component to achieve the expected display effect. For example, the resources of a 3D component may include the face number of the 3D model, the shading point number, the pixel number of the shadow area, the lighting rendering parameters of the shading point, the shadow rendering parameters of the pixels in the shadow area, etc. Optionally, the resources of a 3D component may also include the position information and size information (e.g., width and height) of the 3D component within the page.
[0138] (2) The 3D application calls the 3D rendering service of the application framework layer to render the 3D component. Optionally, the 3D application may provide the 3D rendering service with an identifier of the 3D component. Optionally, the identifier of the 3D component may include a model identifier of the 3D model.
[0139] (3) The 3D rendering service calls the rendering engine to render the 3D component. For example, the 3D rendering service creates a 3D drawing node. Optionally, a 3D drawing node may correspond to one or more 3D components. Optionally, the 3D drawing node includes an identifier of the 3D component and may also include attributes of the 3D component, such as position information, size information, etc.
[0140] (4) The rendering engine obtains the corresponding 3D model face number, shading point number, shadow area pixel number, etc. through the resource management module according to the model identifier of the 3D model.
[0141] (5) The rendering engine obtains the lighting rendering parameters of each shading point (for example, Table 1 above) according to the shading point number through the lighting / shadow module in the engine feature module, including the diffuse color component and the specular lighting component.
[0142] (6) The rendering engine obtains the shadow rendering parameters (for example, Table 3 above) of each pixel point, including the shadow value of the pixel point, through the lighting / shadow module in the rendering engine feature module according to the pixel point number in the shadow area.
[0143] (7) The rendering engine sends a rendering command to the GPU to instruct the GPU to render. The rendering command includes the lighting rendering parameters and shadow rendering parameters of the 3D model.
[0144] (8) GPU performs rendering.
[0145] Figure 6 is a structural diagram of an electronic device 600 provided in an embodiment of the present application. The electronic device 600 may be the mobile phone mentioned above. As shown in Figure 6, the electronic device 600 may include: one or more processors 601; one or more memories 602; a communication interface 603, and one or more computer programs 604, and the above-mentioned devices may be connected via one or more communication buses 605. The one or more computer programs 604 are stored in the above-mentioned memory 602 and are configured to be executed by the one or more processors 601, and the one or more computer programs 604 include instructions. For example, when the electronic device 600 is the mobile phone mentioned above, the instruction can be used to execute the relevant steps of the mobile phone in the corresponding embodiment above, for example, the steps in the embodiment shown in Figure 2. The communication interface 603 is used to realize communication between the electronic device 600 and other devices, for example, the communication interface may be a transceiver.
[0146] In the embodiments provided in the present application above, the method provided in the embodiment of the present application is introduced from the perspective of an electronic device (e.g., a mobile phone) as an execution subject. In order to implement the various functions in the method provided in the embodiment of the present application above, the electronic device may include a hardware structure and / or a software module to implement the above functions in the form of a hardware structure, a software module, or a hardware structure plus a software module. Whether a function of the above functions is executed in the form of a hardware structure, a software module, or a hardware structure plus a software module depends on the specific application and design constraints of the technical solution.
[0147] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described above according to the embodiments of the present invention are generated. The aforementioned computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The aforementioned computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)). In the absence of conflict, the solutions of the above embodiments can be used in combination.
[0148] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0149] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each flow and / or box in the flow chart and / or block diagram, as well as the combination of the flow chart and / or box in the flow chart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more flow charts and / or one or more boxes in the block diagram.
[0150] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0151] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0152] Obviously, those skilled in the art may make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include these modifications and variations.
Claims
1. A rendering method, characterized in that: include: Determine a shadow map of the virtual scene based on a position of a light source in the virtual scene to be rendered, wherein the shadow map includes depth information of pixels in the virtual scene illuminated by the light source; Determine a target area in the shadow map according to a first pixel in the virtual scene, wherein the first pixel is located in a shadow area in the virtual scene, the shadow area is an area in the virtual scene that is not illuminated by the light source, and the target area includes a second pixel, and a projection of the second pixel in the shadow area corresponds to the first pixel; Render the shadow of the first pixel according to the number and / or depth value of the pixels in the target area.
2. The method according to claim 1, characterized in that Rendering the shadow of the first pixel according to the number and / or depth value of the pixel points in the target area includes: Determine a first value according to the number of pixels and / or depth values in the target area; The shadow of the first pixel is rendered according to a ratio between the first value and a second value, where the second value is a default value or is determined according to a first depth value of the first pixel.
3. The method according to claim 2, characterized in that The first value includes: The total number of pixels in the target area; or The average depth value of all pixels in the target area; or The sum of the depth values of all pixels in the target area.
4. The method according to claim 2, characterized in that: The second value is determined according to the first depth value of the first pixel, including: The second value is the total number of pixels in the virtual scene whose depth value is less than the first depth value; or The second value is an average depth value of all pixels in the virtual scene whose depth values are smaller than the first depth value; or The second value is the sum of the depth values of all pixels in the virtual scene whose depth values are less than the first depth value.
5. The method according to claim 1, characterized in that Rendering the shadow of the first pixel according to the number of pixels and / or the depth value of the pixel in the target area includes: Determining the shadow value corresponding to the number of pixels in the target area according to a first corresponding relationship between the number of pixels and the shadow value; and / or, Determining the shadow value corresponding to the pixel depth value in the target area according to a second corresponding relationship between the pixel depth value and the shadow value; Rendering a shadow of the first pixel according to the shadow value.
6. The method according to any one of claims 1 to 5, characterized in that: The target area includes: an area with the second pixel as the center and a first size as the radius, where the first size is a default value or is determined according to the size of the light source and / or the depth difference between the first pixel and the second pixel.
7. The method according to any one of claims 1 to 5, characterized in that: The target area includes: an area with the second pixel as the center and a first size as the radius, the first size is equal to c times the second size, c is a positive number, the second size is a default value or is determined according to the size of the light source and / or the depth difference between the first pixel and the second pixel, and the value of c is a default value or is determined according to the ambient brightness of the virtual scene and / or the user's perspective.
8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: Determine a first shading point on the 3D model to be rendered in the virtual scene, where the first shading point is any shading point on the 3D model; Obtaining the diffuse color component and the specular illumination component of the first shading point; A lighting rendering result of the first shading point is obtained according to the diffuse color component and the specular lighting component.
9. The method according to claim 8, characterized in that Obtaining the diffuse color component and specular illumination component of the first shading point, including: Determine, according to the number of the first shading point, a diffuse reflection color component corresponding to the first shading point in a third corresponding relationship, where the third corresponding relationship is a corresponding relationship between the numbers of each shading point and the diffuse reflection color component; According to the number of the first shading point, the specular illumination component corresponding to the first shading point is determined in a fourth corresponding relationship, and the fourth corresponding relationship is a corresponding relationship between the numbers of each shading point and the specular illumination component.
10. The method according to claim 8 or 9, characterized in that: The lighting rendering result of the first shading point includes a linear combination of the diffuse color component and the specular lighting component.
11. An electronic device, characterized in that: The electronic device includes a 3D application and a rendering engine, and the rendering engine is located in an application package of the 3D application or in an operating system of the electronic device; The 3D application is used to display a virtual scene on a display screen of the electronic device; The rendering engine is used to execute the method according to any one of claims 1-10.
12. An electronic device, characterized in that: The electronic device includes a 3D application client, and the 3D application client is used to send a rendering instruction to the 3D application server and receive a rendering result returned by the 3D application server; The 3D application server includes a rendering engine, or the 3D application server is installed in a cloud server and the 3D application server can call the rendering engine in the cloud server, and the rendering engine is used to execute the method according to any one of claims 1-10.
13. A cloud server, characterized in that: The cloud server includes a 3D application server, and the 3D application server includes a rendering engine, or the cloud server includes a rendering engine and the rendering engine allows the 3D application server to call, and the rendering engine is used to execute the method according to any one of claims 1-10.
14. An electronic device, characterized in that: include: a processor, a memory, and one or more programs; The one or more programs are stored in the memory, and the one or more programs include instructions, and when the instructions are executed by the processor, the electronic device performs the method steps as described in any one of claims 1 to 10.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and when the computer program is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Fast percentage approach soft shadow drawing method
CN109493406A
Shadow softening graphics processing unit and method
US20140176546A1
Rendering method and apparatus
WO2023088047A1