From d94d5d919552ee79bc0b6eaf93dbc9ca67079a97 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Fri, 7 Oct 2016 17:42:10 -0400 Subject: [PATCH] Skeleton for new atmosphere module. --- modules/atmosphere/CMakeLists.txt | 43 ++++++ modules/atmosphere/atmospheremodule.cpp | 43 ++++++ modules/atmosphere/atmospheremodule.h | 40 ++++++ modules/atmosphere/include.cmake | 1 + .../rendering/atmosphereraycaster.cpp | 131 +++++++++++++++++ .../rendering/atmosphereraycaster.h | 80 +++++++++++ .../rendering/renderableatmosphere.cpp | 133 ++++++++++++++++++ .../rendering/renderableatmosphere.h | 62 ++++++++ modules/atmosphere/shaders/boundsfs.glsl | 40 ++++++ modules/atmosphere/shaders/boundsvs.glsl | 47 +++++++ modules/atmosphere/shaders/raycast.glsl | 77 ++++++++++ 11 files changed, 697 insertions(+) create mode 100644 modules/atmosphere/CMakeLists.txt create mode 100644 modules/atmosphere/atmospheremodule.cpp create mode 100644 modules/atmosphere/atmospheremodule.h create mode 100644 modules/atmosphere/include.cmake create mode 100644 modules/atmosphere/rendering/atmosphereraycaster.cpp create mode 100644 modules/atmosphere/rendering/atmosphereraycaster.h create mode 100644 modules/atmosphere/rendering/renderableatmosphere.cpp create mode 100644 modules/atmosphere/rendering/renderableatmosphere.h create mode 100644 modules/atmosphere/shaders/boundsfs.glsl create mode 100644 modules/atmosphere/shaders/boundsvs.glsl create mode 100644 modules/atmosphere/shaders/raycast.glsl diff --git a/modules/atmosphere/CMakeLists.txt b/modules/atmosphere/CMakeLists.txt new file mode 100644 index 0000000000..3e1b3ab94a --- /dev/null +++ b/modules/atmosphere/CMakeLists.txt @@ -0,0 +1,43 @@ +######################################################################################### +# # +# OpenSpace # +# # +# Copyright (c) 2014-2016 # +# # +# Permission is hereby granted, free of charge, to any person obtaining a copy of this # +# software and associated documentation files (the "Software"), to deal in the Software # +# without restriction, including without limitation the rights to use, copy, modify, # +# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the following # +# conditions: # +# # +# The above copyright notice and this permission notice shall be included in all copies # +# or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # +# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +######################################################################################### + +include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) + +set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableatmosphere.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/atmosphereraycaster.h +) +source_group("Header Files" FILES ${HEADER_FILES}) + +set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableatmosphere.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/atmosphereraycaster.cpp +) +source_group("Source Files" FILES ${SOURCE_FILES}) + +create_new_module( + "Atmosphere" + atmosphere_module + ${HEADER_FILES} ${SOURCE_FILES} +) diff --git a/modules/atmosphere/atmospheremodule.cpp b/modules/atmosphere/atmospheremodule.cpp new file mode 100644 index 0000000000..211ac38683 --- /dev/null +++ b/modules/atmosphere/atmospheremodule.cpp @@ -0,0 +1,43 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include + +#include + +#include + +namespace openspace { + +AtmosphereModule::AtmosphereModule() : OpenSpaceModule("Atmosphere") {} + +void AtmosphereModule::internalInitialize() { + auto fRenderable = FactoryManager::ref().factory(); + ghoul_assert(fRenderable, "No renderable factory existed"); + fRenderable->registerClass("RenderableAtmosphere"); +} + +} // namespace openspace diff --git a/modules/atmosphere/atmospheremodule.h b/modules/atmosphere/atmospheremodule.h new file mode 100644 index 0000000000..94b26f4bb7 --- /dev/null +++ b/modules/atmosphere/atmospheremodule.h @@ -0,0 +1,40 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __ATMOSPHEREMODULE_H__ +#define __ATMOSPHEREMODULE_H__ + +#include + +namespace openspace { + +class AtmosphereModule : public OpenSpaceModule { +public: + AtmosphereModule(); + void internalInitialize() override; +}; + +} // namespace openspace + +#endif // __ATMOSPHEREMODULE_H__ diff --git a/modules/atmosphere/include.cmake b/modules/atmosphere/include.cmake new file mode 100644 index 0000000000..ded20927fb --- /dev/null +++ b/modules/atmosphere/include.cmake @@ -0,0 +1 @@ +#set (DEFAULT_MODULE ON) diff --git a/modules/atmosphere/rendering/atmosphereraycaster.cpp b/modules/atmosphere/rendering/atmosphereraycaster.cpp new file mode 100644 index 0000000000..033b4578f9 --- /dev/null +++ b/modules/atmosphere/rendering/atmosphereraycaster.cpp @@ -0,0 +1,131 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace { + const std::string GlslRaycastPath = "${MODULES}/atmosphere/shaders/raycast.glsl"; + const std::string GlslBoundsVsPath = "${MODULES}/atmosphere/shaders/boundsvs.glsl"; + const std::string GlslBoundsFsPath = "${MODULES}/atmosphere/shaders/boundsfs.glsl"; +} + +namespace openspace { + +AtmosphereRaycaster::AtmosphereRaycaster(glm::vec4 color) + : _boundingBox(glm::vec3(1.0)) + , _color(color) {} + +AtmosphereRaycaster::~AtmosphereRaycaster() {} + +void AtmosphereRaycaster::initialize() { + _boundingBox.initialize(); +} + +void AtmosphereRaycaster::deinitialize() { +} + +void AtmosphereRaycaster::renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) { + program.setUniform("modelTransform", _modelTransform); + program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); + Renderable::setPscUniforms(program, data.camera, data.position); + + // Cull back face + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + // Render bounding geometry + _boundingBox.render(); +} + +void AtmosphereRaycaster::renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) { + // Uniforms + program.setUniform("modelTransform", _modelTransform); + program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); + Renderable::setPscUniforms(program, data.camera, data.position); + + // Cull front face + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + + // Render bounding geometry + _boundingBox.render(); + + // Restore defaults + glCullFace(GL_BACK); +} + +void AtmosphereRaycaster::preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) { + std::string colorUniformName = "color" + std::to_string(data.id); + std::string timeUniformName = "time" + std::to_string(data.id); + std::string stepSizeUniformName = "maxStepSize" + std::to_string(data.id); + program.setUniform(colorUniformName, _color); + program.setUniform(stepSizeUniformName, _stepSize); + program.setUniform(timeUniformName, static_cast(std::fmod(_time, 3600.0))); +} + +void AtmosphereRaycaster::postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) { + // For example: release texture units +} + +std::string AtmosphereRaycaster::getBoundsVsPath() const { + return GlslBoundsVsPath; +} + +std::string AtmosphereRaycaster::getBoundsFsPath() const { + return GlslBoundsFsPath; +} + +std::string AtmosphereRaycaster::getRaycastPath() const { + return GlslRaycastPath; +} + +std::string AtmosphereRaycaster::getHelperPath() const { + return ""; // no helper file +} + +void AtmosphereRaycaster::setColor(glm::vec4 color) { + _color = color; +} + +void AtmosphereRaycaster::setModelTransform(glm::mat4 transform) { + _modelTransform = transform; +} + +void AtmosphereRaycaster::setTime(double time) { + _time = time; +} + +void AtmosphereRaycaster::setStepSize(float stepSize) { + _stepSize = stepSize; +} + +} diff --git a/modules/atmosphere/rendering/atmosphereraycaster.h b/modules/atmosphere/rendering/atmosphereraycaster.h new file mode 100644 index 0000000000..076fa60ce1 --- /dev/null +++ b/modules/atmosphere/rendering/atmosphereraycaster.h @@ -0,0 +1,80 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __ATMOSPHERERAYCASTER_H__ +#define __ATMOSPHERERAYCASTER_H__ + +#include +#include +#include +#include +#include +#include + +namespace ghoul { + namespace opengl { + class Texture; + class ProgramObject; + } +} + +namespace openspace { + +class RenderData; +class RaycastData; + +class AtmosphereRaycaster : public VolumeRaycaster { +public: + + AtmosphereRaycaster(glm::vec4 color); + + virtual ~AtmosphereRaycaster(); + void initialize(); + void deinitialize(); + void renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) override; + void renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) override; + void preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) override; + void postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) override; + + std::string getBoundsVsPath() const override; + std::string getBoundsFsPath() const override; + std::string getRaycastPath() const override; + std::string getHelperPath() const override; + + void setColor(glm::vec4 color); + void setModelTransform(glm::mat4 transform); + void setTime(double time); + void setStepSize(float time); +private: + BoxGeometry _boundingBox; + glm::vec4 _color; + glm::mat4 _modelTransform; + float _stepSize; + double _time; + +}; // AtmosphereRaycaster + +} // openspace + +#endif // __ATMOSPHERERAYCASTER_H__ diff --git a/modules/atmosphere/rendering/renderableatmosphere.cpp b/modules/atmosphere/rendering/renderableatmosphere.cpp new file mode 100644 index 0000000000..f7d71af5c0 --- /dev/null +++ b/modules/atmosphere/rendering/renderableatmosphere.cpp @@ -0,0 +1,133 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace openspace { + + RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _scalingExponent("scalingExponent", "Scaling Exponent", 1, -10, 20) + , _stepSize("stepSize", "Step Size", 0.02, 0.01, 1) + , _scaling("scaling", "Scaling", glm::vec3(1.0, 1.0, 1.0), glm::vec3(0.0), glm::vec3(10.0)) + , _translation("translation", "Translation", glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0), glm::vec3(10.0)) + , _rotation("rotation", "Euler rotation", glm::vec3(0.0, 0.0, 0.0), glm::vec3(0), glm::vec3(6.28)) + , _color("color", "Color", glm::vec4(1.0, 0.0, 0.0, 0.1), glm::vec4(0.0), glm::vec4(1.0)) { + + float scalingExponent, stepSize; + glm::vec3 scaling, translation, rotation; + glm::vec4 color; + if (dictionary.getValue("ScalingExponent", scalingExponent)) { + _scalingExponent = scalingExponent; + } + if (dictionary.getValue("Scaling", scaling)) { + _scaling = scaling; + } + if (dictionary.getValue("Translation", translation)) { + _translation = translation; + } + if (dictionary.getValue("Rotation", rotation)) { + _rotation = rotation; + } + if (dictionary.getValue("Color", color)) { + _color = color; + } + if (dictionary.getValue("StepSize", stepSize)) { + _stepSize = stepSize; + } +} + +RenderableAtmosphere::~RenderableAtmosphere() {} + +bool RenderableAtmosphere::initialize() { + _raycaster = std::make_unique(_color); + _raycaster->initialize(); + + OsEng.renderEngine().raycasterManager().attachRaycaster(*_raycaster.get()); + + std::function onChange = [&](bool enabled) { + if (enabled) { + OsEng.renderEngine().raycasterManager().attachRaycaster(*_raycaster.get()); + } + else { + OsEng.renderEngine().raycasterManager().detachRaycaster(*_raycaster.get()); + } + }; + + onEnabledChange(onChange); + + addProperty(_scaling); + addProperty(_scalingExponent); + addProperty(_stepSize); + addProperty(_translation); + addProperty(_rotation); + addProperty(_color); + + return true; +} + +bool RenderableAtmosphere::deinitialize() { + if (_raycaster) { + OsEng.renderEngine().raycasterManager().detachRaycaster(*_raycaster.get()); + _raycaster = nullptr; + } + return true; +} + +bool RenderableAtmosphere::isReady() const { + return true; +} + +void RenderableAtmosphere::update(const UpdateData& data) { + if (_raycaster) { + + glm::mat4 transform = glm::translate(glm::mat4(1.0), static_cast(_translation) * std::pow(10.0f, static_cast(_scalingExponent))); + glm::vec3 eulerRotation = static_cast(_rotation); + transform = glm::rotate(transform, eulerRotation.x, glm::vec3(1, 0, 0)); + transform = glm::rotate(transform, eulerRotation.y, glm::vec3(0, 1, 0)); + transform = glm::rotate(transform, eulerRotation.z, glm::vec3(0, 0, 1)); + transform = glm::scale(transform, static_cast(_scaling) * std::pow(10.0f, static_cast(_scalingExponent))); + + _raycaster->setColor(_color); + _raycaster->setStepSize(_stepSize); + _raycaster->setModelTransform(transform); + _raycaster->setTime(data.time); + } +} + +void RenderableAtmosphere::render(const RenderData& data, RendererTasks& tasks) { + RaycasterTask task{ _raycaster.get(), data }; + tasks.raycasterTasks.push_back(task); +} + +} diff --git a/modules/atmosphere/rendering/renderableatmosphere.h b/modules/atmosphere/rendering/renderableatmosphere.h new file mode 100644 index 0000000000..6ed3df9b61 --- /dev/null +++ b/modules/atmosphere/rendering/renderableatmosphere.h @@ -0,0 +1,62 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __RENDERABLEATMOSPHERE_H__ +#define __RENDERABLEATMOSPHERE_H__ + +#include +#include +#include + +#include +#include + +namespace openspace { + +struct RenderData; + +class RenderableAtmosphere : public Renderable { +public: + RenderableAtmosphere(const ghoul::Dictionary& dictionary); + ~RenderableAtmosphere(); + + bool initialize() override; + bool deinitialize() override; + bool isReady() const override; + void render(const RenderData& data, RendererTasks& tasks) override; + void update(const UpdateData& data) override; + +private: + properties::Vec3Property _scaling; + properties::IntProperty _scalingExponent; + properties::FloatProperty _stepSize; + properties::Vec3Property _translation; + properties::Vec3Property _rotation; + properties::Vec4Property _color; + + std::unique_ptr _raycaster; +}; +} + +#endif // __RENDERABLEATMOSPHERE_H__ diff --git a/modules/atmosphere/shaders/boundsfs.glsl b/modules/atmosphere/shaders/boundsfs.glsl new file mode 100644 index 0000000000..bb4f9c8cd3 --- /dev/null +++ b/modules/atmosphere/shaders/boundsfs.glsl @@ -0,0 +1,40 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +in vec3 vPosition; +in vec4 worldPosition; + +#include "PowerScaling/powerScaling_fs.hglsl" +#include "fragment.glsl" + +Fragment getFragment() { + vec4 fragColor = vec4(vPosition+0.5, 1.0); + vec4 position = worldPosition; + float depth = pscDepth(position); + + Fragment frag; + frag.color = fragColor; + frag.depth = depth; + return frag; +} diff --git a/modules/atmosphere/shaders/boundsvs.glsl b/modules/atmosphere/shaders/boundsvs.glsl new file mode 100644 index 0000000000..ab1cd161f7 --- /dev/null +++ b/modules/atmosphere/shaders/boundsvs.glsl @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +layout(location = 0) in vec4 vertPosition; + +uniform mat4 viewProjection; +uniform mat4 modelTransform; + +out vec3 vPosition; +out vec4 worldPosition; + +#include "PowerScaling/powerScaling_vs.hglsl" + +void main() { + vPosition = vertPosition.xyz; + worldPosition = modelTransform*vertPosition; + + vec4 position = pscTransform(worldPosition, mat4(1.0)); + + // project the position to view space + gl_Position = viewProjection * position; + + gl_Position.z = 1.0; +} diff --git a/modules/atmosphere/shaders/raycast.glsl b/modules/atmosphere/shaders/raycast.glsl new file mode 100644 index 0000000000..28c53a33d7 --- /dev/null +++ b/modules/atmosphere/shaders/raycast.glsl @@ -0,0 +1,77 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + + +uniform vec4 color#{id}; +uniform float time#{id}; +uniform float maxStepSize#{id} = 0.02; + +void sample#{id}(vec3 samplePos, + vec3 dir, + inout vec3 accumulatedColor, + inout vec3 accumulatedAlpha, + inout float stepSize) { + + // Generate a procedural placeholder volume. + // In real situations, the sample function would sample a + // 3D texture to retrieve the color contribution of a given point. + + vec3 fromCenter = vec3(0.5, 0.5, 0.5) - samplePos; + + float theta = atan(fromCenter.x, fromCenter.z); + float angularRatio = (theta + 3.1415) / 6.283; + angularRatio = mod(angularRatio + time#{id}*0.01, 1.0); + + + float timeWave = sin(mod(time#{id}*0.05, 2.0 * 3.1415)); + float rDisplacement = 0.1 * timeWave; + + vec4 c = color#{id}; + float r = length(fromCenter); + c.a *= (1.0 - smoothstep(0.35 + rDisplacement, 0.40 + rDisplacement, r)); + c.a *= (1.0 - smoothstep(0.30 + rDisplacement, 0.25 + rDisplacement, r)); + c.a *= (1.0 - smoothstep(0.1, 0.2, abs(fromCenter.y) / angularRatio * 0.5)); + + c.a *= 1.0 - smoothstep(0.0, 1.0, clamp(angularRatio, 0.0, 1.0)); + c.a *= smoothstep(0.0, 0.1, clamp(angularRatio, 0.0, 1.0)); + + vec3 backAlpha = c.aaa * 10.0; + vec3 backColor = c.rgb * backAlpha; + + backColor *= stepSize; + backAlpha *= stepSize; + + backColor = clamp(backColor, 0.0, 1.0); + backAlpha = clamp(backAlpha, 0.0, 1.0); + + vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha; + accumulatedColor += oneMinusFrontAlpha * backColor; + accumulatedAlpha += oneMinusFrontAlpha * backAlpha; + + stepSize = maxStepSize#{id}; +} + +float stepSize#{id}(vec3 samplePos, vec3 dir) { + return maxStepSize#{id}; +}