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" 63 void update(
double deltaTime);
77 bool getDebugEnabled()
const {
return debugEnabled; }
78 void setDebugEnabled(
bool debugEnabled) { this->debugEnabled = debugEnabled; }
79 bool getPixelLightingEnabled()
const {
return shaderParameters.pixelLighting; }
80 void setPixelLightingEnabled(
const bool val) { shaderParameters.pixelLighting = val;
invalidateCubemap(); }
81 bool getShadowsEnabled(
void)
const {
return shaderParameters.shadows; }
82 void setShadowsEnabled(
bool shadowsEnabled) { shaderParameters.shadows = shadowsEnabled; reinitShadowmapping =
true;
invalidateCubemap(); }
83 bool getUseSimpleShadows()
const {
return simpleShadows; }
84 void setUseSimpleShadows(
bool val) { simpleShadows = val; reinitShadowmapping =
true;
invalidateCubemap(); }
85 bool getBumpsEnabled(
void)
const {
return shaderParameters.bump; }
86 void setBumpsEnabled(
bool bumpsEnabled) { shaderParameters.bump = bumpsEnabled;
invalidateCubemap(); }
87 bool getTorchEnabled(
void)
const {
return shaderParameters.torchLight; }
88 void setTorchEnabled(
bool torchEnabled) { shaderParameters.torchLight = torchEnabled;
invalidateCubemap(); }
91 bool getPCSS()
const {
return shaderParameters.pcss; }
92 void setPCSS(
bool val) { shaderParameters.pcss = val; reinitShadowmapping =
true;
invalidateCubemap(); }
93 bool getLocationInfoEnabled(
void)
const {
return textEnabled; }
94 void setLocationInfoEnabled(
bool locationinfoenabled) { this->textEnabled = locationinfoenabled; }
96 bool getLazyCubemapEnabled()
const {
return lazyDrawing; }
97 void setLazyCubemapEnabled(
bool val) { lazyDrawing = val; }
98 double getLazyCubemapInterval()
const {
return lazyInterval; }
99 void setLazyCubemapInterval(
double val) { lazyInterval = val; }
102 void getLazyCubemapUpdateOnlyDominantFaceOnMoving(
bool &val,
bool &alsoSecondDominantFace) { val = updateOnlyDominantOnMoving; alsoSecondDominantFace = updateSecondDominantOnMoving; }
103 void setLazyCubemapUpdateOnlyDominantFaceOnMoving(
bool val,
bool alsoSecondDominantFace) { updateOnlyDominantOnMoving = val; updateSecondDominantOnMoving = alsoSecondDominantFace; }
123 cubemappingMode = mode; reinitCubemapping =
true;
126 void setUseFullCubemapShadows(
bool val) { fullCubemapShadows = val;
invalidateCubemap();}
127 bool getUseFullCubemapShadows()
const {
return fullCubemapShadows; }
129 uint getCubemapSize()
const {
return cubemapSize; }
131 void setCubemapSize(uint size) { cubemapSize = (size > maximumFramebufferSize ? maximumFramebufferSize : size); reinitCubemapping =
true; }
132 uint getShadowmapSize()
const {
return shadowmapSize; }
134 void setShadowmapSize(uint size) { shadowmapSize = (size > maximumFramebufferSize ? maximumFramebufferSize : size); reinitShadowmapping =
true; }
135 float getTorchBrightness()
const {
return torchBrightness; }
136 void setTorchBrightness(
float brightness) { torchBrightness = brightness;
invalidateCubemap(); }
137 float getTorchRange()
const {
return torchRange; }
140 void setLoadCancel(
bool val) { loadCancel = val; }
153 enum ShadowCaster { None, Sun, Moon, Venus };
163 bool isGeometryShaderCubemapSupported() {
return supportsGSCubemapping; }
164 bool areShadowsSupported() {
return supportsShadows; }
165 bool isShadowFilteringSupported() {
return supportsShadowFiltering; }
166 bool isANGLEContext() {
return isANGLE; }
167 unsigned int getMaximumFramebufferSize() {
return maximumFramebufferSize; }
173 PlanetP sun,moon,venus;
175 bool supportsGSCubemapping;
176 bool supportsShadows;
177 bool supportsShadowFiltering;
179 unsigned int maximumFramebufferSize;
182 float torchBrightness;
189 bool fullCubemapShadows;
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 transformedCubeVertexBuffer;
247 QOpenGLBuffer cubeIndexBuffer;
251 QMatrix4x4 cubeRotation[6];
252 QMatrix4x4 cubeMVP[6];
256 QMatrix4x4 modelViewMatrix;
258 QMatrix4x4 projectionMatrix;
261 struct LightParameters
263 QMatrix4x4 shadowModelView;
265 ShadowCaster lightSource;
266 Vec3f lightDirectionV3f;
267 QVector3D lightDirectionWorld;
269 QVector3D directional;
273 QVector3D torchDiffuse;
274 float torchAttenuation;
280 AABB sceneBoundingBox;
283 QVector<GLuint> shadowFBOs;
285 QVector<GLuint> shadowMapsArray;
287 QVector<QMatrix4x4> shadowCPM;
290 QVector<QVector4D> shadowFrustumSize;
294 float lightOrthoNear;
297 QVector<Frustum> frustumArray;
299 QVector<Polyhedron> focusBodies;
305 QString lightMessage;
306 QString lightMessage2;
307 QString lightMessage3;
311 void determineFeatureSupport();
313 bool initCubemapping();
315 void deleteCubemapping();
318 bool initShadowmapping();
320 void deleteShadowmapping();
328 void drawWithCubeMap();
330 bool renderShadowMaps();
332 void renderShadowMapsForFace(
int face);
334 void generateCubeMap();
336 void renderIntoCubemapGeometryShader();
338 void renderIntoCubemapSixPasses();
340 void drawFromCubeMap();
344 bool drawArrays(
bool shading=
true,
bool blendAlphaAdditive=
false);
349 void calculateShadowCaster();
351 void calculateLighting();
353 void setupPassUniforms(QOpenGLShaderProgram *shader);
355 void setupFrameUniforms(QOpenGLShaderProgram *shader);
357 void setupMaterialUniforms(QOpenGLShaderProgram *shader,
const OBJ::Material& mat);
360 Scenery3d::ShadowCaster calculateLightSource(
float &ambientBrightness,
float &diffuseBrightness,
Vec3f &lightsourcePosition,
float &emissiveFactor);
363 float groundHeight();
366 void setSceneAABB(
const AABB &bbox);
372 void adjustShadowFrustum(
const Vec3d viewPos,
const Vec3d viewDir,
const Vec3d viewUp,
const float fov,
const float aspect);
374 void computeFrustumSplits(
const Vec3d viewPos,
const Vec3d viewDir,
const Vec3d viewUp);
378 void computeCropMatrix(QMatrix4x4& cropMatrix, QVector4D &orthoScale,
Polyhedron &focusBody,
const QMatrix4x4 &lightProj,
const QMatrix4x4 &lightMVP);
380 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...
Uses 6 textures, one for each side of the cube. Seems to be the best for old Intel drivers...
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.
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...
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.
CubemappingMode
Determines the method used for cubemap creation.
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.