Map generation method and device, equipment, storage medium and program product

By acquiring the texture image brightness information and skeletal animation data of two-dimensional objects, and calculating the light intensity to generate dynamic normal maps, the problem of static normal maps being unable to adapt to skeletal animations is solved, achieving naturalness and high quality in dynamic lighting rendering effects.

CN121982185APending Publication Date: 2026-05-05GUANGZHOU BOGUAN TELECOMM TECH LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUANGZHOU BOGUAN TELECOMM TECH LTD
Filing Date
2025-12-15
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In existing technologies, static normal maps cannot adapt to the dynamic deformation of skeletal animation, resulting in unnatural lighting effects and making it difficult to meet the high-quality rendering requirements of dynamic scenes.

Method used

By acquiring the brightness information of the texture image of the target 2D object, combining it with the skeletal animation data to determine the vertex normal vectors, calculating the illumination intensity, and generating a dynamic normal map based on the brightness information and illumination intensity, the brightness is extracted using weighted coefficients, and the dynamic normals are calculated by combining the skeletal transformation matrix and vertex weights to generate depth information that conforms to physical laws.

Benefits of technology

The generated normal maps can deform in real time and accurately follow the character's skeletal movements, eliminating the cost of manual production, achieving dynamic and adaptive lighting rendering effects, and enhancing the expressiveness of 2D games.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121982185A_ABST
    Figure CN121982185A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer graphics, and provides a map generation method and device, equipment, a storage medium and a program product.The map generation method comprises the steps that firstly, a texture image of a target two-dimensional object is obtained, and brightness information of all pixels in the texture image is extracted; meanwhile, acquiring skeleton animation data for driving the target two-dimensional object, and determining a vertex normal vector which is transformed in real time along with skeleton movement; thirdly, calculating theoretical illumination intensity of each pixel in a preset virtual light source direction based on the vertex normal vector; then, the depth information of each pixel is determined by using the difference between the extracted brightness information and the calculated theoretical illumination intensity; and finally, generating a normal map for illumination rendering according to the depth information. According to the method and the device, the normal chartlet adaptive to dynamic deformation of the skeletal animation can be generated, and the problems of high manufacturing cost and incapability of matching a static chartlet with a dynamic posture in related technologies are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer graphics technology, specifically to texture generation methods, apparatus, devices, storage media, and program products. Background Technology

[0002] In 2D game development, normal maps are typically used to simulate the surface details of objects in order to achieve a sense of volume and real-time lighting effects. Current methods for obtaining normal maps mainly rely on manual drawing by artists or estimation from static images using AI models. However, manually drawing normal maps is not only cumbersome and time-consuming, but also makes it difficult to ensure consistency in drawing standards among different artists. Furthermore, existing depth maps or normal maps generated from static images usually have fixed geometric information. When 2D characters undergo dynamic deformations such as bending and rotating under skeletal animation, these static normal data cannot adapt to physical changes, resulting in lighting highlights and shadows failing to follow character movements correctly. This leads to unnatural lighting rendering effects that fail to meet the high-quality rendering requirements of dynamic scenes.

[0003] Therefore, there is an urgent need for a texture generation method to solve the problem that static normal maps in related technologies cannot adapt to the dynamic deformation of skeletal animation. Summary of the Invention

[0004] This disclosure provides a texture generation method, apparatus, device, storage medium, and program product to solve the problem in related technologies that static normal maps cannot adapt to the dynamic deformation of skeletal animation.

[0005] Firstly, this disclosure provides a texture generation method, which includes: Obtain the texture image of the target 2D object and extract the brightness information of each pixel in the texture image; Based on the skeletal animation data of the driving target 2D object, determine the vertex normal vectors that change with the bone movement; Based on the vertex normal vector, the illumination intensity of each pixel in the texture image under the preset virtual light source direction is determined; Based on the brightness information and illumination intensity, the depth information of each pixel in the texture image is determined; Based on the depth information, a normal map is generated for lighting rendering.

[0006] The texture generation method disclosed herein obtains the brightness information of a texture image and combines it with the skeletal animation data of the target 2D object to determine the vertex normal vectors that change with motion. Then, it calculates the illumination intensity under a virtual light source and finally uses the relationship between brightness information and illumination intensity to determine depth information and generate a normal map. The beneficial effect is that by combining static texture brightness with dynamic skeletal normals, it is possible to generate dynamically adaptive depth and normal information. Since the derivation of depth information depends on the vertex normals that change with skeletal movement, the generated normal map can follow the character's skeletal movements in real time and accurately, conforming to physical laws of deformation. This eliminates the cost of manual production and solves the problem of unnatural lighting effects in dynamic skeletal animations caused by traditional static normal maps.

[0007] In one optional implementation, extracting the brightness information of each pixel in the texture image includes: Sample the texture image to obtain the color channel components of each pixel; The color channel components are weighted and summed according to preset weighting coefficients to obtain the brightness information of each pixel.

[0008] This disclosure also obtains brightness information by sampling the texture image and using preset weighting coefficients to perform weighted summation on the color channel components. Compared to simple average calculation, weighted summation can more accurately extract the brightness distribution that conforms to visual perception, thereby making the subsequent depth fluctuations derived from brightness more natural and realistic.

[0009] In one optional implementation, based on the skeletal animation data of the driving target 2D object, the vertex normal vectors that change with the skeletal motion are determined, including: Obtain the initial vertex normal vectors of the target 2D object; Obtain the bone transformation matrix and vertex weights from the skeletal animation data; Based on the vertex weights and the bone transformation matrix, the initial vertex normals are weighted and transformed to obtain the vertex normal vectors that change with the bone movement.

[0010] This disclosure also utilizes skeletal skinning technology to drive normal transformation, ensuring that the direction of vertex normals can maintain strict geometric synchronization with the character's limb movements, thus avoiding a disconnect between lighting and movement.

[0011] In one alternative implementation, the initial vertex normal vector is perpendicular to the screen projection plane where the target 2D object is located.

[0012] This disclosure also provides a standardized initial state that conforms to the characteristic that 2D images are primarily oriented towards screen display, ensuring the correct orientation of the normals when no bone rotation occurs.

[0013] In one optional implementation, the illumination intensity of each pixel in the texture image under a preset virtual light source direction is determined based on the vertex normal vector, including: Obtain the direction vector of the preset virtual light source direction; the preset virtual light source direction is the target direction relative to the texture coordinate system; Calculate the dot product of the vertex normal vector and the direction vector, and limit the dot product result to a preset range to obtain the illumination intensity.

[0014] This disclosure also efficiently calculates the theoretical brightness under virtual lighting by calculating the dot product of the vertex normal vector and the preset virtual light source direction vector and limiting it to a preset range.

[0015] In one optional implementation, the depth information of each pixel in the texture image is determined based on the brightness information and the illumination intensity, including: The difference between the brightness information and the illumination intensity is multiplied by a preset depth scaling parameter to obtain the depth offset. Obtain the base depth value of each pixel in the texture image, and then add the depth offset to the base depth value to obtain the depth information of each pixel.

[0016] This disclosure also uses a differential algorithm to transform the light and dark details of the texture into geometric bumps and depressions relative to the skeletal plane, while providing control over the strength of the three-dimensional effect through depth scaling parameters.

[0017] In one alternative implementation, before the step of generating a normal map for lighting rendering based on depth information, the method further includes: Smooth the depth map corresponding to the depth information.

[0018] This disclosure also effectively eliminates depth abrupt changes caused by excessive noise or pixel differences in the original artwork through smoothing processing, avoiding overly sharp or messy artifacts in the generated normal map.

[0019] In one alternative implementation, a normal map for lighting rendering is generated based on depth information, including: The depth gradient value of each pixel is determined based on the depth information; Normal vectors are constructed based on depth gradient values, and then normalized and mapped to color space to generate normal maps.

[0020] This disclosure also converts depth information into normal directions and ensures that the output data conforms to the standard normal map format specifications through normalization and mapping.

[0021] Secondly, this disclosure provides a texture generation apparatus, the apparatus comprising: The brightness extraction module is used to acquire the texture image of the target two-dimensional object and extract the brightness information of each pixel in the texture image; The normal determination module is used to determine the vertex normal vectors that change with the bone motion based on the skeletal animation data of the driving target 2D object. The lighting determination module is used to determine the lighting intensity of each pixel in the texture image under a preset virtual light source direction based on the vertex normal vector; The depth determination module is used to determine the depth information of each pixel in the texture image based on the brightness information and the illumination intensity. The generation module is used to generate normal maps for lighting rendering based on depth information.

[0022] Thirdly, this disclosure provides an electronic device, including: a memory and a processor, which are communicatively connected to each other. The memory stores computer instructions, and the processor executes the computer instructions to perform the texture generation method of the first aspect or any corresponding embodiment described above.

[0023] Fourthly, this disclosure provides a computer-readable storage medium storing computer instructions for causing a computer to execute the texture generation method of the first aspect or any corresponding embodiment described above.

[0024] Fifthly, this disclosure provides a computer program product, including computer instructions for causing a computer to execute the texture generation method of the first aspect or any corresponding embodiment described above. Attached Figure Description

[0025] To more clearly illustrate the technical solutions in the specific embodiments of this disclosure or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0026] Figure 1 This is a schematic diagram illustrating an application scenario according to an embodiment of this disclosure; Figure 2 This is a schematic flowchart of a first method for generating textures according to an embodiment of the present disclosure; Figure 3 This is a schematic diagram of a second process for a texture generation method according to an embodiment of the present disclosure; Figure 4 This is a schematic flowchart of a depth map lighting method based on 2D skeletal animation according to an embodiment of the present disclosure; Figure 5 This is an initial image schematic diagram of a 2D character according to an embodiment of the present disclosure; Figure 6This is a schematic diagram of the normal map of a 2D character according to an embodiment of the present disclosure; Figure 7 This is a structural block diagram of a texture generation apparatus according to an embodiment of the present disclosure; Figure 8 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of this disclosure. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0028] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0029] Before providing a detailed description of the embodiments of this disclosure, some of the nouns and terms involved in the embodiments of this disclosure will be explained.

[0030] 2D skeletal animation: refers to a two-dimensional animation technique that does not rely on frame-by-frame rendering, but instead binds 2D images (sprites) to a hierarchical skeletal structure. Dynamic effects are achieved by changing the rotation, translation, and scaling of the bones to drive the deformation of the image mesh.

[0031] Normal mapping: a texture mapping technique widely used in 3D graphics. It stores the normal direction vectors of an object's surface in the RGB color channels (usually X corresponds to R, Y to G, and Z to B), and is used to simulate uneven lighting details on flat geometric surfaces.

[0032] Shape recovery from light and shadow: a technique in the field of computer vision that aims to infer the three-dimensional geometry (depth or normal) of an object's surface by analyzing variations in light and shadow (shadows and highlights) in a single image.

[0033] Brightness: refers to the brightness of an image pixel. In computer graphics, it is usually calculated by weighted summation of the RGB color components to reflect the differences in human eye perception of the intensity of different colors of light.

[0034] Central difference method: A numerical differentiation method that approximates the gradient (slope) of a point by calculating the difference between the values ​​of its left and right (or up and down) adjacent points. It is often used to calculate surface normals from depth maps.

[0035] Depth map: A grayscale image in which each pixel value does not represent color, but rather the distance or height of that point from the observer (or reference plane).

[0036] Sprite: In 2D game development, it refers to a two-dimensional image object (such as a picture of a character or prop).

[0037] Shader: A program that runs on a graphics processing unit (GPU) and is used to calculate the rendering effect of an image.

[0038] Vertex Shader: Used to process the vertices of a graphics mesh.

[0039] Fragment shader: Used to process rasterized pixels (fragments).

[0040] URP (Universal Render Pipeline): A universal rendering pipeline provided by the Unity engine that supports high-performance graphics rendering, including a lighting and rendering system specifically designed for 2D games.

[0041] PBR (Physically Based Rendering): This is a rendering technique that simulates the laws governing the propagation of light in the real world.

[0042] As one optional application scenario of this disclosure embodiment, such as Figure 1 As shown, this texture generation method can run on a system that includes at least one terminal device and at least one server. Figure 1 The system, as exemplarily shown, includes a computer 101, a mobile terminal 102, and a server 103, with terminal devices such as the computer 101 and mobile terminal 102 connected to the server 103 via a network 110. The texture generation method provided in this embodiment can run in the graphics processing unit (GPU) or central processing unit (CPU) of the computer 101 or mobile terminal 102, and is used to generate normal maps in real time during game operation or animation production.

[0043] Specifically, the terminal device can be a smartphone, tablet, laptop, PDA, desktop computer, game console, smart TV, smart wearable device, in-vehicle terminal, VR (Virtual Reality) device, AR (Augmented Reality) device, etc. These terminal devices can be equipped with game engines or image processing software that support 2D skeletal animation. Server 103 can be a standalone physical server, a server cluster, a distributed system, or a cloud server providing cloud services. Network 110 can be a wired or wireless network, examples of which include, but are not limited to, the Internet, corporate intranet, local area network, wide area network, mobile communication network, and combinations thereof.

[0044] In related technologies, lighting effects in 2D games typically rely on artists manually drawing a large number of normal maps or using static algorithms to generate depth maps. Addressing the technical problems of high manual production costs, cumbersome processes, and the inability of generated static normals to change in real-time with skeletal animation, resulting in inconsistencies between character movement and the lighting environment, this disclosure provides a texture generation method to achieve physically accurate and detailed dynamic lighting rendering while reducing production costs.

[0045] According to an embodiment of this disclosure, a texture generation method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0046] This embodiment provides a texture generation method that can be used in the aforementioned terminal devices, such as desktop computers and laptops. Figure 2 This is a flowchart of a texture generation method according to an embodiment of the present disclosure, such as... Figure 2 As shown, the process includes the following steps: Step S201: Obtain the texture image of the target two-dimensional object and extract the brightness information of each pixel in the texture image.

[0047] A target 2D object refers to a flat image object displayed in a graphical interface, such as a 2D character sprite, UI icon, or scene prop in a game. These objects are usually composed of one or more images (textures).

[0048] Texture images refer to color image data overlaid on the surface of the target two-dimensional object, which includes color channels such as red, green, and blue (RGB).

[0049] Brightness information refers to numerical values ​​that represent the brightness or darkness of a pixel, and is usually used to reflect whether the pixel is visually bright or dark.

[0050] Specifically, the process begins by reading the current texture map of the target 2D object (such as a 2D game character). Next, it iterates through each pixel in the texture image, extracting its color value and converting it into a scalar brightness value. For example, if the texture is an image of a character's clothing, the brightness of each point on the clothing is calculated; lighter areas (such as white wrinkles) have higher brightness values, while darker areas (such as shadows) have lower brightness values. The purpose of this step is to preliminarily infer the surface undulations of the object based on the relationship between light and dark.

[0051] Furthermore, as a specific method for extracting brightness information, the texture image is sampled pixel by pixel to obtain the red (R), green (G), and blue (B) color channel components for each pixel. Then, based on preset weighting coefficients (for example, leveraging the human eye's heightened sensitivity to green, assigning a higher weight to the green channel, such as 0.587, red 0.299, and blue 0.114), these three components are weighted and summed. The calculation formula can be expressed as: Brightness = 0.299 * R + 0.587 * G + 0.114 * B. The brightness information obtained in this way better matches human visual perception and accurately reflects the three-dimensional structure expressed through light and dark colors in the original image.

[0052] Step S202: Based on the skeletal animation data of the driving target 2D object, determine the vertex normal vectors that change with the bone movement.

[0053] Skeletal animation data refers to a set of data used to drive the deformation of 2D images, including the position, rotation angle, scaling ratio of bones, and the weight of mesh vertices affected by bones.

[0054] A vertex normal vector is a direction vector perpendicular to the surface of an object, used to describe the orientation of the object's surface. Specifically, in 2D skeletal animation, the image is divided into a mesh of many triangles, with the vertices of the mesh following the movement of the bones. When the character performs an action (such as waving), the bones driving the arm rotate. Based on the bone rotation data of the current frame, the new normal direction of each vertex on the mesh is calculated in real time. For example, when the character's body changes from upright to bent over, the normal of the vertices in the chest area will also tilt accordingly. This step determines the object's geometric orientation at a macroscopic level, ensuring that subsequent lighting calculations can correctly respond to changes in the character's pose.

[0055] Step S203: Based on the vertex normal vector, determine the illumination intensity of each pixel in the texture image under the preset virtual light source direction.

[0056] The virtual light source direction is an assumed illumination direction used to calculate the reference brightness, for example, assuming that the light shines down perpendicularly from above.

[0057] Illumination intensity here specifically refers to the theoretical brightness value that a smooth surface should exhibit under assumed conditions.

[0058] Specifically, using the dynamic vertex normals calculated in step S202, combined with a preset virtual light source direction (e.g., vector (0, 1, 0)), the theoretical lighting conditions at each pixel position are calculated through mathematical operations (such as dot product). If the normal of a certain part is facing the virtual light source, the calculated lighting intensity is high; if it is facing away from the light source, the intensity is low. The result calculated in this step represents "how bright the object should be in the current skeletal pose if its surface is smooth and has no texture details".

[0059] Step S204: Determine the depth information of each pixel in the texture image based on the brightness information and illumination intensity.

[0060] Depth information represents the distance of a pixel relative to a reference plane, i.e., the degree of protrusion or depression.

[0061] Specifically, the actual brightness information extracted in step S201 (including details such as wrinkles and buttons drawn by the artist) is compared with the theoretical illumination intensity calculated in step S203 (containing only the general outline of the skeleton). The logic is: if the actual brightness of a pixel is brighter than the theoretical brightness, it means that this point is more convex than its surroundings (more towards the light source); conversely, it means that it is concave. Through this comparison, the depth offset of each pixel can be calculated, thereby constructing a depth map containing rich details. For example, the patterns on the armor are highlights in the original artwork, but through this step, they will be interpreted as having a large depth value (convexity).

[0062] Step S205: Generate a normal map for lighting rendering based on the depth information.

[0063] Normal mapping is a special type of texture that does not store color, but instead stores data on the direction of surface normals, used to simulate bumpiness in lighting rendering.

[0064] Specifically, after obtaining the depth information generated in step S204, the height difference (i.e., slope or gradient) between adjacent pixels in the depth map is calculated. If a pixel on the right is higher than a pixel on the left, it means the surface is tilted to the left. Based on these tilt angles, the final surface normal vector for each pixel is constructed and encoded into a normal map. This generated normal map is ultimately passed to the lighting system of the rendering engine, enabling 2D characters in the game scene to exhibit realistic, motion-dependent lighting effects, just like 3D models.

[0065] In summary, the texture generation method provided in this embodiment obtains the brightness information of the texture image and combines it with the skeletal animation data of the target 2D object to determine the vertex normal vectors that change with motion. Then, it calculates the illumination intensity under a virtual light source and finally uses the relationship between brightness information and illumination intensity to determine depth information and generate a normal map. The beneficial effect is that by combining static texture brightness with dynamic skeletal normals, it is possible to generate dynamically adaptive depth and normal information. Since the derivation of depth information depends on the vertex normals that change with skeletal movement, the generated normal map can follow the character's skeletal movements in real time and accurately, conforming to physical laws of deformation. This eliminates the cost of manual production and solves the problem of unnatural lighting effects in dynamic skeletal animations caused by traditional static normal maps.

[0066] This embodiment provides a texture generation method that can be used in the aforementioned terminal devices, such as desktop computers and laptops. Figure 3 This is a flowchart of a texture generation method according to an embodiment of the present disclosure, such as... Figure 3 As shown, the process includes the following steps: Step S301: Obtain the texture image of the target 2D object and extract the brightness information of each pixel in the texture image. For details, please refer to [link to relevant documentation]. Figure 2 Step S201 of the illustrated embodiment will not be described again here.

[0067] Step S302: Based on the skeletal animation data of the driving target 2D object, determine the vertex normal vectors that change with the bone movement.

[0068] This step is to construct the vertex normal vectors that change with the animation, and specifically includes the following steps: Step S3021: Obtain the initial vertex normal vectors of the target 2D object.

[0069] First, it's necessary to determine the geometric normal reference of the target 2D object in its static or initial state. This initial vertex normal vector is set to have a specific geometric direction, that is, perpendicular to the screen projection plane where the target 2D object lies (e.g., vector (0, 0, 1)). This means that in the initial state, before being driven by skeletal animation or affected by deformation, each vertex of the target 2D object is considered to be on a flat projection plane, with its normal direction orthogonal to that projection plane. This setting provides a unified reference reference that conforms to the planar characteristics of the 2D object for subsequent dynamic transformations.

[0070] Step S3022: Obtain the bone transformation matrix and vertex weights from the skeletal animation data.

[0071] To calculate the normals that change with motion, real-time skeletal animation data used to drive the target 2D object is required. This data specifically includes two key parameters: The skeleton transformation matrix describes the spatial transformation state of the skeleton in the current motion frame (such as rotation, displacement, and other posture changes).

[0072] Vertex weights describe the degree to which each vertex in a target 2D object is influenced by different bones. Since a vertex may be driven by multiple bones simultaneously, vertex weights are used to quantify the proportion of each bone's contribution to the transformation of that vertex.

[0073] Step S3023: Based on the vertex weights and the bone transformation matrix, perform a weighted transformation on the initial vertex normals to obtain vertex normal vectors that change with bone movement.

[0074] After obtaining the initial baseline (initial vertex normals) and driving data (matrices and weights), this step performs specific calculations to obtain the final dynamic normals.

[0075] Specifically, this step utilizes a bone transformation matrix, combined with vertex weights, to perform a weighted transformation on the initial vertex normals. The transformation matrix describing the bone's motion pose is applied to the initial normal vectors, and the influence results of different bones are mixed or superimposed according to the vertex weights.

[0076] After the aforementioned weighted transformation, the initial normal vector, originally perpendicular to the screen projection plane, undergoes a directional shift or change, resulting in a vertex normal vector that changes with the bone movement. This transformed vector can reflect the surface orientation changes of the target 2D object in the current skeletal animation pose in real time.

[0077] Step S303: Based on the vertex normal vector, determine the illumination intensity of each pixel in the texture image under the preset virtual light source direction.

[0078] This step is used to construct a theoretical lighting reference frame.

[0079] Specifically, first, a preset virtual light source direction vector is obtained. This direction can be set to a fixed target direction relative to the texture coordinate system (e.g., directly above, vector (0,1,0)) to simulate the default top lighting environment when artists are drawing the original artwork.

[0080] Then, the dot product of the vertex normal vector and the virtual light source direction vector is calculated. The result of the dot product reflects the cosine of the angle between the two vectors, representing the degree of light received. To ensure physical plausibility, the dot product result is limited to a preset range (usually between 0 and 1), and negative values ​​on the backlit side are discarded, thus obtaining the theoretical light intensity at that location.

[0081] Step S304: Determine the depth information of each pixel in the texture image based on the brightness information and illumination intensity.

[0082] This step is a deep reverse engineering process.

[0083] Specifically, the actual brightness information extracted in step S301 is subtracted from the theoretical illumination intensity obtained in step S303 to obtain a difference. This difference represents the brightness gain brought about by the details.

[0084] The difference is then multiplied by a preset depth scaling parameter, and the result is the depth offset. The depth scaling parameter is an adjustable factor (such as 1.5 or 0.5). If the difference is large, it means that the area is actually bright even though it should theoretically be dark, indicating a significant bulge. Multiplying by the scaling parameter can artificially enhance or weaken this three-dimensional effect to meet artistic requirements.

[0085] Finally, the base depth value of the texture image (usually a reference plane depth) is obtained, and the calculated depth offset is superimposed on the base depth value to obtain the final target depth value for each pixel. The depth information generated in this way includes both the macroscopic orientation of the bones and the microscopic undulations of the texture.

[0086] Furthermore, before generating the normal map, the depth map corresponding to the depth information is smoothed. This smoothing process can use a Gaussian blur algorithm. This is analogous to polishing a rough clay surface, removing subtle noise caused by brushstrokes in the original artwork, resulting in a smoother, more rounded surface.

[0087] Step S305: Generate a normal map for lighting rendering based on the depth information.

[0088] The purpose of this step is to convert the single-channel grayscale depth map (representing height) generated in the previous step into a three-channel RGB normal map (representing surface orientation) that the rendering engine can recognize.

[0089] In computer graphics, depth describes the "elevation of a point," while normals describe the "orientation of a surface." To deduce orientation from height, we need to calculate the rate of change of height, which is mathematically known as the "gradient."

[0090] This step converts the depth data into a normal map usable by the rendering engine, including: calculating the depth gradient values ​​of each pixel in the depth map in the horizontal and vertical directions using the center difference method; constructing normal vectors based on the gradient information, and performing normalization and color space mapping.

[0091] The center difference method calculates the slope by comparing the depth differences of the current pixel's left, right, top, and bottom neighbors. If the right side is much deeper than the left, it indicates a steep slope, and the normal vector will point to the side. Finally, the calculated normal vector (x, y, z) is mapped to RGB colors (r, g, b) to generate the final normal map for use by the game engine's lighting system.

[0092] The specific processing procedure is as follows: First, we need to know whether the current pixel is "flat" or "skewed" relative to its surrounding pixels. This is achieved using the center difference method: Horizontal slope determination (dX): Read the depth value of the right neighboring pixel of the current pixel and subtract the depth value of the left neighboring pixel.

[0093] If the result is positive, it means that the right side is higher than the left side, and the terrain slopes to the left.

[0094] If the result is negative, it means that the right side is lower than the left side, and the terrain slopes to the right.

[0095] Vertical slope determination (dY): Similarly, read the depth value of the upper adjacent pixel and subtract the depth value of the lower adjacent pixel to determine the tilt trend in the vertical direction.

[0096] The dX and dY values ​​calculated in this step directly reflect the "tilt" of the pixel in the horizontal and vertical directions.

[0097] Having determined the degree of tilt, we use the principles of differential geometry to construct a three-dimensional vector to represent the direction perpendicular to the tilted surface (i.e., the normal): X-axis component: Take the negative value (-dX) of the horizontal slope dX. This is because if the terrain rises to the right (dX>0), the surface is actually facing to the left, so the X-component of the normal should point to the left (negative direction).

[0098] Y-axis component: Take the negative value (-dY) of the vertical slope dY. Similarly, if the terrain rises, the surface faces downwards.

[0099] Z-axis component: fixed at 1.0. This is because in a 2D plane, we assume that the reference surface is always approximately facing outwards from the screen (positive Z-axis direction).

[0100] At this stage, dX and dY are multiplied by a preset normal intensity factor. Increasing this factor artificially amplifies the slope value, making the final rendered bumpiness more intense and deep; decreasing this factor makes the surface appear smoother.

[0101] The length of the vector (-dX, -dY, 1.0) constructed above is uncertain. In lighting calculations, normals must be unit vectors (length 1). Therefore, this vector needs to be normalized, preserving its direction while scaling its length to 1.

[0102] In mathematics, the components of a normal vector typically range from -1 to 1 (e.g., -1 for pointing left and +1 for pointing right). However, the color channels (R, G, B) of an image texture can usually only store non-negative values. To store normal data in a texture, a standard mapping operation is required: color value = normal vector * 0.5 + 0.5. Using this formula, "-1" is mapped to 0 (black), "0" is mapped to 0.5 (gray), and "1" is mapped to 1 (white).

[0103] In the final generated texture, light purple (RGB approximately 0.5, 0.5, 1.0) represents flat areas (normals pointing towards the positive Z-axis). Areas that are reddish or greenish represent tilted surfaces.

[0104] This texture, containing rich color information, is the final normal map, which will be passed to the rendering pipeline to give 2D characters a realistic sense of volume under dynamic lighting.

[0105] In summary, the texture generation method provided in this embodiment first uses weighted summation to accurately extract texture brightness as a static detail basis, and then uses the skeletal transformation matrix and vertex weights to calculate dynamic normals that update in real time with the animation as a geometric pose basis. Next, by calculating the difference between theoretical intensity and actual brightness under the physical lighting model, and combining depth scaling parameters, it flexibly infers surface depth details. After smoothing to eliminate noise, a standardized normal map is finally constructed based on the depth gradient. This method integrates image processing techniques (brightness extraction, gradient calculation) and computer graphics animation techniques (skeletal skinning transformation), solving the problem that static textures in traditional 2D game lighting cannot adapt to dynamic actions. It not only generates normal maps with rich bump details, but also ensures that these lighting details change physically in accordance with the character's running, attacking, and other skeletal movements, greatly enhancing the expressiveness of 2D graphics.

[0106] To better illustrate the texture generation method of the embodiments, a preferred embodiment will be provided below. This embodiment is intended to describe the implementation process of this disclosure in detail, but is not intended to limit the scope of protection of this disclosure.

[0107] This embodiment provides a depth map lighting method based on 2D skeletal animation. The core idea of ​​this method is to break the limitations of traditional static normal maps. By using the principle of shape recovery from light and shadow, combined with the real-time skeletal posture of the 2D character, pixel-level depth information is dynamically deduced, thereby generating a normal map that can change with the movement.

[0108] The method in this embodiment can be run on computing devices that include a graphics processing unit (GPU), such as smartphones, tablets, or desktop computers. The specific processing flow is as follows: Figure 4 As shown, it includes the following steps: Step S401: Extraction and preprocessing of texture brightness information.

[0109] In this step, the original texture image of the target 2D character is first obtained, such as... Figure 5 As shown. In order to accurately derive depth, the original texture is required to follow the art convention of being uniformly lit from directly above when it is drawn. That is, the brighter parts in the image usually represent the part facing the light source (i.e., the surface is raised), while the darker parts represent the part facing away from the light source (i.e., the surface is concave or occluded).

[0110] Based on this principle, the original texture of the target 2D character is first sampled in the fragment shader.

[0111] To accurately reflect the human eye's perception of brightness, instead of directly using the average value of RGB, a weighted algorithm that conforms to the characteristics of human vision is employed for conversion. The specific logic is as follows: extract the red (R), green (G), and blue (B) components of a pixel, multiply each by a preset weighting coefficient (preferably: 0.299 for red, 0.587 for green, and 0.114 for blue), and sum the weighted results to obtain the pixel's brightness value. This brightness value not only represents the lightness or darkness of a color but, in this scheme, is also considered as the pixel's diffuse reflection response intensity under virtual lighting.

[0112] In addition, to enhance the sense of depth generated later, the extracted brightness values ​​can be contrast-enhanced to increase the difference between light and dark, or Gaussian blurring can be applied to reduce the interference of noise from the original image on depth derivation.

[0113] Step S402: Calculate dynamic vertex normals based on bone-driven computation.

[0114] To address the issue that static normals cannot deform with animation, this step introduces skeletal animation data in the vertex shader stage.

[0115] Traditional 2D images are treated as a plane with its normal always perpendicular to the screen. However, in this embodiment, the 2D image is given a skeletal skinned mesh. When the character performs an action (e.g., waving an arm), the skeleton rotates and shifts.

[0116] In the vertex shader stage, the initial normal direction of the mesh vertices is first defined, typically set to be perpendicular to the screen plane (i.e., the Z-axis direction). Then, the bone data driving the vertex's motion in the current frame is read, including the bone transformation matrices (containing rotation information) and the weights of the vertex affected by different bones. Using these bone transformation matrices and corresponding weights, the initial normal of the vertex is rotated.

[0117] This process is similar to 3D skinning calculations, causing the normals of the vertices at a character's arm bones to shift upwards as the arm bones rotate upwards. The dynamic vertex normals generated in this step represent the approximate orientation of the object's surface. These dynamic normals provide macroscopic geometric constraints for subsequent depth derivation, ensuring that lighting effects have physical consistency.

[0118] Step S403: Depth back-calculation based on the virtual lighting model.

[0119] This step is used to synthesize a depth map containing details. A virtual lighting environment is constructed in the shader, setting a fixed virtual parallel light source direction (preferably directly above the texture space, i.e., the positive Y-axis direction) to simulate the lighting assumptions made by the artists when creating the original artwork. Next, reverse lighting is performed, as follows: First, calculate the theoretical brightness. Using the dynamic vertex normal obtained in step two, calculate the theoretical diffuse reflection intensity that the normal should have under the illumination of the aforementioned virtual light source (usually obtained by calculating the dot product of the normal and the light direction, and truncating the non-negative value). This value represents "how bright it should be in the current skeleton pose if the surface is smooth".

[0120] The depth offset is then calculated. The actual texture brightness extracted in step one is compared with the theoretical diffuse reflection intensity described above.

[0121] If the actual brightness is greater than the theoretical brightness, it means that the microscopic surface of the pixel is more oriented towards the light source than the skeletal surface, that is, it is "protruding" (such as the bright part of a fold of clothing).

[0122] If the actual brightness is less than the theoretical brightness, it means that this area is "recessed".

[0123] Finally, the depth values ​​are synthesized. The difference between the two is calculated and multiplied by an adjustable depth scaling parameter (such as 1.5 or 0.5) to convert the lighting differences into height differences. Finally, this offset is superimposed on the base depth to generate a real-time depth map containing rich details.

[0124] Step S404, smoothing optimization of the depth map.

[0125] Depth maps generated directly from pixel brightness may contain noise from the original brushstrokes or have overly sharp edges. To achieve a smoother, more natural representation of materials (such as skin and fabric), image processing optimization is performed on the depth map generated in step three, preferably using a Gaussian blur algorithm.

[0126] In the specific logic, sampling is performed cyclically within a neighborhood of a preset radius centered on the current pixel. The weight of each sampling point within the neighborhood is calculated using the Gaussian distribution formula (the closer to the center, the greater the weight). The sampled depth values ​​are multiplied by their corresponding weights and summed, then normalized by dividing by the total weight. This process filters out noise in the depth map, making depth changes smoother and more continuous, and terrain undulations more rounded and smooth, thus simulating a more realistic material texture.

[0127] Step S405: Generation of real-time normal maps.

[0128] This step converts the scalar depth field into a vector field, which generates the final normal map.

[0129] The gradient of the depth map is calculated using the central difference method. The specific logic is as follows: Sample the depth values ​​to the left, right, top, and bottom of the current pixel respectively.

[0130] Calculate the horizontal depth difference (right minus left) as the X-axis gradient, and calculate the vertical depth difference (up minus down) as the Y-axis gradient.

[0131] Construct a normal vector, where the X and Y components are the negative values ​​of the gradient (multiplied by the intensity coefficient), and the Z component is set to 1.0.

[0132] Next, the vector is normalized to a length of 1. Finally, the normalized normal vector is mapped from the interval -1 to 1 to the color space interval, outputting a standard normal map. The final normal map of this 2D character is shown below. Figure 6 As shown.

[0133] Step S406, Dynamic lighting rendering integration.

[0134] Finally, the real-time generated normal map is passed to the game engine's rendering pipeline (such as Unity URP 2DLighting). During the scene rendering phase, the lighting system uses this normal map to calculate the reflections of dynamic light sources (such as point lights and spotlights) on the character's surface, just like it would with a 3D model. Since the above steps are all executed in real time in the GPU every frame, the generated normal details always maintain physical consistency with the character's current pose, regardless of how the character bends, twists, or flips, thus achieving realistic, three-dimensional, and dynamic 2D lighting effects.

[0135] In summary, by simulating the principle of shape recovery from light and shadow and combining it with 2D skeletal animation, rich internal depth details, such as clothing wrinkles, can be automatically extracted from 2D sprite maps without relying on any AI models or pre-trained data, achieving lightweight, high-performance real-time rendering. Furthermore, because depth calculation relies on dynamically updated vertex normals in real time, the generated depth and normal details can naturally change with the character's posture (such as bending and deformation), ensuring dynamic consistency of lighting effects, avoiding the problem of static depth maps being disconnected from dynamic animations, and allowing flexible control over the strength of the sense of three-dimensionality.

[0136] This embodiment also provides a texture generation apparatus for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0137] This embodiment provides a texture generation device, such as... Figure 7 As shown, it includes: The brightness extraction module 701 is used to acquire the texture image of the target two-dimensional object and extract the brightness information of each pixel in the texture image; The normal determination module 702 is used to determine the vertex normal vectors that change with the bone motion based on the skeletal animation data of the driving target 2D object. The lighting determination module 703 is used to determine the lighting intensity of each pixel in the texture image under a preset virtual light source direction based on the vertex normal vector; The depth determination module 704 is used to determine the depth information of each pixel in the texture image based on the brightness information and the illumination intensity. The generation module 705 is used to generate normal maps for lighting rendering based on depth information.

[0138] In some alternative implementations, the brightness extraction module 701 is used for: Sample the texture image to obtain the color channel components of each pixel; The color channel components are weighted and summed according to preset weighting coefficients to obtain the brightness information of each pixel.

[0139] In one alternative implementation, the normal determination module 702 is used for: Obtain the initial vertex normal vectors of the target 2D object; Obtain the bone transformation matrix and vertex weights from the skeletal animation data; Based on the vertex weights and the bone transformation matrix, the initial vertex normals are weighted and transformed to obtain the vertex normal vectors that change with the bone movement.

[0140] In one alternative implementation, the illumination determination module 703 is used for: Obtain the direction vector of the preset virtual light source direction; the preset virtual light source direction is the target direction relative to the texture coordinate system; Calculate the dot product of the vertex normal vector and the direction vector, and limit the dot product result to a preset range to obtain the illumination intensity.

[0141] In one alternative implementation, the depth determination module 704 is used for: The difference between the brightness information and the illumination intensity is multiplied by a preset depth scaling parameter to obtain the depth offset. Obtain the base depth value of each pixel in the texture image, and then add the depth offset to the base depth value to obtain the depth information of each pixel.

[0142] In an alternative implementation, the depth determination module 704 is further configured to: Smooth the depth map corresponding to the depth information.

[0143] In one alternative implementation, the generation module 705 is used for: The depth gradient value of each pixel is determined based on the depth information; Normal vectors are constructed based on depth gradient values, and then normalized and mapped to color space to generate normal maps.

[0144] The texture generation apparatus provided in this disclosure can execute the texture generation method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects for executing the method. Further functional descriptions of the various modules and units described above are the same as in the corresponding embodiments described above, and will not be repeated here.

[0145] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure.

[0146] The following is a detailed reference. Figure 8The diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present disclosure. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 801, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 802 or a program loaded from memory 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the electronic device. The processor 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0147] Typically, the following devices can be connected to I / O interface 805: input devices 806 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 807 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 808 including, for example, magnetic tapes, hard disks, etc.; and communication devices 809. Communication device 809 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 8 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.

[0148] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 809, or installed from a memory 808, or installed from a ROM 802. When the computer program is executed by the processor 801, it performs the functions defined in the texture generation method of embodiments of this disclosure.

[0149] Figure 8 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0150] This disclosure also provides a computer-readable storage medium in which the methods described in this disclosure can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code downloaded over a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and subsequently stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium may also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the texture generation method shown in the above embodiments.

[0151] A portion of this disclosure can be applied to computer program products, such as computer program instructions, which, when executed by a computer, can invoke or provide methods and / or technical solutions according to this disclosure through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, and installation package files. Accordingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions; the computer compiling the instructions and then executing the corresponding compiled program; the computer reading and executing the instructions; or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.

[0152] Although embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A texture generation method, characterized in that, The method includes: Obtain the texture image of the target two-dimensional object, and extract the brightness information of each pixel in the texture image; Based on the skeletal animation data driving the target 2D object, determine the vertex normal vectors that change with the skeletal motion; Based on the vertex normal vector, the illumination intensity of each pixel in the texture image under the preset virtual light source direction is determined; Based on the brightness information and the illumination intensity, the depth information of each pixel in the texture image is determined; Based on the depth information, a normal map is generated for lighting rendering.

2. The method according to claim 1, characterized in that, The step of extracting the brightness information of each pixel in the texture image includes: The texture image is sampled to obtain the color channel components of each pixel; The color channel components are weighted and summed according to preset weighting coefficients to obtain the brightness information of each pixel.

3. The method according to claim 1, characterized in that, The determination of vertex normal vectors that change with bone movement based on the skeletal animation data driving the target 2D object includes: Obtain the initial vertex normal vectors of the target 2D object; Obtain the bone transformation matrix and vertex weights from the skeletal animation data; Based on the vertex weights and the bone transformation matrix, the initial vertex normals are weighted and transformed to obtain vertex normal vectors that change with bone movement.

4. The method according to claim 3, characterized in that, The initial vertex normal vector is perpendicular to the screen projection plane where the target 2D object is located.

5. The method according to claim 1, characterized in that, The step of determining the illumination intensity of each pixel in the texture image under a preset virtual light source direction based on the vertex normal vector includes: Obtain the direction vector of the preset virtual light source direction; the preset virtual light source direction is the target direction relative to the texture coordinate system; The dot product of the vertex normal vector and the direction vector is calculated, and the dot product result is restricted within a preset range to obtain the illumination intensity.

6. The method according to claim 1, characterized in that, Determining the depth information of each pixel in the texture image based on the brightness information and the illumination intensity includes: The difference between the brightness information and the illumination intensity is multiplied by a preset depth scaling parameter to obtain the depth offset. Obtain the base depth value of each pixel in the texture image, and superimpose the depth offset onto the base depth value to obtain the depth information of each pixel.

7. The method according to claim 1, characterized in that, Before the step of generating a normal map for lighting rendering based on the depth information, the method further includes: The depth map corresponding to the depth information is smoothed.

8. The method according to claim 1, characterized in that, The step of generating a normal map for lighting rendering based on the depth information includes: The depth gradient value of each pixel is determined based on the depth information; The normal vector is constructed based on the depth gradient value, and the normal vector is normalized and mapped to a color space to generate the normal map.

9. A texture generation apparatus, characterized in that, The device includes: A brightness extraction module is used to acquire a texture image of a target two-dimensional object and extract the brightness information of each pixel in the texture image; The normal determination module is used to determine the vertex normal vectors that change with the bone movement based on the skeletal animation data that drives the target 2D object. The lighting determination module is used to determine the lighting intensity of each pixel in the texture image under a preset virtual light source direction based on the vertex normal vector; A depth determination module is used to determine the depth information of each pixel in the texture image based on the brightness information and the illumination intensity. The generation module is used to generate a normal map for lighting rendering based on the depth information.

10. An electronic device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the texture generation method according to any one of claims 1 to 8 by executing the computer instructions.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the texture generation method according to any one of claims 1 to 8.

12. A computer program product, characterized in that, Includes computer instructions, said computer instructions being used to cause a computer to perform the texture generation method according to any one of claims 1 to 8.