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,147 @@
#version 450
layout (binding = 1) uniform sampler2D sColorMap;
layout (binding = 2) uniform sampler2D sNormalHeightMap;
layout (binding = 3) uniform UBO
{
float heightScale;
float parallaxBias;
float numLayers;
int mappingMode;
} ubo;
layout (location = 0) in vec2 inUV;
layout (location = 1) in vec3 inTangentLightPos;
layout (location = 2) in vec3 inTangentViewPos;
layout (location = 3) in vec3 inTangentFragPos;
layout (location = 0) out vec4 outColor;
vec2 parallax_uv(vec2 uv, vec3 view_dir, int type)
{
if (type == 2) {
// Parallax mapping
float depth = 1.0 - textureLod(sNormalHeightMap, uv, 0.0).a;
vec2 p = view_dir.xy * (depth * (ubo.heightScale * 0.5) + ubo.parallaxBias) / view_dir.z;
return uv - p;
} else {
float layer_depth = 1.0 / ubo.numLayers;
float cur_layer_depth = 0.0;
vec2 delta_uv = view_dir.xy * ubo.heightScale / (view_dir.z * ubo.numLayers);
vec2 cur_uv = uv;
float depth_from_tex = 1.0 - textureLod(sNormalHeightMap, cur_uv, 0.0).a;
for (int i = 0; i < 32; i++) {
cur_layer_depth += layer_depth;
cur_uv -= delta_uv;
depth_from_tex = 1.0 - textureLod(sNormalHeightMap, cur_uv, 0.0).a;
if (depth_from_tex < cur_layer_depth) {
break;
}
}
if (type == 3) {
// Steep parallax mapping
return cur_uv;
} else {
// Parallax occlusion mapping
vec2 prev_uv = cur_uv + delta_uv;
float next = depth_from_tex - cur_layer_depth;
float prev = 1.0 - textureLod(sNormalHeightMap, prev_uv, 0.0).a - cur_layer_depth + layer_depth;
float weight = next / (next - prev);
return mix(cur_uv, prev_uv, weight);
}
}
}
vec2 parallaxMapping(vec2 uv, vec3 viewDir)
{
float height = 1.0 - textureLod(sNormalHeightMap, uv, 0.0).a;
vec2 p = viewDir.xy * (height * (ubo.heightScale * 0.5) + ubo.parallaxBias) / viewDir.z;
return uv - p;
}
vec2 steepParallaxMapping(vec2 uv, vec3 viewDir)
{
float layerDepth = 1.0 / ubo.numLayers;
float currLayerDepth = 0.0;
vec2 deltaUV = viewDir.xy * ubo.heightScale / (viewDir.z * ubo.numLayers);
vec2 currUV = uv;
float height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a;
for (int i = 0; i < ubo.numLayers; i++) {
currLayerDepth += layerDepth;
currUV -= deltaUV;
height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a;
if (height < currLayerDepth) {
break;
}
}
return currUV;
}
vec2 parallaxOcclusionMapping(vec2 uv, vec3 viewDir)
{
float layerDepth = 1.0 / ubo.numLayers;
float currLayerDepth = 0.0;
vec2 deltaUV = viewDir.xy * ubo.heightScale / (viewDir.z * ubo.numLayers);
vec2 currUV = uv;
float height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a;
for (int i = 0; i < ubo.numLayers; i++) {
currLayerDepth += layerDepth;
currUV -= deltaUV;
height = 1.0 - textureLod(sNormalHeightMap, currUV, 0.0).a;
if (height < currLayerDepth) {
break;
}
}
vec2 prevUV = currUV + deltaUV;
float nextDepth = height - currLayerDepth;
float prevDepth = 1.0 - textureLod(sNormalHeightMap, prevUV, 0.0).a - currLayerDepth + layerDepth;
return mix(currUV, prevUV, nextDepth / (nextDepth - prevDepth));
}
void main(void)
{
vec3 V = normalize(inTangentViewPos - inTangentFragPos);
vec2 uv = inUV;
if (ubo.mappingMode == 0) {
// Color only
outColor = texture(sColorMap, inUV);
} else {
switch(ubo.mappingMode) {
case 2:
uv = parallaxMapping(inUV, V);
break;
case 3:
uv = steepParallaxMapping(inUV, V);
break;
case 4:
uv = parallaxOcclusionMapping(inUV, V);
break;
}
// Perform sampling before (potentially) discarding.
// This is to avoid implicit derivatives in non-uniform control flow.
vec3 normalHeightMapLod = textureLod(sNormalHeightMap, uv, 0.0).rgb;
vec3 color = texture(sColorMap, uv).rgb;
// Discard fragments at texture border
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
discard;
}
vec3 N = normalize(normalHeightMapLod * 2.0 - 1.0);
vec3 L = normalize(inTangentLightPos - inTangentFragPos);
vec3 R = reflect(-L, N);
vec3 H = normalize(L + V);
vec3 ambient = 0.2 * color;
vec3 diffuse = max(dot(L, N), 0.0) * color;
vec3 specular = vec3(0.15) * pow(max(dot(N, H), 0.0), 32.0);
outColor = vec4(ambient + diffuse + specular, 1.0f);
}
}

Binary file not shown.

View file

@ -0,0 +1,37 @@
#version 450
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec2 inUV;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inTangent;
layout (location = 4) in vec3 inBiTangent;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 view;
mat4 model;
vec4 lightPos;
vec4 cameraPos;
} ubo;
layout (location = 0) out vec2 outUV;
layout (location = 1) out vec3 outTangentLightPos;
layout (location = 2) out vec3 outTangentViewPos;
layout (location = 3) out vec3 outTangentFragPos;
void main(void)
{
gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos, 1.0f);
outTangentFragPos = vec3(ubo.model * vec4(inPos, 1.0));
outUV = inUV;
vec3 T = normalize(mat3(ubo.model) * inTangent);
vec3 B = normalize(mat3(ubo.model) * inBiTangent);
vec3 N = normalize(mat3(ubo.model) * inNormal);
mat3 TBN = transpose(mat3(T, B, N));
outTangentLightPos = TBN * ubo.lightPos.xyz;
outTangentViewPos = TBN * ubo.cameraPos.xyz;
outTangentFragPos = TBN * outTangentFragPos;
}

Binary file not shown.