Water surface rendering method and device, equipment and storage medium
Patent Information
- Application Number
- CN202111358143.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-16
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2041-11-16
AI Technical Summary
然而,在对水体进行渲染的过程中,特别是针对海洋这种大面积水体,如果使用至少一个小的法线纹理进行重复渲染,会给人特别规律的感觉,不那么真实;但是如果使用很大的法线纹理进行渲染,载入纹理资源会很慢,影响水面渲染的效率
Smart Images

Figure CN116137051B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer image technology, and in particular to a water surface rendering method, apparatus, device, and storage medium. Background Technology
[0002] With the development of computer graphics technology, the application of 3D visualization simulation technology is becoming increasingly widespread.
[0003] In existing technologies, normal textures are commonly used to make the surfaces of static objects more realistic. Normal textures, also known as bump textures, are a technique in computer graphics used to simulate wrinkles on object surfaces. However, in rendering water, especially large bodies of water like oceans, repeatedly rendering with at least one small normal texture can create a very regular and unrealistic appearance. Conversely, using a large normal texture can slow down texture loading, impacting the efficiency of water surface rendering.
[0004] Therefore, improvements are urgently needed to address the problems existing in the current technology. Summary of the Invention
[0005] This application provides a water surface rendering method, apparatus, device, and storage medium to achieve water surface rendering efficiency while avoiding the storage of a large number of different normal textures.
[0006] In a first aspect, embodiments of this application provide a water surface rendering method, the method comprising:
[0007] Get the base normal texture;
[0008] Based on the base normal texture, at least two derived normal textures are generated; wherein each derived normal texture is different.
[0009] Image rendering is performed based on at least two of the derived normal textures.
[0010] Secondly, embodiments of this application also provide a water surface rendering device, the device comprising:
[0011] The normal texture acquisition module is used to acquire the basic normal texture;
[0012] The normal texture derivation module is used to generate at least two derived normal textures based on the base normal texture; wherein each of the derived normal textures is different.
[0013] An image rendering module is used to render an image based on at least two of the derived normal textures.
[0014] Thirdly, embodiments of this application also provide an electronic device, the device comprising:
[0015] One or more processors;
[0016] Storage device for storing one or more programs.
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement any of the water surface rendering methods provided in the first aspect embodiment.
[0018] Fourthly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the water surface rendering methods provided in the first aspect of the embodiments.
[0019] This application embodiment obtains a base normal texture; generates at least two derived normal textures based on the base normal texture; wherein each derived normal texture is different; and performs image rendering based on the at least two derived normal textures. Through the above technical solution, different derived normal textures can be generated based on the base normal texture without pre-storing various different normal textures, greatly reducing the memory footprint of texture resources. While avoiding the storage of a large number of different normal textures, it also maintains the efficiency of water surface rendering, saves image rendering time, improves image rendering efficiency, and achieves the goal of real-time rendering. Attached Figure Description
[0020] Figure 1 This is a flowchart of a water surface rendering method provided in Embodiment 1 of this application;
[0021] Figure 2 This is a flowchart of a water surface rendering method provided in Embodiment 2 of this application;
[0022] Figure 3 This is a schematic diagram of a basic normal texture provided in Embodiment 2 of this application;
[0023] Figure 4 This is a schematic diagram of generating a derived normal texture based on a target random sampling function A, provided in Embodiment 2 of this application;
[0024] Figure 5 This is a schematic diagram of generating a derived normal texture based on a target random sampling function B, provided in Embodiment 2 of this application;
[0025] Figure 6 This is a schematic diagram of generating a derived normal texture based on a target random sampling function C, provided in Embodiment 2 of this application;
[0026] Figure 7 This is a flowchart of a water surface rendering method provided in Embodiment 3 of this application;
[0027] Figure 8 This is a schematic diagram of a target normal texture image provided in Embodiment 3 of this application;
[0028] Figure 9 This is a schematic diagram of a water surface after rendering, provided in Embodiment 3 of this application;
[0029] Figure 10 This is a schematic diagram of a water surface rendering device provided in Embodiment 4 of this application;
[0030] Figure 11 This is a schematic diagram of an electronic device provided in Embodiment 5 of this application. Detailed Implementation
[0031] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit its scope. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present application are shown in the accompanying drawings.
[0032] Before discussing the exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of these steps can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the steps can be rearranged. The process can be terminated when its operation is complete, but may also have additional steps not included in the figures. The process can correspond to a method, function, procedure, subroutine, subroutine, etc.
[0033] Example 1
[0034] Figure 1 This is a flowchart illustrating a water surface rendering method provided in Embodiment 1 of this application. This embodiment is applicable to image rendering based on a base normal texture. The method can be executed by a water surface rendering device, which can be implemented in software and / or hardware and specifically configured in an electronic device, such as a mobile terminal or a fixed terminal.
[0035] See Figure 1 The water surface rendering method provided in this application includes:
[0036] S110, Obtain the basic normal texture.
[0037] Among them, the normal texture, also known as the bump texture, shows the details of the undulations on the surface of an object. This normal texture can be the normal texture of objects such as ceramic tiles, clothing, and water surfaces.
[0038] In this embodiment, the base normal texture can typically be a water ripple normal texture, used to create a water ripple effect.
[0039] Understandably, a normal texture can be thought of as a texture image. The normal texture stores the normal vector of each pixel. In a undulating water surface, the normal vector of each pixel is different, and the normal texture shows the details of the undulations of the water surface.
[0040] In this embodiment, the base normal texture can be obtained from a texture database. Specifically, it can be randomly obtained from the texture database, or it can be obtained from the texture database according to a preset selection rule. The preset selection rule can be based on user input data such as keyword descriptions, matching base normal textures of a set category from the texture database. The set category can be a ripple type.
[0041] Optionally, the number of basic normal textures is at least one; different basic normal textures have different texture types.
[0042] The texture types can include large ripple type, medium ripple type and small ripple type.
[0043] Specifically, one type of normal texture can be obtained from the large ripple type, medium ripple type, and small ripple type as the base normal texture; or, at least one different type of normal texture can be obtained from the large ripple type, medium ripple type, and small ripple type as the base normal texture; or, three different types of normal textures can be obtained from the large ripple type, medium ripple type, and small ripple type as the base normal texture.
[0044] Understandably, in order to ensure the diversity of normal textures, different types of normal textures can be obtained simultaneously as the base normal textures to improve the realism of image rendering.
[0045] S120. Generate at least two derived normal textures based on the base normal texture; wherein each derived normal texture is different.
[0046] In this embodiment, the different derived normal textures ensure the diversity of derived normal textures.
[0047] Optionally, at least two derived normal textures can be generated based on the base normal texture and a preset normal texture generation rule.
[0048] The preset normal texture generation rule can be generated through texture operations between basic normal textures; alternatively, it can also be generated through texture operations between basic normal textures and intermediate normal textures. Texture operations include addition, subtraction, multiplication, and division, and the intermediate normal textures can be preset according to actual needs.
[0049] It should be noted that the preset normal texture generation rules proposed above are not the only generation rules. Of course, other generation rules can also be used to generate textures according to actual needs, and all of these are within the protection scope of this invention.
[0050] In this embodiment, since the derived normal texture does not need to be pre-stored, it can be generated in real time based on the basic normal texture. Therefore, during image rendering, it is not necessary to load a large amount of texture resources to obtain a variety of different normal textures, which can meet the needs of image rendering and greatly improve rendering efficiency.
[0051] In some embodiments, a derived normal texture can also be generated based on a target random sampling function.
[0052] Specifically, at least two derived normal textures can be generated by texture sampling of the base normal texture based on at least two different target random sampling functions; wherein the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture mapping, and the dependent variable is the texture coordinates of the base normal texture.
[0053] S130. Render the image based on at least two derived normal textures.
[0054] Specifically, when the base normal texture is the normal texture of water ripples, the image being rendered is the water ripples on the water surface.
[0055] In this embodiment, at least two derived normal textures can be superimposed to obtain a target normal texture, and image rendering can be performed based on the target normal texture. Specifically, for each pixel to be rendered, at least two derived normal textures at the pixel location can be superimposed to obtain a target normal texture, and image rendering can be performed based on the superimposed normal texture.
[0056] In some embodiments, image rendering can also be performed based on the base normal texture and the derived normal texture.
[0057] It is understandable that the base normal texture, as the normal texture of the water ripple, can also create a water ripple effect. Therefore, when the derived normal texture is different from the base normal texture, image rendering can be performed simultaneously based on both the base normal texture and the derived normal texture to improve the realism of the image rendering.
[0058] This application embodiment obtains a base normal texture; generates at least two derived normal textures based on the base normal texture; wherein each derived normal texture is different; and performs image rendering based on the at least two derived normal textures. Through the above technical solution, different derived normal textures can be generated based on the base normal texture without pre-storing various different normal textures, greatly reducing the memory footprint of texture resources. While avoiding the storage of a large number of different normal textures, it also maintains the efficiency of water surface rendering, saves image rendering time, improves image rendering efficiency, and achieves the goal of real-time rendering.
[0059] Example 2
[0060] Figure 2 This is a flowchart of a water surface rendering method provided in Embodiment 2 of this application. This embodiment is an optimization of the above scheme based on the above embodiment.
[0061] Furthermore, the operation "generate at least two derived normal textures based on the base normal texture" is refined to "perform texture sampling on the base normal texture based on at least two different target random sampling functions to generate the at least two derived normal textures; wherein, the independent variable of the target random sampling function is the vertex coordinates mapped by the derived normal texture, and the dependent variable is the texture coordinates of the base normal texture," so as to clarify the generation process of the derived normal textures.
[0062] The explanations of terms that are the same as or corresponding to those in the above embodiments will not be repeated here.
[0063] See Figure 2 The water surface rendering method provided in this embodiment includes:
[0064] S210, Obtain the basic normal texture.
[0065] S220. Based on at least two different target random sampling functions, perform texture sampling on the base normal texture to generate at least two derived normal textures.
[0066] The target random sampling function can be a pre-set random sampling function according to actual needs. The independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture.
[0067] In this embodiment, the target random sampling function can be selected from a random sampling function library. The random sampling function library pre-stores at least two different random sampling functions, and these functions can be configured with different sampling periods and directions to sample the basic normal texture, thus forming various different random sampling functions.
[0068] Optionally, the step of performing texture sampling on the base normal texture according to at least two different target random sampling functions to generate the at least two derived normal textures includes: obtaining the calculation results of each of the at least two different target random sampling functions and the vertex coordinates to be mapped in the derived normal textures, wherein the calculation results include at least two different texture coordinates; performing texture sampling on the base normal texture according to the at least two different texture coordinates to obtain at least two different texture sampling results; and generating the at least two derived normal textures according to the at least two different texture sampling results; wherein the texture sampling result is the normal texture at the vertex coordinate position to be mapped in the derived normal texture.
[0069] In this embodiment, the derived normal texture can be a derived normal texture of known size. For each point, i.e. pixel, in the derived normal texture, the normal vector at the vertex coordinate position corresponding to that point needs to be determined one by one.
[0070] It's important to note that a texture is an image, measured in pixels, with each pixel corresponding to a vertex. For example, if a texture contains N pixels, then those N pixels can correspond to N vertices.
[0071] Specifically, each pixel in the derived normal texture can be sampled in the already acquired base normal texture according to a preset sampling method, such as sampling from left to right or from top to bottom.
[0072] Understandably, generating derived normal textures through a target random sampling function is simpler, more convenient, and more operable.
[0073] Optionally, at least two different target random sampling functions can be generated based on the template random sampling function according to a preset texture offset value and different sampling coefficients; wherein the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture.
[0074] The preset texture offset value represents the offset value of the sampled texture, and the preset texture offset value can be determined in advance according to actual needs.
[0075] In this embodiment, at least one sampling coefficient can be set in the template random sampling function.
[0076] The sampling coefficients can include offset coefficients, which can adjust the preset texture offset value. Specifically, the offset coefficients are used to represent the offset of the normal texture. The offset coefficients can take values of 0 and ±1. An offset coefficient of 0 indicates no offset, an offset coefficient of 1 indicates an offset, and the ± sign indicates the direction of the offset.
[0077] Understandably, by selecting different sampling coefficients in the template random sampling function, different target random sampling functions can be obtained, which is simpler, more convenient, and more operable.
[0078] In this embodiment, the template random sampling function can be predetermined based on the specific object to be rendered.
[0079] Optionally, the formula for calculating the template random sampling function can be:
[0080]
[0081] Wherein, PosX represents the vertex x-coordinate of the derived normal texture map, PosY represents the vertex y-coordinate of the derived texture map, u is the texture x-coordinate of the base normal texture, v represents the texture y-coordinate of the base normal texture, animation represents the preset texture offset value; K and Q represent sampling coefficients.
[0082] Specifically, K is the offset coefficient, used to adjust the preset texture offset value; Q is a natural number greater than 0.
[0083] In some embodiments, Q can also be explicitly defined as the product of the vertex range covered by the base normal texture and the repetition factor, that is, the calculation formula of the template random sampling function can be further defined as:
[0084]
[0085] Where `repeat` represents the vertex range covered by the base normal texture; `W` represents the repetition factor, used to double the coordinates of the base normal texture. In this embodiment, the above calculation formula can be used as a template random sampling function.
[0086] Specifically, animation = rate * times, where times represents the number of animations; rate = repeat / M, where M is a constant, such as M = 512, and rate represents the rate of change; the animation value range is [0, repeat]. In this embodiment, the derived normal texture is generated through a template random sampling function. This can be understood as retrieving a basic normal texture from the texture database and then processing it through the template random sampling function to generate at least two derived normal textures.
[0087] Obviously, the derived normal textures are not actually stored. This solves the problem of storing a large number of different normal textures and makes the acquisition of normal textures more flexible, rather than being limited to obtaining normal textures from a texture database.
[0088] For example, taking the template random sampling function mentioned above, the offset coefficient K in the random sampling function of u can be set to 0, meaning no texture offset is performed, and the repetition factor W can be set to 1, meaning the calculated texture coordinates are not doubled; if the offset coefficient and repetition factor of the random sampling function of v are set to be consistent with u, then the generated target random sampling function A can be expressed as:
[0089] u=(PosX) / repeat, v=(PosY) / repeat;
[0090] Here, we assume the base normal texture is an 8x8 image. Figure 3 An example diagram of a basic normal texture is provided. The values of PosX and PosY range from 0 to 8. When repeat is set to 8, the texture coordinates u and v of the derived normal texture range from 0 to 1.
[0091] By sampling the 8x8 base normal texture according to the target random sampling function A, a new derived normal texture can be generated. For example, see [link to example]. Figure 4 An exemplary schematic diagram is given for generating a derived normal texture based on a target random sampling function A. In the diagram, the horizontal direction is the sampling period of the X-axis, and the vertical direction is the sampling period of the Y-axis. The texture coordinate pair (u, v) formed by texture coordinates u and v can sample the entire texture.
[0092] For example, continuing with the template random sampling function mentioned above, we can set the offset coefficient K in the random sampling function of u in the template random sampling function to 1, perform positive texture offset, and set the repetition factor W to 1; set the offset coefficient K in the random sampling function of v in the template random sampling function to 0, do not perform texture offset, and set the repetition factor W to 1. Then the generated target random sampling function B can be expressed as:
[0093] u=(PosX+animation) / repeat, v=(PosY) / (W*repeat);
[0094] Among them, continue to be Figure 3Taking the basic normal texture as an example, if we set `animaiton` to 1 and `repeat` to 8, then the value of `(PosX + animaiton)` will be between 1 and 9. Therefore, the value of `u` will range from 1 / 8 to (1 + 1 / 8). When the texture coordinates are greater than 1, the normal texture will repeat. Therefore, the entire sampled image is an 8*16 texture, which means... Figure 3 The normal texture is obtained by repeating along the X-axis.
[0095] Based on the target random sampling function B, sampling the 8x8 base normal texture generates a new derived normal texture. Compared to the derived normal texture generated based on the target random sampling function A, the value range of v remains unchanged (0-1), while the value range of u changes to 1 / 8 to (1+1 / 8). Because the value ranges of texture coordinates u and v are different, the sampling area changes. The final sampling area can be found in [reference needed]. Figure 5 An exemplary diagram illustrating the generation of derived normal textures based on a target random sampling function B is provided. Clearly, Figure 5 The sampling results shown in the figure are consistent with Figure 4 The sampling results shown are different.
[0096] For example, the offset coefficient K in the random sampling function of u in the template random sampling function can be set to 0, and the repetition factor W can be set to 0.5; the offset coefficient K in the random sampling function of v in the template random sampling function can be set to 0, and the repetition factor W can be set to 1. Then the generated target random sampling function C can be expressed as:
[0097] u=(PosX) / (0.5*repeat), v=(PosY) / repeat;
[0098] Where PosX, PosY, and repeat remain constant, the value of u is 0 / 8, 2 / 8…16 / 8, with the coordinate range of u being 0 to 2, and the coordinate range of v being 0 to 1. When the value of u is greater than 1, an 8*16 normal texture will be sampled, and the sampling frequency is intervalized. The final sampled area can be found in [reference needed]. Figure 6 An exemplary diagram illustrating the generation of derived normal textures based on a target random sampling function C is provided. Clearly, Figure 6 The sampling results shown in the figure are consistent with Figure 4 and Figure 5 The sampling results shown are all different.
[0099] It is understandable that by setting different offset coefficients and / or repetition factors, different target random sampling functions can be obtained. By sampling the base normal texture based on different target random sampling functions, different derived normal textures can be obtained.
[0100] In some embodiments, typically, multiple different derived normal textures can be generated based on only one base normal texture by sampling the base normal texture using multiple different target random sampling functions.
[0101] S230. Render the image based on at least two derived normal textures.
[0102] In this embodiment, based on the basic normal texture, a variety of different derived normal textures are derived. When rendering the water surface based on the generated derived normal textures, the effect of water surface ripples can be created according to the random changes of the normal texture on the water surface.
[0103] Based on the above embodiments, this application clarifies the generation process of derived normal textures. According to at least two different target random sampling functions, texture sampling is performed on the base normal texture to generate the at least two derived normal textures. The independent variable of the target random sampling function is the vertex coordinates mapped by the derived normal textures, and the dependent variable is the texture coordinates of the base normal texture. Through this technical solution, at least two different derived normal textures are generated according to at least two different target random sampling functions, making the determination process of derived normal textures simpler, more convenient, and more operable. Image rendering is performed based on the derived normal textures, saving storage space for normal textures and increasing logical control over water ripples.
[0104] Example 3
[0105] Figure 7 This is a flowchart of a water surface rendering method provided in Embodiment 3 of this application. This embodiment is an optimization of the above scheme based on the above embodiments.
[0106] Furthermore, the operation "perform image rendering based on at least two derived normal textures" is refined to "for each vertex in the preset texture mapping vertex range value, superimpose at least two derived normal textures generated corresponding to the vertex coordinate position to obtain the target normal texture of the vertex; combine the target normal textures corresponding to different vertex coordinate positions according to different vertex coordinate positions to obtain the target normal texture image; and perform image rendering based on the target normal texture image," so as to clarify the image rendering process.
[0107] The explanations of terms that are the same as or corresponding to those in the above embodiments will not be repeated here.
[0108] See Figure 7 The water surface rendering method provided in this embodiment includes:
[0109] S310, Obtain the basic normal texture.
[0110] S320. Based on at least two different target random sampling functions, sample the base normal texture to generate at least two derived normal textures.
[0111] In this embodiment, the following template random sampling function is used to generate the target random sampling function.
[0112]
[0113] Specifically, OpenGL (Open Graphics Library) can be used for image rendering. Before image rendering, K and W are set, and during the image rendering process, the specific sizes of animation and repeat are set in real time.
[0114] In this embodiment, four different target random sampling functions can be generated by setting four different offset coefficients and repetition factors; by sampling the base normal texture according to the four different target random sampling functions, four different derived normal textures can be generated.
[0115] In some embodiments, the target random sampling function can be generated by randomly determining the offset coefficient and the repetition factor.
[0116] For example, corresponding numerical libraries can be set up in advance for the offset coefficient and the repetition factor, and the offset coefficient and the repetition factor can be determined by randomly sampling from the numerical library, thereby realizing the determination of the target random sampling function.
[0117] S330. For each vertex in the preset texture mapping vertex range value, superimpose at least two derived normal textures generated corresponding to the vertex coordinate position to obtain the target normal texture of the vertex.
[0118] In this embodiment, considering the physical principle of water waves, it is the superposition of multiple different waves. The superposition of waves is actually the superposition of the normal vectors of the waves, and the normal vectors of the waves can be obtained from the normal texture.
[0119] Therefore, in order to achieve different normal vectors on the water surface at different locations and times, n normal vectors can be superimposed, which can be understood as the superposition of n normal textures, that is, n different normal textures are needed; the superimposed normal vector is used as the normal vector for the final drawing of water ripples, which is equivalent to the superposition of n normal vectors at a certain point on the image.
[0120] S340. Based on the coordinate positions of different vertices, combine the target normal textures corresponding to the coordinate positions of different vertices to obtain the target normal texture image.
[0121] In this embodiment, image rendering can be performed based on the target normal texture image. For example, see [link to relevant documentation]. Figure 8 An exemplary schematic diagram of a target normal texture image is provided.
[0122] S350: Render the image based on the target normal texture image.
[0123] Specifically, during the image rendering process, a fragment shader can be designed. Based on the target normal texture image, the fragment shader can determine the color value of each pixel and perform image rendering, thereby realizing the depiction of water ripples.
[0124] Optionally, the step of rendering the image based on the target normal texture image includes: determining the normal direction based on the target normal texture image; determining the reflected color value and the specular highlight color value based on the normal direction and the incident light direction, respectively; and rendering the image based on the reflected color value and the specular highlight color value.
[0125] The light incident direction is a preset light incident direction, and the color value of the light can also be set.
[0126] In this embodiment, the direction of light reflection can be determined based on the normal direction and the direction of light incidence; the reflected color value can be determined based on the direction of light incidence and the direction of light reflection. The reflected color value determines the brightness of the object's surface; the closer the direction of light incidence and the direction of light reflection are, the brighter the object, and vice versa.
[0127] Optionally, determining the specular highlight color value based on the normal direction and the incident light direction includes: determining the light reflection direction based on the normal direction and the incident light direction; and determining the specular highlight color value based on the light reflection direction and a preset viewing direction.
[0128] The preset observation direction refers to the visual direction of the human eye, that is, the direction of the line connecting the human eye and each pixel in the water surface. The preset observation direction can be set according to the actual situation.
[0129] In this embodiment, the intensity of the specular highlight is determined by the angle between the direction of light reflection and the preset observation direction; the smaller the angle, the more obvious the highlight.
[0130] It is understandable that the normal texture of the water surface changes at different times, and the normal vector changes accordingly. Thus, with the incident light direction remaining unchanged, the change in the normal vector leads to changes in the reflected color value and the specular highlight color value, making the water surface appear brighter or darker at different times, thus creating a undulating effect.
[0131] Optionally, the step of rendering the image based on the reflected color value and the specular highlight color value includes: spatially sampling a preset skybox according to the direction of light reflection to obtain a sky color value; and rendering the image based on the reflected color value, the specular highlight color value, and the sky color value.
[0132] The skybox is a cube containing six textures, which can be pre-defined and are based on real image textures. Spatial sampling of the skybox is achieved by using the direction of light reflection to hit the skybox. That is, using the reflection vector of the light, the texture hit by the reflection vector is drawn on the water surface, so that the water surface reflects the sky.
[0133] Understandably, to enhance the detail of the water surface, the skybox sampling could be increased, allowing the water surface to reflect the details of the sky, making the water surface more realistic.
[0134] In some embodiments, during the OpenGL image rendering process, an ambient light, also known as a base color value, can be preset, represented by AmbientColor. For example, AmbientColor can be set to RGB(132, 214, 232).
[0135] Based on the four different target random sampling functions determined in step S320, the vertex coordinates to be mapped in the derived normal texture are substituted into the target random sampling functions to obtain the calculation results of each target random sampling function. That is, four different base normal texture coordinates can be calculated. Based on the four different texture coordinates, texture sampling is performed on the base normal texture to obtain four different texture sampling results; correspondingly, four derived normal textures can be generated.
[0136] Specifically, the basic normal texture can be sampled using the OpenGL built-in 2D texture sampling function `texture2D`, which samples the corresponding normal vectors. Four target random sampling functions can respectively obtain four derived normal vectors: `normal1`, `normal2`, `normal3`, and `normal4`.
[0137] Then, according to step S330, these four derived normal vectors can be superimposed to obtain the target normal vector normal at a certain vertex, i.e., pixel.
[0138] It is important to note that during the calculation of the target normal vector, since the target normal texture stores color values with a range of (-1, 1), while the calculated target normal vector has a range of (0, 1), it is necessary to multiply by 2 and then subtract 1 to map (0, 1) to (-1, 1).
[0139] In this embodiment, the target normal textures corresponding to different vertex coordinate positions can be combined according to the coordinate positions of different vertices to obtain a target normal texture image, and then the image can be rendered according to the target normal texture image.
[0140] After obtaining the target normal texture image, the reflection color value can be calculated, represented by `DiffuseColor`. First, the reflection intensity needs to be calculated. The reflection intensity can be calculated based on the angle between the normal direction and the incident light direction, specifically by calculating the dot product of the normal vector and the incident light vector. The incident light vector can be obtained by subtracting the vertex coordinates from the point light source position and then normalizing them. With both the normal vector and the incident light vector available, the reflection intensity can be calculated using the OpenGL built-in dot product function `dot(vecx, vecy)`. Finally, multiplying the reflection intensity by the illumination color value `LightColor` yields the reflection color value.
[0141] While calculating the reflected light color value, the specular highlight color value can also be calculated, denoted by SpecColor. First, the specular highlight intensity needs to be calculated. This calculation requires two vectors: the reflected light vector (i.e., the illumination reflection vector) and the view vector. The reflected light vector uses the OpenGL built-in `reflect(vecl, vecN)` function, which calculates the reflected light vector based on the incident vector and the normal vector. Since the incident and normal vectors are already calculated during the reflected light vector calculation, the reflected light vector `ReflecDir` can be directly calculated using the `reflect` function. The view vector requires the vertex coordinates obtained by subtracting the difference from the eye position in world coordinates, normalizing them to obtain `EyeDir`, and then performing a dot product between `ReflecDir` and `EyeDir` to calculate the angle `spec` between the reflected and view vectors. Finally, a power function is used to calculate the specular highlight intensity `fspec`. fspec = pow(spec, 32), where 32 is the reflectivity of water. The higher the reflectivity of an object, the stronger its ability to reflect light, the less it scatters, and the smaller the highlight will be. The specular highlight color value can be obtained by multiplying the specular highlight intensity by the color value of the light source, LightColor, SpecColor = LightColor * fspec.
[0142] After calculating the specular highlight color value, the sky color value, denoted as SkyColor, also needs to be calculated. Skybox reflection is then calculated to simulate a reflection effect. As explained earlier, the skybox requires a vector to hit the box, and then SkyColor is sampled. This vector uses the direction of light reflection, which is the RefinecDir vector obtained when calculating the specular highlight color value. Skybox sampling requires using the OpenGL built-in sampling function TextureCube(samplerCube, coord). The TextureCube sampling function differs from 2D texture sampling functions.
[0143] Finally, all the previously calculated colors, including the base color value, the reflected color value, the specular highlight color value, and the sky color value, are combined to calculate the final color of the rendered image. The final color is: AmbientColor + DiffuseColor + SpecColor + SkyColor.
[0144] For example, see Figure 9 An example diagram showing the completed water surface rendering.
[0145] Based on the above embodiments, this application clarifies the image rendering process by superimposing at least two derived normal textures to obtain a target normal texture image; image rendering is then performed based on the target normal texture image. Through this technical solution, image rendering is performed on a target normal texture image generated by superimposing multiple different derived normal textures, saving storage of normal textures and increasing logical control over water ripples, resulting in a more realistic image rendering effect.
[0146] Example 4
[0147] Figure 10 This is a schematic diagram of a water surface rendering device provided in Embodiment 4 of this application. See also... Figure 10 This application provides a water surface rendering device, which includes: a normal texture acquisition module 410, a normal texture derivation module 420, and an image rendering module 430.
[0148] Normal texture acquisition module 410 is used to acquire the basic normal texture;
[0149] The normal texture derivation module 420 is used to generate at least two derived normal textures based on the base normal texture; wherein each of the derived normal textures is different.
[0150] Image rendering module 430 is used to perform image rendering based on at least two of the derived normal textures.
[0151] This application embodiment obtains a base normal texture; generates at least two derived normal textures based on the base normal texture; wherein each derived normal texture is different; and performs image rendering based on the at least two derived normal textures. Through the above technical solution, different derived normal textures can be generated based on the base normal texture without pre-storing various different normal textures, greatly reducing the memory footprint of texture resources. While avoiding the storage of a large number of different normal textures, it also maintains the efficiency of water surface rendering, saves image rendering time, improves image rendering efficiency, and achieves the goal of real-time rendering.
[0152] Furthermore, the normal texture derivation module 420 includes:
[0153] The normal texture derivation submodule is used to reorganize the local texture regions of the base normal texture to generate at least two derived normal textures.
[0154] Furthermore, the normal texture derivation module 420 includes:
[0155] The normal texture sampling submodule is used to perform texture sampling on the basic normal texture according to at least two different target random sampling functions to generate the at least two derived normal textures;
[0156] Wherein, the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture.
[0157] Furthermore, the normal texture sampling submodule includes:
[0158] The texture coordinate calculation unit is used to obtain the calculation results of each of the at least two different target random sampling functions and the vertex coordinates to be mapped in the derived normal texture, wherein the calculation results include at least two different texture coordinates;
[0159] A texture sampling unit is used to perform texture sampling on the basic normal texture based on the at least two different texture coordinates to obtain at least two different texture sampling results;
[0160] A normal texture derivation unit is used to generate at least two derived normal textures based on the at least two different texture sampling results; wherein the texture sampling result is the normal texture at the vertex coordinate position to be mapped in the derived normal texture.
[0161] Furthermore, the device also includes:
[0162] The sampling coefficient generation submodule is used to generate at least two different target random sampling functions based on the template random sampling function, according to the preset texture offset value and different sampling coefficients.
[0163] Wherein, the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture.
[0164] Furthermore, the template random sampling function is calculated as follows: Wherein, PosX represents the vertex x-coordinate of the derived normal texture map, PosY represents the vertex y-coordinate of the derived texture map, u is the texture x-coordinate of the base normal texture, v represents the texture y-coordinate of the base normal texture, animation represents the preset texture offset value, and K and Q represent sampling coefficients.
[0165] Furthermore, the number of basic normal textures is at least one; different basic normal textures have different texture types.
[0166] Furthermore, the image rendering module 430 includes:
[0167] The texture overlay submodule is used to overlay at least two derived normal textures corresponding to the coordinate position of each vertex in the preset texture mapping vertex range value to obtain the target normal texture of the vertex.
[0168] The normal texture generation submodule is used to combine the target normal textures corresponding to different vertex coordinate positions to obtain the target normal texture image based on the coordinate positions of different vertices.
[0169] The image rendering submodule is used to perform image rendering based on the target normal texture image.
[0170] Furthermore, the image rendering submodule includes:
[0171] The normal direction determination unit is used to determine the normal direction based on the target normal texture image;
[0172] The color value determination unit is used to determine the reflected color value and the specular highlight color value according to the normal direction and the incident light direction, respectively.
[0173] An image rendering unit is used to render an image based on the reflected color value and the specular highlight color value.
[0174] Furthermore, the color value determination unit includes:
[0175] The reflection direction determination subunit is used to determine the light reflection direction based on the normal direction and the incident light direction;
[0176] The specular highlight color value determination subunit is used to determine the specular highlight color value based on the light reflection direction and the preset observation direction.
[0177] Furthermore, the image rendering unit includes:
[0178] The sky color value determination subunit is used to perform spatial sampling on a preset skybox according to the direction of light reflection to obtain the sky color value;
[0179] The image rendering subunit is used to perform image rendering based on the reflected color value, the specular highlight color value, and the sky color value.
[0180] The water surface rendering apparatus provided in this application embodiment can execute the water surface rendering method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects of the method execution.
[0181] Example 5
[0182] Figure 11 This is a structural diagram of an electronic device provided in Embodiment 5 of this application. Figure 11 A block diagram is shown of an exemplary electronic device 512 suitable for implementing embodiments of the present application. Figure 11 The electronic device 512 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0183] like Figure 11 As shown, electronic device 512 is represented in the form of a general-purpose computing device. The components of electronic device 512 may include, but are not limited to: one or more processors or processing units 516, system memory 528, and bus 518 connecting different system components (including system memory 528 and processing unit 516).
[0184] Bus 518 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MCA) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0185] Electronic device 512 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 512, including volatile and non-volatile media, removable and non-removable media.
[0186] System memory 528 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 530 and / or cache memory 532. Electronic device 512 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 534 may be used to read and write non-removable, non-volatile magnetic media (…). Figure 11 Not shown; usually referred to as a "hard drive"). Although Figure 11 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 518 via one or more data media interfaces. System memory 528 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this application.
[0187] A program / utility 540 having a set (at least one) of program modules 542 may be stored, for example, in system memory 528. Such program modules 542 include—but are not limited to—an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 542 typically perform the functions and / or methods described in the embodiments of this application.
[0188] Electronic device 512 can also communicate with one or more external devices 514 (e.g., keyboard, pointing device, display 524, etc.), and with one or more devices that enable a user to interact with electronic device 512, and / or with any device that enables electronic device 512 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 522. Furthermore, electronic device 512 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 520. As shown, network adapter 520 communicates with other modules of electronic device 512 via bus 518. It should be understood that, although... Figure 11As not shown, other hardware and / or software modules may be used in conjunction with electronic device 512, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0189] The processing unit 516 executes various functional applications and data processing by running at least one of the other programs among a plurality of programs stored in the system memory 528, such as implementing any of the water surface rendering methods provided in the embodiments of this application.
[0190] Example 6
[0191] This application also provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the program implements a water surface rendering method provided in any embodiment of this application. The method includes: obtaining a base normal texture; generating at least two derived normal textures based on the base normal texture; wherein each of the derived normal textures is different; and performing image rendering based on the at least two derived normal textures.
[0192] Based on the above description of the implementation methods, those skilled in the art can clearly understand that this application can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0193] It is worth noting that in the embodiments of the above-mentioned water surface rendering device, the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the scope of protection of this application.
[0194] Note that the above are merely preferred embodiments and the technical principles employed in this application. Those skilled in the art will understand that this application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application, the scope of which is determined by the scope of the appended claims.
Claims
1. A water surface rendering method, characterized in that, include: Obtain the base normal texture; where the base normal texture is the normal texture of the water ripple, used to create the water ripple effect; Based on the preset texture offset value and different sampling coefficients, at least two different target random sampling functions are generated based on the template random sampling function; Wherein, the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture; Based on the at least two different target random sampling functions and the vertex coordinates to be mapped in the derived normal texture, the calculation results of each target random sampling function are obtained, and the calculation results include at least two different texture coordinates; Based on the at least two different texture coordinates, texture sampling is performed on the base normal texture to obtain at least two different texture sampling results; Based on the at least two different texture sampling results, at least two derived normal textures are generated; wherein, the texture sampling result is the normal texture at the vertex coordinate position to be mapped in the derived normal texture; Wherein, the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture; wherein, each of the derived normal textures is different; For each vertex in the preset texture mapping vertex range value, at least two derived normal textures corresponding to the vertex coordinate position are superimposed to obtain the target normal texture of the vertex. Based on the coordinate positions of different vertices, the target normal textures corresponding to the coordinate positions of different vertices are combined to obtain the target normal texture image; Image rendering is performed based on the target normal texture image.
2. The method according to claim 1, characterized in that, The template random sampling function is calculated as follows: , Wherein, PosX represents the vertex x-coordinate of the derived normal texture map, PosY represents the vertex y-coordinate of the derived normal texture map, u is the texture x-coordinate of the base normal texture, v represents the texture y-coordinate of the base normal texture, animation represents the preset texture offset value, and K and Q represent sampling coefficients.
3. The method according to claim 1, characterized in that, The step of rendering the image based on the target normal texture image includes: Determine the normal direction based on the target normal texture image; The reflected color value and the specular highlight color value are determined based on the normal direction and the incident light direction, respectively. Image rendering is performed based on the reflected color value and the specular highlight color value.
4. The method according to claim 3, characterized in that, The process of determining the specular highlight color value based on the normal direction and the incident light direction includes: The direction of light reflection is determined based on the normal direction and the incident direction of the light. The specular highlight color value is determined based on the light reflection direction and the preset observation direction.
5. The method according to claim 4, characterized in that, The step of rendering the image based on the reflected color value and the specular highlight color value includes: Based on the direction of light reflection, spatial sampling is performed on the preset skybox to obtain the sky color value; Image rendering is performed based on the reflected color value, the specular highlight color value, and the sky color value.
6. A water surface rendering device, characterized in that, include: The normal texture acquisition module is used to acquire the basic normal texture; the basic normal texture is the normal texture of water ripples, which is used to create the water ripple effect. The sampling coefficient generation submodule is used to generate at least two different target random sampling functions based on the template random sampling function, according to the preset texture offset value and different sampling coefficients. Wherein, the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture; The normal texture derivation module is used to generate at least two derived normal textures based on the base normal texture; wherein each of the derived normal textures is different. The normal texture derivation module includes: The normal texture sampling submodule is used to perform texture sampling on the basic normal texture according to at least two different target random sampling functions to generate the at least two derived normal textures; Wherein, the independent variable of the target random sampling function is the vertex coordinates of the derived normal texture map, and the dependent variable is the texture coordinates of the base normal texture; The normal texture sampling submodule includes: The texture coordinate calculation unit is used to obtain the calculation results of each of the at least two different target random sampling functions and the vertex coordinates to be mapped in the derived normal texture, wherein the calculation results include at least two different texture coordinates; A texture sampling unit is used to perform texture sampling on the basic normal texture based on the at least two different texture coordinates to obtain at least two different texture sampling results; A normal texture derivation unit is used to generate at least two derived normal textures based on the at least two different texture sampling results; wherein the texture sampling result is the normal texture at the vertex coordinate position to be mapped in the derived normal texture; An image rendering module is used to render an image based on at least two of the derived normal textures; The image rendering module includes: The texture overlay submodule is used to overlay at least two derived normal textures corresponding to the coordinate position of each vertex in the preset texture mapping vertex range value to obtain the target normal texture of the vertex. The normal texture generation submodule is used to combine the target normal textures corresponding to different vertex coordinate positions to obtain the target normal texture image based on the coordinate positions of different vertices. The image rendering submodule is used to perform image rendering based on the target normal texture image.
7. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement a water surface rendering method as described in any one of claims 1-5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements a water surface rendering method as described in any one of claims 1-5.
Citation Information
Patent Citations
Water surface rendering method and apparatus
CN108470369A
Water surface ripple effect generation method and device, electronic equipment and storage medium
CN112884860A
Water wave special effect generation method and device, storage medium and computer equipment
CN112967367A