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
52
data/shaders/glsl/deferredmultisampling/debug.frag
Normal file
52
data/shaders/glsl/deferredmultisampling/debug.frag
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2DMS samplerPosition;
|
||||
layout (binding = 2) uniform sampler2DMS samplerNormal;
|
||||
layout (binding = 3) uniform sampler2DMS samplerAlbedo;
|
||||
|
||||
layout (location = 0) in vec3 inUV;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
layout (constant_id = 0) const int NUM_SAMPLES = 8;
|
||||
|
||||
vec4 resolve(sampler2DMS tex, ivec2 uv)
|
||||
{
|
||||
vec4 result = vec4(0.0);
|
||||
int count = 0;
|
||||
for (int i = 0; i < NUM_SAMPLES; i++)
|
||||
{
|
||||
vec4 val = texelFetch(tex, uv, i);
|
||||
result += val;
|
||||
count++;
|
||||
}
|
||||
return result / float(NUM_SAMPLES);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 attDim = textureSize(samplerPosition);
|
||||
ivec2 UV = ivec2(inUV.st * attDim * 2.0);
|
||||
|
||||
highp int index = 0;
|
||||
if (inUV.s > 0.5)
|
||||
{
|
||||
index = 1;
|
||||
UV.s -= attDim.x;
|
||||
}
|
||||
if (inUV.t > 0.5)
|
||||
{
|
||||
index = 2;
|
||||
UV.t -= attDim.y;
|
||||
}
|
||||
|
||||
vec3 components[3];
|
||||
components[0] = resolve(samplerPosition, UV).rgb;
|
||||
components[1] = resolve(samplerNormal, UV).rgb;
|
||||
components[2] = resolve(samplerAlbedo, UV).rgb;
|
||||
// Uncomment to display specular component
|
||||
//components[2] = vec3(texture(samplerAlbedo, inUV.st).a);
|
||||
|
||||
// Select component depending on UV
|
||||
outFragColor.rgb = components[index];
|
||||
}
|
||||
BIN
data/shaders/glsl/deferredmultisampling/debug.frag.spv
Normal file
BIN
data/shaders/glsl/deferredmultisampling/debug.frag.spv
Normal file
Binary file not shown.
20
data/shaders/glsl/deferredmultisampling/debug.vert
Normal file
20
data/shaders/glsl/deferredmultisampling/debug.vert
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 model;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec3 outUV;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
outUV = vec3((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2, 0.0);
|
||||
gl_Position = vec4(outUV.st * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
BIN
data/shaders/glsl/deferredmultisampling/debug.vert.spv
Normal file
BIN
data/shaders/glsl/deferredmultisampling/debug.vert.spv
Normal file
Binary file not shown.
100
data/shaders/glsl/deferredmultisampling/deferred.frag
Normal file
100
data/shaders/glsl/deferredmultisampling/deferred.frag
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2DMS samplerPosition;
|
||||
layout (binding = 2) uniform sampler2DMS samplerNormal;
|
||||
layout (binding = 3) uniform sampler2DMS samplerAlbedo;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
|
||||
layout (location = 0) out vec4 outFragcolor;
|
||||
|
||||
struct Light {
|
||||
vec4 position;
|
||||
vec3 color;
|
||||
float radius;
|
||||
};
|
||||
|
||||
layout (binding = 4) uniform UBO
|
||||
{
|
||||
Light lights[6];
|
||||
vec4 viewPos;
|
||||
ivec2 windowSize;
|
||||
} ubo;
|
||||
|
||||
layout (constant_id = 0) const int NUM_SAMPLES = 8;
|
||||
|
||||
#define NUM_LIGHTS 6
|
||||
|
||||
// Manual resolve for MSAA samples
|
||||
vec4 resolve(sampler2DMS tex, ivec2 uv)
|
||||
{
|
||||
vec4 result = vec4(0.0);
|
||||
for (int i = 0; i < NUM_SAMPLES; i++)
|
||||
{
|
||||
vec4 val = texelFetch(tex, uv, i);
|
||||
result += val;
|
||||
}
|
||||
// Average resolved samples
|
||||
return result / float(NUM_SAMPLES);
|
||||
}
|
||||
|
||||
vec3 calculateLighting(vec3 pos, vec3 normal, vec4 albedo)
|
||||
{
|
||||
vec3 result = vec3(0.0);
|
||||
|
||||
for(int i = 0; i < NUM_LIGHTS; ++i)
|
||||
{
|
||||
// Vector to light
|
||||
vec3 L = ubo.lights[i].position.xyz - pos;
|
||||
// Distance from light to fragment position
|
||||
float dist = length(L);
|
||||
|
||||
// Viewer to fragment
|
||||
vec3 V = ubo.viewPos.xyz - pos;
|
||||
V = normalize(V);
|
||||
|
||||
// Light to fragment
|
||||
L = normalize(L);
|
||||
|
||||
// Attenuation
|
||||
float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
|
||||
|
||||
// Diffuse part
|
||||
vec3 N = normalize(normal);
|
||||
float NdotL = max(0.0, dot(N, L));
|
||||
vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
|
||||
|
||||
// Specular part
|
||||
vec3 R = reflect(-L, N);
|
||||
float NdotR = max(0.0, dot(R, V));
|
||||
vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 8.0) * atten;
|
||||
|
||||
result += diff + spec;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 attDim = textureSize(samplerPosition);
|
||||
ivec2 UV = ivec2(inUV * attDim);
|
||||
|
||||
#define ambient 0.15
|
||||
|
||||
// Ambient part
|
||||
vec4 alb = resolve(samplerAlbedo, UV);
|
||||
vec3 fragColor = vec3(0.0);
|
||||
|
||||
// Calualte lighting for every MSAA sample
|
||||
for (int i = 0; i < NUM_SAMPLES; i++)
|
||||
{
|
||||
vec3 pos = texelFetch(samplerPosition, UV, i).rgb;
|
||||
vec3 normal = texelFetch(samplerNormal, UV, i).rgb;
|
||||
vec4 albedo = texelFetch(samplerAlbedo, UV, i);
|
||||
fragColor += calculateLighting(pos, normal, albedo);
|
||||
}
|
||||
|
||||
fragColor = (alb.rgb * ambient) + fragColor / float(NUM_SAMPLES);
|
||||
|
||||
outFragcolor = vec4(fragColor, 1.0);
|
||||
}
|
||||
BIN
data/shaders/glsl/deferredmultisampling/deferred.frag.spv
Normal file
BIN
data/shaders/glsl/deferredmultisampling/deferred.frag.spv
Normal file
Binary file not shown.
20
data/shaders/glsl/deferredmultisampling/deferred.vert
Normal file
20
data/shaders/glsl/deferredmultisampling/deferred.vert
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 model;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec2 outUV;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
BIN
data/shaders/glsl/deferredmultisampling/deferred.vert.spv
Normal file
BIN
data/shaders/glsl/deferredmultisampling/deferred.vert.spv
Normal file
Binary file not shown.
30
data/shaders/glsl/deferredmultisampling/mrt.frag
Normal file
30
data/shaders/glsl/deferredmultisampling/mrt.frag
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
layout (binding = 2) uniform sampler2D samplerNormalMap;
|
||||
|
||||
layout (location = 0) in vec3 inNormal;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inColor;
|
||||
layout (location = 3) in vec3 inWorldPos;
|
||||
layout (location = 4) in vec3 inTangent;
|
||||
|
||||
layout (location = 0) out vec4 outPosition;
|
||||
layout (location = 1) out vec4 outNormal;
|
||||
layout (location = 2) out vec4 outAlbedo;
|
||||
|
||||
void main()
|
||||
{
|
||||
outPosition = vec4(inWorldPos, 1.0);
|
||||
|
||||
// Calculate normal in tangent space
|
||||
vec3 N = normalize(inNormal);
|
||||
N.y = -N.y;
|
||||
vec3 T = normalize(inTangent);
|
||||
vec3 B = cross(N, T);
|
||||
mat3 TBN = mat3(T, B, N);
|
||||
vec3 tnorm = TBN * normalize(texture(samplerNormalMap, inUV).xyz * 2.0 - vec3(1.0));
|
||||
outNormal = vec4(tnorm, 1.0);
|
||||
|
||||
outAlbedo = texture(samplerColor, inUV);
|
||||
}
|
||||
BIN
data/shaders/glsl/deferredmultisampling/mrt.frag.spv
Normal file
BIN
data/shaders/glsl/deferredmultisampling/mrt.frag.spv
Normal file
Binary file not shown.
49
data/shaders/glsl/deferredmultisampling/mrt.vert
Normal file
49
data/shaders/glsl/deferredmultisampling/mrt.vert
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 2) in vec3 inColor;
|
||||
layout (location = 3) in vec3 inNormal;
|
||||
layout (location = 4) in vec3 inTangent;
|
||||
|
||||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
vec4 instancePos[3];
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec3 outNormal;
|
||||
layout (location = 1) out vec2 outUV;
|
||||
layout (location = 2) out vec3 outColor;
|
||||
layout (location = 3) out vec3 outWorldPos;
|
||||
layout (location = 4) out vec3 outTangent;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tmpPos = vec4(inPos.xyz, 1.0) + ubo.instancePos[gl_InstanceIndex];
|
||||
|
||||
gl_Position = ubo.projection * ubo.view * ubo.model * tmpPos;
|
||||
|
||||
outUV = inUV;
|
||||
outUV.t = 1.0 - outUV.t;
|
||||
|
||||
// Vertex position in world space
|
||||
outWorldPos = vec3(ubo.model * tmpPos);
|
||||
// GL to Vulkan coord space
|
||||
outWorldPos.y = -outWorldPos.y;
|
||||
|
||||
// Normal in world space
|
||||
mat3 mNormal = transpose(inverse(mat3(ubo.model)));
|
||||
outNormal = mNormal * normalize(inNormal);
|
||||
outTangent = mNormal * normalize(inTangent);
|
||||
|
||||
// Currently just vertex color
|
||||
outColor = inColor;
|
||||
}
|
||||
BIN
data/shaders/glsl/deferredmultisampling/mrt.vert.spv
Normal file
BIN
data/shaders/glsl/deferredmultisampling/mrt.vert.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue