A shadow generation method and related apparatus
By acquiring the depth, normal, and lighting data of points in a virtual scene, and using convolutional filters to generate shadow effects for 3D models, the problem of low efficiency in shadow setting in existing technologies is solved, achieving efficient and accurate shadow generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT DIGITAL (SHENZHEN) CO LTD
- Filing Date
- 2024-11-28
- Publication Date
- 2026-05-29
AI Technical Summary
In existing technologies, setting shadow effects for 3D models is inefficient and incurs high labor and time costs.
By acquiring depth data, normal data, and lighting data from multiple points in the virtual scene as shadow reference data, basic shadow data is generated using a convolutional filter. Weighted shadow data is then generated by weighting the penumbra intensity based on the distance to the virtual light source and the distance the light propagates.
It improves the efficiency of setting shadow effects, reduces labor and time costs, and generates shadow effects that more accurately match the actual situation of the virtual scene.
Smart Images

Figure CN122115693A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a shadow generation method and related apparatus. Background Technology
[0002] A 3D model is a three-dimensional model constructed using 3D software. Because 3D models can flexibly represent various real or fictional objects, they are widely used in various fields, such as games, medicine, film and television production, engineering design, and so on.
[0003] 3D models are typically deployed in virtual scenes. To improve the realism of the 3D models in the virtual scene and simulate the presence of objects in the real world, it is often necessary to set shadow effects for the 3D models in the virtual scene. In related technologies, the shadow effects of 3D models are mainly set manually, but this method is inefficient and requires high labor and time costs. Summary of the Invention
[0004] This application provides a shadow generation method and related apparatus, which can improve the efficiency of setting shadow effects and reduce the required labor and time costs.
[0005] A first aspect of this application provides a shadow generation method, the method comprising:
[0006] Acquire the depth data, normal data, and lighting data of multiple points in the virtual scene, and use them as shadow reference data for each of the multiple points.
[0007] The shadow reference data of each of the plurality of points is input into the first convolutional filter to obtain the basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data.
[0008] Based on the distance from each of the multiple points to the virtual light source in the virtual scene, and the propagation distance of the virtual light emitted by the virtual light source, the penumbra intensity of each of the multiple points is determined. The penumbra intensity of the point is used to adjust the basic shadow data of the point based on the actual propagation path of the virtual light between the virtual light source and the point.
[0009] By using the penumbra intensity of each of the multiple points, the basic shadow data of each of the multiple points is weighted to obtain the weighted shadow data of each of the multiple points. The weighted shadow data is used for shadow rendering of the points.
[0010] A second aspect of this application provides a shadow generation apparatus, the apparatus comprising:
[0011] The acquisition module is used to acquire the depth data, normal data, and lighting data of multiple points in the virtual scene, which serve as the shadow reference data for each of the multiple points.
[0012] A convolutional filtering module is used to input the shadow reference data of each of the plurality of points into a first convolutional filter to obtain the basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data.
[0013] The penumbra determination module is used to determine the penumbra intensity of each of the multiple points based on the distance from each point to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source. The penumbra intensity of the point is used to adjust the basic shadow data of the point based on the actual propagation path of the virtual light between the virtual light source and the point.
[0014] The shadow generation module is used to weight the basic shadow data of the multiple points by utilizing the penumbra intensity of each point to obtain weighted shadow data of the multiple points. The weighted shadow data is used for shadow rendering of the points.
[0015] A third aspect of this application provides a computer device, the device comprising a processor and a memory:
[0016] The memory is used to store computer programs;
[0017] The processor is configured to perform the steps of the shadow generation method as described in the first aspect above, according to the computer program.
[0018] A fourth aspect of this application provides a computer-readable storage medium for storing a computer program for performing the steps of the shadow generation method described in the first aspect.
[0019] A fifth aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of the shadow generation method described in the first aspect.
[0020] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0021] This application provides a shadow generation method, which proposes a scheme for automatically generating shadow effects in a virtual scene based on a convolutional filter. The method includes: acquiring depth data, normal data, and lighting data for multiple points in the virtual scene, as shadow reference data for each point; that is, for each point in the virtual scene, depth data reflecting the propagation path of virtual light at that point, normal data reflecting the angle between the virtual light and the point, and lighting data reflecting the lighting conditions at that point in the virtual scene can be used as shadow reference data to determine the shadow effect at that point. Then, the shadow reference data of each of the multiple points is input into the first convolutional filter to obtain the basic shadow data of each of the multiple points output by the first convolutional filter through the application of filter parameters. These filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data. The first coefficient used to adjust the original filter parameters of the first convolutional filter is determined based on the shadow reference data, so that the filter parameters adjusted by the first coefficient are more suitable for analyzing the lighting conditions in the current virtual scene. Accordingly, the first convolutional filter processes the shadow reference data based on the filter parameters adjusted by the first coefficient to obtain basic shadow data that accurately reflects the shadow situation in the virtual scene. Furthermore, considering that the propagation of virtual light emitted from the virtual light source in the virtual scene to each point affects the shadow effect at each point, such as affecting the brightness of the shadow, the penumbra intensity of each of the multiple points can be determined based on the distance from each point to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted from the virtual light source. The penumbra intensity of a point can be adjusted based on the actual propagation path of the virtual light between the virtual light source and the point to adjust the basic shadow data of that point. After determining the penumbra intensity, the base shadow data of multiple points can be weighted using their individual penumbra intensities. This weighted weighting adjusts the base shadow data of each point based on the impact of virtual light propagation on the shadow effect at that point. This results in more accurate weighted shadow data that better reflects the actual conditions of the virtual scene. This weighted shadow data can then be used for shadow rendering at multiple points. Therefore, this method can automatically and accurately generate shadow effects in a virtual scene, improving the efficiency of shadow effect setup and reducing labor and time costs. Attached Figure Description
[0022] Figure 1 This is a schematic diagram illustrating an application scenario of the shadow generation method provided in the embodiments of this application;
[0023] Figure 2A schematic flowchart illustrating the shadow generation method provided in an embodiment of this application;
[0024] Figure 3 A schematic diagram illustrating the determination of sub-basic shadow data provided in an embodiment of this application;
[0025] Figure 4a This is a flowchart illustrating the process of determining basic shadow data provided in an embodiment of this application.
[0026] Figure 4b A schematic diagram illustrating the penumbra effect provided in an embodiment of this application;
[0027] Figure 5 A schematic diagram illustrating the determination of actual shadow data for multiple points as provided in an embodiment of this application;
[0028] Figure 6 A schematic diagram illustrating the process of determining the adaptive illumination intensity of a light source relative to a three-dimensional model, as provided in an embodiment of this application.
[0029] Figure 7 A schematic diagram illustrating the structure for determining the actual shadow data of multiple points as provided in an embodiment of this application;
[0030] Figure 8 This is a schematic diagram of the structure of the shadow generation device provided in the embodiments of this application;
[0031] Figure 9 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application;
[0032] Figure 10 This is a schematic diagram of the server structure provided in an embodiment of this application. Detailed Implementation
[0033] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0034] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0035] The shadow generation method provided in this application can be executed by a computer device, which can be a terminal device or a server. The terminal device includes, but is not limited to, mobile phones, computers, smart voice interaction devices, smart home appliances, vehicle terminals, and aircraft. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server.
[0036] It should be noted that the information, data and signals involved in the embodiments of this application are all authorized by the relevant parties or fully authorized by all parties, and the collection, use and processing of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0037] To facilitate understanding of the shadow generation method provided in this application embodiment, the following example uses a server as the execution subject of the shadow generation method to illustrate the application scenarios of the shadow generation method.
[0038] See Figure 1 , Figure 1 This is a schematic diagram illustrating an application scenario of the shadow generation method provided in this application embodiment. For example... Figure 1 As shown, this application scenario includes a terminal device 110 and a server 120. The terminal device 110 and the server 120 can communicate directly or indirectly through a wired network or a wireless network.
[0039] The terminal device 110 runs a target application (such as a debugging application) that supports rendering and displaying virtual scenes. The virtual scene displayed in the terminal device 110 may include at least one three-dimensional model. The terminal device 110 can send the depth data, normal data and lighting data of multiple points in the virtual scene to the server 120. These multiple points may be multiple points uniformly sampled in the virtual scene.
[0040] After obtaining the depth data, normal data, and lighting data of multiple points in the virtual scene, server 120 uses the depth data, normal data, and lighting data of each point as shadow reference data for each point. That is, for each point in the virtual scene, the depth data reflecting the propagation path of the virtual light at that point, the normal data reflecting the angle between the virtual light and the point, and the lighting data reflecting the lighting conditions at that point in the virtual scene can be used as shadow reference data to determine the shadow effect at that point.
[0041] Then, server 120 can input the shadow reference data of each of the multiple points into the first convolution filter to obtain the basic shadow data of each of the multiple points output by the first convolution filter after applying the filter parameters, such as... Figure 1 The shadow reference data of point A, ..., and point N are respectively input into the first convolutional filter. This yields the basic shadow data of point A, ..., and point N output by the first convolutional filter after processing. Furthermore, the filter parameters applied by the first convolutional filter when processing the shadow reference data are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data. The first coefficient, used to adjust the original filter parameters of the first convolutional filter based on the shadow reference data, makes the filter parameters adjusted by the first coefficient more suitable for analyzing the lighting conditions in the current virtual scene. Accordingly, the first convolutional filter processes the shadow reference data based on the filter parameters adjusted by the first coefficient, obtaining basic shadow data that accurately reflects the shadow situation in the virtual scene.
[0042] Furthermore, considering that the propagation of virtual light emitted by the virtual light source in the virtual scene to each point will affect the shadow effect at each point, such as the brightness of the shadow, the server 120 can determine the penumbra intensity of each of the multiple points based on the distance from each point to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source. The penumbra intensity of a point can be adjusted based on the actual propagation path of the virtual light between the virtual light source and the point to adjust the basic shadow data of that point. For example, the penumbra intensity of point A can be determined based on the distance from point A to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source; the penumbra intensity of point N can be determined based on the distance from point N to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source.
[0043] Finally, after determining the penumbra intensity of each of the multiple points, server 120 can use the penumbra intensity of each point to weight the basic shadow data of each point. Based on the influence of the propagation of virtual light to the point on the shadow effect at that point, the basic shadow data of each point can be adjusted, thereby obtaining more accurate weighted shadow data that better reflects the actual situation in the virtual scene. The weighted shadow data of each point can then be used for shadow rendering of multiple points. For example, the basic shadow data of point A can be weighted based on the penumbra intensity of point A to obtain the weighted shadow data of point A; the basic shadow data of point N can be weighted based on the penumbra intensity of point N to obtain the weighted shadow data of point N.
[0044] It should be understood that Figure 1 The application scenarios shown are merely examples. In practical applications, the shadow generation method provided in this application embodiment can also be applied to other scenarios. For example, the shadow generation method can be executed independently by a terminal device. No limitations are made here on the application scenarios of the shadow generation method provided in this application embodiment.
[0045] The shadow generation method provided in this application will be described in detail below through method embodiments.
[0046] See Figure 2 , Figure 2 This is a flowchart illustrating the shadow generation method provided in an embodiment of this application, as shown below. Figure 2 As shown, the shadow generation method includes the following steps:
[0047] S201: Obtain the depth data, normal data, and lighting data of multiple points in the virtual scene, and use them as shadow reference data for each point.
[0048] A virtual scene can specifically be a fictional three-dimensional scene. A three-dimensional scene refers to a three-dimensional spatial environment created and presented through 3D software. Three-dimensional models can be deployed within a three-dimensional scene to enrich it. For example, in the gaming field, a three-dimensional scene can be a three-dimensional game space environment, within which three-dimensional models of various virtual elements from the game (including but not limited to virtual characters, virtual items, and virtual scene elements) can be deployed. Of course, in practical applications, the virtual scene in this embodiment can also be a fictional two-dimensional scene, a 2.5-dimensional scene, etc., and this embodiment does not impose any limitations on this. For ease of description, the following description will use a three-dimensional scene as an example.
[0049] Multiple points in a virtual scene refer to multiple points uniformly sampled in the virtual scene, each with a corresponding coordinate position. For example, assuming the virtual scene is a three-dimensional space of size L*W*H (L, W, and H represent length, width, and height, respectively, all integers greater than or equal to 1), a 1*1*1 cube space can be used as a sampling unit. One point is sampled in each 1*1*1 sampling unit in the virtual scene, resulting in L*W*H points. These L*W*H points can then be considered as multiple points in the aforementioned virtual scene.
[0050] Depth data of a point is used to characterize the propagation path of virtual rays at that point in a virtual scene. Point depth data refers to the distance information between the point and the sampling surface of the virtual camera. For example, the depth data of a point in a virtual scene can be obtained through the principle of parallax. Specifically, the process of rendering a virtual scene can be simply understood as capturing the virtual scene with a virtual camera to obtain a two-dimensional image reflecting the content of the virtual scene. Here, the distance between the sampling surface of the virtual camera (i.e., the lens of the virtual camera) and the point is the point's depth information. Normal data of a point is used to characterize the angle information between the virtual ray and the point. When the point belongs to the surface of a 3D model in the corresponding 3D space of the virtual scene, the normal data of the point refers to the vector perpendicular to the surface of that 3D model at that point. For example, the normal data of the point can be directly calculated from the shape and surface structure of the 3D model. When the point does not belong to the surface of any 3D model in the 3D space, the normal data of the point can be determined based on the point's position information and the origin of the virtual scene. For example, the vector pointing from the origin to the point can be used as the normal data of the point. Point lighting data refers to the relevant data of virtual light rays illuminating that point, such as light intensity, light direction, and light type. The lighting data of a point can be determined using physical formulas related to virtual light sources. For example, the light intensity of a point can be calculated based on the distance between the point and the virtual light source using the light intensity attenuation formula of the virtual light source. Alternatively, the light direction at a point can be determined based on the position of the point using the light direction expression formula of the virtual light source. It should be understood that when a virtual scene includes multiple virtual light sources, the lighting data corresponding to each of the multiple virtual light sources can be determined for each point to represent the lighting situation of different virtual light sources at that point.
[0051] It should be noted that in practical applications, the above analysis and calculation methods can be used to determine the depth, normal, and lighting data of multiple points in a virtual scene. That is, based on a constructed virtual scene, the depth, normal, and lighting data of multiple points are determined through corresponding analysis and calculation methods. It should be understood that specific virtual scene rendering or building tools can be used to perform the above analysis and calculations to automatically determine the depth, normal, and lighting data of multiple points.
[0052] In this embodiment, for each point in the virtual scene, the depth data, normal data, and lighting data of that point are used as shadow reference data. This shadow reference data is the basic data used to provide reference information when generating the shadow effect at that point. It should be understood that this embodiment is used for shadow rendering of a virtual scene; therefore, the obtained shadow reference data are all the depth data, normal data, and lighting data of points in the virtual scene.
[0053] As an example, during the rendering process of a virtual model, the debug toolbox of the real-time rendering engine (Unreal Engine 4, UE4) can be used to extract and export the 3D model in real time. The virtual scene in which the 3D model is located can be exported to enrich the shadow situation of the 3D model in the virtual scene based on the points included in the virtual scene. Furthermore, the depth data, normal data, and lighting data of multiple points in the virtual scene can be determined, so that the server can use the depth data, normal data, and lighting data of multiple points in the virtual scene as shadow reference data for each point.
[0054] In another possible implementation, the depth, normal, and lighting data of multiple points in the virtual scene can be directly obtained. That is, when it's necessary to enrich the shadow effect of a 3D model in a virtual scene, the shadow situation of each point in the virtual scene can be determined based on the depth, normal, and lighting data of each point. For example, the depth, normal, and lighting data of multiple points in the virtual scene containing the 3D model whose shadow effect needs to be enriched can be directly obtained from a database. The server then uses this data as the shadow reference data for each point.
[0055] In one possible implementation, the step of S201 above, "acquiring the depth data, normal data, and lighting data of multiple points in the virtual scene as shadow reference data for each of the multiple points," may include:
[0056] For each region in the virtual scene, the sampling rate of the representative points corresponding to the region is determined according to the scene complexity of the region; representative points are sampled in the region according to the sampling rate of the representative points; the depth data, normal data and lighting data of the representative points are used as the shadow reference data of each point in the region.
[0057] Taking a virtual scene as a 3D scene as an example, the 3D scene includes multiple regions. For example, each region in the 3D scene can be determined according to a preset region division method. Each region includes different content. The scene complexity of a region is used to characterize the complexity of the content included in that region. The scene complexity of a region can be determined based on the number of objects included in that region and a preset object number threshold. For example, the scene complexity of a region can be determined based on the difference between the number of objects included in that region and the preset object number threshold. If the number of objects included in a region is less than the preset object number threshold and the difference in the number of objects is within 3, then the scene complexity of the region is considered to be 0.3; if the number of objects included in a region is equal to the preset object number threshold, then the scene complexity of the region is considered to be 0.5; if the number of objects included in a region is greater than the preset object number threshold and the difference in the number of objects is within 3, then the scene complexity of the region is considered to be 0.7.
[0058] For each region in a 3D scene, the sampling rate of the representative points corresponding to the region can be determined based on the scene complexity of the region, as shown in Formula 1.
[0059]
[0060] Among them, Ri adaptive This represents the representative point sampling rate for the i-th region, determined based on the scene complexity of that region in the 3D scene. Ci represents the scene complexity of the i-th region, and β and C0 represent pre-set parameters controlling the sampling rate. Furthermore, the representative point sampling rate can be adjusted based on the propagation of virtual light emitted from virtual light sources within the region. If a region is a shadow edge, the representative point sampling rate can be appropriately increased to perform convolution calculations based on richer shadow reference data. If a region is inside a shadow or a brighter region, the representative point sampling rate can be appropriately decreased to reduce computational load.
[0061] The representative point sampling rate for a region refers to the sampling probability of selecting a representative point within that region. A representative point is a point used to represent that region, and the shadow reference data of the representative point can represent the shadow reference data of other points within that region. For example, assuming the 3D model in a 3D scene is a cube space with dimensions L*W*H (L, W, and H represent length, width, and height, respectively, all integers greater than or equal to 3), according to a preset region division method, a 3*3*3 cube space can be considered as a region, and representative points can be randomly sampled within this region according to the representative point sampling rate.
[0062] After determining the representative point sampling rate, random points can be sampled in the region according to this rate. Then, the depth data, normal data, and lighting data of these representative points can be used as the shadow reference data for each point in the region. For example, the shadow reference data for each point can be determined based on its distance from the representative point. If the distance between representative point A and point B is less than the distance between point B and other representative points, then the depth data, normal data, and lighting data of representative point A can be used as the shadow reference data for point B. This process can be repeated to determine the shadow reference data for each point in each region.
[0063] Therefore, the above method allows for determining the representative point sampling rate for a region based on its scene complexity. Once the representative point sampling rate is determined, representative points can be randomly sampled within the region according to this rate. The depth, normal, and lighting data of these representative points can then be used as shadow reference data for other points in the region. This eliminates the need to determine the individual depth, normal, and lighting data for each point, significantly reducing the computational load for determining shadow reference data. Furthermore, during the calculation of the representative point sampling rate, it can be appropriately adjusted based on the distribution of virtual light sources in the region. This allows for the use of more refined shadow reference data when determining shadow data for shadow edge areas, ensuring accurate shadow detail in such areas. Conversely, it allows for the use of coarser shadow reference data when determining shadow data for bright areas or areas within shadows, reducing the associated computational load.
[0064] S202: Input the shadow reference data of each of the multiple points into the first convolution filter to obtain the basic shadow data of each of the multiple points output by the first convolution filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolution filter using the first coefficient. The first coefficient is determined according to the shadow reference data.
[0065] The first convolutional filter is a three-dimensional convolutional filter, which is a tool used to perform convolution operations in three-dimensional space. It performs convolution operations on the input three-dimensional spatial data by sliding a small filter (i.e., convolution kernel) to obtain new feature data. This new feature data can comprehensively reflect the relevant information of each point in the filter space.
[0066] It should be noted that the first convolutional filter is a filter based on a 3D convolutional kernel, used to determine the basic shadow data of each point using shadow reference data from neighboring points. The structure of the first convolutional filter specifically includes a kernel, padding, and a sliding window. The kernel is a set of weights that determines how the basic shadow data of the current point is determined using shadow reference data from neighboring points in 3D space. The kernel is specifically represented as a 3D convolution matrix, performing convolution operations on the shadow reference data of points within a region. Padding is used to fill the shadow reference data of points at edge positions before the convolution operation, such as padding to 0, to ensure that the size of the processed 3D space is consistent with the size of the input data received by the first convolutional filter. The sliding window moves across the entire 3D space like a window, calculating the filtering result for each point in the 3D space, i.e., the basic shadow data. Each change in the position of the sliding window performs a convolution operation. By inputting the shadow reference data of multiple points into the first convolutional filter, new feature data for each point can be obtained from the output of the first convolutional filter, i.e., the basic shadow data of each point. The basic shadow data refers to the output result obtained by performing a convolution operation on the shadow reference data of multiple points using the first convolution filter. For example, the basic shadow data can be the shadow grayscale value.
[0067] For example, referring to Formula 2, the shadow reference data of multiple points can be input into the first convolution filter to obtain the basic shadow data of multiple points output by the first convolution filter.
[0068]
[0069] Where S(i, j, k) represents the basic shadow data of the point with coordinates (i, j, k) in three-dimensional space, W′(m, n, p) represents the filter parameters applied by the first convolutional filter when processing the shadow reference data, i.e., the convolution kernel applied by the first convolutional filter, X(i, j, k) represents the shadow reference data of the point with coordinates (i, j, k) in three-dimensional space, and M, N, and P represent the radii of the convolution kernel in the horizontal, vertical, and horizontal axes, respectively. As can be seen from Formula 1 above, in the first convolutional filter, when determining the basic shadow data for the point with coordinates (i, j, k), the basic shadow data of the point with coordinates (i, j, k) can be determined based on the shadow reference data of each point in a space of size (2M+1)*(2N+1)*(2K+1) centered on the point with coordinates (i, j, k). Here, (2M+1)*(2N+1)*(2K+1) is the filter size of the first convolutional filter.
[0070] It should be noted that the filter parameters applied by the first convolutional filter when processing the shadow reference data are obtained by adjusting the original filter parameters of the first convolutional filter using the first coefficient. The original filter parameters of the first convolutional filter refer to the unadjusted filter parameters, which can be represented by W(m, n, p). The first coefficient is used to adjust the original filter parameters in the first convolutional filter so that the adjusted filter parameters can generate shadow data that more closely matches the actual lighting conditions. The first coefficient can be determined based on the shadow reference data, for example, by processing the shadow reference data using a neural network model.
[0071] Furthermore, the distribution of the original filter parameters of the first convolution filter determines the contribution of illumination and shadow data at different locations. For example, a Gaussian distribution can be used as the basis for the original filter parameters, which can ensure that the central region of the original filter parameters contributes more to the convolution effect, while the contribution of the edge region gradually decreases. That is, the original filter parameters of the first convolution filter must satisfy Formula 3.
[0072]
[0073] Where W(m,n,p) represents the original filter parameters based on the Gaussian distribution, and σ represents the standard deviation of the Gaussian distribution, which determines the smoothness of the weight distribution.
[0074] Furthermore, to generate more realistic shadow effects, the first convolutional filter can also be a directional 3D convolutional filter. A directional filter can better capture the influence of the virtual light source direction on the shadow data, thus generating a penumbra that conforms to physical laws. The weight distribution of the directional filter can be found in Formula 4.
[0075] W dir (m,n,p)=W(m,n,p)·cos(θ) Formula 4
[0076] Among them, W dir (m,n,p) represents the filter parameter distribution of the directional filter, i.e. the original filter parameters of the first convolution filter, W(m,n,p) represents the original filter parameters without directionality, and θ represents the angle between the center point of the first convolution filter (i.e. the center point of the sliding window) and the direction of the virtual light source.
[0077] It should be understood that the embodiments of this application are used for shadow rendering of virtual scenes. Therefore, the basic shadow data of each of the multiple points determined through this step are the basic shadow data of each of the multiple points in the virtual scene. Specifically, the basic shadow data of a point can be the grayscale value of the point in the virtual scene.
[0078] In one possible implementation, the first coefficient can be determined in the following way:
[0079] The shadow reference data of multiple points is input into the first coefficient classification network to obtain the first coefficients corresponding to each point output by the first coefficient classification network; the first coefficients corresponding to the points are used to adjust the original filter parameters of the basic shadow data used to determine the points in the first convolutional filter; the first coefficient classification network is trained based on the training shadow reference data and the corresponding labeled first coefficients.
[0080] The first coefficient classification network is used to determine the first coefficients corresponding to multiple points based on their respective shadow reference data. These first coefficients are then used to adjust the original filter parameters in the first convolutional filter, enabling the first convolutional filter to better adapt to different lighting conditions and complex geometric structures in a 3D scene to determine the corresponding basic shadow data. Specifically, this first coefficient classification network can be a multi-classification neural network used to perform multi-classification tasks. It can perform multi-classification tasks based on the shadow reference data of the input points to determine the most suitable first coefficient among multiple candidate first coefficients for processing the shadow reference data of that point.
[0081] The first coefficient classification network can be pre-trained based on training shadow reference data and corresponding labeled first coefficients. The training shadow reference data and corresponding labeled first coefficients refer to the training data used in training the first coefficient classification network. The method for obtaining the training shadow reference data is the same as the method for obtaining the shadow reference data of multiple points in a 3D scene. For example, several points can be uniformly sampled in the training 3D scene as training points, and then the depth data, normal data, and lighting data of the training points can be obtained as training shadow reference data. The training shadow data also includes the corresponding labeled first coefficients, i.e., the labels during the training process, which can be obtained through manual annotation.
[0082] During training, multiple training shadow data can be input into the first coefficient classification network to be trained. The first coefficient classification network classifies the multiple training shadow data and outputs the predicted first coefficient corresponding to each training shadow data. Then, based on the difference between the predicted first coefficient and the labeled first coefficient corresponding to each training shadow data, the first coefficient classification network is trained so that the predicted first coefficient output by the first coefficient classification network gradually approaches the labeled first coefficient, thereby optimizing the classification performance of the first coefficient classification network and improving its accuracy.
[0083] It should be understood that in practical applications, a training termination condition can be preset. When the training of the first coefficient classification network reaches this termination condition, the training of the first coefficient classification network can be terminated. This termination condition could be, for example, that the number of training epochs for the first coefficient classification network reaches a preset threshold; or, for example, that the performance of the first coefficient classification network is tested and found to have reached a preset performance standard (such as reaching a preset classification accuracy); or, for example, that the performance of the first coefficient classification network is tested and found to no longer significantly improve with further training. This embodiment of the application does not impose any limitations on this training termination condition.
[0084] Based on the above training process, a first coefficient classification network can be obtained. After this first coefficient classification network is put into practical application, the shadow reference data of multiple points obtained through S201 can be input into the first coefficient classification network for classification, and the first coefficients corresponding to each point can be obtained from the output of the first coefficient classification network. After determining the first coefficients corresponding to each point, the original filter parameters of the first convolution filter used to determine the basic shadow data of the points can be adjusted based on the first coefficients corresponding to the points, as shown in Formula 5.
[0085] W′ NN (m,n,p)=W(m,n,p)·f NN Formula 5 for (X(i,j,k))
[0086] Among them, W′ NN (m,n,p) represents the filter parameters adjusted using the first coefficient, W(m,n,p) represents the original filter parameters, and f NN (X(i,j,k)) represents the first coefficient corresponding to point (i,j,k) obtained after processing the shadow reference data corresponding to point (i,j,k) by the first coefficient classification network; it should be understood that the above W′ NN (m,n,p) are the filter parameters used in the first convolutional filter to determine the basic shadow data corresponding to point (i,j,k).
[0087] Therefore, by using the above method, the shadow reference data of multiple points can be input into the first coefficient classification network for classification, so as to determine the first coefficient corresponding to each of the multiple points. By using the first coefficient to adjust the original filter parameters, the first convolution filter can better adapt to the lighting conditions and complex geometric structures of different points in the 3D scene during the convolution operation. This realizes the dynamic adjustment of the filter parameters applied to the first convolution filter, which helps to generate more realistic and delicate shadow effects.
[0088] In this embodiment of the application, the first coefficient classification network can be trained first. After the training of the first coefficient classification network is completed, the original filter parameters of the first convolutional filter can be trained with the help of the first coefficient classification network.
[0089] As an example, the training process for the original filter parameters may include: inputting training shadow reference data (which may be the same as or different from the training shadow reference data used when training the first coefficient classification network mentioned above) into the first coefficient classification network to determine the first coefficients corresponding to the training shadow reference data; then, adjusting the original filter parameters of the first convolutional filter to be trained using the first coefficients; subsequently, inputting the training shadow reference data into the first convolutional filter to be trained; and performing a convolution operation on the training shadow reference data based on the filter parameters adjusted by the first coefficients, which can output the predicted base shadow data corresponding to the training shadow reference data. The predicted base shadow data corresponding to the training shadow reference data refers to the output result of the first convolutional filter to be trained, used to characterize the predicted base shadow data after the trained first convolutional filter performs a convolution operation on the training shadow reference data.
[0090] The working principle of the first convolutional filter to be trained is the same as that of the first convolutional filter in S202 above. For details, please refer to the relevant content above. It will not be repeated here.
[0091] After obtaining the predicted base shadow data, the difference between the predicted base shadow data and the labeled base shadow data corresponding to the training shadow reference data can be calculated using a loss function. Here, the labeled base shadow data corresponding to the training shadow reference data is pre-labeled to indicate the standard shadow effect at the points corresponding to the training shadow reference data. Furthermore, based on the calculated loss value, the original filter parameters of the first convolutional filter to be trained can be optimized by continuously adjusting the original filter parameters to reduce the loss value, thereby improving the accuracy of the first convolutional filter.
[0092] It should be understood that in practical applications, a training termination condition can be preset. When the training of the first convolutional filter reaches this termination condition, the training of the first convolutional filter can be considered to have ended. This termination condition could be, for example, that the number of training epochs for the first convolutional filter reaches a preset threshold; or, for example, that the performance of the first convolutional filter is tested and found to have reached a preset performance standard (such as reaching a preset accuracy); or, for example, that the performance of the first convolutional filter is tested and found to no longer significantly improve with further training. This application does not impose any limitations on the training termination condition in this embodiment.
[0093] In one possible implementation, the first convolutional filter includes multiple sub-convolutional filters, each with a convolutional kernel of a different size. The step S202 described above, "inputting the shadow reference data of multiple points into the first convolutional filter to obtain the basic shadow data of multiple points output by the first convolutional filter through the application of filter parameters," may include:
[0094] The shadow reference data of each of the multiple points is input into each sub-convolutional filter to obtain the sub-basic shadow data of each of the multiple points output by each sub-convolutional filter through the application of filter parameters; the filter parameters are obtained by adjusting the original filter parameters of the sub-convolutional filter using the first coefficient.
[0095] For each point, the sub-basic shadow data of the point output by multiple sub-convolutional filters are weighted and summed to obtain the basic shadow data of the point.
[0096] The first convolutional filter can include multiple sub-convolutional filters arranged in parallel, each with a convolutional kernel of a different size. Therefore, the shadow reference data for multiple points can be convolved separately based on these sub-convolutional filters with kernels of different sizes. It should be understood that multiple sub-convolutional filters having kernels of different sizes means that the filtering sizes of the sub-convolutional filters are different. The filtering size of a sub-convolutional filter is determined by its filtering radius (which can be represented as M, N, and P) in the horizontal, vertical, and longitudinal dimensions. That is, different sub-convolutional filters differ in at least one of the filtering radii in these three dimensions. Generally, sub-convolutional filters with larger filtering sizes can capture a wider range of lighting variations and generate softer shadow effects, while sub-convolutional filters with smaller filtering sizes can capture details better.
[0097] For reference Figure 3 , Figure 3 This is a schematic diagram illustrating the determination of sub-basic shadow data provided in an embodiment of this application. Shadow reference data for multiple points are input into each sub-convolutional filter. Each sub-convolutional filter performs a convolution operation on the shadow reference data for each of the multiple points, resulting in the output of the sub-basic shadow data for each point. This sub-basic shadow data refers to the output result obtained by the sub-convolutional filter performing a convolution operation based on the shadow reference data for each of the multiple points; specifically, it can be the shadow grayscale value of the point output by the sub-convolutional filter. Figure 3The shadow reference data of point A, ..., and the shadow reference data of point N are respectively input into sub-convolution filters A, ..., and N in the first convolution filter. This allows us to obtain the sub-basic shadow data of point A, ..., and the sub-basic shadow data of point N, as well as the sub-basic shadow data of point A, ..., and the sub-basic shadow data of point N, as well as the sub-basic shadow data of point A, ..., and the sub-basic shadow data of point N, as output by sub-convolution filter A after processing.
[0098] The filter parameters used by the subconvolution filter when processing the shadow reference data are obtained by adjusting the original filter parameters of the subconvolution filter using the first coefficient. That is, referring to Formula 6, the sub-basic shadow data of each point output by each subconvolution filter can be determined.
[0099]
[0100] Among them, S j (i,j,k) represents the base shadow data of the point with coordinates (i,j,k) output by the j-th sub-convolutional filter in the first convolutional filter, W j '(m, n, p) represents the filter parameters applied by the j-th sub-convolutional filter in the first convolutional filter when processing the shadow reference data, i.e., the convolution kernel applied by the j-th sub-convolutional filter, X(i, j, k) represents the shadow reference data of the point with coordinates (i, j, k) in three-dimensional space, M j N j and P j These represent the radii of the convolution kernel in the j-th sub-convolution filter along the horizontal, vertical, and y-axis, respectively.
[0101] It should be understood that the first coefficients used to adjust the original filter parameters of each sub-convolutional filter can be specifically determined by the first coefficient classification network mentioned above based on the shaded reference data of the points.
[0102] For each point, the basic shadow data of the point is obtained by weighted summation of the sub-basic shadow data output by multiple sub-convolutional filters, as shown in Formula 7.
[0103]
[0104] Among them, S multi (i,j,k) represents the basic shading data of point (i,j,k), J represents the total number of sub-convolutional filters in the first convolutional filter, and α j S represents the pre-defined weights of the j-th sub-convolutional filter. Correspondingly, each sub-convolutional filter includes pre-defined weights. j(i,j,k) represents the sub-basic shadow data determined by the j-th sub-convolutional filter for point (i,j,k).
[0105] Therefore, as shown by the above method, when the first convolutional filter includes multiple sub-convolutional filters, the shadow reference data of multiple points can be input into each sub-convolutional filter for convolution processing to extract shadow details and overall contours at different scales, resulting in sub-basic shadow data for each point output by each sub-convolutional filter. Finally, for each point, the sub-basic shadow data output by multiple sub-convolutional filters are weighted and summed to fuse shadow details and overall contours at different scales, contributing to the generation of more natural and realistic shadow effects.
[0106] In one possible implementation, refer to Figure 4a , Figure 4a This is a flowchart illustrating the process of determining basic shadow data provided in an embodiment of this application. In step S202, "inputting the shadow reference data of multiple points into a first convolutional filter to obtain the basic shadow data of multiple points output by the first convolutional filter through the applied filter parameters" can include steps S2021-S2023:
[0107] S2021: Perform a fast Fourier transform on the shadow reference data of multiple points to obtain the frequency domain shadow reference data of multiple points.
[0108] The Fast Fourier Transform (FFT) is an efficient algorithm for computing the Discrete Fourier Transform (DFT), significantly reducing the complexity and time required to compute it. The FFT presents a discrete form in both the spatial and frequency domains, transforming samples of a signal in the spatial domain into samples in the frequency domain. The spatial domain describes the physical quantities that represent how a signal changes with location, while the frequency domain describes how a signal changes with frequency.
[0109] As an example, the Fast Fourier Transform (FFT) algorithm can be used to perform a fast Fourier transform on the shadow reference data of multiple points, transforming the shadow reference data of multiple points from the spatial domain to the frequency domain, thus obtaining the frequency domain shadow reference data of multiple points, that is, the data corresponding to the shadow reference data of multiple points in the frequency space. Here, the FFT algorithm refers to the Fast Fourier Transform algorithm, which can include time decimation and frequency decimation methods.
[0110] S2022: Input the frequency domain shadow reference data of multiple points into the first convolution filter to obtain the frequency domain basic shadow data of multiple points output by the first convolution filter through the application of filter parameters; the filter parameters are frequency domain parameters.
[0111] After determining the frequency domain shadow reference data for each of the multiple points, this data can be input into the first convolution filter for convolution operations. This yields the frequency domain base shadow data for each point, output by the first convolution filter – the data corresponding to the base shadow data in the frequency domain. It should be noted that the filter parameters of the first convolution filter are frequency domain parameters. That is, the filter parameters used by the first convolution filter when processing the frequency domain shadow reference data have also undergone a Fast Fourier Transform (FFT) to convert them to the frequency domain. This allows the first convolution filter to perform convolution operations on the frequency domain shadow reference data based on the corresponding frequency domain parameters, obtaining the frequency domain base shadow data for each point, as shown in Formula 8.
[0112] F(Y)(u,v,w)=F(X)(u,v,w)·F(W)(u,v,w)Formula 8
[0113] Where F(Y)(u,v,w) represents the frequency domain basic shadow data of point (u,v,w), F represents the Fast Fourier Transform, F(X)(u,v,w) represents the frequency domain shadow reference data of point (u,v,w), u, v, w represent the coordinates of the point in the horizontal, vertical and vertical dimensions in the frequency domain space, respectively, and F(W)(u,v,w) represents the frequency domain parameters applied by the first convolution filter when processing the frequency domain shadow reference data.
[0114] It should be understood that the frequency domain filter parameters of the first convolution filter are also obtained based on the adjustment of the first coefficients. That is, the original filter parameters of the first convolution filter can be adjusted first using the first coefficients determined according to the shadow reference data to obtain the filter parameters applied by the first convolution filter in this processing. Then, the filter parameters are transformed to the frequency domain through fast Fourier transform to obtain the frequency domain filter parameters applied by the first convolution filter when processing the frequency domain shadow reference data.
[0115] Furthermore, when the first convolutional filter includes multiple sub-convolutional filters, the filter parameters applied by each sub-convolutional filter when processing the frequency domain shadow reference data are also frequency domain filter parameters. These frequency domain filter parameters are obtained by transforming the filter parameters adjusted based on the first coefficients into the frequency domain through a Fast Fourier Transform. Accordingly, the output of each sub-convolutional filter is the frequency domain sub-basic shadow data for multiple points. For each point, the frequency domain sub-basic shadow data output by each of the multiple sub-convolutional filters needs to be weighted and summed to obtain the frequency domain basic shadow data for that point.
[0116] S2023: Transform the frequency domain basic shadow data of multiple points to the spatial domain to obtain the basic shadow data of multiple points.
[0117] Finally, the frequency domain fundamental shadow data of multiple points can be transformed to the spatial domain to obtain the fundamental shadow data of each point. The spatial domain is the domain that describes the changes of a signal in space (or time). As an example, the frequency domain fundamental shadow data of multiple points can be transformed to the spatial domain through the inverse process of the FFT algorithm to obtain the fundamental shadow data of each point in the spatial domain.
[0118] Therefore, using the above method, a Fast Fourier Transform can be performed on the shadow reference data of multiple points to obtain the frequency domain shadow reference data of each point. Then, a first convolution filter, operating based on the parameters of the frequency domain filter, is used to process the frequency domain shadow reference data of the multiple points to obtain the frequency domain basic shadow data of each point. Finally, the frequency domain basic shadow data of the multiple points is transformed to the spatial domain to obtain the basic shadow data in the spatial domain. The above scheme performs convolution operations based on the lower complexity of the frequency domain space, which can accelerate the convolution operation process and significantly reduce the amount of computation.
[0119] S203: Determine the penumbra intensity of each of the multiple points based on their respective distances to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source; the penumbra intensity of a point is used to adjust the basic shadow data of the point based on the actual propagation path of the virtual light between the virtual light source and the point.
[0120] In the shadow generation process, in addition to determining the basic shadow data for multiple points in the 3D scene, it is also necessary to determine the penumbra intensity for multiple points. The penumbra is a soft transition region created by the finite size of a virtual light source or the presence of multiple virtual light sources; see [link to documentation]. Figure 4b , Figure 4b A schematic diagram of the penumbra provided in the embodiments of this application, as shown below. Figure 4b As shown, the region includes the penumbra, the umbra, and the unoccluded region. The penumbra is brighter than the umbra because it receives some virtual light, but it is less bright than the unoccluded region because it receives less virtual light.
[0121] The penumbra intensity of a point is used to adjust the base shadow data of that point based on the actual propagation path of virtual rays between the virtual light source and the point. Specifically, it characterizes the influence of the propagation relationship of virtual rays relative to the point on the shadow effect at that point. Here, the propagation relationship refers to whether the virtual ray propagates to the point. It should be understood that if a virtual ray emitted by the virtual light source does not propagate to a point, it means that the virtual ray has no effect on the shadow effect at that point. However, if a virtual ray emitted by the virtual light source propagates to the point, it means that the virtual ray can brighten the shadow effect at that point to some extent. Thus, by comprehensively considering the propagation relationship of each virtual ray emitted by the virtual light source relative to a point, the overall influence of the virtual light source on the shadow effect at that point can be determined.
[0122] It should be noted that the "actual" propagation path of the virtual ray between the virtual light source and the point is not relative to the "virtual" aspect of the virtual scene, but rather based on the parameter settings used to render that virtual scene. Furthermore, the actual propagation path of the virtual ray in the virtual scene is not necessarily a straight line between the virtual light source and the point; the actual propagation path may fail to reach the corresponding point due to changes in the direction of the virtual ray or obstruction. More specifically, the aforementioned penumbra intensity refers to the weighted data used to adjust the basic shadow data. By using penumbra intensity to weight the basic shadow data of each point, the shadow effect at each point can correspond to the virtual ray reception at that point, thus reflecting the overall shadow effect described above. Figure 4a There are shadow areas with different brightness levels.
[0123] The penumbra intensity of each point is determined based on its distance from the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source. The distance from each point to the virtual light source in the virtual scene can be calculated based on the coordinates of the point and the virtual light source. The propagation distance of the virtual light emitted by the virtual light source indicates the propagation distance of the virtual light emitted by the virtual light source deployed in the virtual scene. Typically, the virtual light emitted by the virtual light source will be blocked or have its propagation direction changed by a 3D model or the ground in the virtual scene during propagation. In this case, the distance from the virtual light source to the blocking point can be considered as the propagation distance of the virtual light, or the distance from the virtual light source to the point where the direction of the virtual light changes can be considered as the propagation distance of the virtual light.
[0124] It should be understood that the embodiments of this application are used for shadow rendering of virtual scenes. Therefore, the penumbra intensity of each of the multiple points determined in this step provides basic data for shadow rendering. That is, when performing shadow rendering, the penumbra intensity can be used as a reference.
[0125] In one possible implementation, step S203 above, "determining the penumbra intensity of each of the multiple points based on their respective distances to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source," may include:
[0126] For each point, determine the first distance from the point to the virtual light source, and determine the actual propagation distance of the virtual ray associated with the point as the second distance; determine the penumbra intensity of the point based on the ratio of the first distance to the second distance; the original propagation direction of the virtual ray associated with the point passes through the point.
[0127] For each point, the first distance from the point to the virtual light source can be determined based on the difference between the point's coordinates and the virtual light source's coordinates; that is, the difference in coordinates between the point and the virtual light source is used as the first distance. Alternatively, the actual propagation distance of the virtual ray associated with the point can be used as the second distance. The original propagation direction of the virtual ray associated with the point passes through that point, and the actual propagation distance of the virtual ray refers to the distance from the virtual light source to the blocking point (i.e., the point where the propagation direction of the virtual ray changes due to being blocked). When there is no obstruction between the point and the virtual light source, the virtual ray associated with the point will continue to propagate in the virtual scene after passing through that point. In this case, the distance from the point to the virtual light source (the first distance) will be less than the actual propagation distance of the virtual ray (the second distance). However, when there is obstruction between the point and the virtual light source, the virtual ray associated with the point will be blocked before reaching that point, and therefore cannot continue to propagate to that point. In this case, the distance from the point to the virtual light source (the first distance) will be greater than the actual propagation distance of the virtual ray (the second distance).
[0128] Then, the penumbra intensity of the point can be determined based on the ratio of the first distance to the second distance, as shown in Formula 9.
[0129]
[0130] Where P(i,j,k) represents the penumbra intensity determined based on the ratio of the first and second distances from point (i,j,k), d l d represents the first distance determined based on point (i, j, k). max This represents the second distance determined based on the virtual ray associated with point (i, j, k).
[0131] Therefore, by using the above method, in the shadow generation process, not only the distance from the point to the virtual light source is considered, but also the actual propagation distance of the virtual light rays associated with the point is considered. That is, the occlusion relationship of the virtual light rays emitted by the virtual light source relative to the point is considered during the propagation process. The penumbra intensity of the point can be further determined based on the ratio of the first distance to the second distance, which is more in line with the actual propagation of virtual light rays.
[0132] In one possible implementation, the method provided in this application embodiment may further include:
[0133] The penumbra intensities of multiple points are input into the second convolutional filter to obtain the optimized penumbra intensities of multiple points output by the second convolutional filter after applying the adjusted filter parameters; the adjusted filter parameters are obtained by adjusting the original filter parameters of the second convolutional filter using the second coefficient; the second coefficient is determined based on the penumbra intensities.
[0134] The second convolution filter is a tool used to perform convolution operations in three-dimensional space. Its difference from the first convolution filter lies in that the second convolution filter performs convolution operations based on the penumbra intensity of multiple points, outputting optimized penumbra intensities for each point. These optimized penumbra intensities refer to the output results obtained after the second convolution filter performs convolution operations based on the penumbra intensities of multiple points. Optimized penumbra intensities are used to characterize penumbra intensities of higher quality and more closely reflect actual virtual light propagation.
[0135] By inputting the penumbra intensity of each of the multiple points into the second convolution filter, the optimized penumbra intensity of each of the multiple points output by the second convolution filter can be obtained, as shown in Formula 10.
[0136]
[0137] Among them, P refined (i,j,k) represents the optimized penumbra intensity corresponding to point (i,j,k), P(i,j,k) represents the penumbra intensity corresponding to point (i,j,k), and W s ′ hadow (m,n,p) represents the filter parameters applied by the second filter when processing the penumbra intensity.
[0138] It should be noted that the filter parameters applied by the second convolutional filter when processing penumbra intensity are obtained by adjusting the original filter parameters of the second convolutional filter using the second coefficients. The original filter parameters of the second convolutional filter refer to the unadjusted filter parameters. The second coefficients are used to adjust the original filter parameters in the second convolutional filter, so that the adjusted filter parameters can generate a penumbra intensity that more closely resembles the actual effect and has softer edges. The second coefficients can be determined based on the penumbra intensity, meaning they can be obtained through training based on the penumbra intensity.
[0139] As an example, a second coefficient classification network can be used to determine the second coefficient corresponding to the penumbra intensity of multiple points. Based on the determined second coefficient, the original filter parameters in the second convolutional filter are adjusted so that the second convolutional filter can generate an optimized penumbra intensity with softer edges. Specifically, this second coefficient classification network can be a multi-class neural network for performing multi-class classification tasks. It can perform multi-class classification tasks based on the shadow reference data of the input points to determine the second coefficient among multiple candidate second coefficients that is most suitable for processing the shadow reference data of that point.
[0140] The second coefficient classification network can be pre-trained based on the training penumbra intensity and the corresponding labeled second coefficients. The training penumbra intensity and the corresponding labeled second coefficients refer to the training data used in training the second coefficient classification network. The method for obtaining the training penumbra intensity is the same as the method for obtaining the penumbra intensity of multiple points in a 3D scene. The training penumbra intensity also includes the corresponding labeled second coefficients, i.e., the labels during the training process. These labeled second coefficients can be obtained through manual annotation.
[0141] During training, multiple training penumbra intensities can be input into the second coefficient classification network to be trained. The second coefficient classification network classifies the multiple training penumbra intensities and outputs a predicted second coefficient corresponding to each training penumbra intensity. Then, based on the difference between the predicted second coefficient corresponding to each training penumbra intensity and the labeled second coefficient, the second coefficient classification network is trained so that the predicted second coefficient output by the second coefficient classification network gradually approaches the labeled second coefficient, thereby optimizing the classification performance of the second coefficient classification network and improving its accuracy.
[0142] It should be understood that in practical applications, a training termination condition can be preset. When the training of the second coefficient classification network reaches this termination condition, the training of the second coefficient classification network can be terminated. This termination condition could be, for example, that the number of training epochs for the second coefficient classification network reaches a preset threshold; or, for example, that the performance of the second coefficient classification network is tested and found to have reached a preset performance standard (such as reaching a preset classification accuracy); or, for example, that the performance of the second coefficient classification network is tested and found to no longer significantly improve with further training. This application does not impose any limitations on the training termination condition in this embodiment.
[0143] Based on the training process described above, a second coefficient classification network can be obtained. The penumbra intensity of multiple points can be input into this network for classification, yielding the second coefficients for each point. After determining the second coefficients for each point, the original filter parameters used to optimize the penumbra intensity of the points in the second convolutional filter can be adjusted based on these coefficients, as shown in Formula 11.
[0144] W s ′ hadow (m,n,p)=W(m,n,p)·h NN Formula 11 (X(i,j,k))
[0145] Among them, W s ′ hadow (m,n,p) represents the filter parameters adjusted using the second coefficient, W(m,n,p) represents the original filter parameters in the second convolution filter, and h NN (X(i,j,k)) represents the second coefficient corresponding to point (i,j,k) obtained after processing the penumbra intensity corresponding to point (i,j,k) through the second coefficient classification network; it should be understood that the above W s ′ hadow (m,n,p) are the filter parameters used in the second convolution filter to optimize the penumbra intensity at point (i,j,k).
[0146] As an example, the training process of the original filter parameters in the second convolutional filter is similar to that in the first convolutional filter. The difference is that the training shadow reference data in the training process is replaced with the training penumbra intensity, and the adjustment coefficient in the training process is replaced with the second coefficient instead of the first coefficient. The remaining steps are similar and will not be described in detail here.
[0147] Therefore, by inputting the penumbra intensity of multiple points into the second convolutional filter using the above method, the optimized penumbra intensity of each point can be obtained from the output of the second convolutional filter. The filter parameters applied by the second convolutional filter when processing penumbra intensity are obtained by adjusting the original filter parameters of the second convolutional filter using the second coefficient. The second coefficient is determined based on the penumbra intensity, so that the filter parameters adjusted by the second coefficient can better regulate the penumbra region. Thus, in the process of processing penumbra intensity, the second convolutional filter can generate optimized penumbra intensity with softer edges based on the adjusted filter parameters.
[0148] S204: By utilizing the penumbra intensity of multiple points, the basic shadow data of each point is weighted to obtain the weighted shadow data of each point. The weighted shadow data is used for shadow rendering of the points.
[0149] Given the penumbra intensity and base shadow data of multiple points, the base shadow data of multiple points can be weighted using the penumbra intensity of each point. That is, the penumbra intensity of each point is used as the weight of the base shadow data of each point to obtain the product of the base shadow data and the penumbra intensity of each point. This product result can be used as the weighted shadow data of each point, which is used to indicate the actual shadow effect in the 3D scene.
[0150] Therefore, by using the above method, the basic shadow data of multiple points can be determined, that is, the shadow data formed after the virtual light emitted by the virtual light source is blocked. The penumbra intensity of multiple points can also be determined, that is, the soft transition area around the shadow formed after the virtual light emitted by the virtual light source shines on the point. By using the penumbra intensity of multiple points, the basic shadow data of multiple points can be weighted to generate weighted shadow data of multiple points that more closely resembles the actual shadow effect.
[0151] It should be understood that the embodiments of this application are used for rendering virtual scenes. After obtaining the weighted shadow data of multiple points through this step, the weighted shadow data of multiple points can be used as rendering input data to participate in the rendering of the virtual scene, so as to render the shadows in the virtual scene.
[0152] When the optimized penumbra intensity of multiple points is output through the second convolutional filter, the "using the penumbra intensity of multiple points to weight the basic shadow data of multiple points to obtain the weighted shadow data of multiple points" in S204 above can include:
[0153] By utilizing the optimized penumbra intensity of multiple points, the basic shadow data of each point is weighted to obtain the weighted shadow data of each point.
[0154] After determining the optimized penumbra intensity for each of the multiple points, the basic shadow data for each point can be weighted using these optimized penumbra intensities. This means using the optimized penumbra intensity of each point as the weight of its corresponding basic shadow data, and then using the weighted result as the weighted shadow data for each point. (See reference...) Figure 5 , Figure 5 This is a schematic diagram illustrating the determination of weighted shadow data for multiple points as provided in an embodiment of this application, such as... Figure 5As shown, the penumbra intensities of point A, ..., and point N are input into the second convolutional filter, respectively. This yields the optimized penumbra intensities of point A, ..., and point N output by the second convolutional filter. Then, the basic shadow data of point A can be weighted based on the optimized penumbra intensities of point A to obtain the weighted shadow data of point A; similarly, the basic shadow data of point N can be weighted based on the optimized penumbra intensities of point N to obtain the weighted shadow data of point N.
[0155] By utilizing the optimized penumbra intensity of multiple points and weighting the basic shadow data of each point, we can obtain weighted shadow data of multiple points that more closely resembles the actual shadow situation.
[0156] The shadow generation method provided in this application proposes a scheme for automatically generating shadow effects in a virtual scene based on a convolutional filter. The method includes: acquiring depth data, normal data, and lighting data for multiple points in the virtual scene, as shadow reference data for each point; that is, for each point in the virtual scene, depth data reflecting the propagation path of virtual light at that point, normal data reflecting the angle between the virtual light and the point, and lighting data reflecting the lighting conditions at that point in the virtual scene can be used as shadow reference data to determine the shadow effect at that point. Then, the shadow reference data of each of the multiple points is input into the first convolutional filter to obtain the basic shadow data of each of the multiple points output by the first convolutional filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data. The first coefficient used to adjust the original filter parameters of the first convolutional filter is determined based on the shadow reference data, so that the filter parameters adjusted by the first coefficient are more suitable for analyzing the lighting conditions in the current virtual scene. Accordingly, the first convolutional filter processes the shadow reference data based on the filter parameters adjusted by the first coefficient to obtain basic shadow data that accurately reflects the shadow situation in the virtual scene. Furthermore, considering that the propagation of virtual light emitted from the virtual light source in the virtual scene to each point affects the shadow effect at each point, such as affecting the brightness of the shadow, the penumbra intensity of each of the multiple points can be determined based on the distance from each point to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted from the virtual light source. The penumbra intensity of a point can be adjusted based on the actual propagation path of the virtual light between the virtual light source and the point to adjust the basic shadow data of that point. After determining the penumbra intensity, the base shadow data of multiple points can be weighted using their individual penumbra intensities. This weighted weighting adjusts the base shadow data of each point based on the impact of virtual light propagation on the shadow effect at that point. This results in more accurate weighted shadow data that better reflects the actual conditions of the virtual scene. This weighted shadow data can then be used for shadow rendering at multiple points. Therefore, this method can automatically and accurately generate shadow effects in a virtual scene, improving the efficiency of shadow effect setup and reducing labor and time costs.
[0157] In one possible implementation, when the virtual scene includes multiple virtual light sources, the step S202 above, "inputting the shadow reference data of each of the multiple points into the first convolution filter to obtain the basic shadow data of each of the multiple points output by the first convolution filter through the application of filter parameters," may include:
[0158] For each virtual light source, the shadow reference data of multiple points relative to the virtual light source are input into the first convolution filter to obtain the basic shadow data of multiple points relative to the virtual light source, which are output by the first convolution filter by applying the filter parameters; the lighting data in the shadow reference data of the points relative to the virtual light source is used to characterize the lighting of the virtual light source at the point.
[0159] For each point, the basic shadow data of the point relative to multiple virtual light sources is weighted and summed to obtain the comprehensive basic shadow data of the point.
[0160] In a virtual scene with multiple virtual light sources, for each virtual light source, the lighting data of multiple points relative to the virtual light source can be determined based on the virtual light emitted by the virtual light source. For example, the lighting direction and intensity of the virtual light emitted by the virtual light source at these multiple points can be determined. Then, using the depth data, normal data, and lighting data of each of the multiple points relative to the virtual light source, shadow reference data of each of the multiple points relative to the virtual light source can be formed.
[0161] For each virtual light source, after determining the shadow reference data of multiple points relative to that virtual light source, this data can be input into a first convolution filter. By performing a convolution operation through the first convolution filter, the basic shadow data of the multiple points relative to that virtual light source can be obtained. It should be understood that the implementation method of determining the basic shadow data of multiple points relative to a single virtual light source using the first convolution filter can be found in the relevant description of S202 above, and will not be repeated here. The above convolution operation is performed for each virtual light source until the basic shadow data of multiple points relative to each virtual light source is determined.
[0162] For each point, the basic shadow data of the point relative to multiple virtual light sources is weighted and summed to obtain the comprehensive basic shadow data of the point, as shown in Formula 12. The comprehensive basic shadow data of the point is used to characterize the shadow effects formed when different virtual light sources illuminate that point.
[0163]
[0164] Among them, S final S represents the comprehensive basic shading data of the points. i α represents the base shadow data of a point relative to the i-th virtual light source. i The fusion weight is the pre-set weight for the i-th virtual light source. Accordingly, each virtual light source has a pre-set fusion weight, and m represents the number of virtual light sources included in the virtual scene.
[0165] Therefore, in a virtual scene with multiple virtual light sources, shadow reference data for multiple points relative to each virtual light source can be determined. Then, for each virtual light source, the shadow reference data of each point relative to each virtual light source can be input into a first convolutional filter to obtain the basic shadow data of each point relative to each virtual light source, thus determining the basic shadow data of points under different virtual light sources. Next, for each point, the basic shadow data of the point relative to multiple virtual light sources is weighted and summed to fuse the basic shadow data of the point under multiple virtual light sources, thereby determining the shadow effect of the point under the illumination of multiple virtual light sources and obtaining the comprehensive basic shadow data of the point.
[0166] In one possible implementation, when the virtual scene includes multiple virtual light sources, the step S203 above, "determining the penumbra intensity of each of the multiple points based on the distances from each point to the virtual light sources in the virtual scene and the propagation distance of the virtual light emitted by the virtual light sources," may include:
[0167] For each virtual light source, the penumbra intensity of each point relative to the virtual light source is determined based on the distances of multiple points from the virtual light source and the propagation distance of the virtual light emitted by the virtual light source.
[0168] For each point, the penumbra intensity of the point relative to multiple virtual light sources is weighted and summed to obtain the comprehensive penumbra intensity of the point;
[0169] Correspondingly, the phrase "using the penumbra intensity of each of the multiple points to weight the basic shadow data of each of the multiple points, and obtaining the actual shadow data of each of the multiple points" in S204 above includes:
[0170] By using the combined penumbra intensity of multiple points, the combined basic shadow data of multiple points are weighted to obtain the weighted shadow data of multiple points.
[0171] In a virtual scene containing multiple virtual light sources, each virtual light source can be sequentially used as the currently processed virtual light source. Under the currently processed virtual light source, for each point, the penumbra intensity of that point relative to the currently processed virtual light source is calculated. Specifically, for each point, the distance from that point to the currently processed virtual light source can be determined based on the difference between the coordinate information of that point and the coordinate information of the currently processed virtual light source, and this distance is used as the first distance. Then, the actual propagation distance of the virtual light rays associated with that point can be used as the second distance. Furthermore, the ratio between the first distance and the second distance can be calculated to obtain the penumbra intensity of that point under the currently processed virtual light source. In this way, the penumbra intensity of multiple points under the currently processed virtual light source is determined.
[0172] Then, switch the currently processed virtual light source and use the next virtual light source as the current processed virtual light source. Repeat the above operation until all virtual light sources are used as the current processed virtual light sources, and the penumbra intensity of multiple points under each virtual light source is obtained. The specific method for determining the penumbra intensity can be referred to Formula 9 in S203 above, and will not be elaborated here.
[0173] After determining the penumbra intensity of each point relative to multiple virtual light sources, for each point, the weighted sum of the penumbra intensities relative to the multiple virtual light sources can be performed to obtain the comprehensive penumbra intensity of that point, as shown in Formula 13. The comprehensive penumbra intensity of a point is used to characterize the penumbra effect formed by the illumination of that point by multiple virtual light sources.
[0174]
[0175] Among them, P optimized (i,j,k) represents the combined penumbra intensity of point (i,j,k), P i (i,j,k) represents the penumbra intensity of point (i,j,k) relative to the i-th virtual light source, α i The fusion weight is the pre-set weight for the i-th virtual light source. Accordingly, each virtual light source has a pre-set fusion weight, and m represents the number of virtual light sources included in the virtual scene.
[0176] After determining the overall penumbra intensity of multiple points, the overall shadow data of multiple points can be weighted using the overall penumbra intensity of multiple points. That is, the overall penumbra intensity of multiple points is used as the weight of the overall shadow data of the corresponding multiple points, and the weighted result can be used as the weighted shadow data of multiple points.
[0177] Therefore, in a virtual scene with multiple virtual light sources, for each virtual light source, the penumbra intensity of each point relative to that virtual light source can be determined based on the distances from each point to the virtual light source and the propagation distance of the virtual light emitted by the virtual light source. This determines the penumbra effect of a point under different virtual light source illumination. Then, for each point, the penumbra intensities of the point relative to multiple virtual light sources can be weighted and summed to fuse the penumbra intensities of the point under different virtual light sources. This allows us to determine the contribution of different virtual light sources to the same area, obtaining a comprehensive penumbra intensity that more closely resembles real-world shadow conditions. Finally, after obtaining the comprehensive penumbra intensities of multiple points, the comprehensive basic shadow data of each point can be weighted using these intensities. This allows us to adjust the real-world shadow effect of points illuminated by corresponding virtual light sources based on the penumbra conditions of points under different virtual light sources, resulting in weighted shadow data that more closely resembles real-world shadow conditions under different virtual light source illumination.
[0178] In one possible implementation, when the virtual scene is a three-dimensional scene, the deployment positions of the virtual light sources in the three-dimensional scene can be determined in the following way:
[0179] For each candidate light source position in the 3D scene, the measurement parameters corresponding to the candidate light source position are determined based on the direction of the virtual light source, the normal vector of the surface of each 3D model in the 3D scene, and the vector from each 3D model to the candidate light source position.
[0180] The candidate light source locations that meet the preset measurement conditions and are identified are used as the deployment locations of the virtual light sources.
[0181] A 3D scene includes several candidate light source positions, which are pre-defined locations where virtual light sources can be deployed. Virtual light sources deployed at different candidate light source positions may produce different shadow effects. To ensure the optimal shadow effect in the 3D scene, the shadow effects produced at each candidate light source position can be analyzed, and then the candidate light source position that produces the best shadow effect can be selected as the deployment location for the virtual light source.
[0182] In practical applications, the representation of virtual light sources varies depending on their type. Common light source types in 3D graphics include point lights, directional lights, spotlights, and area lights. Each type has different physical characteristics and lighting effects; therefore, it is necessary to select the appropriate light source type for deployment in the 3D scene based on the specific requirements of the scenario.
[0183] Point lights emit virtual rays from a specific point in all directions, radiating outwards in space. They are suitable for simulating small, localized light sources, such as virtual light bulbs or candles. Directional lights emit parallel virtual rays that do not attenuate during propagation. They are suitable for simulating distant virtual light sources, such as virtual sunlight, and also for large-area uniform lighting, such as rendering outdoor scenes. Spotlights are highly directional virtual light sources, concentrating their rays within a cone-shaped area. They are suitable for simulating stage lighting or focused lighting. Area lights are virtual light sources composed of numerous point lights, thus producing more natural shadows and penumbra effects.
[0184] For local light sources (such as point sources and spotlights), the position of the light source can be determined by P. light = (x, y, z) to represent P lightLet (x, y, z) represent the position vector of the light source, and (x, y, z) represent the coordinates of the virtual light source in the 3D scene. For directional lights, the light source position can be represented by a direction vector, and its position can be determined by D. light =(d x d y d z D is represented by ) light d represents the direction vector of the virtual ray from the light source. x d y d z These represent the horizontal, vertical, and axial components of the direction vector, respectively. The components of the direction vector can be determined by adjusting the azimuth and elevation angles of the virtual light source in space. For a region light source, the light source position can be represented by determining its center position and boundary; that is, the light source position can be represented by P. cne =(x c y c , z c ) and S ae = (w, h) to represent P cne S represents the center position of the area light source. ae This represents the width w and height h of the area light source.
[0185] For each candidate light source location in a 3D scene, the corresponding measurement parameters can be determined based on the light source direction of the virtual light source to be deployed at the currently calculated candidate light source location, the normal vector of each 3D model surface in the 3D scene, and the vector from each 3D model to the currently calculated candidate light source location. The measurement parameters corresponding to the candidate light source location are used to measure the quality of the shadow effect produced when a virtual light source is deployed at the candidate light source location.
[0186] A 3D scene includes at least one 3D model, and each 3D model includes multiple surfaces. The normal vector of each surface of a 3D model can be determined by the difference between the maximum and minimum normal vectors of the surfaces included in that 3D model. Specifically, the difference between the maximum and minimum normal vectors of the surfaces included in that 3D model can be used as the normal vector of that 3D model surface. For each 3D model in the 3D scene, the normal vectors of all the meshes included in that 3D model can be calculated, and the maximum and minimum normal vectors can be selected from them.
[0187] As an example, the vector from each 3D model to the currently calculated candidate light source position can be determined based on the coordinate information of the center point of each 3D model and the coordinate information of the currently calculated candidate light source position.
[0188] Specifically, the measurement parameters corresponding to the currently calculated candidate light source positions can be found in Formula 14.
[0189]
[0190] Among them, P k This represents the metric parameter corresponding to the currently calculated candidate light source location, where n represents the number of 3D models in the 3D scene, L represents the virtual light source direction of the virtual light source deployed at the currently calculated candidate light source location, and N... i M represents the normal vector of the i-th surface of the 3D model in the 3D scene. i This represents the vector from the i-th 3D model to the currently calculated candidate light source location. It should be understood that the light source type of the virtual light source deployed at the candidate light source location can be preset.
[0191] After calculating the measurement parameters corresponding to each candidate light source position according to the above formula, the candidate light source positions whose corresponding measurement parameters meet the preset measurement conditions can be determined as the deployment positions of the virtual light sources. The preset measurement conditions refer to the conditions used to indicate whether a candidate light source position corresponding to a measurement parameter can be used as a deployment position of the virtual light source. If the measurement parameters of a candidate light source position meet the preset measurement conditions, then that candidate light source position can be used as the final deployment position of the virtual light source. The preset measurement conditions can be referred to in Formula 15.
[0192]
[0193] Among them, P optimal P represents the deployment location of the virtual light source determined based on preset measurement conditions. light This represents the candidate light source positions. The formula on the right side of the equals sign represents the preset evaluation criteria, indicating that the candidate light source position with the smallest corresponding evaluation parameter is selected as the deployment position of the virtual light source. Additionally, the direction and shape of shadows can be controlled by adjusting the virtual light source's direction vector.
[0194] Therefore, by using the above method, for each candidate light source position in the 3D scene, based on the currently calculated light source direction of the virtual light source, the normal vector of each 3D model surface in the 3D scene, and the vector from each 3D model to the candidate light source position, that is, based on the distribution of 3D models in the 3D scene and the lighting conditions of different candidate light source positions, the measurement parameters of each candidate light source position are determined. Based on the measurement parameters corresponding to each candidate light source position and the preset measurement conditions, the virtual light source position that can maximize the lighting effect and generate the expected shadow effect is determined in the 3D scene.
[0195] In one possible implementation, when the virtual scene is a three-dimensional scene, the initial illumination intensity of the virtual light source in the three-dimensional scene can be determined in the following way:
[0196] For each 3D model in the 3D scene, the adaptive lighting intensity of the virtual light source relative to the 3D model is determined based on the preset lighting intensity, wavelength reflectivity, average wavelength reflectivity of the scene, and the angle between the virtual light ray of the virtual light source and the normal of the 3D model surface.
[0197] The initial illumination intensity of the virtual light source is obtained by weighted summing of the adaptive illumination intensities of the virtual light source relative to each 3D model in the 3D scene.
[0198] The preset illumination intensity of a virtual light source refers to the initial illumination intensity set beforehand for the virtual light source, that is, the original illumination intensity at the virtual light source location. The illumination intensity of a virtual light source attenuates during propagation. For different types of virtual light sources, their respective attenuation formulas can be expressed by the following formulas:
[0199] The formula for light attenuation of a point light source can be expressed as Formula 16.
[0200]
[0201] Where I represents the illumination intensity of the point light source, I0 represents the preset illumination intensity of the point light source, and d represents the distance between the point light source and the object receiving the light.
[0202] The illumination intensity of a directional light source can be expressed as a constant: I = I0.
[0203] The intensity distribution of a spotlight can be represented by Equation 17.
[0204] I = I0·cos n (θ) Formula 17
[0205] Where I represents the spotlight intensity, I0 represents the preset spotlight intensity, θ represents the angle between the virtual ray and the central axis of the spotlight, and n is the spotlight attenuation factor. The larger n is, the more concentrated the virtual ray is and the faster the light intensity attenuates.
[0206] The distribution of light intensity of regional light sources is relatively complex. It can be obtained by integrating the point light sources within the region. The light intensity can be referred to Formula 18.
[0207]
[0208] Where I represents the illumination intensity of the regional light source, I0 represents the preset illumination intensity of the regional light source, A represents the surface area of the regional light source, d represents the distance between the regional light source and the illuminated object, and da represents the small area element within the region.
[0209] It should be understood that the above light intensity can be used as the light data in the shadow reference data in S201.
[0210] Wavelength reflectivity refers to the ability of a 3D model to reflect virtual light emitted from a virtual light source. Specifically, it can be the reflectivity of the 3D model for the λ wavelength of the virtual light source. The scene average wavelength reflectivity is the average of the wavelength reflectivity of all 3D models in the 3D scene; specifically, it can be the average reflectivity of each 3D model for the λ wavelength. For each 3D model in the 3D scene, the adaptive lighting intensity of the virtual light source relative to the currently calculated 3D model can be determined based on the preset illumination intensity of the virtual light source, the wavelength reflectivity, the scene average wavelength reflectivity, and the angle between the virtual light ray from the virtual light source and the normal to the surface of the 3D model. The adaptive lighting intensity refers to the lighting intensity adapted to the currently calculated 3D model. Based on the adaptive lighting intensity, a more suitable expected shadow effect can be determined for the currently calculated 3D model.
[0211] In one possible implementation, refer to Figure 6 , Figure 6 This is a flowchart illustrating the process of determining the adaptive illumination intensity of a virtual light source relative to a 3D model, as provided in an embodiment of this application. The above-mentioned "determining the adaptive illumination intensity of the virtual light source relative to the 3D model based on the preset illumination intensity, wavelength reflectivity, average wavelength reflectivity of the scene, and the angle between the virtual ray of the virtual light source and the normal to the surface of the 3D model" can include steps S601-S604:
[0212] S601: Determine the tangent ray of the virtual light source to the 3D model, and the position of the tangent point of the tangent ray on the surface of the 3D model; determine the angle between the tangent ray and the normal at the position of the tangent point, as the tangential angle.
[0213] A tangent ray is a virtual ray emitted by a virtual light source that is tangent to the surface of a 3D model. When a virtual ray is tangent to the surface of a 3D model at a point, this virtual ray can be taken as the tangent ray of the virtual light source to the 3D model. At the same time, the point where the tangent ray is tangent to the surface of the 3D model can be taken as the point of tangency, and the coordinate information of this point can be used as the location of the point of tangency.
[0214] After determining the tangent ray of the virtual light source to the 3D model, and the tangent point of the tangent ray on the surface of the 3D model, the normal at the tangent point can be further determined, which is the vector perpendicular to the tangent point. After determining the normal at the tangent point, the angle between the tangent ray and the normal at the tangent point can be determined based on the tangent ray and the normal at the tangent point, and this angle can be used as the tangential angle.
[0215] S602: For each sub-region on the 3D model, determine the angle between the virtual ray emitted by the virtual light source that reaches the sub-region and the normal of the sub-region, and use it as the reference angle for the sub-region.
[0216] Sub-regions on a 3D model refer to different regions within the 3D model. Sub-regions on a 3D model can be determined based on the corresponding mesh model of the 3D model. Specifically, one or more meshes in the mesh model can be used as sub-regions on the 3D model.
[0217] For each sub-region in the 3D model, the angle between the virtual ray emitted by the virtual light source reaching the currently calculated sub-region and the normal of the currently calculated sub-region can be determined. This angle is used as the reference angle for the currently calculated sub-region. The reference angle refers to the angle determined based on the virtual ray reaching the sub-region and the normal of the sub-region, and is used to calculate the adaptive lighting intensity of the 3D model to which the sub-region belongs.
[0218] The normal of a sub-region can be determined by calculating the average of the normals of all grids in that sub-region. In other words, the average of the normals of all grids in that sub-region is taken as the normal of that sub-region. The normal of a grid can be obtained by calculating the cross product of the two edge vectors of the grid.
[0219] Based on the above method of calculating the reference angle, the reference angle corresponding to each sub-region in the 3D model can be determined.
[0220] S603: Average the reference angles corresponding to each sub-region on the 3D model to obtain the average reference angle.
[0221] After determining the reference angle corresponding to each sub-region in the 3D model, the average of the reference angles corresponding to each sub-region in the 3D model can be calculated, and the calculated average value can be used as the average reference angle.
[0222] S604: Based on the preset illumination intensity, the ratio between wavelength reflectivity and the average wavelength reflectivity of the scene, and the ratio between the cosine of the tangential angle and the cosine of the average reference angle, determine the adaptive illumination intensity of the virtual light source relative to the 3D model.
[0223] As an example, for each 3D model in a 3D scene, the wavelength reflectivity of the 3D model can be determined based on the ratio of the reflected light intensity to the incident light intensity of the virtual light emitted by the virtual light source. After determining the wavelength reflectivity of each 3D model in the 3D scene, the average wavelength reflectivity of the scene can be obtained by averaging the wavelength reflectivity of each 3D model in the 3D scene.
[0224] After determining the wavelength reflectance and the average wavelength reflectance of the scene, for each 3D model, the adaptive illumination intensity of the virtual light source relative to the 3D model can be determined based on the preset illumination intensity, the ratio between the wavelength reflectance and the average wavelength reflectance of the scene, and the ratio between the cosine of the tangential angle and the cosine of the average reference angle, as shown in Formula 19.
[0225]
[0226] Among them, I adjusted I0 represents the adapted illumination intensity of the virtual light source relative to the 3D model, I0 represents the preset illumination intensity of the virtual light source, and R(λ) represents the wavelength reflectivity. avg (λ) represents the average wavelength reflectivity of the scene, and θ represents the tangential angle. avg This represents the average reference angle.
[0227] Therefore, using the above method, based on the preset illumination intensity of the virtual light source, the ratio between wavelength reflectivity and the average wavelength reflectivity of the scene, and the ratio of the cosine of the tangential angle to the cosine of the average reference angle, the optimal illumination intensity of the virtual light source relative to 3D models of different materials can be determined. This is the adapted illumination intensity of the virtual light source relative to the 3D model, and the lighting conditions that meet the expected shadow effect can be determined based on this adapted illumination intensity. Furthermore, in the process of determining the adapted illumination intensity of the 3D model, the reflectivity of the virtual light source for different areas of the 3D model and the propagation direction of the virtual light are considered, which helps to determine the optimal illumination intensity that better fits the 3D model.
[0228] The adaptation intensity of the virtual light source relative to each 3D model can be determined using the above method. After determining the adaptation intensity of the virtual light source relative to each 3D model, the adaptation intensity of the virtual light source relative to each 3D model in the 3D scene can be weighted and summed. For example, the adaptation intensity of the corresponding 3D model can be weighted based on the preset weights of each 3D model in the 3D scene. By adding the weighted results of each 3D model, the initial illumination intensity of the virtual light source deployed in the 3D scene can be obtained.
[0229] Therefore, using the above method, for each 3D model in the 3D scene, based on the preset illumination intensity, wavelength reflectivity, average scene reflectivity, and the angle between the virtual light source's virtual rays and the normal to the 3D model's surface, the adaptive illumination intensity of the virtual light source relative to the 3D model is determined. This allows for the determination of the optimal illumination intensity of the virtual light source for each 3D model in the 3D scene. Then, the adaptive illumination intensities of the virtual light source relative to each 3D model in the 3D scene are weighted and summed to fuse the optimal illumination intensity of the virtual light source relative to each 3D model in the 3D scene, thus determining the initial illumination intensity of the virtual light source that generates a more consistent and realistic shadow effect. Furthermore, this method ensures that the initial illumination intensity of the virtual light source can adapt to different 3D scenes, generating adaptive and realistic shadow data.
[0230] In one possible implementation, when the virtual scene is a three-dimensional scene, before acquiring the depth data, normal data, and lighting data of multiple points in the virtual scene as shadow reference data for each of the multiple points, the method provided in this application embodiment may further include:
[0231] For each 3D model in the 3D scene, the sub-region to be simplified is determined based on the complexity of each sub-region on the mesh model; at least one simplification process, namely vertex merging and edge folding, is performed on the sub-region to be simplified.
[0232] Vertex merging is used to merge multiple vertices into one vertex by referencing the positions and normal vectors of the vertices in the sub-region to be simplified; edge folding is used to merge two vertices of the edge to be folded into one vertex based on the positions and weights of the two vertices of the edge to be folded in the sub-region to be simplified. The weight of the vertex is determined according to the normal vector of the vertex and the normal vector of the surrounding mesh of the edge to be folded.
[0233] A mesh model corresponding to a 3D model refers to a model composed of polygonal meshes consisting of vertices, edges, and faces, used to describe the solid structure of the 3D model. Each sub-region on the mesh model corresponds to a sub-region in the 3D model. The complexity of each sub-region on the mesh model can be determined by the number of meshes included in the sub-region and a preset mesh number threshold. For example, several mesh number threshold ranges can be preset, with different mesh number threshold ranges corresponding to different complexities. Therefore, the mesh number threshold range to which the number of meshes included in a sub-region belongs can be determined, and the complexity corresponding to that mesh number threshold range can be determined as the complexity of that sub-region.
[0234] For each 3D model in a 3D scene, the complexity of each sub-region on the mesh model can be determined using the aforementioned complexity determination method. If the complexity of a sub-region in the mesh model exceeds a preset complexity threshold, that sub-region can be designated as a sub-region to be simplified. A sub-region to be simplified refers to a sub-region in the 3D model that requires simplification. Performing simplification on this sub-region can effectively reduce the workload of subsequent related calculations.
[0235] After identifying the sub-region to be simplified, at least one simplification method, either vertex merging or edge folding, can be applied to the sub-region.
[0236] Vertex merging refers to combining adjacent or nearby vertices into a new vertex without significantly altering the shape of the 3D model. Vertex merging can be based on the coordinate positions and normal vectors of multiple vertices in the sub-region to be simplified, merging multiple vertices into one vertex, as shown in Formula 20.
[0237]
[0238] Among them, V new V represents the new vertex after the merger, n represents the number of vertices involved in the merger, and V represents the number of vertices involved in the merger. i N represents the coordinates of the vertices participating in the vertex merging. i Represents vertex V i The corresponding normal vector.
[0239] Edge folding refers to merging the two vertices of an edge into a new vertex, thereby reducing the number of grid cells in the region to be simplified. Edge folding can be based on the coordinate positions and weights of the two vertices of the edge to be folded in the sub-region to be simplified, merging the two vertices of the edge to be folded into a new vertex, as shown in Formula 21.
[0240] V new =w1·V1+w2·V2Formula 21
[0241] Among them, V new V1 and V2 represent the coordinates of the two vertices of the edge to be folded, respectively. w1 represents the weight of vertex V1 and w2 represents the weight of vertex V2.
[0242] The weights of the two vertices of the edge to be folded can be determined based on the average of the vertex's normal vector and the normal vectors of the surrounding mesh of the edge to be folded, as shown in formulas 22 and 23. The surrounding mesh of the edge to be folded refers to the mesh adjacent to the edge, i.e., the mesh to which the edge belongs. The normal vector of the surrounding mesh can be obtained by calculating the cross product of the two edge vectors of the mesh.
[0243]
[0244] In Formula 22, w1 represents the weight of vertex V1, N1 represents the normal vector of vertex V1, and N... avg The average value of the normal vectors of the surrounding mesh of the edge to be folded is represented by w2 in Formula 23, which represents the weight of vertex V2 and N2 represents the normal vector of vertex V2. Usually, w1 + w2 = 1.
[0245] In one possible implementation, the edge to be folded in the above-described edge folding process can be selected in the following way:
[0246] For each edge in the sub-region to be simplified, the weight of the edge is determined based on the normal vector of the surrounding mesh and the angle between the edge and the direction of the virtual light source in the 3D scene.
[0247] The edges whose weights satisfy the preset importance conditions are identified as edges to be folded.
[0248] For each edge in the sub-region to be simplified, the weight of the edge can be determined based on the normal vector of the surrounding mesh of the currently calculated edge and the angle between the currently calculated edge and the direction of the virtual light source in the 3D scene, as shown in Formula 24. Here, the surrounding mesh of the edge refers to the mesh adjacent to the currently calculated edge, i.e., the mesh to which the currently calculated edge belongs.
[0249] w′ b =|N1·N2|·(1+α·cos(θ)) Formula 24
[0250] Among them, w′ b This represents the weight corresponding to the currently calculated edge, which is used to determine whether the edge needs to be collapsed. α represents the adjustment coefficient of the original weight. θ represents the angle between the currently calculated edge and the direction of the virtual light source in the 3D scene. When the 3D scene includes multiple virtual light sources, it can be the average of the angles between the virtual light source directions of each of the multiple virtual light sources and the edge. N1 and N2 represent the normal vectors of the surrounding mesh of the currently calculated edge.
[0251] Following the method described above for calculating the weights of edges, the weight of each edge in the sub-region to be simplified can be determined. Then, the weight of each edge can be compared with a preset importance condition. Edges whose weights satisfy the preset importance condition are designated as edges to be collapsed. The preset importance condition refers to the criteria used to determine which edges are to be collapsed. For example, the preset importance condition could be a preset importance threshold. The weight of each edge can be compared with the preset importance threshold. If the weight of an edge is less than the preset importance threshold, it indicates that the edge has low importance, and its weight satisfies the preset importance condition, so it can be designated as an edge to be collapsed. If the weight of an edge is greater than the preset importance threshold, it indicates that the edge has high importance, and its weight does not satisfy the preset importance condition, so it is not designated as an edge to be collapsed.
[0252] Therefore, the weight of each edge in the sub-region to be simplified can be determined using the above method. Based on a comparison of each edge's weight with a preset importance condition, edges whose weights satisfy the preset importance condition are designated as edges to be folded. According to the comparison results, edges with lower importance can be identified, and folding these edges ensures that the mesh model is simplified without affecting the geometry of the sub-region to be simplified. Furthermore, retaining edges with higher importance during the simplification process ensures higher geometric accuracy in the sub-region to be simplified, thereby ensuring the accuracy of shadow generation and improving the realism of the generated actual shadow data.
[0253] Therefore, using the above method, the sub-regions to be simplified can be determined based on the complexity of each sub-region in the mesh model corresponding to the 3D model. After determining the sub-regions to be simplified, at least one simplification process, namely vertex merging and edge collapsing, can be performed on them to reduce computational complexity while maintaining the main features of the geometry, thus ensuring the visual quality of the final rendering result of the 3D model corresponding to the mesh model. During the simplification process, vertex merging reduces the number of meshes in the sub-regions to be simplified. Furthermore, the similarity of normal directions is considered during vertex merging, ensuring more accurate vertex positions after merging and maintaining the shadow effects of the original 3D model. Edge collapsing also considers the differences in normals of surrounding meshes, thus effectively performing simplification on the sub-regions to be simplified while maintaining the main geometry of the 3D model.
[0254] In one possible implementation, the method provided in this application embodiment may further include:
[0255] For the merged vertices obtained through simplification, the normal vector of the merged vertex is determined based on the area and normal vector of each mesh involved in the simplification process.
[0256] During the simplification process for the sub-region to be simplified, the normal vectors corresponding to the vertices will shift due to changes in vertex positions, resulting in inaccurate shadow effects. After simplification, the normal vectors of the vertices can be re-determined based on the merged new vertices.
[0257] For the merged vertices obtained through simplification processing, i.e., for the merged vertices obtained through at least one simplification processing method, namely vertex merging or edge folding, the new normal vector of the merged vertex is determined based on the area and normal vector of each mesh involved in the simplification processing, as shown in Formula 25.
[0258]
[0259] Where, N new N represents the normal vector of the merged vertices. i A represents the normal vector of each mesh involved in the simplification process. i Let represent the area of each mesh participating in the simplification process, and m represent the number of meshes participating in the simplification process. It should be understood that when the simplification process is vertex merging, the meshes participating in the simplification process are the meshes to which each vertex belongs in the merging process; when the simplification process is edge collapsing, the meshes participating in the simplification process are the meshes to which the collapsed edges belong. Following the above calculation method, the normal vector corresponding to each merged vertex obtained through the simplification process in each sub-region to be simplified in the 3D model can be determined.
[0260] Therefore, by using the above method, the normal vector of the merged vertex can be determined based on the area and normal vector of each mesh involved in the simplification process. This allows the normal vector of the merged vertex to be updated synchronously when the vertices in the 3D model change, thus ensuring the accuracy of the shadow data determined based on the simplified 3D model.
[0261] In one possible implementation, the method provided in this application embodiment may further include:
[0262] For each 3D model in the 3D scene, the meshes whose curvature satisfies the preset curvature conditions are identified as the meshes to be optimized. Based on the curvature of the meshes to be optimized, the normal vectors of the meshes to be optimized are amplified.
[0263] In a mesh model, the curvature of the mesh represents the degree of bending of the mesh surface. The greater the curvature, the more curved the mesh surface; the smaller the curvature, the closer the mesh surface is to a straight line or plane. For example, the curvature of the mesh can be calculated using a quadratic surface fitting algorithm.
[0264] For each 3D model in a 3D scene, the curvature of each mesh can be calculated using a quadratic surface fitting algorithm. Mesh models whose curvature satisfies a preset curvature condition are then identified as meshes to be optimized. Here, the mesh to be optimized refers to the meshes in the mesh model that require optimization, and the preset curvature condition refers to the criteria used to determine the mesh to be optimized based on curvature. For example, the preset curvature condition could be a preset curvature threshold. If the curvature of a mesh is greater than the preset curvature threshold, then the curvature of that mesh is considered to meet the preset curvature condition, and that mesh can be considered a mesh to be optimized. If the curvature of a mesh is less than the preset curvature threshold, then the curvature of that mesh is considered to not meet the preset curvature condition, and that mesh is not considered a mesh to be optimized.
[0265] After determining the mesh to be optimized, the normal vector of the mesh can be amplified based on the curvature of the mesh, as shown in Formula 26.
[0266] N ajse =n w Formula 26 (1+k·C)
[0267] Where, N ajse n represents the normal vector of the mesh to be optimized after being enlarged. w Let represent the normal vector of the mesh to be optimized, k represent the adjustment coefficient of the normal vector, and C represent the curvature of the mesh to be optimized.
[0268] Therefore, using the above method, meshes whose curvature meets the preset curvature conditions can be selected from the mesh model, that is, meshes with larger curvature (such as boundaries or sharp parts) can be selected as the mesh to be optimized. After determining the mesh to be optimized, the normal vectors of the mesh to be optimized can be enlarged to enhance the sharpness of the shadow effect, thereby ensuring that the simplified mesh model can better retain the details of the shadow effect.
[0269] Finally, taking a virtual 3D scene as an example, a general overview of shadow generation methods is provided. (See also...) Figure 7 , Figure 7 This is a schematic diagram illustrating the structure for determining the actual shadow data of multiple points according to an embodiment of this application. The method includes:
[0270] As an example, for each 3D model in a 3D scene, based on the complexity of each sub-region within the mesh model, a sub-domain to be simplified is determined. At least one simplification process, either vertex merging or edge folding, is then performed on each sub-region to obtain a 3D scene including the simplified 3D model. Then, candidate light source positions that meet preset measurement conditions can be selected within this 3D scene as the deployment locations of the virtual light source. Further, for each 3D model in the 3D scene, the adapted illumination intensity of the virtual light source relative to the 3D model can be determined based on the preset illumination intensity, wavelength reflectivity, average scene reflectivity, and the angle between the virtual ray of the virtual light source and the normal to the surface of the 3D model. The adapted illumination intensities of the virtual light source relative to each 3D model in the 3D scene are then weighted and summed to obtain the initial illumination intensity of the virtual light source, thus completing the simulated placement of the virtual light source in the 3D scene.
[0271] Finally, depth data, normal data, and lighting data of multiple points in the 3D model can be obtained as shadow reference data for each point. This shadow reference data is then input into a first convolution filter for convolution operations to obtain the basic shadow data for each point, output by the first convolution filter. Furthermore, the penumbra intensity of each point can be determined based on its distance from the virtual light source in the 3D scene and the propagation distance of the virtual light emitted by the virtual light source. This penumbra intensity is then used to weight the basic shadow data of each point, adjusting the basic shadow data based on the influence of the propagation of virtual light at that point. This results in more accurate weighted shadow data that better reflects the actual conditions in the 3D scene.
[0272] Based on the shadow generation method provided in the preceding embodiments, this application also provides a shadow generation apparatus. The following, in conjunction with... Figure 8 To explain, Figure 8 This is a schematic diagram of the structure of the shadow generation apparatus 800 provided in an embodiment of this application. The apparatus includes:
[0273] The acquisition module 801 is used to acquire the depth data, normal data and lighting data of multiple points in the virtual scene, as shadow reference data of the multiple points respectively;
[0274] The convolutional filtering module 802 is used to input the shadow reference data of each of the plurality of points into the first convolutional filter to obtain the basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined according to the shadow reference data.
[0275] The penumbra determination module 803 is used to determine the penumbra intensity of each of the plurality of points based on the distance from each of the plurality of points to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source. The penumbra intensity of the point is used to adjust the basic shadow data of the point based on the actual propagation path of the virtual light between the virtual light source and the point.
[0276] The shadow generation module 804 is used to weight the basic shadow data of the multiple points by using the penumbra intensity of each of the multiple points to obtain the weighted shadow data of the multiple points. The weighted shadow data is used for shadow rendering of the points.
[0277] Optionally, the first convolutional filter includes a plurality of sub-convolutional filters, each of which has a convolutional kernel of a different size; the convolutional filtering module 802 includes:
[0278] The first convolutional filtering unit is used to input the shadow reference data of each of the plurality of points into each of the sub-convolutional filters to obtain the sub-basic shadow data of each of the plurality of points output by each of the sub-convolutional filters through the application of filter parameters; the filter parameters are obtained by adjusting the original filter parameters of the sub-convolutional filters using the first coefficient;
[0279] The first weighted summation unit is used to perform weighted summation on the sub-basic shadow data of the point output by the plurality of sub-convolutional filters for each point, so as to obtain the basic shadow data of the point.
[0280] Optionally, the device further includes the following unit for determining the first coefficient:
[0281] The first coefficient determination unit is used to input the shadow reference data of each of the plurality of points into the first coefficient classification network to obtain the first coefficients corresponding to each of the plurality of points output by the first coefficient classification network; the first coefficients corresponding to the points are used to adjust the original filter parameters in the first convolutional filter used to determine the basic shadow data of the points; the first coefficient classification network is trained based on the training shadow reference data and the corresponding labeled first coefficients.
[0282] Optionally, the penumbra determination module 803 includes:
[0283] The first penumbra intensity determination unit is configured to, for each point, determine a first distance from the point to the virtual light source, determine the actual propagation distance of the virtual light ray associated with the point as a second distance, determine the penumbra intensity of the point based on the ratio of the first distance to the second distance, and the original propagation direction of the virtual light ray associated with the point passes through the point.
[0284] Optionally, the device further includes:
[0285] The second convolutional filtering unit is used to input the penumbra intensity of each of the plurality of points into the second convolutional filter to obtain the optimized penumbra intensity of each of the plurality of points output by the second convolutional filter by applying the adjusted filter parameters; the adjusted filter parameters are obtained by adjusting the original filter parameters of the second convolutional filter using a second coefficient; the second coefficient is determined according to the penumbra intensity.
[0286] Correspondingly, the shadow generation module 804 includes:
[0287] The first weighting unit is used to weight the basic shadow data of the multiple points by utilizing the optimized penumbra intensity of each point, so as to obtain the weighted shadow data of the multiple points.
[0288] Optionally, when the virtual scene includes multiple virtual light sources, the convolutional filtering module 802 includes:
[0289] The third convolutional filtering unit is used to input the shadow reference data of each of the plurality of points relative to the virtual light source into the first convolutional filter for each of the virtual light sources, and obtain the basic shadow data of each of the plurality of points relative to the virtual light source output by the first convolutional filter by applying the filter parameters; the lighting data in the shadow reference data of the points relative to the virtual light source is used to characterize the lighting of the virtual light source at the point.
[0290] The second weighted summation unit is used to perform a weighted summation of the basic shadow data of each point relative to the plurality of virtual light sources to obtain the comprehensive basic shadow data of the point.
[0291] Optionally, the penumbra determination module 803 includes:
[0292] The second penumbra intensity determination unit is used to determine the penumbra intensity of each of the plurality of points relative to the virtual light source for each of the virtual light sources, based on the distance of each of the plurality of points from the virtual light source and the propagation distance of the virtual light emitted by the virtual light source.
[0293] The third weighted summation unit is used to perform a weighted summation of the penumbra intensity of each point relative to the plurality of virtual light sources to obtain the comprehensive penumbra intensity of the point.
[0294] Correspondingly, the shadow generation module 804 includes:
[0295] The second weighting unit is used to weight the comprehensive basic shadow data of the multiple points by utilizing the comprehensive penumbra intensity of each of the multiple points, so as to obtain the weighted shadow data of each of the multiple points.
[0296] Optionally, the convolutional filtering module 802 includes:
[0297] The Fourier transform unit is used to perform a fast Fourier transform on the shadow reference data of each of the plurality of points to obtain the frequency domain shadow reference data of each of the plurality of points.
[0298] The fourth convolutional filtering unit is used to input the frequency domain shadow reference data of each of the plurality of points into the first convolutional filter to obtain the frequency domain basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters; the filter parameters are frequency domain parameters.
[0299] The frequency domain transformation unit is used to transform the frequency domain basic shadow data of the plurality of points to the spatial domain to obtain the basic shadow data of the plurality of points.
[0300] Optionally, the acquisition module 801 includes:
[0301] The sampling unit is used to determine the representative point sampling rate corresponding to each region in the virtual scene based on the scene complexity of the region; to sample representative points in the region according to the representative point sampling rate; and to use the depth data, normal data, and lighting data of the representative points as shadow reference data for each point in the region.
[0302] Optionally, the virtual scene is a three-dimensional scene, and the device further includes the following unit for determining the deployment position of virtual light sources in the three-dimensional scene:
[0303] The measurement parameter determination unit is used to determine the measurement parameters corresponding to each candidate light source position in the three-dimensional scene based on the direction of the virtual light source, the normal vector of the surface of each three-dimensional model in the three-dimensional scene, and the vector from each three-dimensional model to the candidate light source position.
[0304] The deployment location determination unit is used to determine the location of the candidate light source whose corresponding measurement parameters meet the preset measurement conditions, and use it as the deployment location of the virtual light source.
[0305] Optionally, the virtual scene is a three-dimensional scene, and the device further includes the following unit for determining the initial illumination intensity of the virtual light source in the three-dimensional scene:
[0306] The first adaptive illumination intensity determination unit is used to determine the adaptive illumination intensity of the virtual light source relative to the three-dimensional model for each three-dimensional model in the three-dimensional scene, based on the preset illumination intensity, wavelength reflectivity, average wavelength reflectivity of the scene, and the angle between the virtual light ray of the virtual light source and the normal of the surface of the three-dimensional model.
[0307] The fourth weighted summation unit is used to perform a weighted summation of the adaptive illumination intensity of the virtual light source relative to each of the three-dimensional models in the three-dimensional scene to obtain the initial illumination intensity of the virtual light source.
[0308] Optionally, the first adaptive light intensity determination unit includes:
[0309] The tangential angle determination unit is used to determine the tangent ray of the virtual light source to the three-dimensional model, and the tangent point position of the tangent ray on the surface of the three-dimensional model; and to determine the angle between the tangent ray and the normal at the tangent point position as the tangential angle.
[0310] The reference angle determination unit is used to determine the angle between the virtual ray emitted by the virtual light source that reaches the sub-region and the normal of the sub-region for each sub-region on the three-dimensional model, and use it as the reference angle corresponding to the sub-region.
[0311] The averaging unit is used to average the reference angles corresponding to each sub-region on the three-dimensional model to obtain the average reference angle.
[0312] The second adaptive illumination intensity determination unit is used to determine the adaptive illumination intensity of the virtual light source relative to the three-dimensional model based on the preset illumination intensity, the ratio between the wavelength reflectivity and the average wavelength reflectivity of the scene, and the ratio between the cosine value of the tangential angle and the cosine value of the average reference angle.
[0313] Optionally, the virtual scene is a three-dimensional scene, and the device further includes:
[0314] The sub-region to be simplified unit is used to determine the sub-region to be simplified based on the complexity of each sub-region on the mesh model corresponding to each 3D model in the 3D scene; and to perform at least one simplification process, namely vertex merging and edge folding, on the sub-region to be simplified.
[0315] The vertex merging is used to merge multiple vertices into one vertex by referring to their respective positions and normal vectors in the sub-region to be simplified; the edge folding is used to merge two vertices of the edge to be folded into one vertex based on their respective positions and weights in the sub-region to be simplified, wherein the weight of the vertex is determined according to the normal vector of the vertex and the normal vector of the surrounding mesh of the edge to be folded.
[0316] Optionally, the device further includes a unit for selecting the edge to be folded:
[0317] The weight determination unit is used to determine the weight of each edge in the sub-region to be simplified based on the normal vector of the surrounding mesh of the edge and the angle between the edge and the direction of the virtual light source in the three-dimensional scene.
[0318] The edge to be folded determination unit is used to determine the edge whose corresponding weight satisfies the preset important condition, and use it as the edge to be folded.
[0319] Optionally, the device further includes:
[0320] The normal vector determination unit is used to determine the normal vector of the merged vertex obtained through the simplification process, based on the area and normal vector of each mesh participating in the simplification process.
[0321] Optionally, the device further includes:
[0322] The magnification processing unit is used to determine, for each 3D model in the 3D scene, the mesh whose curvature satisfies the preset curvature condition in the mesh model, and take it as the mesh to be optimized; and to magnify the normal vector of the mesh to be optimized based on the curvature corresponding to the mesh to be optimized.
[0323] This application also provides a computer device, which may specifically be a terminal device or a server. The terminal device and server provided in this application will be described below from the perspective of hardware implementation.
[0324] See Figure 9 , Figure 9 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. For example... Figure 9 As shown, for ease of explanation, only the parts related to the embodiments of this application are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of this application. The terminal can be any terminal device including mobile phones, tablets, personal digital assistants (PDAs), point-of-sale (POS) terminals, in-vehicle computers, etc. Taking a computer as an example:
[0325] Figure 9 This is a block diagram illustrating a portion of the structure of a computer associated with the terminal provided in an embodiment of this application. (Reference) Figure 9 The computer includes: a radio frequency (RF) circuit 1210, a memory 1220, an input unit 1230 (including a touch panel 1231 and other input devices 1232), a display unit 1240 (including a display panel 1241), a sensor 1250, an audio circuit 1260 (connected to a speaker 1261 and a microphone 1262), a wireless fidelity (WiFi) module 1270, a processor 1280, and a power supply 1290, etc. Those skilled in the art will understand that... Figure 9 The computer architecture shown does not constitute a limitation on the computer and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0326] The memory 1220 can be used to store software programs and modules. The processor 1280 executes various computer functions and data processing by running the software programs and modules stored in the memory 1220. The memory 1220 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer (such as audio data, telephone directory, etc.). In addition, the memory 1220 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0327] The processor 1280 is the control center of the computer, connecting various parts of the computer through various interfaces and lines. It performs various computer functions and processes data by running or executing software programs and / or modules stored in the memory 1220, and by calling data stored in the memory 1220. Optionally, the processor 1280 may include one or more processing units; preferably, the processor 1280 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 1280.
[0328] In this embodiment of the application, the processor 1280 included in the terminal is used to execute the steps in the shadow generation method described in the foregoing embodiments.
[0329] See Figure 10 , Figure 10 This is a schematic diagram of the structure of a server 1300 provided in an embodiment of this application. The server 1300 can vary significantly due to different configurations or performance, and may include one or more central processing units (CPUs) 1322 (e.g., one or more processors) and memory 1332, and one or more storage media 1330 (e.g., one or more mass storage devices) for storing application programs 1342 or data 1344. The memory 1332 and storage media 1330 can be temporary or persistent storage. The program stored in the storage media 1330 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the server. Furthermore, the CPU 1322 may be configured to communicate with the storage media 1330 and execute the series of instruction operations stored in the storage media 1330 on the server 1300.
[0330] Server 1300 may also include one or more power supplies 1326, one or more wired or wireless network interfaces 1350, one or more input / output interfaces 1358, and / or one or more operating systems, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSD TM etc.
[0331] The steps performed by the server in the above embodiments can be based on this Figure 10 The server structure shown is such that CPU 1322 is used to execute the steps in the shadow generation method described in the foregoing embodiments.
[0332] This application also provides a computer-readable storage medium for storing a computer program that performs the steps in the shadow generation method described in the foregoing embodiments.
[0333] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps in the shadow generation methods described in the foregoing embodiments.
[0334] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0335] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0336] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0337] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0338] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing computer programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0339] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0340] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0341] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for generating shadows, characterized in that, The method includes: Acquire the depth data, normal data, and lighting data of multiple points in the virtual scene, and use them as shadow reference data for each of the multiple points. The shadow reference data of each of the plurality of points is input into the first convolutional filter to obtain the basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data. Based on the distance from each of the multiple points to the virtual light source in the virtual scene, and the propagation distance of the virtual light emitted by the virtual light source, the penumbra intensity of each of the multiple points is determined. The penumbra intensity of the point is used to adjust the basic shadow data of the point based on the actual propagation path of the virtual light between the virtual light source and the point. By using the penumbra intensity of each of the multiple points, the basic shadow data of each of the multiple points is weighted to obtain the weighted shadow data of each of the multiple points. The weighted shadow data is used for shadow rendering of the points.
2. The method according to claim 1, characterized in that, The first convolutional filter includes multiple sub-convolutional filters, each with a convolutional kernel of a different size; the step of inputting the shadow reference data of each of the multiple points into the first convolutional filter to obtain the basic shadow data of each of the multiple points output by the first convolutional filter through the application of filter parameters includes: The shadow reference data of each of the plurality of points is input into each of the sub-convolutional filters to obtain the sub-basic shadow data of each of the plurality of points output by each of the sub-convolutional filters through the application of filter parameters; the filter parameters are obtained by adjusting the original filter parameters of the sub-convolutional filters using the first coefficient; For each point, the sub-basic shadow data of the point output by each of the plurality of sub-convolutional filters are weighted and summed to obtain the basic shadow data of the point.
3. The method according to claim 1 or 2, characterized in that, The first coefficient is determined in the following way: The shadow reference data of each of the plurality of points is input into the first coefficient classification network to obtain the first coefficients corresponding to each of the plurality of points output by the first coefficient classification network; the first coefficients corresponding to the points are used to adjust the original filter parameters in the first convolution filter used to determine the basic shadow data of the points; The first coefficient classification network is trained based on the training shadow reference data and the corresponding labeled first coefficients.
4. The method according to any one of claims 1 to 3, characterized in that, The step of determining the penumbra intensity of each of the plurality of points based on their respective distances to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source includes: For each point, a first distance from the point to the virtual light source is determined, and the actual propagation distance of the virtual ray associated with the point is determined as a second distance; the penumbra intensity of the point is determined based on the ratio of the first distance to the second distance; the original propagation direction of the virtual ray associated with the point passes through the point.
5. The method according to claim 1 or 4, characterized in that, The method further includes: The penumbra intensity of each of the plurality of points is input into the second convolutional filter to obtain the optimized penumbra intensity of each of the plurality of points output by the second convolutional filter by applying the adjusted filter parameters; the adjusted filter parameters are obtained by adjusting the original filter parameters of the second convolutional filter using a second coefficient; the second coefficient is determined based on the penumbra intensity; The step of weighting the basic shadow data of the multiple points by utilizing the penumbra intensity of each point to obtain the weighted shadow data of the multiple points includes: By utilizing the optimized penumbra intensity of each of the multiple points, the basic shadow data of each of the multiple points are weighted to obtain the weighted shadow data of each of the multiple points.
6. The method according to any one of claims 1 to 5, characterized in that, When the virtual scene includes multiple virtual light sources, the step of inputting the shadow reference data of each of the multiple points into a first convolutional filter to obtain the basic shadow data of each of the multiple points output by the first convolutional filter through the application of filter parameters includes: For each virtual light source, the shadow reference data of each of the plurality of points relative to the virtual light source is input into the first convolutional filter to obtain the basic shadow data of each of the plurality of points relative to the virtual light source, which is output by the first convolutional filter by applying the filter parameters; the lighting data in the shadow reference data of the point relative to the virtual light source is used to characterize the lighting of the virtual light source at the point. For each point, the basic shadow data of the point relative to the plurality of virtual light sources is weighted and summed to obtain the comprehensive basic shadow data of the point.
7. The method according to claim 6, characterized in that, The step of determining the penumbra intensity of each of the plurality of points based on their respective distances to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source includes: For each virtual light source, the penumbra intensity of each of the plurality of points relative to the virtual light source is determined based on the distance from each of the plurality of points to the virtual light source and the propagation distance of the virtual light emitted by the virtual light source. For each point, the penumbra intensity of the point relative to the plurality of virtual light sources is weighted and summed to obtain the comprehensive penumbra intensity of the point; The step of weighting the basic shadow data of the multiple points by utilizing the penumbra intensity of each point to obtain the weighted shadow data of the multiple points includes: By using the combined penumbra intensity of each of the multiple points, the combined basic shadow data of each of the multiple points are weighted to obtain the weighted shadow data of each of the multiple points.
8. The method according to any one of claims 1 to 7, characterized in that, The step of inputting the shadow reference data of each of the plurality of points into a first convolutional filter to obtain the basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters includes: Perform a Fast Fourier Transform on the shadow reference data of each of the plurality of points to obtain the frequency domain shadow reference data of each of the plurality of points; The frequency domain shadow reference data of each of the plurality of points is input into the first convolutional filter to obtain the frequency domain basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters; the filter parameters are frequency domain parameters. The frequency domain basic shadow data of each of the multiple points is transformed to the spatial domain to obtain the basic shadow data of each of the multiple points.
9. The method according to any one of claims 1 to 8, characterized in that, The process of acquiring depth data, normal data, and lighting data for multiple points in the virtual scene as shadow reference data for each of the multiple points includes: For each region in the virtual scene, the sampling rate of the representative points corresponding to the region is determined according to the scene complexity of the region; representative points are sampled in the region according to the sampling rate of the representative points; the depth data, normal data and lighting data of the representative points are used as the shadow reference data of each point in the region.
10. The method according to any one of claims 1 to 9, characterized in that, The virtual scene is a three-dimensional scene, and the deployment positions of the virtual light sources in the three-dimensional scene are determined in the following way: For each candidate light source position in the three-dimensional scene, the measurement parameters corresponding to the candidate light source position are determined based on the direction of the virtual light source, the normal vector of the surface of each three-dimensional model in the three-dimensional scene, and the vector from each three-dimensional model to the candidate light source position. The candidate light source positions that satisfy the preset measurement conditions are determined as the deployment positions of the virtual light source.
11. The method according to any one of claims 1 to 10, characterized in that, The virtual scene is a three-dimensional scene, and the initial illumination intensity of the virtual light source in the three-dimensional scene is determined in the following way: For each 3D model in the 3D scene, the adaptive illumination intensity of the virtual light source relative to the 3D model is determined based on the preset illumination intensity, wavelength reflectivity, average wavelength reflectivity of the scene, and the angle between the virtual ray of the virtual light source and the normal of the surface of the 3D model. The initial illumination intensity of the virtual light source is obtained by weighted summing of the adaptive illumination intensities of the virtual light source relative to the various 3D models in the 3D scene.
12. The method according to claim 11, characterized in that, The step of determining the adaptive illumination intensity of the virtual light source relative to the 3D model based on the preset illumination intensity, wavelength reflectivity, average wavelength reflectivity of the scene, and the angle between the virtual ray of the virtual light source and the normal to the surface of the 3D model includes: Determine the tangent ray of the virtual light source to the three-dimensional model, and the position of the tangent point of the tangent ray on the surface of the three-dimensional model; determine the angle between the tangent ray and the normal at the tangent point, as the tangential angle; For each sub-region on the 3D model, the angle between the virtual ray emitted by the virtual light source that reaches the sub-region and the normal of the sub-region is determined, and used as the reference angle for the sub-region. The average reference angle is obtained by averaging the reference angles corresponding to each sub-region on the three-dimensional model. Based on the preset illumination intensity, the ratio between the wavelength reflectivity and the average wavelength reflectivity of the scene, and the ratio between the cosine of the tangential angle and the cosine of the average reference angle, the adaptive illumination intensity of the virtual light source relative to the three-dimensional model is determined.
13. The method according to any one of claims 1 to 12, characterized in that, The virtual scene is a three-dimensional scene. Before acquiring the depth data, normal data, and lighting data of multiple points in the virtual scene as shadow reference data for each of the multiple points, the method further includes: For each 3D model in the 3D scene, a sub-region to be simplified is determined based on the complexity of each sub-region on the mesh model; at least one simplification process, namely vertex merging and edge folding, is performed on the sub-region to be simplified. The vertex merging is used to merge multiple vertices into one vertex by referring to their respective positions and normal vectors in the sub-region to be simplified; the edge folding is used to merge two vertices of the edge to be folded into one vertex based on their respective positions and weights in the sub-region to be simplified, wherein the weight of the vertex is determined according to the normal vector of the vertex and the normal vector of the surrounding mesh of the edge to be folded.
14. The method according to claim 13, characterized in that, The edge to be folded is selected in the following way: For each edge in the sub-region to be simplified, the weight corresponding to the edge is determined based on the normal vector of the surrounding mesh of the edge and the angle between the edge and the direction of the virtual light source in the 3D scene; The edges whose corresponding weights satisfy the preset importance conditions are identified as the edges to be folded.
15. The method according to claim 13 or 14, characterized in that, The method further includes: For the merged vertex obtained through the simplification process, the normal vector of the merged vertex is determined based on the area and normal vector of each mesh that participated in the simplification process.
16. The method according to any one of claims 13 to 15, characterized in that, The method further includes: For each 3D model in the 3D scene, the meshes whose curvature satisfies the preset curvature conditions are identified as the meshes to be optimized; based on the curvature of the meshes to be optimized, the normal vectors of the meshes to be optimized are amplified.
17. A shadow generation device, characterized in that, The device includes: The acquisition module is used to acquire the depth data, normal data, and lighting data of multiple points in the virtual scene, which serve as the shadow reference data for each of the multiple points. A convolutional filtering module is used to input the shadow reference data of each of the plurality of points into a first convolutional filter to obtain the basic shadow data of each of the plurality of points output by the first convolutional filter through the application of filter parameters. The filter parameters are obtained by adjusting the original filter parameters of the first convolutional filter using a first coefficient, which is determined based on the shadow reference data. The penumbra determination module is used to determine the penumbra intensity of each of the multiple points based on the distance from each point to the virtual light source in the virtual scene and the propagation distance of the virtual light emitted by the virtual light source. The penumbra intensity of the point is used to adjust the basic shadow data of the point based on the actual propagation path of the virtual light between the virtual light source and the point. The shadow generation module is used to weight the basic shadow data of the multiple points by utilizing the penumbra intensity of each point to obtain weighted shadow data of the multiple points. The weighted shadow data is used for shadow rendering of the points.
18. A computer device, characterized in that, The device includes a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the shadow generation method according to any one of claims 1 to 16 according to the computer program.
19. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program that, when executed by an electronic device, implements the shadow generation method according to any one of claims 1 to 16.
20. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the shadow generation method according to any one of claims 1 to 16.