GLES2和GLES3之间的一般差异

本页面记录了GLES2和GLES3之间的差异,这些差异是经过设计的,不是因bug造成的。可能有些差异是无心之过,但它们应该被报告为bug。

注解

“GLES2”和“GLES3”是Godot中,两个基于opengl呈现后端的名称。在图形应用程序编程接口方面,GLES2后端映射到桌面的OpenGL 2.1,移动版的OpenGL ES 2.0和web版的WebGL 1.0。GLES3后端映射到桌面的OpenGL 3.3,移动版的OpenGL ES 3.0和web版的WebGL 2.0。

粒子

GLES2不能使用:参考:粒子<类_粒子>`或:参考:`二维粒子<类_二维粒子>`节点,因为它们需要高级GPU特性。相反,使用:参考:`CPU粒子<类_CPU粒子>`或:参考:`CPU二维粒子<类_CPU二维粒子>,它提供了与:参考:`粒子材质<类_粒子材质>`类似的接口。

小技巧

粒子和二维粒子可以通过编辑器中的“转换为CPU粒子”选项,转换为它们的等效CPU节点。

“屏幕_纹理”变频译码

在GLES2中,“屏幕_纹理”(通过:参考:`着色器纹理<类_着色器纹理>`访问)没有计算变频译码。所以当访问不同的细节级别时,纹理不会变得模糊。

“深度图纹理”

虽然GLES2在着色器中支持“深度图纹理”,可能在一些旧的硬件上(特别是移动设备)不能工作。

色彩空间

GLES2和GLES3位于不同的色彩空间中。这表示颜色之间会有细微的差别,特别是在使用灯光的时候。

如果您在游戏中同时使用GLES2和GLES3,您可以使用“如果”(if)语句检查输出是否为sRGB,使用“输出_为_SRGB”。“输出_为_SRGB”在GLES2中返回“真”,在GLES3中返回“假”。

高动态范围

GLES2 is not capable of using High Dynamic Range (HDR) rendering features. If HDR is set for your project, or for a given viewport, Godot will still user Low Dynamic Range (LDR) which limits viewport values to the 0-1 range.

空间材质特性

在GLES2中,在:参考:`空间材质<类_空间材质>`中缺少以下高级渲染特性:

  • Refraction(折射)
  • Subsurface scattering
  • Anisotropy(各向异性)
  • Clearcoat(清漆)
  • 深度映射

使用空间材质时,它们甚至不会出现在编辑器中。

在自定义:参考:`着色器材质<类_着色器材质>`中,您可以为这些特性设置值,但它们是非功能性的。例如,您仍然可以在着色器中设置内置的“次表面散射”(通常会增加次表面散射),但什么都不会发生。

环境特性

在GLES2中,缺少:参考:`环境<类_环境>`中的以下特性:

  • 自动曝光
  • 色调映射
  • 屏幕空间反射
  • 屏幕空间环境遮挡

这意味着在GLES2环境中,您只能设置:

  • 天空(包括程序生成天空)
  • Ambient light
  • 景深
  • 辉光(也称为光晕)
  • Adjustment

全局光照探测器

:参考:`全局光照探测器<类_全局光照探测器>` 在GLES2中不起作用。而是使用:参考:烘焙灯光贴图<类_烘焙灯光贴图>。有关烘焙灯光贴图工作原理的描述,请参见:参考:烘焙灯光贴图教程<文档_烘焙_灯光贴图>。

接触阴影

GLES2中不支持“阴影_接触”属性:参考:灯光<类_灯光>,并且无效。

灯光性能

在GLES2中,使用多盏灯光会造成性能不佳,因为每盏灯光都在一个单独的渲染通道中处理(与GLES3相反,GLES3是一次性完成渲染)。尝试将场景灯光控制在尽可能少的情况,以达到最好效果。

纹理压缩

在移动端,GLES2需要进行纹理压缩,而GLES3需要ETC2纹理压缩。默认启用ETC2纹理压缩,因此,如果使用GLES2导出到移动端,请确保在项目设置中设定了``渲染/显存_压缩/导入_etc压缩``,然后重新导入纹理。

警告

Since ETC doesn’t support transparency, you must reimport textures that contain an alpha channel to use the Uncompressed, Lossy or Lossless compression mode (instead of Video RAM). This can be done in the Import dock after selecting them in the FileSystem dock.

融合变形

在GLES2中不支持融合变形。

着色语言

GLES3提供了许多GLES2没有提供的内置函数。下面是在GLES2中不可用或支持有限的函数列表。

有关内置GLSL函数的完整列表,请参见:参考:着色语言文档<文档_着色_语言>。

函数 
vec_type modf ( vec_type x, out vec_type i ) 
vec_int_type floatBitsToInt ( vec_type x ) 
vec_uint_type floatBitsToUint ( vec_type x ) 
vec_type intBitsToFloat ( vec_int_type x ) 
vec_type uintBitsToFloat ( vec_uint_type x ) 
ivec2 textureSize ( sampler2D_type s, int lod )See workaround below
ivec2 textureSize ( samplerCube s, int lod )See workaround below
vec4_type texture ( sampler_type s, vec_type uv [, float bias] )偏差在顶点着色器中不可用
vec4_type textureProj ( sampler_type s, vec_type uv [, float bias] ) 
vec4_type textureLod ( sampler_type s, vec_type uv, float lod )只在某些硬件的顶点着色器中可用
vec4_type textureProjLod ( sampler_type s, vec_type uv, float lod ) 
vec4_type textureGrad ( sampler_type s, vec_type uv, vec_type dPdx, vec_type dPdy) 
vec_type dFdx ( vec_type p ) 
vec_type dFdy ( vec_type p ) 
vec_type fwidth ( vec_type p ) 

注解

Functions not in GLES2’s GLSL were added with Godots own shader standard library. These functions may perform worse in GLES2 compared to GLES3.

textureSize() workaround

GLES2 does not support textureSize(). You can get the size of a texture the old fashioned way by passing in a uniform with the texture size yourself.

  1. // In the shader:
  2. uniform sampler2D textureName;
  3. uniform vec2 textureName_size;
  1. # In GDScript:
  2. material_name.set_shader_param("textureName", my_texture)
  3. material_name.set_shader_param("textureName_size", my_texture_size)

Built in variables and render modes

Godot also provides many built-in variables and render modes. Some cannot be supported in GLES2. Below is a list of built-in variables and render modes that, when written to, will have no effect or could even cause issues when using the GLES2 backend.

Variable / Render Mode
ensure_correct_normals
INSTANCE_ID
DEPTH
ANISOTROPY
ANISOTROPY_FLOW
SSS_STRENGTH