[go: up one dir, main page]

CN114299217A - Water surface rendering method and device, mobile terminal and storage medium - Google Patents

Water surface rendering method and device, mobile terminal and storage medium Download PDF

Info

Publication number
CN114299217A
CN114299217A CN202111643949.XA CN202111643949A CN114299217A CN 114299217 A CN114299217 A CN 114299217A CN 202111643949 A CN202111643949 A CN 202111643949A CN 114299217 A CN114299217 A CN 114299217A
Authority
CN
China
Prior art keywords
rendering
color
scene
water surface
sampling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111643949.XA
Other languages
Chinese (zh)
Other versions
CN114299217B (en
Inventor
殷龙飞
代天麒
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianjin Yake Interactive Technology Co ltd
Original Assignee
Tianjin Yake Interactive Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianjin Yake Interactive Technology Co ltd filed Critical Tianjin Yake Interactive Technology Co ltd
Priority to CN202111643949.XA priority Critical patent/CN114299217B/en
Publication of CN114299217A publication Critical patent/CN114299217A/en
Application granted granted Critical
Publication of CN114299217B publication Critical patent/CN114299217B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Image Generation (AREA)
  • Processing Or Creating Images (AREA)

Abstract

本发明实施例提供一种水面渲染方法、装置、移动端和存储介质,该方法包括:通过移动端对应的渲染管线完成不透明渲染阶段的渲染处理,以得到不透明渲染阶段的场景颜色;在渲染管线中,基于不透明渲染阶段的场景颜色进行渲染处理,以得到待采样场景颜色;在渲染管线中的半透明渲染阶段,对待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。实现了水面的反射效果和折射效果的渲染,进而使得PC端和移动端渲染出的水面的效果是一致的,让移动端渲染出的水面的效果能够达到美工要求,从而提高用户在游戏中的体验感。

Figure 202111643949

Embodiments of the present invention provide a water surface rendering method, device, mobile terminal, and storage medium. The method includes: completing rendering processing in the opaque rendering stage through a rendering pipeline corresponding to the mobile terminal, so as to obtain the scene color in the opaque rendering stage; In the rendering process, based on the scene color in the opaque rendering stage, the rendering process is performed to obtain the scene color to be sampled; in the translucent rendering stage in the rendering pipeline, the sampling process is performed on the scene color to be sampled to obtain the reflection effect data and refraction effect data of the water surface respectively. . It realizes the rendering of the reflection effect and refraction effect of the water surface, so that the effect of the water surface rendered on the PC and the mobile terminal is consistent, so that the effect of the water surface rendered on the mobile terminal can meet the artistic requirements, thereby improving the user's experience in the game. experience.

Figure 202111643949

Description

水面渲染方法、装置、移动端和存储介质Water surface rendering method, device, mobile terminal and storage medium

技术领域technical field

本发明涉及图像渲染技术领域,尤其涉及一种水面渲染方法、装置、移动端和存储介质。The present invention relates to the technical field of image rendering, and in particular, to a water surface rendering method, device, mobile terminal and storage medium.

背景技术Background technique

UE4(虚幻引擎4)通过水面渲染系统(SingleLayerWater,UE4中负责水面渲染的系统)实现对游戏世界中的水面的渲染,该水面渲染系统不仅支持PC(Personal Computer,个人计算机)端,也支持移动端。但出于PC端和移动端之间性能差异的考虑,对于移动端来说,水面渲染系统的使用有诸多的限制和功能特性的缺失。比如说,移动端缺少实时反射效果、缺少折射效果。这使得PC端和移动端渲染出的水面的效果差别过大,移动端渲染出的水面的效果达不到美工要求,用户体验不佳。UE4 (Unreal Engine 4) realizes the rendering of the water surface in the game world through the water surface rendering system (SingleLayerWater, the system responsible for water surface rendering in UE4). The water surface rendering system not only supports the PC (Personal Computer, personal computer) side, but also supports mobile end. However, due to the performance difference between the PC and the mobile terminal, for the mobile terminal, the use of the water surface rendering system has many limitations and lack of functional characteristics. For example, the mobile terminal lacks real-time reflection effects and lacks refraction effects. This makes the effect of the water surface rendered on the PC side and the mobile terminal too different. The effect of the water surface rendered on the mobile terminal does not meet the artistic requirements, and the user experience is not good.

发明内容SUMMARY OF THE INVENTION

本发明实施例提供一种水面渲染方法、装置、移动端和存储介质,用以实现使得PC端和移动端渲染出的水面的效果是一致的,让移动端渲染出的水面的效果能够达到美工要求,从而提高用户在游戏中的体验感。Embodiments of the present invention provide a water surface rendering method, device, mobile terminal, and storage medium, so as to make the water surface effects rendered by the PC terminal and the mobile terminal consistent, so that the effect of the water surface rendered by the mobile terminal can reach the artistic level requirements, so as to improve the user's experience in the game.

第一方面,本发明实施例提供一种水面渲染方法,该方法包括:In a first aspect, an embodiment of the present invention provides a water surface rendering method, which includes:

通过移动端对应的渲染管线完成不透明渲染阶段的渲染处理,以得到所述不透明渲染阶段的场景颜色;Complete the rendering processing 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;

在所述渲染管线中,基于所述不透明渲染阶段的场景颜色进行渲染处理,以得到待采样场景颜色;In the rendering pipeline, rendering processing is performed based on the scene color of the opaque rendering stage to obtain the scene color to be sampled;

在所述渲染管线中的半透明渲染阶段,对所述待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。In the translucent 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.

可选地,所述基于所述不透明渲染阶段的场景颜色进行渲染处理,包括:Optionally, the rendering processing based on the scene color of the opaque rendering stage includes:

创建渲染纹理;Create render textures;

绑定颜色缓存器中存储的所述不透明渲染阶段的场景颜色作为输入,并将所述渲染纹理设定为渲染目标,进行渲染处理。The scene color of the opaque rendering stage stored in the color buffer is bound as an input, and the rendering texture is set as a rendering target to perform rendering processing.

可选地,所述绑定颜色缓存器中存储的所述不透明渲染阶段的场景颜色作为输入,并将所述渲染纹理设定为渲染目标,进行渲染处理,包括: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, and rendering processing is performed, including:

在像素着色器中,对所述颜色缓存器中存储的所述不透明渲染阶段的场景颜色进行采样处理以及编码处理,将所述采样处理以及所述编码处理的处理结果输出到所述渲染纹理。In the pixel shader, sampling processing and encoding processing are performed on the scene color of the opaque rendering stage stored in the color buffer, and the processing result of the sampling processing and the encoding processing is output to the rendering texture.

可选地,所述对待采样场景颜色进行采样处理,以获得水面的反射效果数据,包括:Optionally, performing sampling processing on the color of the scene to be sampled to obtain reflection effect data on the water surface, including:

在像素着色器中,获取当前需要处理的片段,确定所述片段对应的被反射点的世界空间坐标;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 coordinates of the reflected point;

若所述被反射点深度满足预设条件,则对待采样场景颜色进行采样处理和解码处理,以获得水面的反射效果数据。If the depth of the reflected point satisfies the preset condition, the color of the scene to be sampled is sampled and decoded to obtain reflection effect data on the water surface.

可选地,所述确定所述片段对应的被反射点的世界空间坐标,包括:Optionally, the determining the world space coordinates of the reflected point corresponding to the fragment includes:

获取所述片段在屏幕空间中对应的坐标;Obtain the coordinates corresponding to the fragment in the screen space;

基于所述片段在屏幕空间中对应的坐标,确定所述片段在世界空间中对应的坐标;Determine the coordinates corresponding to the fragment in the world space based on the coordinates corresponding to the fragment in the screen space;

获取所述片段相对于相机的位置;Get the position of the fragment relative to the camera;

基于所述片段相对于所述相机的位置,确定反射向量;determining a reflection vector based on the position of the segment relative to the camera;

从所述片段在所述世界空间中对应的坐标沿所述反射向量的方向步进预设距离,得到所述片段对应的被反射点的世界空间坐标。Steps a preset distance along the direction of the reflection vector from the corresponding coordinates of the fragment in the world space to obtain the world space coordinates of the reflected point corresponding to the fragment.

可选地,所述若所述被反射点深度满足预设条件,则对待采样场景颜色进行采样处理和解码处理,包括:Optionally, if the depth of the reflected point satisfies a preset condition, then performing sampling processing and decoding processing on the color of the scene to be sampled, including:

获取所述片段对应的片段深度;obtain the fragment depth corresponding to the fragment;

若所述被反射点深度大于所述片段深度,且所述相机的视线向量与所述反射向量之间的夹角大于预设角度,则对待采样场景颜色进行采样处理和解码处理。If the depth of the reflected point is greater than the depth of the segment, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, sampling processing and decoding processing are performed on the color of the scene to be sampled.

可选地,所述对待采样场景颜色进行采样处理,以获得水面的折射效果数据,包括:Optionally, performing sampling processing on the color of the scene to be sampled to obtain refraction effect data on the water surface, including:

在像素着色器中,获取当前需要处理的片段,确定所述片段对应的水面部分在屏幕空间中对应的坐标;In the pixel shader, obtain the fragment that needs to be processed currently, and determine the coordinates corresponding to the water surface part corresponding to the fragment in the screen space;

获取扭曲程度;get the degree of distortion;

基于所述扭曲程度对所述片段在所述屏幕空间中对应的坐标进行偏移,得到采样坐标;Offset the coordinates corresponding to the fragment in the screen space based on the distortion degree to obtain sampling coordinates;

通过所述采样坐标对待采样场景颜色进行采样,得到水面的折射效果数据。The color of the scene to be sampled is sampled by the sampling coordinates to obtain the refraction effect data of the water surface.

可选地,所述获取扭曲程度,包括:Optionally, the obtaining the distortion degree includes:

获取相机空间的像素法线以及顶点法线;Get pixel normals and vertex normals in camera space;

确定所述顶点法线减去所述像素法线的差值;determining the difference between the vertex normal and the pixel normal;

用所述差值乘以折射系数,得到扭曲程度。The degree of distortion is obtained by multiplying the difference by the index of refraction.

第二方面,本发明实施例提供一种水面渲染装置,包括:In a second aspect, an embodiment of the present invention provides a water surface rendering device, including:

不透明渲染模块,用于通过移动端对应的渲染管线完成不透明渲染阶段的渲染处理,以得到所述不透明渲染阶段的场景颜色;The opaque rendering module is used to complete the rendering processing 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, configured to perform rendering processing based on the scene color in the opaque rendering stage in the rendering pipeline to obtain the scene color to be sampled;

采样模块,用于在所述渲染管线中的半透明渲染阶段,对所述待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。The sampling module is used for sampling the color of the scene to be sampled in the translucent rendering stage in the rendering pipeline, so as to obtain the reflection effect data and the refraction effect data of the water surface respectively.

可选地,所述全屏渲染模块,用于:Optionally, the full-screen rendering module is used for:

创建渲染纹理;Create render textures;

绑定颜色缓存器中存储的所述不透明渲染阶段的场景颜色作为输入,并将所述渲染纹理设定为渲染目标,进行渲染处理。The scene color of the opaque rendering stage stored in the color buffer is bound as an input, and the rendering texture is set as a rendering target to perform rendering processing.

可选地,所述全屏渲染模块,用于:Optionally, the full-screen rendering module is used for:

在像素着色器中,对所述颜色缓存器中存储的所述不透明渲染阶段的场景颜色进行采样处理以及编码处理,将所述采样处理以及所述编码处理的处理结果输出到所述渲染纹理。In the pixel shader, sampling processing and encoding processing are performed on the scene color of the opaque rendering stage stored in the color buffer, and the processing result of the sampling processing and the encoding processing is output to the rendering texture.

可选地,所述采样模块,用于:Optionally, the sampling module is used for:

在像素着色器中,获取当前需要处理的片段,确定所述片段对应的被反射点的世界空间坐标;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 coordinates of the reflected point;

若所述被反射点深度满足预设条件,则对待采样场景颜色进行采样处理和解码处理,以获得水面的反射效果数据。If the depth of the reflected point satisfies the preset condition, the color of the scene to be sampled is sampled and decoded to obtain reflection effect data on the water surface.

可选地,所述采样模块,用于:Optionally, the sampling module is used for:

获取所述片段在屏幕空间中对应的坐标;Obtain the coordinates corresponding to the fragment in the screen space;

基于所述片段在屏幕空间中对应的坐标,确定所述片段在世界空间中对应的坐标;Determine the coordinates corresponding to the fragment in the world space based on the coordinates corresponding to the fragment in the screen space;

获取所述片段相对于相机的位置;Get the position of the fragment relative to the camera;

基于所述片段相对于所述相机的位置,确定反射向量;determining a reflection vector based on the position of the segment relative to the camera;

从所述片段在所述世界空间中对应的坐标沿所述反射向量的方向步进预设距离,得到所述片段对应的被反射点的世界空间坐标。Steps a preset distance along the direction of the reflection vector from the corresponding coordinates of the fragment in the world space to obtain the world space coordinates of the reflected point corresponding to the fragment.

可选地,所述采样模块,用于:Optionally, the sampling module is used for:

获取所述片段对应的片段深度;obtain the fragment depth corresponding to the fragment;

若所述被反射点深度大于所述片段深度,且所述相机的视线向量与所述反射向量之间的夹角大于预设角度,则对待采样场景颜色进行采样处理和解码处理。If the depth of the reflected point is greater than the depth of the segment, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, sampling processing and decoding processing are performed on the color of the scene to be sampled.

可选地,所述采样模块,用于:Optionally, the sampling module is used for:

在像素着色器中,获取当前需要处理的片段,确定所述片段对应的水面部分在屏幕空间中对应的坐标;In the pixel shader, obtain the fragment that needs to be processed currently, and determine the coordinates corresponding to the water surface part corresponding to the fragment in the screen space;

获取扭曲程度;get the degree of distortion;

基于所述扭曲程度对所述片段在所述屏幕空间中对应的坐标进行偏移,得到采样坐标;Offset the coordinates corresponding to the fragment in the screen space based on the distortion degree to obtain sampling coordinates;

通过所述采样坐标对待采样场景颜色进行采样,得到水面的折射效果数据。The color of the scene to be sampled is sampled by the sampling coordinates to obtain the refraction effect data of the water surface.

可选地,所述采样模块,用于:Optionally, the sampling module is used for:

获取相机空间的像素法线以及顶点法线;Get pixel normals and vertex normals in camera space;

确定所述顶点法线减去所述像素法线的差值;determining the difference between the vertex normal and the pixel normal;

用所述差值乘以折射系数,得到扭曲程度。The degree of distortion is obtained by multiplying the difference by the index of refraction.

第三方面,本发明实施例提供一种移动端,其中包括处理器和存储器,其中,所述存储器上存储有可执行代码,当所述可执行代码被所述处理器执行时,使所述处理器至少可以实现第一方面中的水面渲染方法。In a third aspect, an embodiment of the present invention provides a mobile terminal, which includes a processor and a memory, wherein executable code is stored on the memory, and when the executable code is executed by the processor, the The processor may at least implement the water surface rendering method in the first aspect.

第四方面,本发明实施例提供了一种非暂时性机器可读存储介质,所述非暂时性机器可读存储介质上存储有可执行代码,当所述可执行代码被移动端的处理器执行时,使所述处理器至少可以实现第一方面中的水面渲染方法。In a fourth aspect, an embodiment of the present invention provides a non-transitory machine-readable storage medium, where executable code is stored on the non-transitory machine-readable storage medium, and when the executable code is executed by a processor of a mobile terminal At the time, the processor can at least implement the water surface rendering method in the first aspect.

采用本发明,可以获取不透明渲染阶段的场景颜色,然后基于不透明渲染阶段的场景颜色进行全屏渲染,得到待采样场景颜色。最后可以对待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。通过上述方式,实现了水面的反射效果和折射效果的渲染,进而使得PC端和移动端渲染出的水面的效果是一致的,让移动端渲染出的水面的效果能够达到美工要求,从而提高用户在游戏中的体验感。By adopting the present invention, the scene color in the opaque rendering stage can be acquired, and then full-screen rendering is performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled. Finally, the color of the scene to be sampled can be sampled to obtain the reflection effect data and the refraction effect data of the water surface respectively. Through the above method, the rendering of the reflection effect and the refraction effect of the water surface is realized, so that the effect of the water surface rendered by the PC terminal and the mobile terminal is consistent, so that the effect of the water surface rendered by the mobile terminal can meet the artistic requirements, thereby improving the user experience. experience in the game.

附图说明Description of drawings

为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.

图1为本发明实施例提供的一种水面渲染方法的流程示意图;FIG. 1 is a schematic flowchart of a water surface rendering method according to an embodiment of the present invention;

图2为本发明实施例提供的一种水面渲染的效果示意图;FIG. 2 is a schematic diagram of an effect of water surface rendering provided by an embodiment of the present invention;

图3为本发明实施例提供的一种水面渲染装置的结构示意图;3 is a schematic structural diagram of a water surface rendering apparatus according to an embodiment of the present invention;

图4为本发明实施例提供的一种移动端的结构示意图。FIG. 4 is a schematic structural diagram of a mobile terminal according to an embodiment of the present invention.

具体实施方式Detailed ways

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments These are some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

在本发明实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本发明。在本发明实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义,“多种”一般包含至少两种。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," "the," and "the" as used in the embodiments of the present invention and the appended claims are intended to include the plural forms as well, unless the context clearly dictates otherwise, "a plurality" Generally at least two are included.

取决于语境,如在此所使用的词语“如果”、“若”可以被解释成为“在……时”或“当……时”或“响应于确定”或“响应于检测”。类似地,取决于语境,短语“如果确定”或“如果检测(陈述的条件或事件)”可以被解释成为“当确定时”或“响应于确定”或“当检测(陈述的条件或事件)时”或“响应于检测(陈述的条件或事件)”。Depending on the context, the words "if", "if" as used herein may be interpreted as "at" or "when" or "in response to determining" or "in response to detecting". Similarly, the phrases "if determined" or "if detected (the stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detected (the stated condition or event)," depending on the context )" or "in response to detection (a stated condition or event)".

另外,下述各方法实施例中的步骤时序仅为一种举例,而非严格限定。In addition, the sequence of steps in the following method embodiments is only an example, and is not strictly limited.

图1为本发明实施例提供的一种水面渲染方法的流程图,该方法可以应用于移动端。如图1所示,该方法包括如下步骤:FIG. 1 is a flowchart of a water surface rendering method provided by an embodiment of the present invention, and the method can be applied to a mobile terminal. As shown in Figure 1, the method includes the following steps:

101、通过移动端对应的渲染管线完成不透明渲染阶段的渲染处理,以得到不透明渲染阶段的场景颜色。101. Complete the rendering processing 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.

102、在渲染管线中,基于不透明渲染阶段的场景颜色进行渲染处理,以得到待采样场景颜色。102. In the rendering pipeline, perform rendering processing based on the scene color in the opaque rendering stage to obtain the scene color to be sampled.

103、在渲染管线中的半透明渲染阶段,对待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。103. In the translucent rendering stage in the rendering pipeline, perform sampling processing on the color of the scene to be sampled, so as to obtain reflection effect data and refraction effect data of the water surface respectively.

在本发明实际应用中,在移动端中的渲染管线中对水面渲染的过程分为几个阶段,包括不透明渲染阶段、半透明渲染阶段等。这几个阶段依次的执行顺序是:不透明渲染阶段;半透明渲染阶段。也就是说,在完成前面的阶段之后,进入到下一阶段进行渲染处理。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 translucent rendering stage, and the like. The order of execution of these stages is: opaque rendering stage; translucent rendering stage. That is to say, after completing the previous stage, it goes to the next stage for rendering processing.

首先进入到的是不透明渲染阶段。在该阶段中,可以对场景中的不透明物体进行渲染处理,经过渲染处理之后会输出不透明渲染阶段对应的场景颜色。在不透明渲染过程中,可以以RenderTarget作为渲染目标,这样不透明渲染阶段对应的场景颜色就会累计输出到RenderTarget中。The first thing to enter 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. During the opaque rendering process, the RenderTarget can be used as the rendering target, so that the scene colors corresponding to the opaque rendering stage will be accumulated and output to the RenderTarget.

其中,累计指的是如果在进行不透明渲染阶段之前RenderTarget中原本有一些其他场景颜色,则经过不透明渲染阶段的渲染处理之后输出的场景颜色会与RenderTarget中原本就有的一些其他场景颜色进行叠加。如果不透明渲染阶段是第一个执行的渲染阶段,在其之前不存在其他渲染阶段,那么RenderTarget中没有其他场景颜色,则累计输出后RenderTarget中仅有不透明渲染阶段对应的场景颜色。Among them, accumulation means that if there are some other scene colors in RenderTarget before the opaque rendering stage, the output scene color after rendering processing in the opaque rendering stage will be superimposed with some other scene colors originally in RenderTarget. If the opaque rendering stage is the first executed rendering stage and there are no other rendering stages before it, then there are no other scene colors in the RenderTarget, and only the scene color corresponding to the opaque rendering stage in the RenderTarget after the cumulative output.

基于此,当本发明实施例中提及累计输出时,指的是将经过当前渲染阶段的渲染处理得到的场景颜色叠加到RenderTarget中原本就有的一些其他场景颜色,最终的叠加结果还是存在于RenderTarget中。Based on this, when the cumulative output is mentioned in the embodiment of the present invention, it refers to superimposing the scene color obtained by the rendering process in the current rendering stage to some other scene colors originally in the RenderTarget, and the final superposition result still exists in the RenderTarget.

在渲染管线中,可以使用不透明渲染阶段的场景颜色进行渲染处理,以得到待采样场景颜色。可选地,该使用不透明渲染阶段的场景颜色进行渲染处理的过程可以实现为:创建渲染纹理(RenderTexture);绑定颜色缓存器(ColorBuffer)中存储的不透明渲染阶段的场景颜色作为输入,并将渲染纹理设定为渲染目标(RenderTarget),进行渲染处理。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 may be implemented as: creating a rendering texture (RenderTexture); binding the scene color of the opaque rendering stage stored in the color buffer (ColorBuffer) as input, and using The rendering texture is set as the rendering target (RenderTarget) for rendering processing.

在某些可选实施例中,该渲染纹理可以命名为SceneColorCopy。通过上述操作,经过上述渲染处理得到的场景颜色就累计输出到SceneColorCopy中。In some alternative embodiments, the render texture may be named SceneColorCopy. Through the above operations, the scene colors obtained through the above rendering processing are cumulatively output to SceneColorCopy.

在某些可选实施例中,该SceneColorCopy对应的数据格式可以设定为RGBA32。In some optional embodiments, the data format corresponding to the SceneColorCopy may be set to RGBA32.

在某些可选实施例中,可以将该SceneColorCopy的尺寸设定为小于最终渲染出的画面的分辨率。比如说,最终渲染出的画面的分辨率为1920*1080,则SceneColorCopy的尺寸可以相应设定为960*540或者480*270。In some optional embodiments, the size of the SceneColorCopy may be set to be smaller than the resolution of the final rendered picture. For example, if the resolution of the final rendered picture is 1920*1080, the size of SceneColorCopy can be set to 960*540 or 480*270 accordingly.

可以理解的是,SceneColorCopy的尺寸越小,移动端的计算量越低,移动端的渲染性能越高。但是,如果SceneColorCopy的尺寸过低,则渲染获得的反射效果以及折射效果会变得模糊。It is understandable that the smaller the size of SceneColorCopy, the lower the calculation amount of the mobile terminal, and the higher the rendering performance of the mobile terminal. However, if the size of the SceneColorCopy is too low, the resulting reflections and refractions will be blurred.

可选地,前文提及的绑定颜色缓存器中存储的不透明渲染阶段的场景颜色作为输入,并将渲染纹理设定为渲染目标,进行渲染处理的过程可以实现为:在像素着色器(PixelShader)中,对颜色缓存器中存储的不透明渲染阶段的场景颜色进行采样处理以及编码处理,将采样处理以及编码处理的处理结果输出到渲染纹理。Optionally, the scene color of the opaque rendering stage stored in the aforementioned binding color buffer is used as input, and the rendering texture is set as the rendering target, and the process of rendering processing can be implemented as: ), perform sampling processing and encoding processing on the scene color of the opaque rendering stage stored in the color buffer, and output the processing results of the sampling processing and encoding processing to the rendering texture.

需要说明的是,在上述过程中需要对从颜色缓存器中采样得到的场景颜色进行编码处理是因为,颜色缓存器中存储的场景颜色的数据格式可能是R16G16B16A16,通过编码处理可以一定程度提升暗部细节并保留精度。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, and the dark part can be improved to a certain extent through encoding processing. detail and preserve precision.

在某些可选实施例中,可以通过如下函数对场景颜色进行编码处理:In some optional embodiments, the scene color can be encoded by the following functions:

Pow(Color*0.1,0.25)Pow(Color*0.1,0.25)

其中,Pow()是高阶着色器语言HLSL中用到的一种指数函数。Among them, Pow() is an exponential function used in the high-level shader language HLSL.

在完成上述渲染处理之后,可以对待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。也就是说,可以对SceneColorCopy中的场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。After the above rendering process is completed, the color of the scene to be sampled may be sampled to obtain reflection effect data and refraction effect data of the water surface, respectively. That is to say, the scene color in SceneColorCopy can be sampled to obtain the reflection effect data and the refraction effect data of the water surface respectively.

需要说明的是,渲染水面的反射效果和折射效果是在半透明渲染阶段中完成的。在半透明渲染阶段,渲染水面模型,并实现水面的反射效果和折射效果的渲染。半透明渲染阶段的渲染处理是通过多个绘制命令(即Draw命令,指的是CPU对图形绘制接口的调用,CPU通过调用图形库(directx/opengl)接口,命令GPU进行渲染操作)实现的。对于半透明渲染阶段的第一个Draw命令(第一个Draw命令用于渲染SingleLayerWater模型,SingleLayerWater模型可以用于模拟透明水面的效果)来说,可以将SceneColorCopy以及深度缓存器(DepthBuffer)作为输入,并在几何通道(BasePass,BasePass指的是水面渲染的Pass,用于渲染水面)中实现本发明实施例中提供的水面渲染方法中水面的反射、折射等处理。其中,DepthBuffer是设置为只读不写的。It should be noted that the reflection and refraction effects of rendering the water surface are completed in the translucent rendering stage. In the translucent rendering stage, the water surface model is rendered, and the reflection and refraction effects of the water surface are rendered. The rendering processing in the translucent rendering stage is realized through multiple drawing commands (ie, Draw commands, which refer to the call of the CPU to the graphics drawing interface, and the CPU instructs the GPU to perform rendering operations by calling the graphics library (directx/opengl) interface). For the first Draw command in the translucent 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), you can use SceneColorCopy and the depth buffer (DepthBuffer) as input, The reflection, refraction and other processing of the water surface in the water surface rendering method provided in the embodiment of the present invention is implemented in the geometry channel (BasePass, BasePass refers to the Pass for water surface rendering, which is used for rendering the water surface). Among them, DepthBuffer is set to read only and not write.

可选地,对待采样场景颜色进行采样处理,以获得水面的反射效果数据的过程可以实现为:在像素着色器中,获取当前需要处理的片段,确定片段对应的被反射点的世界空间坐标;获取被反射点对应的被反射点深度;若被反射点深度满足预设条件,则对待采样场景颜色进行采样处理和解码处理,以获得水面的反射效果数据。Optionally, the process of performing sampling processing on the color of the scene to be sampled to obtain the reflection effect data on the water surface can be implemented as follows: in the pixel shader, the fragment that needs to be processed currently is obtained, and the world space coordinate of the reflected point corresponding to the fragment is determined; The depth of the reflected point corresponding to the reflected point is obtained; if the depth of the reflected point satisfies the preset condition, the color of the scene to be sampled is sampled and decoded to obtain the reflection effect data on the water surface.

在某些可选实施例中,可以通过如下函数对从待采样场景颜色中采样得到的编码后的场景颜色进行解码:In some optional embodiments, the encoded scene color sampled from the scene color to be sampled can be decoded by the following function:

Pow(Color’,4)*10Pow(Color',4)*10

其中,Color’表示对场景颜色Color编码后得到的编码后的场景颜色。Among them, Color' represents the encoded scene color obtained by encoding the scene color Color.

在本发明实施例中,使用屏幕空间反射(Screen Space Reflection,SSR)实现水面的反射效果处理。在该过程中,像素着色器处理的片段即水面模型对应的片段,像素着色器会依次对各待渲染的片段进行渲染。对于当前需要处理的片段来说,在某些可选实施例中,可选地,确定当前需要处理的片段对应的被反射点的世界空间坐标的过程可以实现为:获取片段在屏幕空间中对应的坐标;基于片段在屏幕空间中对应的坐标,确定片段在世界空间中对应的坐标;获取片段相对于相机的位置;基于片段相对于相机的位置,确定反射向量;从片段在世界空间中对应的坐标沿反射向量的方向步进预设距离,得到被反射点的世界空间坐标。In this embodiment of the present invention, a 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 currently to be processed, in some optional embodiments, optionally, the process of determining the world space coordinates of the reflected point corresponding to the fragment currently to be processed may be implemented as: obtaining the corresponding fragment in the screen space based on the corresponding coordinates of the fragment in the screen space, determine the corresponding coordinates of the fragment in the world space; obtain the position of the fragment relative to the camera; determine the reflection vector based on the position of the fragment relative to the camera; from the fragment corresponding to the world space The coordinates of , step a preset distance in the direction of the reflection vector to obtain the world space coordinates of the reflected point.

需要说明的是,每个待渲染的片段与一部分水面相对应。对于当前需要处理的片段来说,它在屏幕空间中对应存在一个被反射点,该被反射点的世界空间坐标可以通过上述方式确定得出。It should be noted that each segment to be rendered corresponds to a part of the water surface. For the fragment that needs to be processed currently, it corresponds to a reflected point in the screen space, and the world space coordinate of the reflected point can be determined by the above method.

在确定出当前需要处理的片段对应的被反射点的世界空间坐标之后,可以获取被反射点对应的被反射点深度。具体来说,可以通过UV采样的方式,将被反射点的世界空间坐标映射至屏幕空间得到被反射点的屏幕空间坐标,基于被反射点的屏幕空间坐标对DepthBuffer进行采样,得到被反射点对应的深度。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 by means of UV sampling to obtain the screen space coordinates of the reflected point, and the DepthBuffer is sampled based on the screen space coordinates of the reflected point to obtain the corresponding point of the reflected point. depth.

接着,判断被反射点深度是否满足预设条件。如果被反射点深度满足预设条件,则可以对SceneColorCopy进行采样处理和解码处理,以获得水面的反射效果数据。具体来说,可以以被反射点的屏幕空间坐标作为采样坐标,用采样坐标对SceneColorCopy进行采样处理,得到未解码的颜色数据。然后,可以对该未解码的颜色数据进行解码处理,将解码后的数据作为水面反射的颜色,即当前需要处理的片段所对应的像素点的反射颜色。Next, it is judged whether the depth of the reflected point satisfies the preset condition. If the depth of the reflected point satisfies the preset condition, the SceneColorCopy can be sampled and decoded to obtain the reflection effect data of the water surface. Specifically, the screen space coordinates of the reflected points can be used as sampling coordinates, and the sampling coordinates can be used to perform sampling processing on SceneColorCopy to obtain undecoded color data. Then, decoding processing can be performed on the undecoded color data, and the decoded data can be used as the color reflected by the water surface, that is, the reflected color of the pixel corresponding to the segment to be processed currently.

可选地,上述判断过程可以实现为:获取片段对应的片段深度;若被反射点深度大于片段深度,且相机的视线向量与反射向量之间的夹角大于预设角度,则对SceneColorCopy进行采样处理和解码处理。Optionally, the above judgment process can be implemented as: obtaining the depth of the segment corresponding to the segment; if the depth of the reflected point is greater than the depth of the segment, and the angle between the sight vector of the camera and the reflection vector is greater than the preset angle, then sample SceneColorCopy. processing and decoding processing.

在某些可选实施例中,上述预设角度可以是90°。In some optional embodiments, the above-mentioned preset angle may be 90°.

需要说明的是,可以获取片段对应的水面部分在屏幕空间中对应的坐标(SvPosition),然后基于该SvPosition确定出片段对应的片段深度。It should be noted that the coordinates (SvPosition) corresponding to the water surface part corresponding to the fragment in the screen space can be obtained, and then the fragment depth corresponding to the fragment can be determined based on the SvPosition.

在某些可选实施例中,倘若取得的反射效果从观看上是闪烁的,可以在上述采样SceneColorCopy的过程中进行模糊处理。具体来说,可以使用采样器(包括但不限于Gather采样器)采样取4个像素的颜色并取平均值。In some optional embodiments, if the obtained reflection effect is flickering in view, blurring processing may be performed in the above-mentioned process of sampling SceneColorCopy. Specifically, a sampler (including but not limited to a Gather sampler) can be used to sample the color of 4 pixels and take an average value.

上面介绍了渲染反射效果的过程,下面将介绍渲染折射效果的过程。可选地,对待采样场景颜色进行采样处理,以获得水面的折射效果数据的过程可以实现为:在像素着色器中,获取当前需要处理的片段,确定片段对应的水面部分在屏幕空间中对应的坐标;获取扭曲程度;基于扭曲程度对片段在屏幕空间中对应的坐标进行偏移,得到采样坐标;通过采样坐标对待采样场景颜色进行采样,得到水面的折射效果数据,即当前需要处理的片段所对应的像素点折射的颜色。The process of rendering reflection effects is described above, and the process of rendering refraction effects is described below. 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, and determine the corresponding water surface part of the fragment in the screen space. Coordinates; obtain the distortion degree; offset the corresponding coordinates of the fragment in the screen space based on the distortion degree to obtain the sampling coordinates; sample the color of the scene to be sampled through the sampling coordinates, and obtain the refraction effect data of the water surface, that is, the current fragment to be processed. The color of the refraction of the corresponding pixel point.

需要说明的是,当扭曲程度的值越大时,采样坐标相对于片段在屏幕空间中对应的坐标的偏移程度越大。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.

可选地,上述获取扭曲程度的过程可以实现为:获取相机空间(View空间)的像素法线以及顶点法线;确定顶点法线减去像素法线的差值;用差值乘以折射系数,得到扭曲程度。Optionally, the above-mentioned process of obtaining the degree of distortion may be implemented as: 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; multiplying the difference by the refraction coefficient. , to get the degree of distortion.

需要说明的是,上述像素法线为像素着色器当前需要处理的片段对应的像素点的像素法线,该像素法线在材质编辑器中计算得出,基于该像素法线可以实现水面的流动效果。上述顶点法线是切线空间的向量(0,0,1)转到View空间得到的。上述折射系数是材质中给定的值,即折射系数与材质对应,不同的材质对应不同的折射系数。It should be noted that the above-mentioned pixel normal is the pixel normal of the pixel corresponding to the fragment that the pixel shader currently needs to process. The pixel normal is calculated in the material editor, and the flow of the water surface can be realized based on this pixel normal. Effect. The above vertex normals are obtained by transferring the vector (0, 0, 1) of the tangent space to the View space. The above-mentioned refraction coefficient is a given value in the material, that is, the refraction coefficient corresponds to the material, and different materials correspond to different refraction coefficients.

此外,因为水面以下的部分已经通过采样得到,因此不再需要AlphaBlend(一种函数,用于显示具有指定透明度的图像),需要将输出颜色中alpha改为1。In addition, because the part below the water surface has been sampled, 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.

需要注意的是,移动端中的高度雾效果是在BasePass中计算的,这也就代表着SceneColorCopy中是包含了水下物体的雾效的。如果在经过正常的水面渲染后又计算了一遍水面的雾效,则会使透明区域的雾效加重。在本发明实施例中可以基于深度在像素着色器中计算水下物体的雾效,并在计算扭曲时减去雾效的颜色。但因为在像素着色器中实现上述过程,导致移动端的处理性能较差。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 the normal water surface rendering, the fog effect of the transparent area will be increased. In the embodiment of the present invention, the fog effect of the underwater object may be calculated in the pixel shader based on the depth, and the color of the fog effect may 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.

可选地,在通过采样坐标对待采样场景颜色进行采样,得到水面的折射效果数据之后,本发明实施例提供的方法还可以包括:获取顶点着色器中计算得到的顶点雾数据,用水面的折射效果数据减去该顶点雾数据。Optionally, after sampling the color of the scene to be sampled by sampling coordinates to obtain refraction effect data on the water surface, the method provided by the embodiment of the present invention may further include: acquiring vertex fog data calculated in a vertex shader, and refraction of the water surface. The effect data minus the fog data for this vertex.

通过观察发现,水面的透明区域多是浅水,水面与水底深度差并不大,所以可以使用水面VS(顶点着色器)中计算的顶点雾代替像素着色器中计算的场景雾。采用直接在计算扭曲时减去顶点雾数据的方式,可以节省掉在像素着色器中计算水下物体的雾效的步骤,这样可以大大提高移动端的处理性能。Through observation, it is found that the transparent areas of the water surface are mostly shallow water, and the depth difference between the water surface and the water bottom is not large, so the vertex fog calculated in the water surface VS (vertex shader) can be used to replace the scene fog calculated in the pixel shader. By directly subtracting the vertex fog data when calculating the distortion, the steps 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.

另外,对于UE4中的ColorScaleBehindWater(UE4 SingleLayerWater的材质球中负责接收水下颜色的材质节点)功能来说,相关技术无法在移动端使用该功能,而采用本发明实施例提供的方法,在扭曲中得到场景颜色的同时也解决了此问题。In addition, for the ColorScaleBehindWater function in UE4 (the material node responsible for receiving the underwater color in the shader of UE4 SingleLayerWater), the related technology cannot use this function on the mobile terminal, and the method provided by the embodiment of the present invention is used. Getting the scene color also solved the problem.

可选地,本发明实施例提供的方法还可以包括:通过材质编辑器中的SceneDepthWithoutWater(不包含水深度的场景深度图)节点获取片段深度以及深度缓冲(DepthBuffer)中的深度;用片段深度减去DepthBuffer中的深度得到深度差;若深度差小于预设阈值,则去除高光反射效果。Optionally, the method provided by the 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; Go to the depth in the DepthBuffer to get the depth difference; if the depth difference is less than the preset threshold, the highlight reflection effect is removed.

在某些可选实施例中,还可以移除移动端中的水面的GTAO(Ground TruthAmbient Occlusion)效果(一种通过环境光遮蔽算法获得的效果)。移动端支持在材质编辑器中使用SceneDepthWithoutWater节点获取深度,可以使用片段深度和DepthBuffer中的深度差对岸边的反射效果做消隐(其中,若深度差小于预设阈值,则可确定出岸边),这样可以使水面与岸边自然地过渡。In some optional embodiments, the GTAO (Ground Truth Ambient Occlusion) effect (an effect obtained by an ambient light occlusion algorithm) of the water surface in the mobile terminal can also be removed. The mobile terminal supports the use of the SceneDepthWithoutWater node to obtain the depth in the material editor. You can use the fragment depth and the depth difference in the DepthBuffer to hide the reflection effect of the shore (wherein, if the depth difference is less than the preset threshold, the shore can be determined. ), which allows a natural transition between the water surface and the shore.

最终采用本发明实施例提供的方法渲染出的水面的效果的一种示例可见图2所示。An example of the effect of the water surface finally rendered by the method provided by the embodiment of the present invention is shown in FIG. 2 .

采用本发明,可以获取不透明渲染阶段的场景颜色,然后基于不透明渲染阶段的场景颜色进行全屏渲染,得到待采样场景颜色。最后可以对待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。通过上述方式,实现了水面的反射效果和折射效果的渲染,进而使得PC端和移动端渲染出的水面的效果是一致的,让移动端渲染出的水面的效果能够达到美工要求,从而提高用户在游戏中的体验感。By adopting the present invention, the scene color in the opaque rendering stage can be acquired, and then full-screen rendering is performed based on the scene color in the opaque rendering stage to obtain the scene color to be sampled. Finally, the color of the scene to be sampled can be sampled to obtain the reflection effect data and the refraction effect data of the water surface respectively. Through the above method, the rendering of the reflection effect and the refraction effect of the water surface is realized, so that the effect of the water surface rendered by the PC terminal and the mobile terminal is consistent, so that the effect of the water surface rendered by the mobile terminal can meet the artistic requirements, thereby improving the user experience. experience in the game.

以下将详细描述本发明的一个或多个实施例的水面渲染装置。本领域技术人员可以理解,这些水面渲染装置均可使用市售的硬件组件通过本方案所教导的步骤进行配置来构成。The water surface rendering apparatus according to one or more embodiments of the present invention will be described in detail below. Those skilled in the art can understand that these water surface rendering apparatuses can be configured by using commercially available hardware components through the steps taught in this solution.

图3为本发明实施例提供的一种水面渲染装置的结构示意图,如图3所示,该装置包括:FIG. 3 is a schematic structural diagram of a water surface rendering device according to an embodiment of the present invention. As shown in FIG. 3 , the device includes:

不透明渲染模块31,用于通过移动端对应的渲染管线完成不透明渲染阶段的渲染处理,以得到所述不透明渲染阶段的场景颜色;The 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, so as to obtain the scene color of the opaque rendering stage;

全屏渲染模块32,用于在所述渲染管线中,基于所述不透明渲染阶段的场景颜色进行渲染处理,以得到待采样场景颜色;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 the scene color to be sampled;

采样模块33,用于在所述渲染管线中的半透明渲染阶段,对待采样场景颜色进行采样处理,以分别获得水面的反射效果数据和折射效果数据。The sampling module 33 is configured to perform sampling processing on the color of the scene to be sampled in the translucent rendering stage in the rendering pipeline, so as to obtain the reflection effect data and the refraction effect data of the water surface respectively.

可选地,所述全屏渲染模块32,用于:Optionally, the full-screen rendering module 32 is used for:

创建渲染纹理;Create render textures;

绑定颜色缓存器中存储的所述不透明渲染阶段的场景颜色作为输入,并将所述渲染纹理设定为渲染目标,进行渲染处理。The scene color of the opaque rendering stage stored in the color buffer is bound as an input, and the rendering texture is set as a rendering target to perform rendering processing.

可选地,所述全屏渲染模块32,用于:Optionally, the full-screen rendering module 32 is used for:

在像素着色器中,对所述颜色缓存器中存储的所述不透明渲染阶段的场景颜色进行采样处理以及编码处理,将所述采样处理以及所述编码处理的处理结果输出到所述渲染纹理。In the pixel shader, sampling processing and encoding processing are performed on the scene color of the opaque rendering stage stored in the color buffer, and the processing result of the sampling processing and the encoding processing is output to the rendering texture.

可选地,所述采样模块33,用于:Optionally, the sampling module 33 is used for:

在像素着色器中,获取当前需要处理的片段,确定所述片段对应的被反射点的世界空间坐标;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;

获取所述被反射点坐标对应的被反射点深度;obtaining the depth of the reflected point corresponding to the coordinates of the reflected point;

若所述被反射点深度满足预设条件,则对待采样场景颜色进行采样处理和解码处理,以获得水面的反射效果数据。If the depth of the reflected point satisfies the preset condition, the color of the scene to be sampled is sampled and decoded to obtain reflection effect data on the water surface.

可选地,所述采样模块33,用于:Optionally, the sampling module 33 is used for:

获取所述片段在屏幕空间中对应的坐标;Obtain the coordinates corresponding to the fragment in the screen space;

基于所述片段在屏幕空间中对应的坐标,确定所述片段在世界空间中对应的坐标;Determine the coordinates corresponding to the fragment in the world space based on the coordinates corresponding to the fragment in the screen space;

获取所述片段相对于相机的位置;Get the position of the fragment relative to the camera;

基于所述片段相对于所述相机的位置,确定反射向量;determining a reflection vector based on the position of the segment relative to the camera;

从所述片段在所述世界空间中对应的坐标沿所述反射向量的方向步进预设距离,得到所述片段对应的被反射点的世界空间坐标。Stepping a preset distance along the direction of the reflection vector from the corresponding coordinates of the fragment in the world space, the world space coordinates of the reflected point corresponding to the fragment are obtained.

可选地,所述采样模块33,用于:Optionally, the sampling module 33 is used for:

获取所述片段对应的片段深度;obtain the fragment depth corresponding to the fragment;

若所述被反射点深度大于所述片段深度,且所述相机的视线向量与所述反射向量之间的夹角大于预设角度,则对待采样场景颜色进行采样处理和解码处理。If the depth of the reflected point is greater than the depth of the segment, and the angle between the sight vector of the camera and the reflection vector is greater than a preset angle, sampling processing and decoding processing are performed on the color of the scene to be sampled.

可选地,所述采样模块33,用于:Optionally, the sampling module 33 is used for:

在像素着色器中,获取当前需要处理的片段,确定所述片段对应的对应的被反射点的世界空间坐标;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;

获取扭曲程度;get the degree of distortion;

基于所述扭曲程度对所述片段在所述屏幕空间中对应的坐标进行偏移,得到采样坐标;Offset the coordinates corresponding to the fragment in the screen space based on the distortion degree to obtain sampling coordinates;

通过所述采样坐标对待采样场景颜色进行采样,得到水面的折射效果数据。The color of the scene to be sampled is sampled by the sampling coordinates to obtain the refraction effect data of the water surface.

可选地,所述采样模块33,用于:Optionally, the sampling module 33 is used for:

获取相机空间的像素法线以及顶点法线;Get pixel normals and vertex normals in camera space;

确定所述顶点法线减去所述像素法线的差值;determining the difference between the vertex normal and the pixel normal;

用所述差值乘以折射系数,得到扭曲程度。The degree of distortion is obtained by multiplying the difference by the index of refraction.

图3所示装置可以执行前述图1至图2所示实施例中提供的水面渲染方法,详细的执行过程和技术效果参见前述实施例中的描述,在此不再赘述。The apparatus shown in FIG. 3 can execute the water surface rendering method provided in the embodiments shown in the foregoing FIG. 1 to FIG. 2 . For the detailed execution process and technical effects, refer to the descriptions in the foregoing embodiments, which will not be repeated here.

在一个可能的设计中,上述图3所示水面渲染装置的结构可实现为一移动端,如图4所示,该移动端可以包括:处理器91、存储器92。其中,所述存储器92上存储有可执行代码,当所述可执行代码被所述处理器91执行时,使所述处理器91至少可以实现如前述图1至图2所示实施例中提供的水面渲染方法。In a possible design, the structure of the water surface rendering apparatus shown in FIG. 3 may be implemented as a mobile terminal. As shown in FIG. 4 , the mobile terminal may include: a processor 91 and a memory 92 . Wherein, the memory 92 stores executable codes, and when the executable codes are executed by the processor 91, the processor 91 can at least implement the implementation provided in the embodiments shown in the foregoing FIG. 1 to FIG. 2 . water surface rendering method.

可选地,该移动端中还可以包括通信接口93,用于与其他设备进行通信。Optionally, the mobile terminal may further include a communication interface 93 for communicating with other devices.

另外,本发明实施例提供了一种非暂时性机器可读存储介质,所述非暂时性机器可读存储介质上存储有可执行代码,当所述可执行代码被移动端的处理器执行时,使所述处理器至少可以实现如前述图1至图2所示实施例中提供的水面渲染方法。In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, where executable codes are stored on the non-transitory machine-readable storage medium, and when the executable codes are executed by the processor of the mobile terminal, The processor can at least implement the water surface rendering method provided in the above-mentioned embodiments shown in FIG. 1 to FIG. 2 .

以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The apparatus embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution in this embodiment. Those of ordinary skill in the art can understand and implement it without creative effort.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助加必需的通用硬件平台的方式来实现,当然也可以通过硬件和软件结合的方式来实现。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以计算机产品的形式体现出来,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。From 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 certainly can also be implemented by combining hardware and software. Based on this understanding, the above-mentioned technical solutions can be embodied in the form of computer products in essence or that make contributions to the prior art. In the form of a computer program product embodied on a medium (including but not limited to disk storage, CD-ROM, optical storage, etc.).

本发明实施例提供的水面渲染方法可以由某种程序/软件来执行,该程序/软件可以由网络侧提供,前述实施例中提及的移动端可以将该程序/软件下载到本地的非易失性存储介质中,并在其需要执行前述水面渲染方法时,通过CPU将该程序/软件读取到内存中,进而由CPU执行该程序/软件以实现前述实施例中所提供的水面渲染方法,执行过程可以参见前述图1至图2中的示意。The water surface rendering method provided by the embodiment of the present invention may be executed by a certain program/software, the program/software may be provided by the network side, and the mobile terminal mentioned in the foregoing embodiment may download the program/software to a local non-easy In the volatile storage medium, and when it needs to execute the aforementioned water surface rendering method, the program/software is read into the memory by the CPU, and then the program/software is executed by the CPU to realize the water surface rendering method provided in the foregoing embodiment. , and the execution process may refer to the schematic diagrams in the aforementioned FIG. 1 to FIG. 2 .

最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand: it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (11)

1. A method of water surface rendering, comprising:
finishing the rendering processing of an opaque rendering stage through a rendering pipeline corresponding to the mobile terminal to obtain the scene color of the opaque rendering stage;
in the rendering pipeline, rendering processing is carried out based on the scene color of the opaque rendering stage to obtain the color of the scene to be sampled;
and in a semi-transparent rendering stage in the rendering pipeline, sampling the color of the scene to be sampled so as to respectively obtain reflection effect data and refraction effect data of the water surface.
2. The method of claim 1, wherein the rendering based on the scene color of the opaque rendering stage comprises:
creating a rendering texture;
and binding the scene color of the opaque rendering stage stored in the color buffer as input, setting the rendering texture as a rendering target, and performing rendering processing.
3. The method according to claim 2, wherein the binding color buffer stores the scene color of the opaque rendering stage as an input, and sets the rendering texture as a rendering target, and performs the rendering process, including:
and in a pixel shader, sampling and encoding the scene color of the opaque rendering stage stored in the color buffer, and outputting the processing results of the sampling and encoding to the rendering texture.
4. The method according to claim 1, wherein the sampling the scene color to be sampled to obtain the reflection effect data of the water surface comprises:
in a pixel shader, acquiring a fragment which needs to be processed currently, and determining world space coordinates of a reflected point corresponding to the fragment;
acquiring the depth of the reflected point corresponding to the reflected point;
and if the depth of the reflected point meets a preset condition, sampling and decoding the color of the scene to be sampled to obtain reflection effect data of the water surface.
5. The method of claim 4, wherein determining world space coordinates of the reflected point corresponding to the segment comprises:
acquiring the corresponding coordinates of the fragments in a screen space;
determining the corresponding coordinates of the segment in the world space based on the corresponding coordinates of the segment in the screen space;
acquiring a position of the segment relative to a camera;
determining a reflection vector based on the position of the segment relative to the camera;
and stepping a preset distance along the direction of the reflection vector from the corresponding coordinate of the segment in the world space to obtain the world space coordinate of the reflected point.
6. The method according to claim 5, wherein if the depth of the reflected point satisfies a preset condition, performing sampling processing and decoding processing on the color of the scene to be sampled includes:
acquiring the depth of the segment corresponding to the segment;
and if the depth of the reflected point is greater than the depth of the segment, and an included angle between a sight line vector of the camera and the reflection vector is greater than a preset angle, sampling and decoding the color of the scene to be sampled.
7. The method according to claim 1, wherein the sampling the scene color to be sampled to obtain the refraction effect data of the water surface comprises:
in a pixel shader, acquiring a fragment which needs to be processed currently, and determining a corresponding coordinate of a water surface part corresponding to the fragment in a screen space;
acquiring the distortion degree;
shifting the corresponding coordinates of the segments in the screen space based on the distortion degree to obtain sampling coordinates;
and sampling the color of the scene to be sampled through the sampling coordinates to obtain the refraction effect data of the water surface.
8. The method of claim 7, wherein said obtaining a degree of distortion comprises:
acquiring a pixel normal and a vertex normal of a camera space;
determining a difference of the vertex normal minus the pixel normal;
multiplying the difference by the refractive index to obtain the degree of distortion.
9. A water surface rendering apparatus, comprising:
the opaque rendering module is used for finishing the rendering processing of an opaque rendering stage through a rendering pipeline corresponding to the mobile terminal so as to obtain the scene color of the opaque rendering stage;
a full screen rendering module, configured to perform, in the rendering pipeline, rendering processing based on the scene color of the opaque rendering stage to obtain a scene color to be sampled;
and the sampling module is used for sampling the colors of the scene to be sampled in a semitransparent rendering stage in the rendering pipeline so as to respectively obtain reflection effect data and refraction effect data of the water surface.
10. A mobile terminal, comprising: a memory, a processor; wherein the memory has stored thereon executable code which, when executed by the processor, causes the processor to perform a water surface rendering method as defined in any one of claims 1-8.
11. A non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of a mobile end, causes the processor to perform the surface rendering method of any one of claims 1-8.
CN202111643949.XA 2021-12-29 2021-12-29 Water surface rendering method, device, mobile terminal and storage medium Active CN114299217B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111643949.XA CN114299217B (en) 2021-12-29 2021-12-29 Water surface rendering method, device, mobile terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111643949.XA CN114299217B (en) 2021-12-29 2021-12-29 Water surface rendering method, device, mobile terminal and storage medium

Publications (2)

Publication Number Publication Date
CN114299217A true CN114299217A (en) 2022-04-08
CN114299217B CN114299217B (en) 2025-02-25

Family

ID=80972170

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111643949.XA Active CN114299217B (en) 2021-12-29 2021-12-29 Water surface rendering method, device, mobile terminal and storage medium

Country Status (1)

Country Link
CN (1) CN114299217B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115120973A (en) * 2022-06-15 2022-09-30 网易(杭州)网络有限公司 Model rendering method and device, nonvolatile storage medium and terminal equipment
CN117475050A (en) * 2023-10-08 2024-01-30 粒界(上海)信息科技有限公司 Vehicle model rendering method, device, storage medium and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040181382A1 (en) * 2003-03-14 2004-09-16 Yaohua Hu Visualizing the surface of a liquid
US20070038421A1 (en) * 2005-05-18 2007-02-15 Microsoft Corporation River Modeling
US9147283B1 (en) * 2011-10-30 2015-09-29 Lockhead Martin Corporation Water surface visualization during a simulation
CN107886562A (en) * 2017-12-05 2018-04-06 北京像素软件科技股份有限公司 Water surface rendering intent, device and readable storage medium storing program for executing
CN112837402A (en) * 2021-03-01 2021-05-25 腾讯科技(深圳)有限公司 Scene rendering method, apparatus, computer equipment and storage medium
CN112973121A (en) * 2021-04-30 2021-06-18 成都完美时空网络技术有限公司 Reflection effect generation method and device, storage medium and computer equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040181382A1 (en) * 2003-03-14 2004-09-16 Yaohua Hu Visualizing the surface of a liquid
US20070038421A1 (en) * 2005-05-18 2007-02-15 Microsoft Corporation River Modeling
US9147283B1 (en) * 2011-10-30 2015-09-29 Lockhead Martin Corporation Water surface visualization during a simulation
CN107886562A (en) * 2017-12-05 2018-04-06 北京像素软件科技股份有限公司 Water surface rendering intent, device and readable storage medium storing program for executing
CN112837402A (en) * 2021-03-01 2021-05-25 腾讯科技(深圳)有限公司 Scene rendering method, apparatus, computer equipment and storage medium
CN112973121A (en) * 2021-04-30 2021-06-18 成都完美时空网络技术有限公司 Reflection effect generation method and device, storage medium and computer equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115120973A (en) * 2022-06-15 2022-09-30 网易(杭州)网络有限公司 Model rendering method and device, nonvolatile storage medium and terminal equipment
CN117475050A (en) * 2023-10-08 2024-01-30 粒界(上海)信息科技有限公司 Vehicle model rendering method, device, storage medium and electronic equipment

Also Published As

Publication number Publication date
CN114299217B (en) 2025-02-25

Similar Documents

Publication Publication Date Title
EP2854108B1 (en) Anti-aliasing for graphics hardware
JP6356784B2 (en) Apparatus and method for radiance transfer sampling for augmented reality
US10614619B2 (en) Graphics processing systems
US12235925B2 (en) Interactive path tracing on the web
US10049486B2 (en) Sparse rasterization
CN114820906A (en) Image rendering method and device, electronic equipment and storage medium
CN108805971B (en) An Ambient Occlusion Method
US20200273239A1 (en) Systems and methods for ray-traced shadows of transparent objects
CN107209951B (en) The sputtering of single pass surface
KR20150117662A (en) Method and device for enriching the content of a depth map
CN114299217B (en) Water surface rendering method, device, mobile terminal and storage medium
TWI769138B (en) Graphics processing method, pipeline circuit and computer program
CN115526977A (en) Game picture rendering method and device
US20060250414A1 (en) System and method of anti-aliasing computer images
CN119206029B (en) System, storage medium and device for simulating visual enhancement of reflective effect on the surface of digital three-dimensional model
CN117036577B (en) Scene rendering method and device, storage medium and electronic equipment
GB2535792A (en) Graphic processing systems
US20240249461A1 (en) Vector graphic texture engine
WO2023122357A1 (en) Subsurface scattering for mobile applications
JP2025514733A (en) Apparatus, method, program, and system for real-time volume rendering of dynamic particles
CN119991922A (en) Special effect generation method and device, computer readable storage medium, and electronic device
CN116524102A (en) Cartoon second-order direct illumination rendering method, device and system
CN119540107A (en) Correction per illumination component
CN120047458A (en) A processing method for capturing object images in real time based on computer vision technology
CN119399342A (en) Object Gaussian inverse rendering method based on global-local surface cooperative perception

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant