Skip to content

Instantly share code, notes, and snippets.

@jdolan
Created January 10, 2023 14:35
Show Gist options
  • Save jdolan/1aa047da5b46eac652d3b0715f8cb9b6 to your computer and use it in GitHub Desktop.
Save jdolan/1aa047da5b46eac652d3b0715f8cb9b6 to your computer and use it in GitHub Desktop.
Shadow sampler of a cubemap array texture in GLSL
uniform samplerCubeArrayShadow texture_shadowmap_cube;
/**
* @return The fraction of the sample that is _not_ shadowed (0.0 - 1.0).
*/
float sample_shadowmap(in light_t light, in int index) {
// the position of the fragment in light space
vec4 position = vec4(light.model.xyz - vertex.model, 1.0);
// the position of the fragment in normalized device coordinates (-1.0 - 1.0)
vec4 projected = light_projection * position;
// the position of the fragment in the light's depth map texture
vec2 shadowmap = (projected.xy / projected.w) * 0.5 + 0.5;
return texture(texture_shadowmap, vec4(shadowmap, index, length(position.xyz) / depth_range.y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment