#include "depthpass.glsllib" uniform vec2 CameraClipRange; void frag() { // Simple averaging blur, but makes sure to include the alpha channel from the blur weights // Only need to do this once to actually set the alphas in the blur buffers. vec4 smp0 = textureOffset(Texture0, TexCoord.xy, ivec2(-1,-1)); vec4 smp1 = textureOffset(Texture0, TexCoord.xy, ivec2(0,-1)); vec4 smp2 = textureOffset(Texture0, TexCoord.xy, ivec2(-1,0)); vec4 smp3 = texture(Texture0, TexCoord.xy); smp0.w *= textureOffset(DistBuffer, TexCoord.xy, ivec2(-1,-1)).w; smp1.w *= textureOffset(DistBuffer, TexCoord.xy, ivec2(0,-1)).w; smp2.w *= textureOffset(DistBuffer, TexCoord.xy, ivec2(-1,0)).w; smp3.w *= texture(DistBuffer, TexCoord.xy).w; gl_FragColor = 0.25 * (smp0 + smp1 + smp2 + smp3); } void frag() // Simple averaging blur. { vec4 smp0 = textureOffset(Texture0, TexCoord.xy, ivec2(-1,-1)); vec4 smp1 = textureOffset(Texture0, TexCoord.xy, ivec2(0,-1)); vec4 smp2 = textureOffset(Texture0, TexCoord.xy, ivec2(-1,0)); vec4 smp3 = texture(Texture0, TexCoord.xy); gl_FragColor = 0.25 * (smp0 + smp1 + smp2 + smp3); } void frag() { float planeDepth = SurfDist; vec2 dvec = gl_FragCoord.xy - vec2(DimplePos); float dimple = dot(dvec, dvec) / (DimpleSize * DimpleSize); planeDepth += exp2(-dimple) * DimpleDepth; vec4 depthSample = texture(DepthSampler, TexCoord); float depthVal = getDepthValue( depthSample, CameraClipRange ); float rawDepth = depthValueToLinearDistance( depthVal, CameraClipRange ); if (DepthDebug) { gl_FragColor = vec4( (rawDepth - CameraClipRange.x) / (CameraClipRange.y - CameraClipRange.x) ); return; } float blurAmt = smoothstep(0.0, 1.0, (rawDepth - planeDepth) / BlurDist); gl_FragColor = vec4(blurAmt, blurAmt, blurAmt, 1.0 - blurAmt); } void frag() { vec4 smp = texture(DistBuffer, TexCoord.xy); float sigma = clamp(smp.x * MaxBlur * 0.25, 1.0, 25.0); int smpCount = int(ceil( sigma )); vec4 value = texture(BlurBuffer, TexCoord.xy); float wtsum = 1.0; for (int i = 1; i <= smpCount; ++i) { // Base 2 Gaussian blur float wt = float(i) / (sigma * 0.5); wt = exp2( -wt*wt ); value += wt * textureOffset(BlurBuffer, TexCoord.xy, ivec2(-i,0)); value += wt * textureOffset(BlurBuffer, TexCoord.xy, ivec2(i,0)); wtsum += wt * 2.0; } gl_FragColor = value / wtsum; } void frag() { vec4 smp = texture(DistBuffer, TexCoord.xy); float sigma = clamp(smp.x * MaxBlur * 0.25, 1.0, 25.0); int smpCount = int(ceil( sigma )); vec4 value = texture(BlurBuffer, TexCoord.xy); value.w *= smp.w; float wtsum = 1.0; for (int i = 1; i <= smpCount; ++i) { // Base 2 Gaussian blur float wt = float(i) / (sigma * 0.5); wt = exp2( -wt*wt ); value += wt * textureOffset(BlurBuffer, TexCoord.xy, ivec2(0,-i)); value += wt * textureOffset(BlurBuffer, TexCoord.xy, ivec2(0,i)); wtsum += wt * 2.0; } gl_FragColor = value / wtsum; } void frag() { float blurFac = texture(DistBuffer, TexCoord.xy).x; float lod = log2(MaxBlur * blurFac); float fac0 = clamp(lod, 0.0, 1.0); float fac1 = clamp(lod-1.0, 0.0, 1.0); if (BlurDebug || DepthDebug) { gl_FragColor = vec4(blurFac); return; } vec4 result = texture(SrcSampler, TexCoord.xy); vec4 lvl1 = texture(HalfSampler, TexCoord.xy); vec4 fullBlr = texture(BlurBuffer, TexCoord.xy); // Basically this says that if the blur factor is really small (less than 2 pixels) // we favor the full resolution. If it's between 2 and 4 pixels, we favor the half-res // version (which is like one mip level down)... anything beyond that, we use the bottom // level which actually has the proper local blur. result = mix(mix(result, lvl1, fac0), fullBlr, fac1); // Transform the texture (assuming rotation about the center of the texture) float cosX = cos(OverlayRot * 0.01745329251); float sinX = sin(OverlayRot * 0.01745329251); mat3x3 texMat = mat3x3( 1.0, 0.0, -0.5, 0.0, 1.0, -0.5, 0.0, 0.0, 1.0 ); texMat *= mat3x3( cosX, -sinX, 0.0, sinX, cosX, 0.0, 0.0, 0.0, 1.0); texMat *= mat3x3( 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0 ); texMat *= mat3x3( OverlayScale.x, 0.0, 0.0, 0.0, OverlayScale.y, 0.0, 0.0, 0.0, 1.0); vec3 texForm = texMat * vec3(TexCoord.xy, 1.0); vec4 overSmp = texture(OverlayDif, texForm.xy); float overTrn = 1.0 - texture(OverlayTrn, texForm.xy).x; float nDotL = (texture(OverlayNrm, texForm.xy).z - 0.5) * 2.0; // Want to see how much of a "difference" there is between the light // color and the object color. // We are basically acting as if the objects on the layer are occluders // so the alpha as a result of blurring is like a transparency. // The behavior is that the brighter the light is, the more of a "gap" there is vec3 backlight = LightCol * LightBrt; // Assume that the color map I'm using already tells us what N.dot.L is (for now) float translucency = exp2( -overTrn * OverlayTrans ); // vec3 colorDelta = backlight - result.rgb; // float deltaC = dot(colorDelta, colorDelta) * (1.0 - result.w) * LightBrt / LightExp; // result.rgb -= result.rgb * smoothstep(deltaC, 1.0, result.w); // gl_FragColor = vec4( result.rgb, 1.0 ); // return; backlight *= mix(vec3(1.0), result.rgb, result.w); backlight *= nDotL * translucency * overSmp.rgb; backlight = vec3(1.0) - exp2(-6.28*backlight/LightExp); gl_FragColor = vec4(backlight, 1.0); }