64-bit hashes (#126)
- ContactEvent sample - Improved shadows - #120 - Triangle collision fixes
This commit is contained in:
parent
3fc20f5b45
commit
f42be210a2
49 changed files with 19835 additions and 17544 deletions
51
samples/shaders/common/shadow_cascade.glsl
Normal file
51
samples/shaders/common/shadow_cascade.glsl
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Cascade count plus the parts of the cascaded lookup that touch no
|
||||
// uniform block, shared by the lit shape shaders via @include. Each
|
||||
// shader declares its own ub_pass, so the per-cascade values stay there
|
||||
// and arrive as parameters.
|
||||
|
||||
// Must match SHADOW_CASCADE_COUNT in gfx/shadow.h. The renderer static
|
||||
// asserts the two agree, so a mismatch fails the build instead of
|
||||
// rendering garbage. Changing it here only reaches the committed headers
|
||||
// after a shader regen, which needs BOX3D_BUILD_SHADERS=ON.
|
||||
//
|
||||
// Four is the ceiling. Per-cascade values ride in vec4 lanes and a fifth
|
||||
// cascade would need a second vec4 for each of them.
|
||||
#define SHADOW_CASCADE_COUNT 4
|
||||
|
||||
// Cascade whose slice holds this view depth. The last one is a fallback
|
||||
// rather than a range: its map footprint runs well past the final split,
|
||||
// so content past the split range still gets shadowed.
|
||||
int selectShadowCascade( vec4 far_view_z, float view_z )
|
||||
{
|
||||
int cascade = SHADOW_CASCADE_COUNT - 1;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT - 1; ++i )
|
||||
{
|
||||
if ( view_z < far_view_z[i] )
|
||||
{
|
||||
cascade = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cascade;
|
||||
}
|
||||
|
||||
// Debug view 2.
|
||||
vec3 shadowCascadeTint( int cascade )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
{
|
||||
return vec3( 1.0, 0.4, 0.4 );
|
||||
}
|
||||
if ( cascade == 1 )
|
||||
{
|
||||
return vec3( 0.4, 1.0, 0.4 );
|
||||
}
|
||||
if ( cascade == 2 )
|
||||
{
|
||||
return vec3( 0.4, 0.4, 1.0 );
|
||||
}
|
||||
return vec3( 1.0, 0.9, 0.3 );
|
||||
}
|
||||
|
|
@ -22,14 +22,17 @@ float sampleShadowTap( texture2DArray tex, samplerShadow smp, vec2 uv, float lay
|
|||
}
|
||||
|
||||
// scale multiplies the tap offsets. Cascades cover different world sizes
|
||||
// per texel, the caller passes GetCascadePcfScale's texel-size ratio so
|
||||
// the penumbra keeps a constant world width instead of jumping from
|
||||
// crisp to blurry at every cascade boundary. 1.0 = the full 7x7 kernel.
|
||||
float sampleShadowPCF( texture2DArray tex, samplerShadow smp, int cascade, vec3 light_uv, float bias, float scale )
|
||||
// per texel, so the caller passes the texel-size ratio against the near
|
||||
// cascade and the penumbra keeps a constant world width instead of
|
||||
// jumping from crisp to blurry at every cascade boundary. 1.0 = the full
|
||||
// 7x7 kernel.
|
||||
//
|
||||
// inv_size is one texel in UV. Passed in rather than baked in so the
|
||||
// kernel follows SHADOW_RESOLUTION without a second place to edit.
|
||||
float sampleShadowPCF( texture2DArray tex, samplerShadow smp, int cascade, vec3 light_uv, float bias, float scale,
|
||||
float inv_size )
|
||||
{
|
||||
// Must match SHADOW_RESOLUTION in shadow.h
|
||||
const float size = 4096.0;
|
||||
const float inv_size = 1.0 / size;
|
||||
float size = 1.0 / inv_size;
|
||||
|
||||
float ly = float( cascade );
|
||||
float rz = light_uv.z - bias;
|
||||
|
|
|
|||
Loading…
Reference in a new issue