21 #ifndef _S3DRENDERER_HPP_ 22 #define _S3DRENDERER_HPP_ 24 #include "StelGui.hpp" 25 #include "StelModule.hpp" 26 #include "StelPainter.hpp" 27 #include "Landscape.hpp" 28 #include "SolarSystem.hpp" 30 #include "StelOBJ.hpp" 31 #include "StelOpenGLArray.hpp" 32 #include "Heightmap.hpp" 33 #include "Frustum.hpp" 34 #include "Polyhedron.hpp" 35 #include "S3DEnum.hpp" 36 #include "SceneInfo.hpp" 37 #include "ShaderManager.hpp" 45 Q_DECLARE_LOGGING_CATEGORY(s3drenderer)
47 class
S3DRenderer : public QObject, protected QOpenGLFunctions
61 bool getDebugEnabled()
const {
return debugEnabled; }
62 void setDebugEnabled(
bool debugEnabled) { this->debugEnabled = debugEnabled; }
63 bool getPixelLightingEnabled()
const {
return shaderParameters.pixelLighting; }
64 void setPixelLightingEnabled(
const bool val) { shaderParameters.pixelLighting = val; invalidateCubemap(); }
65 bool getShadowsEnabled(
void)
const {
return shaderParameters.shadows; }
66 void setShadowsEnabled(
bool shadowsEnabled) { shaderParameters.shadows = shadowsEnabled; reinitShadowmapping =
true; invalidateCubemap(); }
67 bool getUseSimpleShadows()
const {
return simpleShadows; }
68 void setUseSimpleShadows(
bool val) { simpleShadows = val; reinitShadowmapping =
true; invalidateCubemap(); }
69 bool getBumpsEnabled(
void)
const {
return shaderParameters.bump; }
70 void setBumpsEnabled(
bool bumpsEnabled) { shaderParameters.bump = bumpsEnabled; invalidateCubemap(); }
71 bool getTorchEnabled(
void)
const {
return shaderParameters.torchLight; }
72 void setTorchEnabled(
bool torchEnabled) { shaderParameters.torchLight = torchEnabled; invalidateCubemap(); }
74 void setShadowFilterQuality(
S3DEnum::ShadowFilterQuality quality) { shaderParameters.shadowFilterQuality = quality; reinitShadowmapping=
true; invalidateCubemap();}
75 bool getPCSS()
const {
return shaderParameters.pcss; }
76 void setPCSS(
bool val) { shaderParameters.pcss = val; reinitShadowmapping =
true; invalidateCubemap(); }
77 bool getLocationInfoEnabled(
void)
const {
return textEnabled; }
78 void setLocationInfoEnabled(
bool locationinfoenabled) { this->textEnabled = locationinfoenabled; }
80 bool getLazyCubemapEnabled()
const {
return lazyDrawing; }
81 void setLazyCubemapEnabled(
bool val) { lazyDrawing = val; }
82 double getLazyCubemapInterval()
const {
return lazyInterval; }
83 void setLazyCubemapInterval(
double val) { lazyInterval = val; }
86 void getLazyCubemapUpdateOnlyDominantFaceOnMoving(
bool &val,
bool &alsoSecondDominantFace)
const { val = updateOnlyDominantOnMoving; alsoSecondDominantFace = updateSecondDominantOnMoving; }
87 void setLazyCubemapUpdateOnlyDominantFaceOnMoving(
bool val,
bool alsoSecondDominantFace) { updateOnlyDominantOnMoving = val; updateSecondDominantOnMoving = alsoSecondDominantFace; }
107 cubemappingMode = mode; reinitCubemapping =
true;
110 void setUseFullCubemapShadows(
bool val) { fullCubemapShadows = val; invalidateCubemap();}
111 bool getUseFullCubemapShadows()
const {
return fullCubemapShadows; }
113 uint getCubemapSize()
const {
return cubemapSize; }
115 void setCubemapSize(uint size) { cubemapSize = (size > maximumFramebufferSize ? maximumFramebufferSize : size); reinitCubemapping =
true; }
116 uint getShadowmapSize()
const {
return shadowmapSize; }
118 void setShadowmapSize(uint size) { shadowmapSize = (size > maximumFramebufferSize ? maximumFramebufferSize : size); reinitShadowmapping =
true; }
119 float getTorchBrightness()
const {
return torchBrightness; }
120 void setTorchBrightness(
float brightness) { torchBrightness = brightness; invalidateCubemap(); }
121 float getTorchRange()
const {
return torchRange; }
122 void setTorchRange(
float range) { torchRange = range; invalidateCubemap(); }
132 bool isGeometryShaderCubemapSupported()
const {
return supportsGSCubemapping; }
133 bool areShadowsSupported()
const {
return supportsShadows; }
134 bool isShadowFilteringSupported()
const {
return supportsShadowFiltering; }
135 bool isANGLEContext()
const {
return isANGLE; }
136 unsigned int getMaximumFramebufferSize()
const {
return maximumFramebufferSize; }
138 void message(
const QString& msg)
const;
142 PlanetP sun,moon,venus;
146 bool supportsGSCubemapping;
147 bool supportsShadows;
148 bool supportsShadowFiltering;
150 unsigned int maximumFramebufferSize;
153 float torchBrightness;
160 bool fullCubemapShadows;
162 bool reinitCubemapping,reinitShadowmapping;
164 unsigned int cubemapSize;
165 unsigned int shadowmapSize;
167 bool wasMovedInLastDrawCall;
168 Vec3d lastDrawnPosition;
176 bool backfaceCullState;
179 QOpenGLShaderProgram* curShader;
180 QSet<QOpenGLShaderProgram*> initializedShaders;
181 QVector<const StelOBJ::MaterialGroup*> transparentGroups;
184 int drawnTriangles,drawnModels;
185 int materialSwitches, shaderSwitches;
188 bool requiresCubemap;
189 bool cubemappingUsedLastFrame;
191 bool updateOnlyDominantOnMoving;
192 bool updateSecondDominantOnMoving;
193 bool needsMovementEndUpdate;
194 bool needsCubemapUpdate;
195 bool needsMovementUpdate;
197 double lastCubemapUpdate;
198 qint64 lastCubemapUpdateRealTime;
199 qint64 lastMovementEndRealTime;
200 GLuint cubeMapCubeTex;
201 GLuint cubeMapCubeDepth;
202 GLuint cubeMapTex[6];
204 int dominantFace,secondDominantFace;
208 GLuint cubeSideFBO[6];
210 bool cubeMappingCreated;
213 QVector<Vec3f> cubeVertices, transformedCubeVertices;
214 QVector<Vec2f> cubeTexcoords;
215 QOpenGLBuffer cubeVertexBuffer;
216 QOpenGLBuffer transformedCubeVertexBuffer;
217 QOpenGLBuffer cubeIndexBuffer;
221 QMatrix4x4 cubeRotation[6];
222 QMatrix4x4 cubeMVP[6];
226 QMatrix4x4 modelViewMatrix;
228 QMatrix4x4 projectionMatrix;
231 struct LightParameters
234 enum ShadowCaster { SC_None, SC_Sun, SC_Moon, SC_Venus } shadowCaster;
235 QMatrix4x4 shadowModelView;
237 Vec3f lightDirectionV3f;
239 QVector3D lightDirectionWorld;
241 QVector3D directional;
245 QVector3D torchDiffuse;
246 float torchAttenuation;
249 enum DirectionalSource { DS_Sun_Horiz, DS_Sun, DS_Moon, DS_Venus, DS_Venus_Ambient } directionalSource;
252 float backgroundAmbient;
253 float landscapeOpacity;
259 QVector<GLuint> shadowFBOs;
261 QVector<GLuint> shadowMapsArray;
263 QVector<QMatrix4x4> shadowCPM;
266 QVector<QVector4D> shadowFrustumSize;
270 float lightOrthoNear;
273 QVector<Frustum> frustumArray;
275 QVector<Polyhedron> focusBodies;
283 void determineFeatureSupport();
285 bool initCubemapping();
287 void deleteCubemapping();
290 bool initShadowmapping();
292 void deleteShadowmapping();
294 void calcCubeMVP(
const Vec3d translation);
300 void drawWithCubeMap();
302 bool renderShadowMaps();
304 void renderShadowMapsForFace(
int face);
306 void generateCubeMap();
308 void renderIntoCubemapGeometryShader();
310 void renderIntoCubemapSixPasses();
312 void drawFromCubeMap();
316 bool drawArrays(
bool shading=
true,
bool blendAlphaAdditive=
false);
321 void drawCoordinatesText();
327 void calculateShadowCaster();
329 void calculateLighting();
331 void setupPassUniforms(QOpenGLShaderProgram *shader);
333 void setupFrameUniforms(QOpenGLShaderProgram *shader);
335 void setupMaterialUniforms(QOpenGLShaderProgram *shader,
const S3DScene::Material& mat);
338 void adjustShadowFrustum(
const Vec3d &viewPos,
const Vec3d &viewDir,
const Vec3d &viewUp,
const float fov,
const float aspect);
340 void computeFrustumSplits(
const Vec3d& viewPos,
const Vec3d& viewDir,
const Vec3d& viewUp);
344 void computeCropMatrix(QMatrix4x4& cropMatrix, QVector4D &orthoScale,
Polyhedron &focusBody,
const QMatrix4x4 &lightProj,
const QMatrix4x4 &lightMVP);
346 void computeOrthoProjVals(
const Vec3f shadowDir,
float &orthoExtent,
float &orthoNear,
float &orthoFar);
348 void rendererMessage(
const QString& msg)
const;
351 #endif //_S3DRENDERER_HPP_ void setCubemapSize(uint size)
Note: This may not set the size to the desired one because of hardware limits, call getCubemapSize to...
Uses 6 textures, one for each side of the cube. Seems to be the best for old Intel drivers...
ShaderMgr & getShaderManager()
Returns the shader manager this instance uses.
This implementation is based on Stingl's Robust Hard Shadows.
A structure for global shader parameters.
Manages all the rendering at the level of the observer's surroundings.
Uses a single GL_TEXTURE_CUBEMAP, seems to work a bit better on "modern" GPUs.
Main class for Stellarium core processing.
QSharedPointer< StelProjector > StelProjectorP
Shared pointer on a StelProjector instance (implement reference counting)
Uses a single GL_TEXTURE_CUBEMAP and a geometry shader to render all 6 sides in one pass...
void setShadowmapSize(uint size)
Note: This may not set the size to the desired one because of hardware limits, call getShadowmapSize ...
void setCubemappingMode(S3DEnum::CubemappingMode mode)
Changes cubemapping mode and forces re-initialization on next draw call.
A simple shader cache class that gives us the correct shader depending on desired configuration...
Scenery3d renderer class.
void invalidateCubemap()
Does a cubemap redraw at the next possible opportunity when lazy-drawing is enabled.
ShadowFilterQuality
Contains different shadow filter settings.
Extension of StelOBJ::Material which provides Scenery3d specific stuff.
CubemappingMode
Determines the method used for cubemap creation.
Represents a bunch of faces following after each other that use the same material.