KiCad PCB EDA Suite
POST_SHADER Class Referenceabstract

#include <post_shader.h>

Inheritance diagram for POST_SHADER:
POST_SHADER_SSAO

Public Member Functions

 POST_SHADER (const CAMERA &aCamera)
 
virtual ~POST_SHADER ()
 
virtual SFVEC3F Shade (const SFVEC2I &aShaderPos) const =0
 
virtual SFVEC3F ApplyShadeColor (const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, const SFVEC3F &aShadeColor) const =0
 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
 
unsigned int GetIndex (const SFVEC2F &aPos) const
 
unsigned int GetIndex (const SFVEC2I &aPos) 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 CAMERAm_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 ()
 

Detailed Description

Definition at line 35 of file post_shader.h.

Constructor & Destructor Documentation

◆ POST_SHADER()

POST_SHADER::POST_SHADER ( const CAMERA aCamera)
explicit

Definition at line 36 of file post_shader.cpp.

36  :
37  m_camera( aCamera )
38 {
39  m_size = SFVEC2UI( 0, 0 );
40  m_normals = nullptr;
41  m_color = nullptr;
42  m_depth = nullptr;
43  m_wc_hitposition = nullptr;
44  m_shadow_att_factor = nullptr;
45  m_tmin = FLT_MAX;
46  m_tmax = FLT_MIN;
47 }
float * m_depth
Definition: post_shader.h:114
glm::uvec2 SFVEC2UI
Definition: xv3d_types.h:38
SFVEC3F * m_wc_hitposition
Definition: post_shader.h:113
float m_tmin
Definition: post_shader.h:116
SFVEC3F * m_normals
Definition: post_shader.h:111
float * m_shadow_att_factor
Definition: post_shader.h:115
SFVEC3F * m_color
Definition: post_shader.h:112
SFVEC2UI m_size
Definition: post_shader.h:110
float m_tmax
Definition: post_shader.h:117
const CAMERA & m_camera
Definition: post_shader.h:108

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

◆ ~POST_SHADER()

POST_SHADER::~POST_SHADER ( )
virtual

Definition at line 50 of file post_shader.cpp.

51 {
53 }
void destroy_buffers()

References destroy_buffers().

Member Function Documentation

◆ ApplyShadeColor()

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

Apply the final color process using a previous stage color.

Parameters
aShadeColorThe result of the shader.
Returns
the result of the shade process

Implemented in POST_SHADER_SSAO.

◆ DebugBuffersOutputAsImages()

void POST_SHADER::DebugBuffersOutputAsImages ( ) const

Definition at line 193 of file post_shader.cpp.

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

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

◆ destroy_buffers()

void POST_SHADER::destroy_buffers ( )
private

Definition at line 107 of file post_shader.cpp.

108 {
109  delete[] m_normals;
110  m_normals = nullptr;
111  delete[] m_color;
112  m_color = nullptr;
113  delete[] m_depth;
114  m_depth = nullptr;
115  delete[] m_shadow_att_factor;
116  m_shadow_att_factor = nullptr;
117  delete[] m_wc_hitposition;
118  m_wc_hitposition = nullptr;
119 }
float * m_depth
Definition: post_shader.h:114
SFVEC3F * m_wc_hitposition
Definition: post_shader.h:113
SFVEC3F * m_normals
Definition: post_shader.h:111
float * m_shadow_att_factor
Definition: post_shader.h:115
SFVEC3F * m_color
Definition: post_shader.h:112

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

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

◆ GetColorAt() [1/2]

const SFVEC3F & POST_SHADER::GetColorAt ( const SFVEC2F aPos) const
protected

Definition at line 128 of file post_shader.cpp.

129 {
130  return m_color[GetIndex( aPos )];
131 }
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
SFVEC3F * m_color
Definition: post_shader.h:112

References GetIndex(), and m_color.

Referenced by POST_SHADER_SSAO::Shade().

◆ GetColorAt() [2/2]

const SFVEC3F & POST_SHADER::GetColorAt ( const SFVEC2I aPos) const
protected

Definition at line 152 of file post_shader.cpp.

153 {
154  return m_color[GetIndex( aPos )];
155 }
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
SFVEC3F * m_color
Definition: post_shader.h:112

References GetIndex(), and m_color.

◆ GetColorAtNotProtected()

const SFVEC3F & POST_SHADER::GetColorAtNotProtected ( const SFVEC2I aPos) const

Definition at line 158 of file post_shader.cpp.

159 {
160  return m_color[ aPos.x + m_size.x * aPos.y ];
161 }
SFVEC3F * m_color
Definition: post_shader.h:112
SFVEC2UI m_size
Definition: post_shader.h:110

References m_color, and m_size.

Referenced by RENDER_3D_RAYTRACE::postProcessBlurFinish().

◆ GetDepthAt() [1/2]

float POST_SHADER::GetDepthAt ( const SFVEC2F aPos) const
protected

Definition at line 134 of file post_shader.cpp.

135 {
136  return m_depth[GetIndex( aPos )];
137 }
float * m_depth
Definition: post_shader.h:114
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66

References GetIndex(), and m_depth.

Referenced by POST_SHADER_SSAO::Blur(), and POST_SHADER_SSAO::Shade().

◆ GetDepthAt() [2/2]

float POST_SHADER::GetDepthAt ( const SFVEC2I aPos) const
protected

Definition at line 164 of file post_shader.cpp.

165 {
166  return m_depth[GetIndex( aPos )];
167 }
float * m_depth
Definition: post_shader.h:114
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66

References GetIndex(), and m_depth.

◆ GetDepthNormalizedAt()

float POST_SHADER::GetDepthNormalizedAt ( const SFVEC2I aPos) const
protected

Definition at line 170 of file post_shader.cpp.

171 {
172  const float depth = m_depth[GetIndex( aPos )];
173 
174  if( depth >= m_tmin )
175  return (depth - m_tmin) / (m_tmax - m_tmin);
176 
177  return 0.0f;
178 }
float * m_depth
Definition: post_shader.h:114
float m_tmin
Definition: post_shader.h:116
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
float m_tmax
Definition: post_shader.h:117

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

Referenced by DebugBuffersOutputAsImages().

◆ GetIndex() [1/2]

unsigned int POST_SHADER::GetIndex ( const SFVEC2F aPos) const
inline

Definition at line 66 of file post_shader.h.

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  }
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
SFVEC2UI m_size
Definition: post_shader.h:110

References m_size.

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

◆ GetIndex() [2/2]

unsigned int POST_SHADER::GetIndex ( const SFVEC2I aPos) const
inline

Definition at line 80 of file post_shader.h.

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  }
glm::ivec2 SFVEC2I
Definition: xv3d_types.h:39
SFVEC2UI m_size
Definition: post_shader.h:110

References m_size.

◆ GetMaxDepth()

float POST_SHADER::GetMaxDepth ( ) const
inlineprotected

Definition at line 102 of file post_shader.h.

102 { return m_tmax; }
float m_tmax
Definition: post_shader.h:117

References m_tmax.

◆ GetNormalAt() [1/2]

const SFVEC3F & POST_SHADER::GetNormalAt ( const SFVEC2F aPos) const
protected

Definition at line 122 of file post_shader.cpp.

123 {
124  return m_normals[GetIndex( aPos )];
125 }
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
SFVEC3F * m_normals
Definition: post_shader.h:111

References GetIndex(), and m_normals.

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

◆ GetNormalAt() [2/2]

const SFVEC3F & POST_SHADER::GetNormalAt ( const SFVEC2I aPos) const
protected

Definition at line 146 of file post_shader.cpp.

147 {
148  return m_normals[GetIndex( aPos )];
149 }
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
SFVEC3F * m_normals
Definition: post_shader.h:111

References GetIndex(), and m_normals.

◆ GetPositionAt() [1/2]

const SFVEC3F & POST_SHADER::GetPositionAt ( const SFVEC2F aPos) const
protected

Definition at line 140 of file post_shader.cpp.

141 {
142  return m_wc_hitposition[GetIndex( aPos )];
143 }
SFVEC3F * m_wc_hitposition
Definition: post_shader.h:113
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66

References GetIndex(), and m_wc_hitposition.

Referenced by POST_SHADER_SSAO::Shade().

◆ GetPositionAt() [2/2]

const SFVEC3F & POST_SHADER::GetPositionAt ( const SFVEC2I aPos) const
protected

Definition at line 181 of file post_shader.cpp.

182 {
183  return m_wc_hitposition[GetIndex( aPos )];
184 }
SFVEC3F * m_wc_hitposition
Definition: post_shader.h:113
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66

References GetIndex(), and m_wc_hitposition.

◆ GetShadowFactorAt()

const float & POST_SHADER::GetShadowFactorAt ( const SFVEC2I aPos) const
protected

Definition at line 187 of file post_shader.cpp.

188 {
189  return m_shadow_att_factor[GetIndex( aPos )];
190 }
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition: post_shader.h:66
float * m_shadow_att_factor
Definition: post_shader.h:115

References GetIndex(), and m_shadow_att_factor.

Referenced by POST_SHADER_SSAO::Shade().

◆ InitFrame()

void POST_SHADER::InitFrame ( )
inline

Definition at line 56 of file post_shader.h.

56 { m_tmin = FLT_MAX; m_tmax = 0.0f; }
float m_tmin
Definition: post_shader.h:116
float m_tmax
Definition: post_shader.h:117

References m_tmax, and m_tmin.

Referenced by RENDER_3D_RAYTRACE::restartRenderState().

◆ SetPixelData()

void POST_SHADER::SetPixelData ( unsigned int  x,
unsigned int  y,
const SFVEC3F aNormal,
const SFVEC3F aColor,
const SFVEC3F aHitPosition,
float  aDepth,
float  aShadowAttFactor 
)

Definition at line 79 of file post_shader.cpp.

82 {
83  wxASSERT( x < m_size.x );
84  wxASSERT( y < m_size.y );
85  wxASSERT( ( aShadowAttFactor >= 0.0f ) && ( aShadowAttFactor <= 1.0f ) );
86 
87  const unsigned int idx = x + y * m_size.x;
88 
89  m_normals[ idx ] = aNormal;
90  m_color [ idx ] = aColor;
91  m_depth [ idx ] = aDepth;
92  m_shadow_att_factor [ idx ] = aShadowAttFactor;
93  m_wc_hitposition[ idx ] = aHitPosition;
94 
95 
96  if( aDepth > FLT_EPSILON )
97  {
98  if( aDepth < m_tmin )
99  m_tmin = aDepth;
100 
101  if( aDepth > m_tmax )
102  m_tmax = aDepth;
103  }
104 }
float * m_depth
Definition: post_shader.h:114
SFVEC3F * m_wc_hitposition
Definition: post_shader.h:113
float m_tmin
Definition: post_shader.h:116
SFVEC3F * m_normals
Definition: post_shader.h:111
float * m_shadow_att_factor
Definition: post_shader.h:115
SFVEC3F * m_color
Definition: post_shader.h:112
SFVEC2UI m_size
Definition: post_shader.h:110
float m_tmax
Definition: post_shader.h:117

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

Referenced by RENDER_3D_RAYTRACE::renderBlockTracing().

◆ Shade()

virtual SFVEC3F POST_SHADER::Shade ( const SFVEC2I aShaderPos) const
pure virtual

Implemented in POST_SHADER_SSAO.

◆ UpdateSize() [1/2]

void POST_SHADER::UpdateSize ( const SFVEC2UI aSize)

Definition at line 73 of file post_shader.cpp.

74 {
75  UpdateSize( aSize.x, aSize.y );
76 }
void UpdateSize(const SFVEC2UI &aSize)
Definition: post_shader.cpp:73

Referenced by RENDER_3D_RAYTRACE::initializeBlockPositions().

◆ UpdateSize() [2/2]

void POST_SHADER::UpdateSize ( unsigned int  xSize,
unsigned int  ySize 
)

Definition at line 56 of file post_shader.cpp.

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

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

Member Data Documentation

◆ m_camera

const CAMERA& POST_SHADER::m_camera
protected

Definition at line 108 of file post_shader.h.

◆ m_color

SFVEC3F* POST_SHADER::m_color
protected

◆ m_depth

float* POST_SHADER::m_depth
protected

◆ m_normals

SFVEC3F* POST_SHADER::m_normals
protected

◆ m_shadow_att_factor

float* POST_SHADER::m_shadow_att_factor
protected

◆ m_size

SFVEC2UI POST_SHADER::m_size
protected

◆ m_tmax

float POST_SHADER::m_tmax
protected

◆ m_tmin

float POST_SHADER::m_tmin
protected

Definition at line 116 of file post_shader.h.

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

◆ m_wc_hitposition

SFVEC3F* POST_SHADER::m_wc_hitposition
protected

Definition at line 113 of file post_shader.h.

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


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