Commit e3401efc authored by Christopher Tenter's avatar Christopher Tenter

- safety check in msaa sample weight computation

- add msaa shaders

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18437 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 74750363
// methods for resolving multisampled textures
vec4 ReadMultisampledTexture(in sampler2DMS tex, in ivec2 pos, in int numSamples)
{
vec4 texel = vec4(0,0,0,0);
for (int i = 0; i < numSamples; ++i)
{
vec4 sample = texelFetch(tex, pos, i);
texel += sample;
}
return texel / float(numSamples);
}
vec4 ReadMultisampledTexture(in sampler2DMS tex, in vec2 texcood, in int numSamples)
{
ivec2 pos = int(floor(texcoord));
return ReadMultisampledTexture(tex, pos, numSamples);
}
vec4 ReadMultisampledTexture(in sampler2DMS tex, in ivec2 pos, in int numSamples, in samplerBuffer filterWeights)
{
vec4 texel = vec4(0,0,0,0);
for (int i = 0; i < numSamples; ++i)
{
float filterWeight = texelFetch(filterWeights, i).x;
vec4 sample = texelFetch(tex, pos, i);
texel += filterWeight * sample;
}
return texel;
}
vec4 ReadMultisampledTexture(in sampler2DMS tex, in vec2 texcood, in int numSamples, in samplerBuffer filterWeights)
{
ivec2 pos = int(floor(texcoord));
return ReadMultisampledTexture(tex, pos, numSamples, filterWeights);
}
vec4 FilterMultisampledTextureBilinear(in sampler2DMS tex, in vec2 texcoord, in int numSamples)
{
ivec2 texSize = textureSize(tex);
// top-left texel position
vec2 pos00 = floor( texSize * texcoord );
ivec2 loc00 = ivec2(pos00);
// lerp weights
vec2 alpha = fract( texSize * texcoord );
// bilinear filtering
// lerp in u-direction top
vec4 sampleX0 = mix(
ReadMultisampledTexture(tex, loc00, numSamples),
ReadMultisampledTexture(tex, loc00 + ivec2(1,0), numSamples),
alpha.x);
// lerp in u-direction bottom
vec4 sampleX1 = mix(
ReadMultisampledTexture(tex, loc00 + ivec2(0,1), numSamples),
ReadMultisampledTexture(tex, loc00 + ivec2(1,1), numSamples),
alpha.x);
// lerp in v direction
return mix(sampleX0, sampleX1, alpha.y);
}
vec4 FilterMultisampledTextureBilinear(in sampler2DMS tex, in vec2 texcoord, in int numSamples, in samplerBuffer filterWeights)
{
ivec2 texSize = textureSize(tex);
// top-left texel position
vec2 pos00 = floor( texSize * texcoord );
ivec2 loc00 = ivec2(pos00);
// lerp weights
vec2 alpha = fract( texSize * texcoord );
// bilinear filtering
// lerp in u-direction top
vec4 sampleX0 = mix(
ReadMultisampledTexture(tex, loc00, numSamples, filterWeights),
ReadMultisampledTexture(tex, loc00 + ivec2(1,0), numSamples, filterWeights),
alpha.x);
// lerp in u-direction bottom
vec4 sampleX1 = mix(
ReadMultisampledTexture(tex, loc00 + ivec2(0,1), numSamples, filterWeights),
ReadMultisampledTexture(tex, loc00 + ivec2(1,1), numSamples, filterWeights),
alpha.x);
// lerp in v direction
return mix(sampleX0, sampleX1, alpha.y);
}
\ No newline at end of file
#version 150
#include "msaa.glsl"
uniform sampler2DMS inputTex;
uniform int numSamples;
in vec2 vTexCoord;
out vec4 outFragment;
void main()
{
outFragment = FilterMultisampledTextureBilinear(inputTex, vTexCoord, numSamples);
}
\ No newline at end of file
#version 150
#include "msaa.glsl"
uniform sampler2DMS inputTex;
uniform int numSamples;
in vec2 vTexCoord;
out vec4 outFragment;
void main()
{
outFragment = ReadMultisampledTexture(inputTex, vTexCoord, numSamples);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment