KiCad PCB EDA Suite
cpostshader.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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 CPOSTSHADER_H
31 #define CPOSTSHADER_H
32 
33 #include "ccamera.h"
34 
36 {
37 public:
38  explicit CPOSTSHADER( const CCAMERA &aCamera );
39  virtual ~CPOSTSHADER();
40 
41  virtual SFVEC3F Shade( const SFVEC2I &aShaderPos ) const = 0;
42 
48  virtual SFVEC3F ApplyShadeColor( const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, const SFVEC3F &aShadeColor ) const = 0;
49 
50  void UpdateSize( const SFVEC2UI &aSize );
51 
52  void UpdateSize( unsigned int xSize, unsigned int ySize );
53 
54  void InitFrame() { m_tmin = FLT_MAX; m_tmax = 0.0f; }
55 
56  void SetPixelData( unsigned int x,
57  unsigned int y,
58  const SFVEC3F &aNormal,
59  const SFVEC3F &aColor,
60  const SFVEC3F &aHitPosition,
61  float aDepth,
62  float aShadowAttFactor );
63 
64  const SFVEC3F &GetColorAtNotProtected( const SFVEC2I &aPos ) const;
65 
66  void DebugBuffersOutputAsImages() const;
67 
68 protected:
69  const SFVEC3F &GetNormalAt( const SFVEC2F &aPos ) const;
70  const SFVEC3F &GetColorAt( const SFVEC2F &aPos ) const;
71  const SFVEC3F &GetPositionAt( const SFVEC2F &aPos ) const;
72  float GetDepthAt( const SFVEC2F &aPos ) const;
73 
74  const SFVEC3F &GetNormalAt( const SFVEC2I &aPos ) const;
75  const SFVEC3F &GetColorAt( const SFVEC2I &aPos ) const;
76  const SFVEC3F &GetPositionAt( const SFVEC2I &aPos ) const;
77  const float &GetShadowFactorAt( const SFVEC2I &aPos ) const;
78 
79  float GetDepthAt( const SFVEC2I &aPos ) const;
80  float GetDepthNormalizedAt( const SFVEC2I &aPos ) const;
81  float GetMaxDepth() const { return m_tmax; }
82 
83 private:
84  void destroy_buffers();
85 
86  inline unsigned int getIndex( const SFVEC2F &aPos ) const
87  {
88  SFVEC2F clampPos;
89 
90  clampPos.x = glm::clamp( aPos.x, 0.0f, 1.0f );
91  clampPos.y = glm::clamp( aPos.y, 0.0f, 1.0f );
92 
93  const unsigned int idx = (unsigned int)( (float)m_size.x * clampPos.x +
94  (float)m_size.x * (float)m_size.y *
95  clampPos.y );
96 
97  return glm::min( idx, m_size.x * m_size.y );
98  }
99 
100  inline unsigned int getIndex( const SFVEC2I &aPos ) const
101  {
102  SFVEC2I clampPos;
103  clampPos.x = glm::clamp( aPos.x, 0, (int)m_size.x - 1 );
104  clampPos.y = glm::clamp( aPos.y, 0, (int)m_size.y - 1 );
105 
106  return (unsigned int)( clampPos.x + m_size.x * clampPos.y );
107  }
108 
109 protected:
111 
116  float *m_depth;
118  float m_tmin;
119  float m_tmax;
120 };
121 
122 
123 #endif // CPOSTSHADER_H
const CCAMERA & m_camera
Definition: cpostshader.h:110
const SFVEC3F & GetColorAtNotProtected(const SFVEC2I &aPos) const
float m_tmax
Definition: cpostshader.h:119
Class CCAMERA is a virtual class used to derive CCAMERA objects from.
Definition: ccamera.h:80
SFVEC2UI m_size
Definition: cpostshader.h:112
CPOSTSHADER(const CCAMERA &aCamera)
Definition: cpostshader.cpp:36
Define an abstract camera.
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
const SFVEC3F & GetNormalAt(const SFVEC2F &aPos) const
SFVEC3F * m_normals
Definition: cpostshader.h:113
void destroy_buffers()
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:41
float * m_depth
Definition: cpostshader.h:116
float GetDepthNormalizedAt(const SFVEC2I &aPos) const
SFVEC3F * m_color
Definition: cpostshader.h:114
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
virtual SFVEC3F ApplyShadeColor(const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, const SFVEC3F &aShadeColor) const =0
ApplyShadeColor - apply the final color process using a previous stage color.
void InitFrame()
Definition: cpostshader.h:54
const SFVEC3F & GetColorAt(const SFVEC2F &aPos) const
float GetMaxDepth() const
Definition: cpostshader.h:81
void DebugBuffersOutputAsImages() const
const SFVEC3F & GetPositionAt(const SFVEC2F &aPos) const
void SetPixelData(unsigned int x, unsigned int y, const SFVEC3F &aNormal, const SFVEC3F &aColor, const SFVEC3F &aHitPosition, float aDepth, float aShadowAttFactor)
Definition: cpostshader.cpp:78
float m_tmin
Definition: cpostshader.h:118
unsigned int getIndex(const SFVEC2I &aPos) const
Definition: cpostshader.h:100
float GetDepthAt(const SFVEC2F &aPos) const
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
virtual SFVEC3F Shade(const SFVEC2I &aShaderPos) const =0
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
void UpdateSize(const SFVEC2UI &aSize)
Definition: cpostshader.cpp:72
virtual ~CPOSTSHADER()
Definition: cpostshader.cpp:49
#define min(a, b)
Definition: auxiliary.h:85
const float & GetShadowFactorAt(const SFVEC2I &aPos) const
float * m_shadow_att_factor
Definition: cpostshader.h:117