DepthTexture is not binding to sampler2DShadow

I tried to bind a DepthTexture to sampler2DShadow uniform variable in my shader but it failed with

[.WebGL-0x13c003b7100] GL_INVALID_OPERATION: Mismatch between texture format and sampler type (signed/unsigned/float/shadow).

Reproducible jsfiddle :point_right: Edit fiddle - JSFiddle - Code Playground

Am I missing something here? Please help.

The usage of sampler2DShadow does not work since it requires a special texture parameter (gl.TEXTURE_COMPARE_MODE) to have a specific value (gl.COMPARE_REF_TO_TEXTURE). However, three.js does not support setting this parameter.

What is your use case for sampler2DShadow? Can’t you just use a normal sampler?

What is your use case for sampler2DShadow ? Can’t you just use a normal sampler?

I’m just venturing :smile:

BTW I tried setting the parameter natively

  const gl = renderer.getContext();

but didn’t work either with the same error message.
Does Three.js internally discard the manually-set parameters? If not, why would it not work? According to Sampler (GLSL) - OpenGL Wiki the only requirements seems to have DEPTH_COMPONENT* format and TEXTURE_COMPARE_MODE set to COMPARE_REF_TO_TEXTURE. I would really appreciate your advice.:pray:

I don’t think your above code snippet is executed at the right time. The depth texture has to be bound otherwise the code has no effect.

1 Like