Hair rendering method and device, computing equipment and computer readable storage medium
By mixing the color values of hair cells based on transparency and depth for each target pixel in the game, the problem of rough hair rendering effect is solved, improving the rendering quality of hair and the overall picture effect.
Patent Information
- Application Number
- CN202411385547.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2024-12-31
AI Technical Summary
The hair rendering effect in existing games is rough and has noise, which affects the display effect of the game screen and the player's experience.
By obtaining the display information of the target cell in the hair model for each target pixel, mixing based on the transparency and depth of the cell, obtaining the mixed color value, and rendering the hair on the target pixel to ensure that the color value is closer to the real scene , reduce the sense of inconsistency.
Improves hair rendering effect, reduces flickering and inconsistency, enhances the dense performance of hair, and improves the display quality of the entire picture.
Smart Images

Figure CN119215405A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of computer technology, and more particularly to a hair rendering method and apparatus, a computing device, a computer-readable storage medium, and a computer program product. Background Art
[0002] With the development of computer technology, the requirements for the display effects of various screens are getting higher and higher. For example, the display effects of various objects in game screens are required to be high.
[0003] Generally, various objects in the game scene (such as people or animals) have hair, and as the player's operation and the scene change, the object's hair will also change shape accordingly. If the display of the object's hair is not realistic enough, it will give the player a sense of disconnection, affecting the overall display effect of the game screen and the player's gaming experience.
[0004] Currently, the hair of objects displayed in game scenes is relatively rough, and there may be some noise points visible to the naked eye, so the display effect of hair still needs to be improved. Summary of the invention
[0005] The embodiments of this specification provide a hair rendering method, which can improve the hair rendering effect, and accordingly improve the display effect of the entire picture. One or more embodiments of this specification also relate to a hair rendering apparatus, a computing device, a computer-readable storage medium, and a computer program product.
[0006] According to one aspect of an embodiment of this specification, a hair rendering method is provided, the method comprising: For any target pixel in the screen display area corresponding to the hair model of the target object, obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model, wherein the display information includes a color value and transparency; In the case where the target pixel corresponds to a plurality of target fragments, based on the transparency of the plurality of target fragments, color values of the plurality of target fragments are sequentially mixed in descending order of depth of the plurality of target fragments to obtain a mixed color value of the target pixel; The hair of the target object is rendered at the target pixel based on the mixed color value.
[0007] According to another aspect of an embodiment of this specification, there is provided a hair rendering device, comprising: A first acquisition module is used to acquire, for any target pixel corresponding to the hair model of the target object in the screen display area, display information of a target fragment to be displayed corresponding to the target pixel in the hair model, wherein the display information includes a color value and transparency; a mixing module, configured to, when the target pixel corresponds to a plurality of target fragments, sequentially mix the color values of the plurality of target fragments in a descending order of depths of the plurality of target fragments based on the transparency of the plurality of target fragments, so as to obtain a mixed color value of the target pixel; A rendering module is used to render the hair of the target object on the target pixel based on the mixed color value.
[0008] According to another aspect of the embodiments of this specification, there is provided a computing device, including: a memory and a processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer programs / instructions are executed by the processor, the steps of the above method are implemented.
[0009] According to another aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores a computer program / instruction, and the steps of the above method are implemented when the computer program / instruction is executed by a processor.
[0010] According to another aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instruction, and when the computer program / instruction in the computer program product is executed in a processor, the steps of the above method are implemented.
[0011] In one embodiment of the present specification, for the target pixel to be rendered hair, the target fragments to be displayed corresponding to the target pixel in the hair model are mixed in color values based on transparency in the order of depth from large to small, and then the hair is rendered on the pixel based on the obtained mixed color value. In this way, for each target pixel, the influence of each hair corresponding to the target pixel on the display of the target pixel can be comprehensively considered, and the color mixing can be performed based on transparency in the depth order of each fragment, which can ensure that the obtained mixed color value is closer to the visual color in the real scene. In combination with transparency, the density of the hair can be enriched, the sense of discontinuity when the hair is displayed can be reduced, and the hair rendering effect can be improved, which can correspondingly improve the display effect of the entire picture. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 is a flow chart of a hair rendering method provided in an embodiment of this specification; Figure 2 is a schematic diagram of a hair model in a homogeneous clipping space provided in an embodiment of the present specification; Figure 3 is a schematic diagram of filling depth in a sub-buffer corresponding to a target pixel provided by an embodiment of this specification; Figure 4is a schematic diagram of a hair model that has undergone depth testing provided in an embodiment of the present specification; Figure 5 This is a schematic diagram of a mixed color value corresponding to a hair model provided by an embodiment of the present specification rendered to a rendering texture; Figure 6 This is a hair rendering effect diagram provided by an embodiment of this specification; Figure 7 It is a structural schematic diagram of a hair rendering device provided in an embodiment of this specification; Figure 8 It is a structural block diagram of a computing device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0013] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0014] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms of "one", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items. The term "at least one" in one or more embodiments of this specification refers to "one or more", and "multiple" refers to "two or more". The term "including" is an open description and should be understood as "including but not limited to", and may include other content on the basis of the content already described.
[0015] It should be understood that although the terms "first", "second", etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, "first" may also be referred to as "second", and similarly, "second" may also be referred to as "first". Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0016] In addition, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant standards and requirements, and corresponding operation entrances shall be provided for users to choose to authorize or refuse.
[0017] At present, the requirements for the display effects of various pictures are getting higher and higher. For example, in three-dimensional games, the rendering quality of game scenes and various game characters (such as human and animal player characters or non-player characters) is crucial. The more realistic the display of game characters is, the more immersive the game experience can be for players. Improving the rendering quality of game characters can not only optimize the visual presentation effect and enhance the player experience, but also improve the competitiveness of the game in the market. The rendering effect of hair (such as hair) has a great impact on game characters. Excellent hair rendering effect can enhance the player's sense of identification with the character.
[0018] In the related art, dithering translucency is used to simulate the hair effect. Dithering translucency is a technology that simulates the translucent effect by changing the transparency at pixel intervals. It is usually used to draw the translucent effect for opaque objects. This method will cause obvious pixelated edges and flickering in the hair, affecting the rendering quality and visual effect of the hair. And because the width of the hair is much smaller than the unit pixel on the screen, the hair rendered by dithering translucency will appear rough. If there is no motion blur, many noise points can be seen by the naked eye. In addition, dithering translucency relies on noise reduction algorithms such as temporal anti-aliasing (TAA) or deep learning super sampling (DLSS) to ensure the semi-transparent effect, and the picture setting is not flexible enough. Dithering translucency renders opaque objects. If there are many facets of hair and they are interlaced, it is easy to show the interlacing of the facets, resulting in poor hair rendering effect.
[0019] The embodiments of this specification provide a hair rendering method that can improve the hair rendering effect. This specification also relates to a hair rendering device, a hair rendering device, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail one by one in the following embodiments. The hair rendering method provided in this specification can be applied to the hair rendering device and the computing device. The hair rendering device and the computing device can be terminal devices with display functions such as smart phones, laptops, tablet computers, virtual reality display devices or augmented reality display devices.
[0020] Figure 1This is a flowchart of a hair rendering method provided in an embodiment of the present specification, and the method can be applied to a hair rendering device. For example, a target application is installed in the hair rendering device, such as a game program, an animation player program, a video editing program, or other program that needs to display the hair of a target object. For example, the target object can be a game character in a game program, an animation character in an animation player program, or a person or animal in a video to be edited in a video editing program. The hair rendering device can execute the hair rendering method provided in an embodiment of the present specification by running the target application. Figure 1 As shown, the hair rendering method includes the following steps: Step 102: for any target pixel in the screen display area corresponding to the hair model of the target object, obtain display information of the target fragment to be displayed corresponding to the target pixel in the hair model, wherein the display information includes color value and transparency.
[0021] In the embodiments of the present specification, the screen display area refers to the area in the hair rendering device used to display the screen to which the target object belongs, and the screen display area may correspond to all or part of the area in the display screen of the hair rendering device. For example, the target object is a game character in a game program, and the screen to which the target object belongs may be the screen of the entire game scene. Each pixel in the screen display area is used to respectively display information at different positions in the game scene. The target object may occupy at least part of the screen display area, and the hair of the target object may be displayed using multiple pixels in the screen display area.
[0022] In the embodiments of this specification, models of various objects (such as three-dimensional models) can be pre-built. During the operation of the target application, the image frame to be currently displayed and the object models required for the display of the image frame are determined based on the current display requirements (such as based on the user's operation or the content of the screen, etc.). The hair rendering method provided in the embodiments of this specification is applied to the situation where the hair of the target object needs to be displayed in the current image frame. The hair of the target object can correspond to a separate hair model, and the hair model includes multiple hairs. The hair model can indicate the information of each hair (such as color, position, depth, and texture information). For example, the target object is a person, and the hair model is a hair model. The hair rendering device can map the hair model of the target object to the corresponding multiple pixels in the screen display area, so as to perform corresponding rendering at the multiple pixels to realize the display of the hair of the target object.
[0023] A 3D model consists of multiple geometric vertices. Adjacent geometric vertices are connected, and the lines connecting three adjacent geometric vertices form a triangle. Geometric vertices can be combined into primitives, such as vertices, line segments connecting vertices, or polygons surrounded by multiple vertices. A 3D model can be said to be composed of primitives.
[0024] In the process of rasterizing a 3D model into a 2D image, primitives can be synthesized into fragments. When displaying a 3D model, it is necessary to project the 3D model into a 2D plane, that is, to project each primitive in the 3D model onto the display screen, such as projecting each triangle in the 3D scene onto the screen (a triangle projected onto the screen is also a triangle), and then determine the pixels covered by the projection area of the projected triangle on the screen. This process is called rasterization. Rasterization converts each primitive into a small 2D image. Each 2D image contains information such as color, depth, and texture. The 2D image and its related information can be called a fragment.
[0025] In the embodiment of the present specification, the hair model of the target object can be projected onto multiple pixels in the screen display area to be displayed at the multiple pixels. There can be multiple primitives in the hair model projected onto the same pixel, and correspondingly multiple fragments corresponding to the multiple primitives are obtained. Different fragments can correspond to different hair strands, and the multiple fragments can correspond to multiple layers of hair. In the embodiment of the present specification, the fragment obtained by projecting each primitive in the hair model onto a pixel is called a fragment in the hair model. A pixel in the screen display area can correspond to multiple fragments in the hair model, and the multiple fragments determine the information that should be displayed at the pixel. In the embodiment of the present specification, each pixel to which the hair model of the target object in the screen display area is projected (that is, the pixel of the hair model to be displayed) is called a target pixel. The following is an introduction to the rendering process for one target pixel as an example, and the corresponding rendering process needs to be performed for other target pixels.
[0026] In addition to displaying the hair of the target object, other object information may also need to be displayed at the target pixel. If the other object information is the foreground information of some hair of the target object, the hair will be blocked. The hair of the target object does not need to be displayed at the target pixel, that is, the corresponding fragments do not need to be displayed. For example, when displaying the front image of a person, the hair behind the person's head will be blocked by the person's face, so the hair behind the person's head does not need to be displayed, that is, the fragments corresponding to the position behind the person's face in the fragments corresponding to the target pixel do not need to be displayed, and the target pixel corresponding to the hair behind the person's head is finally displayed based on the information of the person's face. For each target pixel, the hair rendering device can determine the target fragment to be displayed among the corresponding fragments, and the target fragment can be a fragment that is not blocked by the foreground information, and then determine the display information at the target pixel based on the target fragment. For some target pixels, some of the fragments corresponding to them in the hair model are located after other object information, and some of the fragments are located before the other object information, so the fragment located before the other object can be determined as the target fragment to be displayed.
[0027] After each primitive in the hair model is projected onto the screen to obtain the corresponding fragments, the display information of each fragment can be obtained accordingly, and the display information may include color value and transparency. The display information may also include the depth of the fragment, and the depth of the fragment refers to the distance between the primitive corresponding to the fragment and the virtual camera corresponding to the image frame to be displayed, and the position of the virtual camera matches the projection of the hair model on the screen. The hair rendering device can obtain the display information of each target fragment corresponding to the target pixel based on the information of the hair model. The color and transparency of each hair of the same hair model in different display scenes may be different, and the display information of each fragment may be different accordingly. In the embodiment of this specification, the hair rendering device can obtain the display information of each target fragment corresponding to the target pixel under the display requirement based on the display requirement corresponding to each frame of the image.
[0028] In the embodiment of the present specification, the hair rendering device can render each image frame including the hair of the target object according to the hair rendering method provided in the embodiment of the present specification during the running of the target application. The viewing angles corresponding to different image frames may be different, the positions of the corresponding virtual cameras may also be different, the hair form of the target object to be displayed may change, the projection results of the hair model on the screen may be different, and the fragments corresponding to each target pixel may also change, so it is necessary to adaptively render each image frame again.
[0029] Step 104: When the target pixel corresponds to multiple target fragments, based on the transparency of the multiple target fragments, the color values of the multiple target fragments are mixed in descending order of the depth of the multiple target fragments to obtain a mixed color value of the target pixel.
[0030] The number of target fragments corresponding to the target pixel may be one or more. If the target object corresponds to only one target fragment, the hair rendering device may directly determine the display information of the target fragment as the display information of the target pixel, and then render the hair of the target object on the target pixel based on the display information. In the case where the target object corresponds to multiple target fragments, the hair rendering device may process the display information of the multiple target fragments to comprehensively determine the display information of the target object based on the display information of the multiple target fragments, and then render it on the target pixel.
[0031] In the embodiment of the present specification, hair is introduced into the Alpha channel, and the Alpha channel refers to the channel corresponding to the transparency or semi-transparency of the image. Based on the transparency of multiple target fragments corresponding to the target pixel, the color values of the multiple target fragments are mixed, so as to render the hair at the target pixel based on the obtained mixed color value. The hair rendering device can first determine the depth of each target fragment and sort the depth of each target fragment. Based on the order of the depth of the multiple target fragments corresponding to the target pixel from large to small, the color values of each target fragment are mixed in sequence in combination with the transparency of the target fragment, so as to determine the mixed color value required for the target pixel to display the multiple target fragments as a whole. This mixing method can be a semi-transparent mixing method. In this mixing method, the color mixing can be performed on the two target fragments with the largest depth first, and then the mixing result of the two target fragments is mixed with the previous target fragment again, and this is performed in sequence until all the multiple target fragments are mixed.
[0032] This mixing method can ensure that the final mixed color value matches the visual perception of the human eye to a high degree, ensure a smooth transition of colors between pixels, and improve the hair display effect. In addition, the mixed color value for each target pixel is related to the transparency, and the density of the hair can be indicated by the size of the transparency, without changing the transparency of each pixel interval to simulate a translucent effect, which can eliminate the flickering and discontinuous feeling of hair display.
[0033] In some embodiments, step 104 may be performed by a graphics processing unit (GPU) of the hair rendering device. The graphics processor may, for each image frame to be displayed, sequentially mix the color values of each target fragment in real time based on the transparency of the target fragment and in accordance with the depth sorting.
[0034] Step 106: Render the hair of the target object on the target pixel based on the mixed color value.
[0035] The hair rendering device can control the display of the target pixels based on the mixed color value of each target pixel, so as to render the hair of the target object on each target pixel respectively.
[0036] In the embodiments of the present specification, each target pixel can indicate the density of the hair volume by the size of transparency, without changing the transparency interval of each pixel, which can eliminate the flickering and discontinuous feeling of hair display. In addition, because the hair rendering device performs semi-transparent blending based on the depth sorting of each target fragment in real time when rendering the hair of the target object, it can ensure that the displayed hair interlacing effect is relatively natural for various possible interlacing situations of hair patches in the hair model. When making the hair model, there is no need to consider the problems that may be caused by the interlacing of hair patches, which can simplify the production process of the hair model. In addition, the hair rendering device can achieve a better rendering effect for the hair by simply adjusting the calculation method of the display information for the target pixel, without relying on other rendering functions, which can ensure that the implementation process is relatively simple.
[0037] In summary, in the hair rendering method provided in the embodiment of the present specification, for the target pixel of hair to be rendered, the target fragments to be displayed corresponding to the target pixel in the hair model are mixed in color values based on transparency in the order of depth from large to small, and then the hair is rendered on the pixel based on the obtained mixed color value. In this way, for each target pixel, the influence of each hair corresponding to the target pixel on the display of the target pixel can be comprehensively considered, and the color is mixed based on transparency in the depth order of each fragment, which can ensure that the obtained mixed color value is closer to the visual color in the real scene. The combination of transparency can enrich the density of the hair, reduce the sense of discontinuity when the hair is displayed, improve the hair rendering effect, and accordingly improve the display effect of the entire picture.
[0038] Some implementation methods of the hair rendering method provided in the embodiments of this specification are introduced below.
[0039] In one embodiment, in the above step 102, for any target pixel corresponding to the hair model of the target object in the screen display area, obtaining display information of the target fragment to be displayed corresponding to the target pixel in the hair model may include the following steps 1022 to 1026.
[0040] Step 1022: For any target pixel in the screen display area corresponding to the hair model of the target object, obtain the depth of each fragment corresponding to the target pixel in the hair model.
[0041] The hair rendering device may first project the hair model of the target object in the screen display area based on the information of the current image frame to be displayed (such as its corresponding viewing angle), and determine the target pixels in the screen display area that should be used to display the hair of the target object, that is, the target pixels corresponding to the hair model of the target object. In the embodiment of the present specification, for any target pixel, the hair rendering device may also determine, based on the projection, the fragments corresponding to the target pixel in the hair model, that is, the fragments generated by the projection of the primitive to the target pixel.
[0042] The depth of a fragment indicates the distance between the image element corresponding to the fragment in the hair model and the virtual camera corresponding to the image frame currently to be displayed. The hair model of the target object may correspond to detailed information of all positions thereon, and the hair rendering device may obtain the depth of each fragment in the hair model based on the hair model of the target object, and accordingly may obtain the depth of each fragment corresponding to each target pixel.
[0043] In the embodiment of the present specification, the hair rendering device can call the rendering interface to obtain the rendering list of the hair model of the target object, convert the hair model from the model space (ObjectSpace) to the world space (WorldSpace) based on the model matrix (Model Matrix), and then convert it to the homogeneous clipping space (Homogeneous Clipping Space) via the view projection matrix (View-Projection Matrix). Figure 2 This is a schematic diagram of a hair model in a homogeneous clipping space provided by an embodiment of the present specification. Based on the information of the hair model in the homogeneous clipping space, the depth of each fragment corresponding to each target pixel in the hair model is determined. In the homogeneous clipping space, the XY coordinates of any position in the model correspond to the pixel coordinates of the position in the model in the screen display area, and the Z coordinate of the position is the depth value of the fragment corresponding to the position.
[0044] Step 1024: compare the depth of each fragment with the reference depth corresponding to the target pixel, and determine the target fragment to be displayed in each fragment based on the comparison result; wherein the reference depth includes the depth of the object rendered before the hair of the target object.
[0045] The hair rendering device can obtain the corresponding reference depth for the target pixel, and the reference depth can be the depth of an object (such as an auxiliary object) that is rendered at the target pixel before the hair of the target object. If there are multiple objects that are rendered at the target pixel before the hair of the target object, the minimum depth of the multiple objects can be determined as the reference depth. For example, the head of a person needs to be rendered before the hair. For the target pixel that corresponds to both the head model and the hair model of the person, the corresponding reference depth can be the depth of the primitive corresponding to the target pixel in the head model.
[0046] If the depth of a certain fragment corresponding to the target pixel is greater than the reference depth, the fragment will be blocked by the auxiliary object to be displayed at the target pixel, and the fragment does not need to be displayed. If the depth of a certain fragment corresponding to the target pixel is less than or equal to the reference depth, the display of the fragment will not be affected by the auxiliary object, and the fragment can be displayed in front of the auxiliary object. Therefore, the hair rendering device can determine the target fragment that is not blocked by the auxiliary object and can be displayed based on the comparison result by comparing the depth of each fragment with the reference depth. The comparison result corresponding to each fragment can indicate whether the depth of the fragment is greater than the reference depth. The comparison process is also a depth test process, and the fragment that passes the depth test is used as the fragment to be displayed. The depth test is to compare the depth value of the object itself with the depth value of the current depth buffer (such as the reference depth) for a certain pixel. If the test passes, the color of the object will be written into the color buffer of the pixel.
[0047] In one embodiment, the hair rendering device may not limit the number of target fragments, and directly determine the fragments that pass the depth test among the fragments corresponding to the target pixel, that is, the fragments whose depth is less than or equal to the reference depth (such as called candidate fragments), as the target fragments to be displayed.
[0048] In another embodiment, the hair rendering device may limit the maximum number of target fragments (such as the target number), and determine at most the target number of candidate fragments as the target fragments to be displayed. Accordingly, step 1024 may include: when it is determined based on the comparison result that the number of candidate fragments in each fragment corresponding to the target pixel is greater than the target number, determining the target number of candidate fragments as the target fragments to be displayed; wherein the depth of the candidate fragments is less than or equal to the reference depth.
[0049] For example, the hair rendering device may select the first target number of candidate fragments with smaller depths among the candidate fragments as target fragments. The hair rendering device may sort the depths of the candidate fragments in descending order to determine the first target number of candidate fragments and use them as target fragments. Optionally, the hair rendering device may randomly select the target number of candidate fragments from the candidate fragments as target fragments. Step 1024 may also include: when the number of candidate fragments is less than or equal to the target number, the hair rendering device directly determines each candidate fragment as a target fragment.
[0050] The target number can be 6, 8, 16 or other values, and the setting of the target number must ensure that the rendering effect meets the requirements. The target number can be defined by the user. The higher the target number, the more display information of the fragments needs to be processed, which can improve the rendering quality of the hair accordingly, but it will increase the running time accordingly, which may cause a certain decrease in the frame rate. Reducing the target number can optimize the execution efficiency and improve the frame rate. In the embodiment of this specification, these two aspects can be comprehensively considered to set a suitable target number. By limiting the number of target fragments, the hair rendering device can render based on fewer target fragments on the basis of ensuring the rendering effect of the hair, obtain less display information for the fragments, and process less display information, which can avoid excessive occupation of memory space and improve information processing efficiency.
[0051] Step 1026: Based on the hair model of the target object, obtain display information of the target fragment.
[0052] For each image frame to be displayed, the hair rendering device can obtain the fragments corresponding to each target pixel and the display information of each fragment after projecting the hair model of the target object in the screen display area. After determining the target fragment, the hair rendering device can directly obtain the display information of the target fragment. The display information includes the color value and transparency of the target fragment.
[0053] In some embodiments, the hair rendering device may construct a buffer for each pixel in the screen display area to store information required for rendering the corresponding pixel in each buffer, and then render the corresponding pixel based on the information stored in the buffer. The hair rendering device may also sort the depths of the candidate fragments by filling information in the buffer corresponding to the target pixel, thereby determining the target fragment and caching the display information of the target fragment.
[0054] Before step 102, the hair rendering device may construct a buffer space for the screen display area. The buffer space includes a buffer for each pixel in the screen display area, and the buffer for each pixel includes a target number of sub-buffers. The order of the target number of sub-buffers corresponds to successively decreasing depths, and the target number of sub-buffers may respectively correspond to multiple layers of hair with successively decreasing depths (also corresponding to multiple fragments with successively decreasing depths), and each sub-buffer may store the depth of the corresponding fragment.
[0055] In the above step 1024, when it is determined based on the comparison result that the number of candidate fragments in each fragment is greater than the target number, the target number of candidate fragments are determined as the target fragments to be displayed, which can include: for each candidate fragment in each fragment whose depth indicated by the comparison result is less than or equal to the reference depth, the depth of each candidate fragment is sequentially inserted and sorted in the sub-buffer of the target number; and the candidate fragment corresponding to the depth filled in the sub-buffer of the target number after the insertion and sorting is completed is determined as the target fragment to be displayed.
[0056] The hair rendering device can perform depth tests on each fragment corresponding to the target pixel in turn. After each candidate fragment that passes the depth test is determined, the depth of the candidate fragment is compared with the depth filled in each sub-buffer corresponding to the target pixel, and the filling method for each sub-buffer is determined based on the comparison result. If there is an unfilled sub-buffer during filling, the depth of the newly determined candidate fragment can be filled into a sub-buffer; after each sub-buffer is filled, for the newly determined candidate fragment, it is necessary to determine whether its depth needs to be filled into the sub-buffer. When filling the depth of the candidate fragment in the sub-buffer, the hair rendering device also needs to determine the sub-buffer that should be filled, and whether to adjust the depth originally filled in each sub-buffer.
[0057] When a new candidate fragment is determined, there is a case where there is an unfilled sub-buffer: if the depth of the candidate fragment is less than the depth filled in each sub-buffer, the depth of the candidate fragment is directly filled into the front idle sub-buffer. If the depth of the candidate fragment is between the depths filled in two sub-buffers, the depth filled in each sub-buffer that is less than the depth of the candidate fragment is moved forward by one sub-buffer, and the depth of the candidate fragment is filled into the newly vacated sub-buffer. Each fragment corresponding to a target pixel can represent different hair strands respectively, and the depth of each fragment is basically different. Therefore, the case where the depth of the candidate fragments is the same is not considered in the embodiments of this specification.
[0058] When a new candidate fragment is determined, there is no unfilled sub-buffer: if the depth of the candidate fragment is greater than the depth filled in each sub-buffer, the depth of the candidate fragment is not filled in the sub-buffer. If the depth of the candidate fragment is between the depths filled in two sub-buffers, the maximum filled depth (that is, the depth filled in the last sub-buffer) is deleted, and the depth filled in each sub-buffer greater than the depth of the candidate fragment is moved back by one sub-buffer, and the depth of the candidate fragment is filled into the newly vacated sub-buffer.
[0059] In this way, for each determined candidate fragment, the depth is filled and adjusted in each sub-buffer corresponding to the target pixel. After the traversal of the determined candidate fragments is completed, the depth filled in each sub-buffer is the depth of the candidate fragment of the previous target number with the smallest depth, and the candidate fragment corresponding to the depth filled in each sub-buffer is the determined target fragment.
[0060] Figure 3 It is a schematic diagram of filling depth in a sub-buffer corresponding to a target pixel provided by an embodiment of this specification. Figure 3 Take the case where the number of targets is 6 and the target pixels correspond to 6 sub-buffers. The arrows between the sub-buffers represent the order between the sub-buffers. Along the direction indicated by the arrows, the depth filled in each sub-buffer decreases in sequence. The initial value of each sub-buffer before the depth is not filled is 0xFFFFFFFFu, which is an unsigned hexadecimal immediate value, that is, the maximum value of the 32-bit depth value. Figure 3 As shown, assuming that 4 of the 6 sub-buffers have been filled, and the filled depth values are 0.8, 0.6, 0.4 and 0.2 respectively, the depth values in each sub-buffer decrease in sequence according to the order of the sub-buffers. If the hair rendering device determines another candidate fragment with a depth value of 0.7, the hair rendering device can determine that the depth value is between the depth values filled in the first sub-buffer and the second sub-buffer, and accordingly can insert the depth value between the two depth values, so that the depth values smaller than 0.7 are moved forward one sub-buffer in sequence, thereby adjusting the depth filled in each sub-buffer.
[0061] In one embodiment, each sub-buffer corresponding to the target pixel may also be filled with display information of the fragment, such as the color value and transparency of the fragment. After completing the depth filling for each sub-buffer, the hair rendering device may fill the display information for each sub-buffer based on the depth, and the display information filled in each sub-buffer is the display information of each target fragment. The order of each sub-buffer can reflect the depth order of the target fragment, and the hair rendering device may mix the color value of each target fragment based on the display information filled in each sub-buffer and the order of each sub-buffer.
[0062] In this embodiment, the step 1026 of acquiring the display information of the target fragment based on the hair model of the target object may include: based on the hair model, using the depth filled in each sub-buffer corresponding to the target pixel as an index, acquiring the display information of the corresponding target fragment, and filling the acquired display information into each sub-buffer. The step 104 of sequentially mixing the color values of the multiple target fragments in the order of the depths of the multiple target fragments from large to small based on the transparency of the multiple target fragments may include: sequentially mixing the color values in the display information filled in each sub-buffer based on the transparency in the display information filled in each sub-buffer according to the order of the sub-buffers corresponding to the target pixel.
[0063] Since the depths of different fragments corresponding to the target object are usually different, the depth of the fragment can be directly used as the index of the fragment. After the hair rendering device completes the filling of the depth of each sub-buffer corresponding to the target pixel, it can obtain the display information of the fragment corresponding to the depth (that is, the target fragment) in each fragment corresponding to the target pixel in the hair model of the target object based on the depth filled in each sub-buffer, and fill it into the corresponding sub-buffer.
[0064] The hair rendering device can directly obtain the display information of the corresponding target fragment based on the depth in the sub-buffer. In an optional implementation, the hair rendering device traverses each fragment or each candidate fragment corresponding to the target pixel, and determines whether the depth of each fragment matches the depth filled in the sub-buffer based on the depth and display information of each fragment. When it is determined that the depth of any fragment matches the depth in a sub-buffer, the color value and transparency of the fragment are filled into the sub-buffer. After the traversal is completed, the color value and transparency of each sub-buffer can be filled, and then the color of each target fragment corresponding to the target pixel can be sorted according to the depth, and an RGBA color list sorted according to the depth is obtained, and the display information filled in each sub-buffer is an element in the color list.
[0065] Continue to use Figure 3 For example, if the color of a fragment is red, the depth is 0.4, and the transparency is 0.2, the fragment can match the depth value of 0.4 filled in the sub-buffer, and the red color and the transparency value of 0.2 can be written into the sub-buffer. For example, the depth value can be matched by binary search. Optionally, the hair rendering device can also first determine the index of the sub-buffer, and then write the display information into the sub-buffer indicated by the index. Figure 3 The indexes of the six sub-buffers are 0 to 5 in order, and the index of the sub-buffer corresponding to the depth value of 0.4 is 3. The hair rendering device can write the red color and the transparency value of 0.2 into the sub-buffer with an index of 3.
[0066] In one embodiment, the target pixel corresponds to two groups of target number of sub-buffers, the two groups of sub-buffers are completely identical and correspond one to one, and are used to fill depth and display information respectively. Alternatively, it can be considered that each sub-buffer corresponding to the target pixel includes a depth buffer and a color buffer, and the color buffer is used to fill color values and transparency. Based on the depth information filled in the depth buffer, the display information filled in the color buffer is determined.
[0067] The hair rendering device first mixes the color values filled in the last two color buffers based on the transparency filled in the two color buffers according to the order of the sub-buffers corresponding to the target pixel (such as the order of the color buffers). Then, based on the transparency filled in the previous color buffer, the mixed color value is mixed again with the color value filled in the previous color buffer to obtain a new mixed color value. In this way, the color values filled in each sub-buffer are mixed in sequence to obtain the final mixed color value of the target pixel.
[0068] Assume that the target pixel corresponds to m target fragments, m≥2, and m is less than or equal to the target number. The depths of the m target fragments decrease in sequence, and the first target fragment is the target fragment with the largest depth among the m target fragments, such as its depth and display information filled in the first sub-buffer. The i-th target fragment among the m target fragments can correspond to the i-th sub-buffer, 1≤i≤m. In the above step 104, based on the transparency of the multiple target fragments, the color values of the multiple target fragments are mixed in sequence in the order of the depths of the multiple target fragments from large to small to obtain the mixed color value of the target pixel, which may include the following steps 1042 to 1046.
[0069] Step 1042, superimpose the i-th superimposed color value on the color value of the i+1-th target fragment to obtain the i+1-th mixed color value; wherein, 1≤i≤m, the i-th superimposed color value is determined based on the i-th mixed color value and the transparency of the i+1-th target fragment; when i=1, the i-th mixed color value is the color value of the i-th target fragment.
[0070] In the embodiments of the present specification, each mixed color value can be determined based on a semi-transparent mixing algorithm (such as an OVER operation method), based on the color value of the target fragment in front, the mixed color value of the fragment behind it is superimposed based on transparency, and the mixed color value obtained after the target fragment and the fragment behind it are mixed is obtained. The OVER operation does not conform to the commutative law, so it needs to be calculated in order, so the aforementioned depth-based display information sorting process needs to be performed.
[0071] The i-th superimposed color value D i = (1-a i+1 )×Hi , where C i+1 Indicates the color value of the i+1th target fragment, a i+1 Indicates the transparency of the i+1th target fragment, H i Indicates the i-th mixed color value, and “×” indicates the multiplication operator. When i=1, H i =C i , that is, the first mixed color value is the color value of the first target fragment. Correspondingly, D1=(1-a2)×C1, so by adjusting the color value of the first target fragment, the first superimposed color value required for color mixing with the second target fragment is determined. When 1<i≤m, the i-th mixed color value is obtained based on the method of step 1042.
[0072] The i+1th mixed color value H i+1 =C i+1 +D i =C i+1 + (1-a i+1 )×H i , where C i+1 Represents the color value of the i+1th target fragment, and accordingly H2=C2+(1-a2)×C1, so the color value obtained by mixing the first target fragment and the second target fragment is obtained, that is, the second mixed color value.
[0073] Afterwards, the hair rendering device may set i=i+1 and execute step 1042 again to obtain the third mixed color value, that is, the color value obtained by mixing the first three target fragments. The first target fragments mentioned here refer to the target fragments at the front when the depth is sorted from large to small. The hair rendering device repeatedly sets i=i+1 and executes step 1042 again until i=m, and determines the mth mixed color value. The mth mixed color value can be calculated using the following formula, which can be: H m =[C m + (1-a m )×...[C3+(1-a3)×[C2+(1-a2)×C1]]...].
[0074] In the embodiment of this specification, the hair rendering device can be based on the H m The calculation formula of is used to directly determine the mth mixed color value. Alternatively, the hair rendering device can also perform multiple iterations to determine each mixed color value in turn until the mth mixed color value is obtained. In the embodiment of this specification, the i-th target fragment corresponds to the i-th sub-buffer, and the color value and transparency of the i-th target fragment can be obtained from the corresponding sub-buffer for calculation.
[0075] Step 1044: determine the mth mixed color value as the mixed color value of the target pixel obtained by sequentially mixing the color values of m target fragments.
[0076] The mth mixed color value is the mixed color value obtained by sequentially mixing the target fragments corresponding to the target pixel in the order of depth. Afterwards, the hair rendering device can render the hair at the target pixel based on the mth mixed color value.
[0077] In the embodiment of this specification, the process of constructing a buffer space for the screen display area (such as a display screen) before hair rendering can belong to the rendering preparation process. For example, a calculation buffer (ComputeBuffer, such as ABuffer) can be constructed for the screen display area. The size of ABuffer can satisfy x×y×s 2 ×m×2, where x represents the horizontal number of pixels in the screen display area, y represents the vertical number of pixels in the screen display area, s represents the screen zoom factor that can be defined by the user, and m represents the aforementioned target number, which can be the number of hair layers that need to be sorted defined by the user. For each pixel, a corresponding depth buffer and color buffer can be set, so the size needs to be multiplied by "2" in determining it.
[0078] The user-definable screen scaling factor s has a value range of (0, 1]. When s=1, each image frame will be rendered at the original screen resolution; when s=0.5, each image frame will be rendered at a quarter of the screen resolution. Since both horizontal and vertical pixels are multiplied by the scaling factor when scaling, a square operation needs to be performed on the scaling factor. The target number determines how many layers of hair the hair rendering device can process in the subsequent process. The target number is determined based on a comprehensive consideration of rendering quality and running time.
[0079] After the buffer space is constructed, before each frame of image is rendered, the buffer corresponding to each pixel can be initialized. This process belongs to the rendering preparation process for the frame of image. The hair rendering device can use the compute shader (ComputeShader) to set the ABuffer allocated for each pixel to the "pre-rendering" state. In this state, the color value in each sub-buffer corresponding to each pixel is 0, and the depth value is 0xFFFFFFFFu, which is the maximum depth value. Setting the color value to 0 can clear the rendering result of the previous frame to prevent the phenomenon of screen afterimage. Setting the depth value to the maximum value can facilitate the subsequent sorting of the depth of each incoming fragment. The depth values of all incoming fragments are smaller than the initial depth value in the sub-buffer, so that the depth of all fragments corresponding to each pixel can be considered. After completing this step, the subsequent rendering process can be performed, and step 102 and subsequent steps are executed.
[0080] In the process of rendering the hair of the target object, the XY coordinates of each position in the hair model in the homogeneous clipping space can be defined as the unique index position of the corresponding target pixel in ABuffer. The hair rendering device can first find the reference depth corresponding to each target pixel (which can correspond to a depth map in the screen space), and call the first drawing to obtain the depth of each fragment corresponding to each target pixel. Based on the reference depth corresponding to each target pixel, a depth test is performed on each fragment corresponding to the target pixel to determine whether the depth of each fragment is greater than the reference depth. If greater, the depth test fails and the sorting process for the fragment is not executed; if passed, the insertion sort (Insertion Sort) method is applied to sort the Z values of each fragment of the target pixel corresponding to the XY coordinate for each sub-buffer corresponding to the target pixel, and obtain the fragment depth (corresponding to the hair depth) corresponding to the target pixel sorted from large to small. After completing this step, the depth buffer in ABuffer will be filled.
[0081] For example, Figure 4 is a schematic diagram of a hair model that has undergone depth testing provided by an embodiment of this specification. Figure 4 Take the target object as a person and the hair model as an example. Figure 4 The area surrounded by the white lines is the projection area of the character's hair model in the screen display area. Area Q1 in the projection area indicates the area where the target pixel of the fragment passes the depth test, and area Q2 indicates the area where the target pixel of the fragment fails the depth test. The fragment that fails the depth test is blocked by the foreground, so the corresponding pixel does not need to render the character's hair.
[0082] After sorting the depths of each fragment of the target pixel, the hair rendering device can call the second drawing to obtain the RGBA color value (RGB corresponds to the color value, and A corresponds to transparency) and depth value of each target fragment corresponding to the target pixel. The depth value is matched with the sorted depth values (that is, the depth value in each sub-buffer) to fill the RGBA color value with successful depth matching into the sub-buffer indexed by the corresponding depth value, complete the sorting of the RGBA color value, and obtain the RGBA color list sorted by depth.
[0083] Afterwards, the hair rendering device can mix the hair color according to the depth for each target pixel, that is, mix the color value of each target fragment. The hair rendering device uses the OVER operation to calculate the new RGBA color value obtained after each hair layer is aliased with the hair layer behind it based on the color list sorted according to the depth, so as to obtain the mixed color value of each layer. Based on the operation method, the hair rendering device can obtain the calculation method required for the simultaneous mixing of each target fragment, and then directly determine the final mixed color value obtained by mixing each target fragment corresponding to the target pixel based on the calculation method.
[0084] The hair rendering device may render the obtained mixed color values corresponding to each target pixel to a rendering texture (RenderTexture, which may also be called a rendering material). For example, Figure 5 FIG. 1 is a schematic diagram of a mixed color value corresponding to a hair model provided in an embodiment of the present specification rendered to a rendering texture. Figure 5 As shown, the obtained rendering texture may only include the part of the hair model that is not blocked by the foreground and should be displayed. The hair rendering device may combine the obtained rendering texture corresponding to the hair model into the final color map, and render the final color map to achieve the overall rendering of the image frame, and correspondingly achieve the hair rendering of the target object at each target pixel. For example, the hair rendering device may use the hardware function AlphaBlend of the GPU to combine the rendering texture into the final color map. For example, the parameter of the AlphaBlend function is "One, 1 - Src Alpha".
[0085] The above content takes the mixed rendering for the target pixel based on the color value of the target fragments of the target number at most as an example. In some embodiments, the hair rendering device can also render the target pixel in combination with the display information of the fragments other than the target fragments of the target number in the candidate fragments that pass the depth test. For example, the hair rendering device generates a first rendering texture based on the display information of the fragments other than the target fragments in the candidate fragments. In the above step 106, the hair of the target object is rendered on the target pixel based on the mixed color value corresponding to the target pixel, which may include: generating a second rendering texture based on the mixed color value; rendering the hair of the target object on the target pixel based on the first rendering texture and the second rendering texture. For the generation of the second rendering texture, reference may be made to the above introduction to the rendering texture. The generated first rendering texture may be located under the second rendering texture, and the second rendering texture is displayed as the foreground of the first rendering texture. By also rendering the display information of the candidate fragments other than the target fragment, the rendering effect of the hair of the target object can be further guaranteed, and the skin that should not be exposed under the hair is avoided from being exposed, thereby improving the overall display effect of the picture.
[0086] If there are other fragments in addition to the target number of target fragments in the candidate fragments, the hair rendering device can randomly select a fragment from the other fragments, output the display information of the fragment to the rendering texture, and obtain the first rendering texture. Optionally, the hair rendering device can also generate the first rendering texture based on the display information of the fragment with the smallest depth among the other fragments. For example, when the hair rendering device matches the depth of the candidate fragment corresponding to the target pixel with the depth filled in the sub-buffer during the second drawing, if it is determined that the depth of a candidate fragment is not in each sub-buffer, the display information of the candidate fragment is directly output to the rendering texture.
[0087] In some embodiments, the hair rendering device can also dynamically adjust the resolution of the hair model. Before obtaining the display information of the target fragment to be displayed corresponding to the target pixel in the hair model for any target pixel corresponding to the hair model of the target object in the screen display area in step 102, the hair rendering device can also: obtain the target resolution; determine the target pixels corresponding to the hair model of the target object in the screen display area based on the target resolution. For different target resolutions, the target pixels corresponding to the hair model will be different, and the fragments corresponding to a target pixel will also be different. Under each target resolution, the hair rendering device determines the corresponding target pixel and the fragment corresponding to the target pixel based on the target resolution.
[0088] For example, the hair rendering device can automatically detect its own configuration and performance to determine a target resolution that matches it. Alternatively, the target resolution can also be set by the user, and the hair rendering device can obtain the target resolution set by the user to render the hair of the target object based on the target resolution. For example, the user can adjust the target resolution at any time during the running of the target program.
[0089] Optionally, the target resolution may correspond to the aforementioned user-defined zoom factor. If the user specifies a certain zoom ratio for image display, the hair rendering device may determine the corresponding target resolution based on the zoom factor. If the zoom factor is 1, that is, no zoom is performed, the highest screen resolution or the default screen resolution is used for hair rendering; if the zoom factor is 0.5, the horizontal and vertical resolutions are reduced by half based on the original resolution.
[0090] In the embodiments of this specification, the rendering resolution of hair can be adjusted dynamically, which can improve the flexibility of hair rendering, and can ensure that the actual hair rendering matches the required rendering requirements, thereby improving the hair rendering effect. This can also ensure that the hair model is compatible with a variety of different platforms and can be rendered appropriately on various platforms.
[0091] The rendering of various objects in the screen can be achieved by using the corresponding shader. For example, the hair model is rendered using the hair shader. The hair shader can be understood as the code that describes how the hair should be rendered. The hair shader can usually be written in advance and supports the function of user-defined hair color. The shader can be written and generated using the shader graph. Figure 1 Generally, it is a graphical programming interface editor provided by the game engine to facilitate artists to write shaders. Users can add, delete or modify corresponding module information in the shader graph to modify the shader graph, and adjust the corresponding code logic accordingly to modify the shader. In the embodiment of this specification, based on the shader generated by the shader graph, the shader can realize the above-mentioned hair rendering method, improve user usability and reduce code coupling.
[0092] Before obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model for any target pixel in the screen display area corresponding to the hair model of the target object in step 102, the hair rendering device may first adjust the default shader. For example, the hair rendering device may respond to an instruction to enable the enhanced hair rendering function by adding depth sorting module information and color sorting module information to the initial shader graph to obtain an updated shader graph; and compile the updated shader graph to obtain a target shader.
[0093] For example, an enhanced hair rendering function may be added to the target application of the hair rendering device, such as a control corresponding to the function may be included in the setting page of the target application, and the user may trigger the control to choose whether to enable the function. If the function is not enabled, other methods (such as the dithering translucent method in the related art) may be used for hair rendering. If the function is enabled, the original rendering process is closed, and the hair rendering method provided in the embodiment of this specification is used for hair rendering.
[0094] When this function is turned on, the hair rendering device can receive an instruction to turn on the enhanced hair rendering function, and accordingly can modify the initial shader graph based on the modification method of the shader graph corresponding to the function, such as adding depth sorting module information and color sorting module information to the initial shader graph to obtain an updated shader graph. The depth sorting module information is used to trigger the depth sorting of each fragment corresponding to the target pixel during the rendering process, and the color sorting module information is used to trigger the sorting of color values based on the depth of the target fragment. For the updated shader graph, the corresponding logic code is refreshed to recompile the updated shader graph.
[0095] The hair rendering device can use the target shader to implement the hair rendering method in the embodiment of this specification, such as the aforementioned steps 102 to 106 are all implemented using the target shader. That is, the above step 102 includes: using the target shader, obtaining the display information of the target fragment to be displayed corresponding to the target pixel in the hair model. The above step 104 includes: using the target shader, based on the transparency of the multiple target fragments, in the order of the depth of the multiple target fragments from large to small, sequentially mixing the color values of the multiple target fragments to obtain the mixed color value of the target pixel. The above step 106 includes: using the target shader, based on the mixed color value, rendering the hair of the target object on the target pixel.
[0096] The embodiments of this specification provide a scheme for rendering hair by sorting based on the depth of the fragments. The influence of each hair strand corresponding to each target pixel on the final rendering result can be considered. The hair strands are introduced into the Alpha channel. Under the limitation of a given number of layers (that is, the target number of target fragments), color mixing operations are performed based on transparency in sequence according to the depth order of the hair strand fragments in the homogeneous clipping space. In this way, each pixel can represent the density of the hair by the size of the Alpha value, which can eliminate the flickering and discontinuous feeling of the hair in the traditional hair rendering scheme. During rendering, depth sorting and semi-transparent mixing will be performed in real time on the GPU side, so that the hair interlacing effect is natural, and the hair model does not need to consider the interlacing problem of the hair strands when making it. In addition, in the embodiments of this specification, a good rendering effect can be achieved by relying on other rendering functions, and the rendering resolution of the hair can be dynamically adjusted. This scheme can be adapted to run on more platforms to ensure that hair rendering can be performed well on all platforms.
[0097] Figure 6 This is a hair rendering effect diagram provided in an embodiment of this specification. Figure 6 Figure (a) is a rendering of hair in a traditional solution, and Figure (b) is a rendering of hair in a method for rendering hair according to an embodiment of the specification. Based on the comparison, it can be seen that the present solution has a higher degree of continuity in the display of various hair positions, and better displays the density of hair at various locations, resulting in a better hair rendering effect.
[0098] Corresponding to the above-mentioned hair rendering method embodiment, this specification also provides a hair rendering device embodiment. Figure 7 FIG. 1 is a schematic diagram of a hair rendering device provided in an embodiment of the present specification. Figure 7 As shown, the hair rendering device includes: A first acquisition module 702 is used to acquire, for any target pixel corresponding to the hair model of the target object in the screen display area, display information of a target fragment to be displayed corresponding to the target pixel in the hair model, wherein the display information includes a color value and transparency; A mixing module 704 is used for mixing the color values of the multiple target fragments in descending order of depth based on the transparency of the multiple target fragments to obtain a mixed color value of the target pixel when the target pixel corresponds to multiple target fragments; The rendering module 706 is used to render the hair of the target object on the target pixel based on the mixed color value.
[0099] Optionally, the first acquisition module 702 includes: A first acquisition submodule is used to acquire, for any target pixel corresponding to the hair model of the target object in the screen display area, the depth of each fragment corresponding to the target pixel in the hair model; wherein the depth of the fragment indicates the distance between the fragment and the virtual camera; A determination submodule, configured to compare the depth of each fragment with a reference depth corresponding to a target pixel, and determine a target fragment to be displayed in each fragment based on the comparison result; wherein the reference depth includes the depth of an object rendered before the hair of the target object; The second acquisition submodule is used to acquire display information of the target fragment based on the hair model.
[0100] Optionally, determine the submodule for: When it is determined based on the comparison result that the number of candidate fragments in each fragment is greater than the target number, the target number of candidate fragments are determined as target fragments to be displayed; wherein the depth of the candidate fragments is less than or equal to the reference depth.
[0101] Optionally, the hair rendering device further comprises: A construction module is used to construct a buffer space for the picture display area before obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model for any target pixel corresponding to the target object in the picture display area, wherein the buffer space includes a buffer for each pixel in the picture display area, the buffer for each pixel includes a target number of sub-buffers, and the sub-buffers of the target number are arranged in descending order corresponding to depths; Determine the submodules used to: For each candidate fragment whose comparison result indicates that the depth is less than or equal to the reference depth, the depth of each candidate fragment is sequentially inserted and sorted in the target number of sub-buffers; The candidate fragments corresponding to the depth filled in the target number of sub-buffers after the insertion sort is completed are determined as the target fragments to be displayed.
[0102] Optionally, the second acquisition submodule is used for: Based on the hair model, the depth filled in each sub-buffer corresponding to the target pixel is used as an index to obtain the display information of the corresponding target fragment, and the obtained display information is filled into each sub-buffer; The mixing module 704 is used to: According to the order of the sub-buffers corresponding to the target pixel, based on the transparency in the display information filled in each sub-buffer, the color values in the display information filled in each sub-buffer are mixed in sequence.
[0103] Optionally, the target pixel corresponds to m target fragments, m≥2, the depths of the m target fragments decrease in sequence, and the first target fragment is the target fragment with the largest depth among the m target fragments; the mixing module 704 is used for: Based on the i-th mixed color value and the transparency of the i+1-th target fragment, determine the i-th superimposed color value; where 1≤i≤m; when i=1, the i-th mixed color value is the color value of the i-th target fragment; Superimpose the i-th superimposed color value on the color value of the i+1-th target fragment to obtain the i+1-th mixed color value; The mth mixed color value is determined as the mixed color value of the target pixel obtained by sequentially mixing the color values of the m target fragments.
[0104] Optionally, the hair rendering device further comprises: A generating module, configured to generate a first rendering texture based on display information of fragments other than the target fragment in the candidate fragments; The rendering module 706 is used to: generating a second rendering texture based on the mixed color value; The hair of the target object is rendered on the target pixel based on the first rendering texture and the second rendering texture.
[0105] Optionally, the hair rendering device further comprises: A second acquisition module is used to acquire the target resolution before acquiring display information of a target fragment to be displayed corresponding to the target pixel in the hair model for any target pixel corresponding to the hair model of the target object in the screen display area; The determination module is used to determine each target pixel corresponding to the hair model of the target object in the screen display area based on the target resolution.
[0106] Optionally, the hair rendering device further comprises: An adding module is used for, for any target pixel corresponding to the hair model of the target object in the screen display area, before obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model, in response to an instruction to start the enhanced hair rendering function, adding depth sorting module information and color sorting module information to the initial shader graph to obtain an updated shader graph; A compiling module, used for compiling the updated shader graph to obtain a target shader; The first acquisition module 702 is used for: Using the target shader, obtaining display information of the target fragment to be displayed corresponding to the target pixel in the hair model; The mixing module 704 is used to: Using the target shader, based on the transparency of the multiple target fragments, the color values of the multiple target fragments are sequentially mixed in descending order of the depth of the multiple target fragments to obtain the mixed color value of the target pixel; The rendering module 706 is used to: The target object's hair is rendered at the target pixel based on the blended color value using the target shader.
[0107] In summary, in the hair rendering device provided in the embodiment of the present specification, for the target pixel to be rendered hair, the target fragments to be displayed corresponding to the target pixel in the hair model are mixed in color values based on transparency in the order of depth from large to small, and then the hair is rendered on the pixel based on the obtained mixed color value. In this way, for each target pixel, the influence of each hair corresponding to the target pixel on the display of the target pixel can be comprehensively considered, and the color is mixed based on transparency in the depth order of each fragment, which can ensure that the obtained mixed color value is closer to the visual color in the real scene, and the combination of transparency can enrich the density of the hair, reduce the sense of discontinuity when the hair is displayed, improve the hair rendering effect, and accordingly improve the display effect of the entire picture.
[0108] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. As for the display device of the target image, since it is basically similar to the embodiment of the display method of the target image, the description is relatively simple, and the relevant parts can be referred to the partial description of the embodiment of the display method of the target image.
[0109] Figure 8 800 is a block diagram of a computing device provided in an embodiment of the present specification. The components of the computing device 800 include but are not limited to a memory 810 and a processor 820. The processor 820 is connected to the memory 810 via a bus 830, and the database 850 is used to store data.
[0110] The computing device 800 also includes an access device 840 that enables the computing device 800 to communicate via one or more networks 860. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 840 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, and a near field communication (NFC).
[0111] In one embodiment of the present specification, the above components of the computing device 800 and Figure 8 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 8 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0112] The computing device 800 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 800 may also be a mobile or stationary server.
[0113] The processor 820 is used to execute computer programs / instructions. When the computer programs / instructions are executed by the processor, the above Figure 1 The method shown.
[0114] As for the computing device embodiment, since it is basically similar to the above-mentioned method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0115] One embodiment of the present specification also provides a computer-readable storage medium, which stores computer instructions, and when the computer instructions are executed by the processor, the steps of the above-mentioned image processing method are implemented. The computer instructions include computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable storage medium may include: any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable storage medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable storage media do not include electric carrier signals and telecommunication signals.
[0116] An embodiment of the present specification also provides a computer program product, including a computer program / instruction, which implements the steps of the above method when the computer program / instruction is executed in a processor.
[0117] As for the computer-readable storage medium embodiment and the computer program product embodiment, since they are basically similar to the above-mentioned method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0118] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0119] It should be noted that the above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of the present specification.
[0120] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0121] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can understand and use this specification well.
Claims
1. A hair rendering method, characterized in that: The method comprises: For any target pixel in the screen display area corresponding to the hair model of the target object, obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model, wherein the display information includes a color value and transparency; In the case where the target pixel corresponds to a plurality of target fragments, based on the transparency of the plurality of target fragments, the color values of the plurality of target fragments are sequentially mixed in descending order of the depths of the plurality of target fragments to obtain a mixed color value of the target pixel; wherein the depth of the fragment indicates the distance of the fragment from the virtual camera; The hair of the target object is rendered at the target pixel based on the mixed color value.
2. The method according to claim 1, characterized in that The step of acquiring, for any target pixel in the screen display area corresponding to the hair model of the target object, display information of a target fragment to be displayed corresponding to the target pixel in the hair model, comprises: For any target pixel in the screen display area corresponding to the hair model of the target object, obtaining the depth of each fragment corresponding to the target pixel in the hair model; Comparing the depth of each fragment with a reference depth corresponding to the target pixel, and determining a target fragment to be displayed among the fragments based on the comparison result; wherein the reference depth includes the depth of an object rendered before the hair of the target object; Based on the hair model, display information of the target fragment is obtained.
3. The method according to claim 2, characterized in that The determining of a target fragment to be displayed among the fragments based on the comparison result includes: When it is determined based on the comparison result that the number of candidate fragments in the fragments is greater than the target number, the target number of candidate fragments are determined as target fragments to be displayed; wherein the depth of the candidate fragments is less than or equal to the reference depth.
4. The method according to claim 3, characterized in that Before obtaining display information of a target fragment to be displayed corresponding to any target pixel in the hair model of the target object in the screen display area, the method further includes: Constructing a buffer space for the picture display area, wherein the buffer space includes a buffer for each pixel in the picture display area, each pixel buffer includes a target number of sub-buffers, and the sub-buffers are ordered in descending order corresponding to depths; The step of determining the target number of candidate fragments as target fragments to be displayed when the number of candidate fragments in each fragment is greater than the target number based on the comparison result includes: For each candidate fragment whose comparison result indicates that the depth of each candidate fragment is less than or equal to the reference depth, sequentially inserting and sorting the depths of each candidate fragment in the sub-buffers of the target number; The candidate fragments corresponding to the depth filled in the target number of sub-buffers after the insertion sort is completed are determined as the target fragments to be displayed.
5. The method according to claim 4, characterized in that The acquiring display information of the target fragment based on the hair model includes: Based on the hair model, taking the depth filled in each sub-buffer corresponding to the target pixel as an index, obtaining display information of the corresponding target fragment, and filling the obtained display information into each sub-buffer; The mixing of the color values of the plurality of target fragments in sequence according to the depths of the plurality of target fragments from large to small based on the transparency of the plurality of target fragments comprises: According to the order of the sub-buffers corresponding to the target pixels, based on the transparency in the display information filled in the sub-buffers, the color values in the display information filled in the sub-buffers are mixed in sequence.
6. The method according to any one of claims 1 to 5, characterized in that: The target pixel corresponds to m target fragments, m≥2, the depths of the m target fragments decrease in sequence, and the first target fragment is the target fragment with the largest depth among the m target fragments; the color values of the multiple target fragments are mixed in sequence according to the depths of the multiple target fragments from large to small based on the transparency of the multiple target fragments to obtain the mixed color value of the target pixel, including: The i-th superimposed color value is superimposed on the color value of the i+1-th target fragment to obtain the i+1-th mixed color value; wherein, 1≤i≤m, the i-th superimposed color value is determined based on the i-th mixed color value and the transparency of the i+1-th target fragment; when i=1, the i-th mixed color value is the color value of the i-th target fragment; The mth mixed color value is determined as the mixed color value of the target pixel obtained by sequentially mixing the color values of the m target fragments.
7. The method according to any one of claims 3 to 5, characterized in that: The method further comprises: Generate a first rendering texture based on display information of fragments other than the target fragment in the candidate fragments; The step of rendering the hair of the target object on the target pixel based on the mixed color value comprises: Based on the mixed color value, generating a second rendering texture; The hair of the target object is rendered on the target pixel based on the first rendering texture and the second rendering texture.
8. The method according to any one of claims 1 to 5, characterized in that: Before obtaining display information of a target fragment to be displayed corresponding to any target pixel in the hair model of the target object in the screen display area, the method further includes: Get the target resolution; Each target pixel corresponding to the hair model of the target object in the screen display area is determined based on the target resolution.
9. The method according to any one of claims 1 to 5, characterized in that: Before obtaining display information of a target fragment to be displayed corresponding to any target pixel in the hair model of the target object in the screen display area, the method further includes: In response to an enable instruction for the enhanced hair rendering function, depth sorting module information and color sorting module information are added to the initial shader graph to obtain an updated shader graph; Compiling the updated shader graph to obtain a target shader; The obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model includes: Using the target shader, obtaining display information of a target fragment to be displayed corresponding to the target pixel in the hair model; The step of mixing the color values of the multiple target fragments in descending order of depth based on the transparency of the multiple target fragments to obtain the mixed color value of the target pixel includes: Using the target shader, based on the transparency of the multiple target fragments, and in descending order of the depths of the multiple target fragments, the color values of the multiple target fragments are sequentially mixed to obtain a mixed color value of the target pixel; The step of rendering the hair of the target object on the target pixel based on the mixed color value comprises: The hair of the target object is rendered at the target pixel based on the mixed color value using the target shader.
10. A hair rendering device, characterized in that: The hair rendering device comprises: A first acquisition module is used to acquire, for any target pixel corresponding to the hair model of the target object in the screen display area, display information of a target fragment to be displayed corresponding to the target pixel in the hair model, wherein the display information includes a color value and transparency; a mixing module, configured to, when the target pixel corresponds to a plurality of target fragments, sequentially mix the color values of the plurality of target fragments in a descending order of depths of the plurality of target fragments based on the transparency of the plurality of target fragments, so as to obtain a mixed color value of the target pixel; A rendering module is used to render the hair of the target object on the target pixel based on the mixed color value.
11. A computing device, characterized in that: include: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions. When the computer programs / instructions are executed by the processor, the method according to any one of claims 1 to 9 is implemented.
12. A computer-readable storage medium, characterized in that: A computer program / instruction is stored, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
13. A computer program product, characterized in that The method comprises a computer program / instruction, which implements the method according to any one of claims 1 to 9 when executed by a processor.
