KiCad PCB EDA Suite
post_shader.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2016 Mario Luzeiro <[email protected]>
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
30#ifndef POST_SHADER_H
31#define POST_SHADER_H
32
33#include "camera.h"
34
36{
37public:
38 explicit POST_SHADER( const CAMERA& aCamera );
39 virtual ~POST_SHADER();
40
41 virtual SFVEC3F Shade( const SFVEC2I& aShaderPos ) const = 0;
42
49 virtual SFVEC3F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
50 const SFVEC3F& aShadeColor ) const = 0;
51
52 void UpdateSize( const SFVEC2UI& aSize );
53
54 void UpdateSize( unsigned int xSize, unsigned int ySize );
55
56 void InitFrame() { m_tmin = FLT_MAX; m_tmax = 0.0f; }
57
58 void SetPixelData( unsigned int x, unsigned int y, const SFVEC3F& aNormal,
59 const SFVEC3F& aColor, const SFVEC3F& aHitPosition,
60 float aDepth, float aShadowAttFactor );
61
62 const SFVEC3F& GetColorAtNotProtected( const SFVEC2I& aPos ) const;
63
64 void DebugBuffersOutputAsImages() const;
65
66 inline unsigned int GetIndex( const SFVEC2F& aPos ) const
67 {
68 SFVEC2F clampPos;
69
70 clampPos.x = glm::clamp( aPos.x, 0.0f, 1.0f );
71 clampPos.y = glm::clamp( aPos.y, 0.0f, 1.0f );
72
73 const unsigned int idx = (unsigned int)( (float)m_size.x * clampPos.x +
74 (float)m_size.x * (float)m_size.y *
75 clampPos.y );
76
77 return glm::min( idx, m_size.x * m_size.y );
78 }
79
80 inline unsigned int GetIndex( const SFVEC2I& aPos ) const
81 {
82 SFVEC2I clampPos;
83 clampPos.x = glm::clamp( aPos.x, 0, (int)m_size.x - 1 );
84 clampPos.y = glm::clamp( aPos.y, 0, (int)m_size.y - 1 );
85
86 return (unsigned int)( clampPos.x + m_size.x * clampPos.y );
87 }
88
89protected:
90 const SFVEC3F& GetNormalAt( const SFVEC2F& aPos ) const;
91 const SFVEC3F& GetColorAt( const SFVEC2F& aPos ) const;
92 const SFVEC3F& GetPositionAt( const SFVEC2F& aPos ) const;
93 float GetDepthAt( const SFVEC2F& aPos ) const;
94
95 const SFVEC3F& GetNormalAt( const SFVEC2I& aPos ) const;
96 const SFVEC3F& GetColorAt( const SFVEC2I& aPos ) const;
97 const SFVEC3F& GetPositionAt( const SFVEC2I& aPos ) const;
98 const float& GetShadowFactorAt( const SFVEC2I& aPos ) const;
99
100 float GetDepthAt( const SFVEC2I& aPos ) const;
101 float GetDepthNormalizedAt( const SFVEC2I& aPos ) const;
102 float GetMaxDepth() const { return m_tmax; }
103
104private:
105 void destroy_buffers();
106
107protected:
109
114 float* m_depth;
116 float m_tmin;
117 float m_tmax;
118};
119
120
121#endif // POST_SHADER_H
Define an abstract camera.
A class used to derive camera objects from.
Definition: camera.h:78
float * m_depth
Definition: post_shader.h:114
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
const SFVEC3F & GetColorAtNotProtected(const SFVEC2I &aPos) const
SFVEC3F * m_normals
Definition: post_shader.h:111
POST_SHADER(const CAMERA &aCamera)
Definition: post_shader.cpp:36
const CAMERA & m_camera
Definition: post_shader.h:108
void DebugBuffersOutputAsImages() const
float GetDepthNormalizedAt(const SFVEC2I &aPos) const
void UpdateSize(const SFVEC2UI &aSize)
Definition: post_shader.cpp:73
void SetPixelData(unsigned int x, unsigned int y, const SFVEC3F &aNormal, const SFVEC3F &aColor, const SFVEC3F &aHitPosition, float aDepth, float aShadowAttFactor)
Definition: post_shader.cpp:79
const SFVEC3F & GetColorAt(const SFVEC2F &aPos) const
const SFVEC3F & GetNormalAt(const SFVEC2F &aPos) const
virtual SFVEC3F Shade(const SFVEC2I &aShaderPos) const =0
SFVEC3F * m_color
Definition: post_shader.h:112
float GetMaxDepth() const
Definition: post_shader.h:102
const SFVEC3F & GetPositionAt(const SFVEC2F &aPos) const
SFVEC3F * m_wc_hitposition
Definition: post_shader.h:113
void InitFrame()
Definition: post_shader.h:56
SFVEC2UI m_size
Definition: post_shader.h:110
void destroy_buffers()
virtual ~POST_SHADER()
Definition: post_shader.cpp:50
const float & GetShadowFactorAt(const SFVEC2I &aPos) const
float GetDepthAt(const SFVEC2F &aPos) const
float m_tmax
Definition: post_shader.h:117
virtual SFVEC3F ApplyShadeColor(const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, const SFVEC3F &aShadeColor) const =0
Apply the final color process using a previous stage color.
unsigned int GetIndex(const SFVEC2I &aPos) const
Definition: post_shader.h:80
float * m_shadow_att_factor
Definition: post_shader.h:115
float m_tmin
Definition: post_shader.h:116
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:38