2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2020-12-13 23:02:57 +00:00
|
|
|
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file post_shader.h
|
|
|
|
* @brief A base class to create post shaders.
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#ifndef POST_SHADER_H
|
|
|
|
#define POST_SHADER_H
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-09-23 23:39:12 +00:00
|
|
|
#include <gal/3d/camera.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
class POST_SHADER
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-02 21:05:29 +00:00
|
|
|
explicit POST_SHADER( const CAMERA& aCamera );
|
|
|
|
virtual ~POST_SHADER();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual SFVEC3F Shade( const SFVEC2I& aShaderPos ) const = 0;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
/**
|
2020-12-13 23:02:57 +00:00
|
|
|
* Apply the final color process using a previous stage color.
|
|
|
|
*
|
|
|
|
* @param aShadeColor The result of the shader.
|
2016-11-26 14:38:51 +00:00
|
|
|
* @return the result of the shade process
|
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual SFVEC3F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
|
|
|
|
const SFVEC3F& aShadeColor ) const = 0;
|
2016-11-26 14:38:51 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void UpdateSize( const SFVEC2UI& aSize );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
void UpdateSize( unsigned int xSize, unsigned int ySize );
|
|
|
|
|
|
|
|
void InitFrame() { m_tmin = FLT_MAX; m_tmax = 0.0f; }
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void SetPixelData( unsigned int x, unsigned int y, const SFVEC3F& aNormal,
|
|
|
|
const SFVEC3F& aColor, const SFVEC3F& aHitPosition,
|
2020-12-13 23:02:57 +00:00
|
|
|
float aDepth, float aShadowAttFactor );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const SFVEC3F& GetColorAtNotProtected( const SFVEC2I& aPos ) const;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
void DebugBuffersOutputAsImages() const;
|
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
inline unsigned int GetIndex( const SFVEC2F& aPos ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
SFVEC2F clampPos;
|
|
|
|
|
|
|
|
clampPos.x = glm::clamp( aPos.x, 0.0f, 1.0f );
|
|
|
|
clampPos.y = glm::clamp( aPos.y, 0.0f, 1.0f );
|
|
|
|
|
|
|
|
const unsigned int idx = (unsigned int)( (float)m_size.x * clampPos.x +
|
|
|
|
(float)m_size.x * (float)m_size.y *
|
|
|
|
clampPos.y );
|
|
|
|
|
|
|
|
return glm::min( idx, m_size.x * m_size.y );
|
|
|
|
}
|
|
|
|
|
2020-07-14 16:40:28 +00:00
|
|
|
inline unsigned int GetIndex( const SFVEC2I& aPos ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
SFVEC2I clampPos;
|
|
|
|
clampPos.x = glm::clamp( aPos.x, 0, (int)m_size.x - 1 );
|
|
|
|
clampPos.y = glm::clamp( aPos.y, 0, (int)m_size.y - 1 );
|
|
|
|
|
|
|
|
return (unsigned int)( clampPos.x + m_size.x * clampPos.y );
|
|
|
|
}
|
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
protected:
|
2021-01-02 21:05:29 +00:00
|
|
|
const SFVEC3F& GetNormalAt( const SFVEC2F& aPos ) const;
|
|
|
|
const SFVEC3F& GetColorAt( const SFVEC2F& aPos ) const;
|
|
|
|
const SFVEC3F& GetPositionAt( const SFVEC2F& aPos ) const;
|
|
|
|
float GetDepthAt( const SFVEC2F& aPos ) const;
|
|
|
|
|
|
|
|
const SFVEC3F& GetNormalAt( const SFVEC2I& aPos ) const;
|
|
|
|
const SFVEC3F& GetColorAt( const SFVEC2I& aPos ) const;
|
|
|
|
const SFVEC3F& GetPositionAt( const SFVEC2I& aPos ) const;
|
|
|
|
const float& GetShadowFactorAt( const SFVEC2I& aPos ) const;
|
|
|
|
|
|
|
|
float GetDepthAt( const SFVEC2I& aPos ) const;
|
|
|
|
float GetDepthNormalizedAt( const SFVEC2I& aPos ) const;
|
2020-12-13 23:02:57 +00:00
|
|
|
float GetMaxDepth() const { return m_tmax; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void destroy_buffers();
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
protected:
|
2021-01-02 21:05:29 +00:00
|
|
|
const CAMERA& m_camera;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
SFVEC2UI m_size;
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F* m_normals;
|
|
|
|
SFVEC3F* m_color;
|
|
|
|
SFVEC3F* m_wc_hitposition;
|
|
|
|
float* m_depth;
|
|
|
|
float* m_shadow_att_factor;
|
|
|
|
float m_tmin;
|
|
|
|
float m_tmax;
|
2016-07-19 17:35:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#endif // POST_SHADER_H
|