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
45 virtual SFVEC4F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC4F& aInputColor,
46 const SFVEC3F& aShadeColor ) const = 0;
47
48 void UpdateSize( const SFVEC2UI& aSize );
49
50 void UpdateSize( unsigned int xSize, unsigned int ySize );
51
52 void InitFrame() { m_tmin = FLT_MAX; m_tmax = 0.0f; }
53
54 void SetPixelData( unsigned int x, unsigned int y, const SFVEC3F& aNormal,
55 const SFVEC4F& aColor, const SFVEC3F& aHitPosition,
56 float aDepth, float aShadowAttFactor );
57
58 const SFVEC4F& GetColorAtNotProtected( const SFVEC2I& aPos ) const;
59
60 void DebugBuffersOutputAsImages() const;
61
62 inline unsigned int GetIndex( const SFVEC2F& aPos ) const
63 {
64 SFVEC2F clampPos;
65
66 clampPos.x = glm::clamp( aPos.x, 0.0f, 1.0f );
67 clampPos.y = glm::clamp( aPos.y, 0.0f, 1.0f );
68
69 const unsigned int idx = (unsigned int)( (float)m_size.x * clampPos.x +
70 (float)m_size.x * (float)m_size.y *
71 clampPos.y );
72
73 return glm::min( idx, m_size.x * m_size.y );
74 }
75
76 inline unsigned int GetIndex( const SFVEC2I& aPos ) const
77 {
78 SFVEC2I clampPos;
79 clampPos.x = glm::clamp( aPos.x, 0, (int)m_size.x - 1 );
80 clampPos.y = glm::clamp( aPos.y, 0, (int)m_size.y - 1 );
81
82 return (unsigned int)( clampPos.x + m_size.x * clampPos.y );
83 }
84
85protected:
86 const SFVEC3F& GetNormalAt( const SFVEC2F& aPos ) const;
87 const SFVEC4F& GetColorAt( const SFVEC2F& aPos ) const;
88 const SFVEC3F& GetPositionAt( const SFVEC2F& aPos ) const;
89 float GetDepthAt( const SFVEC2F& aPos ) const;
90
91 const SFVEC3F& GetNormalAt( const SFVEC2I& aPos ) const;
92 const SFVEC4F& GetColorAt( const SFVEC2I& aPos ) const;
93 const SFVEC3F& GetPositionAt( const SFVEC2I& aPos ) const;
94 const float& GetShadowFactorAt( const SFVEC2I& aPos ) const;
95
96 float GetDepthAt( const SFVEC2I& aPos ) const;
97 float GetDepthNormalizedAt( const SFVEC2I& aPos ) const;
98 float GetMaxDepth() const { return m_tmax; }
99
100private:
101 void destroy_buffers();
102
103protected:
105
110 float* m_depth;
112 float m_tmin;
113 float m_tmax;
114};
115
116
117#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:62
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
Definition post_shader.h:98
const SFVEC3F & GetPositionAt(const SFVEC2F &aPos) const
SFVEC3F * m_wc_hitposition
void InitFrame()
Definition post_shader.h:52
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:76
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