Move shaders into glsl and hlsl directories
Move `data/shaders` to `data/shaders/glsl` Move `data/hlsl` to `data/shaders/hlsl` Fix up shader paths in the cpp files to point to the new glsl location. `data/shaders/hlsl/compile.py` still overwrites the glsl .spv files (for now). Issue: #723
This commit is contained in:
parent
cac1d2e850
commit
ca884587a4
1043 changed files with 1207 additions and 1201 deletions
14
data/shaders/glsl/shadowmappingcascade/debugshadowmap.frag
Normal file
14
data/shaders/glsl/shadowmappingcascade/debugshadowmap.frag
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2DArray shadowMap;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
layout (location = 1) flat in uint inCascadeIndex;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = texture(shadowMap, vec3(inUV, float(inCascadeIndex))).r;
|
||||
outFragColor = vec4(vec3((depth)), 1.0);
|
||||
}
|
||||
BIN
data/shaders/glsl/shadowmappingcascade/debugshadowmap.frag.spv
Normal file
BIN
data/shaders/glsl/shadowmappingcascade/debugshadowmap.frag.spv
Normal file
Binary file not shown.
20
data/shaders/glsl/shadowmappingcascade/debugshadowmap.vert
Normal file
20
data/shaders/glsl/shadowmappingcascade/debugshadowmap.vert
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform PushConsts {
|
||||
vec4 position;
|
||||
uint cascadeIndex;
|
||||
} pushConsts;
|
||||
|
||||
layout (location = 0) out vec2 outUV;
|
||||
layout (location = 1) out uint outCascadeIndex;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
outCascadeIndex = pushConsts.cascadeIndex;
|
||||
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
BIN
data/shaders/glsl/shadowmappingcascade/debugshadowmap.vert.spv
Normal file
BIN
data/shaders/glsl/shadowmappingcascade/debugshadowmap.vert.spv
Normal file
Binary file not shown.
13
data/shaders/glsl/shadowmappingcascade/depthpass.frag
Normal file
13
data/shaders/glsl/shadowmappingcascade/depthpass.frag
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#version 450
|
||||
|
||||
layout (set = 1, binding = 0) uniform sampler2D colorMap;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
|
||||
void main()
|
||||
{
|
||||
float alpha = texture(colorMap, inUV).a;
|
||||
if (alpha < 0.5) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
BIN
data/shaders/glsl/shadowmappingcascade/depthpass.frag.spv
Normal file
BIN
data/shaders/glsl/shadowmappingcascade/depthpass.frag.spv
Normal file
Binary file not shown.
29
data/shaders/glsl/shadowmappingcascade/depthpass.vert
Normal file
29
data/shaders/glsl/shadowmappingcascade/depthpass.vert
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec3 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
|
||||
// todo: pass via specialization constant
|
||||
#define SHADOW_MAP_CASCADE_COUNT 4
|
||||
|
||||
layout(push_constant) uniform PushConsts {
|
||||
vec4 position;
|
||||
uint cascadeIndex;
|
||||
} pushConsts;
|
||||
|
||||
layout (binding = 0) uniform UBO {
|
||||
mat4[SHADOW_MAP_CASCADE_COUNT] cascadeViewProjMat;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec2 outUV;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
outUV = inUV;
|
||||
vec3 pos = inPos + pushConsts.position.xyz;
|
||||
gl_Position = ubo.cascadeViewProjMat[pushConsts.cascadeIndex] * vec4(pos, 1.0);
|
||||
}
|
||||
BIN
data/shaders/glsl/shadowmappingcascade/depthpass.vert.spv
Normal file
BIN
data/shaders/glsl/shadowmappingcascade/depthpass.vert.spv
Normal file
Binary file not shown.
123
data/shaders/glsl/shadowmappingcascade/scene.frag
Normal file
123
data/shaders/glsl/shadowmappingcascade/scene.frag
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#version 450
|
||||
|
||||
#define SHADOW_MAP_CASCADE_COUNT 4
|
||||
|
||||
layout (set = 0, binding = 1) uniform sampler2DArray shadowMap;
|
||||
layout (set = 1, binding = 0) uniform sampler2D colorMap;
|
||||
|
||||
layout (location = 0) in vec3 inNormal;
|
||||
layout (location = 1) in vec3 inColor;
|
||||
layout (location = 2) in vec3 inViewPos;
|
||||
layout (location = 3) in vec3 inPos;
|
||||
layout (location = 4) in vec2 inUV;
|
||||
|
||||
layout (constant_id = 0) const int enablePCF = 0;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
#define ambient 0.3
|
||||
|
||||
layout (set = 0, binding = 2) uniform UBO {
|
||||
vec4 cascadeSplits;
|
||||
mat4 cascadeViewProjMat[SHADOW_MAP_CASCADE_COUNT];
|
||||
mat4 inverseViewMat;
|
||||
vec3 lightDir;
|
||||
float _pad;
|
||||
int colorCascades;
|
||||
} ubo;
|
||||
|
||||
const mat4 biasMat = mat4(
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.5, 0.5, 0.0, 1.0
|
||||
);
|
||||
|
||||
float textureProj(vec4 shadowCoord, vec2 offset, uint cascadeIndex)
|
||||
{
|
||||
float shadow = 1.0;
|
||||
float bias = 0.005;
|
||||
|
||||
if ( shadowCoord.z > -1.0 && shadowCoord.z < 1.0 ) {
|
||||
float dist = texture(shadowMap, vec3(shadowCoord.st + offset, cascadeIndex)).r;
|
||||
if (shadowCoord.w > 0 && dist < shadowCoord.z - bias) {
|
||||
shadow = ambient;
|
||||
}
|
||||
}
|
||||
return shadow;
|
||||
|
||||
}
|
||||
|
||||
float filterPCF(vec4 sc, uint cascadeIndex)
|
||||
{
|
||||
ivec2 texDim = textureSize(shadowMap, 0).xy;
|
||||
float scale = 0.75;
|
||||
float dx = scale * 1.0 / float(texDim.x);
|
||||
float dy = scale * 1.0 / float(texDim.y);
|
||||
|
||||
float shadowFactor = 0.0;
|
||||
int count = 0;
|
||||
int range = 1;
|
||||
|
||||
for (int x = -range; x <= range; x++) {
|
||||
for (int y = -range; y <= range; y++) {
|
||||
shadowFactor += textureProj(sc, vec2(dx*x, dy*y), cascadeIndex);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return shadowFactor / count;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(colorMap, inUV);
|
||||
if (color.a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Get cascade index for the current fragment's view position
|
||||
uint cascadeIndex = 0;
|
||||
for(uint i = 0; i < SHADOW_MAP_CASCADE_COUNT - 1; ++i) {
|
||||
if(inViewPos.z < ubo.cascadeSplits[i]) {
|
||||
cascadeIndex = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Depth compare for shadowing
|
||||
vec4 shadowCoord = (biasMat * ubo.cascadeViewProjMat[cascadeIndex]) * vec4(inPos, 1.0);
|
||||
|
||||
float shadow = 0;
|
||||
if (enablePCF == 1) {
|
||||
shadow = filterPCF(shadowCoord / shadowCoord.w, cascadeIndex);
|
||||
} else {
|
||||
shadow = textureProj(shadowCoord / shadowCoord.w, vec2(0.0), cascadeIndex);
|
||||
}
|
||||
|
||||
// Directional light
|
||||
vec3 N = normalize(inNormal);
|
||||
vec3 L = normalize(-ubo.lightDir);
|
||||
vec3 H = normalize(L + inViewPos);
|
||||
float diffuse = max(dot(N, L), ambient);
|
||||
vec3 lightColor = vec3(1.0);
|
||||
outFragColor.rgb = max(lightColor * (diffuse * color.rgb), vec3(0.0));
|
||||
outFragColor.rgb *= shadow;
|
||||
outFragColor.a = color.a;
|
||||
|
||||
// Color cascades (if enabled)
|
||||
if (ubo.colorCascades == 1) {
|
||||
switch(cascadeIndex) {
|
||||
case 0 :
|
||||
outFragColor.rgb *= vec3(1.0f, 0.25f, 0.25f);
|
||||
break;
|
||||
case 1 :
|
||||
outFragColor.rgb *= vec3(0.25f, 1.0f, 0.25f);
|
||||
break;
|
||||
case 2 :
|
||||
outFragColor.rgb *= vec3(0.25f, 0.25f, 1.0f);
|
||||
break;
|
||||
case 3 :
|
||||
outFragColor.rgb *= vec3(1.0f, 1.0f, 0.25f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
data/shaders/glsl/shadowmappingcascade/scene.frag.spv
Normal file
BIN
data/shaders/glsl/shadowmappingcascade/scene.frag.spv
Normal file
Binary file not shown.
39
data/shaders/glsl/shadowmappingcascade/scene.vert
Normal file
39
data/shaders/glsl/shadowmappingcascade/scene.vert
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec3 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inColor;
|
||||
layout (location = 3) in vec3 inNormal;
|
||||
|
||||
layout (binding = 0) uniform UBO {
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec3 outNormal;
|
||||
layout (location = 1) out vec3 outColor;
|
||||
layout (location = 2) out vec3 outViewPos;
|
||||
layout (location = 3) out vec3 outPos;
|
||||
layout (location = 4) out vec2 outUV;
|
||||
|
||||
layout(push_constant) uniform PushConsts {
|
||||
vec4 position;
|
||||
uint cascadeIndex;
|
||||
} pushConsts;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = inColor;
|
||||
outNormal = inNormal;
|
||||
outUV = inUV;
|
||||
vec3 pos = inPos + pushConsts.position.xyz;
|
||||
outPos = pos;
|
||||
outViewPos = (ubo.view * vec4(pos.xyz, 1.0)).xyz;
|
||||
gl_Position = ubo.projection * ubo.view * ubo.model * vec4(pos.xyz, 1.0);
|
||||
}
|
||||
|
||||
BIN
data/shaders/glsl/shadowmappingcascade/scene.vert.spv
Normal file
BIN
data/shaders/glsl/shadowmappingcascade/scene.vert.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue