Skip to content

Instantly share code, notes, and snippets.

@adrian-afl
Created March 23, 2015 16:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrian-afl/93d2bb016c8df49a4c6a to your computer and use it in GitHub Desktop.
Save adrian-afl/93d2bb016c8df49a4c6a to your computer and use it in GitHub Desktop.
MSAA shader resolving
#version 430 core
in vec2 UV;
layout(binding = 0) uniform sampler2DMS texColor;
layout(binding = 1) uniform sampler2DMS texDepth;
const int samples = 8;
float samplesInverted = 1.0 / samples;
out vec4 outColor;
ivec2 ctexSize = textureSize(texColor);
ivec2 dtexSize = textureSize(texDepth);
vec4 fetchColor()
{
vec4 c = vec4(0.0);
ivec2 tx = ivec2(ctexSize * UV);
for (int i = 0; i < samples; i++) c += texelFetch(texColor, tx, i);
return c * samplesInverted;
}
float fetchDepth()
{
float d = 0.0;
ivec2 tx = ivec2(dtexSize * UV);
for (int i = 0; i < samples; i++) d += texelFetch(texDepth, tx, i).r;
return d * samplesInverted;
}
void main()
{
outColor = fetchColor();
gl_FragDepth = fetchDepth();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment