1

I´m trying to do some shadows but the shader only outputs values if I use:

layout (location = 0) out vec4 outColor;

It doesnt work with vec3 or less. You can check my texture properties here:

    shadowTextureProperties.setHasMipMap(false);
    shadowTextureProperties.setMagFilter(EnumTextureFilter.NEAREST);
    shadowTextureProperties.setMinFilter(EnumTextureFilter.NEAREST);
    shadowTextureProperties.setWrapS(EnumTextureWrap.CLAMP_TO_EDGE);
    shadowTextureProperties.setWrapT(EnumTextureWrap.CLAMP_TO_EDGE);
    shadowTextureProperties.setInternalColorFormat(EnumTextureColorFormat.RGB_32F); // 1st format value
    shadowTextureProperties.setSrcColorFormat(EnumTextureColorFormat.RGB); // 2nd format value
    shadowTextureProperties.setValueFormat(EnumValueFormat.FLOAT);

This is my shader fragment source with vec3 output and the format above, I'm getting a completely white screen. With vec4 I'm getting true depth values.

#version 400
precision highp float;
layout (location = 0) out vec3 outColor;

void main()
{
    outColor = vec3(gl_FragCoord.z);
}

Results

With vec3: enter image description here

With vec4: enter image description here

n0rd
  • 11,850
  • 5
  • 35
  • 56
bitQUAKE
  • 473
  • 1
  • 8
  • 19
  • I have an idea what may be happening here and it has to do with blending. If you re-write the `vec3` version of this shader to `vec3 (gl_FragCoord.z * gl_FragCoord.z)`, does that change the output? – Andon M. Coleman Aug 30 '15 at 14:16
  • I tried it but no changes... With vec4 I`m getting an output. – bitQUAKE Aug 30 '15 at 14:53
  • Okay, with that out of the way... is there any reason in particular you want a 3-channel color texture to store your depth? You are duplicating the depth across 3 channels, each 32-bits. You could use a floating-point depth attachment and avoid the issue altogether. Anything that has color-renderable 32-bit floating-point texture support will also support `GL_DEPTH_COMPONENT32F`. At the very least, you could use a single-component color format. `GL_R32F` – Andon M. Coleman Aug 30 '15 at 18:13

0 Answers0