I’m doing a shadow map lookup with the following function:

``````texture(samplerCubeShadow sampler, vec4 coord)
``````

I am having some trouble with the depth value of the vec4 texture coordinate, and I want to eliminate one possible source of confusion. I assume the x, y, and z values just get multiplied by the w value, right? So the two vectors below would be functionally equivalent:

``````vec4(1,2,3,1)
vec4(0.5,1,1.5,0.5)
``````

Is this correct?

[QUOTE=JoshKlint;1255036]I’m doing a shadow map lookup with the following function:

``````texture(samplerCubeShadow sampler, vec4 coord)
``````

I am having some trouble with the depth value of the vec4 texture coordinate, and I want to eliminate one possible source of confusion. I assume the x, y, and z values just get multiplied by the w value, right? So the two vectors below would be functionally equivalent:

``````vec4(1,2,3,1)
vec4(0.5,1,1.5,0.5)
``````

Is this correct?[/QUOTE]
No.

Querying a shadow sampler doesn’t return the depth value, it returns the result of comparing the depth against the reference value, which is normally the last component of the texture coordinates (except for samplerCubeArrayShadow, as samplerCubeArray already needs a vec4, so the shadow version has an extra parameter for the reference value).

If you want to perform the comparison yourself, don’t use a shadow sampler, just use the equivalent non-shadow form (e.g. samplerCube instead of samplerCubeShadow). However, the dedicated shadow form may perform filtering for you.

texture() never does perspective division on the texture coordinates; textureProj() exists for that. But you don’t need that for cube maps, as perspective division simply scales the vector, and cube map lookups don’t care about the magnitude, only the ratios of x:y:z.

Thanks for the explanation.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.