1

I have just include OpenGL ES 3.0 in my iOS app and it is working fine.

I have a working shader below:

#version 300 es

precision mediump float;

uniform sampler2D texSampler;
uniform float fExposure;

in vec2 fTexCoord;
in vec3 fColor;

out vec4 fragmentColor;

void main()
{
  fragmentColor = texture(texSampler, fTexCoord) * vec4(fColor, 1.0) * fExposure;
}

Now, I want to use a sampler3D so I have:

#version 300 es

precision mediump float;

uniform sampler3D texSampler;
uniform float fExposure;

in vec3 fTexCoord;
in vec3 fColor;

out vec4 fragmentColor;

void main()
{
  fragmentColor = texture(texSampler, fTexCoord) * vec4(fColor, 1.0) * fExposure;
}

and it doesn't compile. Also, I changed the vec2 texCoord to vec3 texCoord in the vertex shader.

Actually, sampler3D is not recognized, but as far as i know it exists in OpenGL ES 3.0.

Any ideas?

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
maria_20
  • 23
  • 3

1 Answers1

3

Similar to float, sampler3D does not have a default precision. Add this at the start of your fragment shader, where you also specify the default float precision:

precision mediump sampler3D;

Of course you can use lowp instead if that gives you sufficient precision.

The only sampler types that have a default precision in ES 3.0/3.1 are sampler2D and samplerCube (both default to lowp). For all others, the precision has to be specified either as a default precision, or as part of the variable declaration.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133