21 #ifndef _SHADERMANAGER_HPP_ 22 #define _SHADERMANAGER_HPP_ 23 #include "S3DScene.hpp" 24 #include "StelTexture.hpp" 25 #include "S3DEnum.hpp" 29 class QOpenGLShaderProgram;
31 Q_DECLARE_LOGGING_CATEGORY(shaderMgr)
47 bool hwShadowSamplers;
142 typedef QMap<QString,UNIFORM> t_UniformStrings;
143 static t_UniformStrings uniformStrings;
154 PIXEL_LIGHTING = (1<<2),
164 SHADOW_FILTER = (1<<7),
166 SHADOW_FILTER_HQ = (1<<8),
168 MAT_SPECULAR = (1<<9),
170 MAT_DIFFUSETEX = (1<<10),
172 MAT_EMISSIVETEX = (1<<11),
174 GEOMETRY_SHADER = (1<<12),
187 SINGLE_SHADOW_FRUSTUM = (1<<18),
191 HW_SHADOW_SAMPLERS = (1<<20)
194 typedef QMap<QString,FeatureFlags> t_FeatureFlagStrings;
195 static t_FeatureFlagStrings featureFlagsStrings;
197 QString getVShaderName(uint flags);
198 QString getGShaderName(uint flags);
199 QString getFShaderName(uint flags);
200 QOpenGLShaderProgram* findOrLoadShader(uint flags);
202 bool preprocessShader(
const QString& fileName,
const uint flags, QByteArray& processedSource);
204 bool loadShader(QOpenGLShaderProgram& program,
const QByteArray& vShader,
const QByteArray& gShader,
const QByteArray& fShader);
205 void buildUniformCache(QOpenGLShaderProgram& program);
207 typedef QHash<uint,QOpenGLShaderProgram*> t_ShaderCache;
208 t_ShaderCache m_shaderCache;
210 typedef QHash<QByteArray,QOpenGLShaderProgram*> t_ShaderContentCache;
211 t_ShaderContentCache m_shaderContentCache;
213 typedef QHash<UNIFORM,GLuint> t_UniformCacheEntry;
214 typedef QHash<const QOpenGLShaderProgram*, t_UniformCacheEntry> t_UniformCache;
215 t_UniformCache m_uniformCache;
222 uint flags = INVALID;
223 if(globals.openglES) flags|=OGL_ES2;
224 if(!globals.shadowTransform)
227 if(globals.pixelLighting) flags|= PIXEL_LIGHTING;
228 if(globals.pixelLighting && globals.shadows) flags|= SHADOWS;
229 if(globals.pixelLighting && globals.shadows && globals.shadowFilterQuality>
S3DEnum::SFQ_HARDWARE) flags|= SHADOW_FILTER;
230 if(globals.pixelLighting && globals.shadows && globals.shadowFilterQuality>
S3DEnum::SFQ_LOW_HARDWARE) flags|= SHADOW_FILTER_HQ;
231 if(globals.pixelLighting && globals.shadows && !globals.hwShadowSamplers && (globals.shadowFilterQuality ==
S3DEnum::SFQ_LOW || globals.shadowFilterQuality ==
S3DEnum::SFQ_HIGH) && globals.pcss) flags|= PCSS;
232 if(globals.hwShadowSamplers) flags|=HW_SHADOW_SAMPLERS;
233 if(globals.geometryShader) flags|= GEOMETRY_SHADER;
234 if(globals.torchLight) flags|= TORCH;
235 if(globals.frustumSplits == 1) flags|= SINGLE_SHADOW_FRUSTUM;
244 if(mat->bAlphatest && mat->tex_Kd && mat->tex_Kd->hasAlphaChannel())
247 flags|= MAT_SPECULAR;
250 if(mat->traits.hasDiffuseTexture)
251 flags|= MAT_DIFFUSETEX;
253 flags|= MAT_EMISSIVETEX;
254 if(mat->traits.
hasBumpTexture && globals.bump && globals.pixelLighting)
260 return findOrLoadShader(flags);
265 return findOrLoadShader(DEBUG);
270 return findOrLoadShader(CUBEMAP);
275 return findOrLoadShader(MAT_DIFFUSETEX);
280 t_UniformCache::iterator it = m_uniformCache.find(shad);
281 if(it!=m_uniformCache.end())
283 return it.value().value(uni,-1);
Material global transparency.
Uses a 16-tap Poisson disk.
bool hasSpecularity
True when tex_height is a valid texture.
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.
bool hasEmissiveTexture
True when tex_Kd is a valid texture.
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.
Squared frustum splits (vec4)
bool hasTransparency
True when both Ks and Ns are non-zero.
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)
QOpenGLShaderProgram * getShader(const GlobalShaderParameters &globals, const S3DScene::Material *mat=Q_NULLPTR)
Returns a shader that supports the specified operations. Must be called within a GL context...
Defines the Height texture slot.
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...
bool hasHeightTexture
True when tex_bump is a valid texture.
Defines the emissive texture slot.
ShadowFilterQuality
Contains different shadow filter settings.
Extension of StelOBJ::Material which provides Scenery3d specific stuff.
Uses a 64-tap Poisson disk.
bool isFading
True when the material is (currently) completely invisible.
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...
The shadow matrices (4x 4x4 Matrices)
Scaling of each frustum's light ortho projection (4xvec2)
Material emissive color * light emissive.
void clearCache()
Clears the shaders that have been created by this manager. Must be called within a GL context...
bool hasBumpTexture
True when tex_Ke is a valid texture.
Light directional * Material diffuse.