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
|
|
@ -3,13 +3,25 @@
|
|||
# Each .glsl file in shaders/ becomes a single C header in
|
||||
# generated/<name>.glsl.h that holds source/bytecode for every enabled backend
|
||||
# (D3D11, Metal, GL 4.5 core). The generated headers are committed so a fresh
|
||||
# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default ON) recompiles
|
||||
# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default OFF) recompiles
|
||||
# them in place when a .glsl changes; off builds straight from the committed
|
||||
# headers and fetches no tooling.
|
||||
|
||||
set(SHADER_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated"
|
||||
CACHE INTERNAL "Directory holding generated shader headers")
|
||||
|
||||
# Shared @include fragments - sokol-shdc's @include resolves relative to the
|
||||
# input file, so shaders include these via "../common/<name>.glsl". Listed in
|
||||
# the shaders target's SOURCES so they show up in IDE project trees, which is
|
||||
# the only way they get there - sokol-shdc never sees them as direct inputs.
|
||||
# Globbed unconditionally so they stay searchable when codegen is off, which
|
||||
# is the default. With codegen on they are also DEPENDS on every shader so an
|
||||
# edit to a shared file rebuilds everything that might include it.
|
||||
# CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of a
|
||||
# configure-step stat each build.
|
||||
file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/common/*.glsl")
|
||||
|
||||
if(BOX3D_BUILD_SHADERS)
|
||||
if(NOT SOKOL_SHDC_EXECUTABLE OR NOT EXISTS "${SOKOL_SHDC_EXECUTABLE}")
|
||||
message(FATAL_ERROR
|
||||
|
|
@ -17,17 +29,6 @@ if(BOX3D_BUILD_SHADERS)
|
|||
"${SOKOL_SHDC_EXECUTABLE}")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY "${SHADER_OUTPUT_DIR}")
|
||||
|
||||
# Shared @include fragments - sokol-shdc's @include resolves relative to
|
||||
# the input file, so shaders include these via "../common/<name>.glsl".
|
||||
# Tracked as DEPENDS on every shader so an edit to a shared file triggers
|
||||
# a rebuild of everything that might include it, and listed in the shaders
|
||||
# target's SOURCES so they show up in IDE project trees - sokol-shdc never
|
||||
# sees them as direct inputs, so they would be invisible otherwise.
|
||||
# CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of
|
||||
# a configure-step stat each build.
|
||||
file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/common/*.glsl")
|
||||
endif()
|
||||
|
||||
# Reset the accumulators on every configure so stale entries from a prior
|
||||
|
|
@ -108,31 +109,31 @@ add_shader(world_text "overlays/world_text.glsl")
|
|||
get_property(_outputs GLOBAL PROPERTY SHADER_OUTPUTS)
|
||||
get_property(_inputs GLOBAL PROPERTY SHADER_INPUTS)
|
||||
|
||||
# SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files in
|
||||
# the project tree even though nothing here is compiled. We list the leaf .glsl
|
||||
# shaders, the common/ @include fragments, and the generated .glsl.h.
|
||||
if(BOX3D_BUILD_SHADERS)
|
||||
# DEPENDS drives the build (run sokol-shdc when the .glsl inputs change).
|
||||
# SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files
|
||||
# in the project tree even though nothing here is compiled. We list the leaf
|
||||
# .glsl shaders, the common/ @include fragments, and the generated .glsl.h.
|
||||
add_custom_target(shaders
|
||||
DEPENDS ${_outputs}
|
||||
SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs}
|
||||
)
|
||||
|
||||
# IDE grouping. TREE mirrors the on-disk shaders layout.
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
FILES ${_inputs} ${SHADER_COMMON_INCLUDES})
|
||||
source_group("Generated" FILES ${_outputs})
|
||||
|
||||
# The Visual Studio generator emits a build-stamp file named
|
||||
# CMakeFiles/<target> for each custom target. Left ungrouped it floats at
|
||||
# the project root as a stray "shaders" node with a can't-find-file icon -
|
||||
# file it under the build-rule machinery.
|
||||
source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders")
|
||||
else()
|
||||
# No codegen: the samples build straight from the committed headers.
|
||||
add_custom_target(shaders SOURCES ${_inputs} ${_outputs})
|
||||
add_custom_target(shaders SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs})
|
||||
endif()
|
||||
|
||||
# IDE grouping. TREE mirrors the on-disk shaders layout.
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
FILES ${_inputs} ${SHADER_COMMON_INCLUDES})
|
||||
source_group("Generated" FILES ${_outputs})
|
||||
|
||||
# The Visual Studio generator emits a build-stamp file named CMakeFiles/<target>
|
||||
# for each custom target. Left ungrouped it floats at the project root as a
|
||||
# stray "shaders" node with a can't-find-file icon - file it under the
|
||||
# build-rule machinery.
|
||||
source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders")
|
||||
|
||||
# shader_gen is the INTERFACE library consumers link to. It forwards the include
|
||||
# path for the generated headers (SYSTEM so /WX doesn't trip on shdc output) and
|
||||
# pulls in the shaders target so any link forces the headers to exist first.
|
||||
|
|
|
|||
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;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -22,6 +22,9 @@
|
|||
Uniform block 'ub_frame':
|
||||
C struct: shadow_sphere_ub_frame_t
|
||||
Bind slot: UB_shadow_sphere_ub_frame => 0
|
||||
Uniform block 'ub_pass':
|
||||
C struct: shadow_sphere_ub_pass_t
|
||||
Bind slot: UB_shadow_sphere_ub_pass => 1
|
||||
Storage buffer 'instances':
|
||||
C struct: shadow_sphere_instance_t
|
||||
Bind slot: VIEW_shadow_sphere_instances => 0
|
||||
|
|
@ -40,6 +43,7 @@
|
|||
#define ATTR_shadow_sphere_caster_in_pos (0)
|
||||
#define UB_shadow_sphere_ub_draw (2)
|
||||
#define UB_shadow_sphere_ub_frame (0)
|
||||
#define UB_shadow_sphere_ub_pass (1)
|
||||
#define VIEW_shadow_sphere_instances (0)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_draw_t {
|
||||
|
|
@ -52,6 +56,12 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_frame_t {
|
|||
} shadow_sphere_ub_frame_t;
|
||||
#pragma pack(pop)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_pass_t {
|
||||
Vec4 light_dir;
|
||||
Vec4 depth_row;
|
||||
} shadow_sphere_ub_pass_t;
|
||||
#pragma pack(pop)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t {
|
||||
Vec4 xform_row0;
|
||||
Vec4 xform_row1;
|
||||
|
|
@ -82,15 +92,23 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t {
|
|||
uniform ivec4 ub_draw[1];
|
||||
uniform vec4 ub_frame[4];
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
layout(location = 0) out vec3 v_world_pos_proxy;
|
||||
layout(location = 1) flat out vec3 v_center;
|
||||
layout(location = 2) flat out float v_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
int _30 = ub_draw[0].x + gl_InstanceID;
|
||||
gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in_pos * _15.items[_30].params.x), 1.0);
|
||||
vec3 _63 = vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w);
|
||||
vec3 _76 = _63 + (in_pos * (2.0 * _15.items[_30].params.x));
|
||||
v_world_pos_proxy = _76;
|
||||
v_center = _63;
|
||||
v_radius = _15.items[_30].params.x;
|
||||
gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_76, 1.0);
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_vs_source_glsl430[612] = {
|
||||
static const uint8_t shadow_sphere_vs_source_glsl430[889] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74,
|
||||
0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,
|
||||
|
|
@ -111,38 +129,102 @@ static const uint8_t shadow_sphere_vs_source_glsl430[612] = {
|
|||
0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,
|
||||
0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,
|
||||
0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,
|
||||
0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,
|
||||
0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,
|
||||
0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,
|
||||
0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,
|
||||
0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,
|
||||
0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,
|
||||
0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,
|
||||
0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,
|
||||
0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,
|
||||
0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,
|
||||
0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,
|
||||
0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,
|
||||
0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,
|
||||
0x2e,0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,
|
||||
0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,
|
||||
0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,
|
||||
0x7d,0x0a,0x0a,0x00,
|
||||
0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,
|
||||
0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,
|
||||
0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,
|
||||
0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,
|
||||
0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,
|
||||
0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,
|
||||
0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,
|
||||
0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,
|
||||
0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,
|
||||
0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,
|
||||
0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,
|
||||
0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,
|
||||
0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,
|
||||
0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,
|
||||
0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,
|
||||
0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,
|
||||
0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,
|
||||
0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,
|
||||
0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,
|
||||
0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,
|
||||
0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,
|
||||
0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,
|
||||
0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,
|
||||
0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,
|
||||
0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,
|
||||
0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,
|
||||
0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,
|
||||
0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,
|
||||
0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,
|
||||
0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#version 430
|
||||
layout(depth_greater) out float gl_FragDepth;
|
||||
|
||||
uniform vec4 ub_pass[2];
|
||||
layout(location = 0) in vec3 v_world_pos_proxy;
|
||||
layout(location = 1) flat in vec3 v_center;
|
||||
layout(location = 2) flat in float v_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 _28 = v_world_pos_proxy - v_center;
|
||||
float _33 = dot(_28, ub_pass[0].xyz);
|
||||
float _49 = (_33 * _33) - (dot(_28, _28) - (v_radius * v_radius));
|
||||
if (_49 < 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
gl_FragDepth = dot(ub_pass[1], vec4(v_world_pos_proxy + (ub_pass[0].xyz * max((-_33) - sqrt(_49), 0.0)), 1.0));
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f,
|
||||
0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
|
||||
static const uint8_t shadow_sphere_fs_source_glsl430[563] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79,
|
||||
0x6f,0x75,0x74,0x28,0x64,0x65,0x70,0x74,0x68,0x5f,0x67,0x72,0x65,0x61,0x74,0x65,
|
||||
0x72,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,
|
||||
0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,
|
||||
0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,
|
||||
0x5b,0x32,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,
|
||||
0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,
|
||||
0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,
|
||||
0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,
|
||||
0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,
|
||||
0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x76,
|
||||
0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,
|
||||
0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,
|
||||
0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,
|
||||
0x38,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,
|
||||
0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,
|
||||
0x39,0x20,0x3d,0x20,0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,0x33,0x33,0x29,0x20,
|
||||
0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x32,0x38,0x29,
|
||||
0x20,0x2d,0x20,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,
|
||||
0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,
|
||||
0x66,0x20,0x28,0x5f,0x34,0x39,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,
|
||||
0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,
|
||||
0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,
|
||||
0x74,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x65,
|
||||
0x63,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,
|
||||
0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,
|
||||
0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x28,0x2d,0x5f,
|
||||
0x33,0x33,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x34,0x39,0x29,0x2c,
|
||||
0x20,0x30,0x2e,0x30,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,
|
||||
0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
struct instance
|
||||
|
|
@ -163,13 +245,16 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
|
||||
cbuffer ub_frame : register(b0)
|
||||
{
|
||||
row_major float4x4 _83_light_view_proj : packoffset(c0);
|
||||
row_major float4x4 _93_light_view_proj : packoffset(c0);
|
||||
};
|
||||
|
||||
|
||||
static float4 gl_Position;
|
||||
static int gl_InstanceIndex;
|
||||
static float3 in_pos;
|
||||
static float3 v_world_pos_proxy;
|
||||
static float3 v_center;
|
||||
static float v_radius;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
|
|
@ -179,6 +264,9 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float3 v_world_pos_proxy : TEXCOORD0;
|
||||
nointerpolation float3 v_center : TEXCOORD1;
|
||||
nointerpolation float v_radius : TEXCOORD2;
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
|
|
@ -191,7 +279,12 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
_33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48));
|
||||
_33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64));
|
||||
_33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80));
|
||||
gl_Position = mul(float4(float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w) + (in_pos * _33.params.x), 1.0f), _83_light_view_proj);
|
||||
float3 _63 = float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w);
|
||||
float3 _76 = _63 + (in_pos * (2.0f * _33.params.x));
|
||||
v_world_pos_proxy = _76;
|
||||
v_center = _63;
|
||||
v_radius = _33.params.x;
|
||||
gl_Position = mul(float4(_76, 1.0f), _93_light_view_proj);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
|
|
@ -201,10 +294,13 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.v_world_pos_proxy = v_world_pos_proxy;
|
||||
stage_output.v_center = v_center;
|
||||
stage_output.v_radius = v_radius;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
||||
static const uint8_t shadow_sphere_vs_source_hlsl5[2093] = {
|
||||
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
|
|
@ -225,7 +321,7 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
|||
0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,
|
||||
0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,
|
||||
0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x39,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,
|
||||
0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,
|
||||
0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,
|
||||
|
|
@ -233,6 +329,11 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
|||
0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,
|
||||
0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,
|
||||
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,
|
||||
0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,
|
||||
0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,
|
||||
0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,
|
||||
0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,
|
||||
0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,
|
||||
|
|
@ -241,87 +342,219 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
|||
0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,
|
||||
0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,
|
||||
0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,
|
||||
0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
|
||||
0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,
|
||||
0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,
|
||||
0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,
|
||||
0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,
|
||||
0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,
|
||||
0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,
|
||||
0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,
|
||||
0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,
|
||||
0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,
|
||||
0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,
|
||||
0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,
|
||||
0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,
|
||||
0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,
|
||||
0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
|
||||
0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,
|
||||
0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,
|
||||
0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,
|
||||
0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,
|
||||
0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,
|
||||
0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,
|
||||
0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,
|
||||
0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,
|
||||
0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,
|
||||
0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,
|
||||
0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,
|
||||
0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,
|
||||
0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,
|
||||
0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,
|
||||
0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,
|
||||
0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,
|
||||
0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,
|
||||
0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,
|
||||
0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,
|
||||
0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,
|
||||
0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,
|
||||
0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x34,0x38,0x29,
|
||||
0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,
|
||||
0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,
|
||||
0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,
|
||||
0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,
|
||||
0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,
|
||||
0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,
|
||||
0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,
|
||||
0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,
|
||||
0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,
|
||||
0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,
|
||||
0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,
|
||||
0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,
|
||||
0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,
|
||||
0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20,
|
||||
0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,
|
||||
0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,
|
||||
0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,
|
||||
0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,
|
||||
0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,
|
||||
0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,
|
||||
0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,
|
||||
0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,
|
||||
0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,
|
||||
0x36,0x33,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,
|
||||
0x32,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,
|
||||
0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,
|
||||
0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,
|
||||
0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,
|
||||
0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x39,
|
||||
0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,
|
||||
0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
|
||||
0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,
|
||||
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,
|
||||
0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,
|
||||
0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,
|
||||
0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,
|
||||
0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,
|
||||
0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,
|
||||
0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
|
||||
0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,
|
||||
0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,
|
||||
0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,
|
||||
0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,
|
||||
0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,
|
||||
0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,
|
||||
0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,
|
||||
0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,
|
||||
0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
cbuffer ub_pass : register(b1)
|
||||
{
|
||||
float4 _17_light_dir : packoffset(c0);
|
||||
float4 _17_depth_row : packoffset(c1);
|
||||
};
|
||||
|
||||
|
||||
static float gl_FragDepth;
|
||||
static float3 v_world_pos_proxy;
|
||||
static float3 v_center;
|
||||
static float v_radius;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float3 v_world_pos_proxy : TEXCOORD0;
|
||||
nointerpolation float3 v_center : TEXCOORD1;
|
||||
nointerpolation float v_radius : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float gl_FragDepth : SV_DepthGreaterEqual;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float3 _28 = v_world_pos_proxy - v_center;
|
||||
float _33 = dot(_28, _17_light_dir.xyz);
|
||||
float _49 = (_33 * _33) - (dot(_28, _28) - (v_radius * v_radius));
|
||||
if (_49 < 0.0f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
gl_FragDepth = dot(_17_depth_row, float4(v_world_pos_proxy + (_17_light_dir.xyz * max((-_33) - sqrt(_49), 0.0f)), 1.0f));
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
v_world_pos_proxy = stage_input.v_world_pos_proxy;
|
||||
v_center = stage_input.v_center;
|
||||
v_radius = stage_input.v_radius;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_FragDepth = gl_FragDepth;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_hlsl5[1155] = {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,
|
||||
0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f,
|
||||
0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,
|
||||
0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68,
|
||||
0x5f,0x72,0x6f,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,
|
||||
0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,
|
||||
0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,
|
||||
0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,
|
||||
0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,
|
||||
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,
|
||||
0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,
|
||||
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,
|
||||
0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,
|
||||
0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,
|
||||
0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,
|
||||
0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,
|
||||
0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x7d,0x3b,
|
||||
0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,
|
||||
0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x47,
|
||||
0x72,0x65,0x61,0x74,0x65,0x72,0x45,0x71,0x75,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,
|
||||
0x32,0x38,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,
|
||||
0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,
|
||||
0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,
|
||||
0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x31,0x37,0x5f,
|
||||
0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,
|
||||
0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,0x28,0x64,
|
||||
0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28,
|
||||
0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,
|
||||
0x34,0x39,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,
|
||||
0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,
|
||||
0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,
|
||||
0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x5f,0x6c,0x69,
|
||||
0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x6d,0x61,
|
||||
0x78,0x28,0x28,0x2d,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,
|
||||
0x5f,0x34,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x2c,0x20,0x31,0x2e,
|
||||
0x30,0x66,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,
|
||||
0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,
|
||||
0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
|
||||
0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,
|
||||
0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,
|
||||
0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,
|
||||
0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,
|
||||
0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
void frag_main()
|
||||
{
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_main();
|
||||
}
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_hlsl5[56] = {
|
||||
0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,
|
||||
0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,
|
||||
0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,
|
||||
0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,
|
||||
0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,
|
||||
0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,
|
||||
0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,
|
||||
0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,
|
||||
0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,
|
||||
0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,
|
||||
0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,
|
||||
0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,
|
||||
0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,
|
||||
0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,
|
||||
0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#include <metal_stdlib>
|
||||
|
|
@ -356,6 +589,9 @@ static const uint8_t shadow_sphere_fs_source_hlsl5[56] = {
|
|||
|
||||
struct main0_out
|
||||
{
|
||||
float3 v_world_pos_proxy [[user(locn0)]];
|
||||
float3 v_center [[user(locn1)]];
|
||||
float v_radius [[user(locn2)]];
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
|
|
@ -364,16 +600,21 @@ static const uint8_t shadow_sphere_fs_source_hlsl5[56] = {
|
|||
float3 in_pos [[attribute(0)]];
|
||||
};
|
||||
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _83 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]])
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _93 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]])
|
||||
{
|
||||
main0_out out = {};
|
||||
int _30 = _21.inst_base.x + int(gl_InstanceIndex);
|
||||
out.gl_Position = _83.light_view_proj * float4(float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in.in_pos * _15.items[_30].params.x), 1.0);
|
||||
float3 _63 = float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w);
|
||||
float3 _76 = _63 + (in.in_pos * (2.0 * _15.items[_30].params.x));
|
||||
out.v_world_pos_proxy = _76;
|
||||
out.v_center = _63;
|
||||
out.v_radius = _15.items[_30].params.x;
|
||||
out.gl_Position = _93.light_view_proj * float4(_76, 1.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_vs_source_metal_macos[982] = {
|
||||
static const uint8_t shadow_sphere_vs_source_metal_macos[1254] = {
|
||||
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
|
||||
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
|
||||
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
|
||||
|
|
@ -398,42 +639,59 @@ static const uint8_t shadow_sphere_vs_source_metal_macos[982] = {
|
|||
0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,
|
||||
0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,
|
||||
0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,
|
||||
0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,
|
||||
0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,
|
||||
0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,
|
||||
0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
|
||||
0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
|
||||
0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,
|
||||
0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,
|
||||
0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,
|
||||
0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,
|
||||
0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,
|
||||
0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,
|
||||
0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,
|
||||
0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,
|
||||
0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,
|
||||
0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,
|
||||
0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,
|
||||
0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,
|
||||
0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,
|
||||
0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x38,0x33,0x2e,0x6c,0x69,0x67,0x68,
|
||||
0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,
|
||||
0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,
|
||||
0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,
|
||||
0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,
|
||||
0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,
|
||||
0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,
|
||||
0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,
|
||||
0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,
|
||||
0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,
|
||||
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,
|
||||
0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,
|
||||
0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,
|
||||
0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,
|
||||
0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,
|
||||
0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,
|
||||
0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,
|
||||
0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
|
||||
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,
|
||||
0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,
|
||||
0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,
|
||||
0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,
|
||||
0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,
|
||||
0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x39,
|
||||
0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,
|
||||
0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,
|
||||
0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,
|
||||
0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,
|
||||
0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,
|
||||
0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,
|
||||
0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,
|
||||
0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,
|
||||
0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,
|
||||
0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
|
||||
0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,
|
||||
0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,
|
||||
0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,
|
||||
0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,
|
||||
0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,
|
||||
0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,
|
||||
0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,
|
||||
0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,
|
||||
0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,
|
||||
0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,
|
||||
0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,
|
||||
0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,
|
||||
0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x39,0x33,0x2e,0x6c,0x69,
|
||||
0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,
|
||||
0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
|
|
@ -443,19 +701,94 @@ static const uint8_t shadow_sphere_vs_source_metal_macos[982] = {
|
|||
|
||||
using namespace metal;
|
||||
|
||||
fragment void main0()
|
||||
struct ub_pass
|
||||
{
|
||||
float4 light_dir;
|
||||
float4 depth_row;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float gl_FragDepth [[depth(greater)]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float3 v_world_pos_proxy [[user(locn0)]];
|
||||
float3 v_center [[user(locn1), flat]];
|
||||
float v_radius [[user(locn2), flat]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _17 [[buffer(1)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
float3 _28 = in.v_world_pos_proxy - in.v_center;
|
||||
float _33 = dot(_28, _17.light_dir.xyz);
|
||||
float _49 = (_33 * _33) - (dot(_28, _28) - (in.v_radius * in.v_radius));
|
||||
if (_49 < 0.0)
|
||||
{
|
||||
discard_fragment();
|
||||
}
|
||||
out.gl_FragDepth = dot(_17.depth_row, float4(in.v_world_pos_proxy + (_17.light_dir.xyz * fast::max((-_33) - sqrt(_49), 0.0)), 1.0));
|
||||
return out;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_metal_macos[100] = {
|
||||
static const uint8_t shadow_sphere_fs_source_metal_macos[861] = {
|
||||
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
|
||||
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
|
||||
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
|
||||
0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
|
||||
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,
|
||||
0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a,
|
||||
0x7d,0x0a,0x0a,0x00,
|
||||
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,
|
||||
0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x64,0x65,0x70,0x74,0x68,0x5f,
|
||||
0x72,0x6f,0x77,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,
|
||||
0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,
|
||||
0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x67,0x72,0x65,0x61,0x74,
|
||||
0x65,0x72,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,
|
||||
0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,
|
||||
0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,
|
||||
0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,
|
||||
0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c,
|
||||
0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,
|
||||
0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,
|
||||
0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,
|
||||
0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,
|
||||
0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,
|
||||
0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,
|
||||
0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,
|
||||
0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x37,0x20,0x5b,0x5b,0x62,
|
||||
0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,
|
||||
0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
|
||||
0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,
|
||||
0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x69,0x6e,
|
||||
0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,
|
||||
0x32,0x38,0x2c,0x20,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,
|
||||
0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,
|
||||
0x33,0x33,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,
|
||||
0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,
|
||||
0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x34,0x39,
|
||||
0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,
|
||||
0x61,0x67,0x6d,0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,
|
||||
0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x2e,0x64,
|
||||
0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,
|
||||
0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,
|
||||
0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x66,0x61,0x73,
|
||||
0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x28,0x2d,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,
|
||||
0x73,0x71,0x72,0x74,0x28,0x5f,0x34,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,
|
||||
0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,
|
||||
0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend backend) {
|
||||
if (backend == SG_BACKEND_GLCORE) {
|
||||
|
|
@ -475,6 +808,12 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend
|
|||
desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame";
|
||||
desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT;
|
||||
desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[1].size = 32;
|
||||
desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
|
||||
desc.uniform_blocks[1].glsl_uniforms[0].array_count = 2;
|
||||
desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass";
|
||||
desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[2].size = 16;
|
||||
|
|
@ -506,6 +845,10 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend
|
|||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 64;
|
||||
desc.uniform_blocks[0].hlsl_register_b_n = 0;
|
||||
desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT;
|
||||
desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[1].size = 32;
|
||||
desc.uniform_blocks[1].hlsl_register_b_n = 1;
|
||||
desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[2].size = 16;
|
||||
|
|
@ -531,6 +874,10 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend
|
|||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 64;
|
||||
desc.uniform_blocks[0].msl_buffer_n = 0;
|
||||
desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT;
|
||||
desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[1].size = 32;
|
||||
desc.uniform_blocks[1].msl_buffer_n = 1;
|
||||
desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[2].size = 16;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -131,6 +131,7 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
|
|
@ -140,9 +141,11 @@ layout( binding = 1 ) uniform ub_pass
|
|||
vec4 camera_pos; // .xyz = camera world pos, .w unused
|
||||
mat4 view_proj; // for reverse-Z gl_FragDepth
|
||||
mat4 view; // for view-space depth debug mode + cascade selection
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
|
@ -171,54 +174,57 @@ layout( binding = 3 ) uniform sampler smp_ao;
|
|||
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
// Normal-offset shadows, see cube.glsl for the longer note.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width. See cube.glsl for the longer note.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Slide the lookup along the surface far enough to clear the whole
|
||||
// scaled 7x7 footprint, growing toward grazing light.
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
// Backend-dependent Y orientation, see cube.glsl for the longer note.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float bias = mix( 0.0040, 0.0008, n_dot_l );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// See cube.glsl for the longer note. Cascade 2 has no fallback at its
|
||||
// UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the
|
||||
// polygonal seam where cascade 2's spatial extent ends on the ground.
|
||||
if ( cascade == 2 )
|
||||
// The white border dissolves the XY boundary, only reject past the
|
||||
// kernel's reach. See cube.glsl for the longer note.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade
|
||||
// to hide the polygonal step where they meet. See cube.glsl for the
|
||||
// longer note.
|
||||
if ( cascade < 2 )
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
|
|
@ -408,25 +414,16 @@ void main()
|
|||
if ( flags.x == 2 )
|
||||
{
|
||||
float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z;
|
||||
int cascade = 2;
|
||||
if ( view_z_dbg < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z_dbg < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg );
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
else if ( cascade == 1 )
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
else
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
// debug_view_mode (ub_pass.flags.x) selects the output:
|
||||
// 0 = Lambert + ambient * shadow factor.
|
||||
// 1 = view-space distance from camera as grayscale.
|
||||
// 2 = cascade-index tint (red/green/blue = cascade 0/1/2, white = UV
|
||||
// 2 = cascade-index tint (one color per cascade, white = UV
|
||||
// out of bounds on the chosen cascade, i.e. unsampled).
|
||||
//
|
||||
// UBO bindings are stage-specific in sokol-shdc.
|
||||
|
|
@ -101,19 +101,22 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting
|
||||
vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback)
|
||||
ivec4 flags; // .x = debug_view_mode
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
mat4 view; // IBL: world->view rotation for view->world n_view transform
|
||||
vec4 camera_pos_world; // IBL: world camera pos for V_world derivation
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting
|
||||
vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback)
|
||||
ivec4 flags; // .x = debug_view_mode
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
mat4 view; // IBL: world->view rotation for view->world n_view transform
|
||||
vec4 camera_pos_world; // IBL: world camera pos for V_world derivation
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
||||
// binding=1 (not 0): sokol-shdc enforces disjoint binding numbers between
|
||||
|
|
@ -155,87 +158,92 @@ out vec4 out_color;
|
|||
// Kernel details and the X3570 unrolling note live in the include.
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
float sampleCascade( int cascade, vec3 world_pos, float n_dot_l )
|
||||
// Normal-offset shadows. A depth bias pushes the comparison back along
|
||||
// the light, which detaches contact shadows and can never win at a
|
||||
// silhouette where the stored depth gradient is effectively infinite.
|
||||
// Moving the lookup sideways along the surface normal instead reads a
|
||||
// well-behaved part of the map and leaves the compared depth alone, so
|
||||
// contacts stay welded to the ground.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal, float n_dot_l )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width instead of going crisp to blurry at every
|
||||
// boundary. The floor leaves the taps about two texels apart, close
|
||||
// enough that the hardware 2x2 compare still overlaps them.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Sine of the angle between surface and light. Zero facing the light
|
||||
// where no offset is wanted, growing toward grazing. The offset has to
|
||||
// clear the whole filter, not one texel, or the outer ring of the
|
||||
// kernel self-shadows into a texel-quantized comb along the
|
||||
// terminator. 3 texels is the scaled 7x7 half-width, plus the sampling
|
||||
// snap, and the root two reaches the kernel's corner tap.
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
|
||||
// UV.y orientation is BACKEND-DEPENDENT. D3D11/Metal/WebGPU sample
|
||||
// render targets with V = 0 at the top (NDC.y = +1 -> texture row 0),
|
||||
// they need UV.y = 0.5 - NDC.y * 0.5. OpenGL samples with V = 0 at
|
||||
// the bottom (NDC.y = +1 -> top row N-1), it needs the textbook
|
||||
// UV.y = NDC.y * 0.5 + 0.5. Renderer side sets cascade_far_view_z.w
|
||||
// to -1 on D3D11/Metal/WGPU and +1 on glcore so a single multiply
|
||||
// UV.y = NDC.y * 0.5 + 0.5. Renderer side sets the sign to -1 on
|
||||
// D3D11/Metal/WGPU and +1 on glcore so a single multiply
|
||||
// here picks the right convention.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// Slope-scaled bias: tan(angle to light) = sqrt(1 - n.l^2) / n.l.
|
||||
// Constant texel-step factor keeps the bias roughly the same world
|
||||
// size across cascades (each cascade's depth range scales with its
|
||||
// bounding sphere, bias scales with it via the texel step).
|
||||
float ndl = clamp( n_dot_l, 0.001, 1.0 );
|
||||
float tanAngle = sqrt( 1.0 - ndl * ndl ) / ndl;
|
||||
float texelDepthStep = 0.001;
|
||||
float bias = clamp( texelDepthStep * tanAngle, 0.0005, 0.05 );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// Cascade 2 is the last cascade, sampleShadowCascaded's view-z blend
|
||||
// has nothing to blend into beyond it. On flat ground at glancing sun
|
||||
// angles PCF inside the cascade reads slightly below 1.0 (bias slop
|
||||
// across a kernel that covers ~5 cm of world per texel here), while
|
||||
// fragments outside the cascade's spatial sphere fall through to the
|
||||
// OOB return of 1.0. Without smoothing, cascade 2's UV boundary reads
|
||||
// as a hexagonal polygon on the ground. Fade PCF toward 1.0 over the
|
||||
// outer 10% of UV space to hide the seam.
|
||||
if ( cascade == 2 )
|
||||
// No hard XY bounds test. The sampler's white border makes taps past
|
||||
// the edge compare lit, so the boundary dissolves across the kernel
|
||||
// rather than flipping whole pixels between sampled and lit as the
|
||||
// texel snap steps the map. Rejecting only what lies beyond the
|
||||
// kernel's reach is exact and spares nine taps for everything well
|
||||
// outside the cascade.
|
||||
//
|
||||
// The 3 * scale here and in the normal offset above both encode the
|
||||
// 7x7 kernel's three-texel radius. Widen the kernel and both have to
|
||||
// grow, or the outer ring self-shadows along the terminator.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
// n_dot_l is the (clamped) dot of the surface normal with the sun
|
||||
// direction, passed in by the caller in whichever space is convenient
|
||||
// (rotation-invariant, same value in view and world space).
|
||||
float sampleShadowCascaded( vec3 world_pos, float n_dot_l, float view_z )
|
||||
// (rotation-invariant, same value in view and world space). The normal
|
||||
// itself must be world space, it steers the normal offset.
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float n_dot_l, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
{
|
||||
cascade = 0;
|
||||
}
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
{
|
||||
cascade = 1;
|
||||
}
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, n_dot_l );
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal, n_dot_l );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade.
|
||||
// Each cascade uses the same slope-scaled bias in shadow-UV units,
|
||||
// but cascades cover very different world extents (cascade 0 ~= 1 m,
|
||||
// cascade 2 ~= 25 m+), so PCF response on flat receivers differs
|
||||
// slightly per cascade, without this blend the boundary reads as a
|
||||
// polygonal step on the ground at glancing sun angles.
|
||||
if ( cascade < 2 )
|
||||
// Texel density jumps by roughly 2.5x at every boundary, so even with
|
||||
// matched bias the penumbra width changes there. Without the blend
|
||||
// that reads as a polygonal step on the ground.
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
float alpha = ( view_z - blend_start ) / ( far_z - blend_start );
|
||||
shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, n_dot_l ), alpha );
|
||||
shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, world_normal, n_dot_l ), alpha );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -255,14 +263,14 @@ void main()
|
|||
// GL's dFdy points in +view_y (screen origin is lower-left), while HLSL
|
||||
// ddy and Metal dfdy point in -view_y (screen origin is upper-left).
|
||||
// sokol-shdc cross-compiles dFdy->ddy/dfdy without a sign flip, so the raw
|
||||
// value's screen direction depends on the backend. cascade_far_view_z.w
|
||||
// value's screen direction depends on the backend. shadow_params.x
|
||||
// is +1 on glcore/gles3 and -1 on D3D11/Metal/WGPU (same flag used by
|
||||
// the shadow UV.y remap below), negating it gives a multiplier that
|
||||
// canonicalizes dFdy to the -view_y direction on every backend. With
|
||||
// canonical dy, cross(dy, dx) = (-view_y) x (+view_x) = +view_z, which
|
||||
// points toward the camera (out of the screen), the correct outward
|
||||
// normal for a back-culled front face.
|
||||
vec3 dy = dFdy( v_view_pos ) * ( -cascade_far_view_z.w );
|
||||
vec3 dy = dFdy( v_view_pos ) * ( -shadow_params.x );
|
||||
vec3 n_view = normalize( cross( dy, dx ) );
|
||||
|
||||
float view_z = -v_view_pos.z;
|
||||
|
|
@ -278,36 +286,17 @@ void main()
|
|||
// Debug view : shadow cascades
|
||||
if ( flags.x == 2 )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
{
|
||||
cascade = 0;
|
||||
}
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
{
|
||||
cascade = 1;
|
||||
}
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( v_world_pos, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
{
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
}
|
||||
else if ( cascade == 1 )
|
||||
{
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
}
|
||||
else
|
||||
{
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
}
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
@ -335,23 +324,25 @@ void main()
|
|||
return;
|
||||
}
|
||||
|
||||
// The shadow normal offset and IBL both need a world-space N. view is
|
||||
// the world->view matrix, its 3x3 is orthonormal (camera rotation), so
|
||||
// transpose(mat3(view)) takes view-space -> world-space without
|
||||
// inverse cost. Stays clear of the D3D11 cross-product handedness trap
|
||||
// that forced n_view to be computed in view space. Only rotate here,
|
||||
// no derivatives.
|
||||
mat3 view_to_world = transpose( mat3( view ) );
|
||||
vec3 N_world = normalize( view_to_world * n_view );
|
||||
|
||||
// dot(n, L) is rotation-invariant. Same value with view-space or world-space
|
||||
// normals + sun directions. Use the view-space pair for direct light.
|
||||
vec3 L = normalize( sun_dir_view.xyz );
|
||||
float n_dot_l = max( dot( n_view, L ), 0.0 );
|
||||
float shadow = sampleShadowCascaded( v_world_pos, n_dot_l, view_z );
|
||||
float shadow = sampleShadowCascaded( v_world_pos, N_world, n_dot_l, view_z );
|
||||
|
||||
// Camera sits at origin in view space, so V_view = normalize(-v_view_pos).
|
||||
vec3 V_view = normalize( -v_view_pos );
|
||||
vec3 direct = brdf_evaluate( n_view, V_view, L, sun_color.rgb * shadow, v_base_color.rgb, v_material.x, v_material.y );
|
||||
|
||||
// IBL needs world-space N and V. view is the world->view matrix, its
|
||||
// 3x3 is orthonormal (camera rotation), so transpose(mat3(view))
|
||||
// takes view-space -> world-space without inverse cost. Stays clear
|
||||
// of the D3D11 cross-product handedness trap that forced n_view to
|
||||
// be computed in view space. Only rotate here, no derivatives.
|
||||
mat3 view_to_world = transpose( mat3( view ) );
|
||||
vec3 N_world = normalize( view_to_world * n_view );
|
||||
vec3 V_world = normalize( camera_pos_world.xyz - v_world_pos );
|
||||
vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, N_world, V_world, v_base_color.rgb, v_material.x, v_material.y,
|
||||
sun_color.a, sh, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x );
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
|
|
@ -110,9 +111,11 @@ layout( binding = 1 ) uniform ub_pass
|
|||
vec4 camera_pos; // .xyz = camera world pos, .w unused
|
||||
vec4 grid_offset; // .xy = origin wrapped to grid period (lines), .zw = full origin (axes)
|
||||
mat4 view; // for view-space depth debug mode + cascade selection
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
|
@ -141,54 +144,57 @@ layout( binding = 3 ) uniform sampler smp_ao;
|
|||
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
// Normal-offset shadows, see cube.glsl for the longer note.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width. See cube.glsl for the longer note.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Slide the lookup along the surface far enough to clear the whole
|
||||
// scaled 7x7 footprint, growing toward grazing light.
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
// Backend-dependent Y orientation, see cube.glsl for the longer note.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float bias = mix( 0.0040, 0.0008, n_dot_l );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// See cube.glsl for the longer note. Cascade 2 has no fallback at its
|
||||
// UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the
|
||||
// polygonal seam where cascade 2's spatial extent ends on the ground.
|
||||
if ( cascade == 2 )
|
||||
// The white border dissolves the XY boundary, only reject past the
|
||||
// kernel's reach. See cube.glsl for the longer note.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade
|
||||
// to hide the polygonal step where they meet. See cube.glsl for the
|
||||
// longer note.
|
||||
if ( cascade < 2 )
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
|
|
@ -230,25 +236,16 @@ void main()
|
|||
{
|
||||
// v_view_pos is actually world_pos forwarded from the VS.
|
||||
float view_z_dbg = -( view * vec4( v_view_pos, 1.0 ) ).z;
|
||||
int cascade = 2;
|
||||
if ( view_z_dbg < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z_dbg < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg );
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( v_view_pos, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
else if ( cascade == 1 )
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
else
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,28 +1,18 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Shadow caster for capsules. As with the sphere caster, we substitute
|
||||
// a proxy mesh for the analytic impostor. The proxy is a lat/long cylinder
|
||||
// with two hemispherical caps (see BuildCapsuleProxy in renderer.c for
|
||||
// counts and the silhouette-straddling scale). Vertices are authored in
|
||||
// a "unit-capsule" coordinate frame where each component carries enough
|
||||
// information to scale independently by halfLength and radius.
|
||||
// Shadow caster for capsules. See shadow_caster_sphere.glsl for why the
|
||||
// analytic surface is worth the fill cost and what `depth_greater` rests
|
||||
// on.
|
||||
//
|
||||
// Each vertex is encoded as two attributes:
|
||||
// in_axis, direction along the long axis (vec3). Scaled by halfLength.
|
||||
// For body verts: (+/-1, 0, 0). For cap verts: same as the
|
||||
// attached cap (i.e., (+1,0,0) for +X cap, (-1,0,0) for -X).
|
||||
// in_radial, radial offset (vec3). Scaled by radius. For body verts:
|
||||
// (0, cos theta, sin theta). For cap verts: an extension of the
|
||||
// hemisphere parameterization that includes the cap's
|
||||
// axial bulge, e.g. for +X cap at latitude alpha: in_radial =
|
||||
// (sin alpha, cos alpha cos beta, cos alpha sin beta).
|
||||
// Rasterizes the same OBB the lit capsule impostor uses, half-extents
|
||||
// (halfLength + radius, radius, radius) about the local +X axis.
|
||||
//
|
||||
// The world position is then
|
||||
// world = center + R * (in_axis * halfLength + in_radial * radius)
|
||||
// where R is the capsule's rotation. Since rotation is orthonormal and
|
||||
// halfLength/radius are scalars, the encoding scales linearly and
|
||||
// produces a true capsule for any (halfLength, radius) pair.
|
||||
// Only the entry point matters here, not the normal, so this is a
|
||||
// cheaper intersection than the lit shader's. The capsule is the union
|
||||
// of a finite cylinder and two cap spheres, and the entry into a union
|
||||
// is the nearest entry across its parts, so the hemisphere-rejection
|
||||
// the lit shader needs for correct normals is unnecessary.
|
||||
//
|
||||
// `@module shadow_capsule` namespaces the generated symbols.
|
||||
|
||||
|
|
@ -61,8 +51,14 @@ layout( binding = 0 ) readonly buffer instances
|
|||
instance items[];
|
||||
};
|
||||
|
||||
in vec3 in_axis; // axis-direction component, scaled by halfLength
|
||||
in vec3 in_radial; // radial component, scaled by radius
|
||||
in vec3 in_pos; // unit-cube corner, half-extent 0.5
|
||||
|
||||
out vec3 v_world_pos_proxy;
|
||||
|
||||
flat out vec3 v_center;
|
||||
flat out float v_half_length;
|
||||
flat out float v_radius;
|
||||
flat out vec3 v_axis_x_world;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -71,16 +67,120 @@ void main()
|
|||
float halfLength = inst.params.x;
|
||||
float radius = inst.params.y;
|
||||
|
||||
vec3 local_pos = in_axis * halfLength + in_radial * radius;
|
||||
vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, local_pos ), dot( inst.xform_row1.xyz, local_pos ),
|
||||
dot( inst.xform_row2.xyz, local_pos ) );
|
||||
vec3 obj_pos = vec3( in_pos.x * 2.0 * ( halfLength + radius ), in_pos.y * 2.0 * radius, in_pos.z * 2.0 * radius );
|
||||
vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, obj_pos ), dot( inst.xform_row1.xyz, obj_pos ),
|
||||
dot( inst.xform_row2.xyz, obj_pos ) );
|
||||
|
||||
v_world_pos_proxy = world_pos;
|
||||
v_center = center;
|
||||
v_half_length = halfLength;
|
||||
v_radius = radius;
|
||||
// Local +X in world is the first column of R.
|
||||
v_axis_x_world = vec3( inst.xform_row0.x, inst.xform_row1.x, inst.xform_row2.x );
|
||||
|
||||
gl_Position = light_view_proj * vec4( world_pos, 1.0 );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
#pragma sokol @fs fs
|
||||
|
||||
// UBOs are per-stage in sokol-shdc, so this is a second block rather
|
||||
// than a reuse of the VS ub_frame.
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
vec4 light_dir; // .xyz = world-space direction light travels (normalized)
|
||||
vec4 depth_row; // depth row of the light view-proj, world position to clip depth
|
||||
};
|
||||
|
||||
in vec3 v_world_pos_proxy;
|
||||
|
||||
flat in vec3 v_center;
|
||||
flat in float v_half_length;
|
||||
flat in float v_radius;
|
||||
flat in vec3 v_axis_x_world;
|
||||
|
||||
layout( depth_greater ) out float gl_FragDepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ro = v_world_pos_proxy;
|
||||
vec3 rd = light_dir.xyz;
|
||||
|
||||
vec3 pa = v_center - v_half_length * v_axis_x_world;
|
||||
vec3 pb = v_center + v_half_length * v_axis_x_world;
|
||||
|
||||
// Ray-cylinder, Quilez closed form.
|
||||
// Reference: https://iquilezles.org/articles/intersectors/
|
||||
vec3 ba = pb - pa;
|
||||
vec3 oa = ro - pa;
|
||||
float baba = dot( ba, ba );
|
||||
float bard = dot( ba, rd );
|
||||
float baoa = dot( ba, oa );
|
||||
float rdoa = dot( rd, oa );
|
||||
float oaoa = dot( oa, oa );
|
||||
|
||||
float a_c = baba - bard * bard;
|
||||
float b_c = baba * rdoa - baoa * bard;
|
||||
float c_c = baba * oaoa - baoa * baoa - v_radius * v_radius * baba;
|
||||
float h_c = b_c * b_c - a_c * c_c;
|
||||
|
||||
float t = -1.0;
|
||||
|
||||
// Entry into each part, clamped forward rather than rejected. The
|
||||
// proxy faces are tangent to the surface along a line, and rounding
|
||||
// there puts the origin a hair inside, which drives the near root
|
||||
// negative. Treating that as a miss punches a dashed hole straight
|
||||
// down the middle of the shadow. A part whose far root is behind us
|
||||
// too is a genuine miss, which is what the end faces need: they sit
|
||||
// beyond one cap and the other cap is legitimately behind.
|
||||
//
|
||||
// a_c collapses when the ray runs along the axis, the caps cover
|
||||
// that case. baba collapses when halfLength is zero, and the axial
|
||||
// range test rejects the body for free.
|
||||
if ( h_c >= 0.0 && a_c > 1e-8 )
|
||||
{
|
||||
float q = sqrt( h_c );
|
||||
if ( -b_c + q >= 0.0 )
|
||||
{
|
||||
float t_body = max( ( -b_c - q ) / a_c, 0.0 );
|
||||
float y = baoa + t_body * bard;
|
||||
if ( y > 0.0 && y < baba )
|
||||
{
|
||||
t = t_body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cap spheres at both ends.
|
||||
for ( int i = 0; i < 2; ++i )
|
||||
{
|
||||
vec3 p = ( i == 0 ) ? pa : pb;
|
||||
vec3 oc = ro - p;
|
||||
float b = dot( oc, rd );
|
||||
float c = dot( oc, oc ) - v_radius * v_radius;
|
||||
float h = b * b - c;
|
||||
if ( h >= 0.0 )
|
||||
{
|
||||
float q = sqrt( h );
|
||||
if ( -b + q >= 0.0 )
|
||||
{
|
||||
float tc = max( -b - q, 0.0 );
|
||||
if ( t < 0.0 || tc < t )
|
||||
{
|
||||
t = tc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( t < 0.0 )
|
||||
{
|
||||
// OBB corner, the ray clears the capsule.
|
||||
discard;
|
||||
}
|
||||
|
||||
// Orthographic light, so the clip w is 1 and the divide drops out.
|
||||
gl_FragDepth = dot( depth_row, vec4( ro + t * rd, 1.0 ) );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,36 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Shadow caster for spheres. The lit sphere pipeline ray-casts an
|
||||
// analytic sphere from a bounding-cube proxy, but we can't afford to
|
||||
// write gl_FragDepth in a depth-only shadow pass (early-Z killed, high
|
||||
// shadow-map resolution makes the cost prohibitive). Instead the shadow
|
||||
// pipeline rasterizes a low-poly icosphere proxy (subdiv-1, 42 verts, 80
|
||||
// tris) generated at InitRenderer and stored in dedicated icosphere vbuf/ibuf.
|
||||
// Shadow caster for spheres. Rasterizes the same bounding cube the lit
|
||||
// impostor uses and ray-casts the exact sphere, so caster and receiver
|
||||
// agree on where the surface is and bias only has to cover projection
|
||||
// and PCF slope. An inscribed proxy mesh falls short of the true surface
|
||||
// by a couple percent of the radius, and that gap has to be paid for
|
||||
// with extra depth bias.
|
||||
//
|
||||
// Per-vertex: in_pos is a unit-sphere position (length == 1). Per-instance
|
||||
// reads from the same sphere instance buffer the lit pipeline uses, the
|
||||
// rotation rows are ignored (a sphere is rotation-invariant) and only
|
||||
// the center (xform_row*.w) and radius (params.x) participate.
|
||||
// The light is directional, so every ray is parallel: the origin is the
|
||||
// proxy fragment's world position and the direction is the direction
|
||||
// light travels. Under an orthographic projection depth is linear in
|
||||
// distance along that direction, so marching forward from the proxy
|
||||
// face can only push depth away from the light. Hence
|
||||
// `layout(depth_greater)`, which lets the hardware keep early-Z
|
||||
// rejection despite the gl_FragDepth write. The promise rests on the
|
||||
// pipeline culling back faces, so the rasterized surface is always the
|
||||
// light-facing one.
|
||||
//
|
||||
// Depth is rebuilt from the projection's depth row rather than advanced
|
||||
// from gl_FragCoord.z, which would be one madd instead of a dot4. D3D11
|
||||
// rejects a pixel shader that both reads SV_Position and writes
|
||||
// conservative depth unless the position input is declared
|
||||
// noperspective centroid or sample, and neither GLSL nor SPIRV-Cross
|
||||
// gives us a way to qualify it. The two agree to within rounding: the
|
||||
// only place they can disagree is the single point where the proxy face
|
||||
// is tangent to the surface.
|
||||
//
|
||||
// Per-instance reads from the same sphere instance buffer the lit
|
||||
// pipeline uses. The rotation rows are ignored (a sphere is
|
||||
// rotation-invariant) and only the center (xform_row*.w) and radius
|
||||
// (params.x) participate.
|
||||
//
|
||||
// `@module shadow_sphere` namespaces the generated symbols.
|
||||
|
||||
|
|
@ -50,21 +69,70 @@ layout( binding = 0 ) readonly buffer instances
|
|||
instance items[];
|
||||
};
|
||||
|
||||
in vec3 in_pos; // unit-icosphere vertex (length == 1)
|
||||
in vec3 in_pos; // unit-cube corner, half-extent 0.5
|
||||
|
||||
out vec3 v_world_pos_proxy;
|
||||
|
||||
flat out vec3 v_center;
|
||||
flat out float v_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
instance inst = items[inst_base.x + gl_InstanceIndex];
|
||||
vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w );
|
||||
float radius = inst.params.x;
|
||||
vec3 world_pos = center + radius * in_pos;
|
||||
|
||||
// Half-extent 0.5 scaled by 2*radius gives a cube exactly enclosing
|
||||
// the sphere. Rotation is skipped, a sphere is rotation-invariant.
|
||||
vec3 world_pos = center + ( 2.0 * radius ) * in_pos;
|
||||
|
||||
v_world_pos_proxy = world_pos;
|
||||
v_center = center;
|
||||
v_radius = radius;
|
||||
|
||||
gl_Position = light_view_proj * vec4( world_pos, 1.0 );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
#pragma sokol @fs fs
|
||||
|
||||
// UBOs are per-stage in sokol-shdc, so this is a second block rather
|
||||
// than a reuse of the VS ub_frame.
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
vec4 light_dir; // .xyz = world-space direction light travels (normalized)
|
||||
vec4 depth_row; // depth row of the light view-proj, world position to clip depth
|
||||
};
|
||||
|
||||
in vec3 v_world_pos_proxy;
|
||||
|
||||
flat in vec3 v_center;
|
||||
flat in float v_radius;
|
||||
|
||||
layout( depth_greater ) out float gl_FragDepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ro = v_world_pos_proxy;
|
||||
vec3 rd = light_dir.xyz;
|
||||
|
||||
// Ray-sphere, near root. Reference: https://iquilezles.org/articles/intersectors/
|
||||
vec3 oc = ro - v_center;
|
||||
float b = dot( oc, rd );
|
||||
float c = dot( oc, oc ) - v_radius * v_radius;
|
||||
float h = b * b - c;
|
||||
if ( h < 0.0 )
|
||||
{
|
||||
// Cube corner, the ray clears the sphere.
|
||||
discard;
|
||||
}
|
||||
|
||||
// Non-negative because the proxy face is tangent to the sphere at
|
||||
// worst, never inside it.
|
||||
float t = max( -b - sqrt( h ), 0.0 );
|
||||
|
||||
// Orthographic light, so the clip w is 1 and the divide drops out.
|
||||
gl_FragDepth = dot( depth_row, vec4( ro + t * rd, 1.0 ) );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
|
|
@ -137,9 +138,11 @@ layout( binding = 1 ) uniform ub_pass
|
|||
vec4 camera_pos; // .xyz = camera world pos, .w unused
|
||||
mat4 view_proj; // for reverse-Z gl_FragDepth
|
||||
mat4 view; // for view-space depth debug mode + cascade selection
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
|
@ -168,54 +171,57 @@ layout( binding = 3 ) uniform sampler smp_ao;
|
|||
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
// Normal-offset shadows, see cube.glsl for the longer note.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width. See cube.glsl for the longer note.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Slide the lookup along the surface far enough to clear the whole
|
||||
// scaled 7x7 footprint, growing toward grazing light.
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
// Backend-dependent Y orientation, see cube.glsl for the longer note.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float bias = mix( 0.0040, 0.0008, n_dot_l );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// See cube.glsl for the longer note. Cascade 2 has no fallback at its
|
||||
// UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the
|
||||
// polygonal seam where cascade 2's spatial extent ends on the ground.
|
||||
if ( cascade == 2 )
|
||||
// The white border dissolves the XY boundary, only reject past the
|
||||
// kernel's reach. See cube.glsl for the longer note.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade
|
||||
// to hide the polygonal step where they meet. See cube.glsl for the
|
||||
// longer note.
|
||||
if ( cascade < 2 )
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
|
|
@ -337,25 +343,16 @@ void main()
|
|||
if ( flags.x == 2 )
|
||||
{
|
||||
float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z;
|
||||
int cascade = 2;
|
||||
if ( view_z_dbg < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z_dbg < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg );
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
else if ( cascade == 1 )
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
else
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue