Hair rendering method and device of virtual object, electronic equipment and storage medium
Through depth rendering and highlight coefficient calculation of virtual object hair, combined with diffuse reflection and shadow coefficient, the problem of low hair rendering performance under the UE4 rendering pipeline is solved, and high-quality rendering effects and high performance on the mobile terminal are achieved.
Patent Information
- Application Number
- CN202310259795.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2024-09-10
AI Technical Summary
Under the default rendering pipeline of UE4, the lighting rendering performance of the virtual object's hair is low, the frame rate is low and the noise is serious, especially in mobile applications, which has a large performance consumption.
By performing depth rendering and highlight coefficient calculation on the virtual object's hair, combined with the diffuse reflection coefficient and shadow coefficient, high-quality rendering of the virtual object's hair is achieved, reducing the amount of shader calculations, compressing the number of lighting rendering processes, and adapting to the real-time frame rate requirements of mobile terminals. .
On the premise of ensuring that the hair rendering effect is not damaged, the rendering overhead is reduced, the rendering performance is improved, the appearance of noise is avoided, and the real-time rendering needs of the mobile terminal are met.
Smart Images

Figure CN118628635A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for rendering hair of a virtual object. Background Art
[0002] With the development of computer technology, users can open game applications on terminals at any time to play games. Game applications provide virtual scenes, and virtual objects are displayed in the virtual scenes. In order to improve the rendering effect, there is a need to optimize the rendering of the hair of the virtual objects.
[0003] Under the default rendering pipeline of Unreal Engine 4 (UE4), the Marschner Shading Model is used to perform lighting calculations for the hair of virtual objects. However, the Marschner Shading Model has a huge amount of shader calculations and many lighting rendering processes. When used on mobile devices, the frame rate is low and the noise is severe. Therefore, the rendering overhead on the terminal side is large and the rendering performance needs to be improved. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device and storage medium for rendering hair of a virtual object, which can reduce the amount of shader calculations and compress the number of lighting rendering processes while ensuring that the hair rendering effect is not damaged, can be adapted to mobile terminals and meet the operating requirements of real-time frame rates, and achieve excellent rendering performance with extremely low rendering overhead. The technical solution is as follows:
[0005] In one aspect, a method for rendering hair of a virtual object is provided, the method comprising:
[0006] Performing depth rendering on hair pixels of the virtual object to obtain depth values of the hair pixels;
[0007] Based on the illumination information and the offset map, a first highlight coefficient and a second highlight coefficient of the hair pixel are obtained, wherein the offset map indicates a deformation of a highlight formed by light irradiation, the first highlight coefficient indicates a highlight effect formed by light acting on the hair pixel, and the second highlight coefficient indicates hierarchical modification information of the first highlight coefficient;
[0008] performing color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, and the diffuse reflection coefficient and shadow coefficient of the hair pixel to obtain a color value of the hair pixel, wherein the diffuse reflection coefficient indicates a dispersion condition caused by light acting on the hair pixel, and the shadow coefficient indicates a shadow color caused by light acting on the hair pixel;
[0009] The depth value and the color value of each hair pixel of the virtual object are superimposed to obtain the hair region of the virtual object.
[0010] In one aspect, a hair rendering device for a virtual object is provided, the device comprising:
[0011] A depth rendering module, used to perform depth rendering on hair pixels of a virtual object to obtain depth values of the hair pixels;
[0012] a highlight coefficient acquisition module, configured to acquire a first highlight coefficient and a second highlight coefficient of the hair pixel based on illumination information and an offset map, wherein the offset map indicates a deformation of highlights formed by light irradiation, the first highlight coefficient indicates a highlight effect formed by light acting on the hair pixel, and the second highlight coefficient indicates hierarchical modification information of the first highlight coefficient;
[0013] a color rendering module, configured to perform color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, and a diffuse reflection coefficient and a shadow coefficient of the hair pixel to obtain a color value of the hair pixel, wherein the diffuse reflection coefficient indicates a dispersion condition caused by light acting on the hair pixel, and the shadow coefficient indicates a shadow color caused by light acting on the hair pixel;
[0014] The superposition module is used to superimpose the depth value and color value of each hair pixel of the virtual object to obtain the hair area of the virtual object.
[0015] In some embodiments, the highlight coefficient acquisition module includes:
[0016] a first offset acquisition unit, configured to determine a tangential highlight offset of the hair pixel based on the offset map and tangential disturbance information, wherein the tangential disturbance information indicates a disturbance amount of the offset applied in a tangential direction, and the tangential highlight offset indicates an offset amount of the highlight of the hair pixel in the tangential direction;
[0017] A first highlight coefficient acquisition unit is used to acquire the first highlight coefficient based on the illumination information, the tangential highlight offset and the first highlight indication information, wherein the first highlight indication information represents control information of the first-layer highlight indicated by the first highlight coefficient.
[0018] In some embodiments, the first highlight indication information includes a first highlight intensity coefficient and a first highlight color coefficient;
[0019] The first highlight coefficient obtaining unit is used for:
[0020] Determine a half-angle vector of the hair pixel based on an illumination vector and a sight line vector in the illumination information;
[0021] Determine a first intensity control coefficient based on the tangential highlight offset, the half-angle vector and the first highlight intensity coefficient, wherein the first intensity control coefficient indicates the offset and intensity of the first layer highlight in the tangential direction;
[0022] The first intensity control coefficient is multiplied by the first highlight color coefficient to obtain the first highlight coefficient.
[0023] In some embodiments, the highlight coefficient acquisition module includes:
[0024] a second offset obtaining unit, configured to determine a negative normal highlight offset of the hair pixel based on the offset map and negative normal disturbance information, wherein the negative normal disturbance information indicates a disturbance amount of the offset applied in a direction opposite to the normal direction, and the negative normal highlight offset indicates an offset amount of the hair pixel in a direction opposite to the normal direction;
[0025] A second highlight coefficient acquisition unit is used to acquire the second highlight coefficient based on the illumination information, the negative normal highlight offset and the second highlight indication information, wherein the second highlight indication information represents control information of the second layer of highlights indicated by the second highlight coefficient.
[0026] In some embodiments, the second highlight indication information includes a second highlight intensity coefficient and a second highlight color coefficient;
[0027] The second highlight coefficient obtaining unit is used for:
[0028] Determine a half-angle vector of the hair pixel based on an illumination vector and a sight line vector in the illumination information;
[0029] Determine a second intensity control coefficient based on the negative normal highlight offset, the half-angle vector and the second highlight intensity coefficient, wherein the second intensity control coefficient indicates the offset and intensity of the second layer of highlights in the opposite direction of the normal direction;
[0030] The second intensity control coefficient is multiplied by the second highlight color coefficient to obtain the second highlight coefficient.
[0031] In some embodiments, the depth rendering module includes:
[0032] a mode determination unit, configured to determine a transparency mode of the hair pixel based on a transparency map, wherein the transparency map indicates a transparency condition of the hair region, and the transparency mode indicates whether the hair pixel is opaque or semi-transparent;
[0033] The depth writing unit is used to perform depth writing on the hair pixel based on the transparency mode of the hair pixel to obtain the depth value of the hair pixel.
[0034] In some embodiments, the depth writing unit is used to:
[0035] When the transparency mode is semi-transparent, writing the depth value of the hair pixel in a transparent blending mode;
[0036] When the transparent mode is opaque, a transparent test mode is adopted to write the depth value of the hair pixel.
[0037] In some embodiments, the apparatus further comprises:
[0038] The diffuse reflection coefficient acquisition module is used to obtain the diffuse reflection coefficient of the hair pixel based on the lighting information, the hair material and the hair roughness of the virtual object, wherein the hair material indicates the material color of the hair pixel, and the hair roughness indicates the roughness of the hair pixel.
[0039] In some embodiments, the diffuse reflectance acquisition module is used to:
[0040] Obtaining the dot product of the illumination vector and the normal vector in the illumination information;
[0041] Performing interpolation processing based on the hair roughness to obtain a lightness and darkness adjustment coefficient;
[0042] The diffuse reflection coefficient of the hair pixel is obtained based on the hair material, the dot product and the shading adjustment coefficient.
[0043] In some embodiments, the apparatus further comprises:
[0044] The shadow coefficient acquisition module is used to perform interpolation processing based on the shadow map and the shadow color control information of the hair pixel to obtain the shadow coefficient of the hair pixel, wherein the shadow map indicates the shadow formed by the light irradiating on the hair area.
[0045] On the one hand, an electronic device is provided, which includes one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and the at least one computer program is loaded and executed by the one or more processors to implement the hair rendering method of a virtual object as described above.
[0046] On the one hand, a computer-readable storage medium is provided, in which at least one computer program is stored. The at least one computer program is loaded and executed by a processor to implement the hair rendering method of a virtual object as described above.
[0047] In one aspect, a computer program product is provided, the computer program product comprising one or more computer programs, the one or more computer programs being stored in a computer-readable storage medium. One or more processors of an electronic device can read the one or more computer programs from the computer-readable storage medium, and the one or more processors execute the one or more computer programs, so that the electronic device can perform the above-mentioned virtual object hair rendering method.
[0048] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:
[0049] For each hair pixel in the hair area of the virtual object, all lighting calculations of the hair pixel can be completed after only one depth rendering and one color rendering. In the color rendering process, the highlight coefficients of the two layers of highlights are calculated to ensure high-quality realistic hair rendering effects. The first layer of highlights simulates the highlight effects of direct light sources, and the second layer of highlights performs hierarchical modification on the first layer of highlights to increase the hierarchical nature and realism of the final highlights. Therefore, while ensuring that the hair rendering effect is not damaged, the amount of shader calculation is reduced, the number of lighting rendering processes is compressed, it can be adapted to mobile terminals and meet the real-time frame rate requirements, and can achieve excellent rendering performance with extremely low rendering overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0051] Figure 1 It is a schematic diagram of an implementation environment of a method for rendering hair of a virtual object provided in an embodiment of the present application;
[0052] Figure 2 is a flow chart of a method for rendering hair of a virtual object provided in an embodiment of the present application;
[0053] Figure 3 is a flow chart of a method for rendering hair of a virtual object provided in an embodiment of the present application;
[0054] Figure 4 is a schematic diagram of a material editing interface of a game engine provided in an embodiment of the present application;
[0055] Figure 5 It is a debugging diagram of a depth rendering stage of a hair area provided by an embodiment of the present application;
[0056] Figure 6 This is a rendering effect diagram of a hair area provided by an embodiment of the present application;
[0057] Figure 7 It is an application principle diagram of hair rendering parameter information provided by an embodiment of the present application;
[0058] Figure 8 is a flowchart of a debugging method for hair rendering parameter information provided by an embodiment of the present application;
[0059] Fig. 9 This is a comparison diagram of the rendering effect of a light irradiating the front of a person provided in an embodiment of the present application;
[0060] Fig.10 This is a comparison diagram of the rendering effect of a light irradiating the back of a person provided in an embodiment of the present application;
[0061] Fig.11 This is another comparison diagram of rendering effects of irradiating the front of a person with light provided in an embodiment of the present application;
[0062] Fig.12 It is a three-view diagram of a hair region rendering solution provided in an embodiment of the present application;
[0063] Fig.13 This is an enlarged view of the detail effect of a hair area rendering solution provided in an embodiment of the present application;
[0064] Fig.14 is a structural schematic diagram of a hair rendering device for a virtual object provided in an embodiment of the present application;
[0065] Fig.15 is a structural schematic diagram of an electronic device provided in an embodiment of the present application;
[0066] Fig.16 It is a schematic diagram of the structure of another electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0068] In this application, the terms "first", "second", etc. are used to distinguish identical or similar items with basically the same effects and functions. It should be understood that there is no logical or temporal dependency between "first", "second", and "nth", nor is there any limitation on quantity and execution order.
[0069] In the present application, the term "at least one" means one or more, and the meaning of "plurality" means two or more. For example, a plurality of first positions means two or more first positions.
[0070] In this application, the term "including at least one of A or B" refers to the following situations: including only A, including only B, and including both A and B.
[0071] The user-related information (including but not limited to the user's device information, personal information, behavior information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application, when applied to specific products or technologies in the manner of the embodiments of this application, are all permitted, agreed, authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant information, data and signals must comply with the relevant laws, regulations and standards of the relevant countries and regions. For example, the hair model and hair material of the virtual object involved in this application are all obtained with full authorization.
[0072] The following is an explanation of the terms used in this application.
[0073] Virtual scene: It is a virtual environment displayed (or provided) when the game application is running on the terminal. The virtual scene can be a simulation of the real world, a semi-simulation and semi-fictional virtual environment, or a purely fictional virtual environment. The virtual scene can be any one of a two-dimensional virtual scene, a 2.5-dimensional virtual scene, or a three-dimensional virtual scene. The embodiment of the present application does not limit the dimension of the virtual scene. The user can control the virtual object to move in the virtual scene.
[0074] Virtual object: refers to an active object in a virtual scene. The virtual object can be a player character controlled by the user through a game application, or a non-player character (NPC) set in a virtual scene that can interact, or a wild monster or a companion robot that is not controlled by the user. Schematically, the virtual object is a virtual image in the virtual scene that is used to represent the user, such as a virtual person, a virtual animal, an anime character, etc. The virtual scene may include multiple virtual objects, each of which has its own shape and volume in the virtual scene and occupies a part of the space in the virtual scene. Optionally, when the virtual scene is a three-dimensional virtual scene, the virtual object can be a three-dimensional stereo model, which can be a three-dimensional character built based on three-dimensional human skeleton technology. The same virtual object can show different external images by wearing different skins. In some embodiments, the virtual object can also be implemented using a 2.5-dimensional or 2-dimensional model, which is not limited in the embodiments of the present application.
[0075] Game engine: refers to some pre-written editable computer game systems or core components of some interactive real-time graphics applications. These systems provide game designers with various tools needed to write games, with the aim of allowing game designers to easily and quickly create game programs without starting from scratch. Game engines include the following systems: rendering engine (i.e. "renderer", including 2D graphics engine and 3D graphics engine), physics engine, collision detection system, sound effects, script engine, computer animation, artificial intelligence, network engine and scene management.
[0076] Unreal Engine (UE): An industry-leading game engine developed by the game company EPIC. It is a complete game development platform for next-generation game consoles and DirectX 9 personal computers, providing a large number of core technologies, data generation tools and basic support required by game developers.
[0077] Rendering engine: In the field of image technology, a rendering engine refers to rendering a 3D model of a virtual object into a 2D image, so that the 3D effect of the 3D model is still maintained in the 2D image. In particular, in the field of game technology, the virtual scene itself and all virtual objects in the virtual scene are rendered by the rendering engine after the model data of the 3D model is imported into the rendering engine, which drives the rendering pipeline in the GPU to render, so as to visualize the object indicated by the 3D model on the terminal display screen.
[0078] Graphics Processing Unit (GPU): A dedicated chip used in modern personal computers, servers, mobile devices, game consoles, etc. specifically for graphics image processing.
[0079] Graphics API (Application Programming Interface): The process of CPU (Central Processing Unit) communicating with GPU is carried out according to a specific standard graphics API. The mainstream graphics APIs include OpenGL, OpenGL ES, Direct X, Metal, Vulkan, etc. GPU manufacturers will implement certain standardized interfaces when producing GPUs. When developing graphics, you can call the GPU according to the methods defined by the interface.
[0080] Draw Call (DC) command: A type of DC command that is usually provided in a graphics API for the CPU to instruct the GPU to perform rendering operations. For example, the DrawIndexedPrimitive command in DirectX and the glDrawElement command in OpenGL are all DC commands supported in the corresponding graphics API.
[0081] Rendering pipeline: The graphics rendering process running in the GPU. In the image rendering process, the following rendering pipelines are usually involved: vertex shader, rasterizer, pixel shader. By writing code in the shader, the GPU can be controlled to render the rendering components.
[0082] Vertex Shader (VS): A mandatory part of the GPU rendering pipeline, an image processing unit that adds 3D special effects. VS has programmable features, allowing developers to use new instructions to adjust special effects. Each vertex (Vertex) is defined by a data structure. The basic attributes of the vertex are the vertex coordinates in the three directions of x, y, and z. In addition, vertex attributes may also include color, initial path, material, light characteristics, etc. The program will calculate each vertex of the 3D model one by one according to the code and output the results to the next stage.
[0083] Rasterizer: A non-codable link in the GPU rendering pipeline. The program automatically assembles the output results of the vertex shader or geometry shader into triangles, and rasterizes them into discrete pixels according to the configuration, and outputs them to the pixel shader.
[0084] Pixel Shader (PS): Also implemented as Fragment Shader (FS), an essential part of the GPU rendering pipeline. After the model vertices are transformed and rasterized, they need to be filled with color. The FS / PS filling algorithm is for each pixel on the screen: the program will perform shading calculations on the rasterized pixels according to the code, and output them to the frame buffer after testing, completing a rendering pipeline process.
[0085] AlphaTest mode: A means of handling translucent effects in the GPU rendering pipeline. When processing pixels, a clipping threshold is given. If the opacity of the pixel is lower than the pre-stored clipping threshold, the pixel is discarded. This is generally implemented through the clipping function Clip() provided by the graphics API.
[0086] Transparent blending (Blend) mode: Another means of handling translucent effects in the GPU rendering pipeline. When processing pixels, the transparency of the pixels is used to handle color mixing. The transparent blending mode can achieve color and transparency mixing of translucent objects and the objects they occlude. It is generally implemented through the blending function Blend() provided by the graphics API.
[0087] Game Thread: One of the threads when multi-threading technology is used in the operation of game applications. It is used to maintain the main game business logic and can be used to implement the creation / destruction logic of virtual objects, virtual objects, etc.
[0088] Render Thread: One of the threads when multi-threading technology is used in game application running, used for non-hardware level rendering instruction processing logic.
[0089] The technical concept of the embodiments of the present application is described below.
[0090] As the quality of game effects improves, the realistic rendering effect of the hair of virtual objects in the game can make the virtual objects as a whole become lifelike and vivid. Therefore, in order to improve the rendering effect of virtual objects, there is a need to optimize the rendering of the hair of virtual objects.
[0091] Under the default rendering pipeline of UE4, a multi-reflection lighting model is used to calculate the reflection, refraction and projection of hair. The shader (Shader) of the above multi-reflection lighting model has a huge amount of calculation, high calculation complexity, high number of DC command calls, many drawing batches, many lighting rendering processes (Pass), and high rendering time. In addition, since hair is a translucent material, the above multi-reflection lighting model relies on the TAA (Temporal Anti-Aliasing) calculation method to simulate a similar translucent visual effect. The high-quality TAA method is extremely dependent on high screen resolution, so the above multi-reflection lighting model is generally used for film and television rendering and stand-alone games. When it is used on mobile terminals, the noise is very serious, and the frame rate (Frames PerSecond, FPS) is very low, which has a large performance consumption on mobile devices. Among them, the frame rate refers to the number of frames transmitted per second, which generally refers to the number of frames displayed per second in the game screen stream.
[0092] In view of this, the embodiment of the present application provides a high-quality semi-transparent hair rendering solution suitable for mobile terminals, which ensures that the depth order of the semi-transparent hair of the virtual object is correct, and realizes the double highlight superposition effect of the hair area of the virtual object. The offset effect of each highlight supports customization, and the color of each highlight is also controllable, and the shadow color of the hair area is also controllable. On the basis of the above, the shader calculation amount is small, the complexity is low, the number of DC command calls is small, the drawing batches are small, and a single rendering pass can complete all lighting calculations, the rendering time is low, and the rendering performance is high. In addition, the semi-transparent rendering solution no longer relies on the high-precision TAA calculation method, nor does it rely on the screen resolution, so there is no noise.
[0093] The following describes the system architecture of the embodiment of the present application.
[0094] Figure 1 Schematic diagram of an implementation environment of a virtual object hair rendering method provided by an embodiment of the present application. Figure 1 In this implementation environment, a terminal 101 and a server 102 are involved. The terminal 101 and the server 102 are directly or indirectly connected via wired or wireless communication, and this application does not make any limitation here.
[0095] The terminal 101 is installed and runs a game application that supports virtual scenes. Optionally, the game application includes: MOBA (Multiplayer Online Battle Arena) games, MMOG (Massive Multiplayer Online Game), MMORPG (Massive Multiplayer Online Role-Playing Game), shooting games, virtual reality applications, three-dimensional map programs, multiplayer mechanical survival games, etc.
[0096] In some embodiments, terminal 101 is an electronic device used by a user. When terminal 101 runs a game application, in response to a start operation triggered by the user in the game application, terminal 101 loads and displays a virtual scene, and displays a virtual object controlled by the user in the virtual scene, as well as other virtual objects within the field of view of the virtual object (such as virtual objects controlled by other users, NPCs, neutral virtual objects, AI objects, etc.).
[0097] The server 102 includes at least one of a single server, multiple servers, a cloud computing platform, or a virtualization center. The server 102 is used to provide background services for game applications that support virtual scenes, and the server 102 can provide basic game logic. Optionally, the server 102 is responsible for the main game logic operation, and the terminal 101 is responsible for the secondary game logic operation; or, the server 102 is responsible for the secondary game logic operation, and the terminal 101 is responsible for the main game logic operation; or, the server 102 and the terminal 101 use a distributed computing architecture to perform collaborative game logic operations.
[0098] Optionally, server 102 is an independent physical server, or 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 communications, middleware services, domain name services, security services, CDN (Content Delivery Network) and big data and artificial intelligence platforms.
[0099] In an exemplary scenario, a GameSvr process is created in the server 102 to provide the basic gameplay logic of the game. Accordingly, when the terminal 101 runs the game application, a game thread GameThread and a rendering thread RenderThread are created. The game thread GameThread is used to maintain the main game business logic, and the rendering thread RenderThread is used for non-hardware level rendering instruction processing logic.
[0100] During the rendering process of any frame of the game screen, the game thread GameThread on the terminal 101 side submits the scene resources of the virtual scene to the rendering thread RenderThread, and the rendering thread RenderThread performs OC (Occlusion Cull) detection on each virtual object in the virtual scene, and submits the virtual object that passes the OC detection to the RHI (Render Hardware Interface) thread, i.e., RHIThread, which drives the rendering pipeline on the GPU to render the virtual object that passes the OC detection to obtain the game screen of the current frame.
[0101] The hair rendering method of a virtual object provided in an embodiment of the present application is applicable to the rendering process of the hair area of any virtual object detected by OC by RHIThread, that is, OC detection determines the visibility of the virtual object. For each visible virtual object, when rendering the hair area of the virtual object, the method of the embodiment of the present application can be applied to ensure the lighting and shadow details of the hair, thereby improving the realistic rendering effect of the virtual object's hair.
[0102] It should be noted that the device type of the terminal 101 includes at least one of: a smart phone, a tablet computer, a smart speaker, a smart watch, a smart handheld game device, a vehicle-mounted terminal, a laptop computer, and a desktop computer, but is not limited thereto. For example, the terminal 101 is a smart phone, or other handheld portable game device. The following embodiments are illustrated by taking the terminal 101 as an example including a smart phone.
[0103] Those skilled in the art will appreciate that the number of the above terminals may be more or less. For example, the above terminal may be only one, or the above terminals may be dozens or hundreds, or more. The embodiment of the present application does not limit the number of terminals and device types.
[0104] The following is an introduction to the basic process of hair rendering in an embodiment of the present application.
[0105] Figure 2 is a flow chart of a method for rendering hair of a virtual object provided by an embodiment of the present application. Figure 2 This embodiment is executed by an electronic device and is described by taking the electronic device as a terminal as an example. This embodiment includes the following steps:
[0106] 201. The terminal performs depth rendering on hair pixels of the virtual object to obtain depth values of the hair pixels.
[0107] In the embodiment of the present application, a virtual object refers to any movable object containing a hair area in a virtual scene, such as a virtual character, virtual animal, cartoon character, etc. containing a hair area. A virtual object can be a virtual object controlled by a user through a terminal, or other virtual objects located in the field of view (FoV) of the virtual object controlled by the user. Other virtual objects can be virtual objects controlled by other users through other terminals, or NPCs, wild monsters, companion robots, etc. that are not controlled by the user.
[0108] In the embodiment of the present application, a hair pixel refers to any pixel located in the hair area of the virtual object. In other words, a hair pixel is a pixel of any vertex on the hair model of the virtual object after being discretized by a rasterizer.
[0109] In some embodiments, a user starts a game application on a terminal, and the game application creates a game thread GameThread and a rendering thread RenderThread. If a virtual object needs to be displayed in the lobby interface of the game application, or if a user needs to display a virtual object in a virtual scene after the game application performs a start operation, steps 201-204 can be executed to render the hair area of the virtual object to achieve a high-quality semi-transparent hair rendering effect.
[0110] Since the game application will render the game screen stream in real time, the rendering process of any frame of the game screen in the game screen stream is taken as an example to illustrate. The game thread GameThread submits the scene resources of the virtual scene to the rendering thread RenderThread, and the rendering thread RenderThread determines the virtual objects in the virtual scene that are within the current camera FoV, and then performs OC detection on each virtual object within the FoV, and submits the virtual objects that pass the OC detection to RHIThread. RHIThread drives the rendering pipeline on the GPU through the drawing commands in the graphics API to render the virtual objects that pass the OC detection to obtain the game screen of the current frame.
[0111] When the GPU rendering pipeline draws the hair area of any virtual object detected by OC, after obtaining the hair model of the virtual object (such as the point cloud data and Mesh mesh of the hair), the color and depth of the frame buffer are cleared, the depth write switch of the frame buffer is turned on, and the depth value of each hair pixel indicated by the hair model is written into the frame buffer through the vertex shader. In the embodiment of the present application, only the rendering process of one hair pixel is used as an example for explanation.
[0112] 202. The terminal obtains a first highlight coefficient and a second highlight coefficient of the hair pixel based on the illumination information and the offset map, wherein the offset map indicates a deformation of a highlight formed by light irradiation, the first highlight coefficient indicates a highlight effect formed by light acting on the hair pixel, and the second highlight coefficient indicates hierarchical modification information of the first highlight coefficient.
[0113] In some embodiments, the terminal obtains lighting information of the virtual scene, where the lighting information represents illumination parameters of light generated by a light source in the virtual scene. Optionally, the lighting information at least includes a lighting vector (ie, a light vector).
[0114] In some embodiments, the terminal obtains an offset map of the hair region, and the offset map indicates the deformation of the highlight formed by the light irradiating the hair region of the virtual object. Optionally, the offset map is implemented as a (x, y, z) three-channel offset feature map (i.e., a three-dimensional matrix), the first channel indicates the highlight offset of each hair pixel in the hair region in the x direction, the second channel indicates the highlight offset of each hair pixel in the hair region in the y direction, and the third channel indicates the highlight offset of each hair pixel in the hair region in the z direction. Optionally, the offset map can also be implemented as a single-channel offset feature map, each element in the feature map is a scalar, recording the absolute value of the highlight offset of each hair pixel in the hair region. The embodiments of the present application do not specifically limit the implementation of the offset map.
[0115] In some embodiments, the above-mentioned lighting information can be calculated in real time according to the position of the light source in the virtual scene, and the above-mentioned offset map can be loaded by the terminal from the server or read from the local cache. The embodiment of the present application does not specifically limit the source of the offset map.
[0116] In some embodiments, based on the above-mentioned illumination information and the above-mentioned offset map, the terminal can use the hair illumination calculation model to perform two-layer highlight calculations on each hair pixel in the hair area, and obtain the first highlight coefficient of the first-layer highlight and the second highlight coefficient of the second-layer highlight. Among them, the first-layer highlight refers to the highlight effect directly formed by the light emitted by the light source hitting the hair area, and the second-layer highlight is also the highlight effect directly formed by the light emitted by the light source hitting the hair area, but the second-layer highlight has a highlight offset and a highlight range adjustment compared to the first-layer highlight, which plays the effect of modifying the first-layer highlight and enriching the level of the first-layer highlight. After the calculation results of the two layers of highlights are superimposed, the highlight effect level of the hair area of the virtual object is richer and the highlight effect is more realistic. The calculation method of each layer of highlights will be described in detail in the next embodiment and will not be repeated here.
[0117] 203. The terminal performs color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, and the diffuse reflection coefficient and shadow coefficient of the hair pixel to obtain a color value of the hair pixel, where the diffuse reflection coefficient indicates a dispersion condition caused by the light acting on the hair pixel, and the shadow coefficient indicates a shadow color caused by the light acting on the hair pixel.
[0118] In some embodiments, the terminal also needs to calculate the diffuse reflection coefficient of each hair pixel in the hair area, where the diffuse reflection coefficient reflects the dispersion caused by the light emitted by the light source hitting the hair area. Optionally, based on the lighting information and the hair material, a diffuse reflection lighting model is used to calculate the diffuse reflection coefficient of the hair pixel.
[0119] In some embodiments, the terminal also needs to calculate a shadow coefficient for each hair pixel in the hair area, where the shadow coefficient reflects the shape and color of the shadow caused by the light emitted by the light source hitting the hair area. Optionally, the shadow coefficient of the hair pixel is calculated based on a shadow map and shadow color control information.
[0120] In some embodiments, the terminal performs color rendering on each hair pixel in the hair area according to the diffuse reflection coefficient, shadow coefficient, the depth value written in step 201, and the first highlight coefficient and the second highlight coefficient calculated in step 202 to obtain the color value of each hair pixel.
[0121] In some embodiments, after calculating the depth value for each vertex in the hair model, the vertex shader writes the depth value of each vertex in the frame buffer. Then, the rasterizer is used to assemble the results output by the vertex shader into triangles and discretize the hair pixels according to the configured rasterization layer. Then, the pixel shader will implement the lighting calculation and color calculation involved in steps 202-203 for each hair pixel, fill in the color value of each hair pixel, and then write the color value of each hair pixel into the frame buffer.
[0122] 204. The terminal superimposes the depth value and the color value of each hair pixel of the virtual object to obtain a hair region of the virtual object.
[0123] In some embodiments, for each hair pixel in the hair area, the depth value and color value of the hair pixel in the frame buffer are superimposed to form a rendering effect of the hair pixel in the two-dimensional game screen, and the rendering results of all hair pixels constitute the entire hair area of the virtual avatar in the two-dimensional game screen.
[0124] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0125] The method provided in the embodiment of the present application can complete all the lighting calculations of each hair pixel in the hair area of the virtual object after only one depth rendering and one color rendering. In the process of color rendering, by calculating the highlight coefficients of the two layers of highlights, high-quality realistic hair rendering effects are guaranteed. The first layer of highlights simulates the highlight effect of the direct light source, and the second layer of highlights performs hierarchical modification on the first layer of highlights to increase the hierarchical nature and realism of the final highlights. Therefore, under the premise of ensuring that the hair rendering effect is not damaged, the calculation amount of the shader is reduced, the number of lighting rendering processes is compressed, and it can be adapted to the mobile terminal and meet the real-time frame rate operation requirements, and can achieve excellent rendering performance with extremely low rendering overhead. In addition, since it does not rely on the TAA calculation method, it does not rely on high screen resolution and will not generate noise in the hair area.
[0126] In the above embodiment, the basic process of hair rendering is briefly introduced, and in the embodiment of the present application, the calculation method of the double-layer highlight coefficient, diffuse reflection coefficient, shadow coefficient, etc. will be described in detail.
[0127] Figure 3 is a flow chart of a method for rendering hair of a virtual object provided by an embodiment of the present application. Figure 3 This embodiment is executed by an electronic device and is described by taking the electronic device as a terminal as an example. This embodiment includes the following steps:
[0128] 300. The terminal obtains a hair model of a virtual object, as well as a transparency map, an offset map, a shadow map, tangential disturbance information, negative normal disturbance information, first highlight indication information, second highlight indication information, shadow color control information, hair material, and hair roughness of the hair model.
[0129] In some embodiments, the terminal loads the model data of the hair model of the virtual object into the rendering engine, and the model data of the hair model includes but is not limited to the point cloud data and Mesh grid of the hair model. The hair model can be an independently split model, or it can be the model part of the hair area in the whole body model of the virtual object, and the embodiment of the present application does not specifically limit this. Among them, the point cloud data is the underlying model coordinate data of the hair model, and the Mesh grid is the grid of the hair model, which represents the hair skin data of the outer surface of the hair area indicated by the hair model. The main attributes of the Mesh grid include: vertex coordinates, normals, texture coordinates, triangle drawing sequence, etc.
[0130] In some embodiments, in addition to loading the model data of the hair model, the terminal also needs to load at least one of a transparency map, an offset map, a shadow map, tangential disturbance information, negative normal disturbance information, first highlight indication information, second highlight indication information, shadow color control information, hair material or hair roughness to prepare for the subsequent depth calculation and illumination calculation of the hair pixels. Below, each type of information that may be loaded in the preparation stage is described respectively.
[0131] 1) Transparency map: indicates the transparency of the hair area of the virtual object, and is used to determine the transparency mode of each hair pixel in the following step 301; in one embodiment, each element in the transparency map represents the opacity of the hair pixel at the same position in the hair area.
[0132] 2) Offset map: indicates the deformation of highlights formed by light irradiation, and is used to calculate the tangential highlight offset in the following step 304, and to calculate the negative normal highlight offset in the following step 306; in one embodiment, the offset map is implemented as a (x, y, z) three-channel offset feature map (i.e., a three-dimensional matrix), and the three elements at the same position on the three channels indicate the highlight offset of the hair pixels at the same position in the hair area in the (x, y, z) directions; in another embodiment, the offset map is implemented as a single-channel offset feature map, and each element in the feature map is a scalar, recording the absolute value of the highlight offset of the hair pixels at the same position in the hair area. The embodiment of the present application does not specifically limit the implementation of the offset map.
[0133] 3) Shadow map: indicates the shadow formed by the light shining on the hair area, and is used to calculate the shadow coefficient of each hair pixel in the following step 308; in one embodiment, each element in the shadow map represents whether the hair pixel at the same position in the hair area is in the shadow caused by the light. For example, the shadow map is a binary image, and the element value can only be 1 or 0. When the element value is 1, it means that the associated hair pixel is not in the shadow (i.e., it is illuminated), and when the element value is 0, it means that the associated hair pixel is in the shadow (i.e., it is not illuminated).
[0134] 4) Tangential disturbance information: indicating the disturbance amount of the offset applied in the tangential direction of the hair pixel, which is used to calculate the tangential highlight offset in the following step 304; in one embodiment, the tangential disturbance information is a fixed value, so that all hair pixels in the hair region have the same disturbance amount in the tangential direction; in another embodiment, the tangential disturbance information is a tangential disturbance map, and each element in the tangential disturbance map indicates the disturbance amount of the hair pixel at the same position in the hair region in the tangential direction, so that different tangential disturbances can be applied to the hair pixels at different positions in the hair region.
[0135] 5) Negative normal disturbance information: indicates the disturbance amount of the offset applied in the opposite direction of the normal direction of the hair pixel (i.e., the negative normal direction), and is used to calculate the negative normal highlight offset in the following step 306; in one embodiment, the negative normal disturbance information is a fixed value, so that all hair pixels in the hair region have the same disturbance amount in the negative normal direction; in another embodiment, the negative normal disturbance information is a negative normal disturbance map, and each element in the negative normal disturbance map indicates the disturbance amount of the hair pixel at the same position in the hair region in the negative normal direction, so that different negative normal disturbances can be applied to the hair pixels at different positions in the hair region.
[0136] 6) First highlight indication information: control information representing the highlight effect of the first-layer highlight directly formed by the light emitted by the light source hitting the hair area, and used to calculate the first highlight coefficient indicating the highlight effect of the first-layer highlight in the following step 305; in one embodiment, the first highlight indication information includes at least one of a first highlight intensity coefficient or a first highlight color coefficient, the first highlight intensity coefficient indicates the light intensity of the first-layer highlight, and the first highlight color coefficient indicates the highlight color of the first-layer highlight, so that the first-layer highlight can be customized in terms of light intensity and color, making the first-layer highlight more flexible and changeable, and can be adapted according to the color and type of the light source and the color and material of the hair, and has a wide range of application scenarios.
[0137] 7) Second highlight indication information: control information representing the highlight effect of the second layer of highlights directly formed by the light emitted by the light source hitting the hair area. Compared with the first layer of highlights, the second layer of highlights has a highlight offset and an adjustment of the highlight range, which has the effect of modifying the first layer of highlights and enriching the levels of the first layer of highlights. The information is used to calculate the second highlight coefficient indicating the highlight effect of the second layer of highlights in the following step 307; in one embodiment, the second highlight indication information includes at least one of a second highlight intensity coefficient or a second highlight color coefficient, the second highlight intensity coefficient indicates the illumination intensity of the second layer of highlights, and the second highlight color coefficient indicates the highlight color of the second layer of highlights. In this way, the second layer of highlights can be customized in terms of light intensity and color, making the second layer of highlights more flexible and changeable, and can be adapted according to the color and type of the light source and the color and material of the hair, and has a wide range of application scenarios.
[0138] 8) Shadow color control information: used to control the color of the shadow formed by the light irradiating the hair region, and used to calculate the shadow coefficient of each hair pixel in the following step 308; in one embodiment, the shadow color control information is a fixed value, so that all hair pixels in the hair region that are in the shadow have the same shadow color; in another embodiment, the shadow color control information is a shadow color control map, in which each element indicates the shadow color of the hair pixels at the same position in the hair region if they are in the shadow, so that different shadow colors can be customized for the hair pixels at different positions in the hair region.
[0139] 9) Hair material: indicates the material color of the hair pixels in the hair region, which is used to calculate the diffuse reflectance coefficient of each hair pixel in the following step 303; in one embodiment, the hair material is a material map, and the basic material color is recorded in the attribute information of the material map.
[0140] 10) Hair roughness: indicates the roughness of the hair pixels in the hair region. In other words, it also reflects the smoothness of the hair pixels in the hair region, and is used to calculate the diffuse reflectance coefficient of each hair pixel in the following step 303. In some embodiments, the hair roughness is a fixed value, so that the roughness of all hair pixels in the hair region is the same. In another embodiment, the hair roughness is a roughness control map, and each element in the roughness control map indicates the roughness of the hair pixels at the same position in the hair region. In this way, different roughness can be customized for hair pixels at different positions in the hair region. For example, the roughness of the hair ends is higher, simulating the visual effect of frizzy hair ends, while the roughness of the hair center is lower, simulating the visual effect of smoother hair center.
[0141] In some embodiments, for the sake of simplicity, the 10 types of information 1) to 10) are collectively referred to as hair rendering parameter information. When loading the hair rendering parameter information, the terminal may directly read part or all of the hair rendering parameter information 1) to 10) from the cache, or the terminal may pull part or all of the hair rendering parameter information 1) to 10) from the server. For example, the terminal sends a hair rendering parameter request carrying an object ID (Identification) of a virtual object to the server, and the server returns part or all of the hair rendering parameter information 1) to 10) to the terminal in response to the hair rendering parameter request.
[0142] It should be noted that when the terminal loads the 10 types of hair rendering parameter information 1) to 10) above, it can load part or all of them according to the rendering requirements. For example, if there is no need to control the shadow color, then there is no need to load the shadow color control information, and the default value of the shadow (black) is directly used. For another example, if there is no need to control the highlight color, then in the first highlight indication information and the second highlight indication information, only the first highlight intensity coefficient and the second highlight intensity coefficient need to be loaded respectively, and there is no need to load the first highlight color coefficient and the second highlight color coefficient, and the color of the light is directly inherited or the color of the hair is mixed with the color of the light. For another example, if there is no need to control the roughness of the hair, there is no need to load the roughness of the hair, and so on. In the embodiment of the present application, the loading of all the information 1) to 10) above in the preparation stage is taken as an example for explanation, but it can be adapted on demand according to different game applications, different models of terminals, different virtual objects, different hairstyles, etc., and the embodiment of the present application does not specifically limit this.
[0143] In an example, in the preparation stage, we first create a hair lighting model Kajiya_k ShadingModel and modify the C++ code of the underlying rendering pipeline. Here we need to pay attention to the macro naming rules and the number limit of lighting models. Figure 4 As shown, in the material editing interface 400 of the game engine, the lighting model 405 (Shading Model) of the hair area can be customized to select "Kajiya_k". In addition, in the material editing interface 400, the material domain 401 (Material Domain) of the hair area can be customized to select "Surface", the blending mode 402 (Blend Mode) and the decal blending mode 403 (Decal Blend Mode) can both select "Translucent", and the depth test mode 404 (Depth Function) can select "NearOrEqual". In addition, in the material editing interface 400, it is also possible to control whether to turn on the double-sided material switch 406 (Two Sided), the use of material attributes switch 407 (Use MaterialAttributes) and the cast ray traced shadow switch 408 (Cast Ray Traced Shadow).
[0144] After the hair illumination model Kajiya_k is created, part or all of the hair rendering parameter information in 1) to 10) that has been loaded above needs to be passed into the hair illumination model Kajiya_k, so as to prepare for illumination calculation of each hair pixel. Exemplarily, the hair rendering parameter information passed into the hair illumination model Kajiya_k includes but is not limited to: offset map ShiftTex, tangent perturbation information PrimaryShift, negative normal perturbation information SecondaryShift, first highlight indication information (including first highlight intensity coefficient PrimarySpecScale and first highlight color coefficient PrimaryColor), second highlight indication information (including second highlight intensity coefficient SecondSpecScale and second highlight color coefficient SecondColor), and shadow color control information HairShadowColor. In addition, the normal vector NormalDir (indicating the normal direction) and negative normal vector Bitnormal (indicating the negative normal direction) of the current hair pixel are also obtained.
[0145] Next, before executing the following step 303, it is necessary to complete the variable declaration of the above hair rendering parameter information in sequence in the pixel basic color rendering pipeline (Base Pass Pixel) of the hair lighting model Kajiya_k:
[0146] ShadingModelContext.ShiftTex=saturate(GetCustomData0(MaterialParameters).r);
[0147] ShadingModelContext.PrimaryShift=GetCustomData1(MaterialParameters).r;
[0148] ShadingModelContext.SecondaryShift=GetCustomData1(MaterialParameters).g;
[0149] ShadingModelContext.PrimarySpecScale=GetCustomData1(MaterialParameters).b;
[0150] ShadingModelContext.SecondSpecScale=GetCustomData1(MaterialParameters).a;
[0151] ShadingModelContext.Bitnormal=GetCustomData2(MaterialParameters).xyz;
[0152] ShadingModelContext.NormalDri=GetCustomData3(MaterialParameters).xyz;
[0153] ShadingModelContext.PrimaryColor=saturate(GetCustomData4(MaterialParameters).rgb);
[0154] ShadingModelContext.SecondColor=saturate(GetCustomData5(MaterialParameters).rgb);
[0155] ShadingModelContext.HairShadowColor=saturate(GetCustomData6(MaterialParameters).rgb);
[0156] It should be noted that since the lighting rendering of the virtual object's hair needs to calculate the offset, color, intensity, etc. of the double-layer highlight, the amount of data passed in for the hair rendering parameter information is relatively large, so at least 6 sets of variable controls are required, and finally the normal vector, negative normal vector and shadow color control information are added.
[0157] 301. The terminal determines a transparency mode of hair pixels of the virtual object based on the transparency map.
[0158] The transparency mode indicates whether the hair pixel is opaque or semi-transparent.
[0159] In some embodiments, after the terminal performs the hair illumination model Kajiya_k, it enters the depth only rendering pipeline (Depth Only Pass), in which only each hair pixel is written to depth, which can be regarded as a process of precalculating the depth value of each hair pixel of the translucent material. This depth only rendering pipeline can be implemented in the vertex shader.
[0160] In some embodiments, Figure 5 As shown, in the depth rendering stage of the hair area, the color and depth of the frame buffer are first cleared (ClearDepthStencilView), then the depth write switch of the frame buffer is turned on, and the depth-only rendering pipeline (MobileRenderPrePass, which refers to the pre-rendering depth pipeline for mobile terminal debugging, is an implementation of the depth-only rendering pipeline) is run to pre-calculate the depth value of each hair pixel through this step 301 and the next step 302, and write the depth value of each hair pixel into the frame buffer. It can be seen that when rendering the virtual object A here, the basic phase (Master Phase) of the hair illumination model Kajiya_k and the basic phase of the hair model Hair are used, wherein the drawing command ID (i.e., DrawIndexed) of the hair illumination model Kajiya_k and the hair model Hair are both 36888.
[0161] In some embodiments, different transparency modes can be configured for hair pixels at different positions in the hair region of the virtual object. In this case, the transparency mode of each hair pixel can be determined through steps 301-302, and depth writing can be performed according to the transparency mode. In this step 301, this case is taken as an example for explanation. For each hair pixel in the hair region, the opacity of the hair pixel is obtained based on the transparency map of the hair model. Then, the opacity is compared with a preset clipping threshold. If the opacity is greater than the clipping threshold, the transparency mode of the hair pixel is determined to be opaque. If the opacity is not greater than the clipping threshold, the transparency of the hair pixel is determined to be semi-transparent. The clipping threshold is a preset fixed value greater than or equal to 0, which is pre-configured by a technician. Different hair models can have the same or different clipping thresholds.
[0162] In the above process, by configuring the opacity of each hair pixel in the transparency map, the hair pixels at different positions in the hair area can be controlled to have different transparency modes. For example, the edge hair pixels of the hair area are controlled not to be greater than the cropping threshold, and the center hair pixels of the hair area are greater than the cropping threshold, so that the center hair pixels adopt an opaque mode and the edge hair pixels adopt a semi-transparent mode. In this way, whether the hair pixels at different positions in the hair area are semi-transparent can be accurately controlled, thereby improving the controllability of hair transparency.
[0163] In some other embodiments, the same transparency mode may be configured for all hair pixels in the hair region of the virtual object. In this case, the depth of each hair pixel may be written directly based on the preset transparency mode without determining the depth mode of each hair pixel. For example, the transparency mode of all hair pixels is preset to an opaque mode, and the depth value of each hair pixel is written through the transparency test AlphaTest mode.
[0164] 302. The terminal performs depth writing on the hair pixel based on the transparent mode of the hair pixel to obtain a depth value of the hair pixel.
[0165] In some embodiments, for each hair pixel in the hair area, when the transparency mode of the hair pixel is semi-transparent, the depth value of the hair pixel is written in the transparent blending Blend mode; when the transparency mode of the hair pixel is opaque, the depth value of the hair pixel is written in the transparent testing AlphaTest mode.
[0166] In the above process, by configuring the opacity of each hair pixel in the transparency map, the hair pixels at different positions in the hair area can be controlled to have different transparency modes. For example, after controlling the central hair pixel to adopt the opaque mode and the edge hair pixel to adopt the semi-transparent mode, the central hair of the hair area ensures the correct depth sorting in the opaque mode, and the thicker hair will not produce a semi-transparent perspective effect. The edge hair of the hair area is relatively thin, so it can produce a semi-transparent perspective effect in the semi-transparent mode, making the overall rendering effect of the hair area more realistic.
[0167] In an example, the clipping function Clip() value is used to perform translucent depth blending calculations, as shown in the following code:
[0168] #if MATERIALBLENDING_TRANSLUCENT
[0169] clip(GetMaterialOpacity(PixelMaterialInputs)-GetMaterialOpacityMaskClipValue());
[0170] Among them, Clip() is the clipping function, PixelMaterialInputs is the transparency channel of the input material map (i.e., transparency map), GetMaterialOpacity() is used to obtain the opacity of hair pixels, and GetMaterialOpacityMaskClipValue() is used to obtain the preset clipping threshold.
[0171] In this way, in the transparency test AlphaTest mode, if the subtraction of opacity and clipping threshold is a positive number, then the opaque depth value of the hair pixel is directly written. If the subtraction of opacity and clipping threshold is a negative number or 0, the Clip() function will be used to clip the hair pixel. This means that the hair pixels clipped by the Clip() function need to be deeply rendered using the semi-transparent mode. Therefore, the Blend() function can be used to calculate the semi-transparent depth value of the hair pixels clipped by the Clip() function and write the semi-transparent depth value to the frame buffer.
[0172] In steps 301-302, a possible implementation method of performing depth rendering on the hair pixels of the virtual object to obtain the depth value of the hair pixels is provided. Steps 301-302 are performed on each hair pixel in the hair area of the virtual object. After traversing all the hair pixels, a depth map of the hair area is obtained, such as Figure 6As shown, the far left side shows a depth map 601 of a virtual object A after depth rendering. For ease of explanation, the edge hair in the rectangular framed portion will be written with a semi-transparent depth value, and the center hair will be written with an opaque depth value.
[0173] 303. The terminal obtains a diffuse reflection coefficient of the hair pixel based on the illumination information of the virtual scene, the hair material, and the roughness of the hair.
[0174] The diffuse reflectance coefficient indicates the dispersion condition caused by the light acting on the hair pixel.
[0175] In some embodiments, after the terminal has created the hair illumination model Kajiya_k and has obtained a depth map by performing depth writing on all hair pixels through the depth rendering relationship only, it runs the pixel basic color rendering pipeline (BasePass Pixel). Before running the pixel basic color rendering pipeline, it is necessary to load various hair rendering parameter information involved in step 300 and complete variable declaration. This stage can be called the data preparation stage of the pixel basic color rendering pipeline. Then, through this step 303, the diffuse reflection coefficient can be calculated for each hair pixel.
[0176] In some embodiments, for each hair pixel in the hair area, the diffuse reflection part is calculated using the half-Lambert illumination model as an example. The half-Lambert illumination model can calculate the diffuse reflection coefficient of the hair pixel through the following steps A1 to A3:
[0177] A1. The terminal obtains the dot product of the illumination vector and the normal vector in the illumination information.
[0178] In some embodiments, the terminal determines the illumination vector L and the normal vector N from the illumination information, and then calculates the dot product of the illumination vector L and the normal vector N to obtain the dot product NL.
[0179] A2. The terminal performs interpolation processing based on the hair roughness to obtain a brightness adjustment coefficient.
[0180] In some embodiments, the terminal interpolates the hair roughness R based on the interpolation function Lerp() to obtain a light and dark adjustment coefficient of the diffuse reflection part. For example, the light and dark adjustment coefficient is calculated by Lerp(1.0, 0.5, R), so that the hair roughness R and the light and dark adjustment coefficient can be controlled to be inversely proportional, that is, the greater the hair roughness R, the greater the roughness, the less smooth the hair, and the smaller the light and dark adjustment coefficient value is, which means that the value of the diffuse reflection coefficient will be controlled to be reduced, so that the diffuse reflection result becomes darker.
[0181] In an example, the hair roughness R is a value between [0,1]. When Lerp (1.0, 0.5, R) is used to calculate the shading coefficient, when R is at the left endpoint, i.e., the minimum value 0, the shading coefficient is at the maximum value 1, which can ensure that the diffuse reflection result of smooth hair does not darken. When R is at the right endpoint, i.e., the maximum value 1, the shading coefficient is at the minimum value 0.5, which can control the diffuse reflection result of rough hair to darken.
[0182] A3. The terminal obtains the diffuse reflection coefficient of the hair pixel based on the hair material, the dot product and the brightness adjustment coefficient.
[0183] In some embodiments, the diffuse reflectance of each hair pixel is calculated in a Half-Lambert lighting model based on the following formula in the hair material:
[0184] Diffuse=Basecolor*(NL*0.5+0.5)*Lerp(1.0,0.5,R)
[0185] Among them, Diffuse is the diffuse reflection coefficient, Basecolor is the basic material color in the hair material, NL is the dot product calculated in step A1, Lerp (1.0, 0.5, R) is the light and dark adjustment coefficient calculated in step A2, and R represents the roughness of the hair.
[0186] In the above steps A1 to A3, a possible implementation method of using a semi-Lambert illumination model to calculate the diffuse reflection coefficient of each hair pixel is provided, which can avoid the dark part of the hair area being too dark, and mix the hair roughness to adjust the diffuse reflection coefficient, so that the rougher the part of the hair, the darker the diffuse reflection result, making the diffuse reflection coefficient more accurate.
[0187] In other embodiments, other diffuse reflection illumination models may be used to calculate the diffuse reflection coefficient of each hair pixel, such as the Lambert illumination model, etc., which is not specifically limited in the present embodiment. Alternatively, if the diffuse reflection of light in the hair area is ignored, step 303 may not be performed, and the diffuse reflection coefficient of the hair pixel does not need to be calculated.
[0188] 304. The terminal determines a tangential highlight offset of the hair pixel based on the offset map and the tangential disturbance information.
[0189] The tangential highlight offset indicates the offset of the highlight of the hair pixel in the tangential direction.
[0190] In some embodiments, the terminal may determine a normal vector N and a tangent vector T for each hair pixel, and calculate a tangential highlight offset T of the hair pixel according to the normal vector N, the tangent vector T, the offset map ShiftTex obtained in step 300, and the tangential disturbance information PrimaryShift. o .
[0191] In one embodiment, the offset map ShiftTex is implemented as a (x, y, z) three-channel offset feature map (i.e., a three-dimensional matrix), and the three elements at the same position on the three channels indicate the highlight offset of the hair pixels at the same position in the hair area in the three directions of (x, y, z); in another embodiment, the offset map ShiftTex is implemented as a single-channel offset feature map, and each element in the feature map is a scalar, recording the absolute value of the highlight offset of the hair pixels at the same position in the hair area. The embodiment of the present application does not specifically limit the implementation of the offset map.
[0192] In one embodiment, the tangential disturbance information is a fixed value, so that all hair pixels in the hair region have the same disturbance amount in the tangential direction; in another embodiment, the tangential disturbance information is a tangential disturbance map, and each element in the tangential disturbance map indicates the disturbance amount of the hair pixels at the same position in the hair region in the tangential direction, so that different tangential disturbances can be applied to the hair pixels at different positions in the hair region.
[0193] In some embodiments, the offset map ShiftTex is implemented as a single-channel offset feature map as an example for explanation, and the feature value identical to the hair pixel position is taken out from the offset map ShiftTex as the initial offset of the hair pixel. Then, if the tangential perturbation information PrimaryShift is a fixed value, the fixed value is read as the offset perturbation of the hair pixel, and if the tangential perturbation information PrimaryShift is a tangential perturbation map, the element identical to the hair pixel position is taken out from the tangential perturbation map as the offset perturbation of the hair pixel. Next, the initial offset and the offset disturbance are added to obtain an intermediate offset, the normal vector N is multiplied by the intermediate offset to obtain a normal offset, and the normal offset is added to the tangent vector T to obtain an initial tangential offset. After the initial tangential offsets are calculated for all hair pixels, the initial tangential offsets of each avatar pixel are normalized using the initial tangential offsets of all hair pixels, and the normalized initial tangential offset of each hair pixel is used as the tangential highlight offset of the hair pixel. That is, the above method for obtaining the tangential highlight offset is expressed by the following formula:
[0194] T o=normalize(N*(ShiftTex+PrimaryShift)+T)
[0195] Among them, T o represents the tangent highlight offset, normalize() represents the normalization function, N represents the normal vector, ShiftTex represents the offset map (actually, the initial offset found in the offset map is substituted), PrimaryShift represents the tangent perturbation information (actually, the offset perturbation is substituted, which can be a fixed value or an element found in the tangent perturbation map), and T represents the tangent vector. Obviously, (ShiftTex+PrimaryShift) represents the intermediate offset, N*(ShiftTex+PrimaryShift) represents the normal offset, and (N*(ShiftTex+PrimaryShift)+T) represents the initial tangent offset.
[0196] In this step 304, by calculating the tangential highlight offset of each hair pixel, the highlight shape of the hair area can be stretched based on the offset map ShiftTex, so that the highlight shape in the hair area is richer, and different offset maps can be configured for different virtual objects or different hairstyles of the same virtual object to achieve flexible configuration of the hair appearance. Furthermore, the tangential perturbation information PrimaryShift can be used to control how far the primary highlight is offset in the tangential direction, and based on the initial offset of the offset map ShiftTex, the offset perturbation in the tangential direction can be customized for the primary highlight, so that the highlight effect of the primary highlight is more natural.
[0197] 305. The terminal obtains a first highlight coefficient of the hair pixel based on the illumination information, the tangential highlight offset, and the first highlight indication information.
[0198] The first highlight coefficient indicates a highlight effect formed when light acts on the hair pixel.
[0199] Next, the basic principle of the hair lighting model Kajiya_k is explained: Assuming that the hair normal vector N is located in the plane determined by the tangent vector T and the sight vector V, in the lighting equation of the anisotropic hair lighting model Kajiya_k, the tangent vector T is used instead of the normal vector N. In this way, the light equation of the specular reflection term is as follows:
[0200] Among them, specularity represents the first layer of highlight of specular reflection, T represents the tangent vector, H represents the half-angle vector, and dot() is a function for finding the dot product of two vectors, that is, dot(T,H) represents the dot product of the tangent vector T and the radius vector H.
[0201] In the hair lighting model Kajiya_k, according to the lighting vector L and the sight vector V in the lighting information, the lighting vector L and the sight vector V are added to obtain the half-angle vector H, and then the first highlight indication information obtained in step 300 and the tangential highlight offset T calculated in step 304 are used. o , to calculate the first specular coefficient of each hair pixel based on specular reflection.
[0202] In one embodiment, the first highlight indication information includes at least one of a first highlight intensity coefficient or a first highlight color coefficient. The first highlight intensity coefficient indicates the light intensity of the first-layer highlight, and the first highlight color coefficient indicates the highlight color of the first-layer highlight. This enables customized control of the first-layer highlight in two dimensions of light intensity and color, making the first-layer highlight more flexible and changeable, and can be adapted according to the color and type of the light source, and the color and material of the hair, and has a wide range of application scenarios.
[0203] Hereinafter, a possible method for obtaining the first highlight coefficient will be described by taking the first highlight indication information including the first highlight intensity coefficient and the first highlight color coefficient as an example, referring to steps B1 to B3:
[0204] B1. The terminal determines the half-angle vector of the hair pixel based on the illumination vector and the sight line vector in the illumination information.
[0205] In some embodiments, the terminal determines the illumination vector L and the sight vector V from the illumination information, adds the illumination vector L and the sight vector V, and obtains the half-angle vector H.
[0206] B2. The terminal determines a first intensity control coefficient based on the tangential highlight offset, the half-angle vector and the first highlight intensity coefficient.
[0207] The first intensity control coefficient indicates the offset and light intensity of the first layer highlight in the tangent direction.
[0208] In one embodiment, the first highlight intensity coefficient is a fixed value, so that all hair pixels in the hair area have the same illumination intensity in the first-layer highlight; in another embodiment, the first highlight intensity coefficient is a first-layer highlight intensity map, and each element in the first-layer highlight intensity map indicates the illumination intensity of the hair pixels at the same position in the hair area in the first-layer highlight, so that different first-layer highlight illumination intensities can be configured for hair pixels at different positions in the hair area.
[0209] In some embodiments, if the first highlight intensity coefficient is a fixed value, the fixed value may be directly read as the first highlight intensity coefficient of the hair pixel; if the first highlight intensity coefficient is a first-layer highlight intensity map, the element at the same position as the hair pixel is taken from the first-layer highlight intensity map as the first highlight intensity coefficient of the hair pixel.
[0210] Next, the terminal calculates the tangential highlight offset T calculated in step 304 o The half-angle vector H calculated in step B1 and the first highlight intensity coefficient PrimarySpecScale of the hair pixel are input into the hair illumination model Kajiya_k, and the first intensity control coefficient is calculated by the hair illumination model Kajiya_k. For example, the tangential highlight offset T o Substitute T into the light equation of the specular reflection term, substitute the half-angle vector H into H in the light equation of the specular reflection term, multiply the specular reflection highlight coefficient calculated by the light equation by the first highlight intensity coefficient PrimarySpecScale to obtain the first intensity control coefficient.
[0211] In one example, the process of calculating the first intensity control coefficient in steps B1 to B2 can be implemented by the specular reflection function KajiyaSpecualr() of the hair illumination model Kajiya_k. In this case, only the tangential highlight offset T o , the illumination vector L, the sight vector V and the first highlight intensity coefficient PrimarySpecScale are input into the specular reflection function KajiyaSpecualr(), and the specular reflection function directly outputs the first intensity control coefficient KajiyaSpecualr(T o ,V,L,PrimarySpecScale). The calculation principle of the specular reflection function refers to steps B1 to B2 and will not be described in detail.
[0212] B3. The terminal multiplies the first intensity control coefficient and the first highlight color coefficient to obtain the first highlight coefficient.
[0213] In one embodiment, the first highlight color coefficient is a fixed value, so that all hair pixels in the hair region have the same highlight color in the first-layer highlight; in another embodiment, the first highlight color coefficient is a first-layer highlight color map, and each element in the first-layer highlight color map indicates the highlight color of the hair pixels at the same position in the hair region in the first-layer highlight, so that different highlight colors of the first-layer highlight can be configured for hair pixels at different positions in the hair region.
[0214] In some embodiments, if the first highlight color coefficient is a fixed value, the fixed value may be directly read as the first highlight color coefficient of the hair pixel; if the first highlight color coefficient is a first-layer highlight color map, an element at the same position as the hair pixel is taken from the first-layer highlight color map as the first highlight color coefficient of the hair pixel.
[0215] Next, the terminal calculates the first intensity control coefficient KajiyaSpecualr (T o ,V,L,PrimarySpecScale), multiplied by the first highlight color coefficient PrimaryColor of the hair pixel, to obtain the first highlight coefficient KajiyaSpecualr (T o ,V,L,PrimarySpecScale)*PrimaryColor, the first highlight coefficient is used to indicate the highlight effect of the first layer of highlight.
[0216] In the above steps 304-305, a possible implementation method for obtaining the first highlight coefficient of the hair pixel based on the illumination information and the offset map is provided, that is, the example of controlling both the illumination intensity and the highlight color of the first-layer highlight is used for explanation. Optionally, when the highlight color of the first-layer highlight is not controlled, the first highlight indication information only includes the first highlight intensity coefficient, and the first intensity control coefficient of step B2 can be directly used as the first highlight coefficient. Optionally, when the illumination intensity of the first-layer highlight is not controlled, the first highlight indication information only includes the first highlight color coefficient, and the specular reflection highlight coefficient calculated by the light equation of the specular reflection term can be directly multiplied by the first highlight color coefficient to obtain the first highlight coefficient.
[0217] 306. The terminal determines a negative normal highlight offset of the hair pixel based on the offset map and the negative normal disturbance information.
[0218] The negative normal highlight offset indicates an offset of the hair pixel in the opposite direction of the normal direction.
[0219] In some embodiments, the terminal can determine the normal vector N and the negative normal vector B for each hair pixel, and calculate the negative normal highlight offset B of the hair pixel according to the normal vector N, the negative normal vector B, the offset map ShiftTex and the negative normal disturbance information SecondaryShift obtained in step 300. o The implementation of the offset map ShiftTex is described in step 304 and will not be described in detail.
[0220] In one embodiment, the negative normal perturbation information is a fixed value, so that all hair pixels in the hair region have the same perturbation amount in the opposite direction of the normal direction; in another embodiment, the negative normal perturbation information is a negative normal perturbation map, and each element in the negative normal perturbation map indicates the perturbation amount of the hair pixels at the same position in the hair region in the opposite direction of the normal direction, so that different negative normal perturbations can be applied to the hair pixels at different positions in the hair region.
[0221] In some embodiments, the offset map ShiftTex is implemented as a single-channel offset feature map as an example for explanation, and the feature value at the same position as the hair pixel is taken out from the offset map ShiftTex as the initial offset of the hair pixel. Then, if the negative normal perturbation information SecondaryShift is a fixed value, the fixed value is read as the offset perturbation of the hair pixel, and if the negative normal perturbation information SecondaryShift is a negative normal perturbation map, the element at the same position as the hair pixel is taken out from the negative normal perturbation map as the offset perturbation of the hair pixel. Next, the initial offset is added to the offset disturbance to obtain an intermediate offset, the normal vector N is multiplied by the intermediate offset to obtain a normal offset, and the normal offset is added to the negative normal vector B to obtain an initial negative normal offset. After the initial negative normal offsets are calculated for all hair pixels, the initial negative normal offsets of each avatar pixel are normalized using the initial negative normal offsets of all hair pixels, and the normalized initial negative normal offset of each hair pixel is used as the negative normal highlight offset of the hair pixel. That is, the above method for obtaining the negative normal highlight offset is expressed by the following formula:
[0222] B o =normalize(N*(ShiftTex+SecondaryShift)+B)
[0223] Among them, B o Represents the negative normal highlight offset, normalize() represents the normalization function, N represents the normal vector, ShiftTex represents the offset map (actually, the initial offset found in the offset map is substituted), SecondaryShift represents the negative normal perturbation information (actually, the offset perturbation is substituted, which can be a fixed value or an element found in the negative normal perturbation map), and B represents the negative normal vector. Obviously, (ShiftTex+SecondaryShift) represents the intermediate offset, N*(ShiftTex+SecondaryShift) represents the normal offset, and (N*(ShiftTex+SecondaryShift)+B) represents the initial negative normal offset.
[0224] In this step 306, by calculating the negative normal highlight offset of each hair pixel, the highlight shape of the hair area can be stretched based on the offset map ShiftTex, so that the highlight shape in the hair area is richer, and different offset maps can be configured for different virtual objects or different hairstyles of the same virtual object to achieve flexible configuration of the hair appearance. Furthermore, through the negative normal perturbation information SecondaryShift, it is possible to control how far the second-layer highlight is offset in the opposite direction of the normal direction. Based on the initial offset of the offset map ShiftTex, the offset perturbation in the opposite direction of the normal direction can be customized for the second-layer highlight, so that the highlight effect of the second-layer highlight is more natural.
[0225] Furthermore, since the first layer of highlights applies an offset disturbance in the tangent direction and the second layer of highlights applies an offset disturbance in the negative normal direction, the highlight effect of the two layers of highlights is not a simple repeated superposition, but the double layers of highlights have a multi-level highlight effect when superimposed. The second layer of highlights modifies the first layer of highlights, greatly enriches and increases the sense of layering of the first layer of highlights, so that the double layer of highlights can simulate a very natural and realistic highlight effect.
[0226] 307. The terminal obtains a second highlight coefficient of the hair pixel based on the illumination information, the negative normal highlight offset, and the second highlight indication information.
[0227] The second highlight coefficient indicates level modification information of the first highlight coefficient.
[0228] In the hair lighting model Kajiya_k, according to the lighting vector L and the sight vector V in the lighting information, the lighting vector L and the sight vector V are added to obtain the half-angle vector H, and then the second highlight indication information obtained in step 300 and the negative normal highlight offset B calculated in step 306 are used. o , to calculate the second specular coefficient for each hair pixel based on specular reflection.
[0229] In one embodiment, the second highlight indication information includes at least one of a second highlight intensity coefficient or a second highlight color coefficient, the second highlight intensity coefficient indicates the light intensity of the second layer of highlights, and the second highlight color coefficient indicates the highlight color of the second layer of highlights. In this way, customized control of the two dimensions of light intensity and color of the two-layer highlights can be achieved, making the two-layer highlights more flexible and changeable, and can be adapted according to the color and type of the light source, and the color and material of the hair, and has a wide range of application scenarios.
[0230] Hereinafter, a possible method for obtaining the second highlight coefficient will be described by taking the second highlight indication information including the second highlight intensity coefficient and the second highlight color coefficient as an example, referring to steps C1 to C3:
[0231] C1. The terminal determines the half-angle vector of the hair pixel based on the illumination vector and the sight line vector in the illumination information.
[0232] The above step C1 is similar to the above step B1 and will not be described in detail. If the half-angle vector H is cached when executing step B1, the cached half-angle vector H can be directly read without performing redundant calculations.
[0233] C2. The terminal determines a second intensity control coefficient based on the negative normal highlight offset, the half-angle vector and the second highlight intensity coefficient.
[0234] The second intensity control coefficient indicates the offset and light intensity of the second layer of highlights in the opposite direction of the normal direction.
[0235] In one embodiment, the second highlight intensity coefficient is a fixed value, so that all hair pixels in the hair area have the same illumination intensity in the second layer of highlights; in another embodiment, the second highlight intensity coefficient is a two-layer highlight intensity map, and each element in the two-layer highlight intensity map indicates the illumination intensity of the hair pixel at the same position in the hair area in the second layer of highlights, so that different illumination intensities of the second layer of highlights can be configured for hair pixels at different positions in the hair area.
[0236] In some embodiments, if the second highlight intensity coefficient is a fixed value, the fixed value may be directly read as the second highlight intensity coefficient of the hair pixel; if the second highlight intensity coefficient is a two-layer highlight intensity map, the element at the same position as the hair pixel is taken from the two-layer highlight intensity map as the second highlight intensity coefficient of the hair pixel.
[0237] Next, the terminal calculates the negative normal highlight offset B obtained in step 306. o , the half-angle vector H calculated in step C1 and the second highlight intensity coefficient SecondSpecScale of the hair pixel are input into the hair illumination model Kajiya_k, and the second intensity control coefficient is calculated by the hair illumination model Kajiya_k. For example, the negative normal highlight offset B o Substitute T into the light equation of the specular reflection term, substitute the half-angle vector H into H in the light equation of the specular reflection term, multiply the specular reflection highlight coefficient calculated by the light equation by the second highlight intensity coefficient SecondSpecScale to obtain the second intensity control coefficient.
[0238] In one example, the process of calculating the second intensity control coefficient in steps C1 to C2 can be implemented by the specular reflection function KajiyaSpecualr() of the hair illumination model Kajiya_k. In this case, only the negative normal highlight offset B o , the illumination vector L, the sight vector V and the second highlight intensity coefficient SecondSpecScale are input into the specular reflection function KajiyaSpecualr(), and the specular reflection function directly outputs the second intensity control coefficient KajiyaSpecualr(B o ,V,L,SecondSpecScale). The calculation principle of the specular reflection function refers to steps C1 to C2 and will not be repeated here.
[0239] C3. The terminal multiplies the second intensity control coefficient and the second highlight color coefficient to obtain the second highlight coefficient.
[0240] In one embodiment, the second highlight color coefficient is a fixed value, so that all hair pixels in the hair region have the same highlight color in the second-layer highlight; in another embodiment, the second highlight color coefficient is a two-layer highlight color map, and each element in the two-layer highlight color map indicates the highlight color of the hair pixel at the same position in the hair region in the second-layer highlight, so that different highlight colors of the second-layer highlight can be configured for hair pixels at different positions in the hair region.
[0241] In some embodiments, if the second highlight color coefficient is a fixed value, the fixed value may be directly read as the second highlight color coefficient of the hair pixel; if the second highlight color coefficient is a two-layer highlight color map, the element at the same position as the hair pixel is taken from the two-layer highlight color map as the second highlight color coefficient of the hair pixel.
[0242] Next, the terminal calculates the second intensity control coefficient KajiyaSpecualr (B o ,V,L,SecondSpecScale), multiplied by the second highlight color coefficient SecondColor of the hair pixel, to obtain the second highlight coefficient KajiyaSpecualr (B o ,V,L,SecondSpecScale)*SecondColor, the second highlight coefficient is used to indicate the highlight effect of the second layer of highlight.
[0243] In the above steps 306-307, a possible implementation method for obtaining the second highlight coefficient of the hair pixel based on the illumination information and the offset map is provided, that is, the second highlight coefficient is obtained by controlling both the illumination intensity of the second-layer highlight and the highlight color of the second-layer highlight. Optionally, when the highlight color of the second-layer highlight is not controlled, the second highlight indication information only includes the second highlight intensity coefficient, and the second intensity control coefficient of step C2 can be directly used as the second highlight coefficient. Optionally, when the illumination intensity of the second-layer highlight is not controlled, the second highlight indication information only includes the second highlight color coefficient, and the second highlight color coefficient can be directly multiplied by the specular reflection highlight coefficient calculated by the light equation of the specular reflection term to obtain the second highlight coefficient.
[0244] In the above steps 304-307, a possible implementation method for obtaining the first highlight coefficient and the second highlight coefficient of the hair pixel based on the illumination information and the offset map is provided. The first highlight coefficient and the second highlight coefficient are added to obtain the target highlight coefficient after the double-layer highlight of the hair pixel is superimposed. The target highlight coefficient represents the final highlight calculation result after the double-layer highlight is superimposed.
[0245] In an example, the target highlight coefficient can be expressed as the following formula:
[0246] Specualr = KajiyaSpecualr (T o ,V,L,PrimarySpecScale)*PrimaryColor
[0247] +KajiyaSpecualr(B o ,V,L,SecondSpecScale)*SecondColor
[0248] Among them, KajiyaSpecualr(T o ,V,L,PrimarySpecScale)*PrimaryColor is the first highlight coefficient, KajiyaSpecualr(B o ,V,L,SecondSpecScale)*SecondColor is the second highlight coefficient, and Specualr is the target highlight coefficient.
[0249] 308. The terminal performs interpolation processing based on the shadow map and the shadow color control information to obtain a shadow coefficient of the hair pixel.
[0250] The shadow coefficient indicates the shadow color caused by the light acting on the hair pixel.
[0251] In one embodiment, the shadow color control information is a fixed value, so that all hair pixels in the hair region that are in the shadow have the same shadow color; in another embodiment, the shadow color control information is a shadow color control map, in which each element indicates the shadow color that the hair pixels at the same position in the hair region would have if they were in the shadow, so that different shadow colors can be customized for hair pixels at different positions in the hair region.
[0252] In some embodiments, if the shadow color control information is a fixed value, the fixed value may be directly read as the shadow color control information of the hair pixel; if the shadow color control information is a shadow color control map, the element at the same position as the hair pixel is taken from the shadow color control map as the shadow color control information of the hair pixel.
[0253] In some embodiments, for each hair pixel in the hair region, interpolation processing is performed according to the shadow map Shadow obtained in step 300 and the shadow color control information HairShadowColor of the hair pixel to obtain the shadow coefficient of the hair pixel.
[0254] In an example, the shadow coefficient is calculated by the following code:
[0255] #elif MATERIAL_SHADINGMODEL_Kajiya_k#if MATERIAL_SHADINGMODEL_PREINTEGRATED_SKIN
[0256] half3 ShadowColor=lerp(ShadingModelContext.HairShadowColor,1,Shadow);
[0257] Among them, ShadingModelContext.HairShadowColor refers to the shadow color control information, Shadow is the shadow map, Lerp() is the interpolation function, and half3 ShadowColor is the shadow coefficient.
[0258] In the above process, the shadow color control information can be used to achieve flexible color control of the hair shadow. Of course, the hair shadow color can also be left uncontrolled. In this case, no interpolation calculation is required. It is only necessary to find the hair pixels in the shadow according to the shadow map and write the hair pixels in the shadow into the black color value.
[0259] 309. The terminal performs color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, the diffuse reflection coefficient, and the shadow coefficient to obtain a color value of the hair pixel.
[0260] In some embodiments, for each hair pixel in the hair area, the depth value obtained in step 302, the diffuse reflection coefficient obtained in step 303, the first highlight coefficient obtained in step 305, the second highlight coefficient obtained in step 307, and the shadow coefficient obtained in step 308 are all passed into a material input interface, and the vertex shader is driven to fill the color value of each hair pixel through the material input interface, that is, the color value of each hair pixel is written into the frame buffer.
[0261] like Figure 7 As shown, in an exemplary scene, for a series of hair rendering parameter information involved in step 300: offset map ShiftTex, tangent disturbance information PrimaryShift, first highlight intensity coefficient PrimarySpecScale, negative normal disturbance information SecondaryShift, second highlight intensity coefficient SecondSpecScale, negative normal vector Bitnormal, normal vector NormalDir, first highlight color coefficient PrimaryColor, second highlight color coefficient SecondColor and shadow color control information HairShadowColor, their Material data interfaces are customized respectively. After the data interface is defined, the illumination calculation and color calculation processes involved in 303-309 are implemented respectively, and finally the hair material Material is integrated to obtain a color map of the hair area. Optionally, after the hair material Material is integrated, a series of appearance requirements of the game business logic can also be added, such as other visual effects such as virtual objects being interacted, showing a dominant body or hair dissolving. The customized Material data interfaces include but are not limited to: ShiftTex interface, Primary_Shift / SpecScale / Color interface, Secondary_Shift / SpecScale / Color interface, Bitnormal interface, NormalDir interface, etc.
[0262] Optionally, steps 303-309 are performed for each hair pixel in the hair region of the virtual object, color rendering is performed on the hair pixel, and the color value of the hair pixel is written into the frame buffer. After traversing all the hair pixels, a color map of the hair region is obtained, such as Figure 6As shown, the middle part shows a color map 602 of a virtual object A after color rendering. In the color rendering stage, the color of the edge hair in the rectangular frame portion is mixed with the color of the clothing fabric covered by the hair, thereby presenting a translucent perspective effect, while the center hair is opaque, that is, the color of the center hair is the basic color of the hair material (and mixed with the lighting calculation result), but will not be mixed with the color of the clothing fabric covered by the hair.
[0263] 310. The terminal superimposes the depth value and the color value of each hair pixel of the virtual object to obtain a hair region of the virtual object.
[0264] In some embodiments, for each hair pixel in the hair region, the depth value and color value of the hair pixel in the frame buffer are superimposed to form a rendering effect of the hair pixel in the two-dimensional game screen, and the rendering results of all hair pixels constitute the entire hair region of the virtual avatar in the two-dimensional game screen. Figure 6 As shown, the far right side shows a final semi-transparent hair rendering effect diagram 603 of a virtual object A after superimposing the depth map and the color map. As shown in the rectangular framed portion, it can be seen that the semi-transparent effect of the edge hair and the opaque effect of the center hair are combined, so that the rendering effect of the semi-transparent material such as hair is better. The correct depth sorting is guaranteed in the opaque center hair, and the two-layer highlight calculation can well simulate the real visual effect of the lighting. In the semi-transparent edge hair, since the hair in the edge area is very thin, even if the depth sorting is incorrect in the semi-transparent mode, it will not affect the user experience (because the hair is very thin and difficult to be captured and perceived by the human eye). In dynamic real-time rendering, the combination of the two has a better rendering effect, which greatly improves the realism of the hair area and makes the virtual object lifelike.
[0265] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0266] The method provided in the embodiment of the present application can complete all the lighting calculations of each hair pixel in the hair area of the virtual object after only one depth rendering and one color rendering. In the process of color rendering, by calculating the highlight coefficients of the two layers of highlights, high-quality realistic hair rendering effects are guaranteed. The first layer of highlights simulates the highlight effect of the direct light source, and the second layer of highlights performs hierarchical modification on the first layer of highlights to increase the hierarchical nature and realism of the final highlights. Therefore, under the premise of ensuring that the hair rendering effect is not damaged, the calculation amount of the shader is reduced, the number of lighting rendering processes is compressed, and it can be adapted to the mobile terminal and meet the real-time frame rate operation requirements, and can achieve excellent rendering performance with extremely low rendering overhead. In addition, since it does not rely on the TAA calculation method, it does not rely on high screen resolution and will not generate noise in the hair area.
[0267] In the previous embodiment, the high-quality semi-transparent hair rendering scheme of this application is described in detail. In this embodiment of the application, Figure 8 , which illustrates the debugging method of various hair rendering parameter information in the high-quality semi-transparent hair rendering solution. Figure 8 As shown, this embodiment includes the following steps:
[0268] In step 1, add the hair lighting model Kajiya_k Shading Model.
[0269] In step 2, customize the macro of the hair lighting model Kajiya_k Shading Model.
[0270] In step 3, the C++ low-level rendering pipeline is ready.
[0271] In step 4, the Depth Only Pass calculates the translucent / opaque depth value for each hair pixel.
[0272] In step 5, the pixel basic color rendering pipeline Base Pass Pixel prepares data and loads the hair rendering parameter information required for rendering hair.
[0273] In step 6, customize the Material data interface.
[0274] The customized Material data interfaces include but are not limited to: ShiftTex interface, Primary_Shift / SpecScale / Color interface, Secondary_Shift / SpecScale / Color interface, Bitnormal interface, NormalDir interface, etc.
[0275] In step 7, the lighting calculation begins.
[0276] In step 8, declare the variables transmitted by the Base Pass Pixel pipeline.
[0277] In step 9, the first highlight coefficient of the first layer highlight is calculated.
[0278] In step 10, the second highlight coefficient of the second layer highlight is calculated.
[0279] In step 11, the shadow color of the hair pixel is calculated.
[0280] In step 12, the target highlight coefficient after the double-layer highlights are fused is calculated.
[0281] In step 13, if you need to debug any hair rendering parameter information, modify the SurFace master material, modify the hair rendering parameter information, transfer the modified hair rendering parameter information to the custom data interface, and return to step 5. If you do not need to debug any hair rendering parameter information, skip this step 13.
[0282] In step 14, material functions and detail optimization are further integrated according to the appearance requirements of the virtual object hair in the game business.
[0283] The debugging method of hair rendering parameter information involved in the embodiment of the present application facilitates technicians to repeatedly debug each virtual object or different hairstyles of the same virtual object during the development stage to find the hair rendering parameter information with the best rendering effect. After that, when the user uses the mobile application, he will directly use the optimal hair rendering parameter information found after debugging to perform real-time rendering of the game screen. Whether in the game lobby interface, virtual mall interface, character preview interface, character selection interface or in the big world map, as long as there is any scene where virtual object hair rendering exists, this solution can be used to optimize the rendering performance.
[0284] The rendering effect of the high-quality semi-transparent hair rendering solution of the present application will be described below.
[0285] like Fig. 9As shown, when light illuminates the front of the character, taking the hair rendering task of the same virtual object A as an example, the front lighting rendering effect diagram 901 of the UE4 multi-reflection lighting model Marschner Shading Model and the front lighting rendering effect diagram 902 of the hair lighting model Kajiya_k Shading Model of this scheme are shown. By comparing the two figures, it can be seen that when light illuminates the virtual object's hair from the front, the hair rendering effect of this scheme is basically the same as the rendering effect of the UE4 multi-reflection lighting model, but this scheme greatly reduces the rendering overhead, which is of great significance when applied on mobile terminals and greatly improves the rendering performance.
[0286] like Fig.10 As shown, when light illuminates the back of a person, taking the hair rendering task of the same virtual object A as an example, the back-lighting rendering effect diagram 1001 of the UE4 multi-reflection lighting model Marschner Shading Model and the back-lighting rendering effect diagram 1002 of the hair lighting model Kajiya_k Shading Model of this solution are shown. By comparing the two figures, it can be seen that when light illuminates the back of the virtual object's hair, compared with the UE4 multi-reflection lighting model, the hair rendering effect of this solution has softer highlights, and even simulates the hair highlight attenuation effect in the rectangular frame area, avoiding light leakage and overexposure in the hair area. At the same time, this solution greatly reduces the rendering overhead, which is of great significance in mobile applications and greatly improves the rendering performance.
[0287] like Fig.11 As shown, when light illuminates the front of the character, taking the hair rendering task of the same virtual object B as an example, a front lighting rendering effect diagram 1101 of the UE4 multi-reflection lighting model Marschner Shading Model and a front lighting rendering effect diagram 1102 of the hair lighting model Kajiya_k Shading Model of this scheme are shown. By comparing the two figures, it can be seen that the hair of the virtual object B in 1101 has serious noise and depends on high screen resolution. Its frame rate is only in single digits, which seriously affects the performance of the game application. However, the hair of the virtual object B in 1102 has no noise, does not depend on high screen resolution, and can run stably at full frame rate, presenting a good hair rendering effect.
[0288] like Fig.12As shown, the front view 1201, side view 1202 and back view 1203 of the same virtual object A rendered by the hair lighting model Kajiya_k Shading Model of this scheme are shown. It can be seen that no matter from which angle the virtual object A is observed, there is no noise problem in its hair, and the game can be run at full frame rate. The rendering effect of the game screen is very stable (for example, when observed from the back angle, the highlight is softer and the highlight attenuation effect is simulated, and the rendering effect is better, surpassing the traditional solution), and the calculation amount is less than 1 / 4 of the UE4 multi-reflection lighting model Marschner Shading Model, which saves a lot of GPU computing resources as a whole, greatly improving the real-time rendering performance of the mobile terminal.
[0289] like Fig.13 As shown, a magnified detail image 1300 of the hair lighting model Kajiya_k Shading Model of this scheme is shown when rendering the same virtual object A. From the magnified detail image 1300, it can be seen that even if the hair of the virtual object A is taken in close-up and the hair area is magnified and observed, there is still no noise, and the highlight effect is very realistic, with extremely superior rendering performance.
[0290] Fig.14 This is a structural diagram of a hair rendering device for a virtual object provided in an embodiment of the present application. Please refer to Fig.14 , the device comprises:
[0291] A depth rendering module 1401 is used to perform depth rendering on the hair pixels of the virtual object to obtain a depth value of the hair pixels;
[0292] A highlight coefficient acquisition module 1402 is used to acquire a first highlight coefficient and a second highlight coefficient of the hair pixel based on the illumination information and the offset map, wherein the offset map indicates the deformation of the highlight formed by the light irradiation, the first highlight coefficient indicates the highlight effect formed by the light acting on the hair pixel, and the second highlight coefficient indicates the level modification information of the first highlight coefficient;
[0293] A color rendering module 1403 is used to perform color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, and the diffuse reflection coefficient and shadow coefficient of the hair pixel to obtain a color value of the hair pixel, wherein the diffuse reflection coefficient indicates a dispersion condition caused by light acting on the hair pixel, and the shadow coefficient indicates a shadow color caused by light acting on the hair pixel;
[0294] The superposition module 1404 is used to superimpose the depth value and color value of each hair pixel of the virtual object to obtain the hair region of the virtual object.
[0295] The device provided in the embodiment of the present application can complete all the illumination calculations of each hair pixel in the hair area of the virtual object after only one depth rendering and one color rendering. In the process of color rendering, by calculating the highlight coefficients of the two layers of highlights, a high-quality realistic hair rendering effect is ensured. The first layer of highlights simulates the highlight effect of the direct light source, and the second layer of highlights performs hierarchical modification on the first layer of highlights to increase the hierarchical nature and realism of the final highlights. Therefore, under the premise of ensuring that the hair rendering effect is not damaged, the amount of shader calculation is reduced, the number of illumination rendering processes is compressed, and it can be adapted to the mobile terminal and meet the real-time frame rate operation requirements, and can achieve excellent rendering performance with extremely low rendering overhead. In addition, since it does not rely on the TAA calculation method, it does not rely on high screen resolution and will not generate noise in the hair area.
[0296] In some embodiments, based on Fig.14 The highlight coefficient acquisition module 1402 includes:
[0297] a first offset acquisition unit, configured to determine a tangential highlight offset of the hair pixel based on the offset map and tangential disturbance information, wherein the tangential disturbance information indicates an amount of disturbance of the offset applied in a tangential direction, and the tangential highlight offset indicates an offset of the highlight of the hair pixel in the tangential direction;
[0298] The first highlight coefficient acquisition unit is used to acquire the first highlight coefficient based on the illumination information, the tangential highlight offset and the first highlight indication information, wherein the first highlight indication information represents the control information of the first-layer highlight indicated by the first highlight coefficient.
[0299] In some embodiments, the first highlight indication information includes a first highlight intensity coefficient and a first highlight color coefficient;
[0300] The first highlight coefficient acquisition unit is used for:
[0301] Determine a half-angle vector of the hair pixel based on the illumination vector and the sight vector in the illumination information;
[0302] Based on the tangential highlight offset, the half-angle vector and the first highlight intensity coefficient, a first intensity control coefficient is determined, where the first intensity control coefficient indicates the offset and intensity of the first layer highlight in the tangential direction;
[0303] The first intensity control coefficient is multiplied by the first highlight color coefficient to obtain the first highlight coefficient.
[0304] In some embodiments, based on Fig.14 The highlight coefficient acquisition module 1402 includes:
[0305] a second offset obtaining unit, configured to determine a negative normal highlight offset of the hair pixel based on the offset map and negative normal disturbance information, wherein the negative normal disturbance information indicates a disturbance amount of the offset applied in a direction opposite to the normal direction, and the negative normal highlight offset indicates an offset amount of the hair pixel in a direction opposite to the normal direction;
[0306] The second highlight coefficient acquisition unit is used to acquire the second highlight coefficient based on the illumination information, the negative normal highlight offset and the second highlight indication information, wherein the second highlight indication information represents control information of the second layer of highlights indicated by the second highlight coefficient.
[0307] In some embodiments, the second highlight indication information includes a second highlight intensity coefficient and a second highlight color coefficient;
[0308] The second highlight coefficient acquisition unit is used for:
[0309] Determine a half-angle vector of the hair pixel based on the illumination vector and the sight vector in the illumination information;
[0310] Based on the negative normal highlight offset, the half-angle vector and the second highlight intensity coefficient, determine a second intensity control coefficient, the second intensity control coefficient indicating the offset and intensity of the second layer of highlights in the opposite direction of the normal direction;
[0311] The second intensity control coefficient is multiplied by the second highlight color coefficient to obtain the second highlight coefficient.
[0312] In some embodiments, based on Fig.14 The depth rendering module 1401 includes:
[0313] a mode determination unit, configured to determine a transparency mode of the hair pixel based on a transparency map, wherein the transparency map indicates a transparency condition of the hair region, and the transparency mode indicates whether the hair pixel is opaque or semi-transparent;
[0314] The depth writing unit is used to perform depth writing on the hair pixel based on the transparency mode of the hair pixel to obtain the depth value of the hair pixel.
[0315] In some embodiments, the depth writing unit is used to:
[0316] When the transparency mode is semi-transparent, the depth value of the hair pixel is written in the transparent blending mode;
[0317] When the transparency mode is opaque, the depth value of the hair pixel is written in a transparent test mode.
[0318] In some embodiments, based on Fig.14 The device is composed of:
[0319] The diffuse reflection coefficient acquisition module is used to obtain the diffuse reflection coefficient of the hair pixel based on the lighting information, the hair material and the hair roughness of the virtual object, wherein the hair material indicates the material color of the hair pixel, and the hair roughness indicates the roughness of the hair pixel.
[0320] In some embodiments, the reflectance acquisition module is used to:
[0321] Get the dot product of the illumination vector and the normal vector in the illumination information;
[0322] Perform interpolation processing based on the hair roughness to obtain a lightness and darkness adjustment coefficient;
[0323] The diffuse reflection coefficient of the hair pixel is obtained based on the hair material, the dot product and the shading adjustment coefficient.
[0324] In some embodiments, based on Fig.14 The device is composed of:
[0325] The shadow coefficient acquisition module is used to perform interpolation processing based on the shadow map and the shadow color control information of the hair pixel to obtain the shadow coefficient of the hair pixel. The shadow map indicates the shadow formed by the light irradiating on the hair area.
[0326] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0327] It should be noted that: the hair rendering device for a virtual object provided in the above embodiment only uses the division of the above functional modules as an example when rendering the hair area of a virtual object. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the electronic device is divided into different functional modules to complete all or part of the functions described above. In addition, the hair rendering device for a virtual object provided in the above embodiment and the hair rendering method embodiment for a virtual object belong to the same concept. The specific implementation process is detailed in the hair rendering method embodiment for a virtual object, which will not be repeated here.
[0328] Fig.15 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Fig.15As shown, the electronic device is taken as terminal 1500 for example. Optionally, the device type of the terminal 1500 includes: a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3), an MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) player, a laptop computer or a desktop computer. The terminal 1500 may also be called a user device, a portable terminal, a laptop terminal, a desktop terminal or other names.
[0329] Typically, the terminal 1500 includes a processor 1501 and a memory 1502 .
[0330] Optionally, the processor 1501 includes one or more processing cores, such as a 4-core processor, an 8-core processor, etc. Optionally, the processor 1501 is implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). In some embodiments, the processor 1501 includes a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1501 is integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1501 also includes an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0331] In some embodiments, the memory 1502 includes one or more computer-readable storage media, and optionally, the computer-readable storage medium is non-transitory. Optionally, the memory 1502 also includes a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 1502 is used to store at least one program code, and the at least one program code is used to be executed by the processor 1501 to implement the hair rendering method of the virtual object provided in each embodiment of the present application.
[0332] In some embodiments, the terminal 1500 may further optionally include: a peripheral device interface 1503 and at least one peripheral device. The processor 1501, the memory 1502 and the peripheral device interface 1503 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 1503 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 1504, a display screen 1505, a camera assembly 1506, an audio circuit 1507 and a power supply 1508.
[0333] The peripheral device interface 1503 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 1501 and the memory 1502. In some embodiments, the processor 1501, the memory 1502, and the peripheral device interface 1503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1501, the memory 1502, and the peripheral device interface 1503 are implemented on a separate chip or circuit board, which is not limited in this embodiment.
[0334] The radio frequency circuit 1504 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 1504 communicates with the communication network and other communication devices through electromagnetic signals. The radio frequency circuit 1504 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 1504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. Optionally, the radio frequency circuit 1504 communicates with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: a metropolitan area network, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 1504 also includes circuits related to NFC (Near Field Communication), which is not limited in this application.
[0335] The display screen 1505 is used to display a UI (User Interface). Optionally, the UI includes graphics, text, icons, videos, and any combination thereof. When the display screen 1505 is a touch display screen, the display screen 1505 also has the ability to collect touch signals on the surface or above the surface of the display screen 1505. The touch signal can be input to the processor 1501 as a control signal for processing. Optionally, the display screen 1505 is also used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1505 is one, and the front panel of the terminal 1500 is set; in other embodiments, the display screen 1505 is at least two, which are respectively set on different surfaces of the terminal 1500 or are folded; in some embodiments, the display screen 1505 is a flexible display screen, which is set on the curved surface or folded surface of the terminal 1500. Even, optionally, the display screen 1505 is set to a non-rectangular irregular shape, that is, a special-shaped screen. Optionally, the display screen 1505 is made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0336] The camera assembly 1506 is used to capture images or videos. Optionally, the camera assembly 1506 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1506 also includes a flash. Optionally, the flash is a monochrome temperature flash, or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which is used for light compensation at different color temperatures.
[0337] In some embodiments, the audio circuit 1507 includes a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 1501 for processing, or input them into the radio frequency circuit 1504 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there are multiple microphones, which are respectively arranged at different parts of the terminal 1500. Optionally, the microphone is an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 1501 or the radio frequency circuit 1504 into sound waves. Optionally, the speaker is a traditional film speaker, or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 1507 also includes a headphone jack.
[0338] The power supply 1508 is used to power various components in the terminal 1500. Optionally, the power supply 1508 is an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1508 includes a rechargeable battery, the rechargeable battery supports wired charging or wireless charging. The rechargeable battery is also used to support fast charging technology.
[0339] In some embodiments, the terminal 1500 further includes one or more sensors 1510 . The one or more sensors 1510 include, but are not limited to, an acceleration sensor 1511 , a gyroscope sensor 1512 , a pressure sensor 1513 , an optical sensor 1514 , and a proximity sensor 1515 .
[0340] In some embodiments, the acceleration sensor 1511 detects the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal 1500. For example, the acceleration sensor 1511 is used to detect the components of gravity acceleration on the three coordinate axes. Optionally, the processor 1501 controls the display screen 1505 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 1511. The acceleration sensor 1511 is also used to collect motion data of games or users.
[0341] In some embodiments, the gyroscope sensor 1512 detects the body direction and rotation angle of the terminal 1500, and the gyroscope sensor 1512 cooperates with the acceleration sensor 1511 to collect the user's 3D actions on the terminal 1500. The processor 1501 implements the following functions based on the data collected by the gyroscope sensor 1512: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0342] Optionally, the pressure sensor 1513 is arranged on the side frame of the terminal 1500 and / or the lower layer of the display screen 1505. When the pressure sensor 1513 is arranged on the side frame of the terminal 1500, it can detect the user's holding signal of the terminal 1500, and the processor 1501 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 1513. When the pressure sensor 1513 is arranged on the lower layer of the display screen 1505, the processor 1501 controls the operability controls on the UI interface according to the user's pressure operation on the display screen 1505. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0343] The optical sensor 1514 is used to collect the ambient light intensity. In one embodiment, the processor 1501 controls the display brightness of the display screen 1505 according to the ambient light intensity collected by the optical sensor 1514. Specifically, when the ambient light intensity is high, the display brightness of the display screen 1505 is increased; when the ambient light intensity is low, the display brightness of the display screen 1505 is decreased. In another embodiment, the processor 1501 also dynamically adjusts the shooting parameters of the camera assembly 1506 according to the ambient light intensity collected by the optical sensor 1514.
[0344] The proximity sensor 1515, also called a distance sensor, is usually arranged on the front panel of the terminal 1500. The proximity sensor 1515 is used to collect the distance between the user and the front of the terminal 1500. In one embodiment, when the proximity sensor 1515 detects that the distance between the user and the front of the terminal 1500 is gradually decreasing, the processor 1501 controls the display screen 1505 to switch from the screen-on state to the screen-off state; when the proximity sensor 1515 detects that the distance between the user and the front of the terminal 1500 is gradually increasing, the processor 1501 controls the display screen 1505 to switch from the screen-off state to the screen-on state.
[0345] Those skilled in the art will understand that Fig.15 The structure shown in the figure does not constitute a limitation on the terminal 1500, and the terminal 1500 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.
[0346] Fig.16 1 is a schematic diagram of the structure of another electronic device provided in an embodiment of the present application. The electronic device 1600 may have relatively large differences due to different configurations or performances. The electronic device 1600 includes one or more processors (Central Processing Units, CPU) 1601 and one or more memories 1602, wherein the memory 1602 stores at least one computer program, and the at least one computer program is loaded and executed by the one or more processors 1601 to implement the hair rendering method of the virtual object provided in the above-mentioned embodiments. Optionally, the electronic device 1600 also has components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The electronic device 1600 also includes other components for implementing device functions, which will not be described in detail here.
[0347] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including at least one computer program, and the at least one computer program can be executed by a processor in an electronic device to complete the hair rendering method of a virtual object in each of the above embodiments. For example, the computer-readable storage medium includes ROM (Read-Only Memory), RAM (Random-Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, optical data storage device, etc.
[0348] In an exemplary embodiment, a computer program product is also provided, including one or more computer programs, which are stored in a computer-readable storage medium. One or more processors of an electronic device can read the one or more computer programs from the computer-readable storage medium, and the one or more processors execute the one or more computer programs, so that the electronic device can execute to complete the hair rendering method of the virtual object in the above embodiment.
[0349] A person of ordinary skill in the art will understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by instructing related hardware through a program. Optionally, the program is stored in a computer-readable storage medium. Optionally, the above-mentioned storage medium is a read-only memory, a disk or an optical disk, etc.
[0350] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for rendering hair of a virtual object, characterized in that: The method comprises: Performing depth rendering on hair pixels of the virtual object to obtain depth values of the hair pixels; Based on the illumination information and the offset map, a first highlight coefficient and a second highlight coefficient of the hair pixel are obtained, wherein the offset map indicates a deformation of a highlight formed by light irradiation, the first highlight coefficient indicates a highlight effect formed by light acting on the hair pixel, and the second highlight coefficient indicates hierarchical modification information of the first highlight coefficient; performing color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, and the diffuse reflection coefficient and shadow coefficient of the hair pixel to obtain a color value of the hair pixel, wherein the diffuse reflection coefficient indicates a dispersion condition caused by light acting on the hair pixel, and the shadow coefficient indicates a shadow color caused by light acting on the hair pixel; The depth value and the color value of each hair pixel of the virtual object are superimposed to obtain the hair region of the virtual object.
2. The method according to claim 1, characterized in that The obtaining the first highlight coefficient of the hair pixel based on the illumination information and the offset map comprises: Determining a tangential highlight offset of the hair pixel based on the offset map and tangential disturbance information, wherein the tangential disturbance information indicates an amount of disturbance of the offset applied in a tangential direction, and the tangential highlight offset indicates an offset of the highlight of the hair pixel in the tangential direction; The first highlight coefficient is obtained based on the illumination information, the tangential highlight offset and the first highlight indication information, where the first highlight indication information represents control information of the first-layer highlight indicated by the first highlight coefficient.
3. The method according to claim 2, characterized in that The first highlight indication information includes a first highlight intensity coefficient and a first highlight color coefficient; The acquiring the first highlight coefficient based on the illumination information, the tangential highlight offset and the first highlight indication information comprises: Determine a half-angle vector of the hair pixel based on an illumination vector and a sight line vector in the illumination information; Determine a first intensity control coefficient based on the tangential highlight offset, the half-angle vector and the first highlight intensity coefficient, wherein the first intensity control coefficient indicates the offset and intensity of the first layer highlight in the tangential direction; The first intensity control coefficient is multiplied by the first highlight color coefficient to obtain the first highlight coefficient.
4. The method according to claim 1, characterized in that The obtaining the second highlight coefficient of the hair pixel based on the illumination information and the offset map comprises: determining a negative normal highlight offset of the hair pixel based on the offset map and negative normal perturbation information, wherein the negative normal perturbation information indicates a perturbation amount of the offset applied in a direction opposite to the normal direction, and the negative normal highlight offset indicates an offset amount of the hair pixel in a direction opposite to the normal direction; The second highlight coefficient is obtained based on the illumination information, the negative normal highlight offset, and the second highlight indication information, wherein the second highlight indication information represents control information of the second layer of highlights indicated by the second highlight coefficient.
5. The method according to claim 4, characterized in that The second highlight indication information includes a second highlight intensity coefficient and a second highlight color coefficient; The acquiring the second highlight coefficient based on the illumination information, the negative normal highlight offset and the second highlight indication information comprises: Determine a half-angle vector of the hair pixel based on an illumination vector and a sight line vector in the illumination information; Determine a second intensity control coefficient based on the negative normal highlight offset, the half-angle vector and the second highlight intensity coefficient, wherein the second intensity control coefficient indicates the offset and intensity of the second layer of highlights in the opposite direction of the normal direction; The second intensity control coefficient is multiplied by the second highlight color coefficient to obtain the second highlight coefficient.
6. The method according to claim 1, characterized in that The performing depth rendering on the hair pixels of the virtual object to obtain the depth value of the hair pixels comprises: determining a transparency mode of the hair pixel based on a transparency map, wherein the transparency map indicates a transparency condition of the hair region, and the transparency mode indicates whether the hair pixel is opaque or semi-transparent; Based on the transparency mode of the hair pixel, depth writing is performed on the hair pixel to obtain a depth value of the hair pixel.
7. The method according to claim 6, characterized in that The step of performing depth writing on the hair pixel based on the transparent mode of the hair pixel to obtain the depth value of the hair pixel comprises: When the transparency mode is semi-transparent, writing the depth value of the hair pixel in a transparent blending mode; When the transparent mode is opaque, a transparent test mode is adopted to write the depth value of the hair pixel.
8. The method according to claim 1, characterized in that The method further comprises: The diffuse reflection coefficient of the hair pixel is obtained based on the illumination information, the hair material and the hair roughness of the virtual object, wherein the hair material indicates the material color of the hair pixel, and the hair roughness indicates the roughness of the hair pixel.
9. The method according to claim 8, characterized in that The obtaining the diffuse reflection coefficient of the hair pixel based on the illumination information, the hair material and the hair roughness of the virtual object comprises: Obtaining the dot product of the illumination vector and the normal vector in the illumination information; Performing interpolation processing based on the hair roughness to obtain a lightness and darkness adjustment coefficient; The diffuse reflection coefficient of the hair pixel is obtained based on the hair material, the dot product and the shading adjustment coefficient.
10. The method according to claim 1, characterized in that The method further comprises: An interpolation process is performed based on a shadow map and the shadow color control information of the hair pixel to obtain a shadow coefficient of the hair pixel, wherein the shadow map indicates a shadow condition formed by light irradiating the hair area.
11. A hair rendering device for a virtual object, characterized in that: The device comprises: A depth rendering module, used to perform depth rendering on hair pixels of a virtual object to obtain depth values of the hair pixels; a highlight coefficient acquisition module, configured to acquire a first highlight coefficient and a second highlight coefficient of the hair pixel based on illumination information and an offset map, wherein the offset map indicates a deformation of highlights formed by light irradiation, the first highlight coefficient indicates a highlight effect formed by light acting on the hair pixel, and the second highlight coefficient indicates hierarchical modification information of the first highlight coefficient; a color rendering module, configured to perform color rendering on the hair pixel based on the depth value, the first highlight coefficient, the second highlight coefficient, and a diffuse reflection coefficient and a shadow coefficient of the hair pixel to obtain a color value of the hair pixel, wherein the diffuse reflection coefficient indicates a dispersion condition caused by light acting on the hair pixel, and the shadow coefficient indicates a shadow color caused by light acting on the hair pixel; The superposition module is used to superimpose the depth value and color value of each hair pixel of the virtual object to obtain the hair area of the virtual object.
12. An electronic device, characterized in that: The electronic device includes one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and the at least one computer program is loaded and executed by the one or more processors to implement the hair rendering method of a virtual object as described in any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one computer program, and the at least one computer program is loaded and executed by a processor to implement the hair rendering method of a virtual object according to any one of claims 1 to 10.
14. A computer program product, characterized in that The computer program product comprises at least one computer program, and the at least one computer program is loaded and executed by a processor to implement the hair rendering method of a virtual object according to any one of claims 1 to 10.
