KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#ifndef POST_SHADER_H
27#define POST_SHADER_H
28
29#include <gal/3d/camera.h>
30
32{
33public:
34 explicit POST_SHADER( const CAMERA& aCamera );
35 virtual ~POST_SHADER();
36
37 virtual SFVEC3F Shade( const SFVEC2I& aShaderPos ) const = 0;
38
47 virtual SFVEC4F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC4F& aInputColor,
48 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, unsigned int y, const SFVEC3F& aNormal,
57 const SFVEC4F& aColor, const SFVEC3F& aHitPosition,
58 float aDepth, float aShadowAttFactor );
59
60 const SFVEC4F& GetColorAtNotProtected( const SFVEC2I& aPos ) const;
61
62 void DebugBuffersOutputAsImages() const;
63
64 inline unsigned int GetIndex( const SFVEC2F& aPos ) const
65 {
66 SFVEC2F clampPos;
67
68 clampPos.x = glm::clamp( aPos.x, 0.0f, 1.0f );
69 clampPos.y = glm::clamp( aPos.y, 0.0f, 1.0f );
70
71 const unsigned int idx = (unsigned int)( (float)m_size.x * clampPos.x +
72 (float)m_size.x * (float)m_size.y *
73 clampPos.y );
74
75 return glm::min( idx, m_size.x * m_size.y );
76 }
77
78 inline unsigned int GetIndex( const SFVEC2I& aPos ) const
79 {
80 SFVEC2I clampPos;
81 clampPos.x = glm::clamp( aPos.x, 0, (int)m_size.x - 1 );
82 clampPos.y = glm::clamp( aPos.y, 0, (int)m_size.y - 1 );
83
84 return (unsigned int)( clampPos.x + m_size.x * clampPos.y );
85 }
86
87protected:
88 const SFVEC3F& GetNormalAt( const SFVEC2F& aPos ) const;
89 const SFVEC4F& GetColorAt( const SFVEC2F& aPos ) const;
90 const SFVEC3F& GetPositionAt( const SFVEC2F& aPos ) const;
91 float GetDepthAt( const SFVEC2F& aPos ) const;
92
93 const SFVEC3F& GetNormalAt( const SFVEC2I& aPos ) const;
94 const SFVEC4F& GetColorAt( const SFVEC2I& aPos ) const;
95 const SFVEC3F& GetPositionAt( const SFVEC2I& aPos ) const;
96 const float& GetShadowFactorAt( const SFVEC2I& aPos ) const;
97
98 float GetDepthAt( const SFVEC2I& aPos ) const;
99 float GetDepthNormalizedAt( const SFVEC2I& aPos ) const;
100 float GetMaxDepth() const { return m_tmax; }
101
102private:
103 void destroy_buffers();
104
105protected:
107
112 float* m_depth;
114 float m_tmin;
115 float m_tmax;
116};
117
118
119#endif // POST_SHADER_H
Define an abstract camera.
A class used to derive camera objects from.
Definition camera.h:99
float * m_depth
unsigned int GetIndex(const SFVEC2F &aPos) const
Definition post_shader.h:64
SFVEC3F * m_normals
const SFVEC4F & GetColorAtNotProtected(const SFVEC2I &aPos) const
POST_SHADER(const CAMERA &aCamera)
void SetPixelData(unsigned int x, unsigned int y, const SFVEC3F &aNormal, const SFVEC4F &aColor, const SFVEC3F &aHitPosition, float aDepth, float aShadowAttFactor)
const CAMERA & m_camera
SFVEC4F * m_color
void DebugBuffersOutputAsImages() const
const SFVEC4F & GetColorAt(const SFVEC2F &aPos) const
float GetDepthNormalizedAt(const SFVEC2I &aPos) const
void UpdateSize(const SFVEC2UI &aSize)
virtual SFVEC4F ApplyShadeColor(const SFVEC2I &aShaderPos, const SFVEC4F &aInputColor, const SFVEC3F &aShadeColor) const =0
Apply the final color process using a previous stage color.
const SFVEC3F & GetNormalAt(const SFVEC2F &aPos) const
virtual SFVEC3F Shade(const SFVEC2I &aShaderPos) const =0
float GetMaxDepth() const
const SFVEC3F & GetPositionAt(const SFVEC2F &aPos) const
SFVEC3F * m_wc_hitposition
void InitFrame()
Definition post_shader.h:54
SFVEC2UI m_size
void destroy_buffers()
virtual ~POST_SHADER()
const float & GetShadowFactorAt(const SFVEC2I &aPos) const
float GetDepthAt(const SFVEC2F &aPos) const
unsigned int GetIndex(const SFVEC2I &aPos) const
Definition post_shader.h:78
float * m_shadow_att_factor
glm::ivec2 SFVEC2I
Definition xv3d_types.h:35
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40
glm::uvec2 SFVEC2UI
Definition xv3d_types.h:34
glm::vec4 SFVEC4F
Definition xv3d_types.h:42