21 #ifndef _SHADERMANAGER_HPP_ 22 #define _SHADERMANAGER_HPP_ 24 #include "StelOpenGL.hpp" 25 #include "S3DEnum.hpp" 29 class QOpenGLShaderProgram;
45 bool hwShadowSamplers;
139 inline QOpenGLShaderProgram* getDebugShader();
142 inline QOpenGLShaderProgram* getCubeShader();
145 inline QOpenGLShaderProgram* getTextureShader();
149 inline GLint uniformLocation(
const QOpenGLShaderProgram* shad,
UNIFORM uni);
155 typedef QMap<QString,UNIFORM> t_UniformStrings;
156 static t_UniformStrings uniformStrings;
167 PIXEL_LIGHTING = (1<<2),
177 SHADOW_FILTER = (1<<7),
179 SHADOW_FILTER_HQ = (1<<8),
181 MAT_SPECULAR = (1<<9),
183 MAT_DIFFUSETEX = (1<<10),
185 MAT_EMISSIVETEX = (1<<11),
187 GEOMETRY_SHADER = (1<<12),
200 SINGLE_SHADOW_FRUSTUM = (1<<18),
204 HW_SHADOW_SAMPLERS = (1<<20)
207 typedef QMap<QString,FeatureFlags> t_FeatureFlagStrings;
208 static t_FeatureFlagStrings featureFlagsStrings;
210 QString getVShaderName(uint flags);
211 QString getGShaderName(uint flags);
212 QString getFShaderName(uint flags);
213 QOpenGLShaderProgram* findOrLoadShader(uint flags);
215 bool preprocessShader(
const QString& fileName,
const uint flags, QByteArray& processedSource);
217 bool loadShader(QOpenGLShaderProgram& program,
const QByteArray& vShader,
const QByteArray& gShader,
const QByteArray& fShader);
218 void buildUniformCache(QOpenGLShaderProgram& program);
220 typedef QHash<uint,QOpenGLShaderProgram*> t_ShaderCache;
221 t_ShaderCache m_shaderCache;
223 typedef QHash<QByteArray,QOpenGLShaderProgram*> t_ShaderContentCache;
224 t_ShaderContentCache m_shaderContentCache;
226 typedef QHash<UNIFORM,GLuint> t_UniformCacheEntry;
227 typedef QHash<const QOpenGLShaderProgram*, t_UniformCacheEntry> t_UniformCache;
228 t_UniformCache m_uniformCache;
235 uint flags = INVALID;
236 if(globals.openglES) flags|=OGL_ES2;
237 if(!globals.shadowTransform)
240 if(globals.pixelLighting) flags|= PIXEL_LIGHTING;
241 if(globals.pixelLighting && globals.shadows) flags|= SHADOWS;
242 if(globals.pixelLighting && globals.shadows && globals.shadowFilterQuality>
S3DEnum::SFQ_HARDWARE) flags|= SHADOW_FILTER;
243 if(globals.pixelLighting && globals.shadows && globals.shadowFilterQuality>
S3DEnum::SFQ_LOW_HARDWARE) flags|= SHADOW_FILTER_HQ;
244 if(globals.pixelLighting && globals.shadows && !globals.hwShadowSamplers && (globals.shadowFilterQuality ==
S3DEnum::SFQ_LOW || globals.shadowFilterQuality ==
S3DEnum::SFQ_HIGH) && globals.pcss) flags|= PCSS;
245 if(globals.hwShadowSamplers) flags|=HW_SHADOW_SAMPLERS;
246 if(globals.geometryShader) flags|= GEOMETRY_SHADER;
247 if(globals.torchLight) flags|= TORCH;
248 if(globals.frustumSplits == 1) flags|= SINGLE_SHADOW_FRUSTUM;
257 if(mat->
alphatest && mat->texture && mat->texture->hasAlphaChannel())
260 flags|= MAT_SPECULAR;
264 flags|= MAT_DIFFUSETEX;
265 if(mat->emissive_texture)
266 flags|= MAT_EMISSIVETEX;
267 if(mat->bump_texture && globals.bump && globals.pixelLighting)
269 if(mat->height_texture && globals.bump && globals.pixelLighting)
273 return findOrLoadShader(flags);
278 return findOrLoadShader(DEBUG);
283 return findOrLoadShader(CUBEMAP);
288 return findOrLoadShader(MAT_DIFFUSETEX);
293 t_UniformCache::iterator it = m_uniformCache.find(shad);
294 if(it!=m_uniformCache.end())
296 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...
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.
ATTLOC
Enum for OpenGL shader attribute locations.
Light directional * Material diffuse.