1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details 2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt 3 4 #ifndef _MATERIAL_H 5 #define _MATERIAL_H 6 /* 7 * Materials are used to apply an appropriate shader and other rendering parameters. 8 * Users request materials from the renderer by filling a MaterialDescriptor structure, 9 * and calling Renderer::CreateMaterial. 10 * Users are responsible for deleting a material they have requested. This is because materials 11 * are rarely shareable. 12 * Material::Apply is called by renderer before drawing, and Unapply after drawing (to restore state). 13 * For the OGL renderer, a Material is always accompanied by a Program. 14 */ 15 #include "Color.h" 16 #include "matrix4x4.h" 17 #include "RefCounted.h" 18 19 namespace Graphics { 20 21 class Texture; 22 class RendererOGL; 23 24 // Shorthand for unique effects 25 // The other descriptor parameters may or may not have effect, 26 // depends on the effect 27 enum EffectType { 28 EFFECT_DEFAULT, 29 EFFECT_VTXCOLOR, 30 EFFECT_UI, 31 EFFECT_STARFIELD, 32 EFFECT_PLANETRING, 33 EFFECT_GEOSPHERE_TERRAIN, 34 EFFECT_GEOSPHERE_TERRAIN_WITH_LAVA, 35 EFFECT_GEOSPHERE_TERRAIN_WITH_WATER, 36 EFFECT_GEOSPHERE_SKY, 37 EFFECT_GEOSPHERE_STAR, 38 EFFECT_GASSPHERE_TERRAIN, 39 EFFECT_FRESNEL_SPHERE, 40 EFFECT_SHIELD, 41 EFFECT_SKYBOX, 42 EFFECT_SPHEREIMPOSTOR, 43 EFFECT_GEN_GASGIANT_TEXTURE, 44 EFFECT_BILLBOARD_ATLAS, 45 EFFECT_BILLBOARD 46 }; 47 48 // XXX : there must be a better place to put this 49 enum MaterialQuality { 50 HAS_ATMOSPHERE = 1 << 0, 51 HAS_ECLIPSES = 1 << 1, 52 HAS_HEAT_GRADIENT = 1 << 2 53 }; 54 55 // Renderer creates a material that best matches these requirements. 56 // EffectType may override some of the other flags. 57 class MaterialDescriptor { 58 public: 59 MaterialDescriptor(); 60 EffectType effect; 61 bool alphaTest; 62 bool glowMap; 63 bool ambientMap; 64 bool lighting; 65 bool normalMap; 66 bool specularMap; 67 bool usePatterns; //pattern/color system 68 bool vertexColors; 69 bool instanced; 70 Sint32 textures; //texture count 71 Uint32 dirLights; //set by RendererOGL if lighting == true 72 Uint32 quality; // see: Graphics::MaterialQuality 73 Uint32 numShadows; //use by GeoSphere/GasGiant for eclipse 74 75 friend bool operator==(const MaterialDescriptor &a, const MaterialDescriptor &b); 76 }; 77 78 /* 79 * A generic material with some generic parameters. 80 */ 81 class Material : public RefCounted { 82 public: 83 Material(); ~Material()84 virtual ~Material() {} 85 86 Texture *texture0; 87 Texture *texture1; 88 Texture *texture2; 89 Texture *texture3; 90 Texture *texture4; 91 Texture *texture5; 92 Texture *texture6; 93 Texture *heatGradient; 94 95 Color diffuse; 96 Color specular; 97 Color emissive; 98 int shininess; //specular power 0-128 99 Apply()100 virtual void Apply() {} Unapply()101 virtual void Unapply() {} 102 virtual bool IsProgramLoaded() const = 0; 103 104 virtual void SetCommonUniforms(const matrix4x4f &mv, const matrix4x4f &proj) = 0; 105 106 void *specialParameter0; //this can be whatever. Bit of a hack. 107 108 //XXX may not be necessary. Used by newmodel to check if a material uses patterns GetDescriptor()109 const MaterialDescriptor &GetDescriptor() const { return m_descriptor; } 110 111 protected: 112 MaterialDescriptor m_descriptor; 113 114 private: 115 friend class RendererOGL; 116 }; 117 118 } // namespace Graphics 119 120 #endif 121