procedural-3d-engine/data/shaders/glsl/deferredmultisampling/debug.frag
Ben Clayton ca884587a4 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
2020-06-01 12:22:28 +01:00

52 lines
No EOL
1.1 KiB
GLSL

#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];
}