// Generated on <$_SCRIBE_DATE$>//// Created by Sam Gateau on 6/7/16.// Copyright 2016 High Fidelity, Inc.//// Distributed under the Apache License, Version 2.0.// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html// <@func declareBlurUniforms()@> <@include BlurTask_shared.slh@> struct BlurParameters { vec4 resolutionInfo; vec4 texcoordTransform; vec4 filterInfo; vec4 depthInfo; vec4 stereoInfo; vec4 linearDepthInfo; vec4 taps[BLUR_MAX_NUM_TAPS];}; UNIFORM_BUFFER(0, blurParamsBuffer) { BlurParameters parameters;}; vec2 getInvWidthHeight() { return parameters.resolutionInfo.zw;} vec2 evalTexcoordTransformed(vec2 texcoord) { return (texcoord * parameters.texcoordTransform.zw + parameters.texcoordTransform.xy);} float getFilterScale() { return parameters.filterInfo.x;} int getFilterNumTaps() { return int(parameters.filterInfo.y);} float getOutputAlpha() { return parameters.filterInfo.z;} vec2 getFilterTap(int index) { return parameters.taps[index].xy;} float getFilterTapOffset(vec2 tap) { return tap.x;} float getFilterTapWeight(vec2 tap) { return tap.y;} float getDepthThreshold() { return parameters.depthInfo.x;} float getDepthPerspective() { return parameters.depthInfo.w;} float getPosLinearDepthFar() { return parameters.linearDepthInfo.x;} <@endfunc@> <@func declareBlurGaussian()@> <$declareBlurUniforms()$> TEXTURE(0, sampler2D, sourceMap); vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) { texcoord = evalTexcoordTransformed(texcoord); vec2 finalStep = getFilterScale() * direction * pixelStep; vec4 srcBlurred = vec4(0.0); float totalWeight = 0.f; int numTaps = getFilterNumTaps(); for(int i = 0; i < numTaps; i++) { vec2 tapInfo = getFilterTap(i); // Fetch color for current sample. vec2 sampleCoord = texcoord + (getFilterTapOffset(tapInfo) * finalStep); if (all(greaterThanEqual(sampleCoord, vec2(0,0))) && all(lessThanEqual(sampleCoord, vec2(1.0,1.0)))) { vec4 srcSample = texture(sourceMap, sampleCoord); float weight = getFilterTapWeight(tapInfo); // Accumulate. srcBlurred += srcSample * weight; totalWeight += weight; } } if (totalWeight > 0.0) { srcBlurred /= totalWeight; } srcBlurred.a = getOutputAlpha(); return srcBlurred;} <@endfunc@> <@func declareBlurGaussianDepthAware()@> <$declareBlurUniforms()$> TEXTURE(0, sampler2D, sourceMap);TEXTURE(1, sampler2D, depthMap); vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep) { texcoord = evalTexcoordTransformed(texcoord); float sampleDepth = texture(depthMap, texcoord).x; if (sampleDepth >= getPosLinearDepthFar()) { discard; } vec4 sampleCenter = texture(sourceMap, texcoord); // Calculate the width scale. float distanceToProjectionWindow = getDepthPerspective(); float depthThreshold = getDepthThreshold(); // Calculate the final step to fetch the surrounding pixels. float filterScale = getFilterScale(); float scale = distanceToProjectionWindow / sampleDepth; vec2 finalStep = filterScale * scale * direction * pixelStep; int numTaps = getFilterNumTaps(); // Accumulate the center sample vec2 tapInfo = getFilterTap(0); float totalWeight = getFilterTapWeight(tapInfo); vec4 srcBlurred = sampleCenter * totalWeight; for(int i = 1; i < numTaps; i++) { tapInfo = getFilterTap(i); // Fetch color and depth for current sample. vec2 sampleCoord = texcoord + (getFilterTapOffset(tapInfo) * finalStep); if (all(greaterThanEqual(sampleCoord, vec2(0,0))) && all(lessThanEqual(sampleCoord, vec2(1.0,1.0)))) { float srcDepth = texture(depthMap, sampleCoord).x; vec4 srcSample = texture(sourceMap, sampleCoord); float weight = getFilterTapWeight(tapInfo); // If the difference in depth is huge, we lerp color back. float s = clamp(depthThreshold * distanceToProjectionWindow * filterScale * abs(srcDepth - sampleDepth), 0.0, 1.0); srcSample = mix(srcSample, sampleCenter, s); // Accumulate. srcBlurred += srcSample * weight; totalWeight += weight; } } if (totalWeight > 0.0) { srcBlurred /= totalWeight; } return srcBlurred;} <@endfunc@>
// Generated on <$_SCRIBE_DATE$>
//
// Created by Sam Gateau on 6/7/16.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@func declareBlurUniforms()@>
<@include BlurTask_shared.slh@>
struct BlurParameters {
vec4 resolutionInfo;
vec4 texcoordTransform;
vec4 filterInfo;
vec4 depthInfo;
vec4 stereoInfo;
vec4 linearDepthInfo;
vec4 taps[BLUR_MAX_NUM_TAPS];
};
UNIFORM_BUFFER(0, blurParamsBuffer) {
BlurParameters parameters;
};
vec2 getInvWidthHeight() {
return parameters.resolutionInfo.zw;
}
vec2 evalTexcoordTransformed(vec2 texcoord) {
return (texcoord * parameters.texcoordTransform.zw + parameters.texcoordTransform.xy);
}
float getFilterScale() {
return parameters.filterInfo.x;
}
int getFilterNumTaps() {
return int(parameters.filterInfo.y);
}
float getOutputAlpha() {
return parameters.filterInfo.z;
}
vec2 getFilterTap(int index) {
return parameters.taps[index].xy;
}
float getFilterTapOffset(vec2 tap) {
return tap.x;
}
float getFilterTapWeight(vec2 tap) {
return tap.y;
}
float getDepthThreshold() {
return parameters.depthInfo.x;
}
float getDepthPerspective() {
return parameters.depthInfo.w;
}
float getPosLinearDepthFar() {
return parameters.linearDepthInfo.x;
}
<@endfunc@>
<@func declareBlurGaussian()@>
<$declareBlurUniforms()$>
TEXTURE(0, sampler2D, sourceMap);
vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) {
texcoord = evalTexcoordTransformed(texcoord);
vec2 finalStep = getFilterScale() * direction * pixelStep;
vec4 srcBlurred = vec4(0.0);
float totalWeight = 0.f;
int numTaps = getFilterNumTaps();
for(int i = 0; i < numTaps; i++) {
vec2 tapInfo = getFilterTap(i);
// Fetch color for current sample.
vec2 sampleCoord = texcoord + (getFilterTapOffset(tapInfo) * finalStep);
if (all(greaterThanEqual(sampleCoord, vec2(0,0))) && all(lessThanEqual(sampleCoord, vec2(1.0,1.0)))) {
vec4 srcSample = texture(sourceMap, sampleCoord);
float weight = getFilterTapWeight(tapInfo);
// Accumulate.
srcBlurred += srcSample * weight;
totalWeight += weight;
}
}
if (totalWeight > 0.0) {
srcBlurred /= totalWeight;
}
srcBlurred.a = getOutputAlpha();
return srcBlurred;
}
<@endfunc@>
<@func declareBlurGaussianDepthAware()@>
<$declareBlurUniforms()$>
TEXTURE(0, sampler2D, sourceMap);
TEXTURE(1, sampler2D, depthMap);
vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep) {
texcoord = evalTexcoordTransformed(texcoord);
float sampleDepth = texture(depthMap, texcoord).x;
if (sampleDepth >= getPosLinearDepthFar()) {
discard;
}
vec4 sampleCenter = texture(sourceMap, texcoord);
// Calculate the width scale.
float distanceToProjectionWindow = getDepthPerspective();
float depthThreshold = getDepthThreshold();
// Calculate the final step to fetch the surrounding pixels.
float filterScale = getFilterScale();
float scale = distanceToProjectionWindow / sampleDepth;
vec2 finalStep = filterScale * scale * direction * pixelStep;
int numTaps = getFilterNumTaps();
// Accumulate the center sample
vec2 tapInfo = getFilterTap(0);
float totalWeight = getFilterTapWeight(tapInfo);
vec4 srcBlurred = sampleCenter * totalWeight;
for(int i = 1; i < numTaps; i++) {
tapInfo = getFilterTap(i);
// Fetch color and depth for current sample.
vec2 sampleCoord = texcoord + (getFilterTapOffset(tapInfo) * finalStep);
if (all(greaterThanEqual(sampleCoord, vec2(0,0))) && all(lessThanEqual(sampleCoord, vec2(1.0,1.0)))) {
float srcDepth = texture(depthMap, sampleCoord).x;
vec4 srcSample = texture(sourceMap, sampleCoord);
float weight = getFilterTapWeight(tapInfo);
// If the difference in depth is huge, we lerp color back.
float s = clamp(depthThreshold * distanceToProjectionWindow * filterScale * abs(srcDepth - sampleDepth), 0.0, 1.0);
srcSample = mix(srcSample, sampleCenter, s);
// Accumulate.
srcBlurred += srcSample * weight;
totalWeight += weight;
}
}
if (totalWeight > 0.0) {
srcBlurred /= totalWeight;
}
return srcBlurred;
}
<@endfunc@>