21 #ifndef _SCENERY3D_HPP_
22 #define _SCENERY3D_HPP_
24 #include "StelGui.hpp"
25 #include "StelModule.hpp"
26 #include "StelPainter.hpp"
27 #include "Landscape.hpp"
28 #include "SolarSystem.hpp"
31 #include "Heightmap.hpp"
32 #include "Frustum.hpp"
33 #include "Polyhedron.hpp"
34 #include "S3DEnum.hpp"
35 #include "SceneInfo.hpp"
36 #include "ShaderManager.hpp"
41 class QOpenGLFramebufferObject;
64 void update(
double deltaTime);
78 bool getDebugEnabled()
const {
return debugEnabled; }
79 void setDebugEnabled(
bool debugEnabled) { this->debugEnabled = debugEnabled; }
80 bool getPixelLightingEnabled()
const {
return shaderParameters.pixelLighting; }
81 void setPixelLightingEnabled(
const bool val) { shaderParameters.pixelLighting = val;
invalidateCubemap(); }
82 bool getShadowsEnabled(
void)
const {
return shaderParameters.shadows; }
83 void setShadowsEnabled(
bool shadowsEnabled) { shaderParameters.shadows = shadowsEnabled; reinitShadowmapping =
true;
invalidateCubemap(); }
84 bool getUseSimpleShadows()
const {
return simpleShadows; }
85 void setUseSimpleShadows(
bool val) { simpleShadows = val; reinitShadowmapping =
true;
invalidateCubemap(); }
86 bool getBumpsEnabled(
void)
const {
return shaderParameters.bump; }
87 void setBumpsEnabled(
bool bumpsEnabled) { shaderParameters.bump = bumpsEnabled;
invalidateCubemap(); }
88 bool getTorchEnabled(
void)
const {
return shaderParameters.torchLight; }
89 void setTorchEnabled(
bool torchEnabled) { shaderParameters.torchLight = torchEnabled;
invalidateCubemap(); }
92 bool getPCSS()
const {
return shaderParameters.pcss; }
93 void setPCSS(
bool val) { shaderParameters.pcss = val; reinitShadowmapping =
true;
invalidateCubemap(); }
94 bool getLocationInfoEnabled(
void)
const {
return textEnabled; }
95 void setLocationInfoEnabled(
bool locationinfoenabled) { this->textEnabled = locationinfoenabled; }
97 bool getLazyCubemapEnabled()
const {
return lazyDrawing; }
98 void setLazyCubemapEnabled(
bool val) { lazyDrawing = val; }
99 double getLazyCubemapInterval()
const {
return lazyInterval; }
100 void setLazyCubemapInterval(
double val) { lazyInterval = val; }
103 void getLazyCubemapUpdateOnlyDominantFaceOnMoving(
bool &val,
bool &alsoSecondDominantFace) { val = updateOnlyDominantOnMoving; alsoSecondDominantFace = updateSecondDominantOnMoving; }
104 void setLazyCubemapUpdateOnlyDominantFaceOnMoving(
bool val,
bool alsoSecondDominantFace) { updateOnlyDominantOnMoving = val; updateSecondDominantOnMoving = alsoSecondDominantFace; }
109 S3DEnum::CubemappingMode getCubemappingMode()
const {
return cubemappingMode; }
114 if(mode == S3DEnum::CM_CUBEMAP_GSACCEL && !isGeometryShaderCubemapSupported())
117 mode = S3DEnum::CM_TEXTURES;
119 if(mode == S3DEnum::CM_CUBEMAP && isANGLEContext())
122 mode = S3DEnum::CM_TEXTURES;
124 cubemappingMode = mode; reinitCubemapping =
true;
127 void setUseFullCubemapShadows(
bool val) { fullCubemapShadows = val;
invalidateCubemap();}
128 bool getUseFullCubemapShadows()
const {
return fullCubemapShadows; }
130 uint getCubemapSize()
const {
return cubemapSize; }
132 void setCubemapSize(uint size) { cubemapSize = (size > maximumFramebufferSize ? maximumFramebufferSize : size); reinitCubemapping =
true; }
133 uint getShadowmapSize()
const {
return shadowmapSize; }
135 void setShadowmapSize(uint size) { shadowmapSize = (size > maximumFramebufferSize ? maximumFramebufferSize : size); reinitShadowmapping =
true; }
136 float getTorchBrightness()
const {
return torchBrightness; }
137 void setTorchBrightness(
float brightness) { torchBrightness = brightness;
invalidateCubemap(); }
138 float getTorchRange()
const {
return torchRange; }
141 void setLoadCancel(
bool val) { loadCancel = val; }
154 enum ShadowCaster { None, Sun, Moon, Venus };
164 bool isGeometryShaderCubemapSupported() {
return supportsGSCubemapping; }
165 bool areShadowsSupported() {
return supportsShadows; }
166 bool isShadowFilteringSupported() {
return supportsShadowFiltering; }
167 bool isANGLEContext() {
return isANGLE; }
168 unsigned int getMaximumFramebufferSize() {
return maximumFramebufferSize; }
174 PlanetP sun,moon,venus;
176 bool supportsGSCubemapping;
177 bool supportsShadows;
178 bool supportsShadowFiltering;
180 unsigned int maximumFramebufferSize;
182 float torchBrightness;
189 bool fullCubemapShadows;
190 S3DEnum::CubemappingMode cubemappingMode;
191 bool reinitCubemapping,reinitShadowmapping;
195 unsigned int cubemapSize;
196 unsigned int shadowmapSize;
198 Vec3d absolutePosition;
206 QSharedPointer<OBJ> objModel, objModelLoad, groundModel, groundModelLoad;
214 int drawnTriangles,drawnModels;
215 int materialSwitches, shaderSwitches;
218 bool requiresCubemap;
219 bool cubemappingUsedLastFrame;
221 bool updateOnlyDominantOnMoving;
222 bool updateSecondDominantOnMoving;
223 bool needsMovementEndUpdate;
224 bool needsCubemapUpdate;
225 bool needsMovementUpdate;
227 double lastCubemapUpdate;
228 qint64 lastCubemapUpdateRealTime;
229 qint64 lastMovementEndRealTime;
230 GLuint cubeMapCubeTex;
231 GLuint cubeMapCubeDepth;
232 GLuint cubeMapTex[6];
234 int dominantFace,secondDominantFace;
238 GLuint cubeSideFBO[6];
240 bool cubeMappingCreated;
243 QVector<Vec3f> cubeVertices, transformedCubeVertices;
244 QVector<Vec2f> cubeTexcoords;
245 QOpenGLBuffer cubeVertexBuffer;
246 QOpenGLBuffer cubeIndexBuffer;
250 QMatrix4x4 cubeRotation[6];
251 QMatrix4x4 cubeMVP[6];
255 QMatrix4x4 modelViewMatrix;
257 QMatrix4x4 projectionMatrix;
260 struct LightParameters
262 QMatrix4x4 shadowModelView;
264 ShadowCaster lightSource;
265 Vec3f lightDirectionV3f;
266 QVector3D lightDirectionWorld;
268 QVector3D directional;
272 QVector3D torchDiffuse;
273 float torchAttenuation;
279 AABB sceneBoundingBox;
282 QVector<GLuint> shadowFBOs;
284 QVector<GLuint> shadowMapsArray;
286 QVector<QMatrix4x4> shadowCPM;
289 QVector<QVector4D> shadowFrustumSize;
293 float lightOrthoNear;
296 QVector<Frustum> frustumArray;
298 QVector<Polyhedron> focusBodies;
304 QString lightMessage;
305 QString lightMessage2;
306 QString lightMessage3;
310 void determineFeatureSupport();
312 bool initCubemapping();
314 void deleteCubemapping();
317 bool initShadowmapping();
319 void deleteShadowmapping();
327 void drawWithCubeMap();
329 bool renderShadowMaps();
331 void renderShadowMapsForFace(
int face);
333 void generateCubeMap();
335 void renderIntoCubemapGeometryShader();
337 void renderIntoCubemapSixPasses();
339 void drawFromCubeMap();
343 bool drawArrays(
bool shading=
true,
bool blendAlphaAdditive=
false);
348 void calculateShadowCaster();
350 void calculateLighting();
352 void setupPassUniforms(QOpenGLShaderProgram *shader);
354 void setupFrameUniforms(QOpenGLShaderProgram *shader);
356 void setupMaterialUniforms(QOpenGLShaderProgram *shader,
const OBJ::Material& mat);
359 Scenery3d::ShadowCaster calculateLightSource(
float &ambientBrightness,
float &diffuseBrightness, Vec3f &lightsourcePosition,
float &emissiveFactor);
362 float groundHeight();
365 void setSceneAABB(
const AABB &bbox);
371 void adjustShadowFrustum(
const Vec3d viewPos,
const Vec3d viewDir,
const Vec3d viewUp,
const float fov,
const float aspect);
373 void computeFrustumSplits(
const Vec3d viewPos,
const Vec3d viewDir,
const Vec3d viewUp);
375 void computePolyhedron(
Polyhedron& body,
const Frustum& frustum,
const Vec3f &shadowDir);
377 void computeCropMatrix(QMatrix4x4& cropMatrix, QVector4D &orthoScale,
Polyhedron &focusBody,
const QMatrix4x4 &lightProj,
const QMatrix4x4 &lightMVP);
379 void computeOrthoProjVals(
const Vec3f shadowDir,
float &orthoExtent,
float &orthoNear,
float &orthoFar);
float getEyeHeight() const
Gets the current observer eye height (vertical difference from feet to camera position).
void init()
Performs initialization that requires an valid OpenGL context.
Contains all the metadata necessary for a Scenery3d scene, and can be loaded from special ...
void setCubemapSize(uint size)
Note: This may not set the size to the desired one because of hardware limits, call getCubemapSize to...
void drawCoordinatesText()
Draw observer grid coordinates as text.
void setEyeHeight(const float eyeheight)
Sets the observer eye height.
This represents a heightmap for viewer-ground collision.
void setCubemappingMode(S3DEnum::CubemappingMode mode)
Changes cubemapping mode and forces re-initialization on next draw call.
void draw(StelCore *core)
Draw scenery, called by Scenery3dMgr.
This implementation is based on Stingl's Robust Hard Shadows.
A structure for global shader parameters.
QSharedPointer< StelProjector > StelProjectorP
Main class of the module, inherits from StelModule.
void update(double deltaTime)
Update method, called by Scenery3dMgr.
An axis-aligned bounding-box class.
void handleKeys(QKeyEvent *e)
Walk/Fly Navigation with Ctrl+Cursor and Ctrl+PgUp/Dn keys.
A simple shader cache class that gives us the correct shader depending on desired configuration...
Representation of a complete 3D scenery.
bool loadScene(const SceneInfo &scene)
Loads the specified scene.
ShadowFilterQuality
Contains different shadow filter settings.
Scenery3d(Scenery3dMgr *parent)
Initializes an empty Scenery3d object.
void invalidateCubemap()
Does a cubemap redraw at the next possible opportunity when lazy-drawing is enabled.
void drawDebug()
Draw some text output. This can be filled as needed by development.
void setShadowmapSize(uint size)
Note: This may not set the size to the desired one because of hardware limits, call getShadowmapSize ...
SceneInfo getCurrentScene()
Gets the current scene's metadata.
Vec3d getCurrentGridPosition() const
Gets the current position on the scene's grid (height at feet)
void finalizeLoad()
Loads the model into GL and sets the loaded scene to be the current one.
Encapsulates all information that the describes the surface appearance of a StelModel.
void setGridPosition(Vec3d pos)
Sets the observer position to the specified grid coordinates.
ShaderMgr & getShaderManager()
Returns the shader manager this instance uses.