Shadow rendering method and device and electronic equipment

By obtaining the bone position information of the target character model, building a distance field in the decal component, forming a shadow material and casting it to the ground of the game scene, it solves the problem that indirect light shadows are difficult to render in mobile games, and achieves low-consumption and high-quality shadows Rendering effect improves player experience.

CN119318803APending Publication Date: 2025-01-17NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411337366.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-01-17

AI Technical Summary

Technical Problem

In mobile game rendering, the shadows generated by indirect lighting on movable objects are difficult to render, resulting in performance bottlenecks. The existing technology cannot effectively simulate the indirect shadows of dynamic objects casting on the ground and walls, resulting in poor player gaming experience.

Method used

By obtaining the position information of the foot bones of the target character model, a distance field is built in the decal component, a grayscale value is determined based on the distance value, a shadow material is formed, and a shadow is cast to the ground of the game scene through the decal component to achieve a soft shadow transition.

Benefits of technology

It reduces the performance consumption of shadow rendering, is suitable for mobile, improves the gaming experience, softens the shadow transition, and enhances the character's sense of volume and picture level at the backlight.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119318803A_ABST
    Figure CN119318803A_ABST
Patent Text Reader

Abstract

The invention provides a shadow rendering method and device and electronic equipment. The shadow rendering method comprises the following steps: acquiring skeleton position information of feet of a target role model in a game scene; according to the skeleton position information, constructing a target distance field in a decal assembly below a foot of the target role model; according to the distance value corresponding to each position point in the target distance field, determining the gray value of each position point in the target distance field, and determining the distance field determined by the gray value as a shadow material; and projecting a shadow material to the ground in the game scene through the decal assembly so as to form a shadow of the target role model on the ground. According to the method, the distance field is constructed in the decal assembly through the obtained foot skeleton position information of the role model, so that the shadow is formed under the foot of the role model through the decal assembly, the method is low in shadow rendering consumption and suitable for a mobile terminal, the shadow rendered through the method is soft in transition, and the game experience feeling of players can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of game rendering technology, and in particular to a shadow rendering method, device and electronic device. Background Art

[0002] For real-time rendering on mobile terminals, the shadows cast by indirect lighting on movable objects have always been a rendering problem. The difficulty lies in the performance bottleneck. Many computer-side shadow rendering solutions cannot be applied to mobile terminals. In related technologies, 3D games with third-person or first-person perspectives on mobile terminals usually use AO maps (AO maps are usually grayscale images, black represents the areas with the densest shadows, and white represents areas without shadows) to simulate indirect light shadows, while the indirect light shadows cast by dynamic objects on the ground and walls are most likely to be directly abandoned; for top-down perspective games, direct light shadows can better distinguish visual levels, but when entering a large area of ​​shadow area, the character often has a strong sense of separation from the scene, resulting in a poor gaming experience for players. Summary of the invention

[0003] The purpose of the present disclosure is to provide a color changing method, device and electronic device in a game, so as to render shadows with better visual effects and lower consumption on a mobile terminal, thereby improving the player's gaming experience.

[0004] In a first aspect, the present disclosure provides a shadow rendering method, the method comprising: obtaining skeletal position information of a foot of a target character model in a game scene; constructing a target distance field in a decal component below the foot of the target character model according to the skeletal position information; determining a grayscale value of each position point in the target distance field according to a distance value corresponding to each position point in the target distance field, and determining the distance field determined by the grayscale value as a shadow material; and projecting the shadow material onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground.

[0005] In a second aspect, the present disclosure provides a shadow rendering device, which includes: an information acquisition module, used to obtain the bone position information of the foot of the target character model in the game scene; a distance field creation module, used to construct a target distance field in a decal component under the foot of the target character model according to the bone position information; a material determination module, used to determine the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determine the distance field determined by the grayscale value as a shadow material; a shadow formation module, used to project the shadow material onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground.

[0006] In a third aspect, the present disclosure provides an electronic device, which includes 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 shadow rendering method.

[0007] In a fourth aspect, the present disclosure provides a computer-readable storage medium storing 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 shadow rendering method.

[0008] The embodiments of the present disclosure bring the following beneficial effects:

[0009] The present disclosure provides a shadow rendering method, device and electronic device, which first obtains the bone position information of the foot of the target character model in the game scene; then, based on the bone position information, constructs a target distance field in the decal component below the foot of the target character model; then, based on the distance value corresponding to each position point in the target distance field, determines the grayscale value of each position point in the target distance field, and determines the distance field determined by the grayscale value as the shadow material; then, projects the shadow material onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground. This method constructs a distance field in the decal component by obtaining the bone position information of the foot of the character model, so as to form a shadow under the foot of the character model through the decal component. This method has low consumption for rendering shadows and is suitable for mobile terminals. In addition, the shadows rendered by this method have a smooth transition, which helps to improve the player's gaming experience.

[0010] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.

[0011] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, the following specifically cites preferred implementation modes and describes them in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] 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 ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0013] Figure 1 A flowchart of a shadow rendering method provided by an embodiment of the present disclosure;

[0014] Figure 2 A schematic diagram of a decal assembly provided in an embodiment of the present disclosure;

[0015] Figure 3 A schematic diagram of a shadow presentation on the ground provided in an embodiment of the present disclosure;

[0016] Figure 4 A schematic diagram of the structure of a shadow rendering device provided in an embodiment of the present disclosure;

[0017] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0018] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all the embodiments. The components of the embodiments of the present disclosure described and shown in the drawings here can be arranged and designed in various different configurations.

[0019] Therefore, the following detailed description of the embodiments of the present disclosure provided in the accompanying drawings is not intended to limit the scope of the present disclosure claimed for protection, but merely represents selected embodiments of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present disclosure.

[0020] For real-time rendering on mobile terminals, the shadows cast by indirect light on movable objects have always been a rendering problem. The difficulty lies in the performance bottleneck, and many computer-side solutions cannot be used. Therefore, most 3D games with third-person or first-person perspectives use AO maps to simulate indirect light shadows, and the indirect light shadows cast by dynamic objects on the ground and walls are likely to be directly abandoned. For top-down perspective games, direct light shadows can better distinguish visual levels. Once entering a large area of ​​shadow area, the character often has a strong sense of separation from the scene.

[0021] In the related technologies, the commonly used indirect lighting dynamic shadow solutions on the computer side include the following three:

[0022] The first one is capsule shadow. The basic principle is: build a set of capsule physics assets for the character. Since each capsule can be represented by the position information and radius of the two endpoints, in the post-processing stage, the mathematical information and lighting direction of these capsules can be used to draw the shadow shape using the Ray Marching method in the post-processing stage. Because it is a shadow calculated purely by mathematics, it can produce a very soft penumbra. In addition, indirect lighting shadows are mostly soft shadows, so this technology is often used for indirect lighting shadow rendering.

[0023] The second method is distance field ambient occlusion shadowing. After constructing the distance field information for the entire scene, it can be used as the basic data for dynamic sky light shadow calculation.

[0024] The third method is to use ray tracing to form shadows. This method is the closest to the real light path and can give nearly accurate indirect lighting shadows. At the same time, it consumes a lot of performance and cannot be used on mobile devices.

[0025] However, the ray tracing solution on the computer cannot be implemented on the existing mobile hardware, and the distance field ambient occlusion shadow is not feasible in most mobile game projects. Most game engines will turn off this function in the mobile rendering pipeline. Most projects will choose the baked lighting solution. At this time, it is very uneconomical to build a distance field for complex calculations just to obtain indirect light shadows of dynamic objects. Capsule shadows have a certain possibility of being implemented on mobile terminals, but the extensive use of Ray Matching still has a great performance pressure, and capsule shadows work well when the indirect light has a strong directionality, but the effect advantage of this solution will no longer be obvious under uniform sky lighting.

[0026] In the related technologies, the commonly used indirect lighting dynamic shadow solutions for mobile terminals include the following two:

[0027] The first is the application of AO map drawing. When making model maps, AO baking is performed in DCC software. The lighting is not unidirectional, but wraps inward from all sides to simulate sky lighting.

[0028] The second method is to place a drawn shadow under the character's feet and let it follow the movement. This method is relatively simple. Just draw a circular soft shadow and follow the character's movement to simulate the sky light shadow.

[0029] However, baking AO maps can only solve the indirect light shadows of dynamic objects themselves, but cannot solve the shadows caused by contact with other objects. And the practice of hanging shadow patches on the soles of the feet makes the shadows too rigid and unable to match the character's movements when the character moves.

[0030] Based on the above problems, an embodiment of the present invention provides a shadow rendering method, device and electronic device. The technology is applied to character shadow rendering scenes in games, especially to skylight shadow rendering scenes.

[0031] In order to facilitate understanding of the embodiment of the present invention, a shadow rendering method provided by the embodiment of the present invention is first described in detail. Figure 1 As shown, the method comprises the following specific steps:

[0032] Step S102, obtaining the bone position information of the foot of the target character model in the game scene.

[0033] In the specific implementation, the visual rules of skylight shadows in nature include: the shadow outline is unclear and the transition is soft, and the shadow will decay with the distance, and most of it is projected near the feet. Based on the above characteristics, the present invention renders skylight shadows by obtaining the skeletal position information of the first target foot and the second target foot of the target character model. The above target character model is a three-dimensional model, and the target character model can be a role model of any role in the game scene, which can be determined according to research and development needs. The target character model is composed of multiple bones. For example, the target character module can include hand bones, arm bones, trunk bones, leg bones and foot bones. Among them, the skeleton is the most important element of the character in three-dimensional animation. It is designed to provide the character movement effect. By correctly modeling and organizing the character skeleton, the character can achieve natural and smooth movement. Each skeleton has an endpoint. The skeletal position information of the foot is also the position information of the skeletal endpoint of the first target foot of the target character model and the position information of the skeletal endpoint of the second target foot. In a specific embodiment, the above position information can be a world position coordinate.

[0034] In practical applications, the target character model can be a human model or a quadruped model, etc. Therefore, if the target character model is a human model, the first target foot can be the left foot and the second target foot can be the right foot; if the target character model is a quadruped model, the first target foot can be the left foot of the target character model's rear two feet and the second target foot can be the right foot of the rear two feet. Of course, the first target foot and the second target foot can also be other feet of the quadruped model, which can be determined according to research and development requirements.

[0035] Step S104: construct a target distance field in the decal component below the foot of the target character model according to the bone position information.

[0036] The system will obtain the bone position information of the feet of the target character model in real time. After obtaining the bone position information, it will construct a target distance field with the world space position of the surrounding pixels, so as to subsequently draw the false penumbra of the target character model. The false penumbra here is also a transitional soft shadow. In the specific implementation, when constructing the target distance field, in order to reduce performance consumption and form shadows on the ground of the game scene, it is necessary to add a decal component for drawing shadows to the target character model in advance, and set the parameters such as the position and size of the decal component, so that the target distance field can be constructed only in the decal component according to the bone position information, reducing performance consumption. Specifically, the target distance field can be obtained by subtracting the bone position information from the position information of each position point in the decal component.

[0037] In actual applications, since the skylight shadow is usually located near the soles of the character model's feet, the decal component needs to be set below the feet of the target character model, and the decal component is a functional component with a certain volume. The decal component can be a cube, a cuboid, a cylinder, etc. The upper surface of the decal component is connected to or close to the lower surface of the feet of the target character model; at the same time, the decal component is not visible in the game scene.

[0038] It should be noted that the decal component is a common functional component in 3D model production. The decal component can also be called a decal projector or a decal shader. The decal component Decal Volume is a technology that achieves specific visual effects in game graphics. It simulates effects such as skid marks and splashes by efficiently rendering decals while maintaining good visual quality and performance. It is one of the important technologies in modern game graphics development. Specifically, a decal component is a graphic component that allows a decal to be added to a game or application. This decal can be a texture, pattern, or other visual element, and the decal can be projected onto a surface in the game scene.

[0039] Step S106, determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determining the distance field determined by the grayscale value as the shadow material.

[0040] In the specific implementation, the positions and numbers of the position points in the target distance field and the position points in the decal component are the same, so the distance values ​​corresponding to each position point in the target distance field are determined based on the distance between each position point and the bone position information of the foot of the target character model. Generally, the greater the distance between the position point and the bone position information, the greater the distance value corresponding to the position point. Specifically, the grayscale values ​​corresponding to different distance values ​​are pre-set, so that the grayscale values ​​of each position point in the target distance scene can be determined according to the distance values ​​corresponding to each position point in the target distance scene, so that a material map can be obtained, which is also the above-mentioned shadow material.

[0041] Step S108, projecting a shadow material onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground.

[0042] In a specific implementation, the decal component can be assigned a shadow material, and the shadow material is rendered onto the surface on which it is projected. The present invention can project the shadow material onto the ground in the game scene through the decal component, so as to render and generate the shadow of the target character model on the ground. Generally, the target character model has different skeletal position information of the foot, and the shadow of the target character model formed on the ground is also different. For example, when the target character model stands on the ground, the skylight shadow formed on the ground is larger and darker in color. When the target character model jumps, the higher the jumping height, the smaller the skylight shadow formed on the ground and the lighter in color.

[0043] The present invention provides a shadow rendering method, which constructs a distance field in a decal component by acquiring the position information of the character model's foot bones, so that a shadow is formed under the character model's feet through the decal component. This method has low cost for rendering shadows and is suitable for mobile terminals. Moreover, the shadows rendered by this method have a smooth transition, which helps to improve the player's gaming experience.

[0044] The following embodiments are used to describe how to construct a decal component and how to render shadows based on the decal component.

[0045] Specifically, during the game design phase, you need to add a decal component to the target character model, that is, create a material for drawing shadows for the target character model. When adding a decal component to the target character model, you also need to set the name of the decal component and set the parameters such as the position and size of the decal component. Based on the set parameters such as the position and size, the decal component is set under the feet of the target character model, and the volume of the decal component matches the maximum jump height of the target character model.

[0046] In the specific implementation, the decal component is set at the feet of the target character model, so that the decal component casts a shadow on the surface that the target character model steps on, that is, to the ground under the feet of the target character model. The size of the decal component is set to ensure that the volume of the decal component is sufficient to project the shadow material completely. At the same time, when the target character model jumps up, the volume of the decal component can also be projected onto the ground, that is, to ensure that when the target character model jumps up, the decal component can still intersect with the ground. Figure 2 FIG. 1 is a schematic diagram of a decal assembly provided by an embodiment of the present invention. Figure 2 The character model in is the target character model, and the cube under the feet of the target character model is the decal component.

[0047] It should be noted that the decal component in the game scene is invisible, but the decal component is used to maintain the relative position relationship with the target character model, that is, the decal component is always located under the feet of the target character model, and when the target character model jumps, the decal component will also jump with the target character model.

[0048] Based on the above description, the specific process of projecting shadow material to the ground in the game scene through the decal component to form the shadow of the target character model on the ground includes: determining the tangent surface in the decal component and the ground in the game scene; mapping the grayscale values ​​corresponding to the position points on the tangent surface in the shadow material on the ground to form the shadow of the target character model on the ground.

[0049] In specific implementation, since the decal component has a certain volume and is always located below the target character model, no matter whether the target character model is walking or jumping on the ground, there will be a surface in the decal component that is tangent to the ground. This surface in the decal component is also the above-mentioned tangent surface. However, there is also a situation where the height of the target character model jumping is very high, resulting in the decal component not having a surface tangent to the ground. In this case, the shadow of the target character model will not be formed on the ground. After determining the tangent surface in the decal component, the grayscale value corresponding to the position point on the tangent surface can be mapped to the ground to form a shadow on the ground.

[0050] The above method solves the problem that dynamic skylight shadows cannot be used in mobile rendering due to performance limitations. This method can form a shadow under the feet of the character model through the mapping function of the decal component. This shadow can greatly enhance the character's sense of volume and picture level in the backlight.

[0051] The following embodiments are used to describe the method of constructing a target distance field.

[0052] Specifically, the above-mentioned bone position information includes the first target foot bone position coordinates and the second target foot bone position coordinates; based on this, the specific process of constructing the target distance field in the decal component under the foot of the target character model according to the bone position information can be achieved through the following steps 10-12:

[0053] Step 10: construct a first distance field in the decal component under the foot of the target character model according to the first target foot bone position coordinates.

[0054] In a specific implementation, the first distance field can be constructed based on the distance between the first target foot bone position coordinates and each position point in the decal component. In a specific embodiment, the coordinate positions of each position point in the decal component can be subtracted from the first target foot bone position coordinates to obtain the first vector corresponding to each position point; based on the first vector, the distance value corresponding to each position point is determined; based on the distance value corresponding to each position point, the first distance field is obtained.

[0055] Specifically, since the coordinate positions of each position point in the decal component are three-dimensional coordinate values, and the coordinates of the first target foot bone position are also three-dimensional coordinate values, the coordinate positions of each position point can be subtracted from the coordinates of the coordinate bone position to obtain the first vector corresponding to each position point. The first vector includes not only the corresponding values ​​of the three axes but also the direction. For example, if the coordinate position of a certain position point is (1,2,3) and the coordinates of the first target foot bone position are (1,1,1), then the first vector corresponding to the position point is (0,1,2); if the coordinate position of a certain position point is (1,2,3) and the coordinates of the first target foot bone position are (2,2,2), then the first vector corresponding to the position point is (-1,0,1).

[0056] In an optional embodiment, after obtaining the first vector corresponding to each position point, the distance value corresponding to each position point can be obtained according to the first vector. Specifically, the Euclidean distance can be directly calculated according to the first vector. For example, if the first vector is (0,1,2), then the calculated distance value is √5; if the first vector is (-1,0,1), then the calculated distance value is √2.

[0057] In another optional embodiment, after obtaining the first vector corresponding to each position point, the following operation can be performed for the first vector corresponding to each position point: multiply the first vector corresponding to the current position point by the preset coordinate value to obtain a second vector; wherein the preset coordinate value is used to scale the coordinate value of the preset axis; and the vector length corresponding to the second vector is determined as the distance value corresponding to the current position point.

[0058] In specific implementation, the above preset axis can be determined according to the game rules. For example, if the target character model jumps up and down, then the preset axis is the Z axis that changes when the target character model jumps up and down. Specifically, since the target character model is farther away from the ground when jumping, the shadow needs to be faded or even disappears, so the Z axis is scaled to a certain extent here to match the ideal effect. The above method multiplies the first vector by the preset coordinate value, and the Z axis can be scaled to a certain extent, so that while projecting downward along the Z axis, the Z axis distance field is applied to the height attenuation performance, forming a dynamic and credible skylight shadow intensity.

[0059] In a specific embodiment, the coordinate value of the preset axis in the above preset coordinate value is greater than 1, and the coordinate value corresponding to the axis other than the preset axis is equal to 1. This method can ensure that the shadow intensity outside the preset axis in the projected shadow remains unchanged, but the shadow intensity on the preset axis changes. For example, if the preset axis is the Z axis, then the preset coordinate value can be (1,1,0.75). This method can ensure that when the character jumps, the shadow displayed on the ground will not disappear quickly, but the shadow will gradually fade and disappear.

[0060] Step 11: construct a second distance field in the decal component under the foot of the target character model according to the position coordinates of the second target foot bone.

[0061] In the specific implementation, the second distance field is constructed in the same way as the first distance field, except that the first distance field uses the first target foot bone position coordinates, while the second distance field uses the second target foot bone position coordinates. Therefore, the construction method of the second distance field can refer to the construction method of the first distance field mentioned above, which will not be repeated here.

[0062] Step 12: Fusing the first distance field with the second distance field to obtain a target distance field.

[0063] Since the first distance field and the second distance field are both distance fields formed in the decal component, the two distance fields will definitely affect each other. Therefore, after the first distance field and the second distance field are calculated separately, the first distance field and the second distance field need to be fused to obtain a fused distance field, which is also the target distance field in the decal component.

[0064] In an optional embodiment, the specific process of fusing the first distance field with the second distance field to obtain the target distance field may include: for each position point in the decal component, multiplying the distance value corresponding to the current position point in the first distance field by the distance value corresponding to the current position point in the second distance field to obtain a fused distance value corresponding to the current position point; and obtaining the target distance field based on the fused distance value corresponding to each position point in the decal component.

[0065] In a specific implementation, each position point in the decal component can be used as a current position point, and then the distance value of the current position point in the first distance scene and the distance value in the second distance scene are multiplied to obtain a multiplication result, which is determined as the fusion distance value.

[0066] The above method obtains the skeletal position information of the first target foot and the second target foot, and constructs the distance field of the decal component according to the information, merges the distance fields of the first target foot and the second target foot, and merges the center point distance field at the same time, to form a realistic skylight shadow outline, thereby not only reducing the cost of shadow rendering, but also improving the shadow rendering effect.

[0067] The following embodiments are used to describe a method of determining the grayscale value of each position in the target distance field.

[0068] Specifically, the specific process of determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field may include: setting the position point in the target distance field whose distance value is less than the first preset value to the first grayscale value; setting the position point in the target distance field whose distance value is greater than the second preset value to the second grayscale value; wherein the second preset value is greater than the first preset value; for the target position point in the target distance field whose distance value is not less than the first preset value and not greater than the second preset value, setting the target position point to a grayscale value between the first grayscale value and the second grayscale value according to the distance value corresponding to the target position point.

[0069] In specific implementation, the specific numerical values ​​corresponding to the first preset value and the second preset value can be determined according to research and development requirements, for example, the first preset value can be 0, and the second preset value can be 0.6. The specific grayscale values ​​corresponding to the first grayscale value and the second grayscale value can also be determined according to research and development requirements, for example, the first grayscale value can be 0, and the second grayscale value can be 1 or 255; the first grayscale value is 1 or 255, and the second grayscale value is 0. Among them, when the grayscale value is 0, it represents white, when the grayscale value is 255, it represents black, and after the grayscale value is normalized, when the grayscale value is 1, it represents black. When the distance value corresponding to the position point in the target distance field is greater than or equal to the first preset value and less than or equal to the second preset value, the corresponding grayscale value can be set according to the distance value corresponding to the position point. Usually, the grayscale value corresponding to each distance value is pre-configured. If the first grayscale value is greater than the second grayscale value, the larger the distance value, the smaller the grayscale value corresponding to the position point; if the first grayscale value is less than the second grayscale value, the smaller the distance value, the larger the grayscale value corresponding to the position point.

[0070] In an optional embodiment, if the first grayscale value is a first value and the second grayscale value is a second value, then after obtaining the grayscale value of each position point according to the distance value corresponding to each position point in the target distance field, it is also necessary to invert the grayscale value corresponding to each position point in the target distance field to obtain the inverted grayscale value corresponding to each position point; multiply the inverted grayscale value corresponding to each position point by the preset transparency to obtain the final grayscale value corresponding to each position point. In this way, a soft transition shadow can be obtained. The specific values ​​corresponding to the above-mentioned first value and the second value can be determined according to research and development needs.

[0071] For example, if the first value is 0 and the second value is 1, then the first grayscale value of 1 represents white, and the second grayscale value of 0 represents black. Therefore, the closer the position point is to the foot position of the target character model in the target distance field, the closer it is to white, and the farther the position point is from the foot position of the target character model, the closer it is to black. However, this method is opposite to the color formed by the actual shadow, so the grayscale value needs to be inverted, that is, 1 is subtracted from the grayscale value corresponding to each position point to obtain the inverted grayscale value. For example, if the grayscale value corresponding to a certain position point is 0, then after the inverted processing is performed on the position point, the grayscale value corresponding to the position point becomes 1; if the grayscale value corresponding to a certain position point is 0.2, then after the inverted processing is performed on the position point, the grayscale value corresponding to the position point is 0.8.

[0072] After obtaining the inverted grayscale value corresponding to each position point, in order to make the shadow presentation more realistic, it is necessary to set the shadow to penumbra, that is, to increase the transparency of the shadow. Specifically, the inverted grayscale value can be multiplied by the preset transparency to obtain the final grayscale value corresponding to each position point, so as to generate a shadow material based on the final grayscale value, and project the shadow material onto the ground in the game scene through the decal component, so as to render the shadow of the target character model on the ground.

[0073] In a specific embodiment, in order to enable the decal component to be mapped downward to obtain a semi-transparent shadow, the material domain of the decal component can be set to delayed decal, and the blending mode can be set to semi-transparent mode. The material domain is used to configure the purpose of the decal component, and the blending mode is used to configure whether the final projected shadow is semi-transparent or opaque.

[0074] In actual applications, the pre-made decal component can be used as the parent material, a dynamic material instance can be created and assigned to the decal component, and then the first target foot and the second target foot bone position information can be obtained in real time according to the bone slots of the first target foot and the second target foot. The first target foot bone position information and the second target foot bone position information are then passed into the dynamic material instance, so as to project and adjust the shadow to the ground of the game scene through the dynamic material instance. Figure 3 FIG. 1 is a schematic diagram of a shadow presentation on the ground provided by an embodiment of the present invention. Figure 3 The target character model in the game is named Hunter 1. The dark gray area under the feet of the target character model on the ground in the game scene is a shadow. Figure 3 The target character model in the left image is on the ground, and the shadows at the two feet are darker. Figure 3 The target character model in the right image is in a jumping state, and at this time, the shadow under the feet appears to be circular.

[0075] The above method can approximately form skylight shadows, and the shadows formed by this method have low performance consumption and can be applied to mobile phones.

[0076] Corresponding to the above method embodiment, the embodiment of the present invention further provides a shadow rendering device, such as Figure 4 As shown, the device comprises:

[0077] The information acquisition module 40 is used to acquire the bone position information of the foot of the target character model in the game scene.

[0078] The distance field creation module 41 is used to construct a target distance field in the decal component under the foot of the target character model according to the bone position information.

[0079] The material determination module 42 is used to determine the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determine the distance field determined by the grayscale value as the shadow material.

[0080] The shadow forming module 43 is used to project a shadow material onto the ground in the game scene through a decal component to form a shadow of the target character model on the ground.

[0081] The above-mentioned shadow rendering device constructs a distance field in the decal component by obtaining the position information of the character model's foot bones, so as to form a shadow under the character model's feet through the decal component. This method has low cost for rendering shadows and is suitable for mobile terminals. Moreover, the shadows rendered by this method have a smooth transition, which helps to improve the player's gaming experience.

[0082] Specifically, the decal assembly is disposed below the feet of the target character model, and the volume of the decal assembly matches the maximum jumping height of the target character model.

[0083] Furthermore, the above-mentioned bone position information includes the first target foot bone position coordinates and the second target foot bone position coordinates; based on this, the above-mentioned distance field creation module 41 is used to: construct a first distance field in the decal component under the foot of the target character model according to the first target foot bone position coordinates; construct a second distance field in the decal component under the foot of the target character model according to the second target foot bone position coordinates; and fuse the first distance field with the second distance field to obtain the target distance field.

[0084] Furthermore, the above-mentioned distance field creation module 41 is used to: subtract the coordinate position of each position point in the decal component from the coordinate position of the first target foot bone to obtain a first vector corresponding to each position point; based on the first vector, determine the distance value corresponding to each position point; based on the distance value corresponding to each position point, obtain the first distance field.

[0085] In a specific implementation, the distance field creation module 41 is used to: for the first vector corresponding to each position point, perform the following operations: multiply the first vector corresponding to the current position point by the preset coordinate value to obtain a second vector; wherein the preset coordinate value is used to scale the coordinate value of the preset axis; and determine the vector length corresponding to the second vector as the distance value corresponding to the current position point.

[0086] Furthermore, the coordinate value of the preset axial direction in the above preset coordinate values ​​is greater than 1, and the coordinate value corresponding to the axial direction other than the preset axial direction is equal to 1.

[0087] In a specific implementation, the distance field creation module 41 is used to: for each position point in the decal component, multiply the distance value corresponding to the current position point in the first distance field by the distance value corresponding to the current position point in the second distance field to obtain a fused distance value corresponding to the current position point; and obtain a target distance field based on the fused distance value corresponding to each position point in the decal component.

[0088] Furthermore, the material determination module 42 is used to: set a position point in the target distance field whose distance value is less than a first preset value to a first grayscale value; set a position point in the target distance field whose distance value is greater than a second preset value to a second grayscale value; wherein the second preset value is greater than the first preset value; for a target position point in the target distance field whose distance value is not less than the first preset value and not greater than the second preset value, set the target position point to a grayscale value between the first grayscale value and the second grayscale value according to the distance value corresponding to the target position point.

[0089] Furthermore, the above-mentioned first grayscale value is a first numerical value, and the second grayscale value is a second numerical value; based on this, the above-mentioned device also includes a material transparency module, which is used to: invert the grayscale values ​​corresponding to each position point in the target distance field to obtain the inverted grayscale values ​​corresponding to each position point; multiply the inverted grayscale values ​​corresponding to each position point by the preset transparency to obtain the final grayscale values ​​corresponding to each position point.

[0090] Furthermore, the shadow forming module 43 is used to: determine the tangent surface of the decal component and the ground in the game scene; map the grayscale values ​​corresponding to the position points on the tangent surface in the shadow material onto the ground to form a shadow of the target character model on the ground.

[0091] The shadow rendering device provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.

[0092] The embodiment of the present invention further provides an electronic device, such as Figure 5As shown, the electronic device includes a processor and a memory, 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 shadow rendering method.

[0093] Specifically, the shadow rendering method includes: obtaining the bone position information of the foot of the target character model in the game scene; constructing a target distance field in a decal component under the foot of the target character model according to the bone position information; determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determining the distance field determined by the grayscale value as the shadow material; projecting the shadow material onto the ground in the game scene through the decal component to form the shadow of the target character model on the ground.

[0094] The above-mentioned shadow rendering method constructs a distance field in the decal component by obtaining the position information of the character model's foot bones, so as to form a shadow under the character model's feet through the decal component. This method has low cost for rendering shadows and is suitable for mobile terminals. In addition, the shadows rendered by this method have a smooth transition, which helps to improve the player's gaming experience.

[0095] In an optional embodiment, the decal assembly is disposed under the feet of the target character model, and the volume of the decal assembly matches the maximum jumping height of the target character model.

[0096] In an optional embodiment, the bone position information includes first target foot bone position coordinates and second target foot bone position coordinates; the above step of constructing a target distance field in the decal component under the foot of the target character model based on the bone position information includes: constructing a first distance field in the decal component under the foot of the target character model based on the first target foot bone position coordinates; constructing a second distance field in the decal component under the foot of the target character model based on the second target foot bone position coordinates; and fusing the first distance field with the second distance field to obtain the target distance field.

[0097] In an optional embodiment, the step of constructing a first distance field in the decal component below the foot of the target character model based on the first target foot bone position coordinates includes: subtracting the coordinate positions of each position point in the decal component from the first target foot bone position coordinates to obtain a first vector corresponding to each position point; based on the first vector, determining a distance value corresponding to each position point; and based on the distance value corresponding to each position point, obtaining the first distance field.

[0098] In an optional embodiment, the above-mentioned step of determining the distance value corresponding to each position point based on the first vector includes: performing the following operations for the first vector corresponding to each position point: multiplying the first vector corresponding to the current position point by the preset coordinate value to obtain a second vector; wherein the preset coordinate value is used to scale the coordinate value of the preset axis; and determining the vector length corresponding to the second vector as the distance value corresponding to the current position point.

[0099] In an optional embodiment, the coordinate value of the preset axial direction in the above preset coordinate values ​​is greater than 1, and the coordinate value corresponding to the axial direction other than the preset axial direction is equal to 1.

[0100] In an optional embodiment, the step of fusing the first distance field with the second distance field to obtain a target distance field includes: for each position point in the decal component, multiplying a distance value corresponding to the current position point in the first distance field by a distance value corresponding to the current position point in the second distance field to obtain a fused distance value corresponding to the current position point; and obtaining the target distance field based on the fused distance value corresponding to each position point in the decal component.

[0101] In an optional embodiment, the step of determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field includes: setting the position point in the target distance field whose distance value is less than a first preset value to a first grayscale value; setting the position point in the target distance field whose distance value is greater than a second preset value to a second grayscale value; wherein the second preset value is greater than the first preset value; for a target position point in the target distance field whose distance value is not less than the first preset value and not greater than the second preset value, setting the target position point to a grayscale value between the first grayscale value and the second grayscale value according to the distance value corresponding to the target position point.

[0102] In an optional embodiment, the first grayscale value is a first value, and the second grayscale value is a second value; the above method also includes: inverting the grayscale values ​​corresponding to each position point in the target distance field to obtain the inverted grayscale values ​​corresponding to each position point; multiplying the inverted grayscale values ​​corresponding to each position point by the preset transparency to obtain the final grayscale values ​​corresponding to each position point.

[0103] In an optional embodiment, the above-mentioned step of projecting a shadow material onto the ground in the game scene through a decal component to form a shadow of the target character model on the ground includes: determining a tangent surface in the decal component that is tangent to the ground in the game scene; mapping the grayscale values ​​corresponding to the position points on the tangent surface in the shadow material onto the ground to form a shadow of the target character model on the ground.

[0104] Further, Figure 5The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 101 , the communication interface 103 and the memory 100 are connected via the bus 102 .

[0105] The memory 100 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 5 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.

[0106] The processor 101 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 in the processor 101 or the instruction in the form of software. The above processor 101 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 invention 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 invention 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 100, and the processor 101 reads the information in the memory 100 and completes the steps of the method of the above embodiment in combination with its hardware.

[0107] An embodiment of the present invention 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 shadow rendering method. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0108] Specifically, the shadow rendering method includes: obtaining the bone position information of the foot of the target character model in the game scene; constructing a target distance field in a decal component under the foot of the target character model according to the bone position information; determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determining the distance field determined by the grayscale value as the shadow material; projecting the shadow material onto the ground in the game scene through the decal component to form the shadow of the target character model on the ground.

[0109] The above-mentioned shadow rendering method constructs a distance field in the decal component by obtaining the position information of the character model's foot bones, so as to form a shadow under the character model's feet through the decal component. This method has low cost for rendering shadows and is suitable for mobile terminals. In addition, the shadows rendered by this method have a smooth transition, which helps to improve the player's gaming experience.

[0110] In an optional embodiment, the decal assembly is disposed under the feet of the target character model, and the volume of the decal assembly matches the maximum jumping height of the target character model.

[0111] In an optional embodiment, the bone position information includes first target foot bone position coordinates and second target foot bone position coordinates; the above step of constructing a target distance field in the decal component under the foot of the target character model based on the bone position information includes: constructing a first distance field in the decal component under the foot of the target character model based on the first target foot bone position coordinates; constructing a second distance field in the decal component under the foot of the target character model based on the second target foot bone position coordinates; and fusing the first distance field with the second distance field to obtain the target distance field.

[0112] In an optional embodiment, the step of constructing a first distance field in the decal component below the foot of the target character model based on the first target foot bone position coordinates includes: subtracting the coordinate positions of each position point in the decal component from the first target foot bone position coordinates to obtain a first vector corresponding to each position point; based on the first vector, determining a distance value corresponding to each position point; and based on the distance value corresponding to each position point, obtaining the first distance field.

[0113] In an optional embodiment, the above-mentioned step of determining the distance value corresponding to each position point based on the first vector includes: performing the following operations for the first vector corresponding to each position point: multiplying the first vector corresponding to the current position point by the preset coordinate value to obtain a second vector; wherein the preset coordinate value is used to scale the coordinate value of the preset axis; and determining the vector length corresponding to the second vector as the distance value corresponding to the current position point.

[0114] In an optional embodiment, the coordinate value of the preset axial direction in the above preset coordinate values ​​is greater than 1, and the coordinate value corresponding to the axial direction other than the preset axial direction is equal to 1.

[0115] In an optional embodiment, the step of fusing the first distance field with the second distance field to obtain a target distance field includes: for each position point in the decal component, multiplying a distance value corresponding to the current position point in the first distance field by a distance value corresponding to the current position point in the second distance field to obtain a fused distance value corresponding to the current position point; and obtaining the target distance field based on the fused distance value corresponding to each position point in the decal component.

[0116] In an optional embodiment, the step of determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field includes: setting the position point in the target distance field whose distance value is less than a first preset value to a first grayscale value; setting the position point in the target distance field whose distance value is greater than a second preset value to a second grayscale value; wherein the second preset value is greater than the first preset value; for a target position point in the target distance field whose distance value is not less than the first preset value and not greater than the second preset value, setting the target position point to a grayscale value between the first grayscale value and the second grayscale value according to the distance value corresponding to the target position point.

[0117] In an optional embodiment, the first grayscale value is a first value, and the second grayscale value is a second value; the above method also includes: inverting the grayscale values ​​corresponding to each position point in the target distance field to obtain the inverted grayscale values ​​corresponding to each position point; multiplying the inverted grayscale values ​​corresponding to each position point by the preset transparency to obtain the final grayscale values ​​corresponding to each position point.

[0118] In an optional embodiment, the above-mentioned step of projecting a shadow material onto the ground in the game scene through a decal component to form a shadow of the target character model on the ground includes: determining a tangent surface in the decal component that is tangent to the ground in the game scene; mapping the grayscale values ​​corresponding to the position points on the tangent surface in the shadow material onto the ground to form a shadow of the target character model on the ground.

[0119] 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 invention, 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. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a terminal device, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0120] In the description of the present invention, 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 invention 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 limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0121] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, 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 invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A shadow rendering method, characterized in that: The method comprises: Get the bone position information of the feet of the target character model in the game scene; Constructing a target distance field in a decal component under a foot of the target character model according to the bone position information; Determine the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determine the distance field determined by the grayscale value as the shadow material; The shadow material is projected onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground.

2. The method according to claim 1, characterized in that: The decal component is arranged under the feet of the target character model, and the volume of the decal component matches the maximum jumping height of the target character model.

3. The method according to claim 1, characterized in that: The bone position information includes a first target foot bone position coordinate and a second target foot bone position coordinate; The step of constructing a target distance field in a decal component under the foot of the target character model according to the bone position information comprises: Constructing a first distance field in a decal component under a foot of the target character model according to the first target foot bone position coordinates; Constructing a second distance field in a decal component under a foot of the target character model according to the second target foot bone position coordinates; The first distance field and the second distance field are fused to obtain the target distance field.

4. The method according to claim 3, characterized in that The step of constructing a first distance field in a decal component below the foot of the target character model according to the first target foot bone position coordinates comprises: Subtracting the coordinates of each position point in the decal component from the coordinates of the first target foot bone position to obtain a first vector corresponding to each position point; Based on the first vector, determining the distance value corresponding to each of the position points; The first distance field is obtained based on the distance values ​​corresponding to the respective position points.

5. The method according to claim 4, characterized in that The step of determining the distance values ​​corresponding to the respective position points based on the first vector comprises: For the first vector corresponding to each position point, perform the following operations: Multiplying the first vector corresponding to the current position point by the preset coordinate value to obtain a second vector; wherein the preset coordinate value is used to scale the coordinate value of the preset axis; The vector length corresponding to the second vector is determined as the distance value corresponding to the current position point.

6. The method according to claim 5, characterized in that The coordinate value of the preset axial direction in the preset coordinate values ​​is greater than 1, and the coordinate values ​​corresponding to the axial directions other than the preset axial direction are equal to 1.

7. The method according to claim 3, characterized in that The step of fusing the first distance field with the second distance field to obtain the target distance field includes: For each position point in the decal component, multiply the distance value corresponding to the current position point in the first distance field by the distance value corresponding to the current position point in the second distance field to obtain a fusion distance value corresponding to the current position point; The target distance field is obtained based on the fusion distance value corresponding to each position point in the decal component.

8. The method according to claim 1, characterized in that The step of determining the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field comprises: Setting the position point whose distance value in the target distance field is less than the first preset value to the first grayscale value; setting the position point whose distance value in the target distance field is greater than the second preset value to the second grayscale value; wherein the second preset value is greater than the first preset value; For a target position point in the target distance field whose distance value is not less than the first preset value and not greater than the second preset value, the target position point is set to a grayscale value between the first grayscale value and the second grayscale value according to the distance value corresponding to the target position point.

9. The method according to claim 8, characterized in that The first grayscale value is a first value, and the second grayscale value is a second value; the method further includes: Performing inversion processing on the grayscale value corresponding to each position point in the target distance field to obtain the inverted grayscale value corresponding to each position point; The inverted grayscale value corresponding to each position point is multiplied by the preset transparency to obtain the final grayscale value corresponding to each position point.

10. The method according to claim 1, characterized in that The step of projecting the shadow material onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground includes: Determining a tangent surface of the decal component to the ground in the game scene; The grayscale values ​​corresponding to the position points on the tangent plane in the shadow material are mapped onto the ground, so as to form a shadow of the target character model on the ground.

11. A shadow rendering device, characterized in that: The device comprises: An information acquisition module, used to obtain the bone position information of the foot of the target character model in the game scene; A distance field creation module, configured to construct a target distance field in a decal component below a foot of the target character model according to the bone position information; A material determination module, configured to determine the grayscale value of each position point in the target distance field according to the distance value corresponding to each position point in the target distance field, and determine the distance field determined by the grayscale value as the shadow material; A shadow forming module is used to project the shadow material onto the ground in the game scene through the decal component to form a shadow of the target character model on the ground.

12. An electronic device, characterized in that: The electronic device 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 shadow rendering method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the shadow rendering method according to any one of claims 1 to 10.

Citation Information

Cited By

  • Symbol distance field-based 2D dynamic soft shadow efficient rendering method and system

    CN122415833A