Rendering method and rendering device of 3D model and storage medium

When rendering a 3D model through GPU shader, the model patch is assembled using vertex change data, and the normal vector and drape angle of pixels are calculated, which solves the problem of slow rendering speed in the existing technology, real-time rendering and efficient user interaction are achieved.

CN119722907APending Publication Date: 2025-03-28SHENZHEN ANYCUBIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411884694.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-03-28

Smart Images

  • Figure CN119722907A_ABST
    Figure CN119722907A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a 3D model rendering method and device and a storage medium, and is used for the technical field of 3D printing. In the embodiment of the invention, the GPU shader can assemble the model patch of the 3D model based on the vertex change data and the non-changed vertex data when the vertex data of the 3D model in the screen image is changed, and obtains the suspension angle of the pixel based on the normal vector of the pixel in the assembled model patch. Rendering corresponding colors for the pixels based on the overhang angles of the pixels; according to the method and the device, the vertex data of all triangular patches in the 3D model does not need to be acquired again, the processing speed is high, the change of the 3D model can be processed in real time, the corresponding pixels of the 3D model on the screen image can be rendered in time, and the efficiency of manually adding the support by a user is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of 3D printing technology, and in particular to a rendering method, a rendering device, and a storage medium for a 3D model. Background Art

[0002] In 3D printing slicing software, it is necessary to add support to the 3D model to be printed. The purpose of adding support to the 3D model is to support the model forming during actual printing. Adding support can generally be divided into automatic support and manual support. Automatic support means that after the user clicks the Generate Support button, the algorithm automatically adds support data to the 3D model. Manual support is a supplement to the automatic algorithm, allowing the user to control the generation of support at a certain point of the 3D model.

[0003] In order to help users quickly identify the points on the 3D model where support can be added when manually supporting, the slicing software will pre-process and render the 3D model to be manually supported when entering manual support, and render the triangular faces on the 3D model with a certain overhang angle in a special color for identification. The overhang angle refers to the angle between the normal vector of the triangular face and the xy plane in the three-dimensional xyz coordinate system of the world where the 3D model is located.

[0004] Currently, each time the CPU renders a 3D model, it needs to re-acquire the vertex data of all triangles in the 3D model and then calculate the overhang angles of all triangles. This slows the processing speed and easily makes it difficult to render all triangles on the 3D model in a timely manner, affecting the efficiency of users manually adding supports. Summary of the invention

[0005] The embodiments of the present application provide a 3D model rendering method, a rendering device, and a storage medium, which can timely render the corresponding pixels of the 3D model on the screen image, effectively improving the efficiency of users manually adding supports.

[0006] The embodiment of the present application provides a 3D model rendering method, which is applied to a GPU shader, including:

[0007] When vertex data of the 3D model in the screen image changes, acquiring vertex change data corresponding to the 3D model;

[0008] Assembling model patches of the 3D model based on the vertex change data and the vertex data that has not changed in the 3D model;

[0009] Determine a normal vector of a pixel in a model patch of the 3D model, and obtain an overhang angle of the pixel in three-dimensional space based on the normal vector of the pixel;

[0010] Based on the overhang angle of the pixel, a corresponding color is rendered for the pixel in the screen image, so as to determine the pixel in the 3D model to which support can be added based on the color of the pixel on the screen image.

[0011] In some embodiments of the present application, the GPU shader includes a vertex shader;

[0012] The acquiring of vertex change data corresponding to the 3D model comprises:

[0013] In the process of the vertex shader performing matrix transformation on the vertex data of the 3D model, if a vertex with a changed coordinate is generated, vertex change data corresponding to the vertex is obtained.

[0014] In some embodiments of the present application, the GPU shader includes: a geometry shader;

[0015] Determining the normal vector of a pixel in a model patch of the 3D model comprises:

[0016] Determine a normal vector of a model patch of the 3D model based on the geometry shader;

[0017] Rasterizing the model surface to obtain pixel fragments corresponding to the model surface;

[0018] The normal vector of the model face patch is interpolated based on the coordinate data of the pixel fragment to obtain the normal vector of the pixel fragment, and then the normal vector of the pixel corresponding to the pixel fragment is obtained.

[0019] In some embodiments of the present application, the GPU shader includes: a fragment shader;

[0020] Determining the normal vector of a pixel in a model patch of the 3D model comprises:

[0021] Rasterizing the model surface to obtain pixel fragments corresponding to the model surface;

[0022] In the fragment shader, a normal vector of any pixel in the pixel fragment is determined based on a similarity between the pixel and adjacent pixels.

[0023] In some embodiments of the present application, determining the normal vector of any pixel based on the similarity between any pixel in the pixel segment and adjacent pixels includes:

[0024] Acquire coordinate difference data between any pixel and the adjacent pixel, and determine a first derivative vector of the coordinate difference data in a first direction and a second derivative vector in a second direction; the first direction and the second direction are located on a horizontal plane perpendicular to the gravity direction in the three-dimensional space, and the first direction is perpendicular to the second direction;

[0025] The first derivative vector is cross-multiplied with the second derivative vector to obtain a normal vector of any pixel.

[0026] In some embodiments of the present application, obtaining the overhang angle of the pixel in the three-dimensional space based on the normal vector of the pixel includes:

[0027] Acquire a first angle between a normal vector of the pixel in the 3D model and a gravity vector in the three-dimensional space, and a second angle between a normal vector of an adjacent pixel of the pixel in the 3D model and a gravity vector in the three-dimensional space;

[0028] The first angle and the second angle are summed and then divided by the total number of the pixel and the adjacent pixels to obtain an overhang angle of the pixel in three-dimensional space.

[0029] In some embodiments of the present application, the rendering of a corresponding color for the pixel in the screen image based on the overhang angle of the pixel includes:

[0030] Acquire an overhang angle parameter, where the overhang angle parameter is used to indicate an overhang angle of the added support, and the overhang angle parameter is adjusted based on the angle adjustment instruction;

[0031] If the overhang angle of the pixel is less than or equal to the overhang angle parameter, dyeing the pixel in the screen image into a preset model rendering color;

[0032] If the overhang angle of the pixel is greater than the overhang angle parameter, the pixel is rendered as a target color in the screen image, and the target color is another color that is different from the preset model rendering color.

[0033] In some embodiments of the present application, rendering the pixel in the screen image as a target color includes:

[0034] If the overhang angle of the pixel is larger, the saturation of the target color rendered to the pixel in the screen image is closer to the preset saturation;

[0035] If the overhang angle of the pixel is smaller, the saturation of the target color rendered to the pixel in the screen image is further away from the preset saturation, so that the pixels with an overhang angle greater than the overhang angle parameter form a gradient color.

[0036] The present application also provides a 3D model rendering device, including:

[0037] Processor and memory;

[0038] The memory is used to store executable instructions of the processor;

[0039] The processor is configured to execute the rendering method according to any one of claims 1 to 8 by executing the executable instructions.

[0040] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium includes instructions. When the instructions are executed on a computer, the computer executes the method described above.

[0041] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0042] In an embodiment of the present application, when the vertex data of the 3D model in the screen image changes, the GPU shader can assemble the model faces of the 3D model based on the vertex change data and the vertex data that has not changed, obtain the overhang angle of the pixel based on the normal vector of the pixel in the assembled model facet, and render the pixel with the corresponding color based on the overhang angle of the pixel; there is no need to re-acquire the vertex data of all the triangle faces in the 3D model, the processing speed is fast, the changes of the 3D model can be processed in real time, and the corresponding pixels of the 3D model on the screen image can be rendered in time, effectively improving the efficiency of users manually adding supports. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0044] Figure 1 A rendering flow chart of a 3D model disclosed in an embodiment of the present application;

[0045] Figure 2 A rendering flowchart of another 3D model disclosed in an embodiment of the present application;

[0046] Figure 3 A schematic diagram of a normal vector of a model face disclosed in an embodiment of the present application;

[0047] Figure 4 A schematic diagram of an overhang angle disclosed in an embodiment of the present application;

[0048] Figure 5A schematic diagram of support points on a 3D model disclosed in an embodiment of the present application;

[0049] Figure 6 A rendering device diagram of a 3D model disclosed in an embodiment of the present application;

[0050] Figure 7 A diagram of a rendering device for another 3D model disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0051] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0052] In the description of the embodiments of the present application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the embodiments of the present application can be understood according to specific circumstances.

[0053] In 3D printing slicing software, before 3D printing a 3D model, in addition to using an automatic support adding algorithm to add supports to the 3D model, users can also manually add supports; currently, manual support addition uses a CPU to calculate the overhang angle of a triangular face on the 3D model, and then renders a special color for the triangular face based on the overhang angle, so that users can decide to manually add supports after observation.

[0054] However, since the CPU processes rendering data frame by frame when rendering a 3D model, it can only process the vertex data of all triangles in the 3D model of the rendering frame at a certain moment. If the data of the rendering frame is not processed, the data processing of subsequent frames will be blocked; once some data in the 3D model changes, it can only process all the data in the 3D model as a whole, and cannot process the changed data in the 3D model, and cannot process the changes of the 3D model in real time. Every time the CPU renders a 3D model, it needs to re-acquire the vertex data of all triangles in the 3D model, and then calculate the overhang angles of all triangles. The slow processing speed can easily make it difficult to render all the triangles on the 3D model in a timely manner, affecting the efficiency of users manually adding supports.

[0055] Therefore, the embodiment of the present application provides a 3D model rendering method, which can timely render the corresponding pixels of the 3D model on the screen image, effectively improving the efficiency of users manually adding supports, such as Figure 1 As shown, the specific rendering steps are as follows:

[0056] 101. When vertex data of the 3D model in the screen image changes, vertex change data corresponding to the 3D model is obtained.

[0057] In an embodiment of the present application, when the vertex data of the 3D model in the screen image changes, the vertex change data corresponding to the 3D model can be obtained, and the screen is the display screen corresponding to the GPU shader; it can be understood that the 3D model is composed of multiple vertices, each vertex has vertex coordinates and other attributes (such as transparency) in three-dimensional space, and the vertex data is used to describe the information of the vertex, including vertex coordinate data and other attribute data corresponding to the vertex. When the 3D model is processed by algorithm, such as punching or shelling, the vertex data will be deleted or added accordingly on the 3D model. At this time, the vertex change data that will exist on the 3D model is incremental vertex change data including deleted vertex data and added vertex data. The vertex change data that has changed on the 3D model can be obtained in real time.

[0058] Specifically, the GPU shader includes a vertex shader; the vertex data of the 3D model in the screen image can be mapped from the computer memory of the screen to the cache of the GPU shader; then, the vertex data of the 3D model in the screen image can be input into the vertex shader; in the process of the vertex shader performing matrix transformation on the vertex data of the 3D model, if a vertex with a changed coordinate is generated, the vertex change data corresponding to the vertex is obtained. It can be understood that in the vertex shading stage of the vertex shader, the vertex shader will multiply the vertex data of the 3D model by the matrix of the relevant change for matrix transformation, that is, in the vertex shader, generally execute: out = M * in, in is the input vertex data, out is the output vertex data, and M is the matrix for the relevant change; wherein, M can be an MVP matrix (model-view-projection matrix), the model matrix is ​​used to transform the vertex coordinates into world coordinates; the view matrix is ​​used to transform the world coordinates into the observation coordinates corresponding to the observation angle, such as after the observation angle is rotated, the corresponding M will change; the projection matrix is ​​used to transform the observation coordinates into the projection coordinates corresponding to the screen, and the projection coordinates are the projections of the three-dimensional observation coordinates onto the two-dimensional pixel coordinates on the screen. After the matrix transformation, the vertices whose coordinates have changed can be identified and the corresponding vertex change data can be obtained.

[0059] 102. Assemble model patches of the 3D model based on the vertex change data and the vertex data that has not changed in the 3D model.

[0060] Then, the model patch of the 3D model can be assembled based on the vertex change data and the vertex data that has not changed in the 3D model. Among them, the vertex shader can obtain the coordinate data of the vertex transformation data in the three-dimensional coordinate system through matrix transformation of the vertex change data, and obtain the corresponding coordinate data in the three-dimensional coordinate system through matrix transformation of the vertex data that has not changed in the 3D model.

[0061] In the GPU shader, the coordinate data of multiple vertices constituting the model patch can be assembled into model patches in the 3D model based on the coordinate data of the vertex change data and the coordinate data of the vertex data that has not changed in the 3D model; wherein the model patch can be a triangular patch or a rectangular patch, which is not limited here. Among them, if the GPU shader already has the model patch of the 3D model, the model patch of the 3D model is reassembled, and if not, the model patch of the 3D model is directly assembled.

[0062] 103. Determine a normal vector of a pixel in a model patch of the 3D model, and obtain an overhang angle of the pixel in three-dimensional space based on the normal vector of the pixel.

[0063] After assembling the model patch of the 3D model, the normal vector of the pixel in the model patch of the 3D model can be determined, and the overhang angle of the pixel in the three-dimensional space can be obtained based on the normal vector of the pixel. Among them, the normal vector of the pixel is the normal vector (normal line) of the pixel in the three-dimensional space. It can be understood that the vertices of the 3D model have corresponding pixels on the screen image, and the screen image contains multiple pixels that form the 3D model; in the GPU, the model patch of the 3D model can be automatically rasterized based on the hardware circuit of the GPU to obtain multiple pixel fragments corresponding to the model patch, and the pixel fragment includes the pixel corresponding to the model patch on the screen image and the surrounding pixels of the pixel. Then, the normal vector of the pixel in the pixel fragment can be obtained, that is, the normal vector of the pixel in the model patch of the 3D model is obtained.

[0064] In an embodiment of the present application, after obtaining the normal vector of the pixel, the overhang angle of the pixel in the three-dimensional space can be obtained based on the normal vector of the pixel. Among them, the angle between the normal vector of the pixel and the direction of gravity in the three-dimensional space can be determined, and the overhang angle of the pixel in the three-dimensional space can be obtained based on the angle. Specifically, the unit vector corresponding to the normal vector of the pixel can be dot-multiplied with the unit vector corresponding to the direction of gravity in the three-dimensional space, and the vector product after the dot multiplication can be subjected to an arc cosine operation to obtain the angle between the normal vector of the pixel and the direction of gravity in the three-dimensional space; the angle is subtracted from the right angle to obtain the overhang angle of the pixel in the three-dimensional space.

[0065] For example, the three-dimensional space can be the world's three-dimensional xyz coordinate system, in which the direction of gravity is the -z axis, that is, the angle θ between the normal vector n of the pixel and the -z axis can be calculated. The norms of the normal vector n and -z of the pixel are both unit 1, that is, the unit vector, such as Figure 4 As shown, the corresponding formula is θ=arccos(dot(n,-z)), the unit is radian, that is, the angle of the angle θ is expressed in radians; wherein, the direction of the normal vector n of the pixel must be in the direction of -z. If it is not in the direction of -z, the normal vector n of the pixel is negated, that is, n=-n. Correspondingly, in the world's three-dimensional xyz coordinate system, the overhang angle of the pixel is the angle between the normal line of the pixel and the xy plane, that is, the overhang angle of the pixel can be obtained by subtracting the angle θ from the right angle pi / 4.

[0066] 104. Based on the overhang angle of the pixel, a corresponding color is rendered for the pixel in the screen image.

[0067] Next, based on the overhang angle of the pixel, the corresponding color can be rendered on the screen image for the pixel, so as to determine the pixel in the 3D model that can be supported based on the color of the pixel on the screen image. Generally speaking, the larger the overhang angle of the pixel, the greater the possibility that the pixel needs to be supported. That is, the pixel with an overhang angle greater than a certain angle value can be rendered with a special color. The pixel is the point on the screen image that can be supported for the 3D model. The user manually adds support to the 3D model by observing the screen image. Figure 5 As shown, in the world three-dimensional xyz coordinate system, the 3D model 1 in the printing platform 3 includes support columns 2 for automatically adding supports, and points H where users can manually add supports.

[0068] It is understandable that the existing CPU uses the overhang angle of the triangle to render the corresponding color of the triangle. The triangle is relatively large and difficult to adapt to the 3D model with complex details. In the present application, the GPU uses the overhang angle of the pixel to render the corresponding color of the pixel. The pixel is smaller than the triangle, which can effectively adapt to the 3D model with complex details. At the same time, in the existing CPU, it is necessary to calculate the overhang angle of the triangle in the 3D model one by one, and render the corresponding color of the triangle in the screen image based on the overhang angle of the triangle. However, the 3D model contains more triangles, and the rendering speed of the image in the CPU is slow. In the present application, the GPU can calculate the corresponding overhang angles of multiple pixels on the model face in parallel, and render the corresponding color of the pixel in the screen image in parallel through the overhang angles of multiple pixels, which effectively improves the rendering speed of the image.

[0069] It can be seen that in the embodiment of the present application, the GPU shader can assemble the model patches of the 3D model based on the vertex change data and the vertex data that has not changed when the vertex data of the 3D model in the screen image changes, obtain the overhang angle of the pixel based on the normal vector of the pixel in the assembled model patch, and render the pixel with the corresponding color based on the overhang angle of the pixel; there is no need to re-acquire the vertex data of all the triangular patches in the 3D model, the processing speed is fast, the changes of the 3D model can be processed in real time, and the corresponding pixels of the 3D model on the screen image can be rendered in time, effectively improving the efficiency of users manually adding supports.

[0070] The rendering process of the 3D model in this application will be further described in detail below. Figure 2 As shown, the specific steps include:

[0071] 201. When vertex data of a 3D model in a screen image changes, vertex change data corresponding to the 3D model is obtained.

[0072] 202. Assemble model patches of the 3D model based on the vertex change data and the vertex data that has not changed in the 3D model.

[0073] It can be understood that step 201 and step 202 are similar to the above-mentioned step 101 and step 102, and the details are not repeated here.

[0074] 203. Determine the normal vector of the pixel in the model patch of the 3D model.

[0075] In the embodiment of the present application, the GPU shader also includes a geometry shader and a fragment shader. The normal vector of the pixel can be obtained in the geometry shader based on the primitive data of the model patch, or the normal vector of the pixel can be obtained in the fragment shader based on the derivative vector of the pixel, as shown in specific steps 2031 and 2032:

[0076] 2031. Perform interpolation processing on the normal vector of the model face patch to obtain the normal vector of the pixel fragment, and then obtain the normal vector of the pixel corresponding to the pixel fragment.

[0077] In the embodiment of the present application, the normal vector of the model face of the 3D model can be determined based on the geometry shader; specifically, the vertex data corresponding to the 3D model includes: the vertex coordinate data of multiple model face patches on the 3D model; the vertex coordinate data of the model face patches can be input to the geometry shader to obtain the normal vector of the model face patch output by the geometry shader. Figure 3As shown, the model face of the 3D model is a triangular face. The vertex coordinate data of the three vertices a, b and c of the triangular face can be input into the geometry shader. In the geometry shader, two vectors p1=ba and p2=ca can be obtained. The normal vector n of the triangular face can be obtained by cross-multiplying the vectors p1 and p2.

[0078] Next, based on the hardware circuit of the GPU, the model patch of the 3D model can be automatically rasterized to obtain the pixel fragments corresponding to the model patch. The normal vector of the model patch is interpolated based on the coordinate data of the pixel fragment to obtain the normal vector of the pixel fragment, and then the normal vector of the pixel corresponding to the pixel fragment is obtained.

[0079] Specifically, the interpolation process may include determining the centroid coordinates of the pixel fragment in the model patch, performing weighted averaging on the normal vector of the model patch based on the centroid coordinates, and obtaining the normal vector of the pixel fragment; for example, when the model patch is a triangular patch, the centroid coordinates are the weights of the coordinates of the pixel fragment at the three vertices of the triangular patch, and performing weighted averaging on the weights and the normal vector of the triangular patch to obtain the normal vector of the pixel fragment. The pixel fragment contains a pixel and adjacent pixels, and the normal vector of the pixel fragment may be used as the normal vector of the pixel contained in the pixel fragment.

[0080] It is understandable that, in fact, there may be slight differences in the normal vectors of the pixels in the pixel fragment. In the interpolation process, the normal vector of the pixel fragment is directly used as the normal vector of the pixel contained in the pixel fragment. After the overhang angle of the pixel is obtained based on the normal vector of the pixel and the pixel is rendered in color, a tiny gap of the type of aliasing will be generated between adjacent pixels after rendering on a 3D model with complex details, and it will not be able to adapt to the 3D model with complex details. Therefore, step 2032 is proposed in the embodiment of the present application, and the normal vector of the pixel that conforms to the actual situation can be obtained more accurately by using the similarity between a certain pixel and the adjacent pixels, so that after the pixel is rendered in color, the tiny gap of the type of aliasing can be eliminated, and it can adapt to the 3D model with complex details.

[0081] 2032. Determine a normal vector of any pixel based on the similarity between any pixel and adjacent pixels in the pixel segment.

[0082] Among them, the model face of the 3D model can be rasterized based on the hardware circuit of the GPU to obtain pixel fragments corresponding to the model face; the corresponding pixel fragment data is input into the fragment shader, and in the fragment shader, the normal vector of any pixel is determined based on the similarity between any pixel and the adjacent pixels in the pixel fragment, and the adjacent pixels are the adjacent pixels of the any pixel.

[0083] Specifically, the coordinate difference data between any pixel and the adjacent pixels can be obtained, and the coordinate difference data is the deviation data between the coordinate of any pixel and the coordinate of the adjacent pixels. The coordinate of any pixel can be subtracted from the coordinate of the adjacent pixels to obtain the corresponding coordinate difference data. Then, the first derivative vector of the coordinate difference data in the first direction and the second derivative vector in the second direction can be determined; wherein the first direction and the second direction are located on a horizontal plane perpendicular to the direction of gravity in the three-dimensional space, and the first direction is perpendicular to the second direction; wherein the partial derivative of the coordinate difference data in the first direction can be calculated to obtain the first derivative vector. Then, the first derivative vector is cross-multiplied with the second derivative vector to obtain the normal vector of any pixel.

[0084] It can be understood that a pixel segment contains multiple pixels, and the similarities between different pixels in the pixel segment and adjacent pixels may be different. In the embodiment of the present application, the corresponding normal vector of each pixel in the pixel segment is determined by similarity, so the normal vector of each pixel in the pixel segment can be accurately obtained, and there are certain differences between the normal vectors of different pixels in the pixel segment.

[0085] If the three-dimensional space is the world's three-dimensional xyz coordinate system, the horizontal plane perpendicular to the gravity direction is the xy plane, the first direction is the x direction, and the second direction is the y direction; then we can get:

[0086] vec3 n=normalize(cross(dFdx(fs_in.vertex),dFdy(fs_in.vertex)))

[0087] Among them, in.vertex is the coordinate of the pixel, fs_in.vertex is the coordinate difference data between the pixel and the adjacent pixel, dFdx represents the derivative vector in the x direction, dFdy represents the derivative vector in the y direction, cross represents vector cross product, normalize represents normalization, and vec3 represents a three-dimensional vector.

[0088] It can be seen that in this step, the similarity between the pixel and the adjacent pixels in the pixel segment is used to more accurately obtain the normal vector of the pixel that conforms to the actual situation, that is, the normal vector of each pixel in the pixel segment is accurately obtained, so that after the pixel is rendered in color, the tiny gaps of the aliasing type can be eliminated, which can be adapted to 3D models with complex details.

[0089] In one implementable manner, the existing CPU cannot rasterize three-dimensional data. After the CPU determines the color corresponding to the triangle face based on the overhang angle of the triangle face, if rasterization is required, it is necessary to manually call the rasterization program to rasterize the triangle face, obtain the rendering data of the pixel, and color the pixel. At this time, all pixels in the same triangle face are rendered in the same color, and the shading accuracy is poor. In the present application, the model face is first rasterized by the hardware circuit of the GPU shader, and then the corresponding rendering color is determined for the pixels in the rasterized pixel fragment, which can effectively improve the shading accuracy.

[0090] 204. Based on the normal vector of the pixel and the normal vectors of adjacent pixels in the 3D model, obtain the overhang angle of the pixel in the three-dimensional space.

[0091] After obtaining the normal vector of the pixel in the model patch of the 3D model, the overhang angle of the pixel in the three-dimensional space can be obtained based on the normal vector of the pixel in the 3D model and the normal vector of the adjacent pixel. Specifically, the first angle between the normal vector of the pixel in the 3D model and the gravity vector in the three-dimensional space, and the second angle between the normal vector of the adjacent pixel of the pixel in the 3D model and the gravity vector in the three-dimensional space can be obtained. After summing the first angle and the second angle, divide it by the total number of pixels of the pixel and the adjacent pixel to obtain the overhang angle of the pixel in the three-dimensional space.

[0092] For example, the angle pn between the normal vector of a certain pixel and the gravity vector in three-dimensional space can be obtained by pn=arccos(dot(n,-z)), where p0 represents the angle between the normal vector of the pixel and the gravity vector in three-dimensional space, and n in pn is the number of adjacent pixels, which can be 4 or 6, and is not limited here. At this time, the final angle θ of the pixel is (p0+p1+p2+p3...+pn) / n; the angle θ can be subtracted from the right angle pi / 4 to obtain the overhang angle of the pixel.

[0093] 205. Render corresponding colors for a plurality of pixels in the screen image based on the overhang angle parameter and the overhang angle of the pixel.

[0094] In the embodiment of the present application, in the fragment shader, the corresponding color can be rendered to the pixel in the screen image based on the overhang angle parameter and the overhang angle of the pixel. Specifically, the overhang angle parameter can be obtained, and the overhang angle parameter is used to indicate the overhang angle of the added support, which can be expressed in radians; the overhang angle parameter is adjusted based on the angle adjustment instruction, and the overhang angle parameter can be set by the fragment shader itself or input by the user, which is not limited here.

[0095] In the fragment shader, the overhang angle parameter is compared with the overhang angle of the pixel fragment. If the overhang angle of the pixel is less than or equal to the overhang angle parameter, the pixel is rendered as the preset model rendering color on the screen image. The preset model rendering color is the rendering color of the 3D model under normal circumstances on the fragment shader, which can be gray or brown, etc., and is not specifically limited here. If the overhang angle of the pixel is greater than the overhang angle parameter, the pixel is rendered as the target color on the screen image. The target color is other colors that are different from the preset model rendering color. The other colors can be red or purple, etc., and are not specifically limited here; so that the user can quickly identify the points on the 3D model where support can be added through the screen image. The corresponding pseudo code in the fragment shader can be: If (π / 4-θ)>βthen; color=red; else color=normal; where θ is the angle between the normal vector of the pixel and the gravity direction in the three-dimensional space, π / 4-θ is the overhang angle of the pixel, β is the overhang angle parameter, color represents the color of the pixel fragment, red represents the target color is red, and normal represents the preset model rendering color.

[0096] In some embodiments of the present application, the initial overhang angle parameter of the pixel can be obtained, and the initial overhang angle parameter of the pixel can be the default overhang angle parameter set by the fragment shader itself. Then, in response to the angle adjustment instruction input by the user, the initial overhang angle parameter is adjusted to obtain the overhang angle parameter of the pixel. For example, the user can adjust the initial overhang angle parameter by touching a button in the fragment shader, or directly input the overhang angle parameter of the pixel into the fragment shader to adjust the initial overhang angle parameter, which is not limited here. That is, the user can dynamically adjust the overhang angle parameter of the pixel in real time, and the corresponding color of the pixel fragment is rendered in real time based on the adjusted overhang angle parameter and the overhang angle of the pixel, so that the user can quickly determine the points on the 3D model where support can be added based on their own needs, thereby better improving the interactive use experience of the software.

[0097] In some embodiments of the present application, a pixel segment with an overhang angle greater than an overhang angle parameter can be formed into a gradient color on a screen image. Specifically, when the overhang angle of a pixel is greater than the overhang angle parameter of the pixel segment, if the overhang angle of the pixel is larger, the saturation of the target color rendered to the pixel on the screen image is closer to the preset saturation; if the overhang angle of the pixel is smaller, the saturation of the target color rendered to the pixel on the screen image is further away from the preset saturation, so that the pixel with an overhang angle greater than the overhang angle parameter forms a gradient color. The saturation (i.e., purity) of the target color represents the ratio between the saturation of the target color and the maximum saturation of the target color, ranging from 0% to 100%; the higher the saturation, the darker the target color, and conversely, the lower the saturation, the lighter the target color.

[0098] The preset saturation can be a high saturation, such as 90% or 80%, which is not limited here; at this time, if the overhang angle of the pixel is larger, the target color of the pixel rendered on the screen image is darker, and if the overhang angle of the pixel is smaller, the target color of the pixel rendered on the screen image is lighter. The preset saturation can also be a low saturation, such as 10% or 20%, which is not limited here; at this time, if the overhang angle of the pixel is larger, the target color of the pixel rendered on the screen image is lighter, and if the overhang angle of the pixel is smaller, the target color of the pixel rendered on the screen image is darker.

[0099] For example, the angle θ between the normal vector of the pixel and the gravity direction in three-dimensional space can be used to calculate the final color of the pixel, that is, final color = color*(1-cosθ). At this time, the darker the color, the better the printing effect of the 3D model after adding support to the point. The gradient color allows users to quickly select the point to add support.

[0100] It can be understood that in the embodiment of the present application, when the vertex data of the 3D model in the screen image changes, the hardware circuit of the GPU shader can call the various shading programs (vertex shader, geometry shader and fragment shader) in the GPU shader in parallel, assemble the model facets of the 3D model based on the vertex transformation data, obtain the overhang angle of the pixel based on the normal vector of the pixel in the assembled model facet, and render the pixel with the corresponding color based on the overhang angle of the pixel; the processing speed is fast, which can effectively improve the rendering speed of the 3D model.

[0101] The present application also provides a GPU shader, such as Figure 6 As shown, the details are as follows:

[0102] An acquisition unit 601 is used to acquire vertex change data corresponding to the 3D model when vertex data of the 3D model in the screen image changes;

[0103] An assembling unit 602, configured to assemble model patches of the 3D model based on the vertex change data and the vertex data that has not changed in the 3D model;

[0104] A determination unit 603 is used to determine a normal vector of a pixel in a model patch of the 3D model, and obtain an overhang angle of the pixel in a three-dimensional space based on the normal vector of the pixel;

[0105] The rendering unit 604 is used to render the corresponding color of the pixel in the screen image based on the overhang angle of the pixel, so as to determine the pixel in the 3D model to which support can be added based on the color of the pixel on the screen image.

[0106] In some embodiments of the present application, the GPU shader includes a vertex shader; the acquisition unit 601 is specifically used to obtain vertex change data corresponding to the vertex if a vertex with changed coordinates is generated during the process of the vertex shader performing matrix transformation on the vertex data of the 3D model.

[0107] In some embodiments of the present application, the GPU shader includes: a geometry shader; the determination unit 603 is specifically used to determine the normal vector of the model patch of the 3D model based on the geometry shader; rasterize the model patch to obtain pixel fragments corresponding to the model patch; interpolate the normal vector of the model patch based on the coordinate data of the pixel fragment to obtain the normal vector of the pixel fragment, and then obtain the normal vector of the pixel corresponding to the pixel fragment.

[0108] In some embodiments of the present application, the GPU shader includes: a fragment shader; the determination unit 603 is specifically used to rasterize the model patch to obtain a pixel fragment corresponding to the model patch; in the fragment shader, a normal vector of any pixel in the pixel fragment is determined based on a similarity between any pixel and an adjacent pixel,

[0109] In some embodiments of the present application, the determination unit 603 is specifically used to obtain coordinate difference data between any pixel and the adjacent pixel; determine a first derivative vector of the coordinate difference data in a first direction and a second derivative vector in a second direction; the first direction and the second direction are located on a horizontal plane perpendicular to the direction of gravity in the three-dimensional space, and the first direction is perpendicular to the second direction; cross-multiply the first derivative vector and the second derivative vector to obtain a normal vector of any pixel.

[0110] The rendering unit 604 is specifically used to obtain an overhang angle parameter, where the overhang angle parameter is used to indicate the overhang angle of the added support, and the overhang angle parameter is adjusted based on the angle adjustment instruction; if the overhang angle of the pixel is less than or equal to the overhang angle parameter, the pixel is dyed as a preset model rendering color in the screen image; if the overhang angle of the pixel is greater than the overhang angle parameter, the pixel is rendered as a target color in the screen image, and the target color is other colors that are different from the preset model rendering color.

[0111] The present application also provides a 3D model rendering device 700, such as Figure 7 As shown, the rendering device 700 of the embodiment of the present application may include one or more GPU shaders 701 and a memory 702 , in which one or more application programs or data are stored.

[0112] The memory 702 may be a volatile storage or a persistent storage. The program stored in the memory 702 may include one or more modules, each of which may include a series of instruction operations in the electronic device. Furthermore, the GPU shader 701 may be configured to communicate with the memory 702 and execute a series of instruction operations in the memory 702 on the rendering device 700.

[0113] The rendering device 700 may also include one or more power supplies 705, one or more wired or wireless network interfaces 704, one or more input and output interfaces 703, and / or one or more operating systems, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0114] The GPU shader 701 can execute the operations performed by the aforementioned first aspect or any specific method embodiment of the first aspect, and the details will not be repeated here.

[0115] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium includes instructions. When the instructions are executed on a computer, the computer executes the method described above.

[0116] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0117] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0118] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0119] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0120] If the integrated unit is implemented in the form of 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 the present application is essentially 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.

Claims

1. A 3D model rendering method, applied to a GPU shader, characterized in that: include: When vertex data of the 3D model in the screen image changes, acquiring vertex change data corresponding to the 3D model; Assembling model patches of the 3D model based on the vertex change data and the vertex data that has not changed in the 3D model; Determine a normal vector of a pixel in a model patch of the 3D model, and obtain an overhang angle of the pixel in three-dimensional space based on the normal vector of the pixel; Based on the overhang angle of the pixel, a corresponding color is rendered for the pixel in the screen image, so as to determine the pixel in the 3D model to which support can be added based on the color of the pixel on the screen image.

2. The rendering method according to claim 1, characterized in that: The GPU shader includes a vertex shader; The acquiring of vertex change data corresponding to the 3D model comprises: In the process of the vertex shader performing matrix transformation on the vertex data of the 3D model, if a vertex with a changed coordinate is generated, the vertex change data corresponding to the vertex is obtained.

3. The rendering method according to claim 1, characterized in that: The GPU shader includes: a geometry shader; Determining the normal vector of a pixel in a model patch of the 3D model comprises: Determine a normal vector of a model patch of the 3D model based on the geometry shader; Rasterizing the model surface to obtain pixel fragments corresponding to the model surface; The normal vector of the model face patch is interpolated based on the coordinate data of the pixel fragment to obtain the normal vector of the pixel fragment, and then the normal vector of the pixel corresponding to the pixel fragment is obtained.

4. The rendering method according to claim 1, characterized in that: The GPU shader includes: a fragment shader; Determining the normal vector of a pixel in a model patch of the 3D model comprises: Rasterizing the model surface to obtain pixel fragments corresponding to the model surface; In the fragment shader, a normal vector of any pixel in the pixel fragment is determined based on a similarity between the pixel and adjacent pixels.

5. The rendering method according to claim 4, characterized in that: The determining of the normal vector of any pixel based on the similarity between any pixel and adjacent pixels in the pixel segment comprises: Obtaining coordinate difference data between any one pixel and the adjacent pixel; Determine a first derivative vector of the coordinate difference data in a first direction and a second derivative vector in a second direction; the first direction and the second direction are located on a horizontal plane perpendicular to the gravity direction in the three-dimensional space, and the first direction is perpendicular to the second direction; The first derivative vector is cross-multiplied with the second derivative vector to obtain a normal vector of any pixel.

6. The rendering method according to claim 1, characterized in that: The obtaining the overhang angle of the pixel in the three-dimensional space based on the normal vector of the pixel comprises: Acquire a first angle between a normal vector of the pixel in the 3D model and a gravity vector in the three-dimensional space, and a second angle between a normal vector of an adjacent pixel of the pixel in the 3D model and a gravity vector in the three-dimensional space; The first angle and the second angle are summed and then divided by the total number of the pixel and the adjacent pixels to obtain an overhang angle of the pixel in three-dimensional space.

7. The rendering method according to claim 1, characterized in that: The rendering of a corresponding color for the pixel in the screen image based on the overhang angle of the pixel includes: Acquire an overhang angle parameter, where the overhang angle parameter is used to indicate an overhang angle of the added support, and the overhang angle parameter is adjusted based on the angle adjustment instruction; If the overhang angle of the pixel is less than or equal to the overhang angle parameter, dyeing the pixel in the screen image into a preset model rendering color; If the overhang angle of the pixel is greater than the overhang angle parameter, the pixel is rendered as a target color in the screen image, and the target color is another color that is different from the preset model rendering color.

8. The rendering method according to claim 7, characterized in that: Rendering the pixel in the screen image as a target color comprises: If the overhang angle of the pixel is larger, the saturation of the target color rendered to the pixel in the screen image is closer to the preset saturation; If the overhang angle of the pixel is smaller, the saturation of the target color rendered to the pixel in the screen image is further away from the preset saturation, so that the pixels with an overhang angle greater than the overhang angle parameter form a gradient color.

9. A 3D model rendering device, characterized in that: include: GPU shaders and memory; The memory is used to store executable instructions of the GPU shader; Wherein, the GPU shader is configured to execute the rendering method described in any one of claims 1-8 by executing the executable instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises instructions, and when the instructions are executed on a computer, the computer is caused to perform the method according to any one of claims 1 to 8.