Image rendering method, electronic device, storage medium and computer program product
By modifying the computational data of the rendering scene to draw a second light source space depth map of the target model, and combining the light source space depth map to perform shadow calculation, the problem of insufficient shadow quality of a single model is solved, and efficient shadow rendering effect is achieved.
Patent Information
- Application Number
- CN202511447813.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-10
- Publication Date
- 2026-02-13
AI Technical Summary
In existing technologies, the shadow quality of a single model in a rendered scene cannot meet expectations, and the utilization rate of the light source space depth map is not high, resulting in shadow loss or insufficient shadow quality.
The system collects the first computational data of the rendering scene and the bounding box attribute values of the target model, modifies the computational data to draw the second light source spatial depth map corresponding to the target model, calculates the shadow effect using percentage progressive soft shadow technology, and samples the depth value by combining the first and second light source spatial depth maps.
It improves the shadow quality of single models, makes full use of the shadow acquisition range of the light source space depth map, reduces computing power consumption, and improves the accuracy and effect of shadow rendering.
Smart Images

Figure CN121527291A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of image rendering, and in particular to an image rendering method, an electronic device, a storage medium and a computer program product. BACKGROUND
[0002] The rendering engine usually draws a depth map based on the light source direction for the shadow rendering of all models in the rendering scene, and each model samples the light source space depth map when rendering the color to determine the occlusion relationship of each color point; in the related technology, the camera distance is usually divided into four levels by using a cascaded shadow map (CSM), for example, the camera distance is divided into four levels, and the models at different distances are drawn on the light source space depth map of the corresponding level, so as to achieve the effect of shadow drawing based on light source space depth maps with different accuracies.
[0003] However, when a single model in the rendering scene is displayed, although the shadow quality of the model can be improved by setting a closer light source space depth map collection distance, the utilization rate of the light source space depth map of each level is not high due to the fixed collection position of the light source space depth map of the scene, so that the shadow quality obtained by the single model based on the closer light source space depth map for shadow calculation cannot meet the expectation; if the light source space depth map collection distance is set too close in order to improve the shadow quality of the model, the collection range of the light source space depth map will be small, and if the single model exists in the action display, the shadow loss will be caused due to the fact that the single model is out of the collection range of the light source space depth map. SUMMARY
[0004] Therefore, the embodiments of the present application provide an image rendering method, an electronic device, a storage medium and a computer program product, which aim to improve the shadow quality of a single model in a rendering scene.
[0005] The technical scheme of the embodiments of the present application is as follows: In a first aspect, the embodiments of the present application provide an image rendering method, which comprises: collecting first calculation data of a rendering scene and attribute values of a bounding box of a target model; the first calculation data is used to draw a first light source space depth map of the rendering scene; modifying the first calculation data based on the attribute values of the bounding box to obtain second calculation data; drawing a second light source space depth map corresponding to the target model based on the second calculation data; drawing a shadow effect of the target model based on the second light source space depth map.
[0006] In the above scheme, the first calculation data of the rendering scene is collected, which comprises: acquire a first view space matrix and a first projection matrix used for drawing the first light source space depth map; The attribute value of the bounding box of the target model includes model information and a dynamic range of the target model. Based on the model information and the dynamic range of the target model, a center point of the bounding box and a spherical wrapping radius are obtained.
[0007] In the above scheme, the second calculation data is obtained by modifying the first calculation data based on the attribute value of the bounding box, including: Based on the first view space matrix and the first projection matrix, a position of the center point of the bounding box in the first light source space depth map is calculated. Based on the position of the center point of the bounding box in the first light source space depth map, an offset between the center point of the bounding box and the center point of the first light source space depth map is calculated. Based on the spherical wrapping radius, a scaling ratio of the first light source space depth map is calculated. Based on the offset and the scaling ratio, a second view space matrix and a second projection matrix are obtained by modifying the first view space matrix and the first projection matrix.
[0008] In the above scheme, the second light source space depth map corresponding to the target model is drawn based on the second calculation data, including: Based on the second view space matrix and the second projection matrix, the second light source space depth map corresponding to the target model is drawn. The center point of the bounding box is located at the center point of the second light source space depth map.
[0009] In the above scheme, the shadow effect of the target model is drawn based on the second light source space depth map, including: Based on the first light source space depth map and the second light source space depth map, a Percentage Closer Filtering (PCF) result of each target shading point of the target model is calculated by a Percentage Closer Soft Shadows (PCSS) technique. Based on the PCF result of each target shading point, a soft shadow effect of the target model is drawn.
[0010] In the above scheme, the PCF result of each target shading point of the target model is calculated by the PCSS technique based on the first light source space depth map and the second light source space depth map, including: The depth value of the target shading point in the second light source space depth map is taken as a reference depth value, a depth occlusion result of the target shading point in the first light source space depth map is searched, and an average occluder depth corresponding to the target shading point is calculated; Based on the average occluder depth, a first sampling range of the target shading point in the second light source space depth map is calculated; Based on the first sampling range, a light source space depth map used for depth value sampling is determined, and depth value sampling is performed on the determined light source space depth map to calculate the PCF result of the target shading point.
[0011] In the above scheme, based on the first sampling range, a light source space depth map used for depth value sampling is determined, and depth value sampling is performed on the determined light source space depth map to calculate the PCF result of the target shading point, including: If the first sampling range is less than or equal to a set sampling range, depth value sampling is performed in the second light source space depth map based on the first sampling range to calculate the PCF result of the target shading point; If the first sampling range is greater than the set sampling range, the first sampling range is converted into a second sampling range in the first light source space depth map, and depth value sampling is performed in the first light source space depth map based on the second sampling range to calculate the PCF result of the target shading point.
[0012] In a second aspect, an embodiment of the present application provides an electronic device, including a processor and a memory for storing a computer program capable of running on the processor, wherein the processor is configured to run the computer program to perform the steps of the method in the first aspect.
[0013] In a third aspect, an embodiment of the present application provides a storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the method in the first aspect.
[0014] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program, and the computer program is executed by a processor to implement the steps of the method in the first aspect.
[0015] The technical scheme provided in the embodiment of the application comprises the following steps: collecting attribute values of a bounding box of a target model and first calculation data of a rendering scene; the first calculation data is used to draw a first light source space depth map of the rendering scene; the attribute values of the bounding box are used to modify the first calculation data, so as to obtain second calculation data; the second calculation data is used to draw a second light source space depth map corresponding to the target model; and the second light source space depth map is used to draw a shadow effect of the target model. In this way, the single model to be displayed is matched with the light source space depth map, and the shadow effect of the model is drawn based on the newly drawn light source space depth map. Since the model can fully utilize the shadow collection range of the newly drawn light source space depth map, the shadow quality of the single model is improved. BRIEF DESCRIPTION OF DRAWINGS
[0016] Figure 1 A flowchart of an image rendering method according to an embodiment of the application is shown in FIG. 1. Figure 2 A schematic diagram of a bounding box of a model in an application example is shown in FIG. 2. Figure 3 A schematic diagram of a light source-shield-shadow receiving surface according to an embodiment of the application is shown in FIG. 3. Figure 4 A schematic diagram of pixel ranges of light source space depth maps according to an embodiment of the application is shown in FIG. 4. Figure 5 A structural schematic diagram of an image rendering device according to an embodiment of the application is shown in FIG. 5. Figure 6 A structural schematic diagram of an electronic device according to an embodiment of the application is shown in FIG. 6. DETAILED DESCRIPTION
[0017] The application will be described in further detail below with reference to the drawings and embodiments.
[0018] In the following description, “some embodiments” are described, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.
[0019] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.
[0020] Before the image rendering method provided in the embodiments of the application is described in further detail, the terms and nomenclature involved in the embodiments of the application are described, and the terms and nomenclature involved in the embodiments of the application are applicable to the following explanations.
[0021] Shadow Map: A 2D image recording the distance from each visible point in a 3D rendering scene to a light source from the perspective of the light source. Each pixel in the Shadow Map represents a depth value, indicating the distance from the nearest model surface that the light source can directly illuminate. Shadow Maps are commonly used to render shadow effects for models. By comparing the depth of the model to the light source with the depth value at the corresponding position in the Shadow Map, it can be determined whether the model is occluded.
[0022] Bounds: A virtual boundary container that completely encloses a model, containing all the vertices of the model. It is used to simplify computational tasks that require the model's outline by representing the complex geometry with a simple geometric shape. Common forms of Bounds include Axis-Aligned Bounds, Directional Bounds, Oriented Bounds, and Sphere Bounds.
[0023] Percentage-Closer Filtering (PCF): A shadow rendering technique that gradually transitions the shadow edge by taking multiple sampling points around the current pixel and calculating the proportion of sampling points closer to the light source. This proportion determines the shadow intensity of the pixel, thereby achieving a gradual transition of the shadow edge. PCF is commonly used to optimize the jagged edges of hard shadows.
[0024] Percentage-Closer Soft Shadows (PCSS): An extension of PCF, PCSS generates realistic soft shadows with "near-hard and far-soft" characteristics by dynamically adjusting the shadow blur range. This addresses the issue of PCF's inability to represent the distance-dependent blur of shadows.
[0025] Cascaded Shadow Maps (CSM): An optimization technique for shadow rendering that divides the camera's view frustum into multiple cascaded layers along the depth direction. Each cascaded layer generates a resolution-adapted Shadow Map, resulting in high-resolution shadows for close-range models and low-resolution shadows for distant models.
[0026] The embodiments of the present application provide an image rendering method, as shown in Figure 1 The method comprises the following steps: Step 101: Collecting first calculation data of a rendering scene and attribute values of a Bounds of a target model. The first calculation data is used to draw a first Shadow Map of the rendering scene.
[0027] Step 102: Modifying the first calculation data based on the attribute values of the Bounds to obtain second calculation data.
[0028] Step 103: Drawing a second Shadow Map corresponding to the target model based on the second calculation data.
[0029] In step 104, a shadow effect of the target model is drawn based on the second light source space depth map.
[0030] Here, the target model is a model marked in the rendering scene; in some embodiments, the target model is a single model; in some embodiments, the target model includes a model that needs to be shown close to the user.
[0031] Here, in this application, the light source space depth map is used to draw the shadow effect of the model, that is, the shadow map and the light source depth space map are technical features with the same connotation.
[0032] Here, the first light source space depth map is a light source space depth map drawn based on the rendering scene; the first light source space depth map includes a single-layer light source space depth map of the rendering scene or a first-layer light source space depth map in the cascaded shadow map of the rendering scene.
[0033] It can be understood that when performing image rendering, a single-layer light source space depth map can be generated based on the rendering scene, and each object in the rendering scene is shadow rendered based on the single-layer light source space depth map; for a rendering scene with a large camera depth, a plurality of levels of cascaded shadow maps can also be generated, and the light source space depth map of each level corresponds to a plurality of cascaded layers segmented along the depth direction based on the camera frustum. The resolution of the light source space depth map closest to the camera is higher, and each object in the rendering scene is shadow rendered based on the corresponding level of the light source space depth map according to the camera depth, which can achieve the effect of using high-resolution shadow for close-range models and using low-resolution shadow for long-distance models.
[0034] Here, the first-layer light source space depth map in the cascaded shadow map is the light source space depth map closest to the camera in the cascaded shadow map, that is, the light source space depth map with the highest resolution in the cascaded shadow map.
[0035] It can be understood that before step 101 is performed, the method further includes drawing the first light source space depth map of the rendering scene.
[0036] In some embodiments, when the rendering engine performs image rendering on the rendering scene, the corresponding calculation data is generated based on the configured light source attribute, the frustum range, the precision parameter, and the rendering object filtering parameter, and the coordinates of the model are converted based on the calculation data. Finally, the depth values of each position in the light source space are calculated based on the converted coordinates, and the first light source space depth map is obtained.
[0037] The light source attributes configured in the rendering engine include, but are not limited to: light source type, light source position, and light source orientation; the configured view frustum range includes, but is not limited to: near clipping plane and far clipping plane; the configured precision parameters include, but are not limited to: depth map resolution and depth format; and the configured rendering object filtering parameters include, but are not limited to: static object markers and dynamic object markers.
[0038] The calculated data of the light source spatial depth map is used to perform coordinate transformation on the model, including but not limited to: view matrix and projection matrix; correspondingly, in step 101, the first calculated data of the rendering scene is collected, including: the first view matrix and the first projection matrix used to draw the first light source spatial depth map.
[0039] Here, the view space matrix, also known as the view matrix or observation matrix, is used to convert world space coordinates into view space coordinates from the camera's perspective; the projection matrix is used to convert view space coordinates into two-dimensional clipping space coordinates. In essence, the view space matrix and projection matrix, as techniques for converting the model's three-dimensional world space coordinates into two-dimensional coordinates, are indispensable computational data for drawing light source depth maps.
[0040] It should be noted that some models in the rendering scene need to be displayed at close range (for example, in a game, players zoom in to observe the details of the character model up close), so the requirements for the shadow quality of these single models are higher.
[0041] In related technologies, shadow rendering of the entire scene model is usually achieved by rendering the light space depth map of the scene. Since the shadow quality of the model is directly related to the resolution of the depth map, cascaded shadow mapping technology is usually used to draw multiple layers of light space shadow maps based on the rendering scene. For single models that need to be displayed at close range, the layer depth map that is close to the camera and has a high resolution is selected to draw the shadows in order to improve the shadow quality of the model.
[0042] However, even if multiple layers of light space shadow maps are drawn based on the rendering scene to match the models at different distances from the camera, the acquisition position of each layer of light space shadow map is fixed and needs to be used for shadow drawing of multiple models in the rendering scene. This results in low utilization of the light space depth map at each layer. Therefore, even if the single model is used to calculate shadows based on the closer light space depth map, the shadow quality obtained still cannot meet expectations.
[0043] It should be noted that in the embodiments of the present application, for the target model with high shadow quality requirement, the generated light source space depth map is not used in the shadow calculation, but a second light source space depth map matched with the target model is redrawn, and the shadow effect of the target model is drawn based on the depth map, that is, in the rendering of the shadow, the remaining models in the rendering scene except the target model marked are drawn based on the light source space depth map of the rendering scene, and each target model is drawn based on the corresponding newly drawn second light source space depth map.
[0044] Here, since the first calculation data at least includes the first view space matrix and the first projection matrix, correspondingly, the second calculation data obtained after the first calculation data is modified at least includes the second view space matrix and the second projection matrix; correspondingly, based on the second calculation data, the second light source space depth map corresponding to the target model is drawn, including: based on the second view space matrix and the second projection matrix, the second light source space depth map corresponding to the target model is drawn. It is easy to understand that based on the second view space matrix and the second projection matrix, a new light source space depth map can be drawn.
[0045] It should be noted that the second calculation data is obtained after the first calculation data is modified based on the attribute value of the bounding box of the target model; as Figure 2 As shown, the person model and the box model in the rendering scene are marked as target models respectively, and the attribute values of the bounding boxes of the target models are collected through the editing tool. Since the geometric shape of the bounding box is simple, the calculation amount of generating the second calculation data can be reduced.
[0046] It can be understood that in the embodiments of the present application, by collecting the attribute values of the bounding boxes representing the spatial boundaries of the target models, the first calculation data corresponding to the generated first light source space depth map is modified, so that the range of the second light source space depth map drawn based on the second calculation data obtained after the modification matches the target model, and the second light source space depth map can be fully utilized when the shadow effect of the target model is drawn.
[0047] It can be understood that in the embodiments of the present application, by collecting the attribute values of the bounding boxes representing the spatial boundaries of the target models, the first calculation data corresponding to the generated first light source space depth map is modified, so that the second light source space depth map drawn based on the second calculation data obtained after the modification matches the spatial range of the target model; in this way, when the shadow effect of the target model is drawn, the second light source space depth map can be fully utilized, the resolution waste is avoided, and the shadow quality of the target model is improved.
[0048] Exemplarily, the attribute value of the bounding box of the target model is collected, including: collecting model information and a dynamic range of the target model; and obtaining a center point of the bounding box and a spherical wrapping radius based on the model information and the dynamic range of the target model.
[0049] It should be noted that the target model can have action display requirements, for example, to display character animation. If the attribute value of the bounding box is collected by only generating the bounding box based on the static model information of the target model and drawing the matching second light source space depth map, the actual space range of the target model may exceed the shadow collection range of the second light source space depth map as the target model performs actions, resulting in shadow loss. In the embodiment of the present application, the dynamic range of the target model is additionally collected when the attribute value of the bounding box of the target model is collected. The dynamic range includes the spatial information corresponding to all preset action displays of the target model, so that the shadow collection range of the second light source space depth map drawn based on the collected attribute value of the bounding box of the target model can cover the spatial boundaries of the target model in various action displays, and the situation of shadow loss does not occur.
[0050] Here, the attribute value of the bounding box includes the center point of the bounding box and the spherical wrapping radius. Since the target model may be displaced and the model posture may change when it is displayed, the center point of the bounding box can more accurately reflect the current spatial position of the target model than the center point of the target model. The spherical bounding box generated based on the spherical wrapping radius includes the vertices of the target model in various action displays, that is, the target model will not exceed the spatial boundaries of the spherical bounding box when it performs action display.
[0051] In some embodiments, the collected spherical wrapping radius is the minimum spherical wrapping radius, that is, the minimum spherical radius that can completely wrap all action vertices of the target model. The resolution of the corresponding generated second light source space depth map can be maximized based on the modification of the first calculation data based on the minimum spherical wrapping radius.
[0052] Here, after the attribute value of the bounding box of the target model is collected, the attribute value is transmitted to the shadow drawing pipeline of the rendering engine for generating second calculation data.
[0053] Exemplarily, the first calculation data is modified based on the attribute value of the bounding box to obtain second calculation data, including: calculating the position of the center point of the bounding box in the first light source space depth map based on the first view space matrix and the first projection matrix; calculating the offset between the center point of the bounding box and the center point of the first light source space depth map based on the position of the center point of the bounding box in the first light source space depth map; calculating the scaling ratio of the first light source space depth map based on the spherical wrapping radius; and modifying the first view space matrix and the first projection matrix based on the offset and the scaling ratio to obtain a second view space matrix and a second projection matrix.
[0054] Here, the light source space depth map is essentially a two-dimensional texture, and the position of the first light source space depth map is the geometric center of the corresponding texture coordinate range, i.e., the reference position of the central region; for example, if the texture coordinate range of the first light source space depth map is [0, 1] x [0, 1], the central point of the first light source space depth map is located at the (0.5, 0.5) coordinate point.
[0055] Here, after the first view space matrix and the first projection matrix are modified, a second view space matrix and a second projection matrix are obtained; the center point of the bounding box is located at the center point of the second light source space depth map drawn based on the second view space matrix and the second projection matrix.
[0056] It should be noted that the center point of the bounding box obtained based on the model information and the dynamic range of the target model is a world space coordinate, and the position of the center point of the bounding box in the first light source space depth map can be obtained by transforming the center point of the bounding box in the world space through the first view space matrix and the first projection matrix, and then performing perspective division and mapping processing, which is the texture coordinate in the first light source space depth map. It is easy to understand that based on the texture coordinates of the center point of the bounding box and the center point of the first light source space depth map, the offset in the corresponding texture coordinate system can be calculated, which is used to modify the first calculation data, so that the center point of the second light source space depth map drawn based on the modified second calculation data coincides with the center point of the bounding box, and when the shadow effect of the target model is drawn, the target model is located in the central region of the second light source space depth map.
[0057] Here, the spherical wrapping radius of the bounding box includes all the motion ranges of the target model, and based on the spherical wrapping radius, the scaling ratio of the target model on the first light source space depth map is calculated, so that the shadow collection range of the second light source space depth map drawn based on the modified second calculation data matches the target model, and when the shadow effect of the target model is drawn, the resolution of the second light source space depth map can be maximally utilized to improve the shadow quality of the target model.
[0058] Here, after the scaling ratio is calculated, the offset between the center point of the bounding box and the center point of the first light source space depth map is scaled based on the scaling ratio, so as to move the texture coordinate of the center point of the bounding box of the target model to the direction of the center point of the first light source space depth map based on the spherical wrapping radius of the target model.
[0059] Here, based on the offset and the scaling ratio, the first projection matrix is modified, including: based on the scaling ratio, modifying the first element and the second element of the first projection matrix; wherein the first element is located in the zeroth row and the zeroth column of the first projection matrix, and the second element is located in the first row and the first column of the first projection matrix.
[0060] Here, the first element and the second element of the first projection matrix are modified based on the scaling ratio, and the center point position of the first projection matrix is adjusted based on the offset.
[0061] Here, the first element is a zero-row zero-column element of the first projection matrix, and the second element is a one-row one-column element of the first projection matrix; in the projection matrix, the zero-row zero-column element represents a scaling coefficient of a horizontal direction (x-axis) of a view space coordinate mapping to a clipping coordinate, and the one-row one-column element represents a scaling coefficient of a vertical direction (y-axis) of the view space coordinate mapping to the clipping coordinate; it can be easily understood that, based on the scaling ratio, the first element and the second element of the first projection matrix are modified, the planar scaling value of the light source space depth map can be adjusted, so that the newly drawn second light source space depth map can just wrap the bounding box of the target model.
[0062] Here, after the second light source space depth map is drawn, it is transmitted to a shadow drawing pipeline of a rendering engine, and when a shadow effect of the target model needs to be drawn, the corresponding second light source space depth map is called to draw.
[0063] Here, when the center point position of the bounding box of the target model changes, the second calculation data is updated based on the updated center point, so that the center point of the bounding box of the target model can still be located at the center point of the updated second light source space depth map.
[0064] It can be understood that even if the target model exceeds the shadow collection range of the first light source space depth map in the process of displacement and action change, it will not affect the shadow rendering effect of the target model based on the second light source space depth map.
[0065] It can be understood that, in the related art, even if the cascaded shadow technology is adopted, the first layer light source space depth map is drawn based on the segmentation plane close to the distance camera, but the first layer light source space depth map needs to provide shadow collection and rendering functions for multiple models under the current camera view, and the proportion of the target model to be displayed by a single model in the first layer light source space depth map is still small, and the first layer light source space depth map cannot be fully utilized when the shadow of the target model is rendered. In order to ensure that the target model has good shadow quality, the resolution of the first layer light source space depth map needs to be at least set to 4096x4096, which causes great consumption of computing resources. Based on the image rendering method of the embodiment of the application, for the target model to be displayed by a single model, the rendering engine redraws the high-precision second light source space depth map corresponding to the target model. Since the second light source space depth map is obtained based on the offset and scaling of the first light source space depth map, one pixel in the second light source space depth map can cover 2x2 or even 4x4 pixels in the first light source space depth map. Therefore, the shadow effect drawn by the target model based on the second light source space depth map with a resolution of 1024x1024 can achieve the shadow precision when the shadow effect is drawn based on the first light source space depth map with a resolution of 4096x4096. The shadow quality of the target model is improved by using less computing resources.
[0066] In some embodiments, in order to further improve the shadow quality of the target model, on the basis of shadow rendering of the target model based on the newly drawn second light source space depth map, the application also provides a soft shadow rendering optimization method. Specifically, based on the second light source space depth map, the shadow effect of the target model is drawn, including: based on the first light source space depth map and the second light source space depth map, calculating the PCF result of each target shading point of the target model by PCSS technology; based on the PCF result of each target shading point, drawing the soft shadow effect of the target model.
[0067] It should be noted that when drawing the shadow effect of the model in the rendering scene, the depth value of the shading point of the contrast model and the depth value of the corresponding sampling point in the shadow map are usually used to determine whether the shading point is in the shadow. Due to insufficient sampling accuracy, hard shadow distortion occurs, and jaggies appear at the edge of the shadow, affecting the shadow quality. In order to solve the problem of hard shadow distortion, in the related art, PCF technology is usually used to blur the edge of the shadow to obtain a soft shadow effect.
[0068] It should be noted that the core idea of the PCF technology is that when rendering the shadow effect of a target shading point, instead of collecting the single-point depth value of the corresponding sampling point, multi-point sampling is performed on the corresponding sampling point and the field point (for example, a sampling range of 3x3 or 5x5), occlusion judgment is performed based on the depth value of each sampling point, the occlusion results corresponding to all sampling points are weighted and averaged to obtain the occlusion percentage of the target shading point, and finally the occlusion percentage is used as the shadow lightness, which is mixed with the pixel lighting color of the target shading point. For example, an occlusion percentage of 0.6 indicates that 60% of the area is in the shadow, and finally a soft shadow effect with smooth edges is output, eliminating the hard shadow jaggies.
[0069] It should be noted that the PCF technology as a basic shadow rendering technology only performs weighted averaging on the sampling points in the shadow map during execution, and the blur degree of the shadow edge is fixed, which can only solve the hard shadow jaggies problem and cannot simulate real soft shadow effect. The PCSS technology as an extended shadow rendering technology of the PCF technology can realize the real soft shadow effect that the larger the light source is, the farther the distance between the occluder and the receiver is, and the wider the half shadow is.
[0070] Here, the PCSS technology derives a dynamic shadow radius through an occluder search step, solving the half shadow fixed problem of the PCF technology. The calculation process of the PCSS technology mainly includes the following three steps: 1. calculating the distance between the shader and the average occluder; 2. calculating the sampling range of the PCF rendering using the average occluder distance; and 3. calculating the PCF result based on the obtained sampling range. The method for calculating the sampling range is as shown in the following formula:
[0071] Here, is the half shadow width, i.e., the sampling range of the PCF rendering; is the distance between the shadow receiving surface and the light source; is the average occluder distance; is the light source width. The specific connotation of each parameter of the above formula is as shown in Figure 3
[0072] It should be noted that the computing power consumption of the PCSS technology is mainly concentrated in the above steps 1 and 3. In an example, when performing PCSS shadow rendering, the average occluder depth of the current sampling point and the neighborhood points in the shadow map needs to be searched, for example, using a 7x7 sampling range to search for the occluder. After obtaining the average occluder distance, the sampling range of the PCF rendering is calculated using the principle of similar triangles, for example, it is calculated that a 10x10 sampling range needs to be used to simulate the real soft shadow effect. Therefore, the PCSS shadow rendering process of the target shading point needs to sample the shadow map for a total of 7x7+10x10=149 times. Obviously, compared with the PCF technology, the PCSS technology consumes excessive computing power resources. Therefore, the PCF technology is usually used to draw soft shadow effects in the related art.
[0073] It should be noted that in the embodiments of the present application, the first light source space depth map and the second light source space depth map are mixed sampled, the shadow effect of the target model is softened and blurred by the PCSS technology, the shadow quality is improved, and the computing power consumption in the PCSS shadow rendering process is reduced. Therefore, the PCSS technology does not occupy excessive computing power resources.
[0074] Specifically, based on the first light source space depth map and the second light source space depth map, the PCF result of each target shading point of the target model is calculated by the PCSS technology, including: taking the depth value of the target shading point in the second light source space depth map as a reference depth value, searching the depth occlusion result of the target shading point in the first light source space depth map, and calculating the average occluder depth corresponding to the target shading point; based on the average occluder depth, calculating the first sampling range of the target shading point in the second light source space depth map; if the first sampling range is less than or equal to the set sampling range, then based on the first sampling range, the depth value is sampled in the second light source space depth map, and the PCF result of the target shading point is calculated; if the first sampling range is greater than the set sampling range, then the first sampling range is converted into a second sampling range in the first light source space depth map, and based on the second sampling range, the depth value is sampled in the first light source space depth map, and the PCF result of the target shading point is calculated.
[0075] Here, the method further includes: based on the first calculation data and the second calculation data, calculating the corresponding relationship between each position in the first light source space depth map and the second light source space depth map.
[0076] It can be understood that, based on the conversion relationship between the first view space matrix and the second view space matrix, and the conversion relationship between the first projection matrix and the second projection matrix, the corresponding relationship between positions in the first light source space depth map and the second light source space depth map can be obtained, for example, the coordinate position (0.5, 0.5) in the first light source space depth map corresponds to the coordinate position (0.7, 0.7) in the second light source space depth map.
[0077] Here, the depth occlusion result of the search target shading point in the first light source space depth map includes: based on the sampling point position corresponding to the target shading point in the first light source space depth map, searching for an occluder in the first light source space depth map using a third sampling range, and calculating the depth occlusion result of each sampling point in the third sampling range.
[0078] It should be noted that, in the soft shadow rendering optimization method of the embodiments of the present application, the occluder is searched in the first light source space depth map in the search occluder step; as shown in Figure 4 As can be easily understood, since the single pixel range of the first light source space depth map occupies multiple pixel ranges of the second light source space depth map, searching the first light source space depth map based on a 3x3 sampling range is equivalent to searching the second light source space depth map based on a 6x6 or even 12x12 sampling range, therefore, compared with searching the occluder in the second light source space depth map, searching the occluder in the first light source space depth map in the embodiments of the present application can effectively reduce the sampling times of the search occluder step.
[0079] It can be understood that, since the depth value accuracy of the second light source space depth map is higher than that of the first light source space depth map, the depth value of the target shading point in the second light source space depth map is used as the reference depth value in the search occluder step of the embodiments of the present application.
[0080] Correspondingly, the depth value of the target shading point in the second light source space depth map is used as the reference depth value, the depth occlusion result of the target shading point in the first light source space depth map is searched, and the average occluder depth corresponding to the target shading point is calculated, including: comparing the depth values of the sampling points in the third sampling range with the reference depth value, if the depth value of a sampling point is less than the reference depth value, it is determined that the sampling point is occluded; based on the depth values and the number of the sampling points in the third sampling range that are occluded, the average occluder depth corresponding to the target shading point is calculated.
[0081] Here, the depth values of the sampling points that are occluded are added and divided by the number of the sampling points that are occluded to obtain the average occluder depth corresponding to the target shading point.
[0082] It can be understood that, in the PCSS shadow rendering process, the search step of the occluder is performed in combination with the large search sampling range of the first light source space depth map and the high-precision depth value of the second light source space depth map, so that the number of samplings is reduced while the precision of the average occluder distance is ensured, and the consumption of computing resources is reduced.
[0083] Here, in the embodiments of the present application, after the average occluder depth is obtained, the sampling range of PCF rendering is calculated; the method for calculating the sampling range of PCF rendering can be based on the principle of similar triangles, combined with the above formula, which is not described here.
[0084] It should be noted that, in the embodiments of the present application, after the first sampling range of the target shading point in the second light source space depth map is calculated, the first sampling range is not directly used as the sampling range of PFC rendering, but the first sampling range and the set sampling range are compared, and based on the comparison result of the first sampling range and the set sampling range, it is determined whether the PCF result of the target shading point in the current PCSS shadow rendering process is calculated based on the first light source space depth map or the second light source space depth map. The set sampling range is a sampling range in the second light source space depth map preset based on rendering performance and shadow quality.
[0085] It can be understood that, the larger the sampling range, the more the number of samplings based on the sampling range; for the case that the shadow edge is relatively sharp, since the first sampling range is smaller than or equal to the set sampling range, the number of samplings corresponding to the first sampling range is relatively small, so the first sampling range is directly used as the sampling range of PFC rendering, the depth value is sampled in the second light source space depth map, and the PCF result of the target shading point is calculated; for the case that the half-shadow range is relatively large, since the first sampling range is larger than the set sampling range, the number of samplings corresponding to the first sampling range is relatively large, in order to reduce the number of samplings, the first sampling range is converted based on the corresponding relationship between each position in the first light source space depth map and the second light source space depth map to obtain the corresponding second sampling range in the first light source space depth map, since the single pixel range of the first light source space depth map occupies multiple pixel ranges of the second light source space depth map, the depth value is sampled in the first light source space depth map based on the second sampling range, and the PCF result of the target shading point is calculated, which can effectively reduce the number of samplings in the PCF rendering step.
[0086] In an example, the sampling range setting is set as 6x6, if the calculated first sampling range is 3x3, the depth value sampling is directly performed in the second light source space depth map based on the 3x3 sampling range; if the calculated first sampling range is 20x20, since it exceeds the set sampling range, the 10x10 sampling range of the second light source space depth map is converted into the 4x4 sampling range of the first light source space depth map based on the corresponding relationship between each position in the first light source space depth map and the second light source space depth map, and the depth value sampling is performed in the first light source space depth map based on the 4x4 sampling range.
[0087] It can be understood that, based on the soft shadow rendering optimization method of the embodiments of the present application, the 7x7+10x10 samplings required in the original PCSS shadow rendering process of the target shading point can be simplified to 3x3+4x4 samplings, which improves the quality of the soft shadow effect based on the PCSS technology while reducing the consumption of algorithm resource. In some embodiments, the PCF results of each target shading point of the target model are calculated by the PCSS technology, including: performing a low-resolution processing on the shadow effect of the target model to generate a mask image; determining the edge region of the shadow effect of the target model based on the mask image; calculating the PCF results of each target shading point in the edge region by the PCSS technology, It can be understood that, in order to further reduce the algorithm resource occupied by the PCSS technology, the PCSS shadow rendering is not performed on all shading points of the shadow effect when rendering the shadow effect of the target model; since most of the regions of the shadow effect belong to complete shadow and do not need soft shadow calculation, the mask image is generated by the low-resolution method in the embodiments, and each pixel of the mask image is compared with the corresponding shading point of the shadow effect, if the comparison result of the shading point has a jump from the illumination state to the shadow state, the shading point is marked as a target shading point in the edge region of the bright-dark boundary, and only the soft shadow calculation is performed on each target shading point in the edge region in the subsequent PCSS shadow rendering.
[0088] In order to implement the method of the embodiments of the present application, the embodiments of the present application also provide an image rendering device, which corresponds to the above-mentioned image rendering method, and each step in the above-mentioned image rendering method embodiments is also fully applicable to the device embodiments.
[0089] As Figure 5As shown, the image rendering device of the embodiment of the present application comprises a collection module 501, a calculation module 502, a first drawing module 503 and a second drawing module 504. The collection module 501 is configured to collect first calculation data of a rendering scene and attribute values of a bounding box of a target model; the first calculation data is used to draw a first light source space depth map of the rendering scene; the calculation module 502 is configured to modify the first calculation data based on the attribute values of the bounding box to obtain second calculation data; the first drawing module 503 is configured to draw a second light source space depth map corresponding to the target model based on the second calculation data; and the second drawing module 504 is configured to draw a shadow effect of the target model based on the second light source space depth map.
[0090] In some embodiments, the collection module 501 is specifically configured to: collect a first view space matrix and a first projection matrix used to draw the first light source space depth map; collect model information and a dynamic range of the target model; and obtain a center point of the bounding box and a spherical wrapping radius based on the model information and the dynamic range of the target model.
[0091] In some embodiments, the calculation module 502 is specifically configured to: calculate a position of the center point of the bounding box in the first light source space depth map based on the first view space matrix and the first projection matrix; calculate an offset between the center point of the bounding box and a center point of the first light source space depth map based on the position of the center point of the bounding box in the first light source space depth map; calculate a scaling ratio of the first light source space depth map based on the spherical wrapping radius; and modify the first view space matrix and the first projection matrix based on the offset and the scaling ratio to obtain a second view space matrix and a second projection matrix.
[0092] In some embodiments, the first drawing module 503 is specifically configured to: draw the second light source space depth map corresponding to the target model based on the second view space matrix and the second projection matrix; and wherein the center point of the bounding box is located at the center point of the second light source space depth map.
[0093] In some embodiments, the second drawing module 504 is specifically configured to: calculate a percentage progressive filtering PCF result of each target shading point of the target model by a percentage progressive soft shadow PCSS technique based on the first light source space depth map and the second light source space depth map; and draw a soft shadow effect of the target model based on the percentage progressive filtering PCF result of each target shading point.
[0094] In some embodiments, the second rendering module 504 is specifically configured to: take the depth value of the target shading point in the second light space depth map as a reference depth value, search the depth occlusion result of the target shading point in the first light space depth map, and calculate the average occluder depth corresponding to the target shading point; based on the average occluder depth, calculate the first sampling range of the target shading point in the second light space depth map; based on the first sampling range, determine the light space depth map for depth value sampling, and perform depth value sampling on the determined light space depth map to calculate the PCF result of the target shading point.
[0095] In some embodiments, the second rendering module 504 is specifically configured to: if the first sampling range is less than or equal to a set sampling range, perform depth value sampling in the second light space depth map based on the first sampling range to calculate the percentage progressive filtering PCF result of the target shading point; if the first sampling range is greater than the set sampling range, convert the first sampling range into a second sampling range in the first light space depth map, and perform depth value sampling in the first light space depth map based on the second sampling range to calculate the percentage progressive filtering PCF result of the target shading point.
[0096] It should be noted that the image rendering device provided in the above embodiments is only used as an example for the division of the above program modules when performing image rendering. In actual applications, the above processing can be completed by different program modules according to needs, that is, the internal structure of the device is divided into different program modules to complete all or part of the above processing. In addition, the image rendering device and the image rendering method provided in the above embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiments, which will not be described here.
[0097] Based on the hardware implementation of the above program modules, and in order to implement the image rendering method of the embodiments of the present application, the embodiments of the present application further provide an electronic device, as shown in the Figure 6 The electronic device 600 includes at least one processor 601, a memory 602, a user interface 603, and at least one network interface 604. The various components in the electronic device 600 are coupled together by a bus system 605. It can be understood that the bus system 605 is used to realize the connection and communication between the components. The bus system 605 includes a data bus in addition to power buses, control buses, and status signal buses. However, for the purpose of clear illustration, all kinds of buses are marked as the bus system 605 in the Figure 6 .
[0098] The user interface 603 can include a display, a keyboard, a mouse, a trackball, a click wheel, a key, a button, a touchpad, or a touch screen, etc.
[0099] The memory 602 in the embodiments of the present application is configured to store various types of data to support the operation of the electronic device 600. Examples of the data include any computer programs used for operating the electronic device 600.
[0100] The image rendering method disclosed in the embodiments of the present application can be applied in the processor 601 or implemented by the processor 601. The processor 601 can be an integrated circuit chip having a signal processing capability. In the implementation process, the steps of the image rendering method can be completed by the integrated logic circuits or the instructions in the software form of the hardware in the processor 601. The processor 601 mentioned above can be a general processor, a digital signal processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc. The processor 601 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general processor can be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiments of the present application, the hardware decoding processor can be directly implemented or executed by the hardware and software module combination in the decoding processor. The software module can be located in the storage medium, which is located in the memory 602. The processor 601 reads the information in the memory 602 and combines the hardware to complete the steps of the image rendering method provided in the embodiments of the present application.
[0101] In the exemplary embodiments, the electronic device 600 can be implemented by one or more application specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), FPGAs, general-purpose processors, controllers, microcontrollers (MCUs), microprocessors (Microprocessors), or other electronic elements, for executing the image rendering method mentioned above.
[0102] It is to be understood that the memory 602 can be volatile or nonvolatile memory, or both, and that the memory 602 can include both removable memory and non-removable memory. Non-volatile memory can be read only memory (ROM), programmable ROM (PROM), erasable programmable ROM (EPROM), EEPROM, ferroelectric random access memory (FRAM), flash memory, a magnetic storage disk, a magnetic tape, or a compact disk (CD-ROM). The magnetic storage disk can be a magnetic hard disk or a magnetic tape. Volatile memory can be random access memory (RAM) used as external cache memory. By way of example, and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDR SDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), Sync Link Dynamic Random Access Memory (SLDRAM), and Direct Rambus Random Access Memory (DRRAM). The memory 602 described herein is intended to include, without being limited to, these and any other suitable types of memory.
[0103] Here, the processor 601 of the electronic device runs a rendering engine, and the rendering engine, when running, executes the image rendering method of the embodiments of the present application.
[0104] In the example embodiments, the embodiments of the present application also provide a storage medium, i.e., a computer storage medium, which can be specifically a computer readable storage medium, such as the memory 602 storing the computer program executable by the processor 601 of the electronic device 600 to complete the steps of the image rendering method of the embodiments of the present application. The computer readable storage medium can be a ROM, a PROM, an EPROM, an EEPROM, a Flash Memory, a magnetic surface memory, an optical disc, or a CD-ROM memory, etc.
[0105] In the example embodiments, the embodiments of the present application also provide a computer program product including a computer program executable by the processor 601 of the electronic device 600 to complete the steps of the method of the embodiments of the present application.
[0106] It should be noted that "first", "second", etc. are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.
[0107] In addition, the technical solutions described in the embodiments of the present application can be arbitrarily combined without conflict.
[0108] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. An image rendering method, characterized in that, The method includes: Collect first computational data of the rendering scene and attribute values of the bounding box of the target model; the first computational data is used to draw a first light source space depth map of the rendering scene; Based on the attribute values of the bounding box, the first calculated data is modified to obtain the second calculated data; Based on the second calculated data, a second light source spatial depth map corresponding to the target model is drawn; Based on the spatial depth map of the second light source, the shadow effect of the target model is drawn.
2. The method according to claim 1, characterized in that, The first calculation data of the collected rendering scene includes: Acquire the first view space matrix and the first projection matrix used to draw the spatial depth map of the first light source; Collect the attribute values of the bounding box of the target model, including: Collect model information and dynamic range of the target model; Based on the model information and dynamic range of the target model, the center point of the bounding box and the radius of the spherical enclosure are obtained.
3. The method according to claim 2, characterized in that, The step of modifying the first calculated data based on the attribute values of the bounding box to obtain the second calculated data includes: Based on the first view space matrix and the first projection matrix, calculate the position of the center point of the bounding box in the first light source spatial depth map; Based on the position of the center point of the bounding box in the first light source spatial depth map, calculate the offset between the center point of the bounding box and the center point of the first light source spatial depth map; Based on the radius of the spherical enclosure, calculate the scaling ratio of the spatial depth map of the first light source; Based on the offset and the scaling ratio, the first view space matrix and the first projection matrix are modified to obtain the second view space matrix and the second projection matrix.
4. The method according to claim 3, characterized in that, The step of drawing a second light source spatial depth map corresponding to the target model based on the second calculated data includes: Based on the second view space matrix and the second projection matrix, draw the second light source space depth map corresponding to the target model; The center point of the bounding box is located at the center point of the second light source spatial depth map.
5. The method according to claim 1, characterized in that, The step of drawing the shadow effect of the target model based on the spatial depth map of the second light source includes: Based on the first light source spatial depth map and the second light source spatial depth map, the percentage progressive soft shadow (PCSS) result of each target shading point of the target model is calculated using the percentage progressive soft shadow (PCSS) technique. Based on the PCF results of each target shading point, the soft shadow effect of the target model is drawn.
6. The method according to claim 1, characterized in that, The step of calculating the PCF results of each target shading point of the target model using PCSS technology based on the first light source spatial depth map and the second light source spatial depth map includes: Using the depth value of the target shading point in the spatial depth map of the second light source as the reference depth value, the depth occlusion result of the target shading point in the spatial depth map of the first light source is searched, and the average occlusion depth corresponding to the target shading point is calculated. Based on the average occlusion depth, the first sampling range of the target shading point in the spatial depth map of the second light source is calculated; Based on the first sampling range, a light source space depth map is determined for depth value sampling, and depth value sampling is performed on the determined light source space depth map to calculate the PCF result of the target shading point.
7. The method according to claim 6, characterized in that, The step of determining a light source space depth map for depth value sampling based on the first sampling range, performing depth value sampling on the determined light source space depth map, and calculating the PCF result of the target shading point includes: If the first sampling range is less than or equal to the set sampling range, then depth value sampling is performed in the second light source space depth map based on the first sampling range, and the PCF result of the target shading point is calculated. If the first sampling range is greater than the set sampling range, the first sampling range is converted into a second sampling range in the first light source space depth map, and depth value sampling is performed in the first light source space depth map based on the second sampling range to calculate the PCF result of the target shading point.
8. An electronic device, characterized in that, The electronic device includes: a processor and a memory for storing a computer program capable of running on the processor, wherein the processor, when running the computer program, performs the steps of the method according to any one of claims 1-7.
9. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the steps of the method according to any one of claims 1-7.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-7.