21 #ifndef _SHADERMANAGER_HPP_
22 #define _SHADERMANAGER_HPP_
24 #include "StelOpenGL.hpp"
25 #include "S3DEnum.hpp"
29 class QOpenGLShaderProgram;
154 typedef QMap<QString,UNIFORM> t_UniformStrings;
155 static t_UniformStrings uniformStrings;
166 PIXEL_LIGHTING = (1<<2),
176 SHADOW_FILTER = (1<<7),
178 SHADOW_FILTER_HQ = (1<<8),
180 MAT_SPECULAR = (1<<9),
182 MAT_DIFFUSETEX = (1<<10),
184 MAT_EMISSIVETEX = (1<<11),
186 GEOMETRY_SHADER = (1<<12),
199 SINGLE_SHADOW_FRUSTUM = (1<<18),
204 typedef QMap<QString,FeatureFlags> t_FeatureFlagStrings;
205 static t_FeatureFlagStrings featureFlagsStrings;
207 QString getVShaderName(uint flags);
208 QString getGShaderName(uint flags);
209 QString getFShaderName(uint flags);
210 QOpenGLShaderProgram* findOrLoadShader(uint flags);
212 bool preprocessShader(
const QString& fileName,
const uint flags, QByteArray& processedSource);
214 bool loadShader(QOpenGLShaderProgram& program,
const QByteArray& vShader,
const QByteArray& gShader,
const QByteArray& fShader);
215 void buildUniformCache(QOpenGLShaderProgram& program);
217 typedef QHash<uint,QOpenGLShaderProgram*> t_ShaderCache;
218 t_ShaderCache m_shaderCache;
220 typedef QHash<QByteArray,QOpenGLShaderProgram*> t_ShaderContentCache;
221 t_ShaderContentCache m_shaderContentCache;
223 typedef QHash<UNIFORM,GLuint> t_UniformCacheEntry;
224 typedef QHash<const QOpenGLShaderProgram*, t_UniformCacheEntry> t_UniformCache;
225 t_UniformCache m_uniformCache;
232 uint flags = INVALID;
233 if(globals.openglES) flags|=OGL_ES2;
234 if(!globals.shadowTransform)
237 if(globals.pixelLighting) flags|= PIXEL_LIGHTING;
238 if(globals.pixelLighting && globals.shadows) flags|= SHADOWS;
239 if(globals.pixelLighting && globals.shadows && globals.shadowFilterQuality>
S3DEnum::SFQ_HARDWARE) flags|= SHADOW_FILTER;
240 if(globals.pixelLighting && globals.shadows && globals.shadowFilterQuality>
S3DEnum::SFQ_LOW_HARDWARE) flags|= SHADOW_FILTER_HQ;
241 if(globals.pixelLighting && globals.shadows && (globals.shadowFilterQuality ==
S3DEnum::SFQ_LOW || globals.shadowFilterQuality ==
S3DEnum::SFQ_HIGH) && globals.pcss) flags|= PCSS;
242 if(globals.geometryShader) flags|= GEOMETRY_SHADER;
243 if(globals.torchLight) flags|= TORCH;
244 if(globals.frustumSplits == 1) flags|= SINGLE_SHADOW_FRUSTUM;
253 if(mat->
alphatest && mat->texture && mat->texture->hasAlphaChannel())
256 flags|= MAT_SPECULAR;
260 flags|= MAT_DIFFUSETEX;
261 if(mat->emissive_texture)
262 flags|= MAT_EMISSIVETEX;
263 if(mat->bump_texture && globals.bump && globals.pixelLighting)
265 if(mat->height_texture && globals.bump && globals.pixelLighting)
269 return findOrLoadShader(flags);
274 return findOrLoadShader(DEBUG);
279 return findOrLoadShader(CUBEMAP);
284 return findOrLoadShader(MAT_DIFFUSETEX);
289 t_UniformCache::iterator it = m_uniformCache.find(shad);
290 if(it!=m_uniformCache.end())
292 return it.value().value(uni,-1);
Material global transparency.
Uses a 16-tap Poisson disk.
Defines the ModelView matrix.
Defines the combined ModelViewProjection matrix, used if shader needs no separation of the 2 for a bi...
Material specular shininess (exponent)
Defines the Projection matrix.
Torch color * mat diffuse.
Torchlight attenuation factor (1 float, like in the second model at http://framebunker.com/blog/lighting-2-attenuation/)
Light specular * Material specular color.
A structure for global shader parameters.
Defines the 3x3 Normal matrix (transpose of the inverse MV matrix)
Defines the Bump texture slot.
QOpenGLShaderProgram * getDebugShader()
Returns the Frustum/Boundingbox Debug shader.
bool hasSpecularity
Quick check if this material has specularity.
Squared frustum splits (vec4)
This is the OpenGL attribute location where vertex normals are mapped to.
UNIFORM
Enum for OpenGL shader uniform locations (faster than accessing by string each time) ...
Defines the Diffuse texture slot.
The first cube MVP (array mat4, total 6)
QOpenGLShaderProgram * getTextureShader()
Returns the basic texturing shader.
(Light ambient + const factor) * Material ambient or diffuse, depending on Illum model ...
Light direction vector (view space)
bool alphatest
If to perform binary alpha testing. Default off.
Defines the Height texture slot.
bool hasTransparency
Quick check if this material has "real" transparency (i.e. needs blending)
Uses a 16-tap Poisson disk + hardware filtering.
QOpenGLShaderProgram * getCubeShader()
Returns the cubemapping shader.
A simple shader cache class that gives us the correct shader depending on desired configuration...
Defines the emissive texture slot.
ShadowFilterQuality
Contains different shadow filter settings.
Uses a 64-tap Poisson disk.
Enables OpenGL hardware shadow filtering.
GLint uniformLocation(const QOpenGLShaderProgram *shad, UNIFORM uni)
Returns the location of this uniform for this shader, or -1 if this uniform does not exist...
This is the OpenGL attribute location where vertex texture coordinates are mapped to...
QOpenGLShaderProgram * getShader(const GlobalShaderParameters &globals, const OBJ::Material *mat=NULL)
Returns a shader that supports the specified operations. Must be called within a GL context...
This is the OpenGL attribute location where vertex bitangents are mapped to.
The shadow matrices (4x 4x4 Matrices)
This is the OpenGL attribute location where vertex tangents are mapped to.
This is the OpenGL attribute location where vertex positions are mapped to.
Scaling of each frustum's light ortho projection (4xvec2)
Encapsulates all information that the describes the surface appearance of a StelModel.
Material emissive color * light emissive.
void clearCache()
Clears the shaders that have been created by this manager. Must be called within a GL context...
ATTLOC
Enum for OpenGL shader attribute locations.
Light directional * Material diffuse.