Method, system, electronic device and storage medium for optimizing rendering of stroke effect
By grouping and converting the normals of the model vertex, the problem of high-frequency normal stroke fracture is solved, and the continuous stroke effect of the object outline on the mobile platform is achieved, ensuring both performance and artistic effect.
Patent Information
- Application Number
- CN202011085264.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-12
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2040-10-12
AI Technical Summary
In the prior art, when rendering the object outline, the problem of stroke fracture caused by high-frequency normals has not been effectively solved, especially in mobile phones with limited hardware resources, which is difficult to achieve satisfactory stroke effects.
通过遍历模型的所有顶点,对相同位置的顶点法线分组并求和归一化,转换光滑法线数据范围,构建转换矩阵将光滑法线从模型空间转换到切空间、相机空间和NDC空间, Drawing the stroke color solves the problem of high-frequency normal stroke breakage.
It realizes the continuous effect of high-frequency normal strokes on the object contour on the mobile platform, ensuring performance while rendering excellent stroke effects in real time.
Smart Images

Figure CN112270726B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a method, system, electronic device and storage medium for optimizing rendering of stroke effects. Background Art
[0002] With the growth of the ACG player group, ACG-style mobile games are becoming increasingly popular. One of the common characteristics of this type of game screen is that objects are all line-stroked, that is, the outline is drawn on the edge of the object. On mobile phones with limited hardware resources, it is necessary not only to achieve the edge detection and tracing effect of objects, but also to take into account performance at the same time.
[0003] In the related technology, the stroke rendering based on the observation angle and the surface normal of the object can quickly find the contour line through the dot product result of the surface normal and the camera direction. However, the effect is very limited, and it is difficult to obtain a satisfactory stroke effect in commercial games; the contour rendering based on image processing performs stroke processing in the post-processing stage of rendering, but cannot detect contour lines with very small changes in depth and normal, such as a piece of paper on a table; the contour rendering based on procedural geometry is only suitable for spherical objects with low-frequency surface normals, and is not suitable for angular objects with high-frequency surface normals, such as guns and cannons.
[0004] Currently, in the related technology, when performing stroke rendering on the outline of an object, there is no effective solution to the problem of stroke breakage caused by high-frequency normal stroke. Summary of the invention
[0005] The embodiments of the present application provide a method, system, electronic device and storage medium for optimizing the rendering of stroke effects, which at least solve the problem of stroke breakage caused by high-frequency normal strokes when performing stroke rendering on the outline of an object in the related art.
[0006] In a first aspect, an embodiment of the present application provides a method for optimizing rendering of a stroke effect, the method comprising:
[0007] Traversing all vertices of the model, grouping the normals of the vertices at the same position, and summing and normalizing the normals of the vertices in the same group to obtain a smooth normal;
[0008] Converting the space of the smooth normal data range to obtain a smooth normal in the model space;
[0009] Traversing the vertices, constructing a transformation matrix, transforming the smooth normal from the model space to the tangent space, and saving the smooth normal;
[0010] Take out the smooth normal from uv4 and convert the space of the smooth normal data range;
[0011] The smooth normal is converted from the tangent space to the camera space by means of the constructed transformation matrix, and the vertex is converted from the model space to the camera space, so as to obtain the smooth normal and vertex in the camera space;
[0012] The smooth normal and the vertex are converted to NDC space, and the stroke color is drawn.
[0013] In some embodiments, converting the smooth normal from the model space to the tangent space and saving the smooth normal comprises:
[0014] The smooth normal of the tangent space is saved in vertex uv2 and saved as a new mesh.
[0015] In some embodiments, constructing the transformation matrix includes:
[0016] The tangent and normal of the vertex are taken out to construct the TBN matrix.
[0017] In some embodiments, after converting the smooth normal and the vertex into NDC space, the method includes:
[0018] The smooth normals are scaled by the aspect ratio of the mobile display screen, and the vertices are stretched outward by the NDC normals.
[0019] In a second aspect, an embodiment of the present application provides a system for optimizing rendering of a stroke effect, the system comprising: a server;
[0020] The server traverses all vertices of the model, groups the normals of the vertices at the same position, and normalizes the sum of the normals of the vertices in the same group to obtain a smooth normal;
[0021] The server converts the space of the smooth normal data range to obtain a smooth normal in the model space;
[0022] The server traverses the vertices, constructs a transformation matrix, transforms the smooth normal from the model space to the tangent space, and saves the smooth normal;
[0023] The server extracts the smooth normal from uv4 and converts the space of the smooth normal data range;
[0024] The server transforms the smooth normal from the tangent space to the camera space through the constructed transformation matrix, and transforms the vertex from the model space to the camera space, to obtain the smooth normal and vertex in the camera space;
[0025] The server converts the smooth normal and the vertex into NDC space and draws the stroke color.
[0026] In some embodiments, the server converts the smooth normal from the model space to the tangent space, and saves the smooth normal, comprising:
[0027] The server saves the smooth normal of the tangent space into vertex uv2 as a new mesh.
[0028] In some embodiments, constructing the transformation matrix includes:
[0029] The server extracts the tangent and normal of the vertex and constructs a TBN matrix.
[0030] In some embodiments, after converting the smooth normals and the vertices to NDC space,
[0031] The server scales the smooth normals by the aspect ratio of the mobile display screen, and the vertices are stretched outward by the NDC normals.
[0032] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute any of the above-mentioned methods for optimizing the rendering of the stroke effect.
[0033] In a fourth aspect, an embodiment of the present application provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute any of the above-mentioned methods for optimizing the rendering of the stroke effect when running.
[0034] Compared with the related art, the embodiment of the present application provides a method for optimizing the rendering of a stroke effect, which traverses all vertices of the model, groups the normals of vertices at the same position, and normalizes the sum of the normals of the vertices in the same group to obtain a smooth normal; converts the space of the smooth normal data range to obtain a smooth normal in the model space; then traverses the vertices, constructs a transformation matrix, converts the smooth normal from the model space to the tangent space, and saves the smooth normal; then takes the smooth normal from uv4, and converts the space of the smooth normal data range; converts the smooth normal from the tangent space to the camera space through the constructed transformation matrix, and converts the vertices from the model space to the camera space to obtain smooth normals and vertices in the camera space; finally, converts the smooth normal and the vertices to the NDC space, and draws the stroke color, which solves the problem of stroke breakage when high-frequency normal strokes are used in the case of stroke rendering of the object contour, and can render excellent stroke effects in real time while ensuring performance on mobile platforms. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0036] Figure 1 It is a schematic diagram of an application environment of a rendering optimization method for stroke effects according to an embodiment of the present application;
[0037] Figure 2 is a flowchart of a rendering optimization method for stroke effects according to an embodiment of the present application;
[0038] Figure 3 It is a schematic diagram of the effect of object stroke rendering in the related technology;
[0039] Figure 4 is a schematic diagram of the effect of object stroke rendering according to an embodiment of the present application;
[0040] Figure 5 is a structural block diagram of a rendering optimization system for stroke effects according to an embodiment of the present application;
[0041] Figure 6 It is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for ordinary technicians in the field related to the contents disclosed in the present application, some changes such as design, manufacturing or production based on the technical contents disclosed in the present application are only conventional technical means, and should not be understood as insufficient contents disclosed in the present application.
[0043] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to greater than or equal to two. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, "A and / or B" can represent: A exists alone, A and B exist at the same time, and B exists alone. The terms "first", "second", "third" and the like involved in the present application are merely used to distinguish similar objects and do not represent a specific ordering of the objects.
[0044] The rendering optimization method of the stroke effect provided in this application can be applied to Figure 1 In the application environment shown, Figure 1 is a schematic diagram of an application environment of a method for optimizing rendering of a stroke effect according to an embodiment of the present application, such as Figure 1 As shown, the system of the application environment includes a server 10 and a mobile platform 11, wherein the server 10 traverses all vertices of the model, groups the normals of the vertices at the same position, and normalizes the sum of the normals of the vertices in the same group to obtain a smooth normal; converts the space of the smooth normal data range to obtain a smooth normal in the model space; then traverses the vertices, constructs a transformation matrix, converts the smooth normal from the model space to the tangent space, and saves the smooth normal; then takes the smooth normal from uv4, and converts the space of the smooth normal data range; converts the smooth normal from the tangent space to the camera space through the constructed transformation matrix, and converts the vertices from the model space to the camera space to obtain smooth normals and vertices in the camera space; finally, converts the smooth normal and the vertex to the NDC space, draws the stroke color, and applies it to the object rendering of the mobile platform 11, which solves the problem of stroke breakage when high-frequency normal strokes are used in the case of stroke rendering of the object contour. While ensuring performance on the mobile platform, excellent stroke effects can be rendered in real time at high-frequency normals.
[0045] This embodiment provides a method for optimizing rendering of a stroke effect. Figure 2is a flowchart of a rendering optimization method for stroke effects according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:
[0046] Step S201, traverse all vertices of the model, group the normals of the vertices at the same position, and sum and normalize the normals of the vertices in the same group to obtain a smooth normal. Optionally, this embodiment traverses the spatial coordinates of all vertices of the model, groups the normals of the vertices at the same position, and sums and normalizes the normals of the vertices in the same group to obtain a smooth normal. The smooth normal is obtained by summing and normalizing the model normals, and the smooth normal is used as the basis for subsequent real-time rendering, which can render an excellent stroke effect.
[0047] Step S202, converting the space of the smooth normal data range to obtain the smooth normal in the model space, wherein the model space is also called the object space or the local space, each model has its own independent coordinate space, when it moves or rotates, the model space will also move and rotate. Optionally, this embodiment converts the space of the smooth normal data range, that is, converts the data range of the smooth normal from the -1,1 space to the 0,1 space, to obtain the smooth normal in the model space;
[0048] Step S203, traverse the vertices, construct a transformation matrix, convert the smooth normal from the model space to the tangent space, and save the smooth normal. Optionally, this embodiment traverses the spatial coordinates of the vertices, constructs a transformation matrix, converts the smooth normal from the model space to the tangent space, and saves the smooth normal in the tangent space. The smooth normal obtained after the offline preprocessing of the model normal is saved and applied to the real-time rendering stage to achieve a better stroke art effect.
[0049] Step S204, extract the smooth normal from uv4, and convert the space of the smooth normal data range, where uv is the abbreviation of u, v texture map coordinates, which are the coordinates of the image in the horizontal and vertical directions of the display, that is, the u-th pixel / image width in the horizontal direction and the v-th pixel / image height in the vertical direction, and the value is generally 0-1, which is similar to the x, y, z axis of the spatial model, and it defines the position information of each point on the image. Optionally, this embodiment extracts the smooth normal from uv4 and converts the data range of the smooth normal from the 0,1 space to the -1,1 space;
[0050] Step S205, converting the smooth normal from the tangent space to the camera space through the constructed transformation matrix, and converting the vertex from the model space to the camera space, to obtain the smooth normal and vertex in the camera space. Optionally, in this embodiment, the smooth normal is converted from the tangent space to the camera space through the constructed transformation matrix, and the vertex is converted from the model space to the camera space, to obtain the smooth normal and vertex in the camera space;
[0051] Step S206, converting the smooth normals and vertices to NDC space, drawing the stroke color. Optionally, this embodiment converts the smooth normals and vertices of the camera space to NDC space, draws the stroke color, and finally applies it to the object rendering of the mobile platform 11, which can render an excellent stroke effect.
[0052] Through the above steps S201 to S206, compared with the prior art, the stroke rendering based on the observation angle and the surface normal of the object quickly finds the contour line through the dot product result of the surface normal and the camera direction, but the effect is very limited, and it is difficult to obtain a satisfactory stroke effect in commercial games; the contour rendering based on image processing performs stroke processing in the post-processing stage of rendering, but cannot detect contours with very small changes in depth and normal, such as a piece of paper on a table; and the procedural geometry contour rendering is only suitable for spherical objects with low surface normal frequency, and is not suitable for angular objects with high surface normal frequency. This embodiment adopts an optimized stroke rendering method. The server 10 traverses all vertices of the model, groups the normals of the vertices at the same position, and normalizes the sum of the normals of the vertices in the same group to obtain a smooth normal; converts the space of the smooth normal data range to obtain a smooth normal in the model space; then traverses the vertices, constructs a transformation matrix, converts the smooth normal from the model space to the tangent space, and saves the smooth normal; then takes the smooth normal from uv4, and converts the space of the smooth normal data range; converts the smooth normal from the tangent space to the camera space through the constructed transformation matrix, and converts the vertices from the model space to the camera space to obtain the smooth normal and vertices in the camera space; finally, converts the smooth normal and the vertices to the NDC space, draws the stroke color, and applies it to the object rendering of the mobile platform 11. Figure 3 This is a schematic diagram of the effect of object stroke rendering in related technologies, such as Figure 3 As shown, Figure 4 is a schematic diagram of the effect of object stroke rendering according to an embodiment of the present application, such as Figure 4 As shown, through Figure 3 and Figure 4 It can be found that the stroke effect obtained after the object stroke rendering is performed using the rendering optimization method of the present application is significantly better, which solves the problem of stroke breakage in high-frequency normal strokes when the object contour is stroked, and can ensure performance on mobile platforms while also rendering excellent stroke effects in real time.
[0053] In some of the embodiments, converting the smooth normal from the model space to the tangent space and saving the smooth normal includes: saving the smooth normal of the tangent space into the vertex uv2 and saving it as a new mesh, wherein mesh is a component in Unity, called a mesh component, i.e., the mesh of the model, and the main attributes of the mesh include vertex coordinates (vertex), normals (normal) and texture coordinates (uv), wherein the vertex coordinate array stores the spatial coordinates of each vertex of the mesh, the normal array stores the normal of each vertex of the mesh, and the size corresponds to the vertex coordinates, and the texture coordinates define the position information of each point on the image, that is, each point on the image is accurately corresponded to the surface of the model object. Optionally, this embodiment performs offline preprocessing on the model normal, saves the smooth normal obtained in the tangent space into the vertex uv2, and saves it as a new mesh, so that in the real-time rendering stage of the object, a better stroke effect can be rendered, showing an excellent artistic effect.
[0054] In some embodiments, constructing a transformation matrix includes: taking out the tangent and normal of the vertex, constructing a TBN matrix, wherein the TBN matrix is a matrix that transforms a point from the texture space to the object space, for example, the input is a texture r, g, b, which respectively represent the components on the x, y, and z axes in the texture coordinate system, and the TBN is a one-to-one correspondence between the xyz coordinates, and the final output is the normal vector in the object coordinate system, wherein, when using techniques such as normal mapping, the most critical matrix is the TBN matrix, which is used to convert the normal vector stored in the texture space to the model space. Optionally, this embodiment constructs a TBN matrix by taking out the tangent and normal of the vertex uv2, which is used to convert the smooth normal and vertex coordinates.
[0055] In some of the embodiments, after the smooth normals and vertices are converted to NDC space, the smooth normals are scaled by the aspect ratio of the mobile display screen, and the vertices are stretched outward through the NDC normal normal phase to complete the drawing of the stroke color, where NDC is the normalized device coordinate, that is, the coordinate relative to the screen. Optionally, in this embodiment, after the smooth normals and vertices are converted to NDC space, the smooth normals are scaled by the aspect ratio of the mobile display screen, and the vertices are stretched outward through the NDC normal normal phase to draw the stroke color, which can ensure performance on the mobile platform while also rendering excellent stroke effects in real time.
[0056] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0057] This embodiment also provides a system for rendering optimization of stroke effects, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the terms "module", "unit", "subunit", etc. can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0058] Figure 5 is a structural block diagram of a rendering optimization system for stroke effects according to an embodiment of the present application, such as Figure 5 As shown, the system includes a normal preprocessing module 51, a normal and vertex space conversion module 52 and a stroke module 53:
[0059] The normal preprocessing module 51 is used for the server to traverse all vertices of the model, group the normals of the vertices at the same position, and sum and normalize the normals of the vertices in the same group to obtain a smooth normal, convert the space of the smooth normal data range, obtain the smooth normal in the model space, traverse the vertices, build a conversion matrix, convert the smooth normal from the model space to the tangent space, and save the smooth normal; the normal and vertex space conversion module 52 is used for the server to extract the smooth normal from UV4, and convert the space of the smooth normal data range,
[0060] The smooth normal is converted from the tangent space to the camera space through the constructed transformation matrix, and the vertex is converted from the model space to the camera space to obtain the smooth normal and vertex in the camera space; the stroke module 53 is used for the server to convert the smooth normal and vertex to the NDC space and draw the stroke color.
[0061] Through the above system, the normal preprocessing module 51 obtains the smooth normal by summing and normalizing the model normal, saves the obtained smooth normal, and applies it to the real-time rendering stage, which can achieve better stroke art effect; the normal and vertex space conversion module 52 takes out the smooth normal from uv4, and converts the space of the smooth normal data range, and then converts the smooth normal from the tangent space to the camera space through the constructed conversion matrix, and converts the vertex from the model space to the camera space, and obtains the smooth normal and vertex in the camera space; the stroke module 53 converts the smooth normal and vertex in the camera space to the NDC space, draws the stroke color, and finally applies it to the object rendering of the mobile platform, which can render an excellent stroke effect. The whole system solves the problem of stroke breakage of high-frequency normal strokes when the outline of the object is stroked and rendered, and can render excellent stroke effects in real time while ensuring performance on the mobile platform.
[0062] In some embodiments, in the normal preprocessing module 51, the server converts the smooth normal from the model space to the tangent space, and saves the smooth normal, including: the server saves the smooth normal of the tangent space into the vertex uv2, and saves it as a new mesh, wherein mesh is a component in Unity, called a mesh component, i.e., the mesh of the model, and the main attributes of the mesh include vertex coordinates (vertex), normals (normal) and texture coordinates (uv), wherein the vertex coordinate array stores the spatial coordinates of each vertex of the mesh, the normal array stores the normal of each vertex of the mesh, and the size corresponds to the vertex coordinates, and the texture coordinates define the position information of each point on the image, that is, each point on the image is accurately corresponding to the surface of the model object. Optionally, this embodiment performs offline preprocessing on the model normal, saves the smooth normal obtained in the tangent space into the vertex uv2, and saves it as a new mesh, so that in the real-time rendering stage of the object, a better stroke effect can be rendered, showing an excellent artistic effect.
[0063] In some embodiments, the server constructs a transformation matrix including: the server takes out the tangent and normal of the vertex and constructs a TBN matrix, wherein the TBN matrix is a matrix that transforms a point from the texture space to the object space. For example, the input is r, g, and b of a texture, which respectively represent the components on the x, y, and z axes in the texture coordinate system, and the TBN corresponds to the coordinates of xyz one by one, and the final output is the normal vector in the object coordinate system. When using technologies such as normal mapping, the most critical matrix is the TBN matrix, which is used to convert the normal vector stored in the texture space to the model space. Optionally, this embodiment constructs a TBN matrix by taking out the tangent and normal of the vertex uv2, which is used to convert the smooth normal and vertex coordinates.
[0064] In some of the embodiments, the stroke module 53 is also used for the server to scale the smooth normals and vertices by the aspect ratio of the mobile display screen after converting the smooth normals and vertices to the NDC space, and the vertices are stretched outward by the NDC normal phase to complete the drawing of the stroke color, wherein NDC is the normalized device coordinate, that is, the coordinate relative to the screen. Optionally, in this embodiment, after converting the smooth normals and vertices to the NDC space, the smooth normals are scaled by the aspect ratio of the mobile display screen, and the vertices are stretched outward by the NDC normal phase to draw the stroke color, which can ensure performance on the mobile platform while also rendering excellent stroke effects in real time.
[0065] The present invention is described in detail below in conjunction with application scenarios.
[0066] The process steps of the technical solution for optimizing the rendering of the stroke effect in this embodiment include:
[0067] 1. Overall rendering process:
[0068] S1, draw the first Pass, backface culling and rendering the object itself;
[0069] S2, draw the second Pass, cull the front face and render the stroke;
[0070] 2. Offline preprocessing stage of stroke:
[0071] S1, traverse all vertices of the model, group the vertex normals at the same position, sum and normalize the vertex normals in the same group to obtain a smooth normal;
[0072] S2, converts the normal data range from -1,1 to 0,1 space. The smooth normal obtained is in the model space.
[0073] S3, traverse the vertices, construct the TBN matrix, convert the smooth normal from the model space to the tangent space, save the smooth normal of the tangent space to the vertex uv2, and save it as a new mesh;
[0074] 3. Stroke rendering logic:
[0075] S1, extract the normal and tangent of the vertex and construct the TBN matrix;
[0076] S2, takes the smooth normal from uv4 and converts it from 0,1 space to -1,1 space;
[0077] S3, transform the smooth normal of the tangent space to the camera space through the TBN matrix, and transform the vertex coordinates from the model space to the camera space;
[0078] S4 converts the smoothed normal to NDC space and scales it by the screen aspect ratio, stretches the vertices outward through the NDC normal, and draws the stroke color.
[0079] Through the above system, the improved effect of the optimized stroke algorithm is achieved, and a satisfactory stroke effect can be obtained at the position of the high-frequency normal.
[0080] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0081] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0082] In addition, in combination with the method for optimizing the rendering of the stroke effect in the above embodiment, the embodiment of the present application can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the methods for optimizing the rendering of the stroke effect in the above embodiment is implemented.
[0083] In one embodiment, Figure 6 is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application, such as Figure 6 As shown, an electronic device is provided, which may be a server, and its internal structure diagram may be as shown in Figure 6 As shown. The electronic device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the electronic device is used to store data. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for optimizing rendering of a stroke effect is implemented.
[0084] Those skilled in the art will understand that Figure 6 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0085] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0086] Those skilled in the art should understand that the technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0087] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A method for optimizing rendering of a stroke effect, characterized in that: The method comprises: Traversing all vertices of the model, grouping the normals of the vertices at the same position, and summing and normalizing the normals of the vertices in the same group to obtain a smooth normal; Convert the space of the smooth normal data range from -1,1 space to 0,1 space to obtain a smooth normal in the model space; Traversing the vertices, constructing a transformation matrix, transforming the smooth normal from the model space to the tangent space, and saving the smooth normal; Take the smooth normal from uv4, and convert the space of the smooth normal data range from 0,1 space to -1,1 space, where uv4 represents the vertex texture coordinates in the mesh component, that is, the width of the u-th pixel in the horizontal direction and the height of the v-th pixel in the vertical direction; The smooth normal is converted from the tangent space to the camera space by means of the constructed transformation matrix, and the vertex is converted from the model space to the camera space, so as to obtain the smooth normal and vertex in the camera space; The smooth normal and the vertex are converted to NDC space, and the stroke color is drawn.
2. The method according to claim 1, characterized in that The step of converting the smooth normal from the model space to the tangent space and saving the smooth normal comprises: Save the smooth normal of the cut space to vertex uv2 and save it as a new mesh, where uv2 represents the vertex texture coordinates in the mesh component, that is, the u-th pixel width in the horizontal direction and the v-th pixel height in the vertical direction. Mesh is a mesh component in Unity, and its main properties include the spatial coordinates of the vertex, the normal of the vertex, and the texture coordinates of the vertex.
3. The method according to claim 1 or 2, characterized in that: The constructing of the conversion matrix comprises: The tangent and normal of the vertex are taken out to construct the TBN matrix.
4. The method according to claim 1, characterized in that After converting the smooth normal and the vertex into NDC space, the method comprises: The smooth normals are scaled by the aspect ratio of the mobile display screen, and the vertices are stretched outward by the NDC normals, where NDC is normalized device coordinates.
5. A system for optimizing rendering of stroke effects, characterized in that: The system comprises: a server; The server traverses all vertices of the model, groups the normals of the vertices at the same position, and normalizes the sum of the normals of the vertices in the same group to obtain a smooth normal; The server converts the space of the smooth normal data range from -1,1 space to 0,1 space to obtain a smooth normal in the model space; The server traverses the vertices, constructs a transformation matrix, transforms the smooth normal from the model space to the tangent space, and saves the smooth normal; The server extracts the smooth normal from uv4 and converts the space of the smooth normal data range from 0,1 space to -1,1 space, where uv4 represents the vertex texture coordinates in the mesh component, that is, the width of the u-th pixel in the horizontal direction and the height of the v-th pixel in the vertical direction; The server transforms the smooth normal from the tangent space to the camera space through the constructed transformation matrix, and transforms the vertex from the model space to the camera space, to obtain the smooth normal and vertex in the camera space; The server converts the smooth normal and the vertex into NDC space and draws the stroke color.
6. The system according to claim 5, characterized in that The server converts the smooth normal from the model space to the tangent space, and saves the smooth normal, including: The server saves the smooth normal of the cut space into vertex uv2 as a new mesh, where uv2 represents the vertex texture coordinates in the mesh component, i.e., the u-th pixel width in the horizontal direction and the v-th pixel height in the vertical direction. Mesh is a mesh component in Unity, and its main attributes include the spatial coordinates of the vertex, the normal of the vertex, and the texture coordinates of the vertex.
7. The system according to claim 5 or 6, characterized in that: The constructing of the conversion matrix comprises: The server extracts the tangent and normal of the vertex and constructs a TBN matrix.
8. The system according to claim 5, characterized in that After converting the smooth normal and the vertex into NDC space, The server scales the smooth normals by the aspect ratio of the mobile display screen, and the vertices are stretched outward by NDC normals, where NDC is normalized device coordinates.
9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the method for optimizing rendering of a stroke effect according to any one of claims 1 to 4.
10. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method for optimizing rendering of a stroke effect according to any one of claims 1 to 4 when running.
Citation Information
Patent Citations
Shadow rendering method and device, electronic equipment and storage medium
CN111476877A
System and method for bump mapping setup
US7843463B1