Skip to content

Commit 9ad03dd

Browse files
committed
integrate new shadow system
1 parent 36275dc commit 9ad03dd

5 files changed

Lines changed: 51 additions & 10 deletions

File tree

code/def_files/data/effects/main-f.sdr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ in VertexOutput {
126126
vec4 shadowPos;
127127
#prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS
128128

129-
#ifdef GL_ES
129+
#ifndef USE_HW_CLIP_DISTANCE
130130
float vClipDist;
131131
#endif
132132
} vertIn;

code/def_files/data/effects/shadow_map-g.sdr

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
//? #version 150
2+
#ifdef GL_ES
3+
#extension GL_EXT_gpu_shader5: enable
4+
#extension GL_EXT_clip_cull_distance: enable
5+
precision highp float;
6+
precision highp int;
7+
#else
28
#extension GL_ARB_gpu_shader5: enable
9+
#endif
10+
11+
#if !defined(GL_ES) || defined(GL_EXT_clip_cull_distance)
12+
#define USE_HW_CLIP_DISTANCE
13+
#endif
314

415
layout (triangles) in;
516
layout (triangle_strip, max_vertices = 3) out;
6-
#ifdef GL_ARB_gpu_shader5
17+
#if defined(GL_ARB_gpu_shader5) || defined(GL_EXT_gpu_shader5)
718
layout(invocations = NUM_SHADOW_CASCADES) in;
819
#endif
920

@@ -18,16 +29,19 @@ layout (std140) uniform shadowCascadeParams {
1829
};
1930

2031
in VertexOutput {
21-
#if !defined(GL_ARB_gpu_shader5)
32+
#if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5)
2233
float instance;
2334
#endif
2435
float clipModel;
2536
vec3 normal;
37+
#ifndef USE_HW_CLIP_DISTANCE
38+
float vClipDist;
39+
#endif
2640
} vertIn[];
2741

2842
void main(void)
2943
{
30-
#ifdef GL_ARB_gpu_shader5
44+
#if defined(GL_ARB_gpu_shader5) || defined(GL_EXT_gpu_shader5)
3145
if (gl_InvocationID >= cascade_count) return;
3246
int cascade_id = cascade_offset + gl_InvocationID;
3347
#else
@@ -43,7 +57,12 @@ void main(void)
4357
}
4458

4559
gl_Layer = cascade_id;
46-
gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0];
60+
61+
#ifndef USE_HW_CLIP_DISTANCE
62+
vertOut.vClipDist = vertIn[vert].vClipDist;
63+
#else
64+
gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0];
65+
#endif
4766

4867
EmitVertex();
4968
}

code/def_files/data/effects/shadow_map-v.sdr

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
//? #version 150
2+
#ifdef GL_ES
3+
#extension GL_EXT_gpu_shader5: enable
4+
#extension GL_EXT_clip_cull_distance: enable
5+
precision highp float;
6+
precision highp int;
7+
precision highp samplerBuffer;
8+
#else
29
#extension GL_ARB_gpu_shader5: enable
3-
410
#ifndef GEOMETRY_FALLBACK
511
#extension GL_ARB_shader_viewport_layer_array : enable
612
#endif
13+
#endif
14+
15+
#if !defined(GL_ES) || defined(GL_EXT_clip_cull_distance)
16+
#define USE_HW_CLIP_DISTANCE
17+
#endif
718

819
in vec4 vertPosition;
920
in vec4 vertTexCoord;
@@ -33,11 +44,14 @@ uniform samplerBuffer transform_tex;
3344

3445
#ifdef GEOMETRY_FALLBACK
3546
out VertexOutput {
36-
#if !defined(GL_ARB_gpu_shader5)
47+
#if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5)
3748
float instance;
3849
#endif
3950
float clipModel;
4051
vec3 normal;
52+
#ifndef USE_HW_CLIP_DISTANCE
53+
float vClipDist;
54+
#endif
4155
} vertOut;
4256
#endif
4357

@@ -67,7 +81,7 @@ void main()
6781
normal = normalize(mat3(modelViewMatrix) * mat3(orient) * vertNormal);
6882
position = modelViewMatrix * orient * vertex;
6983

70-
#if !defined(GL_ARB_gpu_shader5)
84+
#if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5)
7185
#ifdef APPLE
7286
vertOut.instance = float(gl_InstanceIDARB);
7387
#else
@@ -86,11 +100,19 @@ void main()
86100
gl_Position = position;
87101
}
88102

103+
#ifdef USE_HW_CLIP_DISTANCE
89104
if (use_clip_plane) {
90105
gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex);
91106
} else {
92107
gl_ClipDistance[0] = 1.0;
93108
}
109+
#else
110+
if (use_clip_plane) {
111+
vertOut.vClipDist = dot(clip_equation, modelMatrix * orient * vertex);
112+
} else {
113+
vertOut.vClipDist = 1.0;
114+
}
115+
#endif
94116

95117
#ifdef GEOMETRY_FALLBACK
96118
vertOut.normal = normal;

code/def_files/data/effects/shadows.sdr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ float samplePoissonPCSS(sampler2DArrayShadow shadow_map, vec4 shadowUV, float ma
4848
for (int i=0; i<SAMPLES_PCSS; i++) {
4949
vec4 uv = shadowUV;
5050
uv.xy += poissonDisc[i] * maxUVOffset;
51-
visibility += texture(shadow_map, uv).r;
51+
visibility += texture(shadow_map, uv);
5252
}
5353
return visibility * (1.0f/float(SAMPLES_PCSS));
5454
}

code/graphics/opengl/es_compatibility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define GL_CLAMP_VERTEX_COLOR 0x891A
3232
#define GL_CLAMP_FRAGMENT_COLOR 0x891B
3333
#define GL_FIXED_ONLY 0x891D
34-
#define GLAD_GL_ARB_shader_viewport_layer_array 0x8DAE // ES 3.2 Core or GL_OES_viewport_array for 3.0/3.1
34+
#define GLAD_GL_ARB_shader_viewport_layer_array 0 // Disabled, no gl_layer in vertex shader //0x8DAE
3535

3636
//Enums Redefinitions
3737
#define GL_CLIP_DISTANCE0 GL_CLIP_DISTANCE0_EXT // GL_EXT_clip_cull_distance

0 commit comments

Comments
 (0)