Hair rendering method, device, electronic device and storage medium
By drawing and sampling the target model, rendering results with hair flow effect are generated, which solves the problem of high hair rendering computing resources consumed in the prior art, and achieves efficient hair rendering performance.
Patent Information
- Application Number
- CN202411573004.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-04-04
AI Technical Summary
The prior art consumes a lot of computing resources when rendering hair effects, resulting in poor performance.
By drawing the target model, the drawing results in the frame buffer are obtained, and then based on this result, multiple steps in the target hair flow direction are performed on the pixel position of the hair region, and multiple sampling results are sampled and mixed to generate a rendering result with the hair flow effect.
There is no need to increase the number of model vertices, number of patches or texture sampling times, which achieves hair/hair flow effect, reduces computing resource consumption, and improves rendering performance.
Smart Images

Figure CN119762641A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of rendering technology, and in particular to a hair rendering method, device, electronic device and storage medium. Background Art
[0002] The production of hair effects is a common requirement in the field of rendering technology. For example, animals (cats, dogs, etc.), blankets, and clothing in games all involve hair rendering.
[0003] Under the premise of not increasing labor costs, the existing technology usually renders the hair effect through noise maps and disparity maps, which has the technical problem of high consumption of computing resources. Summary of the invention
[0004] In view of this, an object of the present disclosure is to provide a hair rendering method, device, electronic device and storage medium to reduce the computing resources consumed by hair rendering.
[0005] In a first aspect, an embodiment of the present disclosure provides a hair rendering method, the method comprising: responding to a rendering instruction for a target model, drawing the target model, and obtaining a first drawing result in a frame buffer; based on the first drawing result, performing multiple steps in a target hair flow direction on the pixel position of a specified hair area, and obtaining a hair pixel position corresponding to each step; sampling the first drawing result at the hair pixel position corresponding to each step, and obtaining a plurality of sampling results of the hair pixel stepping; mixing the plurality of sampling results of the hair pixel stepping, and obtaining a target rendering result having a hair flow effect.
[0006] In a second aspect, an embodiment of the present disclosure provides a hair rendering device, which includes: a drawing module, which is used to respond to a rendering instruction for a target model, draw the target model, and obtain a first drawing result in a frame buffer; a stepping module, which is used to step the pixel position of a specified hair area in a target hair flow direction for multiple times based on the first drawing result, and obtain the hair pixel position corresponding to each step; a sampling module, which is used to sample the first drawing result through the hair pixel position corresponding to each step, and obtain multiple sampling results of hair pixel stepping; and a mixing module, which is used to mix the multiple sampling results of the hair pixel stepping, and obtain a target rendering result with a hair flow effect.
[0007] In a third aspect, an embodiment of the present disclosure provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned hair rendering method.
[0008] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned hair rendering method.
[0009] The embodiments of the present disclosure bring the following beneficial effects:
[0010] The above-mentioned hair rendering method, device, electronic device and storage medium first draw the target model into the frame buffer, and then step the pixels of the specified hair area multiple times in the target hair flow direction, sample the frame buffer at the stepped pixel position, and mix the multiple sampling results obtained to generate a target model rendering result with a hair flow effect, so that the hair / hair flow effect can be achieved without increasing the number of model vertices and faces required for rendering, and the number of times the texture is sampled, thereby reducing the computing resources required for hair rendering and improving the hair rendering performance.
[0011] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or understood by practicing the present disclosure. The purpose and other advantages of the present disclosure are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0012] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0014] Figure 1 is a flow chart of an embodiment of a method for rendering hair in an embodiment of the present disclosure;
[0015] Figure 2 is a schematic diagram of a hair rendering method in an embodiment of the present disclosure;
[0016] Figure 3 is another schematic diagram of the hair rendering method according to an embodiment of the present disclosure;
[0017] Figure 4 is another schematic diagram of the hair rendering method according to an embodiment of the present disclosure;
[0018] Figure 5 is another schematic diagram of the hair rendering method according to an embodiment of the present disclosure;
[0019] Figure 6 A schematic diagram of a hair rendering device provided in an embodiment of the present disclosure;
[0020] Figure 7 A schematic diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0022] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0023] It can be understood that rendering is the process of converting 3D models, materials, lighting and other information into 2D images, and the graphics pipeline is a series of processes that convert 3D models into 2D images. The graphics pipeline can be divided into multiple stages, each of which takes the output of the previous stage as input. The series of processes in the rendering pipeline can be abstracted into the geometry drawing stage (pre-processing stage) and the post-processing stage.
[0024] In the geometry drawing stage, the central processing unit (CPU) passes the model data, material, lighting and other information to the graphics processing unit (GPU), which goes through the rendering process of vertex shader, rasterization, pixel shader, etc., and outputs multiple frame buffers (FBO). The frame buffer can include: color buffer, depth buffer, normal buffer and template buffer.
[0025] The main function of the frame buffer is off-screen rendering, that is, the rendering results in the frame buffer are not directly displayed on the monitor, but stored in the frame buffer, which can be used for more flexible image processing and combination. For example, the rendering results in the frame buffer can be used as a map to achieve various post-processing effects in the post-processing stage, such as blur, high dynamic range imaging (HDR), etc.
[0026] It should be noted that the rendering results in the frame buffer can be directly used for display on the display, or used as a map to achieve various post-processing effects in the post-processing stage. For example, in the embodiment of the present disclosure, the target rendering result with the hair flow effect is the post-processing effect obtained by performing a series of post-processing based on the first drawing result in the frame buffer, so that the rendering of the hair does not need to rely on the three-dimensional model containing a complex hair structure, nor does it need to build a separate hair model as an insert for the three-dimensional model, nor does it need to increase the number of model vertices and faces required for rendering, and there is no need to sample the texture multiple times, so that the computing resources required for hair rendering are reduced and the rendering performance is improved.
[0027] For ease of understanding, the specific process of the embodiment of the present disclosure is described below. Figure 1 , an embodiment of the hair rendering method in the embodiment of the present disclosure includes:
[0028] Step S10, responding to a rendering instruction for a target model, drawing the target model, and obtaining a first drawing result in a frame buffer;
[0029] It is understandable that the target model is a three-dimensional model, responds to the rendering instruction for the target model, enters the graphics rendering pipeline for the target model, and after completing the geometric drawing stage in the graphics rendering pipeline, obtains the rendering result in the frame buffer, that is, the first drawing result. It should be noted that the first drawing result can be directly used for display on the display, and can also be used for the post-processing stage of subsequent steps S20-S40. After the processing in the post-processing stage, the post-processing effect of the hair flow is obtained and displayed on the display.
[0030] In one embodiment, the first drawing result is also a rendering result of the target model, which may include a color buffer (also called a color drawing result), a depth buffer (also called a depth drawing result), a normal buffer (also called a normal drawing result) and a template buffer (also called a template drawing result) of the target model. If the rendering result in the frame buffer is not directly used for display on the display, the color buffer may also be used as a color map, the depth buffer may also be used as a depth map, the normal buffer may also be used as a normal map, and the template buffer may also be used as a template map.
[0031] Among them, the color buffer includes the color information of each pixel, and the depth buffer includes the depth information of each pixel, which can be used for depth testing to determine the front and back relationship of pixels; the template buffer includes template values, which can be used for template testing (Stencil test) to control whether the pixel is written to the color buffer or the target rendering result.
[0032] In one implementation, the target model may be part / all of the scene, and the rendering of the target model may be performed simultaneously with the rendering / drawing of other objects in the scene. For ease of understanding, the disclosed embodiment only describes the rendering process of the target model, and the rendering of other objects in the scene is not described in detail.
[0033] Step S20: Based on the first drawing result, the pixel position of the designated hair area is stepped multiple times in the target hair flow direction to obtain the hair pixel position corresponding to each step;
[0034] It is understood that hair flow refers to the phenomenon that the hair shaft and the skin are tilted in the same direction, such as the hair whorl of human hair. In this embodiment, the designated hair area refers to the area where the hair flow effect needs to be generated, specifically the pixel set specified in the first drawing result, which is not limited here. In one embodiment, the designated hair area can be indicated by a mask map, wherein the pixels of the mask area in the mask map are used to indicate the designated hair area.
[0035] As an example and not limitation, assume that Figure 2 The figure shows the color buffer of the target model in the frame buffer, that is, the color rendering result of the target model in the frame buffer. Figure 3 It is the target rendering result of the target model with fur flow effect. Figure 2 and Figure 3 It can be seen that in the color rendering results of the cartoon cat, all areas except the eyes, clothes and headdress are designated hair areas, and all have obtained the hair flow effect.
[0036] Depend on Figure 2 and Figure 3It can also be seen from the comparison that the color rendering result of the target model of the cartoon cat does not itself include hair or hair flow effects, which means that the hair / hair flow effects can be obtained through the disclosed embodiments without making a target model including a hair structure, thereby reducing the complexity of model making. At the same time, since there is no need to increase the number of model vertices and faces required for rendering, the rendering performance of the hair effect is also improved.
[0037] It should be noted that stepping refers to movement in a specified step length along a specified direction. In the present embodiment, the specified direction is the target hair flow direction. The target hair flow directions corresponding to different pixels may be different. The target hair flow direction refers to the inclination direction of the hair shaft of the corresponding pixel and the skin. Pixels with the same inclination direction have the same corresponding target hair flow direction. The specific details are not limited here.
[0038] It can be understood that in the present embodiment, the pixels in the designated hair area are moved toward the corresponding target hair flow direction for multiple designated steps to obtain the position of the pixels after each movement, that is, the hair pixel position corresponding to each step, wherein the hair pixels are pixels in the designated hair area, and each step moves the hair pixels toward the corresponding target hair flow direction by a designated step distance, and the designated step lengths for each step may be the same or different. If they are the same, the hair flow effect finally obtained will have better continuity of hair and will not easily have discontinuities.
[0039] In one embodiment, the target hair flow direction can be determined according to the normal direction of the corresponding hair pixel and the direction of the force, wherein the force can be a force acting on the target model, such as gravity, buoyancy, pressure, and thrust, etc., which are not specifically limited here. In one embodiment, the target hair flow direction can also be pre-specified by parameters to make rendering more efficient.
[0040] It should be noted that the method of performing ray stepping based on parallax mapping can also generate a rough flow effect. The difference between the disclosed embodiments is that the rough flow effect generated based on the parallax mapping requires multiple ray stepping, and each stepping requires sampling the parallax map and the depth map. This is a processing performed before generating the frame buffer, does not belong to the post-processing stage, and requires more computing resources.
[0041] Step S30, sampling the first drawing result at the hair pixel position corresponding to each step, to obtain a plurality of sampling results of the hair pixel step;
[0042] It should be noted that after each step, the first drawing result can be sampled by the hair pixel position after the step to obtain a sampling result of the hair pixel step, and after multiple steps, multiple sampling results can be obtained; or after multiple steps, the first drawing result can be sampled by the hair pixel position corresponding to each step in turn to obtain multiple sampling results of the hair pixel step, which is not limited here.
[0043] In one embodiment, when sampling the first drawing result, the color drawing result in the first drawing result, that is, the color buffer in the frame buffer, can be sampled to obtain multiple color sampling results of hair pixel stepping, so that the hair / hair flow effect can be achieved without increasing the number of model vertices and faces required for rendering, and the number of times the texture is sampled, thereby improving the rendering performance.
[0044] Step S40: Mix multiple sampling results of hair pixel stepping to obtain a target rendering result with a hair flow effect.
[0045] In this embodiment, all sampling results of hair pixel stepping are mixed to obtain a target rendering result with a hair flow effect. In one embodiment, multiple sampling results of hair pixel stepping can be mixed by a preset mixing algorithm to obtain a target rendering result with a hair flow effect, wherein the preset mixing algorithm can be a mean algorithm, a weighted average algorithm, etc., which is not limited here.
[0046] The hair rendering method provided in the above embodiment first draws the target model into the frame buffer, then samples the frame buffer by stepping the pixels of the specified hair area multiple times in the target hair flow direction, and mixes the multiple sampling results obtained to generate a target model rendering result with a hair flow effect, so that the hair / hair flow effect can be achieved without increasing the number of model vertices and faces required for rendering, and the number of times the texture is sampled, thereby reducing the computing resources required for hair rendering and improving the hair rendering performance.
[0047] Next, the stepping method of hair pixels is described in detail.
[0048] In one embodiment, the first drawing result includes: a color drawing result of a target model; when, based on the first drawing result, the pixel position of a specified hair area is stepped multiple times in a target hair flow direction to obtain the hair pixel position corresponding to each step, the position of each pixel point in the color drawing result in the world space is obtained, and the target normal direction of each pixel point in the world space is obtained; according to the target normal direction and the direction of the force applied to the target model, the target hair flow direction of each hair pixel point in the specified hair area of the color drawing result in the world space is determined; based on the position of each hair pixel point in the world space, each hair pixel point is stepped multiple times in the corresponding target hair flow direction to obtain the hair pixel position corresponding to each step.
[0049] It can be understood that since the first drawing result is a two-dimensional image, including multiple pixel points in the screen space, in order to ensure that the rendered hair flow effect does not lose its three-dimensional sense of space and avoid the planar distortion of the hair flow effect, this embodiment combines the normal direction and the normal of the force to determine the target hair flow direction, so that the hair flow effect has a three-dimensional sense of space that fits the target model and the rendering effect is more realistic.
[0050] It should be noted that since the information of the pixel point in the world space retains its three-dimensional spatial information, in this embodiment, the position and target normal direction of each pixel point in the world space in the color drawing result are first obtained, and then the target hair flow direction that the hair pixel point is to step into is determined based on the target normal direction and the force on the target model, and then the hair pixel point is stepped in the target hair flow direction for multiple times to obtain the hair pixel position corresponding to each step, wherein the hair pixel position is also the position information of the world space, so that the hair pixel point is not stepped in the two-dimensional space of the screen, which will not cause the original three-dimensional spatial sense of the hair flow to be lost.
[0051] It can be understood that the hair pixel points are pixel points in the specified hair area. When stepping, only the hair pixel points are stepped multiple times in the target hair flow direction, and the pixel points outside the specified hair area do not participate in the stepping. When the first drawing result is sampled by the hair pixel position corresponding to each step, the pixel points outside the specified hair area are sampled according to their positions in the first drawing result. Therefore, the sampling result of the pixel points outside the specified hair area is the same as the first drawing result.
[0052] In one implementation, the screen space position of each pixel may be restored to the world space according to the screen space coordinates of each pixel in the color rendering result and the depth information of the corresponding pixel in the depth rendering result, thereby obtaining the position of each pixel in the world space.
[0053] Specifically, in one implementation, the first drawing result includes: a depth drawing result of the target model; when obtaining the position of each pixel point in the color drawing result in the world space, sampling the depth drawing result through the screen space coordinates of each pixel point in the color drawing result to obtain the depth of each pixel point in the world space; according to the inverse view projection matrix and the depth of each pixel point in the world space, converting the screen space coordinates of each pixel point to the world space to obtain the position of each pixel point in the color drawing result in the world space.
[0054] In this embodiment, the frame buffer also includes a depth buffer, that is, a depth rendering result of the target model. The depth rendering result includes the depth of the target model relative to the camera, which can be used to determine the front-back relationship of the pixel points. As an example but not a limitation, Figure 4 Shown is Figure 2 and Figure 3 A depth rendering result corresponding to the target model. The depth can be represented by the grayscale value of the image, which is not limited here.
[0055] In this implementation, the depth rendering result is first sampled according to the UV coordinates (also known as: texture coordinates) of each pixel point in the color buffer to obtain the depth of each pixel point in the world space, and then the screen space coordinates of the pixel point can be restored to the world space coordinates through the inverse view projection matrix to obtain the position of each pixel point in the world space.
[0056] Among them, the inverse view projection matrix (InvViewProj) is a composite matrix of the view matrix (View Matrix), the projection matrix (Projection Matrix) and their inverse matrices, which can be used to convert the coordinates of the screen space back to the coordinates of the world space. Specifically, the view matrix is used to transform the coordinates in the world space to the camera space, the projection matrix is used to project the three-dimensional coordinates in the camera space into the two-dimensional viewport to generate a perspective projection or an orthogonal projection, and the inverse matrix of the matrix is used to reverse the transformation.
[0057] In one embodiment, the first drawing result includes: a normal drawing result of the target model; when obtaining the target normal direction of each pixel point in the world space, the normal direction of each pixel point in the color drawing result is restored to the world space according to the normalization method of the normal drawing result to obtain the target normal direction of each pixel point in the world space.
[0058] It is understandable that the component of the normal direction of the world space on each axis is in the range of [-1,1], that is, the normal direction of the world space can be negative, while the normal map (that is, the normal drawing result of the target model) can only store values greater than 0. Therefore, when the normal direction of the world space is stored in the normal drawing result, the normal direction of the world space is converted to the range of [0,1] through a preset normalization method, that is, the normal direction of the world space is normalized, and then the normal drawing result of the target model is obtained.
[0059] By way of example and not limitation, Figure 5 Shown is Figure 2 A schematic diagram of a normal drawing result corresponding to a target model. The normal drawing result can be normalized as shown in the following formula:
[0060] Normal=WorldNormal.xyz×0.5+0.5
[0061] Among them, WorldNormal is the normal direction of the pixel point in the world space, and Normal is the value of the pixel point saved in the normal drawing result, which is a normalized value.
[0062] In this implementation, the normal direction of each pixel in the color drawing result can be restored to the world space, so as to obtain the target normal direction of each pixel in the world space. Specifically, based on the above normalization method, the normal direction of each pixel in the color drawing result can be restored to the world space by the following formula:
[0063] WorldNormal=Normal×2.0-1.0
[0064] Among them, WorldNormal is the normal direction of the pixel in the world space, and Normal is the value of the pixel saved in the normal drawing result.
[0065] In one embodiment, when determining the target hair flow direction of each hair pixel in the specified hair area of the color drawing result in the world space based on the target normal direction and the direction of the force applied to the target model, the target weight of the force direction is obtained, and the target weight is weightedly calculated on the force direction to obtain the weighted force direction; wherein the force direction is the direction of the force applied to the target model; for each hair pixel in the specified hair area of the color drawing result, the target normal direction is superimposed with the weighted force direction to obtain a first hair flow direction of each hair pixel in the world space; and the first hair flow direction is normalized to obtain the target hair flow direction of each hair pixel in the world space.
[0066] In this embodiment, the direction of the force acting on the target model can be preset. For example, assuming that the force acting on the target model includes gravity, the direction of the force is the direction of gravity. If the target model is acted on by more than one force, the resultant force of all forces can be calculated as the direction of the force in this embodiment. Alternatively, a corresponding target weight can be set for each force to obtain more than one weighted force direction.
[0067] In this implementation, the force direction is first multiplied by the corresponding weight to obtain the weighted force direction, and then for each hair pixel, the weighted force direction is superimposed with the target normal direction to obtain the first hair flow direction of each hair pixel in the world space. The first hair flow direction is a vector. By normalizing the vector, the target hair flow direction of each hair pixel in the world space can be obtained.
[0068] Specifically, assuming that the force acting on the target model is gravity, the target flow direction D is:
[0069] D=Normalize(WorldNormal+Gravity×weight)
[0070] Among them, WorldNormal is the normal direction of the pixel in the world space, weight represents the target weight of gravity, Gravity represents the direction of gravity, and Normalize() is the normalization function.
[0071] It should be noted that gravity is generally vertically downward, which can be represented by a three-dimensional vector float3(0,-1,0), which represents a normal vector perpendicular to the XY plane and pointing toward the negative Y axis; and the size of the target weight can affect the fluffiness of the hair in the target rendering result. The smaller the target weight, the fluffier the hair in the target rendering result. The specific details are not limited here.
[0072] In one embodiment, based on the position of each hair pixel point in the world space, each hair pixel point is stepped multiple times in the corresponding target hair flow direction to obtain the hair pixel position corresponding to each step, and the preset step length is multiplied by the target hair flow direction of each hair pixel point in the world space to obtain the step vector of each hair pixel point; the current pixel position of each hair pixel point is repeatedly superimposed with the corresponding step vector to obtain the hair pixel position corresponding to each step.
[0073] In this embodiment, the preset step length is first multiplied by the target hair flow direction of each hair pixel in the world space to obtain the step vector that each hair pixel needs to superimpose in each step, and then the current pixel position of the hair pixel is repeatedly superimposed with the corresponding step vector to obtain the hair pixel position corresponding to each step, wherein, when the step vector is superimposed for the first time, the current pixel position of the hair pixel is the position of the hair pixel in the world space in the color drawing result, and the hair pixel position corresponding to each step can be used as the current pixel position of the hair pixel when the step vector is superimposed next time, and the cycle is repeated to obtain the hair pixel position corresponding to each step. It can be understood that the current pixel position of the hair pixel is the position information in the world space, which is not specifically limited here.
[0074] Specifically, the calculation method of the hair pixel position newPos corresponding to one step of a hair pixel point is as follows:
[0075] newPos=WorldPos+step×D
[0076] Among them, WorldPos is the current pixel position of the hair pixel in the world space, step is the preset step size, and newPos is the new position of the hair pixel after one step. At the next step, the newPos is used as WorldPos and participates in the next step calculation.
[0077] In one embodiment, the designated hair area can be limited or determined by a template buffer in a frame buffer. Specifically, before performing multiple steps in the target hair flow direction on the pixel position of the designated hair area based on the first drawing result to obtain the hair pixel position corresponding to each step, a template test can also be performed using the template buffer in the frame buffer to determine the designated hair area in the first drawing result.
[0078] It can be understood that the template value in the template buffer can be used to distinguish between the designated hair area and the undesignated hair area. For example, the template value of the pixel in the designated hair area is set to 1, and the template value of the pixel in the undesignated hair area is set to 0. In the post-processing stage, only the pixel with the template value of 1 can be post-processed, that is, the above steps S20-S40 are performed, and for the pixel with the template value of 0, the pixel value in the corresponding color drawing result can be directly sampled, which makes the method of specifying the hair area simpler.
[0079] Next, the method of mixing sampling and sampling results is described in detail.
[0080] In one embodiment, when the first drawing result is sampled by the hair pixel position corresponding to each step to obtain multiple sampling results of the hair pixel step, the hair pixel position corresponding to each step is converted to the screen space to obtain the hair pixel position in the screen space corresponding to each step; the first drawing result is sampled by the hair pixel position in the screen space corresponding to each step to obtain multiple sampling results of the hair pixel step.
[0081] It is understandable that, since the first drawing result is an image in a two-dimensional space, and the hair pixel position corresponding to each step is the position information in the world space, it is necessary to convert the hair pixel position corresponding to each step into the screen space first, obtain the two-dimensional coordinates of the screen space, sample the color drawing result in the first drawing result, and obtain multiple sampling results of the hair pixel step, wherein each step corresponds to one sampling result.
[0082] In one embodiment, the hair pixel position corresponding to each step can be converted to the screen space through the view projection matrix (View Projection Matrix, ViewProj), which is a matrix obtained by multiplying the view matrix and the projection matrix. First, the hair pixel position corresponding to each step (coordinate information in the world space) can be multiplied with the view projection matrix to obtain the hair pixel position in the clipping space, and then the hair pixel position in the clipping space is homogeneously transformed to obtain the hair pixel position in the screen space.
[0083] In one embodiment, when multiple sampling results of hair pixel stepping are mixed to obtain a target rendering result with a hair flow effect, the multiple sampling results of hair pixel stepping are averaged to obtain a target rendering result with a hair flow effect.
[0084] Specifically, the above mean value calculation formula can be expressed as follows:
[0085]
[0086] Among them, color is the target rendering result, n is the number of sampling results, that is, the total number of sampling times, C i is the i-th or i-th sampling result.
[0087] Corresponding to the above method embodiment, see Figure 6A schematic diagram of a hair rendering device is shown, the device comprising: a drawing module 61, for responding to a rendering instruction for a target model, drawing the target model, and obtaining a first drawing result in a frame buffer; a stepping module 62, for performing multiple steps in a target hair flow direction on the pixel position of a specified hair area based on the first drawing result, and obtaining a hair pixel position corresponding to each step; a sampling module 63, for sampling the first drawing result through the hair pixel position corresponding to each step, and obtaining a plurality of sampling results of the hair pixel stepping; a mixing module 64, for mixing the plurality of sampling results of the hair pixel stepping, and obtaining a target rendering result with a hair flow effect.
[0088] The above-mentioned hair rendering device first draws the target model into the frame buffer, and then samples the frame buffer by stepping the pixels of the designated hair area multiple times in the target hair flow direction, and mixes the multiple sampling results obtained to generate a target model rendering result with a hair flow effect, so that the hair / hair flow effect can be achieved without increasing the number of model vertices and faces required for rendering, and the number of times the texture is sampled, thereby reducing the computing resources required for hair rendering and improving the hair rendering performance.
[0089] Optionally, the first drawing result includes: the color drawing result of the target model; the above-mentioned stepping module 62 includes: an acquisition unit, used to obtain the position of each pixel point in the color drawing result in the world space, and obtain the target normal direction of each pixel point in the world space; a determination unit, used to determine the target hair flow direction of each hair pixel point in the specified hair area of the color drawing result in the world space according to the target normal direction and the direction of the force applied to the target model; a stepping unit, used to step each hair pixel point towards the corresponding target hair flow direction multiple times based on the position of each hair pixel point in the world space, and obtain the hair pixel position corresponding to each step.
[0090] Optionally, the first drawing result includes: a depth drawing result of the target model; the acquisition unit is specifically used to: sample the depth drawing result through the screen space coordinates of each pixel point in the color drawing result to obtain the depth of each pixel point in the world space; convert the screen space coordinates of each pixel point to the world space according to the inverse view projection matrix and the depth of each pixel point in the world space to obtain the position of each pixel point in the color drawing result in the world space.
[0091] Optionally, the first drawing result includes: a normal drawing result of the target model; the acquisition unit is further used to: restore the normal direction of each pixel in the color drawing result to the world space according to a normalization method of the normal direction in the normal drawing result, and obtain the target normal direction of each pixel in the world space.
[0092] Optionally, the above-mentioned determination unit is specifically used to: obtain a target weight of the force direction, perform weighted calculation of the target weight on the force direction, and obtain a weighted force direction; wherein the force direction is the direction of the force directed to the target model; for each hair pixel point in the specified hair area of the color drawing result, superimpose the target normal direction with the weighted force direction to obtain a first hair flow direction of each hair pixel point in the world space; normalize the first hair flow direction to obtain the target hair flow direction of each hair pixel point in the world space.
[0093] Optionally, the stepping unit is specifically used to: multiply a preset step size by a target hair flow direction of each hair pixel in the world space to obtain a stepping vector for each hair pixel; repeatedly superimpose the current pixel position of each hair pixel with the corresponding stepping vector to obtain a hair pixel position corresponding to each step.
[0094] Optionally, the above-mentioned device also includes: a testing module, used to perform a template test through the template buffer in the frame buffer to determine the specified hair area in the first drawing result.
[0095] Optionally, the sampling module 63 is specifically used to: convert the hair pixel position corresponding to each step to the screen space to obtain the hair pixel position in the screen space corresponding to each step; sample the first drawing result by the hair pixel position in the screen space corresponding to each step to obtain multiple sampling results of the hair pixel step.
[0096] Optionally, the mixing module 64 is specifically used to: perform mean calculation on multiple sampling results of the hair pixel step to obtain a target rendering result with a hair flow effect.
[0097] This embodiment also provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above hair rendering method. The electronic device can be a server or a terminal device.
[0098] See also Figure 7As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine executable instructions that can be executed by the processor 100. The processor 100 executes the machine executable instructions to implement the above-mentioned hair rendering method.
[0099] Further, Figure 7 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .
[0100] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0101] The processor 100 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 100. The above processor 100 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method of the above embodiment in combination with its hardware, for example:
[0102] In response to a rendering instruction for a target model, the target model is drawn to obtain a first drawing result in a frame buffer; based on the first drawing result, the pixel position of the specified hair area is stepped multiple times in the target hair flow direction to obtain the hair pixel position corresponding to each step; the first drawing result is sampled at the hair pixel position corresponding to each step to obtain multiple sampling results of the hair pixel stepping; the multiple sampling results of the hair pixel stepping are mixed to obtain a target rendering result with a hair flow effect.
[0103] In this method, the target model is first drawn into the frame buffer, and then the pixels of the specified hair area are stepped multiple times in the target hair flow direction, the stepped pixel positions are sampled in the frame buffer, and the multiple sampling results obtained are mixed to generate a target model rendering result with a hair flow effect. This allows the hair / hair flow effect to be achieved without increasing the number of model vertices and faces to be rendered, and the number of times the texture is sampled, thereby reducing the computing resources required for hair rendering and improving the hair rendering performance.
[0104] Optionally, the first drawing result includes: a color drawing result of a target model; based on the first drawing result, performing multiple steps in a target hair flow direction on the pixel position of a specified hair area to obtain a hair pixel position corresponding to each step, comprising: obtaining a position of each pixel point in the color drawing result in world space, and obtaining a target normal direction of each pixel point in the world space; determining a target hair flow direction of each hair pixel point in the specified hair area of the color drawing result in world space according to the target normal direction and a direction of a force acting on the target model; based on the position of each hair pixel point in the world space, performing multiple steps on each hair pixel point in a corresponding target hair flow direction to obtain a hair pixel position corresponding to each step.
[0105] Optionally, the first drawing result includes: a depth drawing result of the target model; a step of obtaining the position of each pixel in the color drawing result in the world space, comprising: sampling the depth drawing result through the screen space coordinates of each pixel in the color drawing result to obtain the depth of each pixel in the world space; converting the screen space coordinates of each pixel to the world space according to the inverse view projection matrix and the depth of each pixel in the world space to obtain the position of each pixel in the color drawing result in the world space.
[0106] Optionally, the first drawing result includes: a normal drawing result of the target model; and a step of obtaining a target normal direction of each pixel point in the world space, comprising: restoring the normal direction of each pixel point in the color drawing result to the world space according to a normalization method of the normal direction in the normal drawing result, and obtaining the target normal direction of each pixel point in the world space.
[0107] Optionally, the step of determining a target hair flow direction in the world space for each hair pixel in the specified hair area of the color drawing result according to the target normal direction and the direction of the force applied to the target model comprises: obtaining a target weight for the force direction, performing weighted calculation on the target weight for the force direction, and obtaining a weighted force direction; wherein the force direction is the direction of the force applied to the target model; for each hair pixel in the specified hair area of the color drawing result, superimposing the target normal direction with the weighted force direction, and obtaining a first hair flow direction for each hair pixel in the world space; and normalizing the first hair flow direction, and obtaining the target hair flow direction for each hair pixel in the world space.
[0108] Optionally, based on the position of each hair pixel point in the world space, each hair pixel point is stepped multiple times in the corresponding target hair flow direction to obtain the hair pixel position corresponding to each step, including: multiplying a preset step length with the target hair flow direction of each hair pixel point in the world space to obtain a step vector for each hair pixel point; repeatedly superimposing the current pixel position of each hair pixel point with the corresponding step vector to obtain the hair pixel position corresponding to each step.
[0109] Optionally, before the step of performing multiple steps in the target hair flow direction on the pixel position of the specified hair area based on the first drawing result to obtain the hair pixel position corresponding to each step, the method also includes: performing a template test through a template buffer in the frame buffer to determine the specified hair area in the first drawing result.
[0110] Optionally, the step of obtaining multiple sampling results of hair pixel steps by sampling the first drawing result at the hair pixel position corresponding to each step includes: converting the hair pixel position corresponding to each step to the screen space to obtain the hair pixel position in the screen space corresponding to each step; and obtaining multiple sampling results of hair pixel steps by sampling the first drawing result at the hair pixel position in the screen space corresponding to each step.
[0111] Optionally, the step of mixing multiple sampling results of hair pixel stepping to obtain a target rendering result with a hair flow effect includes: performing mean calculation on the multiple sampling results of hair pixel stepping to obtain a target rendering result with a hair flow effect.
[0112] This embodiment further provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned hair rendering method, for example:
[0113] In response to a rendering instruction for a target model, the target model is drawn to obtain a first drawing result in a frame buffer; based on the first drawing result, the pixel position of the specified hair area is stepped multiple times in the target hair flow direction to obtain the hair pixel position corresponding to each step; the first drawing result is sampled at the hair pixel position corresponding to each step to obtain multiple sampling results of the hair pixel stepping; the multiple sampling results of the hair pixel stepping are mixed to obtain a target rendering result with a hair flow effect.
[0114] In this method, the target model is first drawn into the frame buffer, and then the pixels of the specified hair area are stepped multiple times in the target hair flow direction, the stepped pixel positions are sampled in the frame buffer, and the multiple sampling results obtained are mixed to generate a target model rendering result with a hair flow effect. This allows the hair / hair flow effect to be achieved without increasing the number of model vertices and faces to be rendered, and the number of times the texture is sampled, thereby reducing the computing resources required for hair rendering and improving the hair rendering performance.
[0115] Optionally, the first drawing result includes: a color drawing result of a target model; based on the first drawing result, performing multiple steps in a target hair flow direction on the pixel position of a specified hair area to obtain a hair pixel position corresponding to each step, comprising: obtaining a position of each pixel point in the color drawing result in world space, and obtaining a target normal direction of each pixel point in the world space; determining a target hair flow direction of each hair pixel point in the specified hair area of the color drawing result in world space according to the target normal direction and a direction of a force acting on the target model; based on the position of each hair pixel point in the world space, performing multiple steps on each hair pixel point in a corresponding target hair flow direction to obtain a hair pixel position corresponding to each step.
[0116] Optionally, the first drawing result includes: a depth drawing result of the target model; a step of obtaining the position of each pixel in the color drawing result in the world space, comprising: sampling the depth drawing result through the screen space coordinates of each pixel in the color drawing result to obtain the depth of each pixel in the world space; converting the screen space coordinates of each pixel to the world space according to the inverse view projection matrix and the depth of each pixel in the world space to obtain the position of each pixel in the color drawing result in the world space.
[0117] Optionally, the first drawing result includes: a normal drawing result of the target model; and a step of obtaining a target normal direction of each pixel point in the world space, comprising: restoring the normal direction of each pixel point in the color drawing result to the world space according to a normalization method of the normal direction in the normal drawing result, and obtaining the target normal direction of each pixel point in the world space.
[0118] Optionally, the step of determining a target hair flow direction in the world space for each hair pixel in the specified hair area of the color drawing result according to the target normal direction and the direction of the force applied to the target model comprises: obtaining a target weight for the force direction, performing weighted calculation on the target weight for the force direction, and obtaining a weighted force direction; wherein the force direction is the direction of the force applied to the target model; for each hair pixel in the specified hair area of the color drawing result, superimposing the target normal direction with the weighted force direction, and obtaining a first hair flow direction for each hair pixel in the world space; and normalizing the first hair flow direction, and obtaining the target hair flow direction for each hair pixel in the world space.
[0119] Optionally, based on the position of each hair pixel point in the world space, each hair pixel point is stepped multiple times in the corresponding target hair flow direction to obtain the hair pixel position corresponding to each step, including: multiplying a preset step length with the target hair flow direction of each hair pixel point in the world space to obtain a step vector for each hair pixel point; repeatedly superimposing the current pixel position of each hair pixel point with the corresponding step vector to obtain the hair pixel position corresponding to each step.
[0120] Optionally, before the step of performing multiple steps in the target hair flow direction on the pixel position of the specified hair area based on the first drawing result to obtain the hair pixel position corresponding to each step, the method also includes: performing a template test through a template buffer in the frame buffer to determine the specified hair area in the first drawing result.
[0121] Optionally, the step of obtaining multiple sampling results of hair pixel steps by sampling the first drawing result at the hair pixel position corresponding to each step includes: converting the hair pixel position corresponding to each step to the screen space to obtain the hair pixel position in the screen space corresponding to each step; and obtaining multiple sampling results of hair pixel steps by sampling the first drawing result at the hair pixel position in the screen space corresponding to each step.
[0122] Optionally, the step of mixing multiple sampling results of hair pixel stepping to obtain a target rendering result with a hair flow effect includes: performing mean calculation on the multiple sampling results of hair pixel stepping to obtain a target rendering result with a hair flow effect.
[0123] The computer program product of the hair rendering method, device, electronic device and storage medium provided in the embodiments of the present disclosure includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. The specific implementation can be found in the method embodiments, which will not be repeated here.
[0124] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0125] In addition, in the description of the embodiments of the present disclosure, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present disclosure can be understood according to specific circumstances.
[0126] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0127] In the description of the present disclosure, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present disclosure and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present disclosure. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0128] Finally, it should be noted that the above embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above embodiments, those skilled in the art should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for rendering hair, characterized in that: The method comprises: In response to a rendering instruction for a target model, the target model is drawn to obtain a first drawing result in a frame buffer; Based on the first drawing result, the pixel position of the designated hair area is stepped multiple times in the target hair flow direction to obtain the hair pixel position corresponding to each step; By sampling the first drawing result at the hair pixel position corresponding to each step, a plurality of sampling results of the hair pixel step are obtained; The multiple sampling results of the hair pixel stepping are mixed to obtain a target rendering result with a hair flow effect.
2. The method according to claim 1, characterized in that The first drawing result includes: a color drawing result of the target model; The step of performing multiple steps in the target hair flow direction on the pixel position of the designated hair area based on the first drawing result to obtain the hair pixel position corresponding to each step includes: Obtaining the position of each pixel point in the color rendering result in the world space, and obtaining the target normal direction of each pixel point in the world space; Determining a target hair flow direction of each hair pixel point in a specified hair area of the color rendering result in a world space according to the target normal direction and the direction of the force acting on the target model; Based on the position of each hair pixel point in the world space, each hair pixel point is stepped multiple times toward the corresponding target hair flow direction to obtain the hair pixel position corresponding to each step.
3. The method according to claim 2, characterized in that The first rendering result includes: a depth rendering result of the target model; The step of obtaining the position of each pixel in the color drawing result in the world space comprises: The depth rendering result is sampled by the screen space coordinates of each pixel point in the color rendering result to obtain the depth of each pixel point in the world space; According to the inverse view projection matrix and the depth of each pixel in the world space, the screen space coordinates of each pixel are converted to the world space to obtain the position of each pixel in the world space in the color drawing result.
4. The method according to claim 2, characterized in that: The first drawing result includes: a normal drawing result of the target model; The step of obtaining the target normal direction of each pixel point in the world space includes: According to the normalization method of the normal direction in the normal drawing result, the normal direction of each pixel in the color drawing result is restored to the world space to obtain the target normal direction of each pixel in the world space.
5. The method according to claim 2, characterized in that: The step of determining the target hair flow direction of each hair pixel point in the specified hair area of the color drawing result in the world space according to the target normal direction and the direction of the force acting on the target model comprises: Obtaining a target weight of a force direction, performing weighted calculation of the target weight on the force direction, and obtaining a weighted force direction; wherein the force direction is a direction of the force directed to the target model; For each hair pixel point in the specified hair area of the color rendering result, superimpose the target normal direction with the weighted force direction to obtain a first hair flow direction of each hair pixel point in the world space; The first hair flow direction is normalized to obtain a target hair flow direction of each hair pixel in the world space.
6. The method according to claim 2, characterized in that The step of performing multiple steps on each hair pixel point toward the corresponding target hair flow direction based on the position of each hair pixel point in the world space to obtain the hair pixel position corresponding to each step includes: Multiply the preset step length by the target hair flow direction of each hair pixel in the world space to obtain the step vector of each hair pixel; Repeat the process of superimposing the current pixel position of each hair pixel with the corresponding step vector multiple times to obtain the hair pixel position corresponding to each step.
7. The method according to claim 1, characterized in that Before the step of performing multiple steps in the target hair flow direction on the pixel position of the designated hair area based on the first drawing result to obtain the hair pixel position corresponding to each step, the method further includes: A stencil test is performed through a stencil buffer in the frame buffer to determine a designated hair area in the first drawing result.
8. The method according to claim 1, characterized in that The step of sampling the first drawing result at the hair pixel position corresponding to each step to obtain a plurality of sampling results of the hair pixel stepping includes: Convert the hair pixel position corresponding to each step to the screen space to obtain the hair pixel position in the screen space corresponding to each step; The first drawing result is sampled by the hair pixel position in the screen space corresponding to each step, so as to obtain a plurality of sampling results of the hair pixel stepping.
9. The method according to claim 1, characterized in that: The step of mixing the multiple sampling results of the hair pixel stepping to obtain a target rendering result with a hair flow effect comprises: A mean value is calculated for a plurality of sampling results of the hair pixel step to obtain a target rendering result with a hair flow effect.
10. A hair rendering device, characterized in that: The device comprises: A drawing module, used for responding to a rendering instruction for a target model, drawing the target model, and obtaining a first drawing result in a frame buffer; A stepping module, configured to perform multiple steps in a target hair flow direction on the pixel position of the designated hair area based on the first drawing result, and obtain a hair pixel position corresponding to each step; A sampling module, configured to sample the first drawing result by the hair pixel position corresponding to each step, so as to obtain a plurality of sampling results of the hair pixel step; The mixing module is used to mix the multiple sampling results of the hair pixel stepping to obtain a target rendering result with a hair flow effect.
11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the hair rendering method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the hair rendering method according to any one of claims 1 to 9.