1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
23  */
24 
25  /**
26  * @file post_shader_ssao.h
27  * @brief Implements a post shader screen space ambient occlusion on software
28  */
29 
30 #ifndef POST_SHADER_SSAO_H
31 #define POST_SHADER_SSAO_H
32 
33 
34 #include "post_shader.h"
35 
36 
37 class POST_SHADER_SSAO : public POST_SHADER
38 {
39 public:
40     explicit POST_SHADER_SSAO( const CAMERA& aCamera );
41 
42     SFVEC3F Shade(const SFVEC2I& aShaderPos ) const override;
43     SFVEC3F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
44                              const SFVEC3F& aShadeColor ) const override;
45 
46     SFVEC3F Blur( const SFVEC2I& aShaderPos ) const;
47 
SetShadedBuffer(SFVEC3F * aShadedBuffer)48     void SetShadedBuffer( SFVEC3F* aShadedBuffer )
49     {
50         m_shadedBuffer = aShadedBuffer;
51     }
52 
SetShadowsEnabled(bool aIsShadowsEnabled)53     void SetShadowsEnabled( bool aIsShadowsEnabled )
54     {
55         m_isUsingShadows = aIsShadowsEnabled;
56     }
57 
58 private:
59     SFVEC3F posFromDepth( const SFVEC2F& coord ) const;
60 
61     float ec_depth( const SFVEC2F& tc ) const;
62 
63     float aoFF( const SFVEC2I& aShaderPos, const SFVEC3F& ddiff, const SFVEC3F& cnorm,
64                 const float aShadowAtSamplePos, const float aShadowAtCenterPos,
65                 int c1, int c2 ) const;
66 
67     float giFF( const SFVEC2I& aShaderPos, const SFVEC3F& ddiff, const SFVEC3F& cnorm,
68                 const float aShadow, int c1, int c2 ) const;
69 
70     /**
71      * Apply a curve transformation to the original color.
72      *
73      * It will attenuate the bright colors (works as a gamma function):
74      * http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIxLjAtKDEvKHgqMS4wKzEuMCkpK3gqMC4zMCIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0wLjA2MjE4NDYxNTM4NDYxNTUwNSIsIjEuMTQyOTg0NjE1Mzg0NjE0NiIsIi0wLjEyNzA5OTk5OTk5OTk5OTc3IiwiMS4xMzI2Il19XQ--
75      *
76      * @param aColor input color.
77      * @return transformed color.
78      */
79     SFVEC3F giColorCurve( const SFVEC3F& aColor ) const;
80 
81     SFVEC3F* m_shadedBuffer;
82 
83     bool m_isUsingShadows;
84 };
85 
86 
87 #endif   // POST_SHADER_SSAO_H
88