mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-02 16:59:37 -05:00
Planet Shadows
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
function preInitialization()
|
||||
--[[
|
||||
The scripts in this function are executed after the scene is loaded but before the
|
||||
scene elements have been initialized, thus they should be used to set the time at
|
||||
which the scene should start and other settings that might determine initialization
|
||||
critical objects.
|
||||
]]--
|
||||
|
||||
--YYYY-MM-DDTHH:MN:SS
|
||||
--openspace.time.setTime(openspace.time.currentWallTime())
|
||||
--[[
|
||||
-- March 9, 2016 total eclipse times from land
|
||||
-- Palembang, South Sumatra, Indonesia
|
||||
-- Partial solar eclipse begins: 6:20 a.m. local Western Indonesian Time
|
||||
-- Total solar eclipse begins: 7:20 a.m. local time
|
||||
-- Maximum eclipse: 7:21 a.m. local time
|
||||
-- Total solar eclipse ends: 7:22 a.m. local time
|
||||
-- Partial solar eclipse ends: 8:31 a.m. local time
|
||||
|
||||
-- 6:20 -> 23:20 day before in UTC
|
||||
]]--
|
||||
openspace.time.setTime("2016-03-08T23:00:00")
|
||||
openspace.time.setDeltaTime(500.0)
|
||||
dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua'))
|
||||
end
|
||||
|
||||
function postInitialization()
|
||||
--[[
|
||||
The scripts in this function are executed after all objects in the scene have been
|
||||
created and initialized, but before the first render call. This is the place to set
|
||||
graphical settings for the renderables.
|
||||
]]--
|
||||
openspace.printInfo("Setting default values")
|
||||
openspace.setPropertyValue("Sun.renderable.enabled", false)
|
||||
openspace.setPropertyValue("SunMarker.renderable.enabled", false)
|
||||
openspace.setPropertyValue("EarthMarker.renderable.enabled", false)
|
||||
--openspace.setPropertyValue("Constellation Bounds.renderable.enabled", false)
|
||||
openspace.setPropertyValue("PlutoTrail.renderable.enabled", false)
|
||||
openspace.setPropertyValue("PlutoTexture.renderable.enabled", false)
|
||||
|
||||
openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.55)
|
||||
openspace.setPropertyValue("MilkyWay.renderable.segments", 50)
|
||||
|
||||
openspace.printInfo("Done setting default values")
|
||||
end
|
||||
|
||||
return {
|
||||
ScenePath = ".",
|
||||
CommonFolder = "common",
|
||||
Camera = {
|
||||
Focus = "Earth",
|
||||
Position = {1, 0, 0, 5},
|
||||
},
|
||||
Modules = {
|
||||
"sun",
|
||||
"mercury",
|
||||
"venus",
|
||||
"earth",
|
||||
"moon",
|
||||
"mars",
|
||||
"jupiter",
|
||||
"saturn",
|
||||
"uranus",
|
||||
"neptune",
|
||||
"stars",
|
||||
-- "stars-denver",
|
||||
"milkyway",
|
||||
-- "milkyway-eso",
|
||||
--"constellationbounds",
|
||||
-- "fieldlines",
|
||||
--"io",
|
||||
--"europa",
|
||||
--"ganymede",
|
||||
--"callisto",
|
||||
--"gridGalactic",
|
||||
--"gridEcliptic",
|
||||
--"gridEquatorial",
|
||||
}
|
||||
}
|
||||
|
||||
+24
-26
@@ -4,21 +4,15 @@ return {
|
||||
Name = "EarthBarycenter",
|
||||
Parent = "SolarSystemBarycenter",
|
||||
Static = true,
|
||||
--[[
|
||||
Ephemeris = {
|
||||
Type = "Kepler",
|
||||
Inclination = 0.00041,
|
||||
AscendingNode = 349.2,
|
||||
Perihelion = 102.8517,
|
||||
SemiMajorAxis = 1.00002,
|
||||
DailyMotion = 0.9855796,
|
||||
Eccentricity = 0.0166967,
|
||||
MeanLongitude = 328.40353
|
||||
}
|
||||
--]]
|
||||
Ephemeris = {
|
||||
Type = "Static"
|
||||
}
|
||||
Type = "Spice",
|
||||
Body = "EARTH BARYCENTER",
|
||||
Reference = "ECLIPJ2000",
|
||||
Observer = "SUN",
|
||||
Kernels = {
|
||||
"${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"
|
||||
}
|
||||
},
|
||||
},
|
||||
-- Earth module
|
||||
{
|
||||
@@ -27,16 +21,28 @@ return {
|
||||
Renderable = {
|
||||
Type = "RenderablePlanet",
|
||||
Frame = "IAU_EARTH",
|
||||
Body = "EARTH",
|
||||
Body = "EARTH",
|
||||
Geometry = {
|
||||
Type = "SimpleSphere",
|
||||
Radius = { 6.371, 6 },
|
||||
Segments = 100
|
||||
},
|
||||
Shadow_Group = {
|
||||
Source1 = {
|
||||
Name = "Sun",
|
||||
Radius = {696.3, 6}
|
||||
},
|
||||
--Source2 = { Name = "Monolith", Radius = {0.01, 6} },
|
||||
Caster1 = {
|
||||
Name = "Moon",
|
||||
Radius = {1.737, 6}
|
||||
},
|
||||
--Caster2 = { Name = "Independency Day Ship", Radius = {0.0, 0.0} }
|
||||
},
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "textures/earth_bluemarble.jpg",
|
||||
Night = "textures/earth_night.jpg",
|
||||
Night = "textures/earth_night.jpg",
|
||||
-- Depth = "textures/earth_depth.png"
|
||||
},
|
||||
Atmosphere = {
|
||||
@@ -45,15 +51,7 @@ return {
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
Body = "EARTH",
|
||||
Reference = "ECLIPJ2000",
|
||||
Observer = "SUN",
|
||||
Kernels = {
|
||||
"${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"
|
||||
}
|
||||
},
|
||||
|
||||
GuiName = "/Solar/Planets/Earth"
|
||||
},
|
||||
-- EarthTrail module
|
||||
@@ -82,7 +80,7 @@ return {
|
||||
Billboard = true,
|
||||
Texture = "textures/marker.png"
|
||||
},
|
||||
Ephemeris = {
|
||||
Ephemeris = {
|
||||
Type = "Static",
|
||||
Position = {0, 0, 0, 5}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
return {
|
||||
FileRequest = {
|
||||
{ Identifier = "moon_textures", Destination = "textures", Version = 1 }
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
return {
|
||||
-- Moon module
|
||||
{
|
||||
Name = "Moon",
|
||||
Parent = "EarthBarycenter",
|
||||
Renderable = {
|
||||
Type = "RenderablePlanet",
|
||||
Frame = "IAU_MOON",
|
||||
Body = "MOON",
|
||||
Geometry = {
|
||||
Type = "SimpleSphere",
|
||||
Radius = { 1.737, 6},
|
||||
Segments = 100
|
||||
},
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "textures/Moon16K.dds",
|
||||
--Color = "textures/moonmap4k.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
Body = "MOON",
|
||||
Reference = "ECLIPJ2000",
|
||||
Observer = "EARTH BARYCENTER",
|
||||
Kernels = {
|
||||
"${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"
|
||||
}
|
||||
},
|
||||
Rotation = {
|
||||
Type = "Spice",
|
||||
Frame = "IAU_MOON",
|
||||
Reference = "ECLIPJ2000"
|
||||
},
|
||||
GuiName = "/Solar/Planets/MOON"
|
||||
},
|
||||
-- MoonTrail module
|
||||
{
|
||||
Name = "MoonTrail",
|
||||
Parent = "EarthBarycenter",
|
||||
Renderable = {
|
||||
Type = "RenderableTrail",
|
||||
Body = "MOON",
|
||||
Frame = "GALACTIC",
|
||||
Observer = "EARTH BARYCENTER",
|
||||
RGB = { 0.5, 0.3, 0.3 },
|
||||
TropicalOrbitPeriod = 60,
|
||||
EarthOrbitRatio = 0.01,
|
||||
DayLength = 1.0,
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "${COMMON_MODULE}/textures/glare_blue.png",
|
||||
-- need to add different texture
|
||||
},
|
||||
},
|
||||
GuiName = "/Solar/MoonTrail"
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,11 @@ namespace {
|
||||
|
||||
const std::string keyFrame = "Frame";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
const std::string keyRadius = "Radius";
|
||||
const std::string keyShading = "PerformShading";
|
||||
const std::string keyShadowGroup = "Shadow_Group";
|
||||
const std::string keyShadowSource = "Source";
|
||||
const std::string keyShadowCaster = "Caster";
|
||||
|
||||
const std::string keyBody = "Body";
|
||||
}
|
||||
@@ -65,8 +69,9 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
, _alpha(1.f)
|
||||
, _planetRadius(0.f)
|
||||
, _nightTexturePath("")
|
||||
, _hasNightTexture(false)
|
||||
, _hasNightTexture(false)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
@@ -84,6 +89,13 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
|
||||
//geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
|
||||
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
|
||||
|
||||
glm::vec2 planetRadiusVec;
|
||||
success = geometryDictionary.getValue(keyRadius, planetRadiusVec);
|
||||
if (success)
|
||||
_planetRadius = planetRadiusVec[0] * glm::pow(10, planetRadiusVec[1]);
|
||||
else
|
||||
LWARNING("No Radius value expecified for " << name << " planet.");
|
||||
}
|
||||
|
||||
dictionary.getValue(keyFrame, _frame);
|
||||
@@ -120,6 +132,79 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_performShading);
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
|
||||
|
||||
// Shadow data:
|
||||
ghoul::Dictionary shadowDictionary;
|
||||
success = dictionary.getValue(keyShadowGroup, shadowDictionary);
|
||||
if (success) {
|
||||
std::vector< std::pair<std::string, float > > sourceArray;
|
||||
unsigned int sourceCounter = 1;
|
||||
while (success) {
|
||||
std::string sourceName;
|
||||
std::stringstream ss;
|
||||
ss << keyShadowSource << sourceCounter << ".Name";
|
||||
success = shadowDictionary.getValue(ss.str(), sourceName);
|
||||
if (success) {
|
||||
glm::vec2 sourceRadius;
|
||||
ss.str(std::string());
|
||||
ss << keyShadowSource << sourceCounter << ".Radius";
|
||||
success = shadowDictionary.getValue(ss.str(), sourceRadius);
|
||||
if (success) {
|
||||
sourceArray.push_back(std::pair< std::string, float>(sourceName, sourceRadius[0] * glm::pow(10, sourceRadius[1])));
|
||||
}
|
||||
else {
|
||||
// TODO: handle not success
|
||||
;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO: handle not success
|
||||
;
|
||||
}
|
||||
|
||||
sourceCounter++;
|
||||
}
|
||||
|
||||
success = true;
|
||||
|
||||
std::vector< std::pair<std::string, float > > casterArray;
|
||||
unsigned int casterCounter = 1;
|
||||
while (success) {
|
||||
std::string casterName;
|
||||
std::stringstream ss;
|
||||
ss << keyShadowCaster << casterCounter << ".Name";
|
||||
success = shadowDictionary.getValue(ss.str(), casterName);
|
||||
if (success) {
|
||||
glm::vec2 casterRadius;
|
||||
ss.str(std::string());
|
||||
ss << keyShadowCaster << casterCounter << ".Radius";
|
||||
success = shadowDictionary.getValue(ss.str(), casterRadius);
|
||||
if (success) {
|
||||
casterArray.push_back(std::pair< std::string, float>(casterName, casterRadius[0] * glm::pow(10, casterRadius[1])));
|
||||
}
|
||||
else {
|
||||
// TODO: handle not success
|
||||
;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO: handle not success
|
||||
;
|
||||
}
|
||||
|
||||
casterCounter++;
|
||||
}
|
||||
|
||||
for ( const auto & source : sourceArray )
|
||||
for (const auto & caster : casterArray) {
|
||||
ShadowConf sc;
|
||||
sc.source = source;
|
||||
sc.caster = caster;
|
||||
_shadowConfArray.push_back(sc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RenderablePlanet::~RenderablePlanet() {
|
||||
@@ -127,13 +212,32 @@ RenderablePlanet::~RenderablePlanet() {
|
||||
|
||||
bool RenderablePlanet::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject == nullptr && _hasNightTexture) {
|
||||
|
||||
if (_programObject == nullptr && !_shadowConfArray.empty() && _hasNightTexture) {
|
||||
// shadow program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"shadowNightProgram",
|
||||
"${MODULE_BASE}/shaders/shadow_nighttexture_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/shadow_nighttexture_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
else if (_programObject == nullptr && !_shadowConfArray.empty()) {
|
||||
// shadow program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"shadowProgram",
|
||||
"${MODULE_BASE}/shaders/shadow_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/shadow_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
else if (_programObject == nullptr && _hasNightTexture) {
|
||||
// Night texture program
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"nightTextureProgram",
|
||||
"${MODULE_BASE}/shaders/nighttexture_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/nighttexture_fs.glsl");
|
||||
if (!_programObject)
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
else if (_programObject == nullptr) {
|
||||
@@ -142,8 +246,8 @@ bool RenderablePlanet::initialize() {
|
||||
"pscstandard",
|
||||
"${MODULE_BASE}/shaders/pscstandard_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/pscstandard_fs.glsl");
|
||||
if (!_programObject) return false;
|
||||
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
@@ -199,18 +303,28 @@ void RenderablePlanet::render(const RenderData& data)
|
||||
}
|
||||
}
|
||||
transform = transform * rot * roty * rotProp;
|
||||
|
||||
//glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
|
||||
//glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
|
||||
|
||||
|
||||
// setup the data to the shader
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt);
|
||||
p *= 1000.0; // from Km to m
|
||||
psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
|
||||
// setup the data to the shader
|
||||
// _programObject->setUniform("camdir", camSpaceEye);
|
||||
//_programObject->setUniform("light_dir", sun_pos.vec4());
|
||||
|
||||
glm::dvec3 pt =
|
||||
SpiceManager::ref().targetPosition(_target, "SUN", "GALACTIC", {}, _time, lt);
|
||||
psc tmppos = PowerScaledCoordinate::CreatePowerScaledCoordinate(pt.x, pt.y, pt.z);
|
||||
glm::vec3 cam_dir = glm::normalize(data.camera.position().vec3() - tmppos.vec3());
|
||||
|
||||
// This is camera position vector (camera direction) in world coordinates.
|
||||
//_programObject->setUniform("cam_dir", cam_dir);
|
||||
|
||||
//glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
|
||||
//glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
|
||||
//_programObject->setUniform("camdir", camSpaceEye);
|
||||
|
||||
_programObject->setUniform("transparency", _alpha);
|
||||
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_programObject->setUniform("ModelTransform", transform);
|
||||
@@ -235,6 +349,74 @@ void RenderablePlanet::render(const RenderData& data)
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// Shadow calculations..
|
||||
if (!_shadowConfArray.empty()) {
|
||||
std::vector<ShadowRenderingStruct> shadowDataArray;
|
||||
shadowDataArray.reserve(_shadowConfArray.size());
|
||||
|
||||
for (const auto & shadowConf : _shadowConfArray) {
|
||||
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!! We need to move this to view space...
|
||||
// Getting source and caster:
|
||||
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(shadowConf.source.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
sourcePos *= 1000.0; // converting to meters
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(shadowConf.caster.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
casterPos *= 1000.0; // converting to meters
|
||||
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(casterPos.x, casterPos.y, casterPos.z);
|
||||
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all calculations in World Coordinates):
|
||||
glm::vec3 planetCasterVec = (caster_pos - data.position).vec3();
|
||||
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
|
||||
float sc_length = glm::length(sourceCasterVec);
|
||||
glm::vec3 planetCaster_proj = (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * sourceCasterVec;
|
||||
float d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
float xp_test = shadowConf.caster.second * sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
float rp_test = shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
ShadowRenderingStruct shadowData;
|
||||
shadowData.isShadowing = false;
|
||||
if ((d_test - rp_test) < _planetRadius) {
|
||||
// The current caster is shadowing the current planet
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second;
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.sourceCasterVec = sourceCasterVec;
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = glm::vec3(casterPos);
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
}
|
||||
|
||||
const std::string uniformVarName("shadowDataArray[");
|
||||
unsigned int counter = 0;
|
||||
for (const auto & sd : shadowDataArray) {
|
||||
std::stringstream ss;
|
||||
ss << uniformVarName << counter << "].isShadowing";
|
||||
_programObject->setUniform(ss.str(), sd.isShadowing);
|
||||
if (sd.isShadowing) {
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].xp";
|
||||
_programObject->setUniform(ss.str(), sd.xp);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].xu";
|
||||
_programObject->setUniform(ss.str(), sd.xu);
|
||||
/*ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].rs";
|
||||
_programObject->setUniform(ss.str(), sd.rs);*/
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].rc";
|
||||
_programObject->setUniform(ss.str(), sd.rc);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].sourceCasterVec";
|
||||
_programObject->setUniform(ss.str(), sd.sourceCasterVec);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].casterPositionVec";
|
||||
_programObject->setUniform(ss.str(), sd.casterPositionVec);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
// render
|
||||
_geometry->render();
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// ghoul includes
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -46,6 +49,21 @@ class PlanetGeometry;
|
||||
}
|
||||
|
||||
class RenderablePlanet : public Renderable {
|
||||
public:
|
||||
// Shadow structure
|
||||
typedef struct {
|
||||
std::pair<std::string, float> source;
|
||||
std::pair<std::string, float> caster;
|
||||
} ShadowConf;
|
||||
|
||||
struct ShadowRenderingStruct {
|
||||
float xu, xp;
|
||||
float rs, rc;
|
||||
glm::vec3 sourceCasterVec;
|
||||
glm::vec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
};
|
||||
|
||||
public:
|
||||
RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanet();
|
||||
@@ -69,6 +87,8 @@ private:
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
float _alpha;
|
||||
std::vector< ShadowConf > _shadowConfArray;
|
||||
float _planetRadius;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
std::string _nightTexturePath;
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
const uint numberOfShadows = 1;
|
||||
|
||||
struct ShadowRenderingStruct {
|
||||
float xu, xp;
|
||||
float rs, rc;
|
||||
vec3 sourceCasterVec;
|
||||
vec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
};
|
||||
|
||||
uniform ShadowRenderingStruct shadowDataArray[numberOfShadows];
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
uniform bool _performShading = true;
|
||||
uniform float transparency;
|
||||
uniform int shadows;
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec2 vs_nightTex;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
in vec4 vs_posWorld;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
vec4 butterworthFunc(const float d, const float r, const float n) {
|
||||
return vec4(vec3(sqrt(r/(r + pow(d, 2*n)))), 1.0);
|
||||
}
|
||||
|
||||
vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows], const vec3 position) {
|
||||
if (shadowInfoArray[0].isShadowing) {
|
||||
vec3 pc = shadowInfoArray[0].casterPositionVec - position;
|
||||
vec3 sc_norm = normalize(shadowInfoArray[0].sourceCasterVec); // we can pass this normalized to the shader
|
||||
vec3 pc_proj = dot(pc, sc_norm) * sc_norm;
|
||||
vec3 d = pc - pc_proj;
|
||||
|
||||
float length_d = length(d);
|
||||
float length_pc_proj = length(pc_proj);
|
||||
|
||||
float r_p_pi = shadowInfoArray[0].rc * (length_pc_proj + shadowInfoArray[0].xp) / shadowInfoArray[0].xp;
|
||||
|
||||
//float r_u_pi = shadowInfoArray[0].rc * (length_pc_proj + shadowInfoArray[0].xu) / shadowInfoArray[0].xu;
|
||||
float r_u_pi = shadowInfoArray[0].rc * (shadowInfoArray[0].xu - length_pc_proj) / shadowInfoArray[0].xu;
|
||||
|
||||
if ( length_d < r_u_pi ) { // umbra
|
||||
return vec4(0.0, 0.0, 0.0, 1.0);
|
||||
//return vec4(1.0, 0.0, 0.0, 1.0);
|
||||
//return butterworthFunc(length_d, r_u_pi, 4.0);
|
||||
}
|
||||
else if ( length_d < r_p_pi ) {// penumbra
|
||||
return vec4(0.5, 0.5, 0.5, 1.0);
|
||||
//return vec4(0.0, 1.0, 0.0, 1.0);
|
||||
//return vec4(vec3(length_d/r_p_pi), 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
return vec4(1.0);
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse = texture(texture1, vs_st);
|
||||
vec4 diffuse2 = texture(nightTex, vs_st);
|
||||
|
||||
Fragment frag;
|
||||
if (_performShading) {
|
||||
// directional lighting
|
||||
vec3 origin = vec3(0.0);
|
||||
vec4 spec = vec4(0.0);
|
||||
|
||||
vec3 n = normalize(vs_normal.xyz);
|
||||
//vec3 e = normalize(camdir);
|
||||
vec3 l_pos = vec3(sun_pos); // sun.
|
||||
vec3 l_dir = normalize(l_pos-objpos.xyz);
|
||||
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
|
||||
float darkSide = min(max(5*dot(n,-l_dir), 0.0), 1);
|
||||
|
||||
float shine = 0.0001;
|
||||
|
||||
vec4 specular = vec4(0.5);
|
||||
vec4 ambient = vec4(0.0,0.0,0.0,transparency);
|
||||
|
||||
vec4 daytex = max(intensity * diffuse, ambient);
|
||||
vec4 mixtex = mix(diffuse, diffuse2, (1+dot(n,-l_dir))/2);
|
||||
|
||||
diffuse = (daytex*2 + mixtex)/3;
|
||||
|
||||
diffuse *= calcShadow(shadowDataArray, vs_posWorld.xyz);
|
||||
}
|
||||
|
||||
diffuse[3] = transparency;
|
||||
frag.color = diffuse;
|
||||
frag.depth = depth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
//layout(location = 3) in vec2 in_nightTex;
|
||||
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
out vec4 vs_posWorld;
|
||||
out float s;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
// set variables
|
||||
vs_st = in_st;
|
||||
vs_position = in_position;
|
||||
vec4 tmp = in_position;
|
||||
|
||||
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
|
||||
|
||||
// The things is not in world coordinates, they are in
|
||||
// regular view/eye coordinates.
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
|
||||
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz;
|
||||
vec4 vP = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
|
||||
vec4 conv = vec4(vP.xyz * pow(10,vP.w), 1.0);
|
||||
vs_posWorld = conv;
|
||||
|
||||
vs_position = tmp;
|
||||
// Now is transforming from view position to SGCT projection
|
||||
// coordinates.
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
+2
-1
@@ -7,7 +7,8 @@ return {
|
||||
|
||||
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
|
||||
-- of all entities that will be visible during an instance of OpenSpace
|
||||
Scene = "${SCENE}/newhorizons.scene",
|
||||
--Scene = "${SCENE}/newhorizons.scene",
|
||||
Scene = "${SCENE}/default-moon.scene",
|
||||
|
||||
Paths = {
|
||||
SGCT = "${BASE_PATH}/config/sgct",
|
||||
|
||||
Reference in New Issue
Block a user