| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma anki input const UVec2 INPUT_TEXTURE_SIZE
- const F32 OFFSET = 1.25;
- const Vec2 TEXEL_SIZE = 1.0 / Vec2(INPUT_TEXTURE_SIZE);
- const Vec2 HALF_TEXEL_SIZE = TEXEL_SIZE / 2.0;
- #pragma anki start vert
- #include <shaders/Common.glsl>
- out gl_PerVertex
- {
- Vec4 gl_Position;
- };
- layout(ANKI_UBO_BINDING(0, 0)) uniform u_
- {
- Vec4 u_nearFarPad2;
- Vec4 u_uvScaleAndTranslation;
- };
- layout(location = 0) out Vec2 out_uv;
- layout(location = 1) flat out Vec2 out_maxUv;
- layout(location = 2) flat out Vec2 out_minUv;
- void main()
- {
- out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0;
- Vec2 pos = out_uv * 2.0 - 1.0;
- out_uv = fma(out_uv, u_uvScaleAndTranslation.zw, u_uvScaleAndTranslation.xy);
- gl_Position = Vec4(pos, 0.0, 1.0);
- // Compute the limits
- out_maxUv = fma(Vec2(1.0), u_uvScaleAndTranslation.zw, u_uvScaleAndTranslation.xy) - HALF_TEXEL_SIZE;
- out_minUv = fma(Vec2(0.0), u_uvScaleAndTranslation.zw, u_uvScaleAndTranslation.xy) + HALF_TEXEL_SIZE;
- }
- #pragma anki end
- #pragma anki start frag
- #include <shaders/GaussianBlurCommon.glsl>
- #include <shaders/Functions.glsl>
- layout(location = 0) in Vec2 in_uv;
- layout(location = 1) flat in Vec2 in_maxUv;
- layout(location = 2) flat in Vec2 in_minUv;
- layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_inputTex;
- layout(ANKI_UBO_BINDING(0, 0)) uniform u_
- {
- Vec4 u_nearFarPad2;
- Vec4 u_uvScaleAndTranslation;
- };
- #define u_near u_nearFarPad2.x
- #define u_far u_nearFarPad2.y
- layout(location = 0) out F32 out_color;
- F32 sampleLinearDepth(Vec2 uv)
- {
- uv = clamp(uv, in_minUv, in_maxUv);
- return linearizeDepth(textureLod(u_inputTex, uv, 0.0).r, u_near, u_far);
- }
- void main()
- {
- const Vec2 UV_OFFSET = OFFSET * TEXEL_SIZE;
- out_color = sampleLinearDepth(in_uv) * BOX_WEIGHTS[0u];
- out_color += sampleLinearDepth(in_uv + Vec2(UV_OFFSET.x, 0.0)) * BOX_WEIGHTS[1u];
- out_color += sampleLinearDepth(in_uv + Vec2(-UV_OFFSET.x, 0.0)) * BOX_WEIGHTS[1u];
- out_color += sampleLinearDepth(in_uv + Vec2(0.0, UV_OFFSET.y)) * BOX_WEIGHTS[1u];
- out_color += sampleLinearDepth(in_uv + Vec2(0.0, -UV_OFFSET.y)) * BOX_WEIGHTS[1u];
- out_color += sampleLinearDepth(in_uv + Vec2(UV_OFFSET.x, UV_OFFSET.y)) * BOX_WEIGHTS[2u];
- out_color += sampleLinearDepth(in_uv + Vec2(-UV_OFFSET.x, UV_OFFSET.y)) * BOX_WEIGHTS[2u];
- out_color += sampleLinearDepth(in_uv + Vec2(UV_OFFSET.x, -UV_OFFSET.y)) * BOX_WEIGHTS[2u];
- out_color += sampleLinearDepth(in_uv + Vec2(-UV_OFFSET.x, -UV_OFFSET.y)) * BOX_WEIGHTS[2u];
- }
- #pragma anki end
|