Model rendering method and device, electronic equipment and computer readable storage medium
By acquiring fragments of a 3D model, determining diffuse reflection intensity based on normals and light source direction, and selecting lighting response levels for rendering, the problem of low efficiency and insufficient flexibility of existing stylization methods is solved, achieving efficient and flexible stylization processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-09
- Publication Date
- 2026-03-27
AI Technical Summary
Existing stylization methods are inefficient and lack flexibility. Manual stylization is inefficient, and procedural tools can only generate existing styles and cannot generate new styles.
By acquiring fragments of a 3D model, determining diffuse reflection intensity based on normals and light source direction, selecting a target illumination response level from discrete illumination response levels, multiplying it by the fragment color value, and performing rendering processing to generate a stylized 2D image.
It improves the efficiency and flexibility of stylization, enabling the generation of different styles according to the needs of different projects, reducing manpower and time costs, and is highly adaptable.
Smart Images

Figure CN121746589A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a model rendering method and device, electronic equipment and computer readable storage medium. BACKGROUND
[0002] Style transfer is an important direction connecting natural modeling and artistic expression in computer graphics, aiming to make realistic models have artistic performance of specific visual style (such as cartoon, sketch, ink or oil painting, etc.). Traditional style transfer methods mainly include two kinds, one is manual style transfer by staff, and the other is automatic style transfer by programmatic tool.
[0003] However, the manual style transfer method is inefficient, and the automatic style transfer method by programmatic tool can only generate the style that already exists in the programmatic tool, and cannot generate new style, which is low in flexibility. SUMMARY
[0004] The present application provides a model rendering method and device, electronic equipment and computer readable storage medium, which can improve the efficiency and flexibility of model style transfer.
[0005] In a first aspect, an embodiment of the present application provides a model rendering method, comprising: obtaining a target three-dimensional model to be stylized, and determining a fragment corresponding to the target three-dimensional model; determining a diffuse reflection intensity corresponding to the fragment based on a normal of the fragment and a direction of a light source of the target three-dimensional model; determining a target light response level corresponding to the diffuse reflection intensity from at least two discrete light response levels; multiplying the target light response level and a color value of the fragment to obtain a basic light value of the fragment; rendering the target three-dimensional model based on a color value of the light source, the color value of the fragment and the basic light value to obtain a stylized two-dimensional image of the target three-dimensional model.
[0006] In a second aspect, an embodiment of the present application provides a model rendering device, comprising: an obtaining module configured to obtain a target three-dimensional model to be stylized, and determine a fragment corresponding to the target three-dimensional model; a first determining module configured to determine a diffuse reflection intensity corresponding to the fragment based on a normal of the fragment and a direction of a light source of the target three-dimensional model; a second determining module configured to determine a target light response level corresponding to the diffuse reflection intensity from at least two discrete light response levels; A multiplication module is configured to multiply the target light response level and the color value of the pixel to obtain a basic light value of the pixel. A rendering module is configured to perform rendering processing on the target three-dimensional model based on the color value of the light source, the color value of the pixel and the basic light value to obtain a stylized two-dimensional image of the target three-dimensional model.
[0007] In a third aspect, an embodiment of the present application further provides an electronic device, which comprises a memory storing a plurality of instructions, and a processor configured to load the instructions from the memory to execute any of the model rendering methods provided by the embodiments of the present application.
[0008] In a fourth aspect, an embodiment of the present application further provides a computer readable storage medium, which stores a plurality of instructions, and the instructions are adapted to be loaded by a processor to execute any of the model rendering methods provided by the embodiments of the present application.
[0009] In the embodiments of the present application, a target three-dimensional model to be stylized is obtained, and a pixel corresponding to the target three-dimensional model is determined. The diffuse reflection intensity corresponding to the pixel is determined based on the normal of the pixel and the direction of the light source of the target three-dimensional model. A target light response level corresponding to the diffuse reflection intensity is determined from at least two discrete light response levels. The target light response level and the color value of the pixel are multiplied to obtain a basic light value of the pixel. The target three-dimensional model is rendered based on the color value of the light source, the color value of the pixel and the basic light value to obtain a stylized two-dimensional image of the target three-dimensional model. The stylized processing is automatically performed, the efficiency of the stylized processing is improved, and the flexibility of the stylized processing is improved because the discrete light response levels can be set according to the actual needs of different projects to generate different styles. BRIEF DESCRIPTION OF DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0011] Figure 1 is a schematic diagram of an application scenario of the model rendering method provided by an exemplary embodiment of the present disclosure; Figure 2 is a flowchart of the model rendering method provided by an exemplary embodiment of the present disclosure; Figure 3 is a schematic diagram of an initial three-dimensional model provided by an exemplary embodiment of the present disclosure; Figure 4is a schematic diagram of a candidate three-dimensional model provided by an example embodiment of the present disclosure; Figure 5 is a schematic diagram of a target three-dimensional model provided by an example embodiment of the present disclosure; Figure 6 is a schematic diagram of a first two-dimensional image provided by an example embodiment of the present disclosure; Figure 7 is another schematic diagram of a model rendering method provided by an example embodiment of the present disclosure; Figure 8 is a schematic diagram of a second two-dimensional image, a third two-dimensional image and a fourth two-dimensional image provided by an example embodiment of the present disclosure; Figure 9 is a schematic diagram of a fifth two-dimensional image and a stylized two-dimensional image provided by an example embodiment of the present disclosure; Figure 10 is a schematic diagram of a model rendering device provided by an example embodiment of the present disclosure; Figure 11 is a schematic diagram of an electronic device provided by an example embodiment of the present disclosure. DETAILED DESCRIPTION
[0012] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0013] In the description of the present application, it should be understood that the terms "first", "second" are used only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise specifically limited. "A and / or B" includes the following three combinations: only A, only B, and the combination of A and B.
[0014] In this application, the word "exemplary" is used to mean "serving as an example, instance, or illustration." Any implementation described as exemplary in this application is not necessarily to be construed as preferred or advantageous over other implementations. The following description is presented to enable any person skilled in the art to make and use the application. Details are set forth in the following description for purpose of explanation. It should be appreciated that one of ordinary skill in the art would realize and cut on that the application can be practiced without the use of these specific details. In other instances, well-known structures and processes are not elaborated as not to obscure the description of the application with unnecessary details. Thus, the present application is not intended to be limited by the embodiments shown, but is to be accorded with the widest scope consistent with the principles and features disclosed.
[0015] Embodiments of the present application provide a model rendering method and device, electronic equipment and computer readable storage medium. Specifically, embodiments of the present application will be described from the perspective of a model rendering device, which can be integrated in electronic equipment, i.e. the model rendering method of the embodiments of the present application can be executed by electronic equipment. Optionally, the electronic equipment can include a terminal device or a server. The terminal device can be a mobile phone, a tablet computer, a smart Bluetooth device, a notebook computer, a game console, or a personal computer (PC) and the like.
[0016] The model rendering method provided by the embodiments of the present application can be applied to a model rendering system. The model rendering system can include a terminal device and a server. The terminal device can be a device including receiving and transmitting hardware, i.e. a device having receiving and transmitting hardware capable of performing bidirectional communication on a bidirectional communication link. The terminal device and the server can perform bidirectional communication through a network.
[0017] Optionally, the server can be a stand-alone server, or a server network or server cluster composed of servers, including but not limited to a computer, a network host, a single network server, a plurality of network server sets, or a cloud server composed of a plurality of servers. The cloud server is composed of a large number of computers or network servers based on cloud computing.
[0018] For example, as shown in FIG. 1, the model rendering system can include a terminal device 100 and a server 200. The terminal device 100 can be a device including receiving and transmitting hardware, i.e. a device having receiving and transmitting hardware capable of performing bidirectional communication on a bidirectional communication link. The terminal device 100 and the server 200 can perform bidirectional communication through a network. Figure 1As shown, the terminal device 10 sends the stylization instruction of the target three-dimensional model to the server 20, the server 20 determines the corresponding patch of the target three-dimensional model, determines the diffuse reflection intensity corresponding to the patch based on the normal of the patch and the direction of the light source of the target three-dimensional model, determines the target light response level corresponding to the diffuse reflection intensity from at least two discrete light response levels, multiplies the target light response level and the color value of the patch to obtain the basic light value of the patch, and sends the color value of the light source, the color value of the patch and the basic light value to the terminal device 10. The terminal device 10 performs rendering processing on the target three-dimensional model based on the color value of the light source, the color value of the patch and the basic light value, obtains the stylized two-dimensional image of the target three-dimensional model, and displays the stylized two-dimensional image.
[0019] The following will be described in detail with reference to the accompanying drawings. In the embodiment, the execution subject is taken as an example of the server. It should be noted that the sequence of the following embodiments is not limited as the preferred sequence of the embodiments. Although the logical sequence is shown in the flowchart, in some cases, the steps shown or described can be performed in a sequence different from that shown in the accompanying drawings.
[0020] Please refer to Figure 2 The specific process of the model rendering method can be as follows: Step 201, obtaining a target three-dimensional model to be stylized, and determining the corresponding patch of the target three-dimensional model.
[0021] The stylization means that the target three-dimensional model has a specific visual style (such as cartoon, sketch, ink or oil painting, etc.) artistic expression. The target three-dimensional model can be a realistic model, which means a digital three-dimensional model that simulates a certain object in the real world as realistically as possible. The type can be set according to the actual situation, such as a leaf model or a building model, which is not limited in the embodiment.
[0022] The patch corresponding to the target three-dimensional model refers to the product obtained in the process of rasterizing the target three-dimensional model, which is a potential screen pixel. Optionally, the coordinates of the vertices of the target three-dimensional model in the model space can be converted into target coordinates in the projection space, the patch covered by the target three-dimensional model on the screen is determined based on the target coordinates, and the normal and color value of the patch are obtained by interpolation based on the normal and color value of each vertex.
[0023] Optionally, the target 3D model can be the original realistic model, or it can be a realistic model obtained after preprocessing the original realistic model. Since some original realistic models may consist of multiple discontinuous, non-manifold, or even overlapping surfaces, resulting in messy or inconsistent normals on the original realistic model, preprocessing is necessary to obtain a stylized 2D image with better stylistic effects. For example, the original realistic model could be an original tree model. Because the normals of each leaf in the tree model are independent, the normals on the tree model are not smooth and consistent enough; therefore, preprocessing is required for the original tree model.
[0024] Optionally, when preprocessing the original realistic model, the target 3D model to be stylized is obtained, including: obtaining the initial 3D model to be stylized, converting the initial 3D model into a voxel mesh, and converting the voxel mesh into the target 3D model.
[0025] The initial 3D model can refer to the original realistic model, i.e., the existing realistic model. The voxel mesh is composed of cubic units, which can be called voxels. Specifically, the bounding box of the initial 3D model can be determined, and the bounding box can be divided to obtain a voxel mesh. The voxel mesh includes multiple voxels, and the target 3D model is generated based on the voxels in the voxel mesh. The method of converting the voxel mesh into the target 3D model can be selected according to the actual situation. For example, Marching Cubes or VDB to Polygons can be used to convert the voxel mesh into the target 3D model; this embodiment does not limit this.
[0026] In this embodiment, an initial 3D model to be stylized is obtained, the initial 3D model is converted into a voxel mesh, and the voxel mesh is converted into a target 3D model. Since converting the initial 3D model into a voxel mesh is equivalent to "blurring" or "sampling" the geometric information into a regular volume grid, a continuous, closed, manifold target 3D model can be regenerated based on each voxel, making the normals of the target 3D model smoother and more consistent. As a result, the target 3D model not only retains the approximate shape of the initial 3D model, but also has more rounded edges and a stronger sense of volume, thus making the stylization effect of the stylized 2D image better.
[0027] In some embodiments, converting a voxel mesh into a target 3D model includes: Convert the voxel mesh into a candidate 3D model; For each target vertex in the candidate 3D model, determine the initial vertex on the initial 3D model that matches the target vertex; The normal of the initial vertex is used as the normal of the target vertex to obtain the target 3D model.
[0028] The initial vertex that matches the target vertex can be understood as the vertex in the initial 3D model that is closest to the target vertex. The algorithm for determining the initial vertex that matches the target vertex can be set according to the actual situation. For example, in Houdini, it can be implemented through Attribute Transfer or Point Wrangle + NearPoints. This embodiment does not limit it.
[0029] For example, the initial 3D model can be like this Figure 3 As shown, candidate 3D models can be as follows: Figure 4 As shown, the target 3D model can be as follows: Figure 5 As shown, where, Figure 3 The color values in the model are numerical representations of the normals of the initial 3D model. Figure 4 The color value in the image is a numerical representation of the normal to the candidate 3D model. Figure 5 The color values in the code are numerical representations of the normals of the target 3D model. Understandably, this is done to facilitate comparison of the shapes of the initial 3D model and the candidate 3D model. Figure 3 The initial 3D model is wrapped with a mesh.
[0030] Since the target 3D model itself lacks the details (such as orientation and surface undulation) and specific shape of the original realistic model, in this embodiment, the voxel mesh is converted into a candidate 3D model; for each target vertex in the candidate 3D model, an initial vertex matching the target vertex is determined on the initial 3D model; the normal of the initial vertex is used as the normal of the target vertex to obtain the target 3D model, thereby transferring the normal of the initial 3D model to the target 3D model, so that the target 3D model retains the details of the initial 3D model, thus making the final stylization effect more natural and realistic.
[0031] In some embodiments, a voxel mesh can be directly converted into a candidate 3D model, or the conversion of a voxel mesh into a candidate 3D model includes: The voxel mesh is initially stylized to obtain the target voxel mesh; The target voxel mesh is converted into a candidate 3D model.
[0032] The initial stylization process can be set according to the actual situation. For example, the initial stylization process can be at least one of smoothing, dilation, erosion, opening and closing operations (removing small bumps or filling small holes to control details) and voxel noise perturbation (adding Perlin / Worley noise to the voxel mesh to generate organic irregular edges). This embodiment does not limit it.
[0033] Alternatively, the initial 3D model can be converted into a voxel mesh using the Houdini tool, the voxel mesh can be preliminarily stylized to obtain the target voxel mesh, the target voxel mesh can be converted into a candidate 3D model, and the normals of the initial vertices can be used as the normals of the target vertices to obtain the target 3D model.
[0034] In this embodiment, the voxel mesh is initially stylized to obtain the target voxel mesh; the target voxel mesh is then converted into a candidate 3D model, so that the obtained target 3D model has the effect of initial stylization, thereby making the final stylized result more in line with the user's needs.
[0035] Step 202: Determine the diffuse reflection intensity corresponding to the fragment based on the normal of the fragment and the direction of the light source of the target 3D model.
[0036] Here, the light source of the target 3D model refers to the light source illuminating the target 3D model. The normal of a fragment can be represented by a normal vector. Specifically, the normal vector of the fragment and the direction of the light source of the target 3D model can be substituted into formula (1) for calculation to obtain the diffuse reflection intensity corresponding to the fragment: (1) in, d Indicates diffuse reflection intensity. N Represents the normal vector. L Indicates the direction of the light source. This indicates dot product.
[0037] Step 203: Determine the target illumination response level corresponding to the diffuse reflection intensity from at least two discrete illumination response levels.
[0038] The illumination response level is used to indicate the level of the 3D model's response to light source illumination. Specifically, at least two discrete illumination response levels and diffuse reflection intensities can be pre-defined. After obtaining the diffuse reflection intensities of fragments, the target illumination response level corresponding to the diffuse reflection intensities of the fragments is determined based on the correspondence. The number of discrete illumination response levels can be set according to actual conditions. For example, there can be four discrete illumination response levels, namely 0, 0.33, 0.63, and 1. This embodiment does not limit this.
[0039] When a 3D model is illuminated by a light source, the brightness and darkness of its surface change. This change is usually smooth and continuous, meaning the 3D model's response to lighting is smooth and continuous. In this embodiment, the smooth and continuous response of the 3D model to lighting is divided into multiple discrete lighting response levels. Fragments belonging to the same lighting response level respond identically to lighting. There are clear boundaries between different lighting response levels, without intermediate gradations. This results in the pixels corresponding to the fragments displaying their original colors on the screen—bright areas retain their original colors, while dark areas become darker. Consequently, the originally smooth light and shadow are quantized into several color blocks, creating a stylized effect.
[0040] Step 204: Multiply the target lighting response level and the fragment's color value to obtain the fragment's basic lighting value.
[0041] For example, after rendering the target 3D model based on the basic lighting values of each fragment corresponding to the target 3D model, the resulting first 2D image can be as follows: Figure 6 As shown.
[0042] Step 205: Render the target 3D model based on the color values of the light source, the color values of the fragments, and the basic lighting values to obtain a stylized 2D image of the target 3D model.
[0043] Among them, stylized 2D images refer to images of 3D models after the target 3D model has been stylized. Users can see 3D models with stylized effects through stylized 2D images.
[0044] Optionally, the color values of the light source, the color values of the fragments, and the basic lighting values can be added together, and the target 3D model can be rendered based on the addition result to obtain a stylized 2D image of the target 3D model.
[0045] In this embodiment, by stylizing existing realistic models instead of creating stylized 3D models from scratch, manpower and time costs are reduced, stylization efficiency is improved, and existing realistic models can be reused between different projects, further improving efficiency. In addition, since the lighting response level can be adjusted according to project needs, this embodiment can adjust the lighting response level according to the stylization requirements of different projects, thereby meeting the stylization requirements of different projects, making it highly adaptable and flexible.
[0046] In some embodiments, this embodiment further includes: The edge light corresponding to the fragment is determined based on the fragment normal and the illumination intensity of the light source; The target 3D model is rendered based on the color values of the light source, the color values of the fragments, and the basic lighting values to obtain a stylized 2D image of the target 3D model, including: The overall illumination value of the fragment is determined based on the color values of the edge light, the light source, and the basic illumination value. Add the overall illumination value and the fragment's color value to obtain the target color value corresponding to the fragment; The target 3D model is rendered based on the target color value to obtain a stylized 2D image of the target 3D model.
[0047] The Fresnel coefficients can be determined based on the fragment's normal vector and the light intensity of the light source. The edge light corresponding to the fragment can then be determined based on these Fresnel coefficients. The edge light and the color value of the light source can be multiplied, and the result can be added to the basic illumination value to obtain the overall illumination value.
[0048] In this embodiment, the edge light corresponding to the fragment is determined based on the normal of the fragment and the illumination intensity of the light source. The overall illumination value of the fragment is determined based on the edge light, the color value of the light source, and the basic illumination value. The overall illumination value and the color value of the fragment are added together to obtain the target color value corresponding to the fragment. The target 3D model is rendered based on the target color value to obtain a stylized 2D image of the target 3D model, which improves the clarity of the outline of the 3D model in the stylized 2D image and enhances the stylization effect of the stylized 2D image.
[0049] In some embodiments, the overall illumination value of a fragment is determined based on the edge light, the color value of the light source, and the basic illumination value, including: Based on the edge light, the fragment normal, and the direction of the light source, determine the target edge light of the fragment in the direction of the light source; Multiply the color values of the target edge light and the light source, and add the result of the multiplication to the basic lighting value to obtain the overall lighting value of the fragment.
[0050] In this process, the normal of the fragment and the direction of the light source can be substituted into formula (2) to calculate the intensity ratio of the edge light corresponding to the fragment. Then, the intensity ratio is multiplied by the edge light of the fragment to obtain the target edge light. (2) in, w This indicates the intensity ratio of the edge light of a fragment. N Represents the normal vector. L Indicates the direction of the light source. This indicates dot product.
[0051] In this embodiment, the target edge light of the fragment is determined in the direction of the light source based on the edge light, the normal of the fragment, and the direction of the light source. The color value of the target edge light and the light source are multiplied, and the multiplication result is added to the basic illumination value to obtain the overall illumination value of the fragment, so that the edge light responds to real illumination, further enhancing the realism and immersion of the stylized 2D image.
[0052] In some embodiments, determining the edge light corresponding to the fragment based on the fragment's normal and the illumination intensity of the light source includes: The display weight of the edge light corresponding to the fragment is determined based on the fragment normal and the viewing angle of the fragment. When the display weight is greater than or equal to a preset threshold, the edge light corresponding to the fragment is determined based on the fragment normal and the illumination intensity of the light source.
[0053] The viewing angle of the observed fragment can be understood as the direction from the fragment to the virtual camera. Specifically, the dot product of the fragment's normal and the viewing angle of the observed fragment can be determined, and the dot product result can be mapped to a value between [0, 1] to obtain the display weight. The preset threshold can be a value between [0, 1].
[0054] Optionally, if the display weight is less than a preset threshold, the edge light corresponding to the fragment is not determined based on the normal of the fragment and the illumination intensity of the light source. That is, if the display weight of the edge light corresponding to the fragment is less than the preset threshold, the fragment does not have edge light.
[0055] Since the preset threshold can be adjusted according to project needs, in this embodiment, the display weight of the edge light corresponding to the fragment is determined based on the normal of the fragment and the viewing angle of the fragment. When the display weight is greater than or equal to the preset threshold, the edge light corresponding to the fragment is determined based on the normal of the fragment and the illumination intensity of the light source. This can make the final stylized effect more in line with the project requirements and further improve the flexibility of stylization.
[0056] In some embodiments, this embodiment further includes: Determine the distance from each voxel in the voxel mesh corresponding to the target 3D model to the surface of the target 3D model, and determine the distance corresponding to the vertex on the target 3D model based on the distance; Use the distance corresponding to the vertex as the transparency value data of the vertex, so that fragments have corresponding distances; Based on the edge light, the color values of the light source, and the basic illumination values, the overall illumination values of the fragment are determined, including: Multiply the edge light, the distance to the fragment, and the color value of the light source to obtain the target illumination value of the fragment; The target illumination value and the base illumination value are added together to obtain the overall illumination value of the fragment.
[0057] The voxel mesh corresponding to the target 3D model can be a voxel network obtained by converting the initial 3D model, or it can be a voxel mesh obtained by converting the target 3D model; this embodiment does not limit this. Optionally, the distance from each voxel in the voxel mesh corresponding to the target 3D model to the surface of the target 3D model can be determined using the distance vdb function in Houdini. The distance from each voxel to the surface of the target 3D model can also be referred to as SDF data.
[0058] After obtaining the voxel mesh, each vertex falls within an interior bounded by the centers of 8 voxels. Interpolation can be performed based on the distances from these 8 voxels to the surface of the target 3D model to obtain the distance corresponding to that vertex. Using the vertex's distance as transparency data means using it as the alpha channel value, allowing interpolation to be performed based on these vertex distances during fragment generation to obtain the fragment's corresponding distance.
[0059] Optionally, the distance from the voxel to the surface of the target 3D model can be mapped to a value between [0, 1] to obtain the ambient occlusion value (also known as the AO value), and then the distance corresponding to the vertex can be determined based on the ambient occlusion value.
[0060] The ambient occlusion value makes it easier for light to be blocked as the pixels corresponding to fragments are closer to the interior of the target 3D model, resulting in a darker interior of the target 3D model. Therefore, by determining the overall illumination value based on the distance to the fragments and rendering the target 3D model based on the overall illumination value, the interior of the target 3D model can be made dark.
[0061] In this embodiment, the distance from each voxel in the voxel mesh corresponding to the target 3D model to the surface of the target 3D model is determined, and the distance corresponding to the vertex on the target 3D model is determined based on the distance; the distance corresponding to the vertex is used as the transparency value data of the vertex so that the fragment has a corresponding distance; the edge light, the distance corresponding to the fragment, and the color value of the light source are multiplied to obtain the target lighting value of the fragment; the target lighting value and the basic lighting value are added to obtain the overall lighting value of the fragment; the overall lighting value and the color value of the fragment are added to obtain the target color value corresponding to the fragment; the target 3D model is rendered based on the target color value to obtain the stylized 2D image of the target 3D model, realizing the calculation of the ambient occlusion value using SDF data, improving the lighting and shadow effect of the 3D model, and making the rendered stylized 2D image more profound and layered.
[0062] As can be seen from the above, in this embodiment, a target 3D model to be stylized is obtained, and the fragments corresponding to the target 3D model are determined; based on the normal of the fragment and the direction of the light source of the target 3D model, the diffuse reflection intensity corresponding to the fragment is determined; the target illumination response level corresponding to the diffuse reflection intensity is determined from at least two discrete illumination response levels; the target illumination response level and the color value of the fragment are multiplied to obtain the basic illumination value of the fragment; the target 3D model is rendered based on the color value of the light source, the color value of the fragment, and the basic illumination value to obtain a stylized 2D image of the target 3D model, thereby achieving automated stylization processing, improving the efficiency of stylization, and since the discrete illumination response levels can be set according to the actual needs of different projects to generate different styles, this embodiment can improve the flexibility of stylization.
[0063] The following is based on Figure 7 The rendering of the model provided in the embodiments of this application will be further explained.
[0064] Step 701: Obtain the initial 3D model to be stylized and convert the initial 3D model into a voxel mesh.
[0065] Step 702: Perform preliminary stylization processing on the voxel mesh to obtain the target voxel mesh.
[0066] Step 703: Determine the distance from each voxel in the target voxel mesh to the surface of the target 3D model, and determine the distance corresponding to the vertex on the target 3D model based on the distance.
[0067] Step 704: Use the distance corresponding to the vertex as the transparency value data of the vertex.
[0068] Step 705: Convert the target voxel mesh into a candidate 3D model. For each target vertex in the candidate 3D model, determine the initial vertex on the initial 3D model that matches the target vertex, and use the normal of the initial vertex as the normal of the target vertex to obtain the target 3D model.
[0069] Step 706: Determine the fragments corresponding to the target 3D model.
[0070] Step 707: Determine the diffuse reflection intensity corresponding to the fragment based on the normal of the fragment and the direction of the light source of the target 3D model.
[0071] Step 708: Determine the target illumination response level corresponding to the diffuse reflection intensity from at least two discrete illumination response levels, and multiply the target illumination response level by the fragment's color value to obtain the fragment's basic illumination value.
[0072] Among them, after rendering the target 3D model based on the basic illumination values of each fragment corresponding to the target 3D model, the resulting first 2D image can be, for example, as shown below. Figure 6 As shown.
[0073] Step 709: Based on the normal of the fragment and the viewing angle of the fragment, determine the display weight of the edge light corresponding to the fragment. If the display weight is greater than or equal to a preset threshold, determine the edge light corresponding to the fragment based on the normal of the fragment and the illumination intensity of the light source.
[0074] Among them, after rendering the target 3D model based on the edge lights corresponding to each fragment of the target 3D model, the resulting second 2D image can be, for example, as shown below. Figure 8 As shown in Figure 801.
[0075] Step 7010: Multiply the edge light and the distance corresponding to the fragment to obtain the first illumination value of the fragment.
[0076] Among them, after rendering the target 3D model based on the first illumination value of each fragment corresponding to the target 3D model, the resulting 3D image can be, for example, as shown below. Figure 8 As shown in Figure 802.
[0077] Step 7011: Determine the second illumination value in the direction of the light source based on the first illumination value, the normal of the fragment, and the direction of the light source.
[0078] The intensity ratio can be obtained by formula (2) above, and then the intensity ratio is multiplied by the first illumination value to obtain the second illumination value in the direction of the light source.
[0079] Step 7012: Multiply the second illumination value and the color value of the light source, and add the multiplication result to the basic illumination value to obtain the overall illumination value of the fragment.
[0080] Among them, the fourth two-dimensional image obtained after rendering the target three-dimensional model based on the multiplication result can be, for example, as shown in the figure. Figure 8 As shown in Figure 803. After rendering the target 3D model based on the overall illumination values of each fragment corresponding to the target 3D model, the resulting fifth 2D image can be, for example, as shown in Figure 803. Figure 9 As shown in 901.
[0081] Step 7013: Add the overall illumination value and the fragment color value to obtain the target color value corresponding to the fragment. Render the target 3D model based on the target color value to obtain a stylized 2D image of the target 3D model.
[0082] Among them, after rendering the target 3D model based on the target color values of each fragment corresponding to the target 3D model, the resulting stylized 2D image can be, for example, as shown below. Figure 9As shown in Figure 902.
[0083] The definitions of terms, specific implementation methods, and corresponding beneficial effects of this embodiment can be found in the above method embodiments, and will not be repeated here.
[0084] This embodiment also provides a model rendering device, which can be integrated into a server. For example, such as Figure 10 As shown, the model rendering device may include: The acquisition module 1001 is used to acquire the target 3D model to be stylized and to determine the fragments corresponding to the target 3D model. The first determining module 1002 is used to determine the diffuse reflection intensity corresponding to the fragment based on the normal of the fragment and the direction of the light source of the target 3D model. The second determining module 1003 is used to determine the target illumination response level corresponding to the diffuse reflection intensity from at least two discrete illumination response levels; The multiplication module 1004 is used to multiply the target illumination response level and the fragment's color value to obtain the fragment's basic illumination value; The rendering module 1005 is used to render the target 3D model based on the color values of the light source, the color values of the fragments, and the basic lighting values, to obtain a stylized 2D image of the target 3D model.
[0085] In some embodiments, the rendering module 1005 is used to perform: The edge light corresponding to the fragment is determined based on the fragment normal and the illumination intensity of the light source; The overall illumination value of the fragment is determined based on the color values of the edge light, the light source, and the basic illumination value. Add the overall illumination value and the fragment's color value to obtain the target color value corresponding to the fragment; The target 3D model is rendered based on the target color value to obtain a stylized 2D image of the target 3D model.
[0086] In some embodiments, the rendering module 1005 is used to perform: Based on the edge light, the fragment normal, and the direction of the light source, determine the target edge light of the fragment in the direction of the light source; Multiply the color values of the target edge light and the light source, and add the result of the multiplication to the basic lighting value to obtain the overall lighting value of the fragment.
[0087] In some embodiments, the rendering module 1005 is used to perform: The display weight of the edge light corresponding to the fragment is determined based on the fragment normal and the viewing angle of the fragment. When the display weight is greater than or equal to a preset threshold, the edge light corresponding to the fragment is determined based on the fragment normal and the illumination intensity of the light source.
[0088] In some embodiments, the acquisition module 1001 is further configured to perform: Determine the distance from each voxel in the voxel mesh corresponding to the target 3D model to the surface of the target 3D model, and determine the distance corresponding to the vertex on the target 3D model based on the distance; Use the distance corresponding to the vertex as the transparency value data of the vertex, so that fragments have corresponding distances; Rendering module 1005 is used to perform: Multiply the edge light, the distance to the fragment, and the color value of the light source to obtain the target illumination value of the fragment; The target illumination value and the base illumination value are added together to obtain the overall illumination value of the fragment.
[0089] In some embodiments, the acquisition module 1001 is further configured to perform: Obtain the initial 3D model to be stylized; The initial 3D model is converted into a voxel mesh, and the voxel mesh is then converted into a candidate 3D model. For each target vertex in the candidate 3D model, determine the initial vertex on the initial 3D model that matches the target vertex; The normal of the initial vertex is used as the normal of the target vertex to obtain the target 3D model.
[0090] In some embodiments, the acquisition module 1001 is used to perform: The voxel mesh is initially stylized to obtain the target voxel mesh; The target voxel mesh is converted into a candidate 3D model.
[0091] In practice, each of the above modules can be implemented as an independent entity or can be combined arbitrarily to be implemented as the same or several entities. For the specific implementation methods and corresponding beneficial effects of each of the above modules, please refer to the previous method embodiments, which will not be repeated here.
[0092] Accordingly, this application also provides an electronic device, which can be a terminal, such as a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. Alternatively, the electronic device can be a server.
[0093] like Figure 11 As shown, Figure 11This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 1100 includes a processor 1101 with one or more processing cores, a memory 1102 with one or more computer-readable storage media, and a computer program stored on the memory 1102 and executable on the processor. The processor 1101 and the memory 1102 are electrically connected. Those skilled in the art will understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0094] The processor 1101 is the control center of the electronic device 1100. It connects various parts of the electronic device 1100 via various interfaces and lines. By running or loading software programs and / or units stored in the memory 1102, and by calling data stored in the memory 1102, it executes various functions of the electronic device 1100 and processes data, thereby providing overall monitoring of the electronic device 1100. The processor 1101 can be a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), etc., and can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application.
[0095] In this embodiment, the processor 1101 in the electronic device 1100 loads the instructions corresponding to the processes of one or more applications into the memory 1102 according to the following steps, and the processor 1101 runs the applications stored in the memory 1102 to realize various functions, such as: Obtain the target 3D model to be stylized and determine the fragments corresponding to the target 3D model; The diffuse reflection intensity corresponding to the fragment is determined based on the normal of the fragment and the direction of the light source of the target 3D model. Determine the target illumination response level corresponding to the diffuse reflection intensity from at least two discrete illumination response levels; Multiply the target lighting response level by the fragment's color value to obtain the fragment's basic lighting value; The target 3D model is rendered based on the color values of the light source, the color values of the fragments, and the basic lighting values to obtain a stylized 2D image of the target 3D model.
[0096] The specific implementation of each of the above operations and their corresponding beneficial effects can be found in the previous embodiments, and will not be repeated here.
[0097] Optional, such as Figure 11As shown, the electronic device 1100 also includes: a touch display screen 1103, a radio frequency circuit 1104, an audio circuit 1105, an input unit 1106, and a power supply 1107. The processor 1101 is electrically connected to the touch display screen 1103, the radio frequency circuit 1104, the audio circuit 1105, the input unit 1106, and the power supply 1107. Those skilled in the art will understand that... Figure 11 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0098] The touch display screen 1103 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 1103 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 1101. It can also receive and execute commands from the processor 1101. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 1101 to determine the type of touch event. Subsequently, the processor 1101 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 1103 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 1103 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 1103 can also be used as part of the input unit 1106 to achieve input functions.
[0099] The radio frequency circuit 1104 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other electronic devices, and to transmit and receive signals with network devices or other electronic devices.
[0100] Audio circuit 1105 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuit 1105 can convert received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuit 1105, converted back into audio data, and then processed by processor 1101 before being transmitted via radio frequency circuit 1104 to, for example, another electronic device, or output to memory 1102 for further processing. Audio circuit 1105 may also include an earphone jack to provide communication between peripheral headphones and electronic devices.
[0101] The input unit 1106 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
[0102] Power supply 1107 is used to supply power to various components of electronic device 1100. Optionally, power supply 1107 can be logically connected to processor 1101 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 1107 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0103] although Figure 11 As not shown in the diagram, the electronic device 1100 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.
[0104] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0105] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0106] Therefore, embodiments of this application provide a computer-readable storage medium storing multiple computer programs that can be loaded by a processor to execute any of the model rendering methods provided in this application. For example, the computer program can execute the steps of the following model rendering method: Obtain the target 3D model to be stylized and determine the fragments corresponding to the target 3D model; The diffuse reflection intensity corresponding to the fragment is determined based on the normal of the fragment and the direction of the light source of the target 3D model. Determine the target illumination response level corresponding to the diffuse reflection intensity from at least two discrete illumination response levels; Multiply the target lighting response level by the fragment's color value to obtain the fragment's basic lighting value; The target 3D model is rendered based on the color values of the light source, the color values of the fragments, and the basic lighting values to obtain a stylized 2D image of the target 3D model.
[0107] The specific implementation of each of the above operations and their corresponding beneficial effects can be found in the previous embodiments, and will not be repeated here.
[0108] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0109] Since the computer program stored in the computer-readable storage medium can execute any of the model rendering methods provided in the embodiments of this application, it can achieve the beneficial effects that any of the model rendering methods provided in the embodiments of this application can achieve, as detailed in the preceding embodiments, and will not be repeated here.
[0110] According to one aspect of this application, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the above embodiments.
[0111] In the above embodiments of the model rendering apparatus, computer-readable storage medium, electronic device, and computer program product, the descriptions of each embodiment have different focuses. Parts not described in detail in a particular embodiment can be referred to in the relevant descriptions of other embodiments. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes and beneficial effects of the model rendering apparatus, computer-readable storage medium, computer program product, electronic device, and their corresponding units described above can be referred to the description of the model rendering method in the above embodiments, and will not be repeated here.
[0112] The foregoing has provided a detailed description of a model rendering method, apparatus, electronic device, computer-readable storage medium, and computer program product provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A model rendering method, characterized by, The method comprises: obtaining a target three-dimensional model to be stylized, and determining a corresponding patch of the target three-dimensional model; determining a diffuse reflection intensity corresponding to the patch based on a normal of the patch and a direction of a light source of the target three-dimensional model; determining a target light response level corresponding to the diffuse reflection intensity from at least two discrete light response levels; multiplying the target light response level and a color value of the patch to obtain a basic light value of the patch; rendering the target three-dimensional model based on a color value of the light source, the color value of the patch and the basic light value to obtain a stylized two-dimensional image of the target three-dimensional model.
2. The method of claim 1, wherein, The method further comprises: determining an edge light corresponding to the patch based on the normal of the patch and an illumination intensity of the light source; the rendering of the target three-dimensional model based on the color value of the light source, the color value of the patch and the basic light value to obtain the stylized two-dimensional image of the target three-dimensional model comprises: determining an overall light value of the patch based on the edge light, the color value of the light source and the basic light value; adding the overall light value and the color value of the patch to obtain a target color value corresponding to the patch; rendering the target three-dimensional model based on the target color value to obtain the stylized two-dimensional image of the target three-dimensional model.
3. The method of claim 2, wherein, The determination of the overall light value of the patch based on the edge light, the color value of the light source and the basic light value comprises: determining a target edge light of the patch in the direction of the light source based on the edge light, the normal of the patch and the direction of the light source; multiplying the target edge light and the color value of the light source, and adding the multiplication result and the basic light value to obtain the overall light value of the patch.
4. The method of claim 2, wherein, The determination of the edge light corresponding to the patch based on the normal of the patch and the illumination intensity of the light source comprises: determining a display weight of the edge light corresponding to the patch based on the normal of the patch and a viewing angle of the patch; in a case where the display weight is greater than or equal to a preset threshold, determining the edge light corresponding to the patch based on the normal of the patch and the illumination intensity of the light source.
5. The method of claim 2, wherein, The method further comprises: determining a distance from each voxel in a voxel grid corresponding to the target three-dimensional model to a surface of the target three-dimensional model, and determining a distance corresponding to a vertex on the target three-dimensional model based on the distance; using the distance corresponding to the vertex as transparency value data of the vertex to make the patch exist the corresponding distance; The determination of the overall light value of the patch based on the edge light, the color value of the light source and the basic light value comprises: multiplying the edge light, the distance corresponding to the patch and the color value of the light source to obtain a target light value of the patch; adding the target light value and the basic light value to obtain the overall light value of the patch.
6. The method according to any one of claims 1 to 5, characterized in that, The obtaining of the target three-dimensional model to be stylized comprises: obtaining an initial three-dimensional model to be stylized; Converting the initial three-dimensional model into a voxel grid, and converting the voxel grid into a candidate three-dimensional model; For each target vertex in the candidate three-dimensional model, determining an initial vertex on the initial three-dimensional model that matches the target vertex; Taking the normal of the initial vertex as the normal of the target vertex, to obtain a target three-dimensional model.
7. The method of claim 6, wherein, The converting the voxel grid into a candidate three-dimensional model comprises: Performing a preliminary stylization on the voxel grid to obtain a target voxel grid; Converting the target voxel grid into a candidate three-dimensional model.
8. A model rendering apparatus, characterized by comprising: Comprise: An acquisition module configured to acquire a target three-dimensional model to be stylized, and determine a corresponding patch of the target three-dimensional model; A first determination module configured to determine a diffuse reflection intensity corresponding to the patch based on a normal of the patch and a direction of a light source of the target three-dimensional model; A second determination module configured to determine a target light response level corresponding to the diffuse reflection intensity from at least two discrete light response levels; A multiplication module configured to multiply the target light response level and a color value of the patch to obtain a basic lighting value of the patch; A rendering module configured to perform a rendering process on the target three-dimensional model based on a color value of the light source, the color value of the patch, and the basic lighting value, to obtain a stylized two-dimensional image of the target three-dimensional model.
9. An electronic device, comprising: A processor and a memory, the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps of the model rendering method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps of the model rendering method according to any one of claims 1 to 7.