Spherical water body coloring method and device and electronic equipment
By acquiring vertex data and multi-scale texture mapping of the 3D model and combining it with the water optical model, the curvature neglect problem in spherical water rendering is solved, achieving efficient and realistic spherical water rendering effects, suitable for large-scale games and mobile platforms.
Patent Information
- Application Number
- CN202511739657.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-25
- Publication Date
- 2026-02-27
AI Technical Summary
Existing technologies ignore the curvature of the sphere when rendering water on the surface of planets, resulting in water that lacks a sense of curvature, is not realistic or accurate enough, and is difficult to adapt to the real-time rendering needs of large-scale games and mobile platforms.
By acquiring vertex data from a 3D model, world coordinates and normals are generated. Multi-scale texture mapping and nonlinear blending algorithms are used in conjunction with a water optical model to generate the coloring result of a spherical water body, achieving natural blending of multi-level details and accurate lighting reproduction.
It improves the texture consistency and geometric fidelity of spherical water bodies, enhancing the realism and accuracy of large-scale spherical water bodies in real-time rendering scenes, and is suitable for large-scale games and mobile platforms.
Smart Images

Figure CN121582433A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a spherical water coloring method, device and electronic equipment. BACKGROUND
[0002] In space-themed electronic games, rendering large-scale water bodies (such as oceans, lakes) on the surface of a planet is one of the key technologies for creating immersion. There are currently a variety of technical solutions on the market for water body rendering, but there are relatively few solutions for simulating planet-scale spherical water bodies or oceans.
[0003] Existing large-scale space games (such as "No Man's Sky", "Stellaris", "Star Citizen", etc.) typically simulate water bodies as a local plane due to the large scale of their game scenes, and often use traditional plane grids combined with localized normal perturbation techniques, or use simple linear waves (such as sine waves, Gerstner waves) to simulate wave motion. Although this method is computationally efficient, it essentially ignores the spherical curvature of the planet, resulting in a lack of "curved surface" sensation in the rendered water bodies, which significantly reduces the realism when the player's field of view is very far or when the planet is viewed from above. Therefore, there is a deficiency in terms of realism and accuracy in rendering. SUMMARY
[0004] The purpose of the present application is to provide a spherical water coloring method, device and electronic equipment that can achieve realistic and accurate rendering in real-time rendering of large-scale spherical water bodies.
[0005] To achieve the above purpose, the technical solutions adopted by the embodiments of the present application are as follows: In a first aspect, the embodiments of the present application provide a spherical water coloring method, device and electronic equipment.
[0006] Optionally, the step of obtaining a set of pixels to be rendered comprises: Obtaining vertex data of a three-dimensional model, the vertex data including local coordinates and local normals of each vertex in the three-dimensional model in a local coordinate system; Based on the vertex data, generating world coordinates and world normals of each vertex in a world coordinate system to obtain each transformed vertex; Based on each transformed vertex, a plurality of triangular primitives are obtained; For each triangular primitive, a plurality of pixels to be rendered are generated that cover the triangular primitive and are located in a screen space; generate a world coordinate and a world normal of each of the to-be-rendered pixel points based on world coordinates and a world normal of each vertex of the triangle primitive, determine a screen coordinate of the to-be-rendered pixel point according to a position of the to-be-rendered pixel point in the screen space, and obtain the set of to-be-rendered pixel points.
[0007] Optionally, each of the to-be-rendered pixel points also has a corresponding screen coordinate; after the step of obtaining the set of to-be-rendered pixel points, the method further comprises: For each of the to-be-rendered pixel points, a pre-established Bayer dithering matrix is used to map the screen coordinate of the to-be-rendered pixel point to a threshold index in a set range; compare the threshold index with a preset dissolving factor; If the threshold index is less than the dissolving factor, the to-be-rendered pixel point is discarded, otherwise, the step of determining three plane mixing weights of the to-be-rendered pixel point in three orthogonal directions according to the projection intensity of the world normal of the to-be-rendered pixel point in the three orthogonal directions of the three-dimensional rectangular coordinate system is performed.
[0008] Optionally, the multi-scale texture mapping model comprises a plurality of texture scaling levels; The step of generating the world space normal component corresponding to the orthogonal direction based on the world coordinate of the to-be-rendered pixel point and the preset multi-scale texture mapping model comprises: generating a noise disturbance vector based on the world coordinate of the to-be-rendered pixel point; calculating a low-frequency texture coordinate, a medium-frequency texture coordinate and a high-frequency texture coordinate in each of the orthogonal directions according to the noise disturbance vector and the plurality of texture scaling levels; sampling a corresponding normal map for each of the low-frequency texture coordinate, the medium-frequency texture coordinate and the high-frequency texture coordinate in each of the orthogonal directions to obtain a plurality of normal sampling results in each of the orthogonal directions; using a nonlinear mixing algorithm based on normal redirection to perform weighted fusion of the plurality of normal sampling results in the same orthogonal direction in their respective tangent spaces to obtain an intermediate normal vector in each of the orthogonal directions; convert the intermediate normal vector in each of the orthogonal directions from the tangent space to the world space to obtain a world space normal vector corresponding to each of the orthogonal directions.
[0009] Optionally, the water optical model comprises screen space reflection, and the light source parameters comprise a set of dynamic light sources and attributes thereof; The step of performing shading calculation based on the world space normal vector, light source parameters required for the current rendering frame and a camera view direction, and a preset water optical model to generate a basic shading result of the to-be-rendered pixel point comprises: According to the world space normal vector, a preset environment cube map is sampled to obtain a basic sky reflection color; A reflection ray direction is calculated based on the world space normal vector and the camera view direction, and screen space reflection tracing is performed on a rendered scene depth texture along the reflection ray direction to detect whether there is a pixel trajectory with continuous depth values along the ray path to determine whether a matchable screen space surface is hit; When it is confirmed that the matchable screen space surface is hit, a screen space reflection resulting color is obtained, and a hit confidence is calculated; and the screen space reflection resulting color and the basic sky reflection color are weighted and fused according to the hit confidence to generate a target reflection value; According to the set of dynamic light sources and their attributes, each effective light source that has an impact on the pixel point to be rendered is filtered out, and based on the world space normal vector, the camera view direction and the preset material parameters, the microfacet bidirectional reflectance distribution function model is used to calculate the specular reflection value and the diffuse reflection value of each effective light source respectively; The target reflection value and the specular reflection value and the diffuse reflection value of each effective light source are accumulated to obtain a basic shading result of the pixel point to be rendered.
[0010] Optionally, each of the pixel points to be rendered also has a corresponding screen coordinate; the method further comprises: Based on the screen coordinate of the pixel point to be rendered, a preset scene depth texture is sampled to obtain a terrain surface depth value corresponding to the position of the screen coordinate; The vertical depth difference between the world space height of the water surface where the pixel point to be rendered is located and the terrain surface depth value is calculated; A non-linear mapping function with smooth transition characteristics is used to convert the vertical depth difference into a transparency value; Based on the transparency value, the Alpha channel of the basic shading result of the pixel point to be rendered is adjusted to generate a first intermediate shading result; The Alpha channel of the first intermediate shading result is mixed with the Alpha channel of the color of the background scene to realize visual soft transition from land to deep sea area.
[0011] Optionally, the method further comprises: Based on the vertical depth difference, a foam intensity coefficient is generated, wherein the foam intensity coefficient exponentially decays or linearly decays with the increase of the vertical depth difference; According to the foam intensity coefficient, a preset foam texture is superimposed on the first intermediate shading result to generate a second intermediate shading result; applying a time-varying UV coordinate offset to a preset caustic texture map to generate a dynamic caustic texture; superimposing the dynamic caustic texture onto the second intermediate shading result to obtain a target shading result of the pixel point to be rendered.
[0012] Optionally, the method further comprises: calculating an exponential attenuation factor based on the vertical depth difference, wherein the exponential attenuation factor represents a degree of attenuation of a light ray passing through the water body, and is used to simulate an influence of a thickness of the water body on light propagation; inputting the exponential attenuation factor into a pre-constructed sub-surface scattering calculation model to simulate absorption and scattering behaviors of the light ray in the water body, and generating a corresponding water color of the pixel point to be rendered; performing weighted mixing of the water color, the target shading result, and a preset spherical atmospheric scattering color to obtain a final dynamic shading result of the pixel point to be rendered.
[0013] In a second aspect, an embodiment of the present application provides a spherical water body shading device, which comprises: an acquisition module configured to acquire a set of pixel points to be rendered, the set of pixel points to be rendered comprising a plurality of pixel points to be rendered, each of the pixel points to be rendered having a corresponding world coordinate and world normal, and acquire light source parameters and a camera view direction required for a current rendering frame; an execution module configured to, for each of the pixel points to be rendered, determine three-plane mixing weights of the pixel point to be rendered in three orthogonal directions of a three-dimensional rectangular coordinate system according to projection intensities of the world normal of the pixel point to be rendered in the three orthogonal directions; for each of the orthogonal directions, generate a world space normal component corresponding to the orthogonal direction based on the world coordinate of the pixel point to be rendered and a preset multi-scale texture mapping model; and perform weighted fusion on the world space normal components corresponding to the three orthogonal directions according to the three-plane mixing weights to obtain a world space normal vector; a shading module configured to perform shading calculation based on the world space normal vector, the light source parameters and the camera view direction required for the current rendering frame, and a preset water body optical model, and generate a basic shading result of the pixel point to be rendered.
[0014] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, and a graphics processing unit (GPU), the memory being configured to store computer program instructions, the processor being configured to execute the computer program instructions to control the GPU to perform graphics rendering; and the GPU being configured to perform pixel shading operations according to rendering instructions issued by the processor, so as to implement the spherical water body shading method in the first aspect.
[0015] Compared to existing technologies, the spherical water coloring method, apparatus, and electronic device provided in this application first determine the three-plane blending weights based on the projection intensity of the world normal of the pixel to be rendered in three orthogonal directions in a three-dimensional Cartesian coordinate system. By dynamically allocating the contribution ratio of each projection direction to the final normal, the detail expression is always dominated by the direction closest to the perpendicular to the viewpoint, regardless of the surface orientation. This avoids the extreme compression and distortion caused by a single projection direction, improving the overall texture consistency and geometric fidelity of the sphere. Based on this, the world space of each orthogonal direction is generated according to the world coordinates of the pixel to be rendered and a preset multi-scale texture mapping model. By sharing world coordinates, the inter-dimensional normal components ensure the continuity of motion between ripples of different scales. Then, based on the three-plane blending weights, the world space normal components corresponding to the three orthogonal directions are weighted and fused to obtain a unified world space normal vector. This ensures that subsequent lighting calculations are performed in a globally consistent coordinate system, avoiding anomalies caused by coordinate system misalignment. Finally, based on the world space normal vector, the light source parameters required for the current rendering frame, the camera's viewing angle, and the preset water optical model, shading calculations are performed to generate the basic shading results for the pixels to be rendered. This ensures that the water body exhibits stable and accurate specular highlights and environmental reflection behavior from different viewing angles. Thus, the multi-directional world space normal fusion mechanism guided by three-plane weights effectively overcomes the seams and distortion problems in spherical mapping, achieving natural blending of multi-level details and accurate restoration of lighting behavior, enhancing the overall realism and geometric accuracy of large-scale spherical water bodies in real-time rendering scenes. Attached Figure Description
[0016] Figure 1 A block diagram of an electronic device provided in an embodiment of this application is shown.
[0017] Figure 2 This application provides a schematic flowchart of a spherical water coloring method according to an embodiment. Figure 1 .
[0018] Figure 3 This application provides a schematic flowchart of a spherical water coloring method according to an embodiment. Figure 2 .
[0019] Figure 4 A block diagram of a spherical water coloring device provided in an embodiment of this application is shown.
[0020] Icons: 100-Spherical water coloring device; 101-Acquisition module; 102-Execution module; 103-Coloring module; 10-Electronic device; 11-Processor; 12-Memory; 13-Bus; 14-GPU. Detailed Implementation
[0021] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
[0022] The spherical water body coloring method provided by the embodiments of the present application is applied to an electronic device, which can be a mobile terminal, for example, various personal computers, notebook computers, smart phones and tablet computers and the like, or a server, for example, a stand-alone server or a server cluster composed of multiple servers.
[0023] Please refer to Figure 1 , Figure 1 A block diagram of an electronic device 10 provided by the embodiments of the present application is shown. The electronic device 10 is a hardware carrier for implementing a graphics rendering function, which includes a processor 11 for performing a computing task, a memory 12 for storing data and program codes, and a GPU (Graphics Processing Unit) 14 dedicated to processing graphics-related operations, and the processor 11 is connected with the memory 12 and the GPU 14 through a bus 13.
[0024] The memory 12 is configured to store computer program instructions, and the processor 11 is configured to execute the computer program instructions to control the GPU 14 to perform graphics rendering; the GPU 14 is configured to perform pixel shading operations according to rendering instructions issued by the processor 11, so as to implement the spherical water body coloring method disclosed in the following embodiments.
[0025] It should be noted that the processor 11 does not directly participate in color calculation at the pixel level, but determines when to start the rendering process, adopts which rendering pipeline stage and transmits necessary parameter information through a high-level scheduling mechanism.
[0026] After the GPU 14 receives the rendering instructions issued by the processor 11, it enters the corresponding graphics processing pipeline stage, which includes but is not limited to vertex processing, primitive assembly, rasterization and pixel shading. By utilizing the high parallel computing capability of the GPU 14, complex lighting model and material simulation operations are performed in the pixel shading stage, so as to realize accurate reproduction of the optical properties of the spherical water body surface. Specifically, the pixel shading operation performs pixel-by-pixel processing on the received fragment data according to a preset shading algorithm, and dynamically calculates the color value finally presented by each pixel in combination with input variables such as viewing direction, normal information, light source position and material properties.
[0027] That is, by encapsulating the specific logic of the spherical water body coloring method in a shader program executable by the GPU 14, and triggering its running by the processor 11, the visual effect of a real spherical water area is efficiently and real-timely rendered on the electronic device 10.
[0028] The memory 12 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.
[0029] The processor 11 can be an integrated circuit chip with signal processing capability. In the implementation process, each step of the above method can be completed by the integrated logic circuit of hardware in the processor 11 or the instruction in the form of software. The processor 11 described above can be a general-purpose processor, including a central processing unit (CPU), a microcontroller unit (MCU), a complex programmable logic device (CPLD), a field programmable gate array (FPGA), an embedded ARM, etc.
[0030] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by the processor 11 to control the GPU 14 to perform graphic rendering and to perform pixel shading operation by the GPU 14 to realize the spherical water body shading method disclosed in the following embodiment.
[0031] Please refer to Figure 2 , Figure 2 A flowchart of a spherical water body shading method provided by the embodiment of the present application is shown, which can include the following steps: S101, a set of to-be-rendered pixel points is acquired, the set of to-be-rendered pixel points includes a plurality of to-be-rendered pixel points, each to-be-rendered pixel point has a corresponding world coordinate and world normal; light source parameters and a camera view direction required for a current rendering frame are acquired.
[0032] S102, for each to-be-rendered pixel point, according to the projection intensity of the world normal of the to-be-rendered pixel point on three orthogonal directions of a three-dimensional rectangular coordinate system, three plane mixing weights of the to-be-rendered pixel point on the three orthogonal directions are determined.
[0033] S103, for each orthogonal direction, based on the world coordinates of the pixel to be rendered and the preset multi-scale texture mapping model, the world space normal component corresponding to the orthogonal direction is generated.
[0034] S104, according to the three-plane blending weight, the world space normal components corresponding to the three orthogonal directions are weighted and fused to obtain a world space normal vector.
[0035] S105, based on the world space normal vector, the light source parameters required by the current rendering frame and the camera view direction, and the preset water optical model, the shading calculation is performed to generate the basic shading result of the pixel to be rendered.
[0036] In step S101, the world coordinates are used to uniquely identify the position of the pixel to be rendered in the global three-dimensional space, and the world normal reflects the basic geometric information of the surface facing the pixel to be rendered. The light source parameters include a set of dynamic light sources and their attributes, such as position, color, intensity, etc., and the camera view direction represents the line of sight direction of the observer in the world coordinate system.
[0037] In step S102, the three orthogonal directions refer to the space main directions defined by the X-axis, Y-axis and Z-axis of the three-dimensional rectangular coordinate system. The projection intensity refers to the absolute value of the world normal component of the pixel to be rendered in the X-axis, Y-axis and Z-axis direction, and its numerical size reflects the alignment degree of the surface of the pixel to be rendered with the corresponding coordinate axis. When the projection intensity in a certain direction is larger, it means that the local surface of the pixel to be rendered is more perpendicular to that direction, and the texture and normal information of the corresponding direction should be given a higher fusion weight.
[0038] In step S103, the multi-scale texture mapping model can be a texture sampling mechanism that supports different resolution levels, which can dynamically select the appropriate level of detail according to the distance or curvature density, and combine the projection coordinates of the world coordinates in a certain direction plane to perform normal mapping query, thereby outputting the world space normal vector in the corresponding direction. This process acts independently on the three orthogonal directions, and can obtain three world space normal components corresponding to the three orthogonal directions, respectively reflecting the surface microstructure characteristics in the corresponding orthogonal direction.
[0039] In step S104, the three-plane blending weight is used as the fusion coefficient to weight and fuse the world space normal components corresponding to the three orthogonal directions to obtain a unified world space normal vector. The above fusion process ensures that the final normal can not only preserve the overall orientation characteristics of the original geometric normal, but also incorporate the high-frequency details provided by the multi-direction texture, while avoiding the seam or distortion problems caused by a single projection plane. Especially in the edge area of the spherical water body, this fusion method based on weight transition can effectively alleviate the discontinuity between different mapping planes, making the normal field smooth and transition on the entire sphere.
[0040] The above method combines three-plane blending weights with multi-scale texture mapping to achieve high-fidelity reconstruction of the surface normals of complex spherical water bodies. Unlike traditional single-plane projection, which is prone to polar distortion, this method fully utilizes the directional characteristics of the normals themselves to adaptively adjust the information contribution ratios of the three orthogonal directions, ensuring that reasonable detail enhancement is achieved regardless of whether the pixel to be rendered is located at the equator or the polar regions.
[0041] In step S105, the water optical model can be a set of mathematical expressions describing the interaction between light and the water surface, covering approximate simulations of physical phenomena such as specular reflection, Fresnel effect, subsurface scattering, and wave transmission. In practical applications, the world space normal vector obtained in step S104 can be used as the input to the water optical model. Combined with the incident light information provided by the light source parameters and the observation angle information provided by the camera's viewing angle direction, the color value and transparency of the pixel to be rendered are calculated to obtain the basic shading result of the pixel to be rendered.
[0042] In practical applications, taking a pixel to be rendered as an example, the vertex shader passes the world coordinates, world normal, and screen coordinates of the pixel to be rendered to the fragment shader at once. Subsequent calculations (i.e., the spherical water shading method provided in this embodiment) are all completed within the GPU, without any back-and-forth between the CPU and GPU, thus improving computational efficiency.
[0043] In one alternative implementation, the process of obtaining the set of pixels to be rendered in step S101 may include: S1011, Obtain the vertex data of the 3D model. The vertex data includes the local coordinates and local normals of each vertex in the 3D model in the local coordinate system.
[0044] S1012, based on vertex data, generates the world coordinates and world normal of each vertex in the world coordinate system, thus obtaining each transformed vertex.
[0045] S1013, based on each transformed vertex, yields multiple triangular primitives.
[0046] S1014: For each triangular primitive, generate multiple pixels to be rendered that cover the triangular primitive and are located in screen space.
[0047] S1015: Based on the world coordinates and world normals of each vertex of the triangle primitive, generate the world coordinates and world normals of each pixel to be rendered, determine its screen coordinates according to the position of the pixel to be rendered in screen space, and obtain the set of pixels to be rendered.
[0048] In the embodiment, the data link mechanism from vertex to screen space is used to ensure that each pixel to be rendered can obtain the world coordinates and world normal with global consistency, thereby providing reliable basic input for continuous rendering of spherical water body under complex curvature.
[0049] In sub-step S1011, the local coordinate system refers to the coordinate system of the three-dimensional model itself. Taking a vertex as an example, the local coordinates and local normal of the vertex describe the geometric shape and surface direction of the vertex in the coordinate system of the three-dimensional model itself.
[0050] In sub-step S1012, based on the vertex data, in the vertex shading stage of the graphics rendering pipeline, that is, in the vertex shader, the local coordinates are converted into world coordinates through a model transformation matrix, and the local normal is transformed and normalized through a normal transformation matrix, to obtain the world coordinates and world normal of each vertex in the world space. The world coordinates represent the global spatial positioning information of the pixel to be rendered, and the world normal represents the surface orientation information of the pixel to be rendered.
[0051] In sub-step S1013, based on each transformed vertex, a plurality of triangular primitives are assembled according to the index relationship defined when modeling, each triangular primitive is composed of three vertices, and the triangular primitive is the basic geometric unit of the rendering object.
[0052] In sub-step S1014, for each triangular primitive, a rasterization operation is performed, that is, the triangular primitive is projected into the screen space and all pixel positions covered in the projection region are determined, to generate a plurality of pixels to be rendered which cover the triangular primitive and are located in the screen space.
[0053] In sub-step S1015, based on the world coordinates and world normal of the vertices of the triangular primitive, the barycentric interpolation method is used to calculate the world coordinates and world normal of each pixel to be rendered, so that the value of any pixel to be rendered is the weighted average of the corresponding attributes of the three vertices of the triangular primitive in which the pixel to be rendered is located. The weight is determined by the relative position of the pixel to be rendered in the screen space. At the same time, the screen coordinates of the pixel to be rendered are determined according to the position of the pixel to be rendered in the screen space. The screen coordinates are used for index positioning in subsequent dithering sampling, depth comparison and reflection ray tracing and other screen space algorithms.
[0054] Currently, the rendering technology for water bodies basically uses a planar grid to draw the water surface, and uses linear wave superposition, pre-rendered texture mapping or a method based on a statistical model to calculate the vertex position of the grid in real time to simulate the undulating fluctuations of the water body. Among them, the linear wave superposition method (such as sine wave and Gerstner wave) is simple and fast, but has deficiencies in the realism and accuracy of rendering, and it is difficult to achieve good visual effects; pre-rendered texture mapping is suitable for games with controllable scene size, and is difficult to apply to large-scale scenes such as planetary surfaces and open worlds; the method based on a statistical model (such as fast Fourier transform) can achieve exquisite water effects, but has large performance overhead and is difficult to run in real time on mobile platforms.
[0055] Therefore, in addition to the above-mentioned deficiencies in realism and accuracy, the prior art is also difficult to adapt to massively multiplayer online (MMO) games and mobile platforms. Based on this, the present embodiment performs a clipping operation in the first line of the fragment shader to quickly judge and discard potentially invalid pixels, thereby reducing the redundancy of subsequent calculations.
[0056] On the basis of Figure 2 , please refer to Figure 3 , after step S101, the spherical water body shading method provided by the present application further includes steps S10A-S10C.
[0057] S10A, for each pixel to be rendered, using a pre-established Bayer dithering matrix, the screen coordinates of the pixel to be rendered are mapped to a threshold index within a specified range.
[0058] S10B, compare the threshold index with the preset dissolution factor; if the threshold index is less than the dissolution factor, execute step S10C, otherwise, execute step S102.
[0059] S10C, discard the pixel to be rendered.
[0060] It should be understood that in the real-time graphics rendering process, the computational load of the fragment shading stage is closely related to the number of pixels to be rendered, especially in the application of large-scale water body covering spherical scenes, a large number of pixels located at the edge of the view frustum or in the transparent region will enter the complete shading process, which will cause significant performance overhead. Therefore, in the present embodiment, by introducing an early pixel screening mechanism based on screen coordinates, the potentially invalid pixels are quickly judged and discarded in the initial stage of the shading process, thereby effectively reducing the redundancy of subsequent calculations.
[0061] In the embodiment, the Bayer dithering matrix is a two-dimensional numerical table of fixed size, for example, a 4x4 matrix, the elements of which are distributed in a preset integer interval, for example, 0-15, and the matrix content is arranged according to the spatial dithering mode, having good visual uniformity and pseudo-random distribution characteristics. The screen coordinates represent the two-dimensional position of the pixel to be rendered on the final imaging plane, and can be used to locate the row and column positions of the pixel to be rendered in the screen space. Optionally, the screen coordinates of the pixel to be rendered are corresponded to an index position in the Bayer dithering matrix in a modulo operation manner, and the value stored in the position is read as the threshold index.
[0062] Subsequently, the threshold index is compared with a preset dissolving factor, which is a programmable control parameter representing the minimum threshold value of the allowed retained pixels in the current rendering frame, and the dynamic adjustment of the value can realize the animation effect of the gradual fading out or local dissolving of the water body edge. If the threshold index is less than the dissolving factor, the pixel to be rendered is discarded, that is, the discard instruction provided by the graphics API is called to interrupt all subsequent processing of the current pixel, so that it does not participate in any normal fusion, illumination calculation or color output operation; otherwise, if the threshold index is greater than or equal to the dissolving factor, the subsequent steps are continued.
[0063] The above lightweight clipping decision at the entry of the fragment shader avoids performing high-cost multi-layer texture sampling and vector transformation operations on pixels that are destined not to contribute to the final image, and is especially suitable for mobile end GPUs or MMO game scenarios.
[0064] In an optional implementation, the process of generating the world space normal component corresponding to the orthogonal direction based on the world coordinates of the pixel to be rendered and the preset multi-scale texture mapping model in step S103 can include: S1031, generating a noise disturbance vector based on the world coordinates of the pixel to be rendered.
[0065] S1032, calculating the low-frequency texture coordinates, the medium-frequency texture coordinates and the high-frequency texture coordinates in each orthogonal direction according to the noise disturbance vector and the plurality of texture scaling levels.
[0066] S1033, sampling the corresponding normal map for each of the low-frequency texture coordinates, the medium-frequency texture coordinates and the high-frequency texture coordinates in each orthogonal direction to obtain a plurality of normal sampling results in each orthogonal direction.
[0067] S1034, using a nonlinear mixing algorithm based on normal redirection to weight and fuse the plurality of normal sampling results in the same orthogonal direction in their respective tangent spaces to obtain an intermediate normal vector in each orthogonal direction.
[0068] S1035, convert the intermediate normal vector in each orthogonal direction from the tangent space to the world space to obtain a world space normal vector corresponding to each orthogonal direction.
[0069] It should be understood that in the rendering process of the spherical water body, the texture mapping of a single frequency is difficult to simultaneously present a large range of wave structure and local detail fluctuation, which is easy to cause a visual repetition or mechanical feeling. In order to overcome this problem, the linear superposition method is often used to fuse multiple layers of textures in the prior art, but this method is easy to produce direction conflict and intensity imbalance when synthesizing normal vectors, resulting in unnatural lighting response, especially on the surface of the sphere with continuous curvature. In addition, the traditional UV mapping has serious stretching in the polar region, which further aggravates the texture distortion problem. Based on this, the embodiment constructs a multi-scale texture mapping model including multiple texture scaling levels, and combines the procedural noise driving and nonlinear normal fusion mechanism to realize the coordinated expression of the multi-level details of the water surface.
[0070] In the embodiment, the multi-scale texture mapping model includes multiple texture scaling levels, specifically a set of scale factors for controlling the texture sampling density, which usually covers three levels of low frequency, medium frequency and high frequency, corresponding to the visual characteristics of large-scale wave, medium undulation and small ripple respectively. The above levels jointly act on the same space coordinate basis to form a dynamic disturbance system with time consistency and spatial continuity.
[0071] In the sub-step S1031, the world coordinates are input into the two-dimensional Simplex noise function snoise() as a globally unique position identifier, and the time variable is combined for evolution calculation, and a two-dimensional floating point offset slowly drifting with time, i.e. a noise disturbance vector, is output. The noise disturbance vector has the characteristics of pseudo-random distribution and smooth change between adjacent pixels, which can effectively break the periodic repetition phenomenon caused by regular grid and simulate the water surface drifting effect driven by wind in nature.
[0072] In the sub-step S1032, after the original world coordinates are added with the noise disturbance vector, they are multiplied by the scaling coefficients corresponding to each level, for example, 1, 2 and 4, to obtain three sets of texture mapping positions with different resolutions, i.e. low-frequency texture coordinates, medium-frequency texture coordinates and high-frequency texture coordinates. Since all levels share the same disturbance source, their spatial motion remains synchronized, so the phenomenon of frequency layer phase error can be avoided, and the macro-to-micro ripple evolution is ensured to be uniform and coordinated. The three sets of frequencies share the same noise disturbance, but the higher the frequency, the greater the disturbance amplification, forming a natural level of detail.
[0073] In sub-step S1033, the normal map used is usually an RGB format texture, and the pixel value of the normal map encodes the normal direction information in tangent space. The sampling of low-frequency texture coordinates, medium-frequency texture coordinates and high-frequency texture coordinates is performed independently, which can retain the respective spatial detail characteristics and provide original data support for subsequent fusion.
[0074] In sub-step S1034, the nonlinear blending algorithm based on normal redirection is different from the traditional linear interpolation or component-wise averaging. The nonlinear blending algorithm adjusts the synthesis path according to the geometric relationship between the normal directions, retains the dominant direction while absorbing the secondary details through the vector redirection mechanism, can significantly weaken the overlapping feeling, and makes the transition between different frequency levels more natural and soft.
[0075] In sub-step S1035, the conversion process depends on the local coordinate system constructed under the current projection direction, which is usually composed of a TBN matrix (tangent-bitangent-normal matrix) composed of a world normal and two other orthogonal vectors. The intermediate normal vector is mapped to the global coordinate system through matrix transformation, so that it can participate in the unified lighting and reflection calculation.
[0076] In this embodiment, by integrating multi-scale sampling, common-source disturbance driving and nonlinear normal fusion strategy, rich and realistic water surface detail expression can be realized under the premise of maintaining a low number of texture access times.
[0077] In an optional implementation, the process of performing shading calculation based on the world space normal vector, the light source parameters required by the current rendering frame and the camera view direction, and the preset water optical model in step S105 to generate the basic shading result of the pixel to be rendered can include: S1051, sampling the preset environment cube map according to the world space normal vector to obtain a basic sky reflection color.
[0078] S1052, calculating a reflection ray direction based on the world space normal vector and the camera view direction, and performing screen space reflection tracking on the rendered scene depth texture along the reflection ray direction to detect whether there is a pixel trajectory with continuous depth values along the ray path to determine whether a matchable screen space surface is hit.
[0079] S1053, when it is confirmed that the matchable screen space surface is hit, obtaining a screen space reflection color and calculating a hit confidence.
[0080] S1054, weighting and fusing the screen space reflection color and the basic sky reflection color according to the hit confidence to generate a target reflection value.
[0081] S1055, according to the dynamic light source set and its attributes, each effective light source affecting the pixel point to be rendered is screened out, and based on the world space normal vector, the camera view direction and the preset material parameter, the micro-surface bidirectional reflection distribution function model is used to calculate the specular reflection value and the diffuse reflection value of each effective light source.
[0082] S1056, the target reflection value and the specular reflection value and the diffuse reflection value of each effective light source are accumulated to obtain the basic shading result of the pixel point to be rendered.
[0083] It should be understood that in order to realize realistic water rendering in a complex three-dimensional scene, the physical interaction relationship between environmental reflection, dynamic lighting and surface material needs to be considered comprehensively. Traditional reflection simulation methods mostly rely on static environment maps or pure screen space tracking technology. The former is difficult to reflect the changes of dynamic objects, and the latter is prone to cracks and holes at the edge of the field of view or when reflecting out of the screen, resulting in distortion of the water surface specular effect. At the same time, in application scenarios such as MMO games where light sources are dense, if all light sources are calculated one by one, a serious performance bottleneck will be caused. Based on this, the embodiment realizes comprehensive shading that takes into account visual realism and computational efficiency by fusing global sampling based on environment cube map and screen space reflection tracking mechanism, and combining dynamic light source screening and micro-surface lighting model.
[0084] In the embodiment, the water optical model can include screen space reflection (SSR) for capturing mirror image information of rendered geometry in the water surface in the current rendering frame. The light source parameters include a dynamic light source set and its attributes, wherein the dynamic light source set includes all light sources that can affect the pixel point to be rendered in the current rendering frame, and the attributes include position, color, intensity, attenuation radius, influence level, etc. Optionally, the influence range of all light sources is encoded into a 32x1 bitmap.
[0085] In sub-step S1051, the environment cube map can be a pre-generated hexahedral texture recording panoramic environmental lighting information centered on the scene. By mapping the reflection direction vector to the cube surface coordinate system, the background color in the corresponding direction can be quickly obtained, which is especially suitable for completing the area at a long distance or not covered by SSR.
[0086] In sub-step S1052, the reflection ray direction is calculated based on the world space normal vector and the camera view direction, which means that the camera view direction is mirror reflected with respect to the world space normal vector to generate a three-dimensional ray direction vector pointing to the screen space, and the vector is projected to the normalized device coordinate system. Then, screen space reflection tracking is performed on the rendered scene depth texture along the reflection ray direction, which means that the depth value is sampled in a step-by-step manner in the screen space, and it is detected whether there is a pixel track with continuous depth value along the ray path, that is, whether a matchable screen space surface is hit. In this way, the effectiveness of the reflection path is verified by using the geometric information in the depth buffer, which can effectively avoid misjudging the blank area as the reflection target.
[0087] In sub-step S1053, when it is confirmed that the matchable screen space surface is hit, the screen space reflection color is obtained, that is, the pixel value corresponding to the hit position is read from the color buffer. At the same time, the hit confidence is calculated according to the tracking path length, the step error, the edge blur degree and other factors. The hit confidence is a value between 0 and 1, reflecting the reliability degree of the reflection result.
[0088] In sub-step S1054, when the target reflection value is generated, the SSR result can be preferentially used in the high-confidence area to enhance local details, and the transition to the cube map content is smoothed in the low-confidence or non-hit area, so that the reflection distortion caused by the spherical curvature can be eliminated, and a visually coherent and stable reflection performance can be realized.
[0089] In sub-step S1055, the screening process of the effective light source can be completed based on the spatial position relationship between the light source action range and the pixel point to be rendered, and only the light source within the effective radius and without occlusion is retained for subsequent calculation to control the operation scale. Optionally, for the current rendering frame, a 32x1 bitmap previously constructed can be read first, and each bit in the bitmap represents whether the corresponding light source covers the rendering block in which the pixel point to be rendered is located. Then, the active bit is quickly identified through a bit scanning instruction to quickly exclude the light source not in the influence area, so as to obtain all the effective light sources.
[0090] Meanwhile, for each effective light source, the microfacet bidirectional reflectance distribution function (BRDF) model is used to calculate the specular reflection value and diffuse reflection value based on the world space normal vector, the camera view direction and the preset material parameters. The microfacet BRDF model approximates the real light scattering behavior by statistics of microfacet distribution, Fresnel response and geometric shading term, so as to ensure that the lighting response conforms to the physical law. Optionally, the microfacet BRDF model can select the Cook-Torrance model.
[0091] In sub-step S1056, the target reflection value and the specular reflection value and the diffuse reflection value of each effective light source are accumulated to form a comprehensive lighting response containing ambient reflection and direct lighting, and a base shading result of the pixel point to be rendered is output. This accumulation process follows the principle of energy conservation, supports the multi-light source superposition effect while maintaining reasonable brightness, and is suitable for high dynamic range rendering pipelines.
[0092] In the embodiment, the above-mentioned shading calculation process can realize effective modeling of complex reflection phenomena and multi-light source interaction under the premise of ensuring visual quality by integrating ambient reflection and local lighting information, not only improves the visual consistency of water bodies in dynamic scenes, but also enhances rendering stability through a confidence-guided mixing strategy, and can ensure high-quality presentation of large-scale spherical water bodies on different hardware platforms.
[0093] In an optional implementation, after step S105, the spherical water body shading method provided by the embodiment of the application further includes steps S106-S110.
[0094] S106, based on the screen coordinates of the pixel point to be rendered, sampling the preset scene depth texture to obtain a terrain surface depth value corresponding to the position of the screen coordinates.
[0095] S107, calculating the vertical depth difference between the world space height of the water surface where the pixel point to be rendered is located and the terrain surface depth value.
[0096] S108, using a nonlinear mapping function with smooth transition characteristics to convert the vertical depth difference into a transparency value.
[0097] S109, adjusting the Alpha channel of the base shading result of the pixel point to be rendered based on the transparency value to generate a first intermediate shading result.
[0098] S110, mixing the Alpha channel of the first intermediate shading result with the Alpha channel of the color of the background scene to realize visual soft transition from land to deep sea area.
[0099] It should be understood that in the rendering process of the intersection area of the spherical water body and the land, if the water body boundary is determined by using hard clipping or fixed threshold, the coastline will often appear jagged or mutate to be blanked out, which destroys the visual continuity. Based on this, the embodiment simulates the optical blanking phenomenon of the gradual transition of the shallow water area to the deep sea in the real world through adaptive edge softening.
[0100] In step S106, the scene depth texture can be full-screen buffer data generated in the previous rendering stage, recording the normalized depth distribution of the drawn geometry between the near and far planes of the camera under the current view angle. By inputting the screen coordinates as texture coordinates, the depth information of the nearest visible surface in the vertical line-of-sight direction of the pixel to be rendered, i.e., the height projection of the land or seabed, can be directly read.
[0101] In step S107, the world space height of the water surface is determined by the vertical component (such as the Y-axis component) in the world coordinates of the pixel to be rendered, reflecting the absolute elevation of the current water surface. After the terrain surface depth value is restored to the world space unit by inverse transformation, the height position of the land or riverbed directly below is represented. The vertical depth difference between the world space height of the water surface where the pixel to be rendered is located and the terrain surface depth value is the actual distance from the water surface to the water bottom.
[0102] In step S108, the non-linear mapping function can be a smoothstep type interpolation function. The output of this function presents an S-shaped curve response with the change of the input. Therefore, when the vertical depth difference is converted into the transparency value using this function, if the vertical depth difference is small (corresponding to the shallow water area), the transparency value tends to 1, indicating that the water body is completely visible. With the increase of the depth, the transparency value gradually decays, simulating the visibility decline caused by the absorption of light. When the depth exceeds the set upper limit, the transparency value tends to 0, realizing natural hiding, thereby avoiding the visual jump caused by the stepwise truncation.
[0103] In step S109, the basic shading result contains complete color information, and the Alpha channel is revalued as the transparency value obtained in step S108, thereby encoding the visual existence intensity of the water body.
[0104] In step S110, the Alpha channel of the first intermediate shading result is mixed with the Alpha channel of the color of the background scene, that is, the foreground water body and the rear land or deep sea background are weighted and superimposed according to the transparency value, so that the gradual evolution from the wet beach, shallow blue lagoon to deep sea can be realized at the pixel level, effectively eliminating the hard boundary and enhancing the realism and immersion experience of the coastal area.
[0105] In another optional implementation, after step S109, the spherical water body shading method provided by the embodiment of the application further includes steps S111-S114.
[0106] S111, generating a foam intensity coefficient based on the vertical depth difference, wherein the foam intensity coefficient exponentially decays or linearly decays with the increase of the vertical depth difference.
[0107] S112, superimpose the preset foam texture to the first intermediate shading result according to the foam intensity coefficient to generate a second intermediate shading result.
[0108] S113, apply time-varying UV coordinate offset to the preset caustic texture map to generate a dynamic caustic texture.
[0109] S114, superimpose the dynamic caustic texture to the second intermediate shading result to obtain the target shading result of the pixel to be rendered.
[0110] It should be understood that in the area where the surface of the water body meets the land, the visual features such as splashing and foam accumulation are often accompanied by natural phenomena, and these details play an important role in enhancing the immersion of the near-shore scene. The existing rendering method often uses fixed texture masks or static masks based on height maps when processing foam effects, which lacks the ability to dynamically respond to depth changes, resulting in unnatural foam distribution and inability to update in real time as the viewing angle or water level adjusts. In addition, the caustic phenomenon in underwater light and shadow is usually realized by using pre-baked maps, which makes it difficult to simulate the dynamic spot movement caused by sunlight penetrating the undulating water surface. Based on this, the present embodiment introduces a foam intensity modulation mechanism based on vertical depth difference driving, and combines a time-evolving dynamic caustic superposition strategy to realize the foam and caustic phenomena of the water body.
[0111] In step S111, the design of the foam intensity coefficient needs to follow the basic rule that the foam intensity is strong in shallow water and weak in deep water. It can be mapped by an exponential decay or linear decay function. Specifically, when the vertical depth difference is small, the foam intensity coefficient tends to a maximum value, corresponding to the near-shore shallow water or intertidal zone. As the depth increases, the foam intensity coefficient decreases at a set rate until it tends to zero, thereby realizing the effect that foam only appears significantly on the shore.
[0112] In step S112, the foam texture can be a two-dimensional image resource containing grayscale information, and the pixel value represents the local foam coverage density. In specific implementation, the corresponding pixel value can be obtained by mapping the texture coordinates to the position of the pixel to be rendered, and then adding the pixel value multiplied by the corresponding foam intensity coefficient to the color channel in the first intermediate shading result to obtain the second intermediate shading result.
[0113] In step S113, the caustic texture map is used to store the high-frequency fluctuating light intensity distribution pattern, which is used to simulate the effect of sunlight penetrating the water surface ripples and focusing on the water bottom. The UV coordinates of the caustic texture map are continuously offset according to the global time variable at each frame of rendering to form a slow flowing animation sequence, making the light spot appear natural and dynamic as it sways with the waves.
[0114] In step S114, the dynamic caustic texture is superimposed to the second intermediate shading result, and color fusion can be performed according to a certain transparency weight, so that the caustic highlight part moderately brightens the underlying color without complete coverage, and the original material property is retained. This process gives the bottom area of the water body dynamic light and shadow changes, which can significantly improve the realism when observing from the perspective of diving or shallow water.
[0115] In yet another optional implementation, after step S109, the spherical water body shading method provided by the embodiments of the present application further includes steps S115-S117.
[0116] In step S115, an exponential attenuation factor is calculated based on the vertical depth difference, wherein the exponential attenuation factor represents the degree of attenuation of light passing through the water body, and is used to simulate the influence of water body thickness on light propagation.
[0117] In step S116, the exponential attenuation factor is input into a pre-constructed subsurface scattering calculation model to simulate the absorption and scattering behavior of light in the water body, and generate a corresponding water body color of the pixel point to be rendered.
[0118] In step S117, the water body color, the target shading result, and a preset spherical atmospheric scattering color are weighted and mixed to obtain a final dynamic shading result of the pixel point to be rendered.
[0119] It should be understood that in a real natural environment, the water body is not a completely transparent medium, and it has a significant absorption and scattering effect on light. The light transmission in the shallow water area is strong, and the color is bright. The deep water area presents a dark blue or dark green tone, and the water color changes with the atmosphere during sunrise and sunset. Based on this, the embodiments introduce an exponential attenuation factor driven by the vertical depth difference, and couple it into the subsurface scattering calculation model, to realize dynamic shading that can reflect the medium characteristics of the water body.
[0120] In step S115, the exponential attenuation factor maps the nonlinear relationship between water depth and light intensity attenuation through an exponential function. As the vertical depth difference increases, the exponential attenuation factor rapidly decreases, simulating the energy weakening caused by scattering loss and selective absorption during light propagation, and reflecting the selective filtering effect of the water body on the spectral components at different depths.
[0121] In step S116, the subsurface scattering calculation model is designed based on the physical and optical principles of the translucent medium, and uses the exponential attenuation factor to regulate the hue and brightness response of the base water color. Specifically, in the shallow water area, the exponential attenuation factor is high, which can retain more spectral information other than short wavelengths, presenting a greenish or light blue color. In the deep water area, the exponential attenuation factor tends to zero, only retaining a very low intensity of dark blue component, forming a natural darkening effect in the deep sea.
[0122] In step S117, the target shading result contains the surface detail information such as water surface reflection, foam, and caustics that have been synthesized in the foregoing process, representing the top-level visual performance of the water body, and the water body color reflects the internal optical properties thereof. Meanwhile, the preset spherical atmospheric scattering color is derived from the global illumination system, records the sky radiation distribution under the current time (such as sunrise, noon, and sunset) and the solar elevation angle, and is used to simulate the influence of the atmospheric illumination condition on the overall hue of the water body. The three are weighted and mixed according to the respective contribution proportions, so as to ensure that the water body color dynamically evolves with the day and night alternation, weather change, and observation angle.
[0123] The spherical water body shading method provided by the embodiments of the present application is completed in a single pixel shader, without additional post-processing, and can be directly embedded into any rendering pipeline supporting HLSL / GLSL.
[0124] In order to perform the above-mentioned method embodiments and the corresponding steps in each possible implementation, an implementation of a spherical water body shading device is given below.
[0125] Please refer to Figure 4 , Figure 4 A block schematic diagram of a spherical water body shading device 100 provided by the embodiments of the present application is shown. The spherical water body shading device 100 is applied to an electronic device and includes an acquisition module 101, an execution module 102, and a shading module 103.
[0126] The acquisition module 101 is configured to acquire a set of to-be-rendered pixel points, the set of to-be-rendered pixel points including a plurality of to-be-rendered pixel points, each to-be-rendered pixel point having a corresponding world coordinate and world normal; and acquire light source parameters and a camera view direction required for a current rendering frame.
[0127] The execution module 102 is configured to, for each to-be-rendered pixel point, determine three-plane mixing weights of the to-be-rendered pixel point in three orthogonal directions of a three-dimensional rectangular coordinate system according to projection intensities of the world normal of the to-be-rendered pixel point in the three orthogonal directions; for each orthogonal direction, generate a world space normal component corresponding to the orthogonal direction based on the world coordinate of the to-be-rendered pixel point and a preset multi-scale texture mapping model; and perform weighted fusion on the world space normal components corresponding to the three orthogonal directions according to the three-plane mixing weights, to obtain a world space normal vector.
[0128] The shading module 103 is configured to perform shading calculation based on the world space normal vector, the light source parameters and the camera view direction required for the current rendering frame, and a preset water body optical model, to generate a basic shading result of the to-be-rendered pixel point.
[0129] Optionally, the obtaining module 101 performs the manner of obtaining the set of to-be-rendered pixel points, including: obtaining vertex data of the three-dimensional model, the vertex data including local coordinates and local normals of each vertex in the three-dimensional model in a local coordinate system; generating world coordinates and world normals of each vertex in a world coordinate system based on the vertex data, to obtain each transformed vertex; obtaining a plurality of triangular primitives based on each transformed vertex; for each triangular primitive, generating a plurality of to-be-rendered pixel points covering the triangular primitive and located in a screen space; generating world coordinates and world normals of each to-be-rendered pixel point based on the world coordinates and world normals of the vertices of the triangular primitive, and determining a screen coordinate of the to-be-rendered pixel point according to its position in the screen space, to obtain the set of to-be-rendered pixel points.
[0130] Optionally, each to-be-rendered pixel point also has a corresponding screen coordinate; the execution module 102 is further configured to: for each to-be-rendered pixel point, map the screen coordinate of the to-be-rendered pixel point to a threshold index in a set range using a pre-established Bayer dithering matrix; compare the threshold index with a preset dissolving factor; if the threshold index is less than the dissolving factor, discard the to-be-rendered pixel point, otherwise, perform the step of determining three-plane mixing weights of the to-be-rendered pixel point in three orthogonal directions according to projection intensities of the world normal of the to-be-rendered pixel point in the three orthogonal directions of a three-dimensional orthogonal coordinate system.
[0131] Optionally, the multi-scale texture mapping model includes a plurality of texture scaling levels; the execution module 102 performs the manner of generating the world space normal component corresponding to the orthogonal direction based on the world coordinates of the to-be-rendered pixel point and the preset multi-scale texture mapping model, including: generating a noise disturbance vector based on the world coordinates of the to-be-rendered pixel point; calculating low-frequency texture coordinates, medium-frequency texture coordinates, and high-frequency texture coordinates in each orthogonal direction according to the noise disturbance vector and the plurality of texture scaling levels; sampling the low-frequency texture coordinates, the medium-frequency texture coordinates, and the high-frequency texture coordinates in each orthogonal direction to obtain a plurality of normal sampling results in each orthogonal direction; using a nonlinear mixing algorithm based on normal redirection, weighting and fusing the plurality of normal sampling results in the same orthogonal direction in their respective tangent spaces to obtain an intermediate normal vector in each orthogonal direction; converting the intermediate normal vector in each orthogonal direction from the tangent space to the world space to obtain the world space normal vector corresponding to each orthogonal direction.
[0132] Optionally, the water body optical model comprises screen space reflection, and the light source parameters comprise a dynamic light source set and attributes thereof; the shading module 103 is specifically configured to: sample a preset environment cube map according to a world space normal vector to obtain a basic sky reflection color; calculate a reflection ray direction based on the world space normal vector and a camera view direction, and perform screen space reflection tracking on a rendered scene depth texture along the reflection ray direction, detect whether there is a pixel trajectory with continuous depth values along the ray path to determine whether a matchable screen space surface is hit; when it is confirmed that the matchable screen space surface is hit, obtain a color obtained by screen space reflection, and calculate a hit confidence; according to the hit confidence, the color obtained by screen space reflection and the basic sky reflection color are weighted and fused to generate a target reflection value; according to the dynamic light source set and the attributes thereof, each effective light source that has an impact on the pixel point to be rendered is screened out, and based on the world space normal vector, the camera view direction and the preset material parameters, the microfacet bidirectional reflectance distribution function model is used to calculate the specular reflection value and the diffuse reflection value of each effective light source respectively; the target reflection value and the specular reflection value and the diffuse reflection value of each effective light source are accumulated to obtain a basic shading result of the pixel point to be rendered.
[0133] Optionally, each pixel point to be rendered also has a corresponding screen coordinate; the shading module 103 is further configured to: sample a preset scene depth texture based on the screen coordinate of the pixel point to be rendered to obtain a terrain surface depth value corresponding to the position of the screen coordinate; calculate a vertical depth difference between the world space height of the water surface where the pixel point to be rendered is located and the terrain surface depth value; convert the vertical depth difference into a transparency value by using a nonlinear mapping function with a smooth transition characteristic; adjust the Alpha channel of the basic shading result of the pixel point to be rendered based on the transparency value to generate a first intermediate shading result; mix the Alpha channel of the first intermediate shading result with the Alpha channel of the color of the background scene to realize visual soft transition from land to deep sea area.
[0134] Optionally, the shading module 103 is further configured to: generate a foam intensity coefficient based on the vertical depth difference, wherein the foam intensity coefficient exponentially decays or linearly decays with the increase of the vertical depth difference; superimpose a preset foam texture onto the first intermediate shading result according to the foam intensity coefficient to generate a second intermediate shading result; generate a dynamic caustic texture by applying a time-varying UV coordinate offset to a preset caustic texture map; superimpose the dynamic caustic texture onto the second intermediate shading result to obtain the target shading result of the pixel point to be rendered.
[0135] Optionally, the shading module 103 is further configured to: calculate an exponential attenuation factor based on the vertical depth difference, wherein the exponential attenuation factor represents a degree of attenuation of the light ray when passing through the water body, and is used to simulate an effect of a thickness of the water body on light propagation; input the exponential attenuation factor into a pre-constructed subsurface scattering calculation model to simulate an absorption and scattering behavior of the light ray in the water body, and generate a corresponding water body color of the pixel point to be rendered; and perform weighted mixing on the water body color, the target shading result, and a preset spherical atmospheric scattering color to obtain a final dynamic shading result of the pixel point to be rendered.
[0136] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the spherical water body shading device 100 described above can refer to the corresponding process in the foregoing method embodiment, which will not be described here.
[0137] To sum up, the spherical water body shading method, device and electronic equipment provided by the embodiments of the present application first determine the three-plane mixing weight according to the projection intensity of the world normal of the pixel point to be rendered in three orthogonal directions of the three-dimensional rectangular coordinate system, then generate the world space normal component in each orthogonal direction based on the world coordinates of the pixel point to be rendered and the preset multi-scale texture mapping model, then perform weighted fusion on the world space normal components corresponding to the three orthogonal directions according to the three-plane mixing weight to obtain a unified world space normal vector, and finally perform shading calculation based on the world space normal vector, the light source parameter and the camera view direction required for the current rendering frame, and the preset water body optical model to generate the basic shading result of the pixel point to be rendered. In this way, through the multi-direction world space normal fusion mechanism guided by the three-plane weight, the seam and distortion problems in spherical mapping are effectively overcome, multi-level detail natural fusion and accurate light behavior restoration are realized, and the overall realism and geometric accuracy of the large-scale spherical water body in the real-time rendering scene are enhanced.
[0138] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. Those skilled in the art can make various modifications and changes to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method of coloring a spherical water body, characterized by, The method comprises: acquiring a set of to-be-rendered pixel points, the set of to-be-rendered pixel points comprising a plurality of to-be-rendered pixel points, each to-be-rendered pixel point having a corresponding world coordinate and a world normal; acquiring light source parameters and a camera perspective direction required for a current rendering frame; for each to-be-rendered pixel point, determining three-plane mixing weights of the to-be-rendered pixel point in three orthogonal directions of a three-dimensional rectangular coordinate system according to projection intensities of the world normal of the to-be-rendered pixel point in the three orthogonal directions; for each orthogonal direction, generating a world space normal component corresponding to the orthogonal direction based on the world coordinate of the to-be-rendered pixel point and a preset multi-scale texture mapping model; weighting and fusing the world space normal components corresponding to the three orthogonal directions according to the three-plane mixing weights to obtain a world space normal vector; performing shading calculation based on the world space normal vector, the light source parameters and the camera perspective direction required for the current rendering frame, and a preset water optical model to generate a basic shading result of the to-be-rendered pixel point.
2. The method of coloring a spherical body of water of claim 1, wherein, The step of acquiring the set of to-be-rendered pixel points comprises: acquiring vertex data of a three-dimensional model, the vertex data comprising local coordinates and local normals of each vertex in the three-dimensional model in a local coordinate system; generating world coordinates and world normals of each vertex in a world coordinate system based on the vertex data to obtain each transformed vertex; obtaining a plurality of triangular primitives based on each transformed vertex; generating a plurality of to-be-rendered pixel points covering each triangular primitive and located in a screen space for each triangular primitive; generating world coordinates and world normals of each to-be-rendered pixel point based on the world coordinates and world normals of the vertices of the triangular primitive, and determining screen coordinates of the to-be-rendered pixel point according to its position in the screen space to obtain the set of to-be-rendered pixel points.
3. The method of spheroid water body coloration of claim 1, wherein, Each to-be-rendered pixel point also has a corresponding screen coordinate; after the step of acquiring the set of to-be-rendered pixel points, the method further comprises: for each to-be-rendered pixel point, mapping the screen coordinate of the to-be-rendered pixel point to a threshold index within a specified range using a pre-established Bayer dithering matrix; comparing the threshold index with a preset dissolving factor; if the threshold index is less than the dissolving factor, discarding the to-be-rendered pixel point, otherwise, performing the step of determining three-plane mixing weights of the to-be-rendered pixel point in three orthogonal directions according to projection intensities of the world normal of the to-be-rendered pixel point in the three orthogonal directions.
4. The method of spheroid water body coloration of claim 1, wherein, The multi-scale texture mapping model comprises a plurality of texture scaling levels; The step of generating a world space normal component corresponding to the orthogonal direction based on the world coordinate of the to-be-rendered pixel point and a preset multi-scale texture mapping model comprises: generating a noise disturbance vector based on the world coordinate of the to-be-rendered pixel point; calculating low-frequency texture coordinates, medium-frequency texture coordinates and high-frequency texture coordinates in each orthogonal direction according to the noise disturbance vector and the plurality of texture scaling levels; sampling a corresponding normal map for each of the low-frequency texture coordinates, the medium-frequency texture coordinates and the high-frequency texture coordinates in each of the orthogonal directions to obtain a plurality of normal sampling results in each of the orthogonal directions; performing weighted fusion of the plurality of normal sampling results in the same orthogonal direction in their respective tangent spaces to obtain an intermediate normal vector in each of the orthogonal directions by using a nonlinear blending algorithm based on normal reorientation; converting the intermediate normal vector in each of the orthogonal directions from the tangent space to the world space to obtain a world-space normal vector corresponding to each of the orthogonal directions.
5. The method of spheroidally coloring a body of water of claim 1 wherein, The water optical model includes screen-space reflection, and the light source parameters include a dynamic light source set and attributes thereof; The step of performing shading calculation based on the world-space normal vector, light source parameters required for the current rendering frame, a camera view direction and a preset water optical model to generate a basic shading result of the pixel point to be rendered includes: sampling a preset environment cube map according to the world-space normal vector to obtain a basic sky reflection color; calculating a reflection ray direction based on the world-space normal vector and the camera view direction, and performing screen-space reflection tracking on a rendered scene depth texture along the reflection ray direction to detect whether there is a pixel trajectory with continuous depth values along the ray path to determine whether a matchable screen-space surface is hit; when it is confirmed that the matchable screen-space surface is hit, obtaining a color obtained by screen-space reflection, and calculating a hit confidence; performing weighted fusion of the color obtained by screen-space reflection and the basic sky reflection color according to the hit confidence to generate a target reflection value; screening out each effective light source that has an impact on the pixel point to be rendered according to the dynamic light source set and the attributes thereof, and calculating a specular reflection value and a diffuse reflection value of each of the effective light sources by using a microfacet bidirectional reflectance distribution function model based on the world-space normal vector, the camera view direction and preset material parameters; accumulating the target reflection value and the specular reflection value and the diffuse reflection value of each of the effective light sources to obtain the basic shading result of the pixel point to be rendered.
6. The method of spheroid water body coloration of claim 1, wherein, Each of the pixel points to be rendered also has a corresponding screen coordinate; the method further includes: sampling a preset scene depth texture based on the screen coordinate of the pixel point to be rendered to obtain a terrain surface depth value corresponding to a position where the screen coordinate is located; calculating a vertical depth difference between a world-space height of a water surface where the pixel point to be rendered is located and the terrain surface depth value; converting the vertical depth difference into a transparency value by using a nonlinear mapping function with a smooth transition characteristic; adjusting an Alpha channel of the basic shading result of the pixel point to be rendered based on the transparency value to generate a first intermediate shading result; mixing the Alpha channel of the first intermediate shading result with an Alpha channel of a color of a background scene to realize visual soft transition from land to deep sea areas.
7. The method of coloring a spherical body of water of claim 6, wherein, The method further includes: generate a foam intensity coefficient based on the vertical depth difference, wherein the foam intensity coefficient exponentially or linearly decays with the increase of the vertical depth difference; superimpose a preset foam texture to the first intermediate shading result according to the foam intensity coefficient, to generate a second intermediate shading result; apply a time-varying UV coordinate offset to a preset plenoptic texture map, to generate a dynamic plenoptic texture; superimpose the dynamic plenoptic texture to the second intermediate shading result, to obtain a target shading result of the pixel point to be rendered.
8. The method of claim 7, wherein the ballasted water is a ballasted water for a ballast water tank of a ship. The method further comprises: calculate an exponential decay factor based on the vertical depth difference, wherein the exponential decay factor represents a degree of attenuation of a light ray passing through the water body, and is used to simulate an influence of a water body thickness on light propagation; input the exponential decay factor into a pre-constructed sub-surface scattering calculation model, to simulate absorption and scattering behaviors of the light ray in the water body, and generate a corresponding water body color of the pixel point to be rendered; perform weighted mixing of the water body color, the target shading result and a preset spherical atmospheric scattering color, to obtain a final dynamic shading result of the pixel point to be rendered.
9. A spherical water body coloring device, characterized by, The device comprises: an acquisition module, configured to acquire a set of pixel points to be rendered, the set of pixel points to be rendered comprising a plurality of pixel points to be rendered, each of the pixel points to be rendered having a corresponding world coordinate and world normal; and acquire light source parameters and a camera view direction required for a current rendering frame; an execution module, configured to, for each of the pixel points to be rendered, determine three-plane mixing weights of the pixel point to be rendered in three orthogonal directions of a three-dimensional rectangular coordinate system according to projection intensities of the world normal of the pixel point to be rendered in the three orthogonal directions; for each of the orthogonal directions, generate a world space normal component corresponding to the orthogonal direction based on the world coordinate of the pixel point to be rendered and a preset multi-scale texture mapping model; and perform weighted fusion on the world space normal components corresponding to the three orthogonal directions according to the three-plane mixing weights, to obtain a world space normal vector; a shading module, configured to perform shading calculation based on the world space normal vector, the light source parameters and the camera view direction required for the current rendering frame, and a preset water body optical model, to generate a basic shading result of the pixel point to be rendered.
10. An electronic device, comprising: A device comprises a processor, a memory and a graphics processing unit (GPU), the memory is configured to store computer program instructions, the processor is configured to execute the computer program instructions to control the GPU to perform graphics rendering; the GPU is configured to perform pixel shading operation according to the rendering instruction issued by the processor, to implement the spherical water body shading method in any one of claims 1-8.