Commit 6e3f53a8 authored by Christopher Tenter's avatar Christopher Tenter

add blur shaders

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20054 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 90b34e00
#version 130
// bilateral filter using the depth buffer
// - separable approximation
// - red channel only
// sigma_s : spatial kernel
// sigma_r : range kernel (linear depth range)
// potential optimization:
// prelinearize depth
#define BLUR_R 0
#define BLUR_RG 1
#define BLUR_RGB 2
#define BLUR_RGBA 3
#ifndef BLUR_CHANNELS
#define BLUR_CHANNELS BLUR_R
#endif
in vec2 vTexCoord;
out vec4 outColor;
#ifndef BLUR_SAMPLES
#define BLUR_SAMPLES 9
#endif
uniform sampler2D g_InputTex;
uniform sampler2D g_DepthTex;
uniform mat4 g_P; // projection
uniform float g_BlurSigmaRcp2; // -1 / (2 * sigma_r^2))
uniform vec2 g_SampleOffsets[BLUR_SAMPLES];
uniform float g_SpatialKernel[BLUR_SAMPLES];
#include "../Common/depthbuffer.glsl"
float GetDepthVS(vec2 uv)
{
// sample depth buffer and linearize
float d = texture(g_DepthTex, uv).x;
return ProjectedToViewspaceDepth(d, g_P[2][2], g_P[2][3]);
}
void main()
{
vec4 res = vec4(0,0,0,0);
float weightSum = 0;
float centerZ = GetDepthVS(vTexCoord);
for (int i = 0; i < BLUR_SAMPLES; ++i)
{
vec2 sampleUV = vTexCoord + g_SampleOffsets[i];
float sampleZ = GetDepthVS(sampleUV);
// weighting based on spatial and range closeness
// here: range = diff linear depth
float diffZ = centerZ - sampleZ;
float d2 = diffZ * diffZ;
float weight = exp(d2 * g_BlurSigmaRcp2 + g_SpatialKernel[i]);
weightSum += weight;
#if (BLUR_CHANNELS == BLUR_R)
res.x += weight * texture(g_InputTex, sampleUV).x;
#elif (BLUR_CHANNELS == BLUR_RG)
res.xy += weight * texture(g_InputTex, sampleUV).xy;
#elif (BLUR_CHANNELS == BLUR_RGB)
res.xyz += weight * texture(g_InputTex, sampleUV).xyz;
#else
res += weight * texture(g_InputTex, sampleUV);
#endif
}
outColor = res / weightSum;
}
\ No newline at end of file
#version 130
in vec2 vTexCoord;
out vec4 outColor;
#ifndef BLUR_SAMPLES
#define BLUR_SAMPLES 9
#endif
uniform sampler2D g_InputTex;
uniform vec2 g_SampleOffsets[BLUR_SAMPLES];
uniform float g_SampleWeights[BLUR_SAMPLES];
void main()
{
vec4 r = vec4(0,0,0,0);
for (int i = 0; i < BLUR_SAMPLES; ++i)
r += texture(g_InputTex, vTexCoord + g_SampleOffsets[i]) * g_SampleWeights[i];
outColor = r;
}
\ No newline at end of file
#version 130
in vec2 vTexCoord;
out vec4 outColor;
#ifndef BLUR_SAMPLES
#define BLUR_SAMPLES 9
#endif
uniform sampler2D g_InputTex;
uniform vec2 g_SampleOffsets[BLUR_SAMPLES];
void main()
{
vec4 r = vec4(0,0,0,0);
for (int i = 0; i < BLUR_SAMPLES; ++i)
r += texture(g_InputTex, vTexCoord + g_SampleOffsets[i]);
outColor = r / BLUR_SAMPLES;
}
\ No newline at end of file
#version 130
in vec2 vTexCoord;
out vec4 outColor;
#ifndef BLUR_SAMPLES
#define BLUR_SAMPLES 8
#endif
uniform sampler2D g_InputTex;
uniform vec2 g_BlurCenter;
uniform float g_BlurRadiusRcp2; // 1 / r^2
uniform float g_BlurIntensity;
void main()
{
/*
// debug, manual params
float blurRadius = 1.5;
vec2 blurCenter = g_BlurCenter;
float blurIntensity = 0.01;
float blurRadiusRcp2 = 1.0 / (blurRadius * blurRadius);
*/
float blurRadiusRcp2 = g_BlurRadiusRcp2;
float blurIntensity = g_BlurIntensity;
vec2 blurDir = g_BlurCenter - vTexCoord;
// quadratic intensity scale
float d2 = dot(blurDir, blurDir);
float blurAmount = clamp(1 - d2 * blurRadiusRcp2, 0, 1) * blurIntensity;
blurDir *= blurAmount;
vec4 r = vec4(0,0,0,0);
for (float i = 0; i < BLUR_SAMPLES; ++i)
r += texture(g_InputTex, vTexCoord + blurDir * i);
outColor = r / BLUR_SAMPLES;
}
\ 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