KiCad PCB EDA Suite
CPOSTSHADER Class Referenceabstract

#include <cpostshader.h>

Inheritance diagram for CPOSTSHADER:
CPOSTSHADER_SSAO

Public Member Functions

 CPOSTSHADER (const CCAMERA &aCamera)
 
virtual ~CPOSTSHADER ()
 
virtual SFVEC3F Shade (const SFVEC2I &aShaderPos) const =0
 
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. More...
 
void UpdateSize (const SFVEC2UI &aSize)
 
void UpdateSize (unsigned int xSize, unsigned int ySize)
 
void InitFrame ()
 
void SetPixelData (unsigned int x, unsigned int y, const SFVEC3F &aNormal, const SFVEC3F &aColor, const SFVEC3F &aHitPosition, float aDepth, float aShadowAttFactor)
 
const SFVEC3FGetColorAtNotProtected (const SFVEC2I &aPos) const
 
void DebugBuffersOutputAsImages () const
 

Protected Member Functions

const SFVEC3FGetNormalAt (const SFVEC2F &aPos) const
 
const SFVEC3FGetColorAt (const SFVEC2F &aPos) const
 
const SFVEC3FGetPositionAt (const SFVEC2F &aPos) const
 
float GetDepthAt (const SFVEC2F &aPos) const
 
const SFVEC3FGetNormalAt (const SFVEC2I &aPos) const
 
const SFVEC3FGetColorAt (const SFVEC2I &aPos) const
 
const SFVEC3FGetPositionAt (const SFVEC2I &aPos) const
 
const float & GetShadowFactorAt (const SFVEC2I &aPos) const
 
float GetDepthAt (const SFVEC2I &aPos) const
 
float GetDepthNormalizedAt (const SFVEC2I &aPos) const
 
float GetMaxDepth () const
 

Protected Attributes

const CCAMERAm_camera
 
SFVEC2UI m_size
 
SFVEC3Fm_normals
 
SFVEC3Fm_color
 
SFVEC3Fm_wc_hitposition
 
float * m_depth
 
float * m_shadow_att_factor
 
float m_tmin
 
float m_tmax
 

Private Member Functions

void destroy_buffers ()
 
unsigned int getIndex (const SFVEC2F &aPos) const
 
unsigned int getIndex (const SFVEC2I &aPos) const
 

Detailed Description

Definition at line 35 of file cpostshader.h.

Constructor & Destructor Documentation

CPOSTSHADER::CPOSTSHADER ( const CCAMERA aCamera)
explicit

Definition at line 36 of file cpostshader.cpp.

References m_color, m_depth, m_normals, m_shadow_att_factor, m_size, m_tmax, m_tmin, and m_wc_hitposition.

36  : m_camera(aCamera)
37 {
38  m_size = SFVEC2UI( 0, 0 );
39  m_normals = NULL;
40  m_color = NULL;
41  m_depth = NULL;
42  m_wc_hitposition = NULL;
43  m_shadow_att_factor = NULL;
44  m_tmin = FLT_MAX;
45  m_tmax = FLT_MIN;
46 }
const CCAMERA & m_camera
Definition: cpostshader.h:110
float m_tmax
Definition: cpostshader.h:119
SFVEC2UI m_size
Definition: cpostshader.h:112
SFVEC3F * m_normals
Definition: cpostshader.h:113
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:41
float * m_depth
Definition: cpostshader.h:116
SFVEC3F * m_color
Definition: cpostshader.h:114
float m_tmin
Definition: cpostshader.h:118
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
float * m_shadow_att_factor
Definition: cpostshader.h:117
CPOSTSHADER::~CPOSTSHADER ( )
virtual

Definition at line 49 of file cpostshader.cpp.

References destroy_buffers().

50 {
52 }
void destroy_buffers()

Member Function Documentation

virtual SFVEC3F CPOSTSHADER::ApplyShadeColor ( const SFVEC2I aShaderPos,
const SFVEC3F aInputColor,
const SFVEC3F aShadeColor 
) const
pure virtual

ApplyShadeColor - apply the final color process using a previous stage color.

Parameters
aShadeColor- The result of the shader
Returns
the result of the shade process

Implemented in CPOSTSHADER_SSAO.

void CPOSTSHADER::DebugBuffersOutputAsImages ( ) const

Definition at line 191 of file cpostshader.cpp.

References DBG_SaveBuffer(), DBG_SaveNormalsBuffer(), GetDepthNormalizedAt(), m_color, m_normals, m_shadow_att_factor, and m_size.

192 {
193  DBG_SaveBuffer( "m_shadow_att_factor", m_shadow_att_factor, m_size.x, m_size.y );
194  DBG_SaveBuffer( "m_color", m_color, m_size.x, m_size.y );
195  DBG_SaveNormalsBuffer( "m_normals", m_normals, m_size.x, m_size.y );
196 
197  // Normalize depth
198  // /////////////////////////////////////////////////////////////////////////
199  float *normalizedDepth = (float*) malloc( m_size.x * m_size.y * sizeof( float ) );
200 
201  float *normalizedDepthPTr = normalizedDepth;
202 
203  for( unsigned int iy = 0; iy < m_size.y; ++iy )
204  for( unsigned int ix = 0; ix < m_size.x; ++ix )
205  {
206  *normalizedDepthPTr = GetDepthNormalizedAt( SFVEC2I( ix, iy) );
207  normalizedDepthPTr++;
208  }
209 
210  DBG_SaveBuffer( "m_depthNormalized", normalizedDepth, m_size.x, m_size.y );
211 
212  free( normalizedDepth );
213 }
SFVEC2UI m_size
Definition: cpostshader.h:112
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
SFVEC3F * m_normals
Definition: cpostshader.h:113
float GetDepthNormalizedAt(const SFVEC2I &aPos) const
SFVEC3F * m_color
Definition: cpostshader.h:114
void DBG_SaveNormalsBuffer(wxString aFileName, const SFVEC3F *aInNormalsBuffer, unsigned int aXSize, unsigned int aYSize)
void DBG_SaveBuffer(wxString aFileName, const unsigned char *aInBuffer, unsigned int aXSize, unsigned int aYSize)
float * m_shadow_att_factor
Definition: cpostshader.h:117
void CPOSTSHADER::destroy_buffers ( )
private

Definition at line 110 of file cpostshader.cpp.

References m_color, m_depth, m_normals, m_shadow_att_factor, and m_wc_hitposition.

Referenced by UpdateSize(), and ~CPOSTSHADER().

111 {
112  delete[] m_normals; m_normals = nullptr;
113  delete[] m_color; m_color = nullptr;
114  delete[] m_depth; m_depth = nullptr;
115  delete[] m_shadow_att_factor; m_shadow_att_factor = nullptr;
116  delete[] m_wc_hitposition; m_wc_hitposition = nullptr;
117 }
SFVEC3F * m_normals
Definition: cpostshader.h:113
float * m_depth
Definition: cpostshader.h:116
SFVEC3F * m_color
Definition: cpostshader.h:114
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
float * m_shadow_att_factor
Definition: cpostshader.h:117
const SFVEC3F & CPOSTSHADER::GetColorAt ( const SFVEC2F aPos) const
protected

Definition at line 126 of file cpostshader.cpp.

References getIndex(), and m_color.

Referenced by CPOSTSHADER_SSAO::Shade().

127 {
128  return m_color[ getIndex( aPos ) ];
129 }
SFVEC3F * m_color
Definition: cpostshader.h:114
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
const SFVEC3F & CPOSTSHADER::GetColorAt ( const SFVEC2I aPos) const
protected

Definition at line 150 of file cpostshader.cpp.

References getIndex(), and m_color.

151 {
152  return m_color[ getIndex( aPos ) ];
153 }
SFVEC3F * m_color
Definition: cpostshader.h:114
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
const SFVEC3F & CPOSTSHADER::GetColorAtNotProtected ( const SFVEC2I aPos) const

Definition at line 156 of file cpostshader.cpp.

References m_color, and m_size.

Referenced by C3D_RENDER_RAYTRACING::rt_render_post_process_blur_finish().

157 {
158  return m_color[ aPos.x + m_size.x * aPos.y ];
159 }
SFVEC2UI m_size
Definition: cpostshader.h:112
SFVEC3F * m_color
Definition: cpostshader.h:114
float CPOSTSHADER::GetDepthAt ( const SFVEC2F aPos) const
protected

Definition at line 132 of file cpostshader.cpp.

References getIndex(), and m_depth.

Referenced by CPOSTSHADER_SSAO::Shade().

133 {
134  return m_depth[ getIndex( aPos ) ];
135 }
float * m_depth
Definition: cpostshader.h:116
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
float CPOSTSHADER::GetDepthAt ( const SFVEC2I aPos) const
protected

Definition at line 162 of file cpostshader.cpp.

References getIndex(), and m_depth.

163 {
164  return m_depth[ getIndex( aPos ) ];
165 }
float * m_depth
Definition: cpostshader.h:116
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
float CPOSTSHADER::GetDepthNormalizedAt ( const SFVEC2I aPos) const
protected

Definition at line 168 of file cpostshader.cpp.

References getIndex(), m_depth, m_tmax, and m_tmin.

Referenced by DebugBuffersOutputAsImages().

169 {
170  const float depth = m_depth[ getIndex( aPos ) ];
171 
172  if( depth >= m_tmin )
173  return (depth - m_tmin) / (m_tmax - m_tmin);
174 
175  return 0.0f;
176 }
float m_tmax
Definition: cpostshader.h:119
float * m_depth
Definition: cpostshader.h:116
float m_tmin
Definition: cpostshader.h:118
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
unsigned int CPOSTSHADER::getIndex ( const SFVEC2F aPos) const
inlineprivate

Definition at line 86 of file cpostshader.h.

References m_size, and min.

Referenced by GetColorAt(), GetDepthAt(), GetDepthNormalizedAt(), GetNormalAt(), GetPositionAt(), and GetShadowFactorAt().

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  }
SFVEC2UI m_size
Definition: cpostshader.h:112
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
#define min(a, b)
Definition: auxiliary.h:85
unsigned int CPOSTSHADER::getIndex ( const SFVEC2I aPos) const
inlineprivate

Definition at line 100 of file cpostshader.h.

References m_size.

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  }
SFVEC2UI m_size
Definition: cpostshader.h:112
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:42
float CPOSTSHADER::GetMaxDepth ( ) const
inlineprotected

Definition at line 81 of file cpostshader.h.

References m_tmax.

81 { return m_tmax; }
float m_tmax
Definition: cpostshader.h:119
const SFVEC3F & CPOSTSHADER::GetNormalAt ( const SFVEC2F aPos) const
protected

Definition at line 120 of file cpostshader.cpp.

References getIndex(), and m_normals.

Referenced by CPOSTSHADER_SSAO::aoFF(), CPOSTSHADER_SSAO::giFF(), and CPOSTSHADER_SSAO::Shade().

121 {
122  return m_normals[ getIndex( aPos ) ];
123 }
SFVEC3F * m_normals
Definition: cpostshader.h:113
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
const SFVEC3F & CPOSTSHADER::GetNormalAt ( const SFVEC2I aPos) const
protected

Definition at line 144 of file cpostshader.cpp.

References getIndex(), and m_normals.

145 {
146  return m_normals[ getIndex( aPos ) ];
147 }
SFVEC3F * m_normals
Definition: cpostshader.h:113
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
const SFVEC3F & CPOSTSHADER::GetPositionAt ( const SFVEC2F aPos) const
protected

Definition at line 138 of file cpostshader.cpp.

References getIndex(), and m_wc_hitposition.

Referenced by CPOSTSHADER_SSAO::Shade().

139 {
140  return m_wc_hitposition[ getIndex( aPos ) ];
141 }
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
const SFVEC3F & CPOSTSHADER::GetPositionAt ( const SFVEC2I aPos) const
protected

Definition at line 179 of file cpostshader.cpp.

References getIndex(), and m_wc_hitposition.

180 {
181  return m_wc_hitposition[ getIndex( aPos ) ];
182 }
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
const float & CPOSTSHADER::GetShadowFactorAt ( const SFVEC2I aPos) const
protected

Definition at line 185 of file cpostshader.cpp.

References getIndex(), and m_shadow_att_factor.

Referenced by CPOSTSHADER_SSAO::aoFF().

186 {
187  return m_shadow_att_factor[ getIndex( aPos ) ];
188 }
unsigned int getIndex(const SFVEC2F &aPos) const
Definition: cpostshader.h:86
float * m_shadow_att_factor
Definition: cpostshader.h:117
void CPOSTSHADER::InitFrame ( )
inline

Definition at line 54 of file cpostshader.h.

References m_tmax, and m_tmin.

Referenced by C3D_RENDER_RAYTRACING::restart_render_state().

54 { m_tmin = FLT_MAX; m_tmax = 0.0f; }
float m_tmax
Definition: cpostshader.h:119
float m_tmin
Definition: cpostshader.h:118
void CPOSTSHADER::SetPixelData ( unsigned int  x,
unsigned int  y,
const SFVEC3F aNormal,
const SFVEC3F aColor,
const SFVEC3F aHitPosition,
float  aDepth,
float  aShadowAttFactor 
)

Definition at line 78 of file cpostshader.cpp.

References m_color, m_depth, m_normals, m_shadow_att_factor, m_size, m_tmax, m_tmin, and m_wc_hitposition.

Referenced by C3D_RENDER_RAYTRACING::rt_render_trace_block().

85 {
86  wxASSERT( x < m_size.x );
87  wxASSERT( y < m_size.y );
88  wxASSERT( (aShadowAttFactor >= 0.0f) && (aShadowAttFactor <= 1.0f) );
89 
90  const unsigned int idx = x + y * m_size.x;
91 
92  m_normals[ idx ] = aNormal;
93  m_color [ idx ] = aColor;
94  m_depth [ idx ] = aDepth;
95  m_shadow_att_factor [ idx ] = aShadowAttFactor;
96  m_wc_hitposition[ idx ] = aHitPosition;
97 
98 
99  if( aDepth > FLT_EPSILON )
100  {
101  if( aDepth < m_tmin )
102  m_tmin = aDepth;
103 
104  if( aDepth > m_tmax )
105  m_tmax = aDepth;
106  }
107 }
float m_tmax
Definition: cpostshader.h:119
SFVEC2UI m_size
Definition: cpostshader.h:112
SFVEC3F * m_normals
Definition: cpostshader.h:113
float * m_depth
Definition: cpostshader.h:116
SFVEC3F * m_color
Definition: cpostshader.h:114
float m_tmin
Definition: cpostshader.h:118
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
float * m_shadow_att_factor
Definition: cpostshader.h:117
virtual SFVEC3F CPOSTSHADER::Shade ( const SFVEC2I aShaderPos) const
pure virtual

Implemented in CPOSTSHADER_SSAO.

void CPOSTSHADER::UpdateSize ( const SFVEC2UI aSize)

Definition at line 72 of file cpostshader.cpp.

Referenced by C3D_RENDER_RAYTRACING::initialize_block_positions().

73 {
74  UpdateSize( aSize.x, aSize.y );
75 }
void UpdateSize(const SFVEC2UI &aSize)
Definition: cpostshader.cpp:72
void CPOSTSHADER::UpdateSize ( unsigned int  xSize,
unsigned int  ySize 
)

Definition at line 55 of file cpostshader.cpp.

References destroy_buffers(), m_color, m_depth, m_normals, m_shadow_att_factor, m_size, and m_wc_hitposition.

56 {
58 
59  m_size.x = xSize;
60  m_size.y = ySize;
61 
62  const unsigned int n_elements = xSize * ySize;
63 
64  m_normals = new SFVEC3F[n_elements];
65  m_color = new SFVEC3F[n_elements];
66  m_depth = new float[n_elements];
67  m_wc_hitposition = new SFVEC3F[n_elements];
68  m_shadow_att_factor = new float[n_elements];
69 }
SFVEC2UI m_size
Definition: cpostshader.h:112
SFVEC3F * m_normals
Definition: cpostshader.h:113
void destroy_buffers()
float * m_depth
Definition: cpostshader.h:116
SFVEC3F * m_color
Definition: cpostshader.h:114
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC3F * m_wc_hitposition
Definition: cpostshader.h:115
float * m_shadow_att_factor
Definition: cpostshader.h:117

Member Data Documentation

const CCAMERA& CPOSTSHADER::m_camera
protected

Definition at line 110 of file cpostshader.h.

SFVEC3F* CPOSTSHADER::m_color
protected
float* CPOSTSHADER::m_depth
protected
SFVEC3F* CPOSTSHADER::m_normals
protected
float* CPOSTSHADER::m_shadow_att_factor
protected
SFVEC2UI CPOSTSHADER::m_size
protected
float CPOSTSHADER::m_tmax
protected
float CPOSTSHADER::m_tmin
protected

Definition at line 118 of file cpostshader.h.

Referenced by CPOSTSHADER(), GetDepthNormalizedAt(), InitFrame(), and SetPixelData().

SFVEC3F* CPOSTSHADER::m_wc_hitposition
protected

Definition at line 115 of file cpostshader.h.

Referenced by CPOSTSHADER(), destroy_buffers(), GetPositionAt(), SetPixelData(), and UpdateSize().


The documentation for this class was generated from the following files: