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:
Ben Clayton 2020-05-29 16:08:53 +01:00
parent cac1d2e850
commit ca884587a4
1043 changed files with 1207 additions and 1201 deletions

View file

@ -0,0 +1,54 @@
#version 450
layout (binding = 1) uniform samplerCube shadowCubeMap;
layout (location = 0) in vec2 inUV;
layout (location = 0) out vec4 outFragColor;
void main()
{
outFragColor.rgb = vec3(0.0, 0.0, 0.2);
vec3 samplePos = vec3(0.0f);
// Crude statement to visualize different cube map faces based on UV coordinates
int x = int(floor(inUV.x / 0.25f));
int y = int(floor(inUV.y / (1.0 / 3.0)));
if (y == 1) {
vec2 uv = vec2(inUV.x * 4.0f, (inUV.y - 1.0/3.0) * 3.0);
uv = 2.0 * vec2(uv.x - float(x) * 1.0, uv.y) - 1.0;
switch (x) {
case 0: // NEGATIVE_X
samplePos = vec3(-1.0f, uv.y, uv.x);
break;
case 1: // POSITIVE_Z
samplePos = vec3(uv.x, uv.y, 1.0f);
break;
case 2: // POSITIVE_X
samplePos = vec3(1.0, uv.y, -uv.x);
break;
case 3: // NEGATIVE_Z
samplePos = vec3(-uv.x, uv.y, -1.0f);
break;
}
} else {
if (x == 1) {
vec2 uv = vec2((inUV.x - 0.25) * 4.0, (inUV.y - float(y) / 3.0) * 3.0);
uv = 2.0 * uv - 1.0;
switch (y) {
case 0: // NEGATIVE_Y
samplePos = vec3(uv.x, -1.0f, uv.y);
break;
case 2: // POSITIVE_Y
samplePos = vec3(uv.x, 1.0f, -uv.y);
break;
}
}
}
if ((samplePos.x != 0.0f) && (samplePos.y != 0.0f)) {
float dist = length(texture(shadowCubeMap, samplePos).xyz) * 0.005;
outFragColor = vec4(vec3(dist), 1.0);
}
}

View file

@ -0,0 +1,17 @@
#version 450
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
mat4 model;
} ubo;
layout (location = 0) out vec2 outUV;
void main()
{
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUV.xy * 2.0f - 1.0f, 0.0f, 1.0f);
}

View file

@ -0,0 +1,7 @@
glslangvalidator -V offscreen.vert -o offscreen.vert.spv
glslangvalidator -V offscreen.frag -o offscreen.frag.spv
glslangvalidator -V scene.vert -o scene.vert.spv
glslangvalidator -V scene.frag -o scene.frag.spv
glslangvalidator -V cubemapdisplay.vert -o cubemapdisplay.vert.spv
glslangvalidator -V cubemapdisplay.frag -o cubemapdisplay.frag.spv

View file

@ -0,0 +1,13 @@
#version 450
layout (location = 0) out float outFragColor;
layout (location = 0) in vec4 inPos;
layout (location = 1) in vec3 inLightPos;
void main()
{
// Store distance to light as 32 bit float value
vec3 lightVec = inPos.xyz - inLightPos;
outFragColor = length(lightVec);
}

Binary file not shown.

View file

@ -0,0 +1,32 @@
#version 450
layout (location = 0) in vec3 inPos;
layout (location = 0) out vec4 outPos;
layout (location = 1) out vec3 outLightPos;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
mat4 model;
vec4 lightPos;
} ubo;
layout(push_constant) uniform PushConsts
{
mat4 view;
} pushConsts;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
gl_Position = ubo.projection * pushConsts.view * ubo.model * vec4(inPos, 1.0);
outPos = vec4(inPos, 1.0);
outLightPos = ubo.lightPos.xyz;
}

Binary file not shown.

View file

@ -0,0 +1,40 @@
#version 450
layout (binding = 1) uniform samplerCube shadowCubeMap;
layout (location = 0) in vec3 inNormal;
layout (location = 1) in vec3 inColor;
layout (location = 2) in vec3 inEyePos;
layout (location = 3) in vec3 inLightVec;
layout (location = 4) in vec3 inWorldPos;
layout (location = 5) in vec3 inLightPos;
layout (location = 0) out vec4 outFragColor;
#define EPSILON 0.15
#define SHADOW_OPACITY 0.5
void main()
{
// Lighting
vec3 N = normalize(inNormal);
vec3 L = normalize(vec3(1.0));
vec3 Eye = normalize(-inEyePos);
vec3 Reflected = normalize(reflect(-inLightVec, inNormal));
vec4 IAmbient = vec4(vec3(0.05), 1.0);
vec4 IDiffuse = vec4(1.0) * max(dot(inNormal, inLightVec), 0.0);
outFragColor = vec4(IAmbient + IDiffuse * vec4(inColor, 1.0));
// Shadow
vec3 lightVec = inWorldPos - inLightPos;
float sampledDist = texture(shadowCubeMap, lightVec).r;
float dist = length(lightVec);
// Check if fragment is in shadow
float shadow = (dist <= sampledDist + EPSILON) ? 1.0 : SHADOW_OPACITY;
outFragColor.rgb *= shadow;
}

Binary file not shown.

View file

@ -0,0 +1,39 @@
#version 450
layout (location = 0) in vec3 inPos;
layout (location = 2) in vec3 inColor;
layout (location = 3) in vec3 inNormal;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
mat4 model;
vec4 lightPos;
} ubo;
layout (location = 0) out vec3 outNormal;
layout (location = 1) out vec3 outColor;
layout (location = 2) out vec3 outEyePos;
layout (location = 3) out vec3 outLightVec;
layout (location = 4) out vec3 outWorldPos;
layout (location = 5) out vec3 outLightPos;
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
{
outColor = inColor;
outNormal = inNormal;
gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos.xyz, 1.0);
outEyePos = vec3(ubo.model * vec4(inPos, 1.0f));
outLightVec = normalize(ubo.lightPos.xyz - inPos.xyz);
outWorldPos = inPos;
outLightPos = ubo.lightPos.xyz;
}

Binary file not shown.