2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2020-12-13 23:02:57 +00:00
|
|
|
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file post_shader_ssao.cpp
|
|
|
|
* @brief Implement a post shader screen space ambient occlusion in software.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "post_shader_ssao.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
#include "../3d_fastmath.h"
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
POST_SHADER_SSAO::POST_SHADER_SSAO( const CAMERA& aCamera ) :
|
|
|
|
POST_SHADER( aCamera ),
|
2020-07-18 22:56:39 +00:00
|
|
|
m_shadedBuffer( nullptr ),
|
|
|
|
m_isUsingShadows( false )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
// There are different sources for this shader on the web
|
2016-11-26 14:38:51 +00:00
|
|
|
//https://github.com/scanberg/hbao/blob/master/resources/shaders/ssao_frag.glsl
|
|
|
|
|
|
|
|
//http://www.gamedev.net/topic/556187-the-best-ssao-ive-seen/
|
2016-07-19 17:35:25 +00:00
|
|
|
//http://www.gamedev.net/topic/556187-the-best-ssao-ive-seen/?view=findpost&p=4632208
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
float POST_SHADER_SSAO::aoFF( const SFVEC2I& aShaderPos, const SFVEC3F& ddiff,
|
|
|
|
const SFVEC3F& cnorm, const float aShadowAtSamplePos,
|
2020-12-13 23:02:57 +00:00
|
|
|
const float aShadowAtCenterPos, int c1, int c2 ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-07-14 16:40:28 +00:00
|
|
|
const float shadowGain = 0.60f;
|
2016-11-26 14:38:51 +00:00
|
|
|
const float aoGain = 1.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
const float shadow_factor_at_sample = ( 1.0f - aShadowAtSamplePos ) * shadowGain;
|
|
|
|
const float shadow_factor_at_center = ( 1.0f - aShadowAtCenterPos ) * shadowGain;
|
|
|
|
|
|
|
|
float return_value = shadow_factor_at_center;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
const float rd = glm::length( ddiff );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
// This limits the zero of the function (see below)
|
2020-07-14 16:40:28 +00:00
|
|
|
if( rd < 2.0f )
|
2016-11-26 14:38:51 +00:00
|
|
|
{
|
|
|
|
if( rd > FLT_EPSILON )
|
|
|
|
{
|
|
|
|
const SFVEC3F vv = glm::normalize( ddiff );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
// Calculate an attenuation distance factor, this was get the best
|
|
|
|
// results by experimentation
|
|
|
|
// Changing this factor will change how much shadow in relation to the
|
|
|
|
// distance of the hit it will be in shadow
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIwLjgteCowLjYiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjAsImVxIjoiMS8oeCp4KjAuNSsxKSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0yLjU5Mjk0NTkyNTA5ODA0MSIsIjQuNTUzODc5NjU1NDQ1OTIzIiwiLTEuNzY3MDMwOTAzMjgxNjgxOCIsIjIuNjMxMDE1NjA3ODIyMjk3Il0sInNpemUiOls2NDksMzk5XX1d
|
|
|
|
const float attDistFactor = 1.0f / ( rd * rd * 8.0f + 1.0f );
|
|
|
|
|
|
|
|
const SFVEC2I vr = aShaderPos + SFVEC2I( c1, c2 );
|
|
|
|
|
|
|
|
float sampledNormalFactor = glm::max( glm::dot( GetNormalAt( vr ), cnorm ), 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
sampledNormalFactor = glm::max( 1.0f - sampledNormalFactor *
|
|
|
|
sampledNormalFactor, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
const float shadowAttDistFactor = glm::max( glm::min( rd * 5.0f - 0.25f, 1.0f ), 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
float shadowAttFactor = glm::min( sampledNormalFactor + shadowAttDistFactor, 1.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
const float shadowFactor = glm::mix( shadow_factor_at_sample, shadow_factor_at_center,
|
2020-07-14 16:40:28 +00:00
|
|
|
shadowAttFactor );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
// This is a dot product threshold factor.
|
2020-12-13 23:02:57 +00:00
|
|
|
// it defines after which angle we consider that the point starts to occlude.
|
2020-07-14 16:40:28 +00:00
|
|
|
// if the value is high, it will discard low angles point
|
2016-11-26 14:38:51 +00:00
|
|
|
const float aDotThreshold = 0.15f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
// This is the dot product between the center pixel normal (the one that is being
|
|
|
|
// shaded) and the vector from the center to the sampled point
|
2016-11-26 14:38:51 +00:00
|
|
|
const float localNormalFactor = glm::dot( cnorm, vv );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
const float localNormalFactorWithThreshold =
|
2021-01-03 22:23:00 +00:00
|
|
|
( glm::max( localNormalFactor, aDotThreshold ) - aDotThreshold ) /
|
2020-12-13 23:02:57 +00:00
|
|
|
( 1.0f - aDotThreshold );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
const float aoFactor = localNormalFactorWithThreshold * aoGain * attDistFactor;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
return_value = glm::min( aoFactor + shadowFactor, 1.0f );
|
2016-11-26 14:38:51 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
return return_value;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
float POST_SHADER_SSAO::giFF( const SFVEC2I& aShaderPos, const SFVEC3F& ddiff,
|
|
|
|
const SFVEC3F& cnorm, const float aShadow, int c1, int c2 ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-13 23:02:57 +00:00
|
|
|
if( ( ddiff.x > FLT_EPSILON ) || ( ddiff.y > FLT_EPSILON ) || ( ddiff.z > FLT_EPSILON ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const SFVEC3F vv = glm::normalize( ddiff );
|
|
|
|
const float rd = glm::length( ddiff );
|
|
|
|
const SFVEC2I vr = aShaderPos + SFVEC2I( c1, c2 );
|
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
const float attDistFactor = 1.0f / ( rd * rd + 1.0f );
|
|
|
|
|
|
|
|
return ( glm::clamp( glm::dot( GetNormalAt( vr ), -vv), 0.0f, 1.0f ) *
|
2020-12-13 23:02:57 +00:00
|
|
|
glm::clamp( glm::dot( cnorm, vv ), 0.0f, 1.0f ) * attDistFactor ) *
|
|
|
|
( 0.03f + aShadow ) * 3.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F POST_SHADER_SSAO::Shade( const SFVEC2I& aShaderPos ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
float cdepth = GetDepthAt( aShaderPos );
|
|
|
|
|
|
|
|
if( cdepth > FLT_EPSILON )
|
|
|
|
{
|
2020-07-14 16:40:28 +00:00
|
|
|
cdepth = ( 30.0f / ( cdepth * 2.0f + 1.0f ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
// read current normal, position and color.
|
2016-09-29 17:56:56 +00:00
|
|
|
const SFVEC3F n = GetNormalAt( aShaderPos );
|
|
|
|
const SFVEC3F p = GetPositionAt( aShaderPos );
|
2020-07-14 16:40:28 +00:00
|
|
|
|
|
|
|
const float shadowAt0 = GetShadowFactorAt( aShaderPos );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// initialize variables:
|
|
|
|
float ao = 0.0f;
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F gi = SFVEC3F( 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
#define ROUNDS 3
|
|
|
|
for( unsigned int i = 0; i < ROUNDS; ++i )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-07-14 16:40:28 +00:00
|
|
|
static const int limit[ROUNDS] = { 0x01, 0x03, 0x03 };
|
|
|
|
|
|
|
|
const int pw = Fast_rand() & limit[i];
|
|
|
|
const int ph = Fast_rand() & limit[i];
|
|
|
|
|
|
|
|
const int npw = (int) ( ( pw + i ) * cdepth ) + ( i + 1 );
|
|
|
|
const int nph = (int) ( ( ph + i ) * cdepth ) + ( i + 1 );
|
|
|
|
|
|
|
|
const SFVEC3F ddiff = GetPositionAt( aShaderPos + SFVEC2I( npw, nph ) ) - p;
|
|
|
|
const SFVEC3F ddiff2 = GetPositionAt( aShaderPos + SFVEC2I( npw, -nph ) ) - p;
|
|
|
|
const SFVEC3F ddiff3 = GetPositionAt( aShaderPos + SFVEC2I( -npw, nph ) ) - p;
|
|
|
|
const SFVEC3F ddiff4 = GetPositionAt( aShaderPos + SFVEC2I( -npw, -nph ) ) - p;
|
|
|
|
const SFVEC3F ddiff5 = GetPositionAt( aShaderPos + SFVEC2I( pw, nph ) ) - p;
|
|
|
|
const SFVEC3F ddiff6 = GetPositionAt( aShaderPos + SFVEC2I( pw, -nph ) ) - p;
|
|
|
|
const SFVEC3F ddiff7 = GetPositionAt( aShaderPos + SFVEC2I( npw, ph ) ) - p;
|
|
|
|
const SFVEC3F ddiff8 = GetPositionAt( aShaderPos + SFVEC2I(-npw, ph ) ) - p;
|
|
|
|
|
|
|
|
const float shadowAt1 = GetShadowFactorAt( aShaderPos + SFVEC2I( +npw, nph ) );
|
|
|
|
const float shadowAt2 = GetShadowFactorAt( aShaderPos + SFVEC2I( +npw, -nph ) );
|
|
|
|
const float shadowAt3 = GetShadowFactorAt( aShaderPos + SFVEC2I( -npw, nph ) );
|
|
|
|
const float shadowAt4 = GetShadowFactorAt( aShaderPos + SFVEC2I( -npw, -nph ) );
|
|
|
|
const float shadowAt5 = GetShadowFactorAt( aShaderPos + SFVEC2I( +pw, nph ) );
|
|
|
|
const float shadowAt6 = GetShadowFactorAt( aShaderPos + SFVEC2I( pw, -nph ) );
|
|
|
|
const float shadowAt7 = GetShadowFactorAt( aShaderPos + SFVEC2I( npw, ph ) );
|
|
|
|
const float shadowAt8 = GetShadowFactorAt( aShaderPos + SFVEC2I( -npw, ph ) );
|
|
|
|
|
|
|
|
ao += aoFF( aShaderPos, ddiff , n, shadowAt1, shadowAt0, npw, nph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff2, n, shadowAt2, shadowAt0, npw, -nph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff3, n, shadowAt3, shadowAt0, -npw, nph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff4, n, shadowAt4, shadowAt0, -npw, -nph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff5, n, shadowAt5, shadowAt0, pw, nph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff6, n, shadowAt6, shadowAt0, pw, -nph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff7, n, shadowAt7, shadowAt0, npw, ph );
|
|
|
|
ao += aoFF( aShaderPos, ddiff8, n, shadowAt8, shadowAt0, -npw, ph );
|
|
|
|
|
|
|
|
gi += giFF( aShaderPos, ddiff , n, shadowAt1, npw, nph) *
|
2016-07-19 17:35:25 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( npw, nph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff2, n, shadowAt2, npw, -nph) *
|
2016-07-19 17:35:25 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( npw,-nph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff3, n, shadowAt3, -npw, nph) *
|
2016-07-19 17:35:25 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( -npw, nph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff4, n, shadowAt4, -npw, -nph) *
|
2016-07-19 17:35:25 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( -npw,-nph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff5, n, shadowAt5 , pw, nph) *
|
2016-11-26 14:38:51 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( pw, nph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff6, n, shadowAt6, pw,-nph) *
|
2016-11-26 14:38:51 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( pw,-nph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff7, n, shadowAt7, npw, ph) *
|
2016-11-26 14:38:51 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( npw, ph ) ) );
|
2020-07-14 16:40:28 +00:00
|
|
|
gi += giFF( aShaderPos, ddiff8, n, shadowAt8, -npw, ph) *
|
2016-11-26 14:38:51 +00:00
|
|
|
giColorCurve( GetColorAt( aShaderPos + SFVEC2I( -npw, ph ) ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-07-14 16:40:28 +00:00
|
|
|
|
|
|
|
// If it received direct light, it shouldn't consider much AO
|
|
|
|
// shadowAt0 1.0 when no shadow
|
|
|
|
const float reduceAOwhenNoShadow = m_isUsingShadows ? ( 1.0f - shadowAt0 * 0.3f ) : 1.0f;
|
|
|
|
|
|
|
|
ao = reduceAOwhenNoShadow * ( ao / ( ROUNDS * 8.0f ) );
|
|
|
|
|
|
|
|
ao = ( 1.0f - 1.0f / ( ao * ao * 5.0f + 1.0f ) ) * 1.2f;
|
|
|
|
|
|
|
|
gi = ( gi / ( ROUNDS * 8.0f ) );
|
|
|
|
|
|
|
|
float giL = glm::min( glm::length( gi ) * 4.0f, 1.0f );
|
|
|
|
|
|
|
|
giL = ( 1.0f - 1.0f / ( giL * 4.0f + 1.0f ) ) * 1.5f;
|
|
|
|
|
|
|
|
return glm::mix( SFVEC3F( ao ), -gi, giL );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
2020-12-13 23:02:57 +00:00
|
|
|
{
|
|
|
|
return SFVEC3F( 0.0f );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F POST_SHADER_SSAO::ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
|
|
|
|
const SFVEC3F& aShadeColor ) const
|
2016-11-26 14:38:51 +00:00
|
|
|
{
|
2020-07-14 16:40:28 +00:00
|
|
|
SFVEC3F outColor;
|
|
|
|
|
|
|
|
const SFVEC3F subtracted = aInputColor - aShadeColor;
|
2020-12-13 23:02:57 +00:00
|
|
|
const SFVEC3F mixed = glm::mix( aInputColor, aInputColor * 0.50f - aShadeColor * 0.05f,
|
2020-07-14 16:40:28 +00:00
|
|
|
glm::min( aShadeColor, 1.0f ) );
|
|
|
|
|
|
|
|
outColor.r = ( aShadeColor.r < 0.0f ) ? subtracted.r : mixed.r;
|
|
|
|
outColor.g = ( aShadeColor.g < 0.0f ) ? subtracted.g : mixed.g;
|
|
|
|
outColor.b = ( aShadeColor.b < 0.0f ) ? subtracted.b : mixed.b;
|
2016-11-26 14:38:51 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
return outColor;
|
2016-11-26 14:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F POST_SHADER_SSAO::giColorCurve( const SFVEC3F& aColor ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-13 23:02:57 +00:00
|
|
|
const SFVEC3F vec1 = SFVEC3F( 1.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
// This option actually apply a gamma since we are using linear color space
|
2016-11-26 14:38:51 +00:00
|
|
|
// and the result shader will be applied after convert back to sRGB
|
|
|
|
|
|
|
|
// http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIxLjAtKDEuMC8oeCo5LjArMS4wKSkreCowLjEiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyItMC4wNjIxODQ2MTUzODQ2MTU1MDUiLCIxLjE0Mjk4NDYxNTM4NDYxNDYiLCItMC4xMjcwOTk5OTk5OTk5OTk3NyIsIjEuMTMyNiJdfV0-
|
|
|
|
return vec1 - ( vec1 / (aColor * SFVEC3F(9.0f) + vec1) ) + aColor * SFVEC3F(0.10f);
|
2020-07-14 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F POST_SHADER_SSAO::Blur( const SFVEC2I& aShaderPos ) const
|
2020-07-14 16:40:28 +00:00
|
|
|
{
|
|
|
|
const float dCenter = GetDepthAt( aShaderPos );
|
|
|
|
|
|
|
|
SFVEC3F shadedOut = SFVEC3F( 0.0f );
|
|
|
|
|
|
|
|
float totalWeight = 1.0f;
|
|
|
|
|
|
|
|
for( int y = -3; y < 3; y++ )
|
|
|
|
{
|
|
|
|
for( int x = -3; x < 3; x++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
const unsigned int idx = GetIndex( SFVEC2I( aShaderPos.x + x, aShaderPos.y + y ) );
|
|
|
|
|
|
|
|
const SFVEC3F s = m_shadedBuffer[idx];
|
|
|
|
|
|
|
|
if( !( ( x == 0 ) && ( y == 0 ) ) )
|
|
|
|
{
|
|
|
|
|
|
|
|
const float d = GetDepthAt( SFVEC2I( aShaderPos.x + x, aShaderPos.y + y ) );
|
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
// Increasing the value will get more sharpness effect.
|
|
|
|
const float depthAtt = ( dCenter - d ) * dCenter * 25.0f;
|
2020-07-14 16:40:28 +00:00
|
|
|
|
|
|
|
const float depthAttSqr = depthAtt * depthAtt;
|
|
|
|
|
|
|
|
float weight = ( 1.0f / ( depthAttSqr + 1.0f ) ) - 0.02f * depthAttSqr;
|
|
|
|
|
|
|
|
weight = glm::max( weight, 0.0f );
|
|
|
|
|
|
|
|
shadedOut += s * weight;
|
|
|
|
totalWeight += weight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shadedOut += s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-26 14:38:51 +00:00
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
return shadedOut / totalWeight;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|