Virtual model processing method and device, computer device, and storage medium
Patent Information
- Application Number
- CN202410083500.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-19
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2044-01-19
AI Technical Summary
然而,现有技术中为游戏人物或游戏物体设置边缘效果的方式,对终端设备的计算量要求比较大,导致终端设备的性能不理想;并且,需要花费大量时间和人力资源进行边缘效果的制作,导致游戏人物或游戏物体边缘的边缘效果的制作效率不高
[0017]本申请实施例提供一种虚拟模型的处理方法、装置、计算机设备及存储介质,通过获取预设虚拟模型中各模型顶点的顶点法线、在屏幕空间对应的屏幕像素点的像素点坐标;然后,对各像素点坐标进行计算,得到各模型顶点对应的梯度偏移值;接着,基于预设轮廓点对应的梯度偏移值阈值、以及各模型顶点对应的梯度偏移值,筛选出所述预设虚拟模型的边缘轮廓顶点;最后,基于各边缘轮廓顶点对应的轮廓像素点,对预设纹理贴图进行采样处理,以将所述预设纹理贴图中的纹理渲染到轮廓像素点上,得到目标虚拟模型。在本申请实施例中,通过计算得到虚拟模型各模型顶点的顶点法线,在屏幕空间对应的梯度偏移值,根据梯度偏移值阈值以及各模型顶点对应的梯度偏移值,从虚拟模型中筛选出该虚拟模型的边缘轮廓顶点,从而确定虚拟模型的模型边缘轮廓,并且,基于预设纹理贴图对边缘轮廓顶点设置目标纹理效果,从而为虚拟模型的模型边缘轮廓设置目标纹理效果,可以节省时间和人力资源,提高模型边缘轮廓的纹理效果的制作效率。
Smart Images

Figure CN117899490B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer image processing technology, specifically to a method, apparatus, computer device, and storage medium for processing virtual models. Background Technology
[0002] With the continuous development of computer communication technology and the widespread use of terminals such as smartphones, tablets, and laptops, terminals are becoming increasingly diversified and personalized, becoming indispensable in people's lives and work. To satisfy people's pursuit of spiritual enrichment, entertainment games that can be played on these terminals have emerged, resulting in a growing number of such games. Terminal games have become an indispensable form of entertainment. To provide users with a better gaming experience, many terminal games are often based on real-world characters and scenes. Therefore, when designing games, the implementation of game scenes aims to be as close to reality as possible.
[0003] In practical game design, to make games more vivid and interesting, edge effects are often added to the edges of game characters or objects to highlight them. Current mobile games employ various methods for presenting edge lighting effects. One common approach is to use Fresnel geometry or algorithms that calculate a smooth edge lighting effect based on the dot product of the lighting direction, normal, and view distance. Another method utilizes post-processing to calculate ambient occlusion, screen space depth, and normals to determine object surface information. However, existing methods for setting edge effects for game characters or objects place significant demands on the computational power of the terminal device, leading to less than ideal device performance. Furthermore, the creation of edge effects requires substantial time and manpower, resulting in low efficiency in the production of edge effects for game characters or objects. Summary of the Invention
[0004] This application provides a method, apparatus, computer device, and storage medium for processing virtual models. By calculating the vertex normals of each vertex of the virtual model and the corresponding gradient offset values in screen space, the edge contour vertices of the virtual model are selected from the virtual model based on the gradient offset value threshold and the gradient offset values corresponding to each vertex, thereby determining the edge contour of the virtual model. Furthermore, a target texture effect is set on the edge contour vertices based on a preset texture map, thereby setting the target texture effect for the edge contour of the virtual model. This can save time and manpower and improve the efficiency of creating texture effects for the model edge contour.
[0005] This application provides a method for processing virtual models, including:
[0006] Obtain the vertex normals of each vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space;
[0007] The gradient offset value corresponding to each model vertex is obtained by calculating the coordinates of each pixel.
[0008] Based on the preset gradient offset value threshold corresponding to the contour points and the gradient offset value corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected.
[0009] Based on the contour pixels corresponding to each edge contour vertex, a preset texture map is sampled to render the texture in the preset texture map onto the contour pixels, thereby obtaining the target virtual model.
[0010] Accordingly, embodiments of this application also provide a virtual model processing apparatus, which includes:
[0011] The acquisition unit is used to acquire the vertex normals of each model vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space;
[0012] The calculation unit is used to calculate the coordinates of each pixel point to obtain the gradient offset value corresponding to each model vertex;
[0013] The filtering unit is used to filter out the edge contour vertices of the preset virtual model based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset value corresponding to each model vertex.
[0014] The sampling unit is used to sample the preset texture map based on the contour pixels corresponding to each edge contour vertex, so as to render the texture in the preset texture map onto the contour pixels to obtain the target virtual model.
[0015] Accordingly, this application also provides a computer device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the processing method of the virtual model as described above.
[0016] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the processing method of the virtual model described above.
[0017] This application provides a method, apparatus, computer device, and storage medium for processing virtual models. The method involves acquiring the vertex normals and corresponding screen pixel coordinates of each vertex in a preset virtual model; then calculating the gradient offset value for each vertex; next, filtering out the edge contour vertices of the preset virtual model based on a preset gradient offset threshold and the gradient offset values of each vertex; finally, sampling a preset texture map based on the contour pixels of each edge contour vertex to render the texture from the preset texture map onto the contour pixels, thus obtaining the target virtual model. In this application embodiment, by calculating the vertex normals and corresponding gradient offset values of each vertex in the virtual model, and filtering out the edge contour vertices of the virtual model based on the gradient offset threshold and the gradient offset values of each vertex, the edge contour of the virtual model is determined. Furthermore, by setting target texture effects on the edge contour vertices based on the preset texture map, the target texture effects for the virtual model's edge contours can be set, saving time and manpower and improving the efficiency of creating texture effects for the model's edge contours. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating a virtual model processing method provided in an embodiment of this application.
[0020] Figure 2 This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0021] Figure 3 This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0022] Figure 4 This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0023] Figure 5 This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0024] Figure 6a This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0025] Figure 6b This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0026] Figure 6c This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0027] Figure 7 This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0028] Figure 8 This is a schematic diagram illustrating an application scenario of the virtual model processing method provided in this application embodiment.
[0029] Figure 9 This is a schematic diagram of a virtual model processing device provided in an embodiment of this application.
[0030] Figure 10 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0031] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0032] In existing technologies, to make games more vivid and interesting, edge effects are often added to the edges of game characters or objects to highlight them. The presentation of edge lighting effects in current mobile games varies. One common approach is to use Fresnel or an algorithm that calculates a smooth edge lighting effect based on the dot product of the lighting direction, normal, and view distance. Another approach is to use post-processing to calculate ambient occlusion, screen space depth, and normals to determine the object's surface information. However, existing edge lighting effects created using post-processing require the rendering pipeline's buffer to contain information such as normals, screen space depth, and SSAO, which places high demands on computation and results in unsatisfactory performance. Edge lighting calculated using Fresnel or similar algorithms largely depends on the model's structural details or normal maps, and some areas may have excessively large edge lighting areas, thus requiring significant manpower and time, leading to low efficiency in edge lighting creation. Therefore, the existing methods for setting edge effects for game characters or game objects place a large demand on the computing power of the terminal device, resulting in unsatisfactory performance of the terminal device; moreover, a lot of time and human resources are required to create the edge effects, resulting in low efficiency in creating edge effects for game characters or game objects.
[0033] This application provides a method, apparatus, computer device, and storage medium for processing virtual models. The method involves obtaining the vertex normals of each vertex in a preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space. Then, the gradient offset values corresponding to each model vertex are calculated based on the pixel coordinates. Next, based on a preset threshold for gradient offset values corresponding to contour points and the gradient offset values corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected. Finally, based on the contour pixels corresponding to each edge contour vertex, a preset texture map is sampled to render the texture from the preset texture map onto the contour pixels, thus obtaining the target virtual model.
[0034] This application provides a method, apparatus, computer device, and storage medium for processing virtual models. Specifically, the virtual model processing method of this application can be executed by a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet, laptop, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. The terminal can also include a client, which can be a game application client, a browser client carrying a game program, or an instant messaging client. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0035] For example, when the processing method for the virtual model runs on a terminal, the terminal device stores a game application and uses it to render virtual scenes in the game. The terminal device is used to interact with the user through a graphical user interface (GUI), such as by downloading, installing, and running the game application. The way the terminal device provides the GUI to the user can be varied; for example, it can be rendered and displayed on the terminal device's screen, or presented via holographic projection. For instance, the terminal device can include a touchscreen display and a processor. The touchscreen display is used to present the GUI and receive user input commands generated by the GUI, which includes game visuals. The processor is used to run the game, generate the GUI, respond to input commands, and control the display of the GUI on the touchscreen display.
[0036] For example, when the processing method of the virtual model runs on a server, it can be called cloud gaming. Cloud gaming refers to a gaming method based on cloud computing. In the cloud gaming operating mode, the main body running the game application and the main body displaying the game screen are separated. The storage and execution of the virtual model processing method are completed on the cloud gaming server. The game screen display is completed on the cloud gaming client. The cloud gaming client is mainly used for receiving and sending game data and displaying game screens. For example, the cloud gaming client can be a display device with data transmission capabilities close to the user, such as a mobile terminal, television, computer, PDA, personal digital assistant, etc., but the terminal device for processing game data is the cloud gaming server in the cloud. When playing the game, the user operates the cloud gaming client to send operation commands to the cloud gaming server. The cloud gaming server runs the game according to the operation commands, encodes and compresses the game screen and other data, returns it to the cloud gaming client through the network, and finally, the cloud gaming client decodes and outputs the game screen.
[0037] Please see Figure 1 , Figure 1 This is a schematic diagram of a virtual model processing system provided in an embodiment of this application. The system may include at least one terminal, at least one server, at least one database, and a network. A user's terminal can connect to different game servers via the network. The terminal is any device with computing hardware capable of supporting and executing software products corresponding to the game. Furthermore, when the system includes multiple terminals, multiple servers, and multiple networks, different terminals can connect to each other through different networks and servers. The network can be a wireless network or a wired network, such as a wireless local area network (WLAN), local area network (LAN), cellular network, 2G network, 3G network, 4G network, 5G network, etc. Additionally, different terminals can also connect to other terminals or servers using their own Bluetooth networks or hotspot networks. For example, multiple users can connect online through different terminals via appropriate networks and synchronize with each other to support multiplayer games. Furthermore, the system may include multiple databases coupled to different servers, and can continuously store game environment-related information in the databases while different users are playing multiplayer games online.
[0038] It should be noted that, Figure 1The schematic diagram of the virtual model processing system shown is merely an example. The virtual model processing system and scenario described in this application embodiment are for the purpose of more clearly illustrating the technical solutions of this application embodiment and do not constitute a limitation on the technical solutions provided in this application embodiment. As those skilled in the art will know, with the emergence of new business scenarios, the technical solutions provided in this application embodiment are also applicable to similar technical problems.
[0039] To address the aforementioned problems, this application provides a method, apparatus, computer device, and storage medium for processing virtual models, which can improve the realism of virtual models displayed in games. These will be described in detail below. It should be noted that the order of description of the following embodiments is not intended to limit the preferred order of the embodiments.
[0040] Please see Figure 2 , Figure 2 This is a flowchart illustrating a virtual model processing method provided in an embodiment of this application. The specific process of the virtual model processing method can be shown in steps 101 to 106 below:
[0041] 101. Obtain the vertex normals of each vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space.
[0042] In this embodiment, the vertex normals of each vertex in a preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space can be obtained. Specifically, the virtual model is a model located in world coordinates, and the pixel coordinates of the screen pixels corresponding to the vertex normals of the virtual model in screen space can be calculated.
[0043] World coordinates, in general, refer to a coordinate system in three-dimensional space used to describe the position and orientation of virtual objects. It is an absolute coordinate system that does not change with the observer's perspective. The origin of the world coordinate system can be any location; game developers typically choose a point that is convenient for calculation. Essentially, world coordinates refer to the coordinate position of a virtual model in three-dimensional space. In three-dimensional space, the coordinates of a point are usually represented by three values, representing its coordinates on the x, y, and z axes. For example, the world coordinates of a sphere can be represented as (x, y, z, r), where (x, y, z) are the coordinates of the sphere's center, and r is the sphere's radius. World coordinates are fundamental for describing the position of graphical objects; they can be used to calculate the relative positions and distances between graphical objects, and are also crucial for implementing graphical transformations and animations. For example, translating a sphere 10 units along the x-axis can be achieved by modifying the x-value in its world coordinates. Screen coordinates, on the other hand, refer to a coordinate system used on a two-dimensional screen to describe the position of an image or object. Screen coordinates are a relative coordinate system. Its origin is typically located at the top-left corner of the screen, with the horizontal coordinate increasing to the right and the vertical coordinate increasing downwards. The unit of screen coordinates can be pixels or other units of length. Essentially, screen coordinates refer to the coordinate position of a graphic object on the screen. In a two-dimensional screen, the coordinates of a point are usually represented by two values, representing its coordinates on the x and y axes. For example, the screen coordinates of a square can be represented as (x, y, w, h), where (x, y) are the coordinates of the top-left corner of the square, and w and h represent its width and height, respectively. Screen coordinates are fundamental to graphic display and interaction. They are used to calculate the position and size of graphic objects on the screen and are also crucial for implementing mouse event responses and interactions. For example, when the mouse clicks on a square on the screen, this can be achieved by determining whether the mouse's coordinates are inside the square.
[0044] Since world coordinates and screen coordinates are usually different because they represent different coordinate systems, in practical applications, it is necessary to convert world coordinates to screen coordinates to achieve graphic display and interaction. The conversion from world coordinates to screen coordinates typically includes the following steps: view transformation, converting the world coordinate system to the camera coordinate system or viewing coordinate system to achieve changes in perspective and operations such as rotation and translation of graphics; projection transformation, mapping points in the camera coordinate system or viewing coordinate system to the projection plane, usually including orthographic projection and perspective projection; viewport transformation, mapping points on the projection plane to the screen coordinate system, usually including coordinate transformation and size transformation. It should be noted that the conversion from screen coordinates to world coordinates is usually achieved through the inverse transformation of the above steps.
[0045] 102. Calculate the coordinates of each pixel to obtain the gradient offset value corresponding to each model vertex.
[0046] Specifically, the gradient is essentially a vector representing the directional derivative of a function at a given point, where the directional derivative reaches its maximum value along that direction. In other words, the function changes most rapidly and has the largest rate of change along that direction (the direction of the gradient) at that point. In this embodiment, the gradient offset value of the vertex normal can be understood as being used to calculate the rate of change of the virtual model's surface along the normal direction. The larger this rate of change, the greater the transition in the virtual model at that point, i.e., the less smooth it is. Unevenness in the virtual model generally occurs at transition points; therefore, the gradient offset value can be used to find the edges of the virtual model, i.e., the edges of the model's outline.
[0047] This application embodiment uses the second-order partial derivative function ddx / ddy to determine the rate of change of the pixel value corresponding to the vertex normal relative to the screen space x or y coordinate direction, i.e., the horizontal or vertical gradient offset value. This gradient offset value can be used to detect changes in texture, color, or other attributes in the horizontal direction, thereby obtaining better edge performance without correcting normals or textures. This application uses the ddx / ddy function to detect the rate of change of the screen space world coordinate normal. By looking at the flatness of the model surface normal, it can be understood that areas with large transitions are usually the edge structure of the virtual model, thus identifying the edge parts of the virtual model during rendering. The second-order partial derivative function ddx / ddy is a built-in function in most engines. ddx indicates the calculation of the gradient and change in the x-direction of the image, and ddy indicates the calculation of the gradient and change in the y-direction of the image.
[0048] The specific definition of the second-order partial derivative function of ddx / ddy is as follows: Let a function be z = f(x, y). When y remains stationary in the y0 direction, we assume there is an increment in the x-direction at x0. We can then easily calculate the growth slope at the point (x0, y0). This process involves taking the partial derivative of the function z = f(x, y) with respect to x at the point (x0, y0). Similarly, we can also take the partial derivative of z = f(x, y) with respect to y at the point (x0, y0). Specifically, the formula for calculating the growth slope is as follows:
[0049]
[0050] When calculating pixels in a GPU, pixels are organized into 2x2 pixel blocks for parallel processing. This means that taking the partial derivative with respect to a pixel is equivalent to calculating the rate of change of a certain value for that pixel. The direction of the partial derivative differs when taking it with respect to x or y.
[0051] Specifically, when calculating the rate of change of the normal, we can perform a cross product of the tangent and the bitangent. The rate of change of the normal is calculated by obtaining the tangent and bitangent, which represent the slopes of the vertex coordinate changes in different directions. In 3D coordinate space, the change of vertex coordinates can be viewed as a function. Taking the partial derivative with respect to x gives us the slope of this function at the point (x0, y0, z0) in the x-direction, which is the tangent. The same logic applies to the y-direction. Therefore, in Unity shaders, taking the partial derivative with respect to x or y yields the tangent and bitangent, which can then be cross-producted to calculate the rate of change. After calculation, a normalize operation is applied for normalization.
[0052] In this embodiment, since the second-order partial derivative of ddx only calculates the positive part, a simplified absolute value algorithm is used to calculate the negative part of the offset, thus obtaining a more complete edge structure. Because ddx calculates the rate of change along the positive x-axis (horizontal to the right), a negative number will occur if the value on the left is larger than the value on the right; therefore, the absolute value is used to determine the actual rate of change. Similarly, ddy is vertically downwards as the positive direction, and the absolute value of the rate of change is also used. The specific implementation code is shown below:
[0053] float3 dd_bias=abs(ddy(world_normal))+abs(ddx(world_normal));
[0054] In the code above, `abs` is a function that processes a number and returns its absolute value. `ddy(world_normal)` calculates the gradient and change of the scene normal in the y-direction, and `ddx(world_normal)` calculates the gradient and change of the scene normal in the x-direction.
[0055] Furthermore, to more accurately determine the edge structure of the virtual model, this embodiment, based on the above steps, performs an overall amplification of the xyz direction values obtained from the pixel coordinates of the vertex normal, thereby maximizing the identification of the virtual model's edge structure within a certain gradient range. The specific implementation code is shown below:
[0056] float normalBias=(max(dd_bias.x,max(dd_bias.y,dd_bias.z))-0.0000002f);
[0057] In this embodiment, the normal change rate of each model vertex corresponding to the pixel is calculated, and vertices with a change rate greater than a preset threshold are identified as edge vertices. The edge portion of the model is determined based on multiple edge vertices. The normal change rate can be calculated based on the gradient of the world coordinate normal, the gradient offset value, and the normal smoothness threshold. Here, the normal change rate is the gradient of the world coordinate normal, the gradient offset value also refers to the gradient, and the normal smoothness threshold can be a specified value or a calculated value, such as 0.0000002f in the code above.
[0058] In one embodiment, the method for step "calculating the coordinates of each pixel to obtain the gradient offset value corresponding to each model vertex" may include:
[0059] The coordinates of each pixel are calculated using a preset second-order partial derivative function to obtain the gradient offset value corresponding to each model vertex.
[0060] Furthermore, the step "calculating the coordinates of each pixel using the second-order partial derivative function to obtain the gradient offset value corresponding to each model vertex" can include:
[0061] The second-order partial derivative function is used to determine the target rate of change of each pixel's coordinates on at least one specified coordinate axis;
[0062] The gradient offset value corresponding to each model vertex is determined based on the target rate of change.
[0063] In this embodiment of the application, the second-order partial derivative function can be used to determine the first target rate of change of each pixel coordinate on the x-axis. Then, the second-order partial derivative function can be used to determine the second target rate of change of each pixel coordinate on the y-axis. Based on the first target rate of change and the second target rate of change, the gradient offset value of the model vertex can be determined.
[0064] In one embodiment, the direction of step "determining the target rate of change of each pixel coordinate on at least one specified coordinate axis using the second-order partial derivative function" may include:
[0065] Using the second-order partial derivative function, the first rate of change of the coordinates of each pixel in the first direction on the specified coordinate axis is determined, and the second rate of change of the coordinates of each pixel in the second direction on the specified coordinate axis is determined;
[0066] The target rate of change is determined based on the first rate of change and the second rate of change.
[0067] Specifically, in this embodiment, the second-order partial derivative function can be used to determine the first rate of change of each pixel's coordinates in the positive direction of the x-coordinate axis and the second rate of change of each pixel's coordinates in the negative direction of the x-coordinate axis. A first target rate of change is then determined based on the first rate of change in the positive direction of the x-coordinate axis and the second rate of change in the negative direction of the x-coordinate axis. Furthermore, the second-order partial derivative function can also be used to determine the first rate of change of each pixel's coordinates in the positive direction of the y-coordinate axis and the second rate of change of each pixel's coordinates in the negative direction of the y-coordinate axis. A second target rate of change is then determined based on the first rate of change in the positive direction of the y-coordinate axis and the second rate of change in the negative direction of the y-coordinate axis.
[0068] Optionally, in order to more accurately determine the edge structure of the virtual model, after the step "calculate the coordinates of each pixel to obtain the gradient offset value corresponding to each model vertex", the method may include:
[0069] The gradient offset value is numerically amplified based on preset parameters to obtain the amplified gradient offset value.
[0070] 103. Based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset value corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected.
[0071] In this embodiment, the edge contour vertices of the preset virtual model can be filtered based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset value corresponding to each model vertex. Game developers can preset the gradient offset value threshold. Model vertices corresponding to gradient offset values less than the threshold are regular model vertices, while model vertices corresponding to gradient offset values greater than or equal to the threshold are edge contour vertices. The model contour edges of the virtual model and the corresponding edge contour vertices can be determined from the virtual model using the gradient offset value threshold.
[0072] 104. Based on the contour pixels corresponding to each edge contour vertex, the preset texture map is sampled to render the texture in the preset texture map onto the contour pixels to obtain the target virtual model.
[0073] This application embodiment can take the pixel point of the vertex normal of each vertex of the virtual model, multiply the normal direction of the model vertex by the preset view direction of the virtual camera to obtain a result, and then superimpose a half Lambert offset on the result to calculate a larger range of edge light. The specific implementation code is shown below:
[0074] float invNdVMNormal=saturate(1.0h-(ndv*0.5h+0.5h));
[0075] Semi-Lambert scattering is a method for calculating diffuse reflection, a phenomenon where light reflects off an object's surface due to the interaction of light with the surface's minute irregularities. In computer graphics, diffuse reflection is a commonly used lighting model to simulate the lighting effects on object surfaces. Specifically, semi-Lambert scattering is a simplified version of Lambert's law. Lambert's law states that diffuse light rays on an object's surface have equal intensity in all directions, while semi-Lambert scattering assumes that diffuse light rays have intensity only in the direction normal to the object's surface, with zero intensity in other directions. At the pixel level, semi-Lambert scattering can be achieved using the following formula:
[0076] diffuse=max(dot(normal,lightDir),0.0);
[0077] Here, `normal` is the normal vector of the object's surface, and `lightDir` is the direction vector of the light ray. `dot(normal,lightDir)` represents the dot product of the normal vector and the light ray direction vector, and the `max` function is used to ensure that the intensity of the diffuse light is not less than zero. The final diffuse color can be obtained by multiplying the color of the object's surface by the intensity of the diffuse light: `color = objectColor * diffuse`; where `objectColor` is the color of the object's surface.
[0078] Next, in this embodiment, the edge light obtained in the above steps can be used as the masking range. Based on the screen spatial distance, a first preset texture image is sampled. This first preset texture image can be a bar noise image. The specific implementation code is as follows:
[0079] FLOAT2 screenUV=input.clipPos.xy*screenScale*0.01;
[0080] #if ENABLE_SCREENDISdepth=saturate(distance(input.positionWS,CameraPosition.xyz).x)*CamDist;
[0081] `screenUV* = depth`; the `depth` parameter adaptively scales the screen-space UV by multiplying the distance from the vertex's world coordinates to the camera's position by the screen-space UV value.
[0082] #else
[0083] screenUV* = 1;
[0084] #endif
[0085] HALF4 dithermap = SAMPLE_TEXTURE(Tex2, screenUV); Using the edge light as the masking range, sample a first preset texture map according to the screen spatial distance.
[0086] The `depth` parameter adaptively scales the screen-space UVs by multiplying the distance from the vertex's world coordinate position to the camera's position by the screen-space UV coordinates. The screen control distance refers to the distance between the virtual model's vertex coordinates in world coordinates and the virtual camera's camera coordinates. Scaling based on screen-space UV sampling ensures that the spacing of the stripe noise at the model's edges remains proportional to the virtual model. Furthermore, since the virtual model's UV arrangement is not always regular, sampling along its own UV arrangement would result in erratic stripe noise directions. Sampling along the screen-space UVs ensures the stripe effect remains perpendicular because the screen-space UV coordinates are aligned with the screen's orientation and do not change. The specific implementation code is as follows:
[0087] distance(input.positionWS,CameraPosition.xyz).x
[0088] The code above refers to the distance between the virtual model's vertices in world coordinates and camera coordinates. Screen-space UV sampling is a technique that uses screen-space coordinates as UV coordinates to sample textures. In practical applications, UVs are usually derived from the UV information recorded by a pre-defined texture. The texture information corresponding to the model's coordinates is obtained from the texture through the correspondence between the texture's recorded coordinates and the virtual model's coordinates. Screen-space UV sampling, however, uses screen-space / eye-space coordinates as UVs to sample textures. The calculation of screen UVs is relatively simple; after passing through the MVP matrix, the clipping space ranges from [-1,1], requiring only remapping to the [0,1] range used for UV coordinates. Specifically, UV coordinates are the texture coordinates used by the virtual model when sampling textures, and their range is 0 to 1. The vertex attributes of the virtual model contain UV coordinates, thus establishing a mapping relationship between the model's vertices in 3D space and the textures in 2D space. For example, by obtaining the coordinates of the model's vertices and normalizing them, the virtual model can be scaled into a unit sphere, with all vertices of the virtual model lying on the surface of the unit sphere. At this point, the spherical coordinates Theta and Phi of the vertex can be obtained by normalizing the vertex coordinates. In spherical coordinates, Theta takes values from 0 to 2π, and Phi takes values from 0 to π. By scaling Theta and Phi to the range of 0 to 1, i.e., Theta / 2π and Phi / π, the UV coordinates can be obtained.
[0089] Furthermore, in this embodiment of the application, a second preset texture map can be superimposed on the above steps. The second preset texture map can be a texture map with different shapes, such as a star texture map, a normal noise texture map, a grid texture map, a dot texture map, etc.
[0090] For example, this embodiment of the application can add a layer of flowing UV stars based on the above steps. The flowing UV stars are obtained by dynamically sampling a star noise map according to FrameTime. uv_temp_offsetk can be understood as the flow velocity, and scalex / y is the tiling size of the map in the xy direction. The specific implementation code for sampling is shown below:
[0091] FLOAT glitter_value=SAMPLE_TEXTURE(STAR_TEXTURE,(FLOAT2(f_uv.x*scalex,f_uv.y*scaley)+uv_temp_offset*FrameTime).g;
[0092] Then, interpolation is performed using the above data and the basecolor of the texture itself. The white part of the data uses the custom edge light color rim_l.rgb, and the black part uses the basecolor, to obtain the final result, so that the edges of the virtual model have diagonal lines and highlights (e.g. Figure 7 (Edge effects of the virtual model). The specific implementation code is shown below:
[0093] finalColor.rgb=lerp(baseColor.rgb,rim_l.rgb*rim_l.a,saturate(rim_l.a));
[0094] Specifically, in the embodiments of this application, for example, please refer to Figure 6b The "white portion" corresponds to the model's edge contour, using a custom color for edge lighting, such as white. The white portion represents the pixel area where stripe noise is superimposed on the edge pixels of the virtual model. The "black portion" corresponds to the rest of the model excluding the edge contour, i.e. Figure 6b The black areas in the image use the colors originally set for the model's vertices, and the star texture effect is overlaid on the entire virtual model. Furthermore, it can be seen that as the camera zooms in or out on the virtual model, the detail of the edge perturbations adapts proportionally. For example, please refer to... Figure 6c As can be seen, the detail size of the edge perturbations of the virtual model of the fourth effect from the first viewing perspective and the virtual model of the fourth effect from the second viewing perspective will adapt to the scale.
[0095] In this embodiment of the application, the preset texture map includes a first preset texture map and a second preset texture map. The step "sampling the preset texture map based on the contour pixels corresponding to each edge contour vertex to render the texture in the preset texture map onto the contour pixels to obtain the target virtual model" can include:
[0096] Based on the vertex normals of each edge contour vertex and the edge light parameters, generate the edge light for each edge contour vertex;
[0097] Based on the edge light of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model, the first preset texture map is sampled to obtain the first virtual model;
[0098] Based on the pixel coordinates of each vertex in the first virtual model, the second preset texture map is sampled to obtain the second virtual model, which serves as the target virtual model.
[0099] Furthermore, the method for "generating edge lights for each edge contour vertex based on the vertex normals and edge light parameters of each edge contour vertex" may include:
[0100] Obtain the preset offset value, the preset camera's viewing direction, and the normal direction of the vertex normals of each edge contour vertex;
[0101] The edge light of each edge contour vertex is obtained by superimposing the preset offset value, the view direction, and each normal direction.
[0102] Specifically, the method for "sampling the first preset texture map based on the edge light of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model to obtain the first virtual model" may include:
[0103] Obtain the relative spatial distance between each edge contour vertex and the preset camera;
[0104] Based on the edge light of each edge contour vertex, the relative spatial distance of each edge contour vertex, and the pixel coordinates of each model vertex in the preset virtual model, the first preset texture map is sampled to obtain the first virtual model.
[0105] Furthermore, the method for "sampling the first preset texture map based on the edge light of each edge contour vertex, the relative spatial distance of each edge contour vertex, and the pixel coordinates of each model vertex in the preset virtual model to obtain the first virtual model" may include:
[0106] Using the edge light of each edge contour vertex as the masking range, the first preset texture map is sampled according to the relative spatial distance of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model to obtain the first virtual model. The pixels of each edge contour vertex in the first virtual model are superimposed with the texture noise value of the first preset texture map.
[0107] This application's embodiments utilize the cost-effectiveness of pre-compiling world space normals using DDX to simplify the calculation of complex post-processing shaders, reduce shader complexity, and save performance overhead. Furthermore, through adaptive edges, finely textured edge details (i.e.,...) are achieved. Figure 7 The edge texture and highlighting effect of the virtual model will not be lost as the model distance increases. Compared with stars without adaptive processing, the star texture effect in this embodiment gradually disappears as the virtual camera lens moves away, and the star effect becomes more obvious as the lens gets closer.
[0108] In summary, this application provides a method for processing a virtual model. This method involves obtaining the vertex normals and corresponding screen pixel coordinates of each vertex in a preset virtual model. Then, the gradient offset values for each pixel coordinate are calculated. Next, based on a preset gradient offset threshold and the gradient offset values of each vertex, the edge contour vertices of the preset virtual model are selected. Finally, based on the contour pixels of each edge contour vertex, a preset texture map is sampled to render the texture from the preset texture map onto the contour pixels, thus obtaining the target virtual model. In this application, by calculating the vertex normals and corresponding gradient offset values of each vertex in the virtual model, and selecting the edge contour vertices of the virtual model based on the gradient offset threshold and the gradient offset values of each vertex, the edge contour of the virtual model is determined. Furthermore, by setting target texture effects for the edge contour vertices based on the preset texture map, the target texture effects for the virtual model's edge contours are set, saving time and manpower and improving the efficiency of creating texture effects for the model's edge contours.
[0109] Based on the above description, the following examples will further illustrate the virtual model processing method of this application. Specific embodiments of this virtual model processing method are described below:
[0110] (1) In this embodiment, the vertex normals of each model vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space can be obtained. Specifically, the virtual model is a model located in world coordinates, and the pixel coordinates of the screen pixels corresponding to the vertex normals of the virtual model in screen space can be calculated. In this embodiment, the second-order partial derivative function ddx / ddy can be used to determine the rate of change of the pixel value of the pixel coordinates corresponding to the vertex normals relative to the x or y coordinates in screen space, that is, the horizontal or vertical gradient offset value, thereby determining the gradient offset value corresponding to each model vertex.
[0111] (2) In this embodiment, the edge contour vertices of the preset virtual model can be filtered based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset values corresponding to each model vertex. Game developers can preset the gradient offset value threshold. Model vertices corresponding to gradient offset values less than the threshold are regular model vertices, and model vertices corresponding to gradient offset values greater than or equal to the threshold are edge contour vertices. The model contour edges of the virtual model and the edge contour vertices corresponding to the model contour edges can be determined from the virtual model using the gradient offset value threshold. For example, please refer to [further details omitted]. Figure 3 and Figure 4 , Figure 3 It is the DDX effect after taking the absolute value of the virtual model, that is, the virtual model with the first effect. Figure 4 The virtual model is the result of edge search based on gradient offset values. That is, based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset value corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected, and the virtual model with the second effect is obtained based on the obtained edge contour vertices.
[0112] (3) In this embodiment, the pixel point of the vertex normal of each vertex of the virtual model can be multiplied by the normal direction of the model vertex by the preset viewing direction of the virtual camera to obtain a result, and a half-Lambert offset can be superimposed on the result to calculate a larger range of edge light. For example, please refer to Figure 5 , Figure 5 It is a virtual model that calculates the third effect of a large-scale edge light.
[0113] (4) In this embodiment of the application, the edge light obtained in the above steps can be used as the masking range. A first preset texture image is sampled according to the screen spatial distance. This first preset texture image can be a bar noise image, for example, such as... Figure 6a The bar noise map is shown. Then, based on the above steps, a layer of flowing UVs is added to create stars. Specifically, the second preset texture map "star map" can be sampled based on the pixel coordinates of each model vertex in the virtual model to obtain the second virtual model, which serves as the target virtual model. For example, please refer to [link / reference]. Figure 7 and Figure 8 , Figure 7 This is a schematic diagram of a virtual model that obtains the fourth effect by sampling the noise of the first preset texture map in screen space adaptive UV sampling. Figure 8 It is a target virtual model with target edge effect obtained based on the first preset texture map and the second preset texture map.
[0114] In summary, this application provides a method for processing a virtual model. This method involves obtaining the vertex normals and corresponding screen pixel coordinates of each vertex in a preset virtual model. Then, the gradient offset values for each pixel coordinate are calculated. Next, based on a preset gradient offset threshold and the gradient offset values of each vertex, the edge contour vertices of the preset virtual model are selected. Finally, based on the contour pixels of each edge contour vertex, a preset texture map is sampled to render the texture from the preset texture map onto the contour pixels, thus obtaining the target virtual model. In this application, by calculating the vertex normals and corresponding gradient offset values of each vertex in the virtual model, and selecting the edge contour vertices of the virtual model based on the gradient offset threshold and the gradient offset values of each vertex, the edge contour of the virtual model is determined. Furthermore, by setting target texture effects for the edge contour vertices based on the preset texture map, the target texture effects for the virtual model's edge contours are set, saving time and manpower and improving the efficiency of creating texture effects for the model's edge contours.
[0115] To facilitate better implementation of the virtual model processing method provided in this application embodiment, this application embodiment also provides a processing apparatus based on the above-described virtual model. The meanings of the terms used are the same as in the virtual model processing method described above, and specific implementation details can be found in the descriptions in the method embodiments.
[0116] Please see Figure 9 , Figure 9 This application provides a schematic diagram of the structure of a virtual model processing device, which includes:
[0117] The acquisition unit 201 is used to acquire the vertex normals of each model vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space;
[0118] The calculation unit 202 is used to calculate the coordinates of each pixel point to obtain the gradient offset value corresponding to each model vertex;
[0119] The filtering unit 203 is used to filter out the edge contour vertices of the preset virtual model based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset value corresponding to each model vertex.
[0120] The sampling unit 204 is used to sample the preset texture map based on the contour pixels corresponding to each edge contour vertex, so as to render the texture in the preset texture map onto the contour pixels to obtain the target virtual model.
[0121] In some embodiments, the processing apparatus for the virtual model includes:
[0122] The calculation subunit is used to calculate the coordinates of each pixel point using a preset second-order partial derivative function to obtain the gradient offset value corresponding to each model vertex.
[0123] In some embodiments, the processing apparatus for the virtual model includes:
[0124] The first determining subunit is used to determine the target rate of change of each pixel coordinate on at least one specified coordinate axis using the second-order partial derivative function.
[0125] The first determining unit is also used to determine the gradient offset value corresponding to each model vertex based on the target rate of change.
[0126] In some embodiments, the processing apparatus for the virtual model includes:
[0127] The second determining subunit is used to determine, using the second-order partial derivative function, a first rate of change of the coordinates of each pixel point in a first direction on the specified coordinate axis, and a second rate of change of the coordinates of each pixel point in a second direction on the specified coordinate axis;
[0128] The second determining subunit is further configured to determine a target rate of change based on the first rate of change and the second rate of change.
[0129] In some embodiments, the processing apparatus for the virtual model includes:
[0130] The first processing subunit is used to perform numerical amplification processing on the gradient offset value based on preset parameters to obtain the amplified gradient offset value.
[0131] In some embodiments, the processing apparatus for the virtual model includes:
[0132] The generation sub-unit is used to generate edge lights for each edge contour vertex based on the vertex normals and edge light parameters of each edge contour vertex;
[0133] The first sampling subunit is used to sample the first preset texture map based on the edge light of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model to obtain the first virtual model.
[0134] The first sampling subunit is further configured to sample the second preset texture map based on the pixel coordinates of each model vertex in the first virtual model to obtain a second virtual model, which serves as the target virtual model.
[0135] In some embodiments, the processing apparatus for the virtual model includes:
[0136] The first acquisition subunit is used to acquire the preset offset value, the preset camera's viewing direction, and the normal direction of the vertex normals of each edge contour vertex;
[0137] The second processing subunit is used to perform superposition processing based on the preset offset value, the viewing direction, and each normal direction to obtain the edge light of each edge contour vertex.
[0138] In some embodiments, the processing apparatus for the virtual model includes:
[0139] The second acquisition subunit is used to acquire the relative spatial distance between each edge contour vertex and the preset camera;
[0140] The second sampling subunit is used to sample the first preset texture map based on the edge light of each edge contour vertex, the relative spatial distance of each edge contour vertex, and the pixel coordinates of each model vertex in the preset virtual model, to obtain the first virtual model.
[0141] In some embodiments, the processing apparatus for the virtual model includes:
[0142] The third sampling subunit is used to sample the first preset texture map with the edge light of each edge contour vertex as the masking range, according to the relative spatial distance of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model, to obtain the first virtual model, wherein the pixel of each edge contour vertex in the first virtual model is superimposed with the texture noise value of the first preset texture map.
[0143] This application provides a virtual model processing device. An acquisition unit 201 acquires the vertex normals of each model vertex in a preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space. A calculation unit 202 calculates the gradient offset values corresponding to each model vertex based on the pixel coordinates. A filtering unit 203 filters out the edge contour vertices of the preset virtual model based on a preset gradient offset value threshold corresponding to contour points and the gradient offset values corresponding to each model vertex. A sampling unit 204 samples a preset texture map based on the contour pixels corresponding to each edge contour vertex to render the texture in the preset texture map onto the contour pixels, thereby obtaining the target virtual model. In this embodiment, the vertex normals of each vertex of the virtual model are calculated, and the gradient offset values corresponding to them in screen space are obtained. Based on the gradient offset value threshold and the gradient offset values corresponding to each vertex, the edge contour vertices of the virtual model are selected from the virtual model to determine the model edge contour. Furthermore, the target texture effect is set on the edge contour vertices based on the preset texture map, thereby setting the target texture effect for the model edge contour of the virtual model. This can save time and manpower and improve the production efficiency of the texture effect of the model edge contour.
[0144] Accordingly, this application also provides a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. Figure 10 As shown, Figure 10 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 300 includes a processor 301 with one or more processing cores, a memory 302 with one or more computer-readable storage media, and a computer program stored in the memory 302 and executable on the processor. The processor 301 and the memory 302 are electrically connected. Those skilled in the art will understand that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0145] The processor 301 is the control center of the computer device 300. It connects various parts of the computer device 300 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 302, and calling data stored in the memory 302, it performs various functions of the computer device 300 and processes data, thereby monitoring the computer device 300 as a whole.
[0146] In this embodiment, the processor 301 in the computer device 300 loads the instructions corresponding to the processes of one or more applications into the memory 302 according to the following steps, and the processor 301 runs the applications stored in the memory 302 to achieve various functions:
[0147] Obtain the vertex normals of each vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space;
[0148] The gradient offset value corresponding to each model vertex is obtained by calculating the coordinates of each pixel.
[0149] Based on the preset gradient offset value threshold corresponding to the contour points and the gradient offset value corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected.
[0150] Based on the contour pixels corresponding to each edge contour vertex, a preset texture map is sampled to render the texture in the preset texture map onto the contour pixels, thereby obtaining the target virtual model.
[0151] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0152] Optional, such as Figure 10 As shown, the computer device 300 also includes: a touch screen display 303, a radio frequency circuit 304, an audio circuit 305, an input unit 306, and a power supply 307. The processor 301 is electrically connected to the touch screen display 303, the radio frequency circuit 304, the audio circuit 305, the input unit 306, and the power supply 307. Those skilled in the art will understand that... Figure 4 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0153] The touch display screen 303 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 303 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the computer device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 301. It can also receive and execute commands from the processor 301. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 301 to determine the type of touch event. Subsequently, the processor 301 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 303 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 303 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 303 can also be used as part of the input unit 306 to achieve input functions.
[0154] In this embodiment, a game application is executed by processor 301 to generate a graphical user interface (GUI) on touch display screen 303. The touch display screen 303 is used to present the GUI and receive user commands generated by the GUI.
[0155] The radio frequency circuit 304 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other computer devices, and to transmit and receive signals with network devices or other computer devices.
[0156] Audio circuitry 305 can be used to provide an audio interface between a user and a computer device via a speaker and a microphone. Audio circuitry 305 converts received audio data into electrical signals, transmits them to the speaker, and the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuitry 305, converted back into audio data, and output to processor 301 for processing. The audio data is then transmitted via radio frequency circuitry 304 to, for example, another computer device, or output to memory 302 for further processing. Audio circuitry 305 may also include an earphone jack to facilitate communication between peripheral headphones and the computer device.
[0157] The input unit 306 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
[0158] Power supply 307 is used to supply power to various components of computer device 300. Optionally, power supply 307 can be logically connected to processor 301 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 307 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0159] although Figure 10 As not shown in the diagram, computer equipment 300 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.
[0160] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0161] As can be seen from the above, the computer device provided in this embodiment obtains the vertex normals of each model vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space; then, it calculates the gradient offset value corresponding to each model vertex based on the pixel coordinates; next, it filters out the edge contour vertices of the preset virtual model based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset values corresponding to each model vertex; finally, it samples the preset texture map based on the contour pixels corresponding to each edge contour vertex to render the texture in the preset texture map onto the contour pixels, thereby obtaining the target virtual model. In this embodiment, by calculating the vertex normals of each model vertex of the virtual model and the gradient offset values corresponding to the screen space, and filtering out the edge contour vertices of the virtual model according to the gradient offset value threshold and the gradient offset values corresponding to each model vertex, the model edge contour of the virtual model is determined. Furthermore, by setting the target texture effect on the edge contour vertices based on the preset texture map, the target texture effect of the model edge contour of the virtual model can be set, which can save time and manpower and improve the production efficiency of the texture effect of the model edge contour.
[0162] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0163] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of computer programs that can be loaded by a processor to execute steps in any of the virtual model processing methods provided in embodiments of this application. For example, the computer program can execute the following steps:
[0164] Obtain the vertex normals of each vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space;
[0165] The gradient offset value corresponding to each model vertex is obtained by calculating the coordinates of each pixel.
[0166] Based on the preset gradient offset value threshold corresponding to the contour points and the gradient offset value corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected.
[0167] Based on the contour pixels corresponding to each edge contour vertex, a preset texture map is sampled to render the texture in the preset texture map onto the contour pixels, thereby obtaining the target virtual model.
[0168] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0169] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0170] The computer program stored in this storage medium obtains the vertex normals and corresponding screen pixel coordinates of each model vertex in a preset virtual model. Then, it calculates the gradient offset value corresponding to each model vertex based on the pixel coordinates. Next, based on a preset gradient offset threshold and the gradient offset values of each model vertex, it filters out the edge contour vertices of the preset virtual model. Finally, based on the contour pixels corresponding to each edge contour vertex, it samples a preset texture map to render the texture from the preset texture map onto the contour pixels, thus obtaining the target virtual model. In this embodiment, by calculating the vertex normals and corresponding gradient offset values of each model vertex in the virtual model, and filtering out the edge contour vertices of the virtual model based on the gradient offset threshold and the gradient offset values of each model vertex, the edge contour of the virtual model is determined. Furthermore, by setting target texture effects on the edge contour vertices based on the preset texture map, the target texture effects for the virtual model's edge contours can be set, saving time and manpower and improving the efficiency of creating texture effects for the model's edge contours.
[0171] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0172] The foregoing has provided a detailed description of a virtual model processing method, apparatus, computer device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the technical solutions and core ideas of this application. Those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A method for processing virtual models, characterized in that, include: Obtain the vertex normals of each vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space; The gradient offset value corresponding to each model vertex is obtained by calculating the coordinates of each pixel. Based on the preset gradient offset value threshold corresponding to the contour points and the gradient offset value corresponding to each model vertex, the edge contour vertices of the preset virtual model are selected. Based on the contour pixels corresponding to each edge contour vertex, a preset texture map is sampled to render the texture in the preset texture map onto the contour pixels, thereby obtaining the target virtual model.
2. The method for processing virtual models according to claim 1, characterized in that, The gradient offset values corresponding to each model vertex are obtained by calculating the coordinates of each pixel, including: The coordinates of each pixel are calculated using a preset second-order partial derivative function to obtain the gradient offset value corresponding to each model vertex.
3. The virtual model processing method according to claim 2, characterized in that, The second-order partial derivative function is used to calculate the coordinates of each pixel to obtain the gradient offset value corresponding to each model vertex, including: The second-order partial derivative function is used to determine the target rate of change of each pixel's coordinates on at least one specified coordinate axis; The gradient offset value corresponding to each model vertex is determined based on the target rate of change.
4. The virtual model processing method according to claim 3, characterized in that, The step of determining the target rate of change of each pixel's coordinates on at least one specified coordinate axis using the second-order partial derivative function includes: Using the second-order partial derivative function, the first rate of change of the coordinates of each pixel in the first direction on the specified coordinate axis is determined, and the second rate of change of the coordinates of each pixel in the second direction on the specified coordinate axis is determined; The target rate of change is determined based on the first rate of change and the second rate of change.
5. The method for processing virtual models according to claim 1, characterized in that, After calculating the coordinates of each pixel to obtain the gradient offset value corresponding to each model vertex, the process also includes: The gradient offset value is numerically amplified based on preset parameters to obtain the amplified gradient offset value.
6. The method for processing virtual models according to claim 1, characterized in that, The preset texture map includes a first preset texture map and a second preset texture map; The step of sampling a preset texture map based on the contour pixels corresponding to each edge contour vertex, and rendering the texture in the preset texture map onto the contour pixels to obtain the target virtual model, includes: Based on the vertex normals of each edge contour vertex and the edge light parameters, generate the edge light for each edge contour vertex; Based on the edge light of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model, the first preset texture map is sampled to obtain the first virtual model; Based on the pixel coordinates of each vertex in the first virtual model, the second preset texture map is sampled to obtain the second virtual model, which serves as the target virtual model.
7. The method for processing virtual models according to claim 6, characterized in that, The generation of edge lights for each edge contour vertex based on the vertex normals and edge light parameters includes: Obtain the preset offset value, the preset camera's viewing direction, and the normal direction of the vertex normals of each edge contour vertex; The edge light of each edge contour vertex is obtained by superimposing the preset offset value, the view direction, and each normal direction.
8. The method for processing virtual models according to claim 7, characterized in that, The first virtual model is obtained by sampling the first preset texture map based on the edge light of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model, including: Obtain the relative spatial distance between each edge contour vertex and the preset camera; Based on the edge light of each edge contour vertex, the relative spatial distance of each edge contour vertex, and the pixel coordinates of each model vertex in the preset virtual model, the first preset texture map is sampled to obtain the first virtual model.
9. The method for processing virtual models according to claim 8, characterized in that, The first virtual model is obtained by sampling the first preset texture map based on the edge light of each edge contour vertex, the relative spatial distance of each edge contour vertex, and the pixel coordinates of each model vertex in the preset virtual model, including: Using the edge light of each edge contour vertex as the masking range, the first preset texture map is sampled according to the relative spatial distance of each edge contour vertex and the pixel coordinates of each model vertex in the preset virtual model to obtain the first virtual model. The pixels of each edge contour vertex in the first virtual model are superimposed with the texture noise value of the first preset texture map.
10. A processing apparatus for a virtual model, characterized in that, include: The acquisition unit is used to acquire the vertex normals of each model vertex in the preset virtual model and the pixel coordinates of the corresponding screen pixels in screen space; The calculation unit is used to calculate the coordinates of each pixel to obtain the gradient offset value corresponding to each model vertex; The filtering unit is used to filter out the edge contour vertices of the preset virtual model based on the gradient offset value threshold corresponding to the preset contour points and the gradient offset value corresponding to each model vertex. The sampling unit is used to sample the preset texture map based on the contour pixels corresponding to each edge contour vertex, so as to render the texture in the preset texture map onto the contour pixels to obtain the target virtual model.
11. A computer device, characterized in that, The computer device includes a memory and a processor. The memory stores a computer program, and the processor executes the steps of the virtual model processing method as described in any one of claims 1 to 9 by calling the computer program stored in the memory.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program adapted for loading by a processor to perform the steps of the virtual model processing method as described in any one of claims 1 to 9.
Citation Information
Patent Citations
Texture processing method and device of virtual model, computer equipment and storage medium
CN115393495A
Image rendering method and apparatus, electronic device, computer-readable storage medium, and computer program product
US20240005588A1