Data processing method and device, electronic equipment and readable storage medium
By using noise graph generation functions and periodic functions in game development and computer graphics to process UV coordinates, generate height maps and finally generate normal maps, the problem that the existing technology cannot accurately restore the three-dimensional morphological changes and flow of quicksand is solved, and a more realistic quicksand effect is achieved.
Patent Information
- Application Number
- CN202510143021.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-08
- Publication Date
- 2025-06-13
AI Technical Summary
The prior art is difficult to accurately restore the three-dimensional morphological changes and flow of quicksand in game development and computer graphics, and cannot effectively simulate the graininess and dynamic characteristics of quicksand.
By using the UV coordinates based on the initial map, the noise map generation function is used to generate the target noise map, and the periodic function is used to process the noise map to obtain offset information, and then disturb the UV coordinates to generate a height map, and finally generate a normal map based on the height map.
It realizes the generation of normal maps including height information, which can more realistically restore the flow effect of materials with flow characteristics in the real world, enhancing the dynamic and grainy feeling of quicksand.
Smart Images

Figure CN120147503A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and particularly to a method, device, electronic device, and readable storage medium for processing data. Background Art
[0002] In game development and computer graphics, normal mapping is a technique used to simulate the surface details and textures of real objects. Through normal mapping, the surface of real objects can appear more realistic and three-dimensional.
[0003] Currently, a flow map that controls the UV flow direction is created to perturb the normal map of the original terrain for flow, approximately restoring the dynamics of flowing sand in reality. However, since normal maps mainly simulate the lighting effects of surface details, they do not contain information about the actual height or depth of the surface. Therefore, even if the normal map is perturbed using a flow map, the three-dimensional morphological changes of the flowing sand, such as the undulations and landslides formed by the accumulation of sand grains, cannot be reflected, and the sense of flow and granularity of the flowing sand in the real world cannot be well restored. Summary of the Invention
[0004] In view of this, this application provides a method, device, electronic device, and readable storage medium for processing data, which can restore the flow effect of materials with flow characteristics in the real world.
[0005] In a first aspect, an embodiment of this application provides a method for processing data. The method includes:
[0006] Based on the first UV coordinates of the initial map, use a noise map generation function to generate a target noise map of the initial map;
[0007] Use a first periodic function to process the target noise map to obtain first offset information;
[0008] Use the first offset information to perturb the first UV coordinates of the initial map to obtain second UV coordinates of the initial map;
[0009] Sample the target noise map based on the second UV coordinates to obtain a first height map;
[0010] Generate a normal map based on the first height map.
[0011] In a second aspect, an embodiment of this application provides a device for processing data. The device includes:
[0012] A first generation module, configured to generate a target noise map of the initial map based on the first UV coordinates of the initial map using a noise map generation function;
[0013] A processing module, configured to process the target noise map using a first periodic function to obtain first offset information;
[0014] A perturbation module, configured to perturb the first UV coordinates of the initial texture map using the first offset information to obtain the second UV coordinates of the initial texture map;
[0015] A sampling module, configured to sample the target noise map based on the second UV coordinates to obtain a first height map;
[0016] A second generation module, configured to generate a normal map based on the first height map.
[0017] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0018] A processor; and
[0019] A memory, configured to store a data processing program, and after the electronic device is powered on and runs the program through the processor, execute the method according to the first aspect.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, storing a data processing program, and when the program is run by a processor, execute the method according to the first aspect.
[0021] The method for processing data provided by the present application is based on the first UV coordinates of the initial texture map, generates a target noise map of the initial texture map using a noise map generation function; processes the target noise map using a first periodic function to obtain first offset information; perturbs the first UV coordinates of the initial texture map using the first offset information to obtain the second UV coordinates of the initial texture map; samples the target noise map based on the second UV coordinates to obtain a first height map; generates a normal map based on the first height map. By this method, a normal map including height information is generated to restore the flow effect of materials with flow characteristics in the real world. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the description of the embodiments of the present application. Obviously, the drawings in the following description are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0023] Figure 1 A flowchart of an example of the method for processing data provided by an embodiment of the present application;
[0024] Figure 2 A schematic diagram of a third height map provided by an embodiment of the present application;
[0025] Figure 3 A schematic diagram of a normal map provided by an embodiment of the present application;
[0026] Figure 4 Another flowchart of the method for processing data provided by the embodiment of the present application;
[0027] Figure 5 A schematic structural diagram of the device for processing data provided by the embodiment of the present application;
[0028] Figure 6 A structural block diagram of an electronic device for implementing the method for processing data provided by the embodiment of the present application. Detailed implementation manners
[0029] In the following description, many specific details are set forth to facilitate a thorough understanding of the present application. However, the present application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar generalizations without departing from the connotation of the present application. Therefore, the present application is not limited by the specific implementations disclosed below.
[0030] It should be noted that the terms "first", "second", "third", etc. in the claims, the description and the drawings of the present application are used to distinguish similar objects and are not used to describe a specific order or sequence. Such data can be interchanged under appropriate circumstances so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising", "having" and their variants are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that comprises a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these process, method, product or device.
[0031] It should be understood that in the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "And / or" is merely a description of the association relationship between associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after. "Comprising A, B and / or C" means including any one or any two or all three of A, B and C.
[0032] It should be understood that in the embodiments of the present application, "B corresponding to A", "B corresponding to A relatively", "A corresponding to B relatively" or "B corresponding to A relatively" means that B is associated with A, and B can be determined according to A. Determining B according to A does not mean determining B only according to A, but B can also be determined according to A and / or other information.
[0033] Based on the problems existing in the above related technologies, the embodiments of the present application provide a method, an apparatus, an electronic device, and a readable storage medium for processing data.
[0034] Before elaborating on the embodiments of the present application in detail, the related concepts of the present application will be further introduced first.
[0035] Texture mapping: In game development, texture mapping refers to the process of applying an image or pattern to the surface of a 3D model, which is used to increase the visual details and realism of the model.
[0036] Normal: It refers to the vector perpendicular to the surface of an object, which is used to simulate the lighting effect of a high-polygon model.
[0037] Normal map: It is a 2D texture map used to enhance surface details and simulate lighting effects. It records the direction information of the surface normal at each pixel point to simulate the bumpy texture and tiny details of the surface, so that the object looks more real and three-dimensional during rendering.
[0038] Flow map: It is a 2D texture map used to simulate the surface flow effect. It records the flow direction and speed information of each pixel point on the surface. By sampling and calculating the flow map during the rendering process, the fluid flow effects in different regions can be simulated, making the surface show flow details such as ripples, waves, and droplets, and enhancing the dynamic sense and realism of the scene.
[0039] Texture coordinates: The coordinate positions of individual pixels (texture elements) in a texture image, which are used to locate and process texture data in a shader to ensure accurate sampling and mapping of the texture. Among them, UV coordinates are a type of texture coordinates.
[0040] UV coordinates: A coordinate system used to map a 2D texture to the surface of a 3D model. UV coordinates are a 2D coordinate system, usually represented as (u, v), where u represents the horizontal (lateral) coordinate and v represents the vertical coordinate. The range of UV coordinates is usually from (0, 0) to (1, 1), with the upper left corner being (0, 0) and the lower right corner being (1, 1). Each vertex on the 3D model has a corresponding UV coordinate, and these coordinates tell the rendering engine where to find the color of that vertex on the texture.
[0041] UV flow: It refers to the process in which UV coordinates change dynamically over time or with certain parameters in a shader. This technology is often used to achieve various dynamic effects, such as the simulation of natural phenomena like water flow and clouds.
[0042] Height Map: A grayscale image used to represent the height information of a surface. The grayscale values usually correspond to the height offsets of each point on the surface. A height map can generate normal maps or perform surface bump simulations, affecting the lighting effects during rendering and making the surface appear more three-dimensional and realistic.
[0043] fmod Function: The fmod function is used to calculate the modulo operation (remainder) of floating-point numbers. It is typically used to calculate the remainder obtained when one floating-point number is divided by another. This restricts the time parameter within a predefined period, ensuring that dynamic effects loop within a controllable time interval and avoiding numerical precision issues caused by the unbounded growth of the time parameter.
[0044] Noise Map Generation Function: Common functions for generating noise maps include Perlin Noise and Simplex Noise. These functions can generate various complex noise maps by adjusting parameters, superimposing multiple layers, applying filters, etc., which are used to enhance the realism and details of game scenes, texture maps, etc.
[0045] Lerp (Linear Interpolation) Function: Used for linear interpolation between two values. It is mainly used in data blending processing to smoothly blend the data of the previous frame and the current frame, avoiding sudden changes and ensuring the coherence of dynamic effects. For example, it can achieve smooth blending of the data of the previous frame and the current frame through smooth movement, smooth rotation, and color fade. In mathematics and computer graphics, the lerp function is usually expressed as:
[0046] lerp(a, b, t) = (1 - t) * a + t * b;
[0047] Where a represents the starting value, b represents the ending value, and t represents the interpolation weight.
[0048] Cross Product: The cross product of vectors is an important operation in vector operations. When two vectors are cross-producted, the result is a new vector that is perpendicular to the plane formed by the original vectors. The cross product operation is used to calculate the normal vector, determine the surface bump direction, and affect the lighting and shadow effects.
[0049] Noise Superposition Algorithm: Refers to the process of superimposing multiple noise patterns with different frequencies and amplitudes to generate more complex and detailed textures. By superimposing different levels of noise, various natural phenomena can be simulated, such as the undulations of mountains and the variations in the density of clouds. The noise superposition algorithm usually involves the combination of multiple noise functions, and by adjusting the parameters (such as frequency, amplitude, etc.) of each noise function, the characteristics of the finally generated texture can be controlled.
[0050] Periodic function: It refers to a mathematical function with a fixed period, such as the sin (sine) function and the cos (cosine) function, etc. Through periodic functions, repetitive and regular change patterns can be generated to simulate periodic phenomena in nature, such as undulating waves and flowing effects.
[0051] UV perturbation: It refers to offsetting or changing the original UV coordinates, causing the texture sampling position to change dynamically. Through UV perturbation, the dynamic movement or undulating effect of the texture can be achieved to simulate dynamic phenomena such as the flow and waves on the surface.
[0052] Sampling process: It refers to obtaining the pixel value corresponding to a specific UV coordinate from the texture map, and obtaining height information and normal information in the shader for dynamic calculation and display effects to achieve the dynamic change of the texture.
[0053] Shader: It is a program used to control the graphics rendering process, usually running on the GPU (Graphics Processing Unit). Common shader types include vertex shaders and fragment shaders (pixel shaders), etc., which are used to achieve complex visual effects, such as lighting calculation, texture mapping, dynamic effects, etc., to improve the rendering quality and efficiency. In this application, the shader is responsible for generating and updating the dynamic normal map, and processing the UV perturbation and normal calculation of each pixel.
[0054] Particle system: It is a technology that simulates the movement and interaction of a large number of small particles such as smoke, fire, and raindrops, and is widely used in computer graphics and game development. Through the particle system, the dynamic changes of natural phenomena can be simulated, and complex visual effects can be presented through the coordinated movement of a large number of particles.
[0055] Vector normalization: The process of adjusting the length of a vector to 1 while keeping its direction unchanged, ensuring that the normal vector has a consistent length and guaranteeing the accuracy of lighting calculation.
[0056] Rendering pipeline: A series of processing steps for a graphics rendering engine to generate the final image from 3D models and textures. The dynamic normal map generation method is integrated into the shading stage of the rendering pipeline to apply dynamic surface changes in real time. Among them, ShaderLab is a part of the Unity rendering pipeline. It is a scripting language for writing shader programs. Through ShaderLab, developers can define how materials respond to lighting, color, and other effects to achieve specific visual effects.
[0057] Frame buffer: The memory area that stores the rendering output (such as color and depth information), usually managed by the GPU. It is also used to store the height map and normal map generated for each frame, supporting cross-frame data access and continuous update of dynamic effects.
[0058] Normal vector: A vector perpendicular to the surface, used to describe the surface direction. During the rendering process, the normal vector is used for: Lighting calculation: Determines how light interacts with the surface, affecting brightness and shadow effects. Reflection and refraction: Affects the direction of reflected and refracted light, enhancing the realism of the material. Bumpiness: Simulates subtle surface bumps through normal maps, enhancing visual details without increasing geometric complexity.
[0059] The technical principle of this application lies in the technical method of using normal maps to generate dynamic flow effects (such as quicksand) in the field of computer graphics. A normal map is a texture that stores surface normal vectors. By changing the normal direction of the surface, it can simulate subtle surface bumps and lighting effects without increasing geometric complexity. The core technical principle of this invention is to generate a normal map carrying height information through a noise map generation function driven by a time parameter, a noise superposition algorithm, and a periodic mathematical function, thereby achieving a dynamic flow effect on the surface.
[0060] The technical principle and corresponding technical solutions of this application can be applied to the following scenarios:
[0061] Video games: Enhance the realism of the game environment, such as dynamic sand dunes, flowing desert scenes, moving water surfaces, mudslides, environmental erosion, volcanic lava, and flames, etc., enhancing the player's immersion.
[0062] Virtual reality (VR) and augmented reality (AR): Provide a highly interactive and realistic virtual environment, enabling users to experience a more real and dynamic environment.
[0063] Film and television special effects: Create natural phenomena in movies or animations, such as sandstorms, flowing deserts, volcanic lava flows, etc., improving the quality and realism of visual special effects.
[0064] Architectural visualization: Dynamically display the changes in the natural environment around buildings, such as buildings in the desert, simulating the impact of natural erosion or environmental changes on buildings.
[0065] Simulation training: In simulation training in the military, geology, or environmental science, simulate dynamic terrains and natural phenomena, enhancing the authenticity and effectiveness of training.
[0066] Product design and prototyping: Visualize the performance of products in a dynamic environment, such as demonstrating the stability and interactivity of products on flowing sand or water surfaces.
[0067] Examples of application scenarios are as follows:
[0068] Desert scene in a video game: Scene description: Players explore in the desert, and the sand dunes change continuously over time and with the player's movement.
[0069] Beach experience in virtual reality: A virtual character walks on a virtual beach, feeling the real sense of sand flowing with the steps and the wind blowing the sand.
[0070] Sandstorm effect in film and television animation: Simulate the dynamic flow of a sandstorm through a dynamic normal map. A realistic sandstorm with sand grains flying in the air and covering the ground, enhancing the realism and dynamics of visual effects.
[0071] Of course, the method for processing data provided by the embodiments of the present application can also be applied to other application scenarios according to actual needs, and the present application does not limit this.
[0072] Next, the present application takes the application scenario of implementing the flowing effect of quicksand as an example to illustrate in detail the method for processing data provided by the embodiments of the present application. The method for processing data provided by the embodiments of the present application can be executed by an electronic device, and the electronic device can be a terminal or a server, etc. The terminal can be a terminal device such as a smart phone, a tablet computer, or a laptop computer. The server can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. It can be understood that the present application does not specifically limit the execution entity for executing the method for processing data.
[0073] In an alternative embodiment, when the method for processing data runs on a terminal device, the terminal device stores an application program for implementing the method for processing data. The terminal device interacts with the user through a graphical user interface. The manner in which the terminal device provides the graphical user interface to the user can include various ways. For example, it can be rendered and displayed on the display screen of the terminal device, or the graphical user interface can be presented through holographic projection.
[0074] In an alternative embodiment, when the method for processing data runs on a server, the method can be implemented and executed based on a cloud service system. The cloud service system refers to a service mode based on cloud computing. The cloud service system includes a server and client devices. The running entity and the display screen presenting entity of the application program for implementing the method for processing data are separated. The storage and running of the method for processing data are completed on the server. The display screen presentation for implementing the method for processing data is completed on the client side. The client is mainly used for data reception, sending, and data presentation. For example, the client can be a display device with data transmission function near the user side, such as a mobile terminal, a television, a computer, a personal digital assistant, a head-mounted display device (headset device), etc. However, the electronic device for implementing the method for processing data is the cloud server. The user operates the client to send an instruction to the server. The server controls the running of the method for processing data according to the instruction, encodes and compresses the data such as the display screen corresponding to the method for processing data, returns it to the client through the network. Finally, the client decodes and outputs the display of the screen corresponding to the method for processing data.
[0075] It should be noted that in the embodiments of the present application, the execution entity of the method for processing data can be a terminal device or a server. Among them, the terminal device can be a local terminal device or a client device in the aforementioned cloud service system. The embodiments of the present application do not limit the type of the execution entity.
[0076] The technical solutions of the present application will be described in detail below through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments described below are used to explain the technical solutions of the present application and are not used as a limitation for actual use.
[0077] In the related art, a flow map is created, a flow vector is sampled from the flow map, the offset of the UV coordinates of each pixel is calculated based on the flow vector and time parameters, and the normal map is resampled using the calculated offset to obtain the perturbed normal information. By creating a flow map that controls the UV flow direction to perturb the original terrain's normal map for flow, it approximately restores the dynamics of flowing sand in reality. However, since the flow map is essentially a two-dimensional texture, it guides how surface details "flow" on a two-dimensional plane. However, the behavior of flowing sand is three-dimensional, including phenomena such as volume change, accumulation, and collapse. Since the flow map only provides two-dimensional direction guidance, it cannot accurately represent the behavior of flowing sand at different depth levels, such as the interaction and displacement between particles. That is, it is difficult to accurately describe the characteristics of flowing sand, such as the sense of flow, graininess, and subtle fluctuations of flowing sand, in the way of the related art.
[0078] Moreover, in the related art, a particle system is also used to control a large number of particles to move and interact with each other, simulating the flow and accumulation effects of quicksand. Although the effect of realizing the quicksand effect through the particle system is relatively realistic, due to its excessive performance consumption in real-time rendering, it is generally only realized in offline rendering, resulting in poor scalability in games.
[0079] To solve the problems existing in the related art, an embodiment of the present application provides a method for processing data, as Figure 1 shown Figure 1 is a flowchart of an example of the method for processing data provided by an embodiment of the present application. It should be noted that the steps shown can be executed in a logical order different from that shown in the flowchart of the method.
[0080] This method performs multiple superimpositions and periodic processing on the noise data of the texture map, perturbs the UV coordinates of the texture map, and mixes the height information across frames, thereby showing a dynamic flow texture effect similar to quicksand in the continuously rendered images. The core of this idea is to combine the time factor, the noise map generation function, the noise superposition algorithm, and the periodic function to generate a normal map, and finally visually show details such as flow, fluctuation, and fine particle sense.
[0081] It should be noted that there are various preset shaders provided in the unity engine, but these shaders may not meet the requirements of all projects. Therefore, with the help of HLSL (High Level Shader Language) or CG language, developers can create shaders for realizing the flow effect of quicksand in the unity engine and apply the written shaders to specific application scenarios.
[0082] This method may include the following steps S101 to step S105.
[0083] S101: Based on the first UV coordinates of the initial texture map, use the noise map generation function to generate the target noise map of the initial texture map.
[0084] It should be noted that the initial texture map is a blank texture map, which refers to a texture image without specific patterns or color information in computer graphics and game development. In some games or application programs that support procedural content generation, the blank texture map may be used as the basis for algorithms to generate more complex textures. For example, a program can generate textures of natural landscapes such as quicksand based on the blank texture map.
[0085] The size of the initial texture map can be set according to actual needs, and the present application does not limit this. For example, an initial texture map with a size of 1024*1024 is obtained.
[0086] In 3D computer graphics, UV coordinates are two-dimensional coordinates used to specify the texture mapping positions on the surface of a model. In modern graphics rendering pipelines and shader programming, the UV coordinates of normal maps are passed or calculated through material properties or shader built-in variables.
[0087] In an alternative embodiment, the UV coordinates are passed in through material properties. In this case, the UV coordinates are directly set as part of the material. This is typically done in a 3D modeling software or the material editor of a game / graphics engine.
[0088] In an alternative embodiment, the UV coordinates are obtained through shader built-in variables or calculations. For example, the vertex shader receives the UV coordinates from vertex attributes. Among them, these UV coordinates are the initial state of the texture mapping coordinates and are called the first UV coordinates.
[0089] The first UV coordinates are used to represent the undisturbed UV coordinates. U represents the horizontal coordinate and V represents the vertical coordinate. The first UV coordinates serve as the initial reference coordinates, providing a benchmark for subsequent perturbations and transformations, ensuring the consistency and controllability of texture mapping, and ensuring an initial position reference in subsequent steps. And the fixed input of UV coordinates is a basic feature of the rendering pipeline, with technical feasibility and stability in implementation.
[0090] In this step, the introduction of UV coordinates into the noise map generation function is to be able to sample noise values in a specific texture space and create a procedural texture or terrain based on the UV coordinates.
[0091] In an alternative embodiment, based on the first UV coordinates of the initial texture, a target noise map of the initial texture is generated using the noise map generation function, including:
[0092] Based on the first UV coordinates of the initial texture, time parameters, frequency parameters, and amplitude parameters, a target noise map of the initial texture is generated using the noise map generation function.
[0093] Introducing time parameters into the noise map generation function can create dynamic effects that change over time. By adding a time dimension, static noise patterns can be programmed into animations, making them more vivid and realistic.
[0094] In an alternative embodiment, the time parameter is a value obtained by performing a modulo operation on the initial time parameter.
[0095] The initial time parameter can be the system time, which is obtained through a built-in function provided by the programming language. Among them, the built-in function can be the time.time() function in the Python language.
[0096] The initial time parameter can also be to track time by setting an internal clock or timer in a game engine such as the Unity engine.
[0097] Perform a modulo operation on the initial time parameter to obtain the time parameter: Use the fmod function to perform a modulo operation on the initial time parameter to obtain the time parameter.
[0098] In an optional example, target Time Parameter (time parameter) = fmod(timeParameter (initial time parameter), period), where target Time Parameter is the time parameter, timeParameter is the initial time parameter, and period is a preset period value. Through the modulo operation, the time parameter changes reciprocally between 0 and period, thereby realizing the periodic change of the noise input, making the subsequent generated texture effect repeat or cycle within a certain time interval, ensuring the controllability and regularity of the dynamic texture change, and preventing the time parameter from growing infinitely, resulting in too large a value, loss of precision, or a difficult-to-control periodic effect. And the time parameter is a continuously increasing floating-point number, which is used as the driving force for the dynamic texture change.
[0099] If you want the periodic effect (such as fluctuations) to repeat, you can select a suitable period (such as 10 seconds or shorter) to achieve the loop of the time parameter.
[0100] The fmod function can be directly implemented in the GPU shader language (HLSL / GLSL) or calculated on the CPU side and then passed into the shader.
[0101] To create more complex and natural patterns, multiple noise maps with different frequencies and amplitudes are usually superimposed. This technique is called "fractal noise". It should be noted that by superimposing multiple noise layers with different frequencies and amplitudes, a first noise map is obtained. Each layer is called an "octave", and the sum of all octaves constitutes the final noise map (the first noise map). The frequency and amplitude respectively determine the change rate of each octave and the degree of influence on the final result.
[0102] In an optional embodiment, the frequency parameter includes multiple first frequency parameters, the amplitude parameter includes multiple first amplitude parameters, and each first frequency parameter corresponds to each first amplitude parameter one by one; based on the first UV coordinates, time parameter, frequency parameter, and amplitude parameter of the initial texture, use the noise map generation function to generate the target noise map of the initial texture, including:
[0103] For each first frequency parameter and the corresponding first amplitude parameter, based on the first UV coordinates of the initial texture map and the current time parameter, use the noise map generation function to generate a layer noise map corresponding to the first frequency parameter and the first amplitude parameter; superimpose each layer noise map to obtain a first noise map; obtain the target noise map of the initial texture map based on the first noise map.
[0104] Set the frequency: For each octave, the frequency generally increases or decreases as the octave increases. Higher frequencies mean finer and more frequent changes, while lower frequencies represent larger-scale and smoother changes.
[0105] As an example, the frequency of the 0th octave (octave = 0) is 2^0 = 1; the frequency of the 1st octave (octave = 1) is 2^1 = 2. The frequency of the 2nd octave (octave = 2) is 2^2 = 4, and so on.
[0106] Set the amplitude: For each octave, the amplitude generally increases or decreases as the octave increases. Lower amplitudes mean that the octave contributes less to the final result and are mainly used to add fine details; higher amplitudes will have a greater impact on the overall pattern.
[0107] As an example, the amplitude of the 0th octave (octave = 0) is 0.5^0 = 1; the amplitude of the 1st octave (octave = 1) is 0.5^1 = 0.5; the amplitude of the 2nd octave (octave = 2) is 0.5^2 = 0.25, and so on.
[0108] In an alternative example, the specific settings of the frequency parameter and the amplitude parameter are shown in the following table:
[0109] Frequency parameter Amplitude parameter 1 1 2 0.5 4 0.25
[0110] Table 1
[0111] In an alternative example, generating the first noise map includes the following steps:
[0112] (1) Generate the 0th layer noise map based on the first UV coordinates of the initial texture map, the current time parameter, the first first frequency parameter, and the first first amplitude parameter;
[0113] (2) Generate the 1st layer noise map based on the first UV coordinates of the initial texture map, the current time parameter, the second first frequency parameter, and the second first amplitude parameter, and superimpose the 0th layer noise map and the 1st layer noise map to obtain the superimposed 1st layer noise map;
[0114] (3) Generate the second noise map based on the first UV coordinates of the initial texture map, the current time parameter, the third first frequency parameter, and the third first amplitude parameter, and perform superposition processing on the second noise map and the superposition-processed first noise map to obtain the superposition-processed second noise map. And so on, to obtain the first noise map of the initial texture map.
[0115] In an optional example, call the noise map generation function in the shader, such as a*noise(U*f_i+timeParameter, V*f_i+timeParameter), where a represents the amplitude parameter, U represents the horizontal coordinate, V represents the vertical coordinate, f_i represents the i-th frequency, and timeParameter is the time parameter.
[0116] Obtain the first noise map in the shader using the following formula:
[0117] N(U, V) = a1*noise(U*f1+timeParameter, V*f1+timeParameter)+a2*noise(U*f2+timeParameter, V*f2+timeParameter)+a3*noise(U*f3+timeParameter, V*f3+timeParameter).
[0118] In an optional embodiment, the method further includes:
[0119] Obtain the current time parameter, the second frequency parameter, and the second amplitude parameter; generate the second noise map of the initial texture map based on the first UV coordinates of the initial texture map, the current time parameter, the second frequency parameter, and the second amplitude parameter using the noise map generation function;
[0120] Obtain the target noise map of the initial texture map based on the first noise map, including: performing superposition processing on the first noise map and the second noise map to obtain the target noise map of the initial texture map.
[0121] It should be noted that the setting rules of the second frequency parameter and the second amplitude parameter are different from the setting rules of the above-mentioned first frequency parameter and the first amplitude parameter. Therefore, it is necessary to separately perform superposition processing on the second noise map generated based on the second frequency parameter and the second amplitude parameter and the first noise map to obtain the target noise map of the initial texture map. In this way, textures or terrains with rich detail levels can be built, which helps to more realistically simulate phenomena in nature, such as quicksand, clouds, mountains, rivers, vegetation distribution, etc. Different noise layers can represent different natural forces or temporal changes. By mixing multiple noise maps, this regularity can be broken, making the generated content more random and natural.
[0122] During the actual coloring process, as the time parameter continuously changes, noise changes over time, making the surface of the flowing sand appear to move and change slightly continuously, enhancing the realism and dynamic feeling of the scene. By superimposing noise maps with multiple frequencies and amplitudes, rich texture levels and details can be generated to simulate complex and irregular surface changes in nature.
[0123] In an alternative embodiment, a noise superimposition algorithm can be used to process the noise maps. The noise superimposition algorithm includes at least one or more of the following algorithms: simple superimposition algorithm, average superimposition algorithm, multiplication superimposition algorithm.
[0124] The simple superimposition algorithm is to directly add the pixel values of two or more noise maps. This method can increase the level of detail, but may cause the result value to exceed the expected range (such as 0 to 1), so normalization processing may be required. The average superimposition algorithm is to take the average value of the pixel values of all noise maps. This can keep the output within a certain range and can smoothly mix different noise patterns. The multiplication superimposition algorithm is to use one noise map as the intensity modulator of another noise map, and affect the final result by multiplying their pixel values. This method can make some areas brighter or darker, depending on the specific values of the used noise. It should be noted that the embodiments of the present application can also use other noise superimposition algorithms to process the noise maps, and the present application does not limit this.
[0125] In an alternative example, combinedNoise = (noise1 * w1 + noise2 * w2 + noise3 * w3) / (w1 + w2 + w3). Wherein, combinedNoise is the first noise map, noise1, noise2, and noise3 are multi-layer noise maps, and w1, w2, and w3 are the weights corresponding to the multi-layer noise maps.
[0126] In the embodiments of the present application, high-frequency noise (fine texture) can be superimposed with low-frequency noise (large-scale structure), so that the result has both a gradual change in the overall form and changes in microscopic details. The data processing method of synthesizing multiple layers of noise into an image has clear logic and can achieve hierarchical control and enhancement of surface details. After multiple noises are superimposed, the surface details are richer, and the complex texture characteristics of the flowing sand can be simulated more realistically. Through the synthesized noise map, it lays a foundation for the next periodic function processing and height information extraction. Step S102: Process the target noise map using the first periodic function to obtain the first offset information.
[0127] In an alternative embodiment, the first periodic function is a sine function, and the first offset information may include the first offset of the U coordinate of the initial texture map and the first offset of the V coordinate of the initial texture map.
[0128] In an optional example, the target noise map is processed using the following formula to obtain the first offset information:
[0129] offsetU1=sin(U), offsetV 1=sin(V);
[0130] Among them, offsetU1 is the first offset of the U coordinate of the initial map, sin(U) is the function value obtained by taking the U coordinate of the initial map as the input of the sine function; offsetV is the second offset of the V coordinate of the initial map, sin(V) is the function value obtained by taking the V coordinate of the initial map as the input of the sine function.
[0131] It should be noted that if the offset is large, the sine wave changes more dramatically; if the offset is small, the change will be more gradual. The offset is used to control the level of detail of the terrain. A larger offset can result in more details or a more complex terrain structure.
[0132] In this step, the periodicity of the sine function is used to make the movement of the noise image repeat within a certain period to generate periodicity.
[0133] Step S103: using the first offset information to perturb the first UV coordinates of the initial texture to obtain the second UV coordinates of the initial texture.
[0134] In an optional embodiment, the first UV coordinate of the initial map is disturbed using the following formula to obtain the second UV coordinate of the initial map:
[0135] U_New_1=U_original+offsetU1, V_New_1=V_original+offsetV1;
[0136] Among them, U_New_1 is the second U coordinate, U_original is the first U coordinate, offsetU1 is the first offset of the U coordinate of the initial map, V_New_1 is the second V coordinate, V_original is the first V coordinate, and offsetV is the first offset of the V coordinate of the initial map.
[0137] In this step: By perturbing the first UV coordinates of the initial map, the originally regular noise pattern can be made more random and irregular, thereby increasing the level of detail. When using periodic noise (such as Perlin noise), obvious repeating patterns may appear. By perturbing the UV coordinates, this regularity can be broken to a certain extent, making the generated texture look more natural and disordered. And the perturbation changes over time, which can help create dynamic effects, such as flowing water, floating clouds or other moving objects.
[0138] Step S104: Sample the target noise map based on the second UV coordinates to obtain the first height map.
[0139] Sampling the target noise map based on the second UV coordinates to obtain the first height map means: using the second UV coordinates as an index, extracting the corresponding values from the target noise map, normalizing the sampled values to an appropriate range, and saving or displaying them as a height map to obtain the first height map.
[0140] In this step, due to the perturbation of the UV coordinates, the terrain features become more complex and natural.
[0141] In an optional embodiment, store the first height map in the initial texture map for subsequent graphics processing or game development workflows.
[0142] In an optional embodiment, store the first height map in the form of parameters. Storing the height map in the form of parameters can significantly reduce the data volume without losing too much detail, and is particularly suitable for application scenarios that require real-time generation or dynamic adjustment of terrain, such as video games, simulators, and virtual reality environments.
[0143] In an optional embodiment, use Fourier transform to convert the first height map into coefficients in the frequency domain. The original height map can be approximated with fewer data points. This method is particularly effective for height maps with periodic or repetitive patterns. Of course, the first height map can also be stored in the form of parameters in other ways, and this application does not limit it.
[0144] Step S105: Generate a normal map based on the first height map.
[0145] In an optional embodiment, generating a normal map based on the first height map includes the following steps:
[0146] S1051: Obtain multiple height differences between each pixel point in the first height map and its adjacent pixel points;
[0147] S1052: Determine multiple vector directions pointing from each pixel point to its adjacent pixel points based on the multiple height differences;
[0148] S1053: Perform a cross product calculation on the multiple vector directions to obtain the normal vector of each pixel point;
[0149] S1054: Map the normal vector into the color space to obtain the normal map.
[0150] In step S1051, in an optional embodiment, obtaining multiple height differences between each pixel point in the first height map and its adjacent pixel points includes: taking the pixel point as the center and obtaining multiple height differences of M pixel points adjacent to the pixel point.
[0151] It should be noted that the value of M depends on the number of adjacent pixel points. In an alternative embodiment, the value range of M is 2 - 4.
[0152] Select a pixel point from the first height map as the central pixel point, for example, the pixel point (x, y). Determine the neighborhood range and select at least two pixel points from the surrounding pixel points (x + 1, y), (x - 1, y), (x, y + 1), and (x, y - 1). For the selected central pixel, traverse its M adjacent pixels. This may involve accessing different coordinate positions in the image. For each adjacent pixel, calculate the height difference between it and the central pixel. The height difference can be obtained through a simple subtraction operation: height_difference = center_pixel_height - neighbor_pixel_height, where height_difference represents the height difference, center_pixel_height represents the height value of the central pixel, and neighbor_pixel_height represents the height value of the adjacent pixel. Save all the calculated height differences in a suitable frame buffer, such as an array, a list, or a dictionary, for subsequent use. Repeat the above steps for each pixel point in the first height map until all pixel points are processed.
[0153] In step S1052, in an alternative embodiment, determining multiple vector directions for each pixel point pointing to adjacent pixel points based on multiple height differences includes: determining the direction from the current pixel point to the adjacent pixel point according to the height difference. If the height increases, the vector will point to the adjacent pixel point; if the height decreases, the vector will point to the current pixel point. If the heights of two pixel points are the same, it is possible to choose not to generate a vector or specify a default behavior.
[0154] In an alternative embodiment, use the normalization formula to normalize the vector directions. In this way, it is ensured that all vector lengths are consistent.
[0155] In step S1053, in an alternative embodiment, performing a cross - product calculation on multiple vector directions to obtain the normal vector for each pixel point includes: selecting two non - parallel direction vectors for each pixel point and performing a cross - product operation on the direction vectors to obtain the normal vector.
[0156] In an alternative example, assuming that the pixel point M includes direction vectors corresponding to four adjacent pixel points above, below, left, and right (such as the left direction vector, the right direction vector, the upper direction vector, and the lower direction vector), then the direction vector A is: right direction vector - left direction vector, the direction vector B is: upper direction vector - lower direction vector, and perform a cross - product on the direction vectors A and B.
[0157] In an alternative example, assume that pixel point M includes the direction vectors corresponding to the two adjacent pixel points below and to the left. Then, direction vector A is the left direction vector, direction vector B is the downward direction vector, and a cross product is performed on direction vectors A and B.
[0158] In an alternative example, assume that pixel point M includes the direction vectors corresponding to the two adjacent pixel points above and to the right. Then, direction vector A is the right direction vector, direction vector B is the upward direction vector, and a cross product is performed on direction vectors A and B.
[0159] In an alternative example, assume that pixel point M includes the direction vectors corresponding to the two adjacent pixel points above and to the left. Then, direction vector A is the left direction vector, direction vector B is the upward direction vector, and a cross product is performed on direction vectors A and B.
[0160] In an alternative embodiment, the obtained normal vector is normalized to a unit vector for subsequent calculations.
[0161] In step S1054, in an alternative embodiment, the normal vector is typically a three-dimensional unit vector with its components ranging between [-1, 1]. However, the color channel values of an image typically range between [0, 255] or the normalized [0, 1].
[0162] X component: Map from [-1, 1] to [0, 1], and then multiply by 255 to get [0, 255].
[0163] Y component: Map from [-1, 1] to [0, 1], and then multiply by 255 to get [0, 255].
[0164] Z component: Since the normal vector typically points directly upward (i.e., the Z-axis), the Z component is positive, and it is similarly mapped to [0, 1] or [0, 255].
[0165] The X component is stored in the red channel (R), the Y component is stored in the green channel (G), and the Z component is stored in the blue channel (B). In this way, the normal vector is mapped into the color space to obtain a normal map. Figure 3 A schematic diagram of the normal map provided by the embodiments of the present application.
[0166] In the embodiments of the present application, based on the first UV coordinates of the initial texture map, a target noise map of the initial texture map is generated by using a noise map generation function; the target noise map is processed by using a first periodic function to obtain first offset information; the first UV coordinates of the initial texture map are perturbed by using the first offset information to obtain second UV coordinates of the initial texture map; the target noise map is sampled based on the second UV coordinates to obtain a first height map; and a normal map is generated based on the first height map. By using this method, a normal map including height information is generated to restore the flowing effect of materials with flowing characteristics in the real world.
[0167] In the embodiments of the present application, it is considered that during the operation of a game, to achieve the flowing effect of quicksand, it is often necessary to generate multiple frames of normal maps. When generating the current frame of the normal map, the first height map (specified height map) used to generate the previous frame of the normal map can be combined.
[0168] In an optional embodiment, the method further includes:
[0169] Step S1061: Process the target noise map by using a first periodic function and a second periodic function to obtain second offset information;
[0170] Step S1062: Perturb the first UV coordinates of the initial texture map by using the second offset information to obtain third UV coordinates of the initial texture map;
[0171] Step S1063: Sample a specified noise map based on the third UV coordinates to obtain a second height map;
[0172] Step S1064: Perform a blending process on the first height map and the second height map to obtain a third height map;
[0173] Step S1065: Generate a normal map based on the third height map.
[0174] In step S1061, in an optional embodiment, the first periodic function is a sine function, the second periodic function is a cosine function, and the second offset information may include a second offset amount of the U coordinate of the initial texture map and a second offset amount of the V coordinate of the initial texture map.
[0175] In an optional example, the following formula is used to process the target noise map to obtain third offset information:
[0176] offsetU2 = sin(U), offsetV2 = cos(V);
[0177] Among them, offsetU2 is the second offset of the U coordinate of the initial texture map, and sin(U) is the function value obtained by taking the U coordinate of the initial texture map as the input of the sine function; offsetV2 is the second offset of the V coordinate of the initial texture map, and cos(V) is the function value obtained by taking the V coordinate of the initial texture map as the input of the sine function.
[0178] It should be noted that if the offset is large, the change of the sine wave will be more intense; if the offset is small, the change will be more gentle. The offset is used to control the detail level of the terrain. A larger offset can result in more details or a more complex terrain structure.
[0179] In this step, the periodicity of the sine function and the cosine function is utilized to make the movement of the noise map repeat within a certain period, generating periodicity.
[0180] In step S1062, in an optional embodiment, the following formula is used to perturb the first UV coordinates of the initial texture map to obtain the third UV coordinates of the initial texture map:
[0181] U_New_2 = U_original + offsetU2, V_New_2 = V_original + offsetV2;
[0182] Among them, U_New_2 is the third U coordinate, U_original is the first U coordinate, offsetU2 is the second offset of the U coordinate of the initial texture map, V_New_2 is the third V coordinate, V_original is the first V coordinate, and offsetV2 is the second offset of the V coordinate of the initial texture map.
[0183] In this step: By perturbing the first UV coordinates of the initial texture map, the originally regular noise pattern can be made more random and irregular, thereby increasing the detail level. When using periodic noise (such as Perlin noise), obvious repeating patterns may appear. By perturbing the UV coordinates, this regularity can be broken to a certain extent, making the generated texture look more natural and disordered. And the perturbation changes over time, which can help create dynamic effects, such as flowing water, floating clouds, or other moving objects.
[0184] In step S1063, sampling the specified noise map based on the third UV coordinates to obtain the second height map means: Using the third UV coordinates as an index, extracting the corresponding value from the specified noise map, normalizing the sampled value to a suitable range, and saving or displaying it as a height map to obtain the second height map.
[0185] In this step, due to the perturbation of the UV coordinates, the terrain features become more complex and natural.
[0186] In an alternative embodiment, the method further includes:
[0187] Updating a specified noise map based on the first height map.
[0188] It should be noted that when generating the first frame of normal map, the specified noise map is a height map with pixel values being a preset value. For example, the specified noise map is a height map with pixel values being 1. When generating normal maps for frames greater than 1, the specified noise map is the first height map for generating the previous frame of normal map.
[0189] In an alternative embodiment, the second height map is stored in a second texture map, and the second texture map can be a blank texture map. The size of the second texture map can be set according to actual needs, and the present application does not limit this. For example, a first texture map with a size of 1024*1024 is obtained.
[0190] In an alternative embodiment, the second height map is stored in the form of parameters. Storing the height map in the form of parameters can significantly reduce the data volume without losing too much detail, and is particularly suitable for application scenarios that require real-time generation or dynamic adjustment of terrain, such as video games, simulators, and virtual reality environments.
[0191] In step S1064, in an alternative embodiment, the first height map and the second height map are blended to obtain a third height map, including:
[0192] Using a linear interpolation function to blend the first height map and the second height map according to a preset ratio to obtain the third height map. As Figure 2 shown, Figure 2 This is a schematic diagram of the third height map provided by an embodiment of the present application.
[0193] Among them, the formula of the linear interpolation function is as follows:
[0194] finalHeight = lerp(prevFrameHeight, currentFrameHeight, blendFactor);
[0195] Among them, finalHeight represents the third height map, prevFrameHeight represents the second height map, currentFrameHeight represents the first height map, and blendFactor is the preset ratio, which determines the blending ratio of the first height map and the second height map.
[0196] In an alternative embodiment, the blending ratio of the second height map in the preset ratio is greater than the blending ratio of the first height map. For example, the blending ratio of the second height map to the first height map is: 0.01:0.99.
[0197] Linear interpolation has high stability and controllability. The mixed cross-frame data can achieve a smooth transition of dynamic effects over time, avoiding abrupt jumps, with clear logic and technical feasibility.
[0198] In the embodiments of the present application, by adjusting the mixing ratio, the severity of the quicksand texture change can be controlled. When the mixing ratio is small, the quicksand normal map changes greatly and the texture form updates violently. When the mixing ratio is large, the change is smoother and more gradual.
[0199] In step S1065, in an alternative embodiment, generating a normal map based on the third height map includes the following steps:
[0200] Obtain multiple height differences between each pixel point in the first height map and its adjacent pixel points; determine multiple vector directions pointing from each pixel point to its adjacent pixel points based on the multiple height differences; perform a cross product calculation on the multiple vector directions to obtain the normal vector of each pixel point; map the normal vector into the color space to obtain the normal map.
[0201] It should be noted that in step S1065, the specific process of generating the normal map based on the third height map is similar to the process of generating the normal map based on the first height map in step S105, and the present application will not elaborate here. As Figure 3 shown, Figure 3 is a schematic diagram of the normal map provided by the embodiments of the present application.
[0202] In this embodiment, using the height map mixing technology can create a smoother transition effect, making the change of the quicksand look more natural and smooth. Combined with the normal map, it can further increase the surface details, making the texture and lighting reaction of the quicksand appear more realistic. By adjusting the parameters of the height map (such as the mixing ratio), the dynamic characteristics of the quicksand can be easily changed without having to deeply understand the complex physical simulation principles. In this way, not only can the authenticity and beauty of the game scene be greatly improved, but also a good balance can be achieved between performance and development efficiency.
[0203] Store the first height map in the first texture, store the second height map in the second texture, and store the third height map in the initial texture for subsequent graphics processing or game development workflows. Store the first height map, the second height map, and the third height map in the form of parameters. Storing the height maps in the form of parameters can significantly reduce the data volume without losing too much detail, and is particularly suitable for application scenarios that require real-time generation or dynamic adjustment of terrain, such as video games, simulators, and virtual reality environments.
[0204] The embodiments of the present application also provide a preferred embodiment of a method for processing data. In a real-time rendering engine (such as Unity), these steps are executed in sequence in the fragment shader:
[0205] S401: Define an initial texture map with a resolution of 1024*1024.
[0206] S402: Obtain the first UV coordinates (original UV coordinates) of the initial texture map.
[0207] S403: Obtain the initial time parameter.
[0208] S404: Perform a modulo operation on the initial time parameter to obtain the time parameter.
[0209] S405: Input the current time parameter, multiple first frequency parameters, multiple first amplitude parameters corresponding to the multiple first frequency parameters, and the first UV coordinates of the initial texture map into the noise map generation function to obtain the first noise map of the initial texture map.
[0210] S406: Input the current time parameter, the second frequency parameter, the second amplitude parameter, and the first UV coordinates of the initial texture map into the noise map generation function to obtain the second noise map of the initial texture map.
[0211] S407: Perform a superposition process on the first noise map and the second noise map to obtain the target noise map of the initial texture map.
[0212] S408: Process the first noise map using the first periodic function to obtain the first offset information.
[0213] S409: Perturb the first UV coordinates of the initial texture map using the first offset information to obtain the second UV coordinates of the initial texture map.
[0214] S410: Sample the first noise map based on the second UV coordinates to obtain the first height map.
[0215] Store the first height map in the first texture map in the form of a parameter.
[0216] S411: Process the target noise map using the first periodic function and the second periodic function to obtain the second offset information.
[0217] S412: Perturb the first UV coordinates using the second offset information to obtain the third UV coordinates.
[0218] S413: Sample the specified noise map based on the third UV coordinates to obtain the second height map.
[0219] Store the second height map in the second texture map in the form of a parameter.
[0220] S414: Use the linear interpolation function to mix the first height map and the second height map to obtain the third height map.
[0221] S415: Generate a normal map based on the third height map.
[0222] Store the third height map in the initial map in parametric form.
[0223] Corresponding to the method for processing data provided in the embodiments of the present application, the embodiments of the present application further provide a device 500 for processing data, as Figure 5 shown. The device includes:
[0224] A first generation module 501, configured to generate a target noise map of the initial map by using a noise map generation function based on the first UV coordinates of the initial map;
[0225] A processing module 502, configured to process the target noise map by using a first periodic function to obtain first offset information;
[0226] A perturbation module 503, configured to perturb the first UV coordinates of the initial map by using the first offset information to obtain second UV coordinates of the initial map;
[0227] A sampling module 504, configured to sample the target noise map based on the second UV coordinates to obtain a first height map;
[0228] A second generation module 505, configured to generate a normal map based on the first height map.
[0229] Corresponding to the method for processing data provided in the embodiments of the present application, the embodiments of the present application further provide an electronic device for implementing the method for processing data, as Figure 6 shown. The electronic device includes: a processor 601; and a memory 602, configured to store a program for the method for processing data. After the device is powered on and runs the program for the method for processing data through the processor, the following steps are executed:
[0230] Generate a target noise map of the initial map by using a noise map generation function based on the first UV coordinates of the initial map;
[0231] Process the target noise map by using a first periodic function to obtain first offset information;
[0232] Perturb the first UV coordinates of the initial map by using the first offset information to obtain second UV coordinates of the initial map;
[0233] Sample the target noise map based on the second UV coordinates to obtain a first height map;
[0234] Generate a normal map based on the first height map.
[0235] In an embodiment of the present application, based on the first UV coordinates of the initial texture map, a target noise map of the initial texture map is generated by using a noise map generation function; the target noise map is processed by using a first periodic function to obtain first offset information; the first UV coordinates of the initial texture map are perturbed by using the first offset information to obtain second UV coordinates of the initial texture map; the target noise map is sampled based on the second UV coordinates to obtain a first height map; and a normal map is generated based on the first height map. By this method, a normal map including height information is generated to restore the flow effect of materials with flow characteristics in the real world.
[0236] Corresponding to the method for processing data provided in the embodiment of the present application, the embodiment of the present application further provides a computer-readable storage medium storing a program for the method for processing data. When the program is run by a processor, the following steps are executed:
[0237] Based on the first UV coordinates of the initial texture map, a target noise map of the initial texture map is generated by using a noise map generation function;
[0238] The target noise map is processed by using a first periodic function to obtain first offset information;
[0239] The first UV coordinates of the initial texture map are perturbed by using the first offset information to obtain second UV coordinates of the initial texture map;
[0240] The target noise map is sampled based on the second UV coordinates to obtain a first height map;
[0241] A normal map is generated based on the first height map.
[0242] In an embodiment of the present application, based on the first UV coordinates of the initial texture map, a target noise map of the initial texture map is generated by using a noise map generation function; the target noise map is processed by using a first periodic function to obtain first offset information; the first UV coordinates of the initial texture map are perturbed by using the first offset information to obtain second UV coordinates of the initial texture map; the target noise map is sampled based on the second UV coordinates to obtain a first height map; and a normal map is generated based on the first height map. By this method, a normal map including height information is generated to restore the flow effect of materials with flow characteristics in the real world.
[0243] It should be noted that for the detailed description of the device, electronic device, and computer-readable storage medium provided in the embodiment of the present application, reference may be made to the relevant description of the embodiment of the method for processing data provided in the embodiment of the present application, which will not be elaborated here.
[0244] Although the present application is disclosed above with preferred embodiments, it is not intended to limit the present application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the protection scope of the present application shall be subject to the scope defined by the claims of the present application.
[0245] In a typical configuration, an electronic device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0246] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0247] 1. Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable operations, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0248] 2. Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0249] Although the present application is disclosed above with preferred embodiments, it is not intended to limit the present application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the protection scope of the present application shall be subject to the scope defined by the claims of the present application.
Claims
1. A method for processing data, characterized in that: The method comprises: Based on the first UV coordinate of the initial map, a target noise map of the initial map is generated using a noise map generation function; Processing the target noise image using a first periodic function to obtain first offset information; Using the first offset information, perturbing the first UV coordinate of the initial map to obtain a second UV coordinate of the initial map; Sampling the target noise map based on the second UV coordinates to obtain a first height map; A normal map is generated based on the first height map.
2. The method according to claim 1, characterized in that The method further comprises: Processing the target noise image using the first periodic function and the second periodic function to obtain second offset information; Using the second offset information, perturbing the first UV coordinate of the initial map to obtain a third UV coordinate of the initial map; Based on the third UV coordinate, sampling the specified noise map to obtain a second height map; Mixing the first height map and the second height map to obtain a third height map; A normal map is generated based on the third height map.
3. The method according to claim 2, characterized in that The method further comprises: The specified noise map is updated based on the first height map.
4. The method according to claim 1, characterized in that: The step of generating a target noise map of the initial map by using a noise map generation function based on the first UV coordinate of the initial map comprises: A target noise map of the initial map is generated by using a noise map generation function based on the first UV coordinate, time parameter, frequency parameter and amplitude parameter of the initial map.
5. The method according to claim 4, characterized in that The time parameter is a value obtained by performing a modulo operation on the initial time parameter.
6. The method according to claim 4, characterized in that The frequency parameters include a plurality of first frequency parameters, the amplitude parameters include a plurality of first amplitude parameters, and each of the first frequency parameters corresponds to each of the first amplitude parameters one by one; the target noise map of the initial map is generated by using a noise map generation function based on the first UV coordinate, time parameter, frequency parameter and amplitude parameter of the initial map, including: For each first frequency parameter and the corresponding first amplitude parameter, based on the first UV coordinate of the initial map and the current time parameter, a layer noise map corresponding to the first frequency parameter and the first amplitude parameter is generated using a noise map generation function; each layer noise map is superimposed to obtain a first noise map; A target noise map of the initial map is obtained based on the first noise map.
7. The method according to claim 6, characterized in that The method further comprises: Obtain the current time parameter, the second frequency parameter and the second amplitude parameter; Generate a second noise map of the initial map using a noise map generation function based on the first UV coordinate of the initial map, the current time parameter, the second frequency parameter, and the second amplitude parameter; The step of obtaining a target noise map of the initial map based on the first noise map includes: The first noise map and the second noise map are superimposed to obtain a target noise map of the initial map.
8. The method according to claim 2, characterized in that: The mixing of the first height map and the second height map to obtain a third height map includes: The first height map and the second height map are mixed according to a preset ratio using a linear interpolation function to obtain a third height map.
9. The method according to claim 8, characterized in that The mixing ratio of the second height map in the preset ratio is greater than the mixing ratio of the first height map.
10. The method according to claim 2, characterized in that The method further comprises: storing the first height map in a first map; storing the second height maps in the second textures respectively; The third height map is stored in the initial map.
11. The method according to claim 2, characterized in that The method further comprises: The first height map, the second height map, and the third height map are stored in parameter form.
12. The method according to claim 2, characterized in that: The first periodic function is a sine function, and the second periodic function is a cosine function.
13. The method according to claim 1, characterized in that The generating a normal map based on the first height map comprises: Obtain multiple height differences between each pixel and adjacent pixels in the first height map; Determine multiple vector directions of each pixel pointing to adjacent pixel points based on the multiple height differences; Performing cross product calculation on the multiple vector directions to obtain the normal vector of each pixel point; The normal vector is mapped into a color space to obtain a normal map.
14. A device for processing data, characterized in that: The device comprises: A first generating module, used for generating a target noise map of the initial map by using a noise map generating function based on a first UV coordinate of the initial map; A processing module, configured to process the target noise image using a first periodic function to obtain first offset information; a perturbation module, configured to perturb the first UV coordinate of the initial map by using the first offset information to obtain a second UV coordinate of the initial map; A sampling module, used for sampling the target noise map based on the second UV coordinate to obtain a first height map; The second generating module is used to generate a normal map based on the first height map.
15. An electronic device, characterized in that: include: processor; as well as The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the method according to any one of claims 1 to 13 is executed.
16. A computer-readable storage medium, characterized in that: A data processing program is stored, and the program is run by a processor to execute the method according to any one of claims 1 to 13.
Citation Information
Cited By
Imaging data transmission method and system based on holographic image
CN120428531A