Rendering method and electronic equipment

By determining the target area in the shadow map and rendering the shadow according to the number of pixels and depth values, the problem of insufficient shadow changes in the shadow area are solved, and higher rendering fidelity and anti-aliasing are achieved.

CN119722909APending Publication Date: 2025-03-28HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311765737.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-09-28
Filing Date
2023-12-20
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

Existing 3D rendering technology is difficult to achieve realistic shadow rendering in shadow areas, resulting in insufficient shadow changes being smooth and soft enough, and insufficient anti-aliasing.

Method used

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 smoother and softer.

Benefits of technology

Improves the smoothness and softness of pixels in the shadowed area in the virtual scene, enhances the anti-aliasing of rendering, thereby improving the vividness of rendering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119722909A_ABST
    Figure CN119722909A_ABST
Patent Text Reader

Abstract

A rendering method and an electronic device are used for improving the rendering fidelity of a virtual scene. For example, an electronic device determines a shadow map of a virtual scene to be rendered based on a position of a light source in the virtual scene. The shadow map comprises depth information of pixel points irradiated by the light source in the virtual scene. The electronic equipment determines a target area in the shadow map according to a first pixel point in the virtual scene, the first pixel point is located in a shadow area in the virtual scene, the shadow area is an area which cannot be irradiated by a light source in the virtual scene, the target area comprises a second pixel point, and projection of the second pixel point in the shadow area corresponds to the first pixel point. And the electronic equipment renders the shadow of the first pixel point according to the number and / or the depth value of the pixel points in the target area.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application claims the priority of the Chinese patent application filed with the China Patent Office on September 28, 2023, with application number 202311292708.4 and application name “3D Object Rendering Method”, all contents of which are incorporated by reference in this application. Technical Field

[0002] The present application relates to the field of terminal technology, and in particular to a rendering method and an electronic device. Background Art

[0003] Three-dimensional (3D) rendering technology refers to rendering 3D models based on 3D model data (such as object geometry, surface material, etc.) and light data (including light source position, intensity, etc.). The rendered 3D model is close to real objects in the real world under the same lighting conditions, giving viewers an immersive experience as if they were in the real world. Taking 3D games as an example, generally speaking, players will be attracted by the realistic rendering of the game screen, so high-quality rendering of 3D models is a technology that application developers are constantly pursuing. Summary of the invention

[0004] The embodiments of the present application provide a rendering method and an electronic device for improving the rendering fidelity of a 3D model.

[0005] 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, the first pixel is located in a shadow area in the virtual scene, the shadow area is an area not illuminated by the light source in the virtual scene, the target area includes a second pixel, and 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.

[0006] 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 fidelity of the virtual scene. Moreover, the shadow of a pixel (e.g., a first pixel) in the shadow area is determined according to the number of pixels and / or depth value in the area (i.e., the target area) where the pixel (e.g., the second pixel) corresponding to the pixel is located on the shadow map. The same principle can be used for 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 gentle, 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 according to 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 according to 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.

[0007] In one possible design, an electronic device renders a shadow of a first pixel based on the number of pixels and / or depth values ​​in a 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, wherein the second value is a default value or is determined based on the first depth value of the first pixel.

[0008] In the embodiment of the present application, the shadow of a pixel point (e.g., the first pixel point) in the shadow area of ​​the virtual scene is determined according to the number of pixels and / or depth value in the area (i.e., the target area) where the pixel point (e.g., the second pixel point) corresponding to the pixel point on the shadow map is located. The same principle can be used for the shadow of each pixel point in the shadow area, so that the shadow change of two adjacent pixels in the shadow area will not be too abrupt, but relatively gentle and soft.

[0009] 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.

[0010] 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 a 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.

[0011] 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.

[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 values ​​in the area (i.e., the target area) where a 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.

[0013] In one possible design, an electronic device renders a shadow of a 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 corresponding relationship 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 corresponding relationship between the depth value of the pixel and the shadow value; and rendering the shadow of the first pixel based on the shadow value.

[0014] 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.

[0015] 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.

[0016] In some examples, the first size may have other names, for example, filter kernel size. In an embodiment of the present application, the filter kernel size may be determined according to 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 thereby improving the accuracy of the target area and the accuracy of the shadow.

[0017] In one possible design, the target area includes: an area with a 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.

[0018] 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.

[0019] In a possible design, the rendering method further includes: the electronic device determines 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. The electronic device obtains a diffuse color component and a specular illumination component of the first shading point. The electronic device obtains a lighting rendering result of the first shading point based on the diffuse color component and the specular illumination component.

[0020] 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.

[0021] In one possible design, the electronic device obtains the diffuse color component and the specular illumination component of the first shading point, including: determining the diffuse color component corresponding to the first shading point in a third correspondence relationship according to the number of the first shading point, the third correspondence relationship being the correspondence between the numbers of each shading point and the diffuse color component; determining the specular illumination component corresponding to the first shading point in a fourth correspondence relationship according to the number of the first shading point, the fourth correspondence relationship being the correspondence between the numbers of each shading point and the specular illumination component.

[0022] 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.

[0023] 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.

[0024] 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.

[0025] 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 used to display a virtual scene on a display screen of the electronic device. The rendering engine is used to execute the method provided in the first aspect above.

[0026] In a third aspect, an electronic device is also provided. The electronic device includes a 3D application client. 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 provided in the first aspect above.

[0027] In a fourth aspect, a cloud server is further 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 and the rendering engine allows the 3D application server to call. The rendering engine is used to execute the method provided in the first aspect above.

[0028] In a fifth aspect, an electronic device is also provided, including:

[0029] a processor, a memory, and one or more programs;

[0030] 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.

[0031] 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, the computer executes the method provided in the first aspect above.

[0032] In a seventh aspect, a computer program product is provided, comprising a computer program, which, when executed on a computer, enables the computer to execute the method provided in the first aspect.

[0033] 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.

[0034] For the technical effects that can be achieved by 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

[0035] Figure 1 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application;

[0036] Figure 2 A schematic diagram of a flow chart of a rendering method provided in an embodiment of the present application;

[0037] Figure 3 A schematic diagram of a face sheet provided in an embodiment of the present application;

[0038] Figure 4 A schematic diagram of the filter kernel size provided in an embodiment of the present application;

[0039] Figure 5 Another structural schematic diagram of an electronic device provided in one embodiment of the present application;

[0040] Figure 6 A schematic diagram of a page node provided in accordance with an embodiment of the present application. DETAILED DESCRIPTION

[0041] Below, some terms in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.

[0042] The at least one involved in the embodiments of the present application includes one or more; wherein, a plurality refers to greater than or equal to two. In addition, it should be understood that in the description of this specification, the words "first", "second", etc. are only used for the purpose of distinguishing the description, and cannot be understood as an explicit or implicit relative importance, nor can they be understood as an explicit or implicit 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 associated with each other are in an "or" relationship.

[0043] References to "one embodiment", "in some examples" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the specification. Thus, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", "in some examples", "in some other examples", etc. appearing in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0044] As used in this specification, the term “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 phrase “upon determining that” or “if (stated condition or event) is detected” may be interpreted to mean “if determining 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.

[0045] The rendering method provided in the embodiment of the present application is applicable to electronic devices. Exemplary, 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 a 3D application may be included in an electronic device (e.g., a mobile phone), 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.

[0046] Figure 1 FIG. 1 is a schematic diagram showing the hardware structure of an electronic device. Figure 1As shown, 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 screen 194, and a subscriber identification module (SIM) card interface 195, etc. 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.

[0047] 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 processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). Among them, different processing units may be independent devices or integrated into one or more processors. Among them, the controller may be the nerve center and command center of the electronic device. The controller may generate an operation control signal according to the instruction opcode and the timing signal to complete the control of fetching and executing instructions. A memory may also be set in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a high-speed cache memory. The memory may store instructions or data that the processor 110 has just used or circulated. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. Repeated access is avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved. Optionally, the rendering method provided in the embodiment of the present application may be executed by the processor 110 .

[0048] In some embodiments, the processor 110 may include one or more interfaces. The interface 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, etc.

[0049] The wireless communication function of the electronic device can be implemented by antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modulation and demodulation processor and 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 the utilization of the antenna. For example, antenna 1 can be reused as a diversity antenna of a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0050] 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.

[0051] 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.

[0052] The internal memory 121 may be used to store computer executable program codes, which include instructions. The processor 110 executes the instructions stored in the internal memory 121 to perform various functional applications and data processing of the electronic device.

[0053] Understandably, Figure 1 The components shown do not constitute a specific limitation on the electronic device. The electronic device in the embodiment of the present application may include Figure 1 In addition, Figure 1 The combination / connection relationship between the components can also be adjusted and modified.

[0054] The rendering method provided by the embodiment of the present application is described below with reference to the accompanying drawings.

[0055] See also Figure 2 , is a flow chart of a rendering method provided by an embodiment of the present application. The process may include two parts, one of which is lighting rendering, which includes Figure 2 S201 to S203 in the other part is shadow rendering, which includes Figure 2 S204 to S206 in. Figure 2 As shown, the process includes:

[0056] S201, obtaining relevant information of the virtual scene.

[0057] One possible scenario is that after the electronic device starts a certain 3D application, the interface of the 3D application will be displayed, and the interface includes a virtual scene, so the electronic device will obtain relevant information of the virtual scene after starting the 3D application. One possible way is that the electronic device obtains relevant information of 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.

[0058] In some examples, the 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 the real scene is generally a surface light source, the embodiments of the present application are mainly described by taking the light source as a surface light source as an example.

[0059] In some examples, the relevant information of the virtual scene includes light source data and data of one or more 3D models to be rendered. The light source data may include the position, intensity, shape, size, etc. of the light source. The data of the 3D model to be rendered may include the position, size, posture, and face division of the 3D model in the virtual scene, face number, geometric parameters and material parameters of the face, etc. The content about the face will be explained later.

[0060] It should be understood that in a real scene, a light source (e.g., 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 contact point, 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 contact point, 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.

[0061] In order to improve the rendering precision, the embodiment of the present application can divide the surface of the 3D model to be rendered into a certain number of small planes. These planes are also called facets (also known as grids or other names), which can be any 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 can be divided into different ways of facets. For example, 3D models with different shapes may have different shapes and quantities of facets. It is understandable that the size of the facets can be set as needed, and the higher the accuracy requirement for the rendered image, the smaller the size of the facets can be set.

[0062] The relevant information of the virtual scene acquired by the electronic device in S201 includes: the face division of the 3D model to be rendered, the face number, the geometric parameters and material parameters of the face. The face division may include, for example, the number and position of the face. The face number is used to uniquely identify the face. The geometric parameters of the face are used to describe the shape and size of the face. For example, see Figure 3As shown, 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, 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, and the image includes pixel information, such as red, green, and blue (RGB) colors, and 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 is not described in detail in the embodiments of the present application. Mapping a pixel value (e.g., color value) on a map at different positions on the unfolded 2D plane is equivalent to pasting a picture on the surface of a 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, where N is a positive integer, and each face corresponds to a map, etc., which is not limited in the embodiments of the present application.

[0063] S202, calculating the diffuse color component and the specular lighting component of each shading point on the 3D model to be rendered according to the relevant information of the virtual scene.

[0064] To make it easier to understand, let's first briefly explain the coloring point. Figure 3 Take the facet shown in the figure as an example. After the light generated by the light source contacts the surface of the facet, diffuse reflection occurs at the contact point to generate reflected light. When the reflected light enters the user's eyes, the color of the contact point on the facet is seen. Therefore, the contact point between the light and the facet can be understood as a shading point. For a facet, the number of contact points between the light and the facet can be one or more, so a facet can include one or more shading points. For example, Figure 3 Here p1, p2 and p3 are three different coloring points.

[0065] 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:

[0066] L=L diff +L spec (1)

[0067] 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 It refers to the specular illumination 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.

[0068] The following describes the diffuse color component (L diff ) and the specular illumination component (L spec ) determination process.

[0069] 1. The process of determining the diffuse color component of a shading point.

[0070] In the embodiment of the present application, the diffuse reflection color component of the shading point can satisfy the following formula:

[0071]

[0072] where θ represents the latitude coordinate (e.g., Figure 3 The polar angle θ in Represents a longitude coordinate (for example, Figure 3 The azimuth angle α in the figure is α, 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, of light intensity. is a spherical harmonic function and can be expressed as the following function:

[0073]

[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]

[0076]

[0077] Therefore, the spherical harmonic function is a polynomial, and in some examples, spherical harmonic functions can be used The diffuse color component is approximated by the first n terms of diff For example, when n=9, we only need to use the first 9 terms of the spherical harmonic function and substitute them into formula (2) to obtain the diffuse color component L of the shading point: diff .

[0078] 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, and the final result can be obtained through these two results. The final result can be a linear or nonlinear combination of the two results, for example, the final result is the sum, average, weighted average, etc. of the two results.

[0079] For example, the diffuse color component is expressed once using the first 3, first 5, first 7, first 9, first 11, and first 13 items of the spherical harmonic function. For example, expressing the diffuse color component through the first 3 items will result in a result, expressed as L3, expressing the diffuse color component through the first 5 items will result in a result, expressed as L5, expressing the diffuse color component through the first 7 items will result in a result, expressed as L7, expressing the diffuse color component through the first 9 items will result in a result, expressed as L9, and expressing the diffuse color component through the first 11 items will result in a result, expressed as L 11 , expressing the diffuse color component through the first 13 items will get a result, expressed as L 13 . Therefore, the final diffuse color component can be expressed as:

[0080] L diff =∑ρ i L i i=3,5,7,9,11,13 (6)

[0081] Among them, i It 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.

[0082] 2. Specular illumination component of the shading point (L spec ) determination process.

[0083] 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 considered that in a real scene, when light shines on 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 shines on 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 .

[0084] Optionally, the specular lighting component L spe Satisfies the following formula:

[0085]

[0086] 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, and 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 normal of the pixel, L m (w i ) is in w i The intensity of incident light in a certain direction.

[0087] 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.

[0088] For example, the lighting rendering result of the shading point can be obtained by 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.

[0089] In some examples, the diffuse color component and the specular lighting component of each shading point may be stored for subsequent use (this process is also referred to as a pre-calculation process), for example, as shown in Table 1 below.

[0090] Table 1

[0091]

[0092]

[0093] 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 the above Table 1 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, and for dynamic lighting, the diffuse color component and specular lighting component of the shading point can be calculated in real time.

[0094] The above S201 to S203 are used to illustrate the illumination rendering process, and the following S204 to S206 are used to illustrate the shadow rendering process.

[0095] To facilitate understanding, the principle of shadow generation in virtual scenes is explained first. When there is a light source in a virtual scene, each 3D model in the scene may be illuminated by the light source. With the light source as the center, all spaces blocked by occluders are shadow spaces. Occluders are also called obstacles. 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, see Figure 4 , which is a schematic diagram of the shadow principle. Figure 4 In the example, due to the occlusion of obstacles, a part of the ground is located in the shadow space, and this part needs to be rendered with a shadow (ie, the shadow of the obstacle). Therefore, the following S204 to S206 are used to illustrate the shadow rendering process.

[0096] S204, calculating the size of the shadow filter kernel according to the light source size and the occlusion distance.

[0097] It is understandable that before S204, the electronic device may determine the light source size and the shielding distance.

[0098] In some examples, the electronic device may determine the size of the light source in a manner as described above. In S201, the electronic device obtains relevant information about the virtual scene, and the relevant information includes 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 relevant information of the virtual scene acquired by the electronic device in S201 includes the size S of the light source. light .

[0099] In some examples, the occlusion distance includes the depth difference between the shadow recipient and the obstacle. The shadow recipient is described above. 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. Figure 4For example, the electronic device may determine the occlusion distance by: determining the depth value of a shadow receiver (Receiver), expressed as dreceiver, determining the depth value of an 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.

[0100] It should be noted that, before this, it is necessary to determine the depth of the shadow receiver dreceiver and the depth value of the obstacle dbloker.

[0101] 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 perspective of the center of the light source, 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.

[0102] Therefore, one possible method is that the average depth of all pixels in the virtual scene except the pixels on the shadow map is the depth dreceiver of the shadow receiver. Of course, the depth dreceiver of the shadow receiver can also be determined in other ways, which is not limited in the embodiments of the present application.

[0103] Optionally, after obtaining the shadow map, the electronic device may determine that the average depth of all pixels in the shadow map is dbloker. Alternatively, the electronic device filters out some pixels in the shadow map, and the average depth of these pixels is dbloker. The filtered out pixels include pixels on the shadow map whose depth values ​​are less than dreceiver.

[0104] After the electronic device obtains the light source size and the occlusion distance, it can calculate the size of the shadow filter kernel according to the light source size and the occlusion distance (i.e., S204). The shadow filter kernel is used to determine the search area in the shadow map, and the pixels in the search area can be used to determine the shadow values ​​of the pixels in the shadow area, so it is called the 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.

[0105] One possible implementation is that the electronic device stores the correspondence between the light source size, the occlusion distance and the shadow filter kernel size, and determines the size of the shadow filter kernel according to the correspondence. For example, the correspondence is shown in Table 2 below:

[0106] Table 2

[0107] Light source size Occlusion distance Shadow filter kernel size X1 Y1 Z1 … … …

[0108] Optionally, the above correspondence relationship (such as Table 2 above) may be pre-stored in the electronic device. It is more efficient to determine the size of the shadow filter kernel according to the above correspondence relationship.

[0109] Another possible implementation is to continue with Figure 4 For 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:

[0110] S penumbra =(d receiver -d blocker )S light / d blocker

[0111] 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.

[0112] 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.

[0113] Optionally, before S205, the step of: determining pixels in the virtual scene that are located in the shadow area may be included. A possible implementation is that the electronic device determines that all pixels in the virtual scene except the pixels on the shadow map are pixels in the shadow area.

[0114] 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:

[0115] Method 1: The electronic device stores a correspondence between the filter kernel size and the shadow value of the pixel point, and based on the correspondence, the shadow value of the pixel point can be determined.

[0116] Other methods may include: taking the first pixel in the shadow area as an example, the first pixel may be any pixel in the shadow area. The electronic device determines a second pixel in the shadow map, and the second pixel corresponds to the first pixel. The correspondence here may be understood as the shadow (or projection) generated by the second pixel is located on the first pixel in the shadow area. With the second pixel 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 pixels. The electronic device determines the shadow value of the first pixel based on the number of pixels and / or depth values ​​in the search area, including but not limited to the following methods:

[0117] 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 whose depth value is less than the depth value 1 (the depth value of the first pixel) as number b, and determine the ratio of number a to number b, which is the shadow value of the first pixel.

[0118] 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.

[0119] 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 values ​​are 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.

[0120] 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.

[0121] Optionally, in the above method, a parameter c is involved. In the embodiment of the present application, c may be a fixed value, or a dynamically changeable value. Taking the dynamic change of c as an example, a possible implementation method is that the electronic device can determine the value of c according to 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 according to the user's perspective. It can be understood that the ambient brightness perceived by the user at different perspectives is different, so the value of c is different. For example, the electronic device stores the correspondence between each perspective and the value of c, and 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.

[0122] S206, obtaining a shadow rendering result of the pixel point according to the shadow value of the pixel point in the shadow area.

[0123] 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.

[0124] 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 the following Table 3.

[0125] Table 3

[0126]

[0127] 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.

[0128] The rendering method provided in the embodiment of the present application may 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.

[0129] One possible situation is that a 3D application is installed in the mobile phone. The application package of the 3D application includes a rendering engine, which is used to render the 3D model using the rendering method provided in the embodiment of the present application.

[0130] Another possible situation is that the rendering engine can also be built into the operating system of the mobile phone, that is, the operating system of the mobile phone can use the rendering method provided in the embodiment of the present application to render the 3D model. In order to save memory, when the operating system of the mobile phone includes a rendering engine, the application package of the 3D application may not include the rendering engine.

[0131] Another possible situation is that the 3D application installed in the mobile phone belongs to the 3D application client, and the developer of the 3D application not only provides the 3D application client, but also provides the 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 a game 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 a cloud server. The game application server includes a rendering engine.

[0132] Optionally, when the rendering engine is located in the 3D application server, the 3D application client may not include the rendering engine.

[0133] In the case where the rendering engine is located on the 3D application server, a possible implementation method is that after the mobile phone starts the 3D application client, it receives a user input operation, and the mobile phone sends the user input instruction to the 3D application server. The 3D application server responds to the user input instruction and calls the rendering engine in the 3D application server, uses the rendering method provided in the embodiment of the present application to generate a rendering result, and then sends the rendering result to the 3D client in the mobile phone to display it to the user. In this way, the amount of rendering tasks on the mobile phone side is reduced to avoid freezes.

[0134] 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.

[0135] The following uses the example of a rendering engine integrated into an operating system of a mobile phone to illustrate the rendering process of the rendering engine.

[0136] For example, see Figure 5 , is a schematic diagram of the software structure of an electronic device provided in an embodiment of the present application. The software structure of the electronic device is a layered structure. The layered architecture is to divide the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces.

[0137] like Figure 5 The application layer may include a series of application packages. For example, 3D applications. Exemplarily, 3D applications may include 3D game applications, VR / AR applications, and the like.

[0138] The application framework layer includes a 3D rendering service that can call a rendering engine. One possible implementation is that when a 3D application in the application layer has a rendering requirement, it can call the rendering engine for rendering through the 3D rendering service. For example, a 3D application can call a 3D rendering service through an API interface (not shown in the figure), and then call the rendering engine through the 3D rendering service. Therefore, the API interface can be understood as a communication bridge between the application in the application layer and the 3D rendering service.

[0139] The rendering engine may include three parts: engine API module, engine feature module, and engine core module.

[0140] 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.

[0141] The engine feature modules include material modules, lighting / shadow modules, and rendering pipelines. The material module includes material texture maps, which are used to render material effects on the surface of the 3D model. Please refer to the previous description. The lighting / shadow module includes lighting rendering parameters and shadow rendering parameters. The lighting rendering parameters are shown in Table 1 above, which include 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. Shadow rendering parameters are shown in Table 3 above, which include the shadow value of each pixel in the shadow area of ​​the virtual scene, which are used to render shadow effects on the surface of the 3D model. For the determination process of lighting rendering parameters, please refer to Figure 2 For the process of determining the shadow rendering parameters, see S201 to S203 in Figure 2 S204 to S206 in the above. The rendering pipeline is used to transmit rendering commands to the application layer.

[0142] The engine core includes: a resource management module for managing resources in 3D applications, such as model identifiers of various 3D models, as well as face numbers, shading point numbers, pixel numbering in shadow areas, etc. on the 3D models.

[0143] The hardware layer includes various hardware, such as GPU, which is used to render 3D models.

[0144] It should be noted that Figure 5In the example, the rendering engine is located between the application framework layer and the hardware layer. In fact, 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.

[0145] Combined with the following Figure 5 and Figure 6 , exemplarily illustrating the rendering process provided in the embodiment of the present application.

[0146] (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, a 3D component is displayed in one area of ​​an interface and a 2D component is displayed in another area. 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 pixel 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 in the page.

[0147] (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.

[0148] (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 properties of the 3D component, such as position information, size information, etc.

[0149] (4) The rendering engine obtains the face number, shading point number, pixel number of the shadow area, etc. of the corresponding 3D model through the resource management module according to the model identifier of the 3D model.

[0150] (5) The rendering engine obtains the lighting rendering parameters of each shading point (for example, Table 1 above), including the diffuse color component and the specular lighting component, through the lighting / shadow module in the engine feature module according to the shading point number.

[0151] (6) The rendering engine obtains the shadow rendering parameters (for example, Table 3 above) of each pixel, including the shadow value of the pixel, through the illumination / shadow module in the rendering engine feature module according to the pixel number in the shadow area.

[0152] (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.

[0153] (8) GPU for rendering.

[0154] Figure 6 The electronic device 600 provided in the embodiment of the present application is a schematic diagram of the structure. The electronic device 600 may be the mobile phone mentioned above. Figure 6 As shown, 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 components 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 instructions can be used to execute the relevant steps of the mobile phone in the corresponding embodiment above, for example, Figure 2 The steps in the embodiment shown in . The communication interface 603 is used to implement the communication between the electronic device 600 and other devices, for example, the communication interface can be a transceiver.

[0155] In the embodiments provided by the present application, the method provided by the embodiments 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 functions in the methods provided by the embodiments of the present application, the electronic device may include a hardware structure and / or a software module to implement the functions in the form of a hardware structure, a software module, or a hardware structure plus a software module. Whether a function of the functions described above 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.

[0156] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part 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, the aforementioned process or function according to the embodiment of the present invention is generated in whole or in part. The aforementioned computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The aforementioned computer instructions may 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 may be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may 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 Solid State Disk (SSD)), etc. In the absence of conflict, the solutions of the above embodiments can be used in combination.

[0157] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may 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 may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0158] 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 process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart 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 generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0159] These computer program instructions may also be stored in a computer-readable memory capable of directing 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 an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0160] 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, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0161] Obviously, those skilled in the art can 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 also 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.