mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Merge pull request #6743 from zzmp/fix/skymap-tex-load
Guard against unloaded skymap tex
This commit is contained in:
commit
54edd94dd2
3 changed files with 87 additions and 79 deletions
|
@ -3486,78 +3486,86 @@ namespace render {
|
||||||
|
|
||||||
// Background rendering decision
|
// Background rendering decision
|
||||||
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
|
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
|
||||||
if (skyStage->getBackgroundMode() == model::SunSkyStage::NO_BACKGROUND) {
|
auto backgroundMode = skyStage->getBackgroundMode();
|
||||||
|
|
||||||
|
if (backgroundMode == model::SunSkyStage::NO_BACKGROUND) {
|
||||||
// this line intentionally left blank
|
// this line intentionally left blank
|
||||||
} else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_DOME) {
|
} else {
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
|
if (backgroundMode == model::SunSkyStage::SKY_BOX) {
|
||||||
PerformanceTimer perfTimer("stars");
|
auto skybox = skyStage->getSkybox();
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
if (skybox && skybox->getCubemap() && skybox->getCubemap()->isDefined()) {
|
||||||
"Application::payloadRender<BackgroundRenderData>() ... stars...");
|
PerformanceTimer perfTimer("skybox");
|
||||||
// should be the first rendering pass - w/o depth buffer / lighting
|
skybox->render(batch, *(args->_viewFrustum));
|
||||||
|
} else {
|
||||||
// compute starfield alpha based on distance from atmosphere
|
// If no skybox texture is available, render the SKY_DOME while it loads
|
||||||
float alpha = 1.0f;
|
backgroundMode = model::SunSkyStage::SKY_DOME;
|
||||||
bool hasStars = true;
|
|
||||||
|
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
|
|
||||||
// TODO: handle this correctly for zones
|
|
||||||
const EnvironmentData& closestData = background->_environment->getClosestData(args->_viewFrustum->getPosition()); // was theCamera instead of _viewFrustum
|
|
||||||
|
|
||||||
if (closestData.getHasStars()) {
|
|
||||||
const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f;
|
|
||||||
const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f;
|
|
||||||
|
|
||||||
glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation())
|
|
||||||
/ closestData.getAtmosphereOuterRadius();
|
|
||||||
float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter());
|
|
||||||
if (height < closestData.getAtmosphereInnerRadius()) {
|
|
||||||
// If we're inside the atmosphere, then determine if our keyLight is below the horizon
|
|
||||||
alpha = 0.0f;
|
|
||||||
|
|
||||||
if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
|
|
||||||
float directionY = glm::clamp(sunDirection.y,
|
|
||||||
-APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
|
|
||||||
+ APPROXIMATE_DISTANCE_FROM_HORIZON;
|
|
||||||
alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if (height < closestData.getAtmosphereOuterRadius()) {
|
|
||||||
alpha = (height - closestData.getAtmosphereInnerRadius()) /
|
|
||||||
(closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());
|
|
||||||
|
|
||||||
if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
|
|
||||||
float directionY = glm::clamp(sunDirection.y,
|
|
||||||
-APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
|
|
||||||
+ APPROXIMATE_DISTANCE_FROM_HORIZON;
|
|
||||||
alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hasStars = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally render the starfield
|
|
||||||
if (hasStars) {
|
|
||||||
background->_stars.render(args, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw the sky dome
|
|
||||||
if (/*!selfAvatarOnly &&*/ Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
|
|
||||||
PerformanceTimer perfTimer("atmosphere");
|
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
|
||||||
"Application::displaySide() ... atmosphere...");
|
|
||||||
|
|
||||||
background->_environment->renderAtmospheres(batch, *(args->_viewFrustum));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) {
|
if (backgroundMode == model::SunSkyStage::SKY_DOME) {
|
||||||
PerformanceTimer perfTimer("skybox");
|
if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
|
||||||
auto skybox = skyStage->getSkybox();
|
PerformanceTimer perfTimer("stars");
|
||||||
if (skybox) {
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
skybox->render(batch, *(args->_viewFrustum));
|
"Application::payloadRender<BackgroundRenderData>() ... stars...");
|
||||||
|
// should be the first rendering pass - w/o depth buffer / lighting
|
||||||
|
|
||||||
|
// compute starfield alpha based on distance from atmosphere
|
||||||
|
float alpha = 1.0f;
|
||||||
|
bool hasStars = true;
|
||||||
|
|
||||||
|
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
|
||||||
|
// TODO: handle this correctly for zones
|
||||||
|
const EnvironmentData& closestData = background->_environment->getClosestData(args->_viewFrustum->getPosition()); // was theCamera instead of _viewFrustum
|
||||||
|
|
||||||
|
if (closestData.getHasStars()) {
|
||||||
|
const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f;
|
||||||
|
const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f;
|
||||||
|
|
||||||
|
glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation())
|
||||||
|
/ closestData.getAtmosphereOuterRadius();
|
||||||
|
float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter());
|
||||||
|
if (height < closestData.getAtmosphereInnerRadius()) {
|
||||||
|
// If we're inside the atmosphere, then determine if our keyLight is below the horizon
|
||||||
|
alpha = 0.0f;
|
||||||
|
|
||||||
|
if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
|
||||||
|
float directionY = glm::clamp(sunDirection.y,
|
||||||
|
-APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
|
||||||
|
+ APPROXIMATE_DISTANCE_FROM_HORIZON;
|
||||||
|
alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else if (height < closestData.getAtmosphereOuterRadius()) {
|
||||||
|
alpha = (height - closestData.getAtmosphereInnerRadius()) /
|
||||||
|
(closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());
|
||||||
|
|
||||||
|
if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) {
|
||||||
|
float directionY = glm::clamp(sunDirection.y,
|
||||||
|
-APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON)
|
||||||
|
+ APPROXIMATE_DISTANCE_FROM_HORIZON;
|
||||||
|
alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hasStars = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally render the starfield
|
||||||
|
if (hasStars) {
|
||||||
|
background->_stars.render(args, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw the sky dome
|
||||||
|
if (/*!selfAvatarOnly &&*/ Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
|
||||||
|
PerformanceTimer perfTimer("atmosphere");
|
||||||
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
|
"Application::displaySide() ... atmosphere...");
|
||||||
|
|
||||||
|
background->_environment->renderAtmospheres(batch, *(args->_viewFrustum));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,12 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
|
gpu::TexturePointer skymap = skybox.getCubemap();
|
||||||
|
// FIXME: skymap->isDefined may not be threadsafe
|
||||||
|
assert(skymap && skymap->isDefined());
|
||||||
|
|
||||||
glm::mat4 projMat;
|
glm::mat4 projMat;
|
||||||
viewFrustum.evalProjectionMatrix(projMat);
|
viewFrustum.evalProjectionMatrix(projMat);
|
||||||
|
|
||||||
|
@ -106,11 +111,6 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky
|
||||||
batch.setViewTransform(viewTransform);
|
batch.setViewTransform(viewTransform);
|
||||||
batch.setModelTransform(Transform()); // only for Mac
|
batch.setModelTransform(Transform()); // only for Mac
|
||||||
|
|
||||||
gpu::TexturePointer skymap;
|
|
||||||
if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
|
|
||||||
skymap = skybox.getCubemap();
|
|
||||||
}
|
|
||||||
|
|
||||||
batch.setPipeline(thePipeline);
|
batch.setPipeline(thePipeline);
|
||||||
batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._dataBuffer);
|
batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._dataBuffer);
|
||||||
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap);
|
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap);
|
||||||
|
@ -118,6 +118,5 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||||
|
|
||||||
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr);
|
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,10 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) {
|
if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) {
|
||||||
|
gpu::TexturePointer skymap = skybox.getCubemap();
|
||||||
|
// FIXME: skymap->isDefined may not be threadsafe
|
||||||
|
assert(skymap && skymap->isDefined());
|
||||||
|
|
||||||
glm::mat4 projMat;
|
glm::mat4 projMat;
|
||||||
viewFrustum.evalProjectionMatrix(projMat);
|
viewFrustum.evalProjectionMatrix(projMat);
|
||||||
|
|
||||||
|
@ -56,10 +60,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum,
|
||||||
batch.setProjectionTransform(projMat);
|
batch.setProjectionTransform(projMat);
|
||||||
batch.setViewTransform(viewTransform);
|
batch.setViewTransform(viewTransform);
|
||||||
batch.setModelTransform(Transform()); // only for Mac
|
batch.setModelTransform(Transform()); // only for Mac
|
||||||
|
batch.setResourceTexture(0, skybox.getCubemap());
|
||||||
if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
|
|
||||||
batch.setResourceTexture(0, skybox.getCubemap());
|
|
||||||
}
|
|
||||||
|
|
||||||
skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1));
|
skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1));
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||||
|
|
Loading…
Reference in a new issue