【问题标题】:Use 3D Texture for Fragment shader on Android在 Android 上为片段着色器使用 3D 纹理
【发布时间】:2020-12-19 04:55:10
【问题描述】:

我需要在 Android 上的片段着色器中使用 3D 纹理,但出现编译错误。 我使用 GLES3.0,我认为它应该支持 3D 纹理。 我的着色器如下所示:

#extension GL_OES_texture_3D : enable

precision mediump float;

uniform sampler3D u_Texture;

没有#extension GL_OES_texture_3D : enable我得到错误

L0003:关键字“sampler3D”已保留

#extension GL_OES_texture_3D : enable 出现错误

S0032:没有为变量“u_Texture”定义默认精度

即使我使用uniform medium float sampler3D u_Texture,我也得到了

期望,找到 sampler3D 错误。

希望得到您的帮助!

非常感谢。

YL

【问题讨论】:

标签: android opengl-es glsl shader


【解决方案1】:

首先,您必须在着色器程序的第一行中通过版本限定符指定 glsl 版本:

#version 300 es

精度限定符是highpmediumplowp,并且必须在类型之前指定。类型是sampler3D 而不是float

声明

uniform medium float sampler3D u_Texture

有 2 种类型(floatsampler3D),因此会导致语法错误。

应该是的

#version 300 es

uniform medium sampler3D u_Texture;

或使用默认的精度限定符

#version 300 es
precision mediump sampler3D;

uniform sampler3D u_Texture;

(当然precision mediump float;也必须指定)

OpenGL ES Shading Language 3.20 Specification - 4.7.3. Precision Qualifiers

【讨论】:

  • 这里不需要#extension 行; 3D 纹理是 ES 3.0 中的核心功能。我猜 OP 不见了 #version 300 es
猜你喜欢
  • 1970-01-01
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-04
  • 2020-03-03
  • 2019-01-23
相关资源
最近更新 更多