2026-05-10 14:57:16 -07:00
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 10:00:33 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 10:00:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#ifndef INCLUDED_MATERIAL
|
|
|
|
|
#define INCLUDED_MATERIAL
|
2004-09-22 21:00:56 -07:00
|
|
|
|
2012-04-03 11:44:46 -07:00
|
|
|
#include "graphics/ShaderDefines.h"
|
|
|
|
|
#include "graphics/Texture.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "ps/CStr.h"
|
2012-04-03 11:44:46 -07:00
|
|
|
#include "ps/CStrIntern.h"
|
2025-07-16 11:25:46 -07:00
|
|
|
|
2026-05-10 14:57:16 -07:00
|
|
|
#include <array>
|
2025-07-16 11:25:46 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
class CVector4D;
|
2011-03-18 09:57:54 -07:00
|
|
|
|
2004-09-22 21:00:56 -07:00
|
|
|
class CMaterial
|
|
|
|
|
{
|
|
|
|
|
public:
|
2026-05-10 14:57:16 -07:00
|
|
|
enum class Pass : uint8_t
|
|
|
|
|
{
|
|
|
|
|
MAIN,
|
|
|
|
|
SHADOW_CASTER,
|
|
|
|
|
REFLECTIONS,
|
|
|
|
|
REFRACTIONS,
|
|
|
|
|
SILHOUETTE_OCCLUDER,
|
|
|
|
|
SILHOUETTE_CASTER,
|
|
|
|
|
WIREFRAME,
|
|
|
|
|
WIREFRAME_SOLID,
|
|
|
|
|
COUNT
|
|
|
|
|
};
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2012-07-23 15:49:46 -07:00
|
|
|
struct TextureSampler
|
|
|
|
|
{
|
2015-03-15 04:37:26 -07:00
|
|
|
TextureSampler(const CStr &n, CTexturePtr t) : Name(n), Sampler(t) {}
|
|
|
|
|
TextureSampler(const CStrIntern &n, CTexturePtr t) : Name(n), Sampler(t) {}
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2012-07-23 15:49:46 -07:00
|
|
|
CStrIntern Name;
|
|
|
|
|
CTexturePtr Sampler;
|
|
|
|
|
};
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2012-07-23 15:49:46 -07:00
|
|
|
typedef std::vector<TextureSampler> SamplersVector;
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2004-09-22 21:00:56 -07:00
|
|
|
CMaterial();
|
|
|
|
|
|
2012-04-03 11:44:46 -07:00
|
|
|
// Whether this material's shaders use alpha blending, in which case
|
|
|
|
|
// models using this material need to be rendered in a special order
|
|
|
|
|
// relative to the alpha-blended water plane
|
|
|
|
|
void SetUsesAlphaBlending(bool flag) { m_AlphaBlending = flag; }
|
2020-01-26 13:32:12 -08:00
|
|
|
bool UsesAlphaBlending() const { return m_AlphaBlending; }
|
2004-09-22 21:00:56 -07:00
|
|
|
|
2012-04-03 11:44:46 -07:00
|
|
|
const CTexturePtr& GetDiffuseTexture() const { return m_DiffuseTexture; }
|
2005-04-06 21:29:07 -07:00
|
|
|
|
2026-05-10 14:57:16 -07:00
|
|
|
void SetShaderEffect(const Pass pass, CStrIntern effect);
|
|
|
|
|
CStrIntern GetShaderEffect(const Pass pass) const;
|
2011-03-18 09:57:54 -07:00
|
|
|
|
2013-09-29 07:02:47 -07:00
|
|
|
// Must call RecomputeCombinedShaderDefines after this, before rendering with this material
|
2013-09-29 06:19:52 -07:00
|
|
|
void AddShaderDefine(CStrIntern key, CStrIntern value);
|
2013-09-28 17:30:58 -07:00
|
|
|
|
2022-03-15 15:13:22 -07:00
|
|
|
const CShaderDefines& GetShaderDefines() const { return m_ShaderDefines; }
|
2005-04-06 21:29:07 -07:00
|
|
|
|
2012-04-08 08:55:06 -07:00
|
|
|
void AddStaticUniform(const char* key, const CVector4D& value);
|
|
|
|
|
const CShaderUniforms& GetStaticUniforms() const { return m_StaticUniforms; }
|
|
|
|
|
|
2012-07-23 15:49:46 -07:00
|
|
|
void AddSampler(const TextureSampler& texture);
|
|
|
|
|
const SamplersVector& GetSamplers() const { return m_Samplers; }
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2012-08-06 12:10:47 -07:00
|
|
|
void AddRenderQuery(const char* key);
|
|
|
|
|
const CShaderRenderQueries& GetRenderQueries() const { return m_RenderQueries; }
|
2012-07-23 15:49:46 -07:00
|
|
|
|
2015-03-15 04:37:26 -07:00
|
|
|
void AddRequiredSampler(const CStr& samplerName);
|
|
|
|
|
const std::vector<CStrIntern>& GetRequiredSampler() const { return m_RequiredSamplers; }
|
|
|
|
|
|
2011-03-18 09:57:54 -07:00
|
|
|
private:
|
2016-11-23 03:18:37 -08:00
|
|
|
|
|
|
|
|
// This pointer is kept to make it easier for the fixed pipeline to
|
2012-07-23 15:49:46 -07:00
|
|
|
// access the only texture it's interested in.
|
2012-04-03 11:44:46 -07:00
|
|
|
CTexturePtr m_DiffuseTexture;
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2012-07-23 15:49:46 -07:00
|
|
|
SamplersVector m_Samplers;
|
2015-03-15 04:37:26 -07:00
|
|
|
std::vector<CStrIntern> m_RequiredSamplers;
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2026-05-10 14:57:16 -07:00
|
|
|
std::array<CStrIntern, static_cast<size_t>(Pass::COUNT)> m_ShaderEffects;
|
2012-04-03 11:44:46 -07:00
|
|
|
CShaderDefines m_ShaderDefines;
|
2012-04-08 08:55:06 -07:00
|
|
|
CShaderUniforms m_StaticUniforms;
|
2012-08-06 12:10:47 -07:00
|
|
|
CShaderRenderQueries m_RenderQueries;
|
2004-09-22 21:00:56 -07:00
|
|
|
|
2012-04-03 11:44:46 -07:00
|
|
|
bool m_AlphaBlending;
|
2004-09-22 21:00:56 -07:00
|
|
|
};
|
|
|
|
|
|
2022-03-15 15:13:22 -07:00
|
|
|
#endif // INCLUDED_MATERIAL
|