Water surface rendering method, device, mobile terminal and storage medium
By completing the opaque and translucent rendering stages in the rendering pipeline of the mobile terminal, the sampling process obtains the water surface reflection and refraction effect data, solving the problem of lack of reflection and refraction effects of the mobile terminal water surface rendering, and achieving consistent water surface effects and improvements with the PC terminal user experience.
Patent Information
- Application Number
- CN202111643949.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-12-29
AI Technical Summary
The mobile terminal lacks real-time reflection and refraction effects when rendering the water surface, which leads to too much difference from the water surface effect rendered by the PC side, which cannot meet the art requirements, and has poor user experience.
Through the mobile rendering pipeline, the rendering process of the opaque rendering stage and the translucent rendering stage is completed, the color of the scene to be sampled is obtained, and the reflection effect data and refraction effect data of the water surface are obtained respectively.
The reflection and refractive effects of the water surface are rendered, so that the water surface effect rendered by the mobile terminal is consistent with that of the PC terminal, meeting the requirements of the art, and improving the user's experience in the game.
Smart Images

Figure CN114299217B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image rendering technology, and in particular to a water surface rendering method, device, mobile terminal and storage medium. Background Art
[0002] UE4 (Unreal Engine 4) uses the water surface rendering system (SingleLayerWater, the system responsible for water surface rendering in UE4) to render the water surface in the game world. This water surface rendering system supports not only PC (Personal Computer) terminals, but also mobile terminals. However, due to the performance difference between PC terminals and mobile terminals, the use of the water surface rendering system has many limitations and missing functional features for mobile terminals. For example, the mobile terminal lacks real-time reflection effects and refraction effects. This makes the effects of the water surface rendered by the PC terminal and the mobile terminal too different. The effect of the water surface rendered by the mobile terminal does not meet the requirements of the art designer, and the user experience is not good. Summary of the invention
[0003] The embodiments of the present invention provide a water surface rendering method, device, mobile terminal and storage medium, which are used to achieve that the effects of water surfaces rendered by a PC terminal and a mobile terminal are consistent, so that the effects of water surfaces rendered by the mobile terminal can meet the artistic requirements, thereby improving the user experience in the game.
[0004] In a first aspect, an embodiment of the present invention provides a water surface rendering method, the method comprising:
[0005] The rendering pipeline corresponding to the mobile terminal completes the rendering process of the opaque rendering stage to obtain the scene color of the opaque rendering stage;
[0006] In the rendering pipeline, rendering processing is performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled;
[0007] In the semi-transparent rendering stage in the rendering pipeline, the scene color to be sampled is sampled to obtain reflection effect data and refraction effect data of the water surface respectively.
[0008] Optionally, the rendering process based on the scene color in the opaque rendering stage includes:
[0009] Create render textures;
[0010] The scene color of the opaque rendering stage stored in the color buffer is bound as input, and the rendering texture is set as a rendering target to perform rendering processing.
[0011] Optionally, the scene color of the opaque rendering stage stored in the binding color buffer is used as input, and the rendering texture is set as a rendering target to perform rendering processing, including:
[0012] In the pixel shader, the scene color of the opaque rendering stage stored in the color buffer is sampled and encoded, and the processing results of the sampling and encoding are output to the rendering texture.
[0013] Optionally, the sampling process of the color of the scene to be sampled to obtain the reflection effect data of the water surface includes:
[0014] In the pixel shader, obtain the fragment currently to be processed, and determine the world space coordinates of the reflected point corresponding to the fragment;
[0015] Obtaining the depth of the reflected point corresponding to the coordinates of the reflected point;
[0016] If the depth of the reflected point meets a preset condition, the color of the scene to be sampled is sampled and decoded to obtain the reflection effect data of the water surface.
[0017] Optionally, determining the world space coordinates of the reflected point corresponding to the fragment includes:
[0018] Get the coordinates corresponding to the fragment in screen space;
[0019] Determining coordinates corresponding to the fragment in world space based on coordinates corresponding to the fragment in screen space;
[0020] Get the position of the fragment relative to the camera;
[0021] determining a reflection vector based on a position of the fragment relative to the camera;
[0022] The coordinates corresponding to the fragment in the world space are stepped by a preset distance along the direction of the reflection vector to obtain the world space coordinates of the reflected point corresponding to the fragment.
[0023] Optionally, if the depth of the reflected point meets a preset condition, sampling and decoding the color of the scene to be sampled include:
[0024] Get the fragment depth corresponding to the fragment;
[0025] If the depth of the reflected point is greater than the fragment depth, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, the color of the scene to be sampled is sampled and decoded.
[0026] Optionally, the sampling process of the scene color to be sampled to obtain the refraction effect data of the water surface includes:
[0027] In the pixel shader, obtain the fragment that needs to be processed currently, and determine the coordinates of the water surface part corresponding to the fragment in the screen space;
[0028] Get the degree of distortion;
[0029] offsetting the coordinates corresponding to the fragment in the screen space based on the degree of distortion to obtain sampling coordinates;
[0030] The color of the scene to be sampled is sampled through the sampling coordinates to obtain the refraction effect data of the water surface.
[0031] Optionally, obtaining the degree of distortion includes:
[0032] Get the pixel normal and vertex normal in camera space;
[0033] Determining the difference of the vertex normal minus the pixel normal;
[0034] Multiplying the difference by the refractive index gives the degree of distortion.
[0035] In a second aspect, an embodiment of the present invention provides a water surface rendering device, comprising:
[0036] An opaque rendering module, used to complete the rendering process of the opaque rendering stage through the rendering pipeline corresponding to the mobile terminal, so as to obtain the scene color of the opaque rendering stage;
[0037] A full-screen rendering module, used for performing rendering processing based on the scene color in the opaque rendering stage in the rendering pipeline to obtain a scene color to be sampled;
[0038] The sampling module is used to sample the scene color to be sampled in the semi-transparent rendering stage in the rendering pipeline to obtain the reflection effect data and the refraction effect data of the water surface respectively.
[0039] Optionally, the full-screen rendering module is used to:
[0040] Create render textures;
[0041] The scene color of the opaque rendering stage stored in the color buffer is bound as input, and the rendering texture is set as a rendering target to perform rendering processing.
[0042] Optionally, the full-screen rendering module is used to:
[0043] In the pixel shader, the scene color of the opaque rendering stage stored in the color buffer is sampled and encoded, and the processing results of the sampling and encoding are output to the rendering texture.
[0044] Optionally, the sampling module is used to:
[0045] In the pixel shader, obtain the fragment currently to be processed, and determine the world space coordinates of the reflected point corresponding to the fragment;
[0046] Obtaining the depth of the reflected point corresponding to the coordinates of the reflected point;
[0047] If the depth of the reflected point meets a preset condition, the color of the scene to be sampled is sampled and decoded to obtain the reflection effect data of the water surface.
[0048] Optionally, the sampling module is used to:
[0049] Get the coordinates corresponding to the fragment in screen space;
[0050] Determining coordinates corresponding to the fragment in world space based on coordinates corresponding to the fragment in screen space;
[0051] Get the position of the fragment relative to the camera;
[0052] determining a reflection vector based on a position of the fragment relative to the camera;
[0053] The coordinates corresponding to the fragment in the world space are stepped by a preset distance along the direction of the reflection vector to obtain the world space coordinates of the reflected point corresponding to the fragment.
[0054] Optionally, the sampling module is used to:
[0055] Get the fragment depth corresponding to the fragment;
[0056] If the depth of the reflected point is greater than the fragment depth, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, the color of the scene to be sampled is sampled and decoded.
[0057] Optionally, the sampling module is used to:
[0058] In the pixel shader, obtain the fragment that needs to be processed currently, and determine the coordinates of the water surface part corresponding to the fragment in the screen space;
[0059] Get the degree of distortion;
[0060] offsetting the coordinates corresponding to the fragment in the screen space based on the degree of distortion to obtain sampling coordinates;
[0061] The color of the scene to be sampled is sampled through the sampling coordinates to obtain the refraction effect data of the water surface.
[0062] Optionally, the sampling module is used to:
[0063] Get the pixel normal and vertex normal in camera space;
[0064] Determining the difference of the vertex normal minus the pixel normal;
[0065] Multiplying the difference by the refractive index gives the degree of distortion.
[0066] In a third aspect, an embodiment of the present invention provides a mobile terminal, which includes a processor and a memory, wherein the memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the water surface rendering method in the first aspect.
[0067] In a fourth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of a mobile terminal, the processor can at least implement the water surface rendering method in the first aspect.
[0068] By adopting the present invention, the scene color in the opaque rendering stage can be obtained, and then full-screen rendering can be performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled. Finally, the scene color to be sampled can be sampled to obtain the reflection effect data and refraction effect data of the water surface respectively. Through the above method, the rendering of the reflection effect and refraction effect of the water surface is realized, so that the effect of the water surface rendered by the PC end and the mobile end is consistent, so that the effect of the water surface rendered by the mobile end can meet the artistic requirements, thereby improving the user experience in the game. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0070] Figure 1 A schematic diagram of a flow chart of a water surface rendering method provided by an embodiment of the present invention;
[0071] Figure 2A schematic diagram of a water surface rendering effect provided by an embodiment of the present invention;
[0072] Figure 3 A schematic structural diagram of a water surface rendering device provided by an embodiment of the present invention;
[0073] Figure 4 A structural diagram of a mobile terminal provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0074] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0075] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two.
[0076] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0077] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.
[0078] Figure 1 The flowchart of a water surface rendering method provided by an embodiment of the present invention can be applied to a mobile terminal. Figure 1 As shown, the method comprises the following steps:
[0079] 101. Complete the rendering process of the opaque rendering stage through the rendering pipeline corresponding to the mobile terminal to obtain the scene color of the opaque rendering stage.
[0080] 102. In the rendering pipeline, rendering processing is performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled.
[0081] 103. In the semi-transparent rendering stage of the rendering pipeline, the scene color to be sampled is sampled to obtain the reflection effect data and the refraction effect data of the water surface respectively.
[0082] In the practical application of the present invention, the process of rendering the water surface in the rendering pipeline in the mobile terminal is divided into several stages, including an opaque rendering stage, a semi-transparent rendering stage, etc. The execution order of these stages is: opaque rendering stage; semi-transparent rendering stage. That is, after completing the previous stage, enter the next stage for rendering processing.
[0083] The first stage is the opaque rendering stage. In this stage, the opaque objects in the scene can be rendered, and after rendering, the scene color corresponding to the opaque rendering stage will be output. In the opaque rendering process, RenderTarget can be used as the rendering target, so that the scene color corresponding to the opaque rendering stage will be accumulated and output to RenderTarget.
[0084] The accumulation means that if there are some other scene colors in the RenderTarget before the opaque rendering stage, the output scene colors after the rendering process of the opaque rendering stage will be superimposed with some other scene colors originally in the RenderTarget. If the opaque rendering stage is the first rendering stage executed and there are no other rendering stages before it, then there are no other scene colors in the RenderTarget. After the accumulation output, the RenderTarget will only have the scene colors corresponding to the opaque rendering stage.
[0085] Based on this, when cumulative output is mentioned in the embodiments of the present invention, it means that the scene color obtained by the rendering process of the current rendering stage is superimposed on some other scene colors originally in the RenderTarget, and the final superposition result still exists in the RenderTarget.
[0086] In the rendering pipeline, the scene color of the opaque rendering stage can be used for rendering processing to obtain the scene color to be sampled. Optionally, the process of using the scene color of the opaque rendering stage for rendering processing can be implemented as follows: creating a rendering texture (RenderTexture); binding the scene color of the opaque rendering stage stored in the color buffer (ColorBuffer) as input, and setting the rendering texture as a rendering target (RenderTarget) for rendering processing.
[0087] In some optional embodiments, the rendering texture may be named SceneColorCopy. Through the above operations, the scene colors obtained through the above rendering process are cumulatively output to SceneColorCopy.
[0088] In some optional embodiments, the data format corresponding to the SceneColorCopy can be set to RGBA32.
[0089] In some optional embodiments, the size of the SceneColorCopy can be set to be smaller than the resolution of the final rendered image. For example, if the resolution of the final rendered image is 1920*1080, the size of the SceneColorCopy can be set to 960*540 or 480*270 accordingly.
[0090] It is understandable that the smaller the size of SceneColorCopy, the lower the amount of calculation on the mobile terminal and the higher the rendering performance on the mobile terminal. However, if the size of SceneColorCopy is too small, the reflection and refraction effects obtained by rendering will become blurred.
[0091] Optionally, the scene color of the opaque rendering stage stored in the bound color buffer mentioned above is used as input, and the rendering texture is set as the rendering target. The rendering process can be implemented as follows: in the pixel shader (PixelShader), the scene color of the opaque rendering stage stored in the color buffer is sampled and encoded, and the processing results of the sampling and encoding processing are output to the rendering texture.
[0092] It should be noted that in the above process, the scene color sampled from the color buffer needs to be encoded because the data format of the scene color stored in the color buffer may be R16G16B16A16. The encoding process can improve the dark details and retain the accuracy to a certain extent.
[0093] In some optional embodiments, the scene color can be encoded by the following function:
[0094] Pow(Color*0.1,0.25)
[0095] Among them, Pow() is an exponential function used in the high-level shader language HLSL.
[0096] After the above rendering process is completed, the scene color to be sampled can be sampled to obtain the reflection effect data and refraction effect data of the water surface. In other words, the scene color in SceneColorCopy can be sampled to obtain the reflection effect data and refraction effect data of the water surface.
[0097] It should be noted that the reflection and refraction effects of the water surface are rendered in the semi-transparent rendering stage. In the semi-transparent rendering stage, the water surface model is rendered, and the reflection and refraction effects of the water surface are rendered. The rendering process of the semi-transparent rendering stage is implemented by multiple drawing commands (i.e., Draw commands, which refer to the CPU's call to the graphics drawing interface. The CPU commands the GPU to perform rendering operations by calling the graphics library (directx / opengl) interface). For the first Draw command in the semi-transparent rendering stage (the first Draw command is used to render the SingleLayerWater model, and the SingleLayerWater model can be used to simulate the effect of a transparent water surface), SceneColorCopy and a depth buffer (DepthBuffer) can be used as inputs, and the reflection, refraction, and other processing of the water surface in the water surface rendering method provided in the embodiment of the present invention are implemented in the geometry channel (BasePass, BasePass refers to the Pass of the water surface rendering, which is used to render the water surface). Among them, DepthBuffer is set to read-only and not write-only.
[0098] Optionally, the process of sampling the sampled scene color to obtain the reflection effect data of the water surface can be implemented as follows: in the pixel shader, obtain the fragment that needs to be processed currently, and determine the world space coordinates of the reflected point corresponding to the fragment; obtain the depth of the reflected point corresponding to the reflected point; if the depth of the reflected point meets the preset conditions, sample and decode the scene color to obtain the reflection effect data of the water surface.
[0099] In some optional embodiments, the encoded scene color sampled from the scene color to be sampled may be decoded by the following function:
[0100] Pow(Color',4)*10
[0101] Here, Color' represents the encoded scene color obtained by encoding the scene color Color.
[0102] In an embodiment of the present invention, screen space reflection (Screen Space Reflection, SSR) is used to realize the reflection effect processing of the water surface. In this process, the fragment processed by the pixel shader is the fragment corresponding to the water surface model, and the pixel shader will render each fragment to be rendered in turn. For the fragment that needs to be processed currently, in some optional embodiments, optionally, the process of determining the world space coordinates of the reflected point corresponding to the fragment that needs to be processed currently can be implemented as follows: obtaining the coordinates corresponding to the fragment in the screen space; based on the coordinates corresponding to the fragment in the screen space, determining the coordinates corresponding to the fragment in the world space; obtaining the position of the fragment relative to the camera; based on the position of the fragment relative to the camera, determining the reflection vector; stepping a preset distance from the coordinates corresponding to the fragment in the world space along the direction of the reflection vector to obtain the world space coordinates of the reflected point.
[0103] It should be noted that each fragment to be rendered corresponds to a portion of the water surface. For the fragment currently to be processed, it corresponds to a reflected point in the screen space, and the world space coordinates of the reflected point can be determined in the above manner.
[0104] After determining the world space coordinates of the reflected point corresponding to the fragment currently to be processed, the depth of the reflected point corresponding to the reflected point can be obtained. Specifically, the world space coordinates of the reflected point can be mapped to the screen space to obtain the screen space coordinates of the reflected point by UV sampling, and the DepthBuffer can be sampled based on the screen space coordinates of the reflected point to obtain the depth corresponding to the reflected point.
[0105] Next, determine whether the depth of the reflected point meets the preset conditions. If the depth of the reflected point meets the preset conditions, SceneColorCopy can be sampled and decoded to obtain the reflection effect data of the water surface. Specifically, the screen space coordinates of the reflected point can be used as sampling coordinates, and SceneColorCopy can be sampled using the sampling coordinates to obtain undecoded color data. Then, the undecoded color data can be decoded and the decoded data can be used as the color reflected by the water surface, that is, the reflection color of the pixel corresponding to the fragment currently to be processed.
[0106] Optionally, the above judgment process can be implemented as follows: obtaining the fragment depth corresponding to the fragment; if the depth of the reflected point is greater than the fragment depth, and the angle between the camera's sight vector and the reflection vector is greater than a preset angle, sampling and decoding SceneColorCopy.
[0107] In some optional embodiments, the preset angle may be 90°.
[0108] It should be noted that the coordinates (SvPosition) corresponding to the water surface portion of the fragment in the screen space may be obtained, and then the fragment depth corresponding to the fragment may be determined based on the SvPosition.
[0109] In some optional embodiments, if the reflection effect obtained is flickering from the perspective of viewing, blurring can be performed in the above-mentioned sampling SceneColorCopy process. Specifically, a sampler (including but not limited to a Gather sampler) can be used to sample the colors of 4 pixels and take the average value.
[0110] The above describes the process of rendering reflection effects, and the following describes the process of rendering refraction effects. Optionally, the process of sampling the scene color to be sampled to obtain the refraction effect data of the water surface can be implemented as follows: in the pixel shader, obtain the fragment that needs to be processed currently, determine the coordinates of the water surface part corresponding to the fragment in the screen space; obtain the degree of distortion; offset the coordinates corresponding to the fragment in the screen space based on the degree of distortion to obtain the sampling coordinates; sample the scene color to be sampled through the sampling coordinates to obtain the refraction effect data of the water surface, that is, the color of the pixel point corresponding to the fragment that needs to be processed currently.
[0111] It should be noted that, when the value of the distortion degree is larger, the offset degree of the sampling coordinates relative to the corresponding coordinates of the fragment in the screen space is larger.
[0112] Optionally, the process of obtaining the degree of distortion may be implemented as follows: obtaining the pixel normal and the vertex normal in the camera space (View space); determining the difference between the vertex normal and the pixel normal; and multiplying the difference by the refraction coefficient to obtain the degree of distortion.
[0113] It should be noted that the above pixel normal is the pixel normal of the pixel point corresponding to the fragment that the pixel shader currently needs to process. The pixel normal is calculated in the material editor, and the flow effect of the water surface can be achieved based on the pixel normal. The above vertex normal is obtained by converting the vector (0,0,1) in the tangent space to the View space. The above refraction coefficient is a value given in the material, that is, the refraction coefficient corresponds to the material, and different materials correspond to different refraction coefficients.
[0114] In addition, because the part below the water surface has been obtained by sampling, AlphaBlend (a function used to display an image with a specified transparency) is no longer needed, and the alpha in the output color needs to be changed to 1.
[0115] It should be noted that the height fog effect in the mobile terminal is calculated in BasePass, which means that the fog effect of underwater objects is included in SceneColorCopy. If the fog effect of the water surface is calculated again after normal water surface rendering, the fog effect in the transparent area will be aggravated. In an embodiment of the present invention, the fog effect of underwater objects can be calculated in the pixel shader based on the depth, and the color of the fog effect can be subtracted when calculating the distortion. However, because the above process is implemented in the pixel shader, the processing performance of the mobile terminal is poor.
[0116] Optionally, after sampling the color of the scene to be sampled through the sampling coordinates to obtain the refraction effect data of the water surface, the method provided by the embodiment of the present invention may also include: obtaining vertex fog data calculated in the vertex shader, and subtracting the vertex fog data from the refraction effect data of the water surface.
[0117] Through observation, it is found that the transparent areas on the water surface are mostly shallow water, and the depth difference between the water surface and the bottom is not large, so the vertex fog calculated in the water surface VS (vertex shader) can be used instead of the scene fog calculated in the pixel shader. By directly subtracting the vertex fog data when calculating the distortion, the step of calculating the fog effect of underwater objects in the pixel shader can be saved, which can greatly improve the processing performance of the mobile terminal.
[0118] In addition, for the ColorScaleBehindWater function in UE4 (the material node in the material ball of UE4 SingleLayerWater that is responsible for receiving underwater color), the related technology cannot use this function on the mobile terminal. However, the method provided in the embodiment of the present invention solves this problem while obtaining the scene color in the distortion.
[0119] Optionally, the method provided by an embodiment of the present invention may further include: obtaining the fragment depth and the depth in the depth buffer (DepthBuffer) through the SceneDepthWithoutWater (scene depth map without water depth) node in the material editor; subtracting the depth in the DepthBuffer from the fragment depth to obtain the depth difference; if the depth difference is less than a preset threshold, removing the highlight reflection effect.
[0120] In some optional embodiments, the GTAO (Ground Truth Ambient Occlusion) effect (an effect obtained by the ambient light occlusion algorithm) of the water surface in the mobile terminal can also be removed. The mobile terminal supports using the SceneDepthWithoutWater node in the material editor to obtain the depth, and the fragment depth and the depth difference in the DepthBuffer can be used to hide the reflection effect of the shore (wherein, if the depth difference is less than a preset threshold, the shore can be determined), so that the water surface and the shore can transition naturally.
[0121] An example of the effect of the water surface rendered by the method provided by the embodiment of the present invention can be seen as follows: Figure 2 shown.
[0122] By adopting the present invention, the scene color in the opaque rendering stage can be obtained, and then full-screen rendering can be performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled. Finally, the scene color to be sampled can be sampled to obtain the reflection effect data and refraction effect data of the water surface respectively. Through the above method, the rendering of the reflection effect and refraction effect of the water surface is realized, so that the effect of the water surface rendered by the PC end and the mobile end is consistent, so that the effect of the water surface rendered by the mobile end can meet the artistic requirements, thereby improving the user experience in the game.
[0123] The water surface rendering device of one or more embodiments of the present invention will be described in detail below. Those skilled in the art will appreciate that these water surface rendering devices can be configured using commercially available hardware components through the steps taught in this solution.
[0124] Figure 3 A schematic diagram of the structure of a water surface rendering device provided by an embodiment of the present invention is shown in FIG. Figure 3 As shown, the device comprises:
[0125] An opaque rendering module 31 is used to complete the rendering process of the opaque rendering stage through the rendering pipeline corresponding to the mobile terminal to obtain the scene color of the opaque rendering stage;
[0126] A full-screen rendering module 32, configured to perform rendering processing based on the scene color in the opaque rendering stage in the rendering pipeline to obtain a scene color to be sampled;
[0127] The sampling module 33 is used to perform sampling processing on the color of the scene to be sampled in the semi-transparent rendering stage of the rendering pipeline to obtain reflection effect data and refraction effect data of the water surface respectively.
[0128] Optionally, the full-screen rendering module 32 is used to:
[0129] Create render textures;
[0130] The scene color of the opaque rendering stage stored in the color buffer is bound as input, and the rendering texture is set as a rendering target to perform rendering processing.
[0131] Optionally, the full-screen rendering module 32 is used to:
[0132] In the pixel shader, the scene color of the opaque rendering stage stored in the color buffer is sampled and encoded, and the processing results of the sampling and encoding are output to the rendering texture.
[0133] Optionally, the sampling module 33 is used to:
[0134] In the pixel shader, obtain the fragment currently to be processed, and determine the world space coordinates of the reflected point corresponding to the fragment;
[0135] Obtaining the depth of the reflected point corresponding to the coordinates of the reflected point;
[0136] If the depth of the reflected point meets a preset condition, the color of the scene to be sampled is sampled and decoded to obtain the reflection effect data of the water surface.
[0137] Optionally, the sampling module 33 is used to:
[0138] Get the coordinates corresponding to the fragment in screen space;
[0139] Determining coordinates corresponding to the fragment in world space based on coordinates corresponding to the fragment in screen space;
[0140] Get the position of the fragment relative to the camera;
[0141] determining a reflection vector based on a position of the fragment relative to the camera;
[0142] The coordinates corresponding to the fragment in the world space are stepped by a preset distance along the direction of the reflection vector to obtain the world space coordinates of the reflected point corresponding to the fragment.
[0143] Optionally, the sampling module 33 is used to:
[0144] Get the fragment depth corresponding to the fragment;
[0145] If the depth of the reflected point is greater than the fragment depth, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, the color of the scene to be sampled is sampled and decoded.
[0146] Optionally, the sampling module 33 is used to:
[0147] In the pixel shader, obtain the fragment that needs to be processed currently, and determine the world space coordinates of the corresponding reflected point corresponding to the fragment;
[0148] Get the degree of distortion;
[0149] offsetting the coordinates corresponding to the fragment in the screen space based on the degree of distortion to obtain sampling coordinates;
[0150] The color of the scene to be sampled is sampled through the sampling coordinates to obtain the refraction effect data of the water surface.
[0151] Optionally, the sampling module 33 is used to:
[0152] Get the pixel normal and vertex normal in camera space;
[0153] Determining the difference of the vertex normal minus the pixel normal;
[0154] Multiplying the difference by the refractive index gives the degree of distortion.
[0155] Figure 3 The device shown can perform the aforementioned Figure 1 to Figure 2 The water surface rendering method provided in the illustrated embodiment, the detailed execution process and technical effects thereof refer to the description in the aforementioned embodiment, which will not be repeated here.
[0156] In one possible design, the above Figure 3 The structure of the water surface rendering device shown can be implemented as a mobile terminal, such as Figure 4 As shown, the mobile terminal may include: a processor 91 and a memory 92. The memory 92 stores executable code. When the executable code is executed by the processor 91, the processor 91 can at least implement the above-mentioned Figure 1 to Figure 2 The water surface rendering method provided in the illustrated embodiment.
[0157] Optionally, the mobile terminal may also include a communication interface 93 for communicating with other devices.
[0158] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of a mobile terminal, the processor can at least implement the above-mentioned Figure 1 to Figure 2 The water surface rendering method provided in the illustrated embodiment.
[0159] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. Those of ordinary skill in the art may understand and implement the present invention without creative effort.
[0160] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a computer product, and the present invention can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0161] The water surface rendering method provided in the embodiment of the present invention can be executed by a certain program / software, and the program / software can be provided by the network side. The mobile terminal mentioned in the above embodiment can download the program / software to a local non-volatile storage medium, and when it needs to execute the above water surface rendering method, the program / software is read into the memory by the CPU, and then the CPU executes the program / software to implement the water surface rendering method provided in the above embodiment. The execution process can refer to the above Figure 1 to Figure 2 Instructions in .
[0162] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A water surface rendering method, characterized in that: include: The rendering pipeline corresponding to the mobile terminal completes the rendering process of the opaque rendering stage to obtain the scene color of the opaque rendering stage; In the rendering pipeline, rendering processing is performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled; In the semi-transparent rendering stage in the rendering pipeline, the color of the scene to be sampled is sampled to obtain reflection effect data and refraction effect data of the water surface respectively; The vertex fog data calculated in the vertex shader is obtained, and the vertex fog data is subtracted by the refraction effect of the water surface.
2. The method according to claim 1, characterized in that The rendering process based on the scene color in the opaque rendering stage includes: Create render textures; The scene color of the opaque rendering stage stored in the color buffer is bound as input, and the rendering texture is set as a rendering target to perform rendering processing.
3. The method according to claim 2, characterized in that The method further comprises: using the scene color of the opaque rendering stage stored in the binding color buffer as input, setting the rendering texture as a rendering target, and performing rendering processing, including: In the pixel shader, the scene color of the opaque rendering stage stored in the color buffer is sampled and encoded, and the processing results of the sampling and encoding are output to the rendering texture.
4. The method according to claim 1, characterized in that The sampling process of the color of the scene to be sampled to obtain the reflection effect data of the water surface includes: In the pixel shader, obtain the fragment currently to be processed, and determine the world space coordinates of the reflected point corresponding to the fragment; Obtaining the depth of the reflected point corresponding to the reflected point; If the depth of the reflected point meets a preset condition, the color of the scene to be sampled is sampled and decoded to obtain the reflection effect data of the water surface.
5. The method according to claim 4, characterized in that Determining the world space coordinates of the reflected point corresponding to the fragment includes: Get the coordinates corresponding to the fragment in screen space; Determining coordinates corresponding to the fragment in world space based on coordinates corresponding to the fragment in screen space; Get the position of the fragment relative to the camera; determining a reflection vector based on a position of the fragment relative to the camera; The coordinates corresponding to the fragment in the world space are stepped by a preset distance along the direction of the reflection vector to obtain the world space coordinates of the reflected point.
6. The method according to claim 5, characterized in that If the depth of the reflected point meets a preset condition, sampling and decoding the color of the scene to be sampled are performed, including: Get the fragment depth corresponding to the fragment; If the depth of the reflected point is greater than the fragment depth, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, the color of the scene to be sampled is sampled and decoded.
7. The method according to claim 1, characterized in that The sampling process of the scene color to be sampled to obtain the refraction effect data of the water surface includes: In the pixel shader, obtain the fragment that needs to be processed currently, and determine the coordinates of the water surface part corresponding to the fragment in the screen space; Get the degree of distortion; offsetting the coordinates corresponding to the fragment in the screen space based on the degree of distortion to obtain sampling coordinates; The color of the scene to be sampled is sampled through the sampling coordinates to obtain refraction effect data of the water surface.
8. The method according to claim 7, characterized in that The obtaining of the degree of distortion comprises: Get the pixel normal and vertex normal in camera space; Determining the difference of the vertex normal minus the pixel normal; Multiplying the difference by the refractive index gives the degree of distortion.
9. A water surface rendering device, characterized in that: include: An opaque rendering module, used to complete the rendering process of the opaque rendering stage through the rendering pipeline corresponding to the mobile terminal, so as to obtain the scene color of the opaque rendering stage; A full-screen rendering module, used for performing rendering processing based on the scene color in the opaque rendering stage in the rendering pipeline to obtain a scene color to be sampled; A sampling module is used to sample the scene color to be sampled in the semi-transparent rendering stage in the rendering pipeline to obtain the reflection effect data and refraction effect data of the water surface respectively; and the sampling module is also used to: obtain the vertex fog data calculated in the vertex shader, and subtract the vertex fog data with the refraction effect of the water surface.
10. A mobile terminal, characterized in that: include: A memory and a processor; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the water surface rendering method according to any one of claims 1 to 8.
11. A non-transitory machine-readable storage medium, characterized in that: The non-transitory machine-readable storage medium stores executable code, and when the executable code is executed by a processor of a mobile terminal, the processor executes the water surface rendering method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Scene rendering method and device, computer equipment and storage medium
CN112837402A
Reflection effect generation method and device, storage medium and computer equipment
CN112973121A