| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <!--
- Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
- All rights reserved.
- Code licensed under the BSD License.
- http://www.anki3d.org/LICENSE
- -->
- <shaderProgram>
- <mutators>
- <mutator name="HORIZONTAL" values="0 1"/>
- <mutator name="KERNEL_SIZE" values="3 5 7 9 11 13 15"/>
- <mutator name="COLOR_COMPONENTS" values="4 3 1"/>
- </mutators>
- <shaders>
- <shader type="vert">
- <source><![CDATA[
- #include "shaders/QuadVert.glsl"
- ]]></source>
- </shader>
- <shader type="frag">
- <inputs>
- <input name="TEXTURE_SIZE" type="uvec2" const="1"/>
- </inputs>
- <source><![CDATA[
- #include "shaders/GaussianBlurCommon.glsl"
- #include "shaders/Tonemapping.glsl"
- #include "shaders/Functions.glsl"
- // Determine color type
- #if COLOR_COMPONENTS == 4
- # define COL_TYPE vec4
- # define TEX_FETCH rgba
- #elif COLOR_COMPONENTS == 3
- # define COL_TYPE vec3
- # define TEX_FETCH rgb
- #elif COLOR_COMPONENTS == 1
- # define COL_TYPE float
- # define TEX_FETCH r
- #else
- # error See file
- #endif
- layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex;
- layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_depthRt;
- layout(location = 0) in vec2 in_uv;
- layout(location = 0) out COL_TYPE out_color;
- float computeDepthWeight(float refDepth, float depth)
- {
- float diff = abs(refDepth - depth);
- float weight = 1.0 / (EPSILON + diff);
- return sqrt(weight);
- }
- float readDepth(vec2 uv)
- {
- return textureLod(u_depthRt, uv, 0.0).r;
- }
- void main()
- {
- #if HORIZONTAL
- const vec2 TEXEL_SIZE = vec2(1.0 / float(TEXTURE_SIZE.x), 0.0);
- #else
- const vec2 TEXEL_SIZE = vec2(0.0, 1.0 / float(TEXTURE_SIZE.y));
- #endif
- out_color = texture(u_tex, in_uv).TEX_FETCH;
- float refDepth = readDepth(in_uv);
- float weight = 1.0;
- vec2 texCoordOffset = 1.5 * TEXEL_SIZE;
- for(uint i = 0u; i < STEP_COUNT; ++i)
- {
- vec2 uv = in_uv + texCoordOffset;
- COL_TYPE col = texture(u_tex, uv).TEX_FETCH;
- float w = computeDepthWeight(refDepth, readDepth(uv));
- out_color += col * w;
- weight += w;
- uv = in_uv - texCoordOffset;
- col = texture(u_tex, uv).TEX_FETCH;
- w = computeDepthWeight(refDepth, readDepth(uv));
- out_color += col * w;
- weight += w;
- texCoordOffset += 2.0 * TEXEL_SIZE;
- }
- out_color = out_color / weight;
- }
- ]]></source>
- </shader>
- </shaders>
- </shaderProgram>
|