procedural-3d-engine/data/shaders/deferredmultisampling/debug.frag
Gary Sweet 7632def9d6 Fix sample count limits in deferredmultisampling
The sample count was previously fixed at 8, which is not supported
on some platforms. The code now checks for the maximum supported
sample count and uses that instead.

If you would prefer the upper limit to be fixed at 8, that is
obviously trivial to change.
2019-03-06 12:58:28 +00: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];
}