Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ void ViewerSettingsPlugin::drawDialog( float menuScaling, ImGuiContext* )
ImGui::ColorEdit4( "Color", &shadowGl_->shadowColor.x,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_PickerHueWheel );
ImGui::DragFloat2( "Shift", &shadowGl_->shadowShift.x, 0.4f, -200.0f, 200.0f );
ImGui::SetTooltipIfHovered( "X, Y shift in screen coordinates:\nX going right\nY going up", menuScaling );
ImGui::DragFloatValid( "Blur radius", &shadowGl_->blurRadius, 0.2f, 0, 200 );
float quality = shadowGl_->getQuality();
ImGui::DragFloatValid( "Quality", &quality, 0.0625f, 0.001f, 1.0f );
ImGui::SetTooltipIfHovered( "Blur texture downscaling coefficient", menuScaling );
shadowGl_->setQuality( quality );
}
}
ImGui::EndCustomStatePlugin();
Expand Down
58 changes: 26 additions & 32 deletions source/MRViewer/MRGLStaticHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,46 +1243,35 @@ void main(void)
uniform vec4 color;
uniform vec2 shift;
uniform float blurRadius;
uniform bool convX;
out vec4 outColor; // (out to render) fragment color

#define NUM_DIRECTIONS 12
#define QUALITY 3

#define DIR_STEP 0.5235987756
#define INV_QUALITY 0.33333334
#define INV_NUM_SAMPLES 0.020833333
const float gaussWeights[] = float[7] (0.161046, 0.148645, 0.116919, 0.078381, 0.044771, 0.021742, 0.009019);

void main()
{
gl_FragDepth = 0.9999;
ivec2 texSize = textureSize( pixels, 0 );
vec2 pos = gl_FragCoord.xy + shift;
vec2 pos = gl_FragCoord.xy;
if ( !convX )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use this shader for x convolution and for y convolution, shift can be applied only for one of them

pos = pos - shift;
pos = vec2( pos.x/float(texSize.x),pos.y/float(texSize.y) );

if ( texelFetch(pixels, ivec2( gl_FragCoord.xy ), 0 ).a == 1.0 )
discard;

if ( textureLod(pixels,pos,max(10.0,log2(blurRadius)+2.0)).a == 0.0 )
discard;

float avgValue = 0.0;
float maxRadiusSq = blurRadius*blurRadius;

avgValue = texture(pixels, pos).a;

for ( int r = 1; r <= QUALITY; r = r + 1 )
vec2 posShift = vec2(0.0);
if ( convX )
posShift = vec2(blurRadius /(6.0* float(texSize.x)),0.0);
else
posShift = vec2(0.0,blurRadius /(6.0* float(texSize.y)));

float convSum = gaussWeights[0]*texture(pixels, pos).a;
for ( int i=1; i<=6; ++i )
{
float radius = float(r)*(blurRadius-0.5)*INV_QUALITY;
vec2 normRad = vec2(radius/float(texSize.x),radius/float(texSize.y));
for ( int ang = 0; ang < NUM_DIRECTIONS; ang = ang + 1 )
{
float realAng = float(ang)*DIR_STEP;
vec2 addPos = vec2(cos(realAng)*normRad.x, sin(realAng)*normRad.y);
avgValue = avgValue + texture(pixels, pos+addPos).a;
}
vec2 fullShift = float(i)*posShift;
convSum = convSum + gaussWeights[i]*texture(pixels, pos+fullShift).a;
convSum = convSum + gaussWeights[i]*texture(pixels, pos-fullShift).a;
}
avgValue = avgValue * INV_NUM_SAMPLES;
outColor = vec4(color.rgb,avgValue*color.a);
gl_FragDepth = 0.9999;
outColor = vec4(color.rgb,convSum);
if ( !convX )
outColor.a = outColor.a*color.a;
if (outColor.a == 0.0)
discard;
}
Expand All @@ -1294,11 +1283,16 @@ void main(void)
MR_GLSL_VERSION_LINE R"(
precision highp float;
uniform sampler2D pixels;
uniform vec2 viewportSize;
uniform float depth;
out vec4 outColor; // (out to render) fragment color

void main()
{
outColor = texelFetch(pixels, ivec2( gl_FragCoord.xy ), 0 );
gl_FragDepth = depth;
vec2 pos = gl_FragCoord.xy;
pos = vec2( pos.x/float(viewportSize.x),pos.y/float(viewportSize.y) );
outColor = texture(pixels, pos );
if (outColor.a == 0.0)
discard;
}
Expand Down
Loading