mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Merge branch 'feature/globebrowsing' of github.com:OpenSpace/OpenSpace-Development into feature/globebrowsing
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -89,6 +89,9 @@ data/scene/earth/textures/earth_bluemarble.jpg
|
||||
data/scene/earth/textures/earth_bluemarble_height.jpg
|
||||
data/scene/earth/textures/earth_night.jpg
|
||||
data/scene/earth/textures/marker.png
|
||||
data/scene/earth/textures/earth_clouds.jpg
|
||||
data/scene/earth/textures/earth_reflectance.png
|
||||
data/scene/moon/textures/Moon16k.dds
|
||||
data/scene/newhorizons/jupiter/europa/textures/europa.jpg
|
||||
data/scene/newhorizons/jupiter/ganymede/textures/ganymede.jpg
|
||||
data/scene/newhorizons/jupiter/io/textures/io.jpg
|
||||
|
||||
89
data/scene/default-moon.scene
Normal file
89
data/scene/default-moon.scene
Normal file
@@ -0,0 +1,89 @@
|
||||
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-08T22:45:00")
|
||||
|
||||
|
||||
-- Total Lunar Eclipse Jan 31, 2018 at 10:51:13 UTC
|
||||
-- Regions seeing, at least, some parts of the eclipse: North/East Europe,
|
||||
-- Asia, Australia, North/East Africa, North America, North/East South America,
|
||||
-- Pacific, Atlantic, Indian Ocean, Arctic, Antarctica.
|
||||
--openspace.time.setTime("2018-01-31T10:30:00")
|
||||
|
||||
--openspace.time.setDeltaTime(200.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",
|
||||
--Focus = "Moon",
|
||||
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",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
return {
|
||||
FileRequest = {
|
||||
{ Identifier = "earth_textures", Destination = "textures", Version = 1 }
|
||||
{ Identifier = "earth_textures", Destination = "textures", Version = 2 }
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,33 +21,88 @@ 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",
|
||||
-- All radius in meters
|
||||
Radius = {696.3, 6}
|
||||
},
|
||||
--Source2 = { Name = "Monolith", Radius = {0.01, 6} },
|
||||
Caster1 = {
|
||||
Name = "Moon",
|
||||
-- All radius in meters
|
||||
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",
|
||||
Height = "textures/earth_bluemarble_height.jpg"
|
||||
Night = "textures/earth_night.jpg",
|
||||
--Height = "textures/earth_bluemarble_height.jpg",
|
||||
-- Depth = "textures/earth_depth.png",
|
||||
Reflectance = "textures/earth_reflectance.png",
|
||||
Clouds = "textures/earth_clouds.jpg"
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
Body = "EARTH",
|
||||
Reference = "ECLIPJ2000",
|
||||
Observer = "SUN",
|
||||
Kernels = {
|
||||
"${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"
|
||||
-- Atmosphere radius in Km
|
||||
AtmoshereRadius = 6420,
|
||||
--AtmoshereRadius = 6390,
|
||||
--PlanetRadius = 6371,
|
||||
PlanetRadius = 6360,
|
||||
PlanetAverageGroundReflectance = 0.1,
|
||||
Rayleigh = {
|
||||
Coefficients = {
|
||||
-- Wavelengths are given in 10^-9m
|
||||
Wavelengths = {680, 550, 440},
|
||||
-- Reflection coefficients are given in km^-1
|
||||
Scattering = {5.8e-3, 1.35e-2, 3.31e-2},
|
||||
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
|
||||
},
|
||||
-- Thichkness of atmosphere if its density were uniform, in Km
|
||||
H_R = 8.0,
|
||||
},
|
||||
-- Default
|
||||
Mie = {
|
||||
Coefficients = {
|
||||
-- Reflection coefficients are given in km^-1
|
||||
Scattering = {4e-3, 4e-3, 4e-3},
|
||||
--Scattering = {2e-5, 2e-5, 2e-5},
|
||||
-- Extinction coefficients are a fraction of the Scattering coefficients
|
||||
Extinction = {4e-3/0.9, 4e-3/0.9, 4e-3/0.9}
|
||||
-- Height scale (atmosphere thickness for constant density) in Km
|
||||
},
|
||||
H_M = 1.2,
|
||||
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
|
||||
G = 1.0,
|
||||
},
|
||||
-- Clear Sky
|
||||
-- Mie = {
|
||||
-- Coefficients = {
|
||||
-- Scattering = {20e-3, 20e-3, 20e-3},
|
||||
-- Extinction = 1.0/0.9,
|
||||
-- }
|
||||
-- H_M = 1.2,
|
||||
-- G = 0.76,
|
||||
-- },
|
||||
-- Cloudy
|
||||
-- Mie = {
|
||||
-- Coefficients = {
|
||||
-- Scattering = {3e-3, 3e-3, 3e-3},
|
||||
-- Extinction = 1.0/0.9,
|
||||
-- }
|
||||
-- H_M = 3.0,
|
||||
-- G = 0.65,
|
||||
-- },
|
||||
}
|
||||
},
|
||||
|
||||
GuiName = "/Solar/Planets/Earth"
|
||||
},
|
||||
-- EarthTrail module
|
||||
@@ -82,7 +131,7 @@ return {
|
||||
Billboard = true,
|
||||
Texture = "textures/marker.png"
|
||||
},
|
||||
Ephemeris = {
|
||||
Ephemeris = {
|
||||
Type = "Static",
|
||||
Position = {0, 0, 0, 5}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,6 @@ return {
|
||||
Type = "simple",
|
||||
Color = "textures/mars.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
|
||||
@@ -25,11 +25,6 @@ return {
|
||||
Type = "simple",
|
||||
Color = "textures/mercury.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
|
||||
5
data/scene/moon/moon.data
Normal file
5
data/scene/moon/moon.data
Normal file
@@ -0,0 +1,5 @@
|
||||
return {
|
||||
FileRequest = {
|
||||
{ Identifier = "moon_textures", Destination = "textures", Version = 1 }
|
||||
},
|
||||
}
|
||||
68
data/scene/moon/moon.mod
Normal file
68
data/scene/moon/moon.mod
Normal file
@@ -0,0 +1,68 @@
|
||||
return {
|
||||
-- Moon module
|
||||
{
|
||||
Name = "Moon",
|
||||
Parent = "EarthBarycenter",
|
||||
Renderable = {
|
||||
Type = "RenderablePlanet",
|
||||
Frame = "IAU_MOON",
|
||||
Body = "MOON",
|
||||
Geometry = {
|
||||
Type = "SimpleSphere",
|
||||
Radius = { 1.737, 6},
|
||||
Segments = 100
|
||||
},
|
||||
Shadow_Group = {
|
||||
Source1 = {
|
||||
Name = "Sun",
|
||||
Radius = {696.3, 6}
|
||||
},
|
||||
Caster1 = {
|
||||
Name = "Earth",
|
||||
Radius = {6.371, 6}
|
||||
},
|
||||
},
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "textures/Moon16K.dds",
|
||||
--Color = "textures/moonmap4k.jpg",
|
||||
},
|
||||
},
|
||||
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"
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,6 @@ return {
|
||||
Type = "simple",
|
||||
Color = "textures/neptune.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
|
||||
@@ -25,11 +25,6 @@ return {
|
||||
Type = "simple",
|
||||
Color = "textures/saturn.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
|
||||
@@ -25,11 +25,6 @@ return {
|
||||
Type = "simple",
|
||||
Color = "textures/uranus.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
|
||||
@@ -25,11 +25,6 @@ return {
|
||||
Type = "simple",
|
||||
Color = "textures/venus.jpg",
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Ephemeris = {
|
||||
Type = "Spice",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,11 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// ghoul includes
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -46,6 +51,53 @@ 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;
|
||||
};
|
||||
|
||||
// See: Precomputed Atmospheric Scattering from Bruneton et al.
|
||||
// for explanation of the following parameters.
|
||||
|
||||
const unsigned int TRANSMITTANCE_TABLE_WIDTH = 256;
|
||||
const unsigned int TRANSMITTANCE_TABLE_HEIGHT = 64;
|
||||
|
||||
const unsigned int IRRADIANCE_TABLE_WIDTH = 64;
|
||||
const unsigned int IRRADIANCE_TABLE_HEIGHT = 16;
|
||||
|
||||
const unsigned int DELTA_E_TABLE_WIDTH = 64;
|
||||
const unsigned int DELTA_E_TABLE_HEIGHT = 16;
|
||||
|
||||
|
||||
/*const unsigned int TRANSMITTANCE_TABLE_WIDTH = 512;
|
||||
const unsigned int TRANSMITTANCE_TABLE_HEIGHT = 128;
|
||||
|
||||
const unsigned int IRRADIANCE_TABLE_WIDTH = 128;
|
||||
const unsigned int IRRADIANCE_TABLE_HEIGHT = 32;
|
||||
|
||||
const unsigned int DELTA_E_TABLE_WIDTH = 128;
|
||||
const unsigned int DELTA_E_TABLE_HEIGHT = 32;*/
|
||||
|
||||
const unsigned int R_SAMPLES = 32;
|
||||
const unsigned int MU_SAMPLES = 128;
|
||||
const unsigned int MU_S_SAMPLES = 32;
|
||||
const unsigned int NU_SAMPLES = 8;
|
||||
|
||||
/*const unsigned int R_SAMPLES = 64;
|
||||
const unsigned int MU_SAMPLES = 256;
|
||||
const unsigned int MU_S_SAMPLES = 64;
|
||||
const unsigned int NU_SAMPLES = 16;*/
|
||||
|
||||
public:
|
||||
RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanet();
|
||||
@@ -60,15 +112,69 @@ public:
|
||||
protected:
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
void loadComputationPrograms();
|
||||
void unloadComputationPrograms();
|
||||
void createComputationTextures();
|
||||
void deleteComputationTextures();
|
||||
void deleteUnusedComputationTextures();
|
||||
void loadAtmosphereDataIntoShaderProgram(std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg);
|
||||
void executeCalculations(const GLuint vao, const GLenum drawBuffers[2], const GLsizei vertexSize);
|
||||
void preCalculateAtmosphereParam();
|
||||
void createAtmosphereFBO();
|
||||
void createRenderQuad(GLuint * vao, GLuint * vbo, const GLfloat size);
|
||||
void renderQuadForCalc(const GLuint vao, const GLsizei size);
|
||||
void step3DTexture(std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg,
|
||||
const int layer, const bool doCalc = true);
|
||||
void saveTextureToPPMFile(const GLenum color_buffer_attachment, const std::string & fileName,
|
||||
const int width, const int height) const;
|
||||
|
||||
private:
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::StringProperty _nightTexturePath;
|
||||
properties::StringProperty _heightMapTexturePath;
|
||||
properties::StringProperty _cloudsTexturePath;
|
||||
properties::StringProperty _reflectanceTexturePath;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _transmittanceProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _irradianceProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _irradianceSupTermsProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _inScatteringProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _inScatteringSupTermsProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaEProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaSProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaSSupTermsProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaJProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _atmosphereProgramObject;
|
||||
ghoul::opengl::TextureUnit _dummyTextureUnit;
|
||||
ghoul::opengl::TextureUnit _dummy3DTextureUnit;
|
||||
ghoul::opengl::TextureUnit _transmittanceTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _irradianceTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _inScatteringTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _deltaETableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _deltaSRayleighTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _deltaSMieTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _deltaJTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit _atmosphereTextureUnit;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _nightTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _reflectanceTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _heightMapTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _cloudsTexture;
|
||||
GLuint _transmittanceTableTexture;
|
||||
GLuint _irradianceTableTexture;
|
||||
GLuint _inScatteringTableTexture;
|
||||
GLuint _deltaETableTexture;
|
||||
GLuint _deltaSRayleighTableTexture;
|
||||
GLuint _deltaSMieTableTexture;
|
||||
GLuint _deltaJTableTexture;
|
||||
GLuint _dummyTexture;
|
||||
GLuint _dummy3DTexture;
|
||||
GLuint _atmosphereTexture;
|
||||
GLuint _atmosphereFBO;
|
||||
GLuint _atmosphereRenderVAO;
|
||||
GLuint _atmosphereRenderVBO;
|
||||
|
||||
properties::FloatProperty _heightExaggeration;
|
||||
|
||||
@@ -76,13 +182,36 @@ private:
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
float _alpha;
|
||||
std::vector< ShadowConf > _shadowConfArray;
|
||||
float _planetRadius;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
bool _hasNightTexture;
|
||||
bool _hasReflectanceTexture;
|
||||
bool _hasHeightTexture;
|
||||
bool _hasCloudsTexture;
|
||||
bool _shadowEnabled;
|
||||
double _time;
|
||||
|
||||
// Atmosphere Data
|
||||
bool _atmosphereCalculated;
|
||||
bool _atmosphereEnabled;
|
||||
float _atmosphereRadius;
|
||||
float _atmospherePlanetRadius;
|
||||
float _planetAverageGroundReflectance;
|
||||
float _rayleighHeightScale;
|
||||
float _mieHeightScale;
|
||||
float _miePhaseConstant;
|
||||
glm::vec3 _mieExtinctionCoeff;
|
||||
glm::vec3 _rayleighScatteringCoeff;
|
||||
glm::vec3 _mieScatteringCoeff;
|
||||
|
||||
|
||||
bool tempPic;
|
||||
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
85
modules/base/shaders/atmosphere_common.glsl
Normal file
85
modules/base/shaders/atmosphere_common.glsl
Normal file
@@ -0,0 +1,85 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
// Atmosphere Rendering Parameters
|
||||
uniform float Rg;
|
||||
uniform float Rt;
|
||||
uniform float AVERAGE_GROUND_REFLECTANCE;
|
||||
uniform float HR;
|
||||
uniform vec3 betaR;
|
||||
uniform float HM;
|
||||
uniform vec3 betaMSca;
|
||||
uniform vec3 betaMEx;
|
||||
uniform float mieG;
|
||||
|
||||
const float ATM_EPSILON = 1.0;
|
||||
// const float RL = Rt + 1.0;
|
||||
|
||||
// const float Rg = 6360.0;
|
||||
// const float Rt = 6420.0;
|
||||
// const float RL = 6421.0;
|
||||
// const float ATM_EPSILON = 1.0;
|
||||
|
||||
// const float AVERAGE_GROUND_REFLECTANCE = 0.1;
|
||||
|
||||
// // Rayleigh
|
||||
// const float HR = 8.0;
|
||||
// const vec3 betaR = vec3(5.8e-3, 1.35e-2, 3.31e-2);
|
||||
|
||||
// // Mie
|
||||
// // DEFAULT
|
||||
// const float HM = 1.2;
|
||||
// const vec3 betaMSca = vec3(4e-3);
|
||||
// //const vec3 betaMSca = vec3(2e-5);
|
||||
// const vec3 betaMEx = betaMSca / 0.9;
|
||||
// const float mieG = 1.0;
|
||||
|
||||
// Integration steps
|
||||
const int TRANSMITTANCE_STEPS = 500;
|
||||
const int INSCATTER_INTEGRAL_SAMPLES = 50;
|
||||
const int IRRADIANCE_INTEGRAL_SAMPLES = 32;
|
||||
const int INSCATTER_SPHERICAL_INTEGRAL_SAMPLES = 16;
|
||||
|
||||
// The next values crash NVIDIA driver for Quadro K620 -- JCC
|
||||
// const int TRANSMITTANCE_INTEGRAL_SAMPLES = 1000;
|
||||
// const int INSCATTER_INTEGRAL_SAMPLES = 100;
|
||||
// const int IRRADIANCE_INTEGRAL_SAMPLES = 64;
|
||||
// const int INSCATTER_SPHERICAL_INTEGRAL_SAMPLES = 32;
|
||||
|
||||
const float M_PI = 3.141592657;
|
||||
|
||||
const int TRANSMITTANCE_W = 256;
|
||||
const int TRANSMITTANCE_H = 64;
|
||||
|
||||
const int SKY_W = 64;
|
||||
const int SKY_H = 16;
|
||||
|
||||
const int OTHER_TEXTURES_W = 64;
|
||||
const int OTHER_TEXTURES_H = 16;
|
||||
|
||||
|
||||
const int RES_R = 32;
|
||||
const int RES_MU = 128;
|
||||
const int RES_MU_S = 32;
|
||||
const int RES_NU = 8;
|
||||
501
modules/base/shaders/atmosphere_fs.glsl
Normal file
501
modules/base/shaders/atmosphere_fs.glsl
Normal file
@@ -0,0 +1,501 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#define EPSILON 0.0001f
|
||||
|
||||
// Sun Irradiance
|
||||
const float ISun = 50.0;
|
||||
const uint numberOfShadows = 1;
|
||||
|
||||
struct ShadowRenderingStruct {
|
||||
float xu, xp;
|
||||
float rs, rc;
|
||||
vec3 sourceCasterVec;
|
||||
vec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
};
|
||||
|
||||
uniform ShadowRenderingStruct shadowDataArray[numberOfShadows];
|
||||
|
||||
uniform mat4 completeInverse;
|
||||
uniform mat4 projInverse;
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
uniform vec4 cameraPosObj;
|
||||
uniform vec4 planetPositionObj;
|
||||
uniform vec3 sunPositionObj;
|
||||
|
||||
uniform bool _performShading = true;
|
||||
uniform float transparency;
|
||||
uniform int shadows;
|
||||
|
||||
uniform float screenX;
|
||||
uniform float screenY;
|
||||
uniform float screenWIDTH;
|
||||
uniform float screenHEIGHT;
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
uniform sampler2D cloudsTexture;
|
||||
|
||||
uniform sampler2D reflectanceTexture;
|
||||
uniform sampler2D transmittanceTexture;
|
||||
uniform sampler2D irradianceTexture;
|
||||
uniform sampler3D inscatterTexture;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec2 vs_nightTex;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
in vec4 vs_posWorld;
|
||||
|
||||
#include "hdr.glsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
#include "atmosphere_common.glsl"
|
||||
|
||||
vec4 butterworthFunc(const float d, const float r, const float n) {
|
||||
return vec4(vec3(sqrt(r/(r + pow(d, 2*n)))), 1.0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
****** ALL CALCULATIONS FOR ATMOSPHERE ARE KM AND IN OBJECT SPACE SYSTEM ******
|
||||
*******************************************************************************/
|
||||
|
||||
/* Calculates the intersection of the view ray direction with the atmosphere and
|
||||
* returns the first intersection (0.0 when inside atmosphere): offset
|
||||
* and the second intersection: maxLength
|
||||
*/
|
||||
|
||||
struct Ray {
|
||||
vec4 origin;
|
||||
vec4 direction;
|
||||
};
|
||||
|
||||
struct Ellipsoid {
|
||||
vec4 center;
|
||||
vec4 size;
|
||||
};
|
||||
|
||||
bool intersectEllipsoid(const Ray ray, const Ellipsoid ellipsoid, out float offset, out float maxLength) {
|
||||
vec4 O_C = ray.origin-ellipsoid.center;
|
||||
vec4 dir = normalize(ray.direction);
|
||||
|
||||
offset = 0.0f;
|
||||
maxLength = 0.0f;
|
||||
|
||||
float a =
|
||||
((dir.x*dir.x)/(ellipsoid.size.x*ellipsoid.size.x))
|
||||
+ ((dir.y*dir.y)/(ellipsoid.size.y*ellipsoid.size.y))
|
||||
+ ((dir.z*dir.z)/(ellipsoid.size.z*ellipsoid.size.z));
|
||||
float b =
|
||||
((2.f*O_C.x*dir.x)/(ellipsoid.size.x*ellipsoid.size.x))
|
||||
+ ((2.f*O_C.y*dir.y)/(ellipsoid.size.y*ellipsoid.size.y))
|
||||
+ ((2.f*O_C.z*dir.z)/(ellipsoid.size.z*ellipsoid.size.z));
|
||||
float c =
|
||||
((O_C.x*O_C.x)/(ellipsoid.size.x*ellipsoid.size.x))
|
||||
+ ((O_C.y*O_C.y)/(ellipsoid.size.y*ellipsoid.size.y))
|
||||
+ ((O_C.z*O_C.z)/(ellipsoid.size.z*ellipsoid.size.z))
|
||||
- 1.f;
|
||||
|
||||
float d = ((b*b)-(4.f*a*c));
|
||||
if ( d<0.f || a==0.f || b==0.f || c==0.f )
|
||||
return false;
|
||||
|
||||
d = sqrt(d);
|
||||
|
||||
float t1 = (-b+d)/(2.f*a);
|
||||
float t2 = (-b-d)/(2.f*a);
|
||||
|
||||
if( t1<=EPSILON && t2<=EPSILON )
|
||||
return false; // both intersections are behind the ray origin
|
||||
|
||||
bool back = (t1<=EPSILON || t2<=EPSILON); // If only one intersection (t>0) then we are inside the ellipsoid and the intersection is at the back of the ellipsoid
|
||||
float t=0.f;
|
||||
if( t1<=EPSILON )
|
||||
t = t2;
|
||||
else
|
||||
if( t2<=EPSILON )
|
||||
t = t1;
|
||||
else
|
||||
t=(t1<t2) ? t1 : t2;
|
||||
|
||||
if( t<EPSILON ) return false; // Too close to intersection
|
||||
|
||||
vec4 intersection = ray.origin + t*dir;
|
||||
vec4 normal = intersection-ellipsoid.center;
|
||||
normal.x = 2.f*normal.x/(ellipsoid.size.x*ellipsoid.size.x);
|
||||
normal.y = 2.f*normal.y/(ellipsoid.size.y*ellipsoid.size.y);
|
||||
normal.z = 2.f*normal.z/(ellipsoid.size.z*ellipsoid.size.z);
|
||||
|
||||
normal.w = 0.f;
|
||||
normal *= (back) ? -1.f : 1.f;
|
||||
normal = normalize(normal);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool intersectAtmosphere(const vec4 planetPos, const vec3 rayDirection, const float sphereRadius,
|
||||
out float offset, out float maxLength) {
|
||||
offset = 0.0f;
|
||||
maxLength = 0.0f;
|
||||
|
||||
vec3 l = planetPos.xyz - cameraPosObj.xyz;
|
||||
float s = dot(l, rayDirection);
|
||||
float l2 = dot(l, l);
|
||||
|
||||
// sphereRadius in Km
|
||||
float r = sphereRadius - EPSILON; // EPSILON to avoid surface acne
|
||||
float r2 = r * r;
|
||||
|
||||
if (l2 <= r2) {
|
||||
// ray origin inside sphere
|
||||
float m2 = l2 - (s*s);
|
||||
float q = sqrt(r2 - m2);
|
||||
maxLength = s + q;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (s >= 0.0) {
|
||||
// ray outside sphere
|
||||
float m2 = l2 - (s*s);
|
||||
if (m2 <= r2) {
|
||||
// ray hits atmosphere
|
||||
float q = sqrt(r2 - m2);
|
||||
offset = s-q;
|
||||
maxLength = (s+q)-offset;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Rayleigh phase function
|
||||
float phaseFunctionR(float mu) {
|
||||
return (3.0 / (16.0 * M_PI)) * (1.0 + mu * mu);
|
||||
}
|
||||
|
||||
// Mie phase function
|
||||
float phaseFunctionM(float mu) {
|
||||
return 1.5 * 1.0 / (4.0 * M_PI) * (1.0 - mieG*mieG) * pow(1.0 + (mieG*mieG) - 2.0*mieG*mu, -3.0/2.0) * (1.0 + mu * mu) / (2.0 + mieG*mieG);
|
||||
}
|
||||
|
||||
float opticalDepth(float H, float r, float mu, float d) {
|
||||
float a = sqrt((0.5/H)*r);
|
||||
vec2 a01 = a*vec2(mu, mu + d / r);
|
||||
vec2 a01s = sign(a01);
|
||||
vec2 a01sq = a01*a01;
|
||||
float x = a01s.y > a01s.x ? exp(a01sq.x) : 0.0;
|
||||
vec2 y = a01s / (2.3193*abs(a01) + sqrt(1.52*a01sq + 4.0)) * vec2(1.0, exp(-d/H*(d/(2.0*r)+mu)));
|
||||
return sqrt((6.2831*H)*r) * exp((Rg-r)/H) * (x + dot(y, vec2(1.0, -1.0)));
|
||||
}
|
||||
|
||||
vec4 texture4D(sampler3D table, float r, float mu, float muS, float nu)
|
||||
{
|
||||
float H = sqrt(Rt * Rt - Rg * Rg);
|
||||
float rho = sqrt(r * r - Rg * Rg);
|
||||
float rmu = r * mu;
|
||||
float delta = rmu * rmu - r * r + Rg * Rg;
|
||||
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
|
||||
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
|
||||
float uMu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
|
||||
float uMuS = 0.5 / float(RES_MU_S) + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
|
||||
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
|
||||
float uNu = floor(lerp);
|
||||
lerp = lerp - uNu;
|
||||
return texture(table, vec3((uNu + uMuS) / float(RES_NU), uMu, uR)) * (1.0 - lerp) +
|
||||
texture(table, vec3((uNu + uMuS + 1.0) / float(RES_NU), uMu, uR)) * lerp;
|
||||
}
|
||||
|
||||
vec3 analyticTransmittance(float r, float mu, float d) {
|
||||
return exp(- betaR * opticalDepth(HR, r, mu, d) - betaMEx * opticalDepth(HM, r, mu, d));
|
||||
}
|
||||
|
||||
vec3 getMie(vec4 rayMie) {
|
||||
return rayMie.rgb * rayMie.a / max(rayMie.r, 1e-4) * (betaR.r / betaR);
|
||||
}
|
||||
|
||||
vec2 getTransmittanceUV(float r, float mu) {
|
||||
float uR, uMu;
|
||||
uR = sqrt((r - Rg) / (Rt - Rg));
|
||||
uMu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
|
||||
return vec2(uMu, uR);
|
||||
}
|
||||
|
||||
vec3 transmittanceFromTexture(float r, float mu) {
|
||||
vec2 uv = getTransmittanceUV(r, mu);
|
||||
return texture(transmittanceTexture, uv).rgb;
|
||||
}
|
||||
|
||||
vec3 transmittanceWithShadow(float r, float mu) {
|
||||
return mu < -sqrt(1.0 - (Rg / r) * (Rg / r)) ? vec3(0.0) : transmittanceFromTexture(r, mu);
|
||||
}
|
||||
|
||||
vec3 transmittance(float r, float mu, vec3 v, vec3 x0) {
|
||||
vec3 result;
|
||||
float r1 = length(x0);
|
||||
float mu1 = dot(x0, v) / r;
|
||||
if (mu > 0.0) {
|
||||
result = min(transmittanceFromTexture(r, mu) /
|
||||
transmittanceFromTexture(r1, mu1), 1.0);
|
||||
} else {
|
||||
result = min(transmittanceFromTexture(r1, -mu1) /
|
||||
transmittanceFromTexture(r, -mu), 1.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
vec2 getIrradianceUV(float r, float muS) {
|
||||
float uR = (r - Rg) / (Rt - Rg);
|
||||
float uMuS = (muS + 0.2) / (1.0 + 0.2);
|
||||
return vec2(uMuS, uR);
|
||||
}
|
||||
|
||||
vec3 irradiance(sampler2D sampler, float r, float muS) {
|
||||
vec2 uv = getIrradianceUV(r, muS);
|
||||
return texture(sampler, uv).rgb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates the light scattering in the view direction comming from other
|
||||
* light rays scattered in the atmosphere.
|
||||
* The view direction here is the ray: x + tv, s is the sun direction,
|
||||
* r and mu the position and zenith cossine angle as in the paper.
|
||||
*/
|
||||
vec3 inscatterLight(inout vec3 x, inout float t, vec3 v, vec3 s,
|
||||
out float r, out float mu, out vec3 attenuation) {
|
||||
vec3 result;
|
||||
r = length(x);
|
||||
mu = dot(x, v) / r;
|
||||
float d = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rt * Rt);
|
||||
if (d > 0.0) {
|
||||
x += d * v;
|
||||
t -= d;
|
||||
mu = (r * mu + d) / Rt;
|
||||
r = Rt;
|
||||
}
|
||||
// Intersects atmosphere?
|
||||
if (r <= Rt) {
|
||||
float nu = dot(v, s);
|
||||
float muS = dot(x, s) / r;
|
||||
float phaseR = phaseFunctionR(nu);
|
||||
float phaseM = phaseFunctionM(nu);
|
||||
vec4 inscatter = max(texture4D(inscatterTexture, r, mu, muS, nu), 0.0);
|
||||
if (t > 0.0) {
|
||||
vec3 x0 = x + t * v;
|
||||
float r0 = length(x0);
|
||||
float rMu0 = dot(x0, v);
|
||||
float mu0 = rMu0 / r0;
|
||||
float muS0 = dot(x0, s) / r0;
|
||||
|
||||
attenuation = analyticTransmittance(r, mu, t);
|
||||
//attenuation = transmittance(r, mu, v, x+t*v);
|
||||
|
||||
//The following Code is generating surface acne on atmosphere. JCC
|
||||
// We need a better acne avoindance constant (0.01). Done!! Adaptive from distance to x
|
||||
if (r0 > Rg + 0.1*r) {
|
||||
inscatter = max(inscatter - attenuation.rgbr * texture4D(inscatterTexture, r0, mu0, muS0, nu), 0.0);
|
||||
const float EPS = 0.004;
|
||||
float muHoriz = -sqrt(1.0 - (Rg / r) * (Rg / r));
|
||||
if (abs(mu - muHoriz) < EPS) {
|
||||
float a = ((mu - muHoriz) + EPS) / (2.0 * EPS);
|
||||
|
||||
mu = muHoriz - EPS;
|
||||
r0 = sqrt(r * r + t * t + 2.0 * r * t * mu);
|
||||
mu0 = (r * mu + t) / r0;
|
||||
vec4 inScatter0 = texture4D(inscatterTexture, r, mu, muS, nu);
|
||||
vec4 inScatter1 = texture4D(inscatterTexture, r0, mu0, muS0, nu);
|
||||
vec4 inScatterA = max(inScatter0 - attenuation.rgbr * inScatter1, 0.0);
|
||||
|
||||
mu = muHoriz + EPS;
|
||||
r0 = sqrt(r * r + t * t + 2.0 * r * t * mu);
|
||||
mu0 = (r * mu + t) / r0;
|
||||
inScatter0 = texture4D(inscatterTexture, r, mu, muS, nu);
|
||||
inScatter1 = texture4D(inscatterTexture, r0, mu0, muS0, nu);
|
||||
vec4 inScatterB = max(inScatter0 - attenuation.rgbr * inScatter1, 0.0);
|
||||
|
||||
inscatter = mix(inScatterA, inScatterB, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
inscatter.w *= smoothstep(0.00, 0.02, muS);
|
||||
result = max(inscatter.rgb * phaseR + getMie(inscatter) * phaseM, 0.0);
|
||||
|
||||
} else {
|
||||
// No intersection with earth
|
||||
result = vec3(0.0);
|
||||
}
|
||||
return result * ISun;
|
||||
}
|
||||
|
||||
vec3 groundColor(vec3 x, float t, vec3 v, vec3 s, float r, float mu, vec3 attenuation)
|
||||
{
|
||||
vec3 result;
|
||||
// Ray hits ground
|
||||
if (t > 0.0) {
|
||||
vec3 x0 = x + t * v;
|
||||
float r0 = length(x0);
|
||||
vec3 n = x0 / r0;
|
||||
|
||||
// Fixing texture coordinates:
|
||||
vec4 reflectance = texture(reflectanceTexture, vs_st) * vec4(0.2, 0.2, 0.2, 1.0);
|
||||
|
||||
// The following code is generating surface acne in ground.
|
||||
// It is only necessary inside atmosphere rendering. JCC
|
||||
// if (r0 > Rg + 0.01) {
|
||||
// reflectance = vec4(0.4, 0.4, 0.4, 0.0);
|
||||
// }
|
||||
|
||||
float muS = dot(n, s);
|
||||
vec3 sunLight = transmittanceWithShadow(r0, muS);
|
||||
|
||||
vec3 groundSkyLight = irradiance(irradianceTexture, r0, muS);
|
||||
|
||||
vec4 clouds = vec4(0.85)*texture(cloudsTexture, vs_st);
|
||||
vec3 groundColor = (reflectance.rgb + clouds.rgb) *
|
||||
(max(muS, 0.0) * sunLight + groundSkyLight) * ISun / M_PI;
|
||||
|
||||
// Yellowish reflection from sun on oceans and rivers
|
||||
if (reflectance.w > 0.0) {
|
||||
vec3 h = normalize(s - v);
|
||||
float fresnel = 0.02 + 0.98 * pow(1.0 - dot(-v, h), 5.0);
|
||||
float waterBrdf = fresnel * pow(max(dot(h, n), 0.0), 150.0);
|
||||
groundColor += reflectance.w * max(waterBrdf, 0.0) * sunLight * ISun;
|
||||
}
|
||||
|
||||
result = attenuation * groundColor;
|
||||
} else {
|
||||
// No hit
|
||||
result = vec3(0.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
vec3 sunColor(vec3 x, float t, vec3 v, vec3 s, float r, float mu) {
|
||||
if (t > 0.0) {
|
||||
return vec3(0.0);
|
||||
} else {
|
||||
vec3 transmittance = r <= Rt ? transmittanceWithShadow(r, mu) : vec3(1.0);
|
||||
float isun = step(cos(M_PI / 180.0), dot(v, s)) * ISun;
|
||||
return transmittance * isun;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
******* CALCULATIONS FOR SHADOWS ARE IN WORLD SPACE IN METERS *********
|
||||
***********************************************************************/
|
||||
// TODO: Change calculations for view space in KM.
|
||||
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);
|
||||
vec4 clouds = texture(cloudsTexture, vs_st);
|
||||
|
||||
Fragment frag;
|
||||
if (_performShading) {
|
||||
// atmosphere
|
||||
vec4 viewport = vec4(screenX, screenY, screenWIDTH, screenHEIGHT);
|
||||
vec4 ndcPos;
|
||||
ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1;
|
||||
ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
|
||||
(gl_DepthRange.far - gl_DepthRange.near);
|
||||
ndcPos.w = 1.0;
|
||||
vec4 clipPos = ndcPos / gl_FragCoord.w;
|
||||
vec4 projCoords = projInverse * clipPos;
|
||||
vec4 viewDirection = normalize(completeInverse * vec4(projCoords.xyz, 0.0));
|
||||
vec3 v = normalize(viewDirection.xyz);
|
||||
|
||||
float offset, maxLength;
|
||||
vec4 ppos = vec4(0.0);
|
||||
//if (intersectAtmosphere(planetPositionObj, v, Rt, offset, maxLength)) {
|
||||
if (intersectAtmosphere(ppos, v, Rg, offset, maxLength)) {
|
||||
// Following paper nomenclature
|
||||
float t = offset;
|
||||
vec3 x = cameraPosObj.xyz;// + offset * v;
|
||||
float r = length(x);
|
||||
float mu = dot(x, v) / r;
|
||||
vec3 s = normalize(sunPositionObj);
|
||||
|
||||
vec3 attenuation;
|
||||
vec3 inscatterColor = inscatterLight(x, t, v, s, r, mu, attenuation);
|
||||
vec3 groundColor = groundColor(x, t, v, s, r, mu, attenuation);
|
||||
vec3 sunColor = sunColor(x, t, v, s, r, mu);
|
||||
|
||||
//diffuse = HDR(vec4(sunColor + groundColor + inscatterColor, 1.0));
|
||||
//diffuse = HDR(vec4(sunColor, 1.0));
|
||||
//diffuse = HDR(vec4(groundColor, 1.0));
|
||||
//diffuse = HDR(vec4(inscatterColor, 1.0));
|
||||
|
||||
//diffuse = HDR(vec4(sunColor + groundColor + inscatterColor, 1.0) + diffuse2);
|
||||
diffuse = HDR((vec4(sunColor + groundColor + inscatterColor, 1.0) + diffuse2) *
|
||||
calcShadow(shadowDataArray, vs_posWorld.xyz) );
|
||||
}
|
||||
// else
|
||||
// diffuse = HDR(diffuse);
|
||||
}
|
||||
|
||||
diffuse[3] = transparency;
|
||||
frag.color = diffuse;
|
||||
frag.depth = depth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
76
modules/base/shaders/atmosphere_vs.glsl
Normal file
76
modules/base/shaders/atmosphere_vs.glsl
Normal file
@@ -0,0 +1,76 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform mat4 NormalTransform;
|
||||
|
||||
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;
|
||||
out vec4 ray;
|
||||
|
||||
#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));
|
||||
|
||||
// This is the wright transformation for the normals
|
||||
vs_normal = normalize(NormalTransform * vec4(in_normal,0));
|
||||
|
||||
// The position is not in world coordinates, it is in
|
||||
// regular view/eye coordinates.
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
|
||||
// Vertex position in world coordinates in meters and
|
||||
// with no powerscalling coordiantes
|
||||
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 the position is transformed from view coordinates to SGCT projection
|
||||
// coordinates.
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
48
modules/base/shaders/deltaE_calc_fs.glsl
Normal file
48
modules/base/shaders/deltaE_calc_fs.glsl
Normal file
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTableColor;
|
||||
|
||||
// See paper algorithm
|
||||
uniform int line;
|
||||
uniform sampler2D deltaETexture;
|
||||
|
||||
Fragment getFragment() {
|
||||
if (line == 4)
|
||||
renderTableColor = vec4(0.0);
|
||||
else if (line == 10) {
|
||||
vec2 uv = gl_FragCoord.xy / vec2(OTHER_TEXTURES_W, OTHER_TEXTURES_H);
|
||||
renderTableColor = texture(deltaETexture, uv);
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
31
modules/base/shaders/deltaE_calc_vs.glsl
Normal file
31
modules/base/shaders/deltaE_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
192
modules/base/shaders/deltaJ_calc_fs.glsl
Normal file
192
modules/base/shaders/deltaJ_calc_fs.glsl
Normal file
@@ -0,0 +1,192 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTarget1;
|
||||
|
||||
uniform float r;
|
||||
uniform vec4 dhdH;
|
||||
|
||||
uniform sampler2D transmittanceTexture;
|
||||
uniform sampler2D deltaETexture;
|
||||
uniform sampler3D deltaSRTexture;
|
||||
uniform sampler3D deltaSMTexture;
|
||||
uniform float first;
|
||||
|
||||
const float dphi = M_PI / float(INSCATTER_SPHERICAL_INTEGRAL_SAMPLES);
|
||||
const float dtheta = M_PI / float(INSCATTER_SPHERICAL_INTEGRAL_SAMPLES);
|
||||
|
||||
void getMuMuSNu(const float r, vec4 dhdH, out float mu, out float mu_s, out float nu) {
|
||||
float x = gl_FragCoord.x - 0.5;
|
||||
float y = gl_FragCoord.y - 0.5;
|
||||
if (y < float(RES_MU) / 2.0) {
|
||||
float d = 1.0 - y / (float(RES_MU) / 2.0 - 1.0);
|
||||
d = min(max(dhdH.z, d * dhdH.w), dhdH.w * 0.999);
|
||||
mu = (Rg * Rg - r * r - d * d) / (2.0 * r * d);
|
||||
mu = min(mu, -sqrt(1.0 - (Rg / r) * (Rg / r)) - 0.001);
|
||||
} else {
|
||||
float d = (y - float(RES_MU) / 2.0) / (float(RES_MU) / 2.0 - 1.0);
|
||||
d = min(max(dhdH.x, d * dhdH.y), dhdH.y * 0.999);
|
||||
mu = (Rt * Rt - r * r - d * d) / (2.0 * r * d);
|
||||
}
|
||||
mu_s = mod(x, float(RES_MU_S)) / (float(RES_MU_S) - 1.0);
|
||||
mu_s = tan((2.0 * mu_s - 1.0 + 0.26) * 1.1) / tan(1.26 * 1.1);
|
||||
nu = -1.0 + floor(x / float(RES_MU_S)) / (float(RES_NU) - 1.0) * 2.0;
|
||||
}
|
||||
|
||||
vec3 transmittanceFromTexture(const float r, const float mu) {
|
||||
float u_r = sqrt((r - Rg) / (Rt - Rg));
|
||||
// See Colliene to understand the different mapping.
|
||||
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
|
||||
|
||||
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
|
||||
}
|
||||
|
||||
vec3 transmittance(const float r, const float mu, float d) {
|
||||
vec3 result;
|
||||
float r1 = sqrt(r * r + d * d + 2.0 * r * mu * d);
|
||||
float mu1 = (r * mu + d) / r1;
|
||||
if (mu > 0.0) {
|
||||
result = min(transmittanceFromTexture(r, mu) /
|
||||
transmittanceFromTexture(r1, mu1), 1.0);
|
||||
} else {
|
||||
result = min(transmittanceFromTexture(r1, -mu1) /
|
||||
transmittanceFromTexture(r, -mu), 1.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Rayleigh phase
|
||||
float phaseFunctionR(const float mu) {
|
||||
return (3.0 / (16.0 * M_PI)) * (1.0 + mu * mu);
|
||||
}
|
||||
|
||||
// Mie phase
|
||||
float phaseFunctionM(const float mu) {
|
||||
return (3.0 / (8.0 * M_PI)) *
|
||||
( ( (1.0 - (mieG*mieG) ) * (1+mu*mu) ) /
|
||||
( (2+mieG*mieG) * pow(1+mieG*mieG - 2.0*mieG*mu, 3.0/2.0) ) );
|
||||
}
|
||||
|
||||
vec3 irradiance(sampler2D calcTexture, const float r, const float mu_s) {
|
||||
float u_r = (r - Rg) / (Rt - Rg);
|
||||
float u_mu_s = (mu_s + 0.2) / (1.0 + 0.2);
|
||||
return texture(calcTexture, vec2(u_mu_s, u_r)).rgb;
|
||||
}
|
||||
|
||||
vec4 texture4D(sampler3D table, const float r, const float mu,
|
||||
const float mu_s, const float nu)
|
||||
{
|
||||
float H = sqrt(Rt * Rt - Rg * Rg);
|
||||
float rho = sqrt(r * r - Rg * Rg);
|
||||
float rmu = r * mu;
|
||||
float delta = rmu * rmu - r * r + Rg * Rg;
|
||||
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
|
||||
float u_r = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
|
||||
float u_mu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
|
||||
float u_mu_s = 0.5 / float(RES_MU_S) + (atan(max(mu_s, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
|
||||
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
|
||||
float uNu = floor(lerp);
|
||||
lerp = lerp - uNu;
|
||||
return texture(table, vec3((uNu + u_mu_s) / float(RES_NU), u_mu, u_r)) * (1.0 - lerp) +
|
||||
texture(table, vec3((uNu + u_mu_s + 1.0) / float(RES_NU), u_mu, u_r)) * lerp;
|
||||
}
|
||||
|
||||
void inscatter(float r, float mu, float mu_s, float nu, out vec3 raymie) {
|
||||
r = clamp(r, Rg, Rt);
|
||||
mu = clamp(mu, -1.0, 1.0);
|
||||
mu_s = clamp(mu_s, -1.0, 1.0);
|
||||
float var = sqrt(1.0 - mu * mu) * sqrt(1.0 - mu_s * mu_s);
|
||||
nu = clamp(nu, mu_s * mu - var, mu_s * mu + var);
|
||||
|
||||
float cthetamin = -sqrt(1.0 - (Rg / r) * (Rg / r));
|
||||
|
||||
vec3 v = vec3(sqrt(1.0 - mu * mu), 0.0, mu);
|
||||
float sx = v.x == 0.0 ? 0.0 : (nu - mu_s * mu) / v.x;
|
||||
vec3 s = vec3(sx, sqrt(max(0.0, 1.0 - sx * sx - mu_s * mu_s)), mu_s);
|
||||
|
||||
raymie = vec3(0.0);
|
||||
|
||||
for (int itheta = 0; itheta < INSCATTER_SPHERICAL_INTEGRAL_SAMPLES; ++itheta) {
|
||||
float theta = (float(itheta) + 0.5) * dtheta;
|
||||
float ctheta = cos(theta);
|
||||
|
||||
float greflectance = 0.0;
|
||||
float dground = 0.0;
|
||||
vec3 gtransp = vec3(0.0);
|
||||
if (ctheta < cthetamin) {
|
||||
greflectance = AVERAGE_GROUND_REFLECTANCE / M_PI;
|
||||
dground = -r * ctheta - sqrt(r * r * (ctheta * ctheta - 1.0) + Rg * Rg);
|
||||
gtransp = transmittance(Rg, -(r * ctheta + dground) / Rg, dground);
|
||||
}
|
||||
|
||||
for (int iphi = 0; iphi < 2 * INSCATTER_SPHERICAL_INTEGRAL_SAMPLES; ++iphi) {
|
||||
float phi = (float(iphi) + 0.5) * dphi;
|
||||
float dw = dtheta * dphi * sin(theta);
|
||||
vec3 w = vec3(cos(phi) * sin(theta), sin(phi) * sin(theta), ctheta);
|
||||
|
||||
float nu1 = dot(s, w);
|
||||
float nu2 = dot(v, w);
|
||||
float pr2 = phaseFunctionR(nu2);
|
||||
float pm2 = phaseFunctionM(nu2);
|
||||
|
||||
vec3 gnormal = (vec3(0.0, 0.0, r) + dground * w) / Rg;
|
||||
vec3 girradiance = irradiance(deltaETexture, Rg, dot(gnormal, s));
|
||||
|
||||
vec3 raymie1;
|
||||
|
||||
raymie1 = greflectance * girradiance * gtransp;
|
||||
|
||||
if (first == 1.0) {
|
||||
float pr1 = phaseFunctionR(nu1);
|
||||
float pm1 = phaseFunctionM(nu1);
|
||||
vec3 ray1 = texture4D(deltaSRTexture, r, w.z, mu_s, nu1).rgb;
|
||||
vec3 mie1 = texture4D(deltaSMTexture, r, w.z, mu_s, nu1).rgb;
|
||||
raymie1 += ray1 * pr1 + mie1 * pm1;
|
||||
} else {
|
||||
raymie1 += texture4D(deltaSRTexture, r, w.z, mu_s, nu1).rgb;
|
||||
}
|
||||
|
||||
raymie += raymie1 * (betaR * exp(-(r - Rg) / HR) * pr2 + betaMSca * exp(-(r - Rg) / HM) * pm2) * dw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
vec3 raymie;
|
||||
float mu, mu_s, nu;
|
||||
getMuMuSNu(r, dhdH, mu, mu_s, nu);
|
||||
inscatter(r, mu, mu_s, nu, raymie);
|
||||
|
||||
renderTarget1 = vec4(raymie, 1.0);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* 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 *
|
||||
@@ -22,32 +22,20 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef TEXTURETILE_HGLSL
|
||||
#define TEXTURETILE_HGLSL
|
||||
#version __CONTEXT__
|
||||
|
||||
struct TileDepthTransform {
|
||||
float depthScale;
|
||||
float depthOffset;
|
||||
};
|
||||
uniform int layer;
|
||||
|
||||
struct TileUvTransform {
|
||||
vec2 uvOffset;
|
||||
vec2 uvScale;
|
||||
};
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
|
||||
struct TextureTile {
|
||||
sampler2D textureSampler;
|
||||
|
||||
TileDepthTransform depthTransform;
|
||||
TileUvTransform uvTransform;
|
||||
};
|
||||
|
||||
vec4 patchBorderOverlay(vec2 uv, vec3 borderColor, float borderSize) {
|
||||
vec2 uvOffset = uv - vec2(0.5);
|
||||
float thres = 0.5 - borderSize/2;
|
||||
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
|
||||
vec3 color = isBorder ? borderColor : vec3(0);
|
||||
return vec4(color, 0);
|
||||
}
|
||||
|
||||
#endif // TEXTURETILE_HGLSL
|
||||
void main()
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < gl_in.length(); ++n) {
|
||||
gl_Position = gl_in[n].gl_Position;
|
||||
gl_Layer = layer;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
31
modules/base/shaders/deltaJ_calc_vs.glsl
Normal file
31
modules/base/shaders/deltaJ_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
51
modules/base/shaders/deltaS_calc_fs.glsl
Normal file
51
modules/base/shaders/deltaS_calc_fs.glsl
Normal file
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTarget1;
|
||||
|
||||
uniform int layer;
|
||||
|
||||
uniform sampler3D deltaSRTexture;
|
||||
uniform sampler3D deltaSMTexture;
|
||||
|
||||
Fragment getFragment() {
|
||||
vec3 uvw = vec3(gl_FragCoord.xy, float(layer) + 0.5) / vec3(ivec3(RES_MU_S * RES_NU, RES_MU, RES_R));
|
||||
vec4 ray = texture(deltaSRTexture, uvw);
|
||||
vec4 mie = texture(deltaSMTexture, uvw);
|
||||
|
||||
// We are using only the red component of the Mie scattering
|
||||
// See the Precomputed Atmosphere Scattering paper for details about
|
||||
// the angular precision.
|
||||
renderTarget1 = vec4(ray.rgb, mie.r);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
41
modules/base/shaders/deltaS_calc_gs.glsl
Normal file
41
modules/base/shaders/deltaS_calc_gs.glsl
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform int layer;
|
||||
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
|
||||
void main()
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < gl_in.length(); ++n) {
|
||||
gl_Position = gl_in[n].gl_Position;
|
||||
gl_Layer = layer;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
31
modules/base/shaders/deltaS_calc_vs.glsl
Normal file
31
modules/base/shaders/deltaS_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
54
modules/base/shaders/deltaS_sup_calc_fs.glsl
Normal file
54
modules/base/shaders/deltaS_sup_calc_fs.glsl
Normal file
@@ -0,0 +1,54 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTarget1;
|
||||
|
||||
uniform int layer;
|
||||
|
||||
uniform sampler3D deltaSTexture;
|
||||
|
||||
// Rayleigh phase
|
||||
float phaseFunctionR(const float mu) {
|
||||
return (3.0 / (16.0 * M_PI)) * (1.0 + mu * mu);
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
float x = gl_FragCoord.x - 0.5;
|
||||
float y = gl_FragCoord.y - 0.5;
|
||||
|
||||
float nu = -1.0 + floor(x / float(RES_MU_S)) / (float(RES_NU) - 1.0) * 2.0;
|
||||
vec3 uvw = vec3(gl_FragCoord.xy, float(layer) + 0.5) / vec3(ivec3(RES_MU_S * RES_NU, RES_MU, RES_R));
|
||||
|
||||
renderTarget1 = vec4(texture(deltaSTexture, uvw).rgb / phaseFunctionR(nu), 1.0);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
41
modules/base/shaders/deltaS_sup_calc_gs.glsl
Normal file
41
modules/base/shaders/deltaS_sup_calc_gs.glsl
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform int layer;
|
||||
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
|
||||
void main()
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < gl_in.length(); ++n) {
|
||||
gl_Position = gl_in[n].gl_Position;
|
||||
gl_Layer = layer;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
31
modules/base/shaders/deltaS_sup_calc_vs.glsl
Normal file
31
modules/base/shaders/deltaS_sup_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
35
modules/base/shaders/hdr.glsl
Normal file
35
modules/base/shaders/hdr.glsl
Normal file
@@ -0,0 +1,35 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
uniform float exposure;
|
||||
|
||||
vec4 HDR(vec4 color) {
|
||||
color *= exposure;
|
||||
|
||||
color.r = color.r < 1.413 ? pow(color.r * 0.38317, 1.0 / 2.2) : 1.0 - exp(-color.r);
|
||||
color.g = color.g < 1.413 ? pow(color.g * 0.38317, 1.0 / 2.2) : 1.0 - exp(-color.g);
|
||||
color.b = color.b < 1.413 ? pow(color.b * 0.38317, 1.0 / 2.2) : 1.0 - exp(-color.b);
|
||||
|
||||
return color;
|
||||
}
|
||||
154
modules/base/shaders/inScattering_calc_fs.glsl
Normal file
154
modules/base/shaders/inScattering_calc_fs.glsl
Normal file
@@ -0,0 +1,154 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTarget1;
|
||||
layout(location = 2) out vec4 renderTarget2;
|
||||
|
||||
uniform float r;
|
||||
uniform vec4 dhdH;
|
||||
|
||||
uniform sampler2D transmittanceTexture;
|
||||
|
||||
// In the following shaders r (altitude) is the length of vector/position x in the
|
||||
// atmosphere (or on the top of it when considering an observer in space),
|
||||
// where the light is comming from the opposity direction of the view direction,
|
||||
// here the vector v or viewDirection.
|
||||
// Rg is the planet radius
|
||||
|
||||
void getMuMuSNu(const float r, vec4 dhdH, out float mu, out float mu_s, out float nu) {
|
||||
float x = gl_FragCoord.x - 0.5;
|
||||
float y = gl_FragCoord.y - 0.5;
|
||||
if (y < float(RES_MU) / 2.0) {
|
||||
float d = 1.0 - y / (float(RES_MU) / 2.0 - 1.0);
|
||||
d = min(max(dhdH.z, d * dhdH.w), dhdH.w * 0.999);
|
||||
mu = (Rg * Rg - r * r - d * d) / (2.0 * r * d);
|
||||
mu = min(mu, -sqrt(1.0 - (Rg / r) * (Rg / r)) - 0.001);
|
||||
} else {
|
||||
float d = (y - float(RES_MU) / 2.0) / (float(RES_MU) / 2.0 - 1.0);
|
||||
d = min(max(dhdH.x, d * dhdH.y), dhdH.y * 0.999);
|
||||
mu = (Rt * Rt - r * r - d * d) / (2.0 * r * d);
|
||||
}
|
||||
mu_s = mod(x, float(RES_MU_S)) / (float(RES_MU_S) - 1.0);
|
||||
mu_s = tan((2.0 * mu_s - 1.0 + 0.26) * 1.1) / tan(1.26 * 1.1);
|
||||
nu = -1.0 + floor(x / float(RES_MU_S)) / (float(RES_NU) - 1.0) * 2.0;
|
||||
}
|
||||
|
||||
vec3 transmittanceFromTexture(const float r, const float mu) {
|
||||
float u_r = sqrt((r - Rg) / (Rt - Rg));
|
||||
// See Colliene to understand the different mapping.
|
||||
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
|
||||
|
||||
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
|
||||
}
|
||||
|
||||
vec3 transmittance(const float r, const float mu, float d) {
|
||||
vec3 result;
|
||||
float r1 = sqrt(r * r + d * d + 2.0 * r * mu * d);
|
||||
float mu1 = (r * mu + d) / r1;
|
||||
if (mu > 0.0) {
|
||||
result = min(transmittanceFromTexture(r, mu) /
|
||||
transmittanceFromTexture(r1, mu1), 1.0);
|
||||
} else {
|
||||
result = min(transmittanceFromTexture(r1, -mu1) /
|
||||
transmittanceFromTexture(r, -mu), 1.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void integrand(const float r, const float mu, const float muS, const float nu,
|
||||
const float t, out vec3 ray, out vec3 mie) {
|
||||
ray = vec3(0.0);
|
||||
mie = vec3(0.0);
|
||||
float ri = sqrt(r * r + t * t + 2.0 * r * mu * t);
|
||||
float muSi = (nu * t + muS * r) / ri;
|
||||
ri = max(Rg, ri);
|
||||
if (muSi >= -sqrt(1.0 - Rg * Rg / (ri * ri))) {
|
||||
vec3 ti = transmittance(r, mu, t) * transmittanceFromTexture(ri, muSi);
|
||||
ray = exp(-(ri - Rg) / HR) * ti;
|
||||
mie = exp(-(ri - Rg) / HM) * ti;
|
||||
}
|
||||
}
|
||||
|
||||
float rayDistance(const float r, const float mu) {
|
||||
// cosine law
|
||||
float distanceAtmosphereIntersect = -r * mu + sqrt(r * r * (mu * mu - 1.0) +
|
||||
(Rt + ATM_EPSILON)*(Rt + ATM_EPSILON));
|
||||
float distance = distanceAtmosphereIntersect;
|
||||
float delta = r * r * (mu * mu - 1.0) + Rg * Rg;
|
||||
// No imaginary numbers... :-)
|
||||
if (delta >= 0.0) {
|
||||
float distanceEarthIntersect = -r * mu - sqrt(delta);
|
||||
if (distanceEarthIntersect >= 0.0) {
|
||||
distance = min(distanceAtmosphereIntersect, distanceEarthIntersect);
|
||||
}
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
void inscatter(float r, float mu, float muS, float nu, out vec3 ray, out vec3 mie) {
|
||||
// Integrating using the Trapezoidal rule:
|
||||
// Integral(f(y)dy)(from a to b) = (b-a)/2n_steps*(Sum(f(y_i+1)+f(y_i)))
|
||||
ray = vec3(0.0);
|
||||
mie = vec3(0.0);
|
||||
float dx = rayDistance(r, mu) / float(INSCATTER_INTEGRAL_SAMPLES);
|
||||
float xi = 0.0;
|
||||
vec3 rayi;
|
||||
vec3 miei;
|
||||
integrand(r, mu, muS, nu, 0.0, rayi, miei);
|
||||
for (int i = 1; i <= INSCATTER_INTEGRAL_SAMPLES; ++i) {
|
||||
float xj = float(i) * dx;
|
||||
vec3 rayj;
|
||||
vec3 miej;
|
||||
integrand(r, mu, muS, nu, xj, rayj, miej);
|
||||
ray += (rayi + rayj) / 2.0 * dx;
|
||||
mie += (miei + miej) / 2.0 * dx;
|
||||
xi = xj;
|
||||
rayi = rayj;
|
||||
miei = miej;
|
||||
}
|
||||
ray *= betaR;
|
||||
mie *= betaMSca;
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
vec3 ray;
|
||||
vec3 mie;
|
||||
float mu, muS, nu;
|
||||
getMuMuSNu(r, dhdH, mu, muS, nu);
|
||||
inscatter(r, mu, muS, nu, ray, mie);
|
||||
// store separately Rayleigh and Mie contributions, WITHOUT the phase function factor
|
||||
// (cf "Angular precision")
|
||||
renderTarget1 = vec4(ray, 1.0);
|
||||
renderTarget2 = vec4(mie, 1.0);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
41
modules/base/shaders/inScattering_calc_gs.glsl
Normal file
41
modules/base/shaders/inScattering_calc_gs.glsl
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform int layer;
|
||||
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices=3) out;
|
||||
|
||||
void main()
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < gl_in.length(); ++n) {
|
||||
gl_Position = gl_in[n].gl_Position;
|
||||
gl_Layer = layer;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
31
modules/base/shaders/inScattering_calc_vs.glsl
Normal file
31
modules/base/shaders/inScattering_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
155
modules/base/shaders/inScattering_sup_calc_fs.glsl
Normal file
155
modules/base/shaders/inScattering_sup_calc_fs.glsl
Normal file
@@ -0,0 +1,155 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTarget1;
|
||||
|
||||
uniform float r;
|
||||
uniform vec4 dhdH;
|
||||
|
||||
uniform sampler2D transmittanceTexture;
|
||||
uniform sampler3D deltaJTexture;
|
||||
|
||||
void getMuMuSNu(const float r, vec4 dhdH, out float mu, out float mu_s, out float nu) {
|
||||
float x = gl_FragCoord.x - 0.5;
|
||||
float y = gl_FragCoord.y - 0.5;
|
||||
if (y < float(RES_MU) / 2.0) {
|
||||
float d = 1.0 - y / (float(RES_MU) / 2.0 - 1.0);
|
||||
d = min(max(dhdH.z, d * dhdH.w), dhdH.w * 0.999);
|
||||
mu = (Rg * Rg - r * r - d * d) / (2.0 * r * d);
|
||||
mu = min(mu, -sqrt(1.0 - (Rg / r) * (Rg / r)) - 0.001);
|
||||
} else {
|
||||
float d = (y - float(RES_MU) / 2.0) / (float(RES_MU) / 2.0 - 1.0);
|
||||
d = min(max(dhdH.x, d * dhdH.y), dhdH.y * 0.999);
|
||||
mu = (Rt * Rt - r * r - d * d) / (2.0 * r * d);
|
||||
}
|
||||
mu_s = mod(x, float(RES_MU_S)) / (float(RES_MU_S) - 1.0);
|
||||
mu_s = tan((2.0 * mu_s - 1.0 + 0.26) * 1.1) / tan(1.26 * 1.1);
|
||||
nu = -1.0 + floor(x / float(RES_MU_S)) / (float(RES_NU) - 1.0) * 2.0;
|
||||
}
|
||||
|
||||
vec4 texture4D(sampler3D table, float r, float mu, float muS, float nu)
|
||||
{
|
||||
float H = sqrt(Rt * Rt - Rg * Rg);
|
||||
float rho = sqrt(r * r - Rg * Rg);
|
||||
float rmu = r * mu;
|
||||
float delta = rmu * rmu - r * r + Rg * Rg;
|
||||
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
|
||||
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
|
||||
float uMu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
|
||||
float uMuS = 0.5 / float(RES_MU_S) + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
|
||||
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
|
||||
float uNu = floor(lerp);
|
||||
lerp = lerp - uNu;
|
||||
return texture(table, vec3((uNu + uMuS) / float(RES_NU), uMu, uR)) * (1.0 - lerp) +
|
||||
texture(table, vec3((uNu + uMuS + 1.0) / float(RES_NU), uMu, uR)) * lerp;
|
||||
}
|
||||
|
||||
float limit(float r, float mu) {
|
||||
float dout = -r * mu + sqrt(r * r * (mu * mu - 1.0) + ((Rt+ATM_EPSILON) * (Rt+ATM_EPSILON)));
|
||||
float delta2 = r * r * (mu * mu - 1.0) + Rg * Rg;
|
||||
if (delta2 >= 0.0) {
|
||||
float din = -r * mu - sqrt(delta2);
|
||||
if (din >= 0.0) {
|
||||
dout = min(dout, din);
|
||||
}
|
||||
}
|
||||
return dout;
|
||||
}
|
||||
|
||||
vec3 transmittanceFromTexture(const float r, const float mu) {
|
||||
float u_r = sqrt((r - Rg) / (Rt - Rg));
|
||||
// See Colliene to understand the different mapping.
|
||||
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
|
||||
|
||||
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
|
||||
}
|
||||
|
||||
vec3 transmittance(const float r, const float mu, const float d) {
|
||||
vec3 result;
|
||||
float r1 = sqrt(r * r + d * d + 2.0 * r * mu * d);
|
||||
float mu1 = (r * mu + d) / r1;
|
||||
if (mu > 0.0) {
|
||||
result = min(transmittanceFromTexture(r, mu) /
|
||||
transmittanceFromTexture(r1, mu1), 1.0);
|
||||
} else {
|
||||
result = min(transmittanceFromTexture(r1, -mu1) /
|
||||
transmittanceFromTexture(r, -mu), 1.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
vec3 integrand(float r, float mu, float muS, float nu, float t) {
|
||||
float ri = sqrt(r * r + t * t + 2.0 * r * mu * t);
|
||||
float mui = (r * mu + t) / ri;
|
||||
float muSi = (nu * t + muS * r) / ri;
|
||||
return texture4D(deltaJTexture, ri, mui, muSi, nu).rgb * transmittance(r, mu, t);
|
||||
}
|
||||
|
||||
float rayDistance(const float r, const float mu) {
|
||||
// cosine law
|
||||
float distanceAtmosphereIntersect = -r * mu + sqrt(r * r * (mu * mu - 1.0) +
|
||||
(Rt + ATM_EPSILON)*(Rt + ATM_EPSILON));
|
||||
float distance = distanceAtmosphereIntersect;
|
||||
float delta = r * r * (mu * mu - 1.0) + Rg * Rg;
|
||||
// No imaginary numbers... :-)
|
||||
if (delta >= 0.0) {
|
||||
float distanceEarthIntersect = -r * mu - sqrt(delta);
|
||||
if (distanceEarthIntersect >= 0.0) {
|
||||
distance = min(distanceAtmosphereIntersect, distanceEarthIntersect);
|
||||
}
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
vec3 inscatter(float r, float mu, float muS, float nu) {
|
||||
vec3 raymie = vec3(0.0);
|
||||
float dx = rayDistance(r, mu) / float(INSCATTER_INTEGRAL_SAMPLES);
|
||||
float xi = 0.0;
|
||||
vec3 raymiei = integrand(r, mu, muS, nu, 0.0);
|
||||
for (int i = 1; i <= INSCATTER_INTEGRAL_SAMPLES; ++i) {
|
||||
float xj = float(i) * dx;
|
||||
vec3 raymiej = integrand(r, mu, muS, nu, xj);
|
||||
raymie += (raymiei + raymiej) / 2.0 * dx;
|
||||
xi = xj;
|
||||
raymiei = raymiej;
|
||||
}
|
||||
return raymie;
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
float mu, muS, nu;
|
||||
getMuMuSNu(r, dhdH, mu, muS, nu);
|
||||
|
||||
renderTarget1 = vec4(inscatter(r, mu, muS, nu), 1.0);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
41
modules/base/shaders/inScattering_sup_calc_gs.glsl
Normal file
41
modules/base/shaders/inScattering_sup_calc_gs.glsl
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform int layer;
|
||||
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices = 3) out;
|
||||
|
||||
void main()
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < gl_in.length(); ++n) {
|
||||
gl_Position = gl_in[n].gl_Position;
|
||||
gl_Layer = layer;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
31
modules/base/shaders/inScattering_sup_calc_vs.glsl
Normal file
31
modules/base/shaders/inScattering_sup_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
57
modules/base/shaders/irradiance_calc_fs.glsl
Normal file
57
modules/base/shaders/irradiance_calc_fs.glsl
Normal file
@@ -0,0 +1,57 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTableColor;
|
||||
|
||||
uniform sampler2D transmittanceTexture;
|
||||
|
||||
void getRAndMu(out float r, out float mu) {
|
||||
// See Bruneton and Colliene to understand the mapping.
|
||||
mu = -0.2 + (gl_FragCoord.x - 0.5) / (float(OTHER_TEXTURES_W) - 1.0) * (1.0 + 0.2);
|
||||
r = Rg + (gl_FragCoord.y - 0.5) / (float(OTHER_TEXTURES_H) - 1.0) * (Rt - Rg);
|
||||
}
|
||||
|
||||
vec3 transmittance(const float r, const float mu) {
|
||||
float u_r = sqrt((r - Rg) / (Rt - Rg));
|
||||
// See Colliene to understand the different mapping.
|
||||
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
|
||||
|
||||
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
float mu, r;
|
||||
getRAndMu(r, mu);
|
||||
renderTableColor = vec4(transmittance(r, mu) * max(mu, 0.0), 1.0);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
31
modules/base/shaders/irradiance_calc_vs.glsl
Normal file
31
modules/base/shaders/irradiance_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
101
modules/base/shaders/irradiance_sup_calc_fs.glsl
Normal file
101
modules/base/shaders/irradiance_sup_calc_fs.glsl
Normal file
@@ -0,0 +1,101 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTableColor;
|
||||
|
||||
uniform float first;
|
||||
|
||||
const float dphi = M_PI / float(IRRADIANCE_INTEGRAL_SAMPLES);
|
||||
const float dtheta = M_PI / float(IRRADIANCE_INTEGRAL_SAMPLES);
|
||||
|
||||
uniform sampler2D transmittanceTexture;
|
||||
uniform sampler3D deltaSRTexture;
|
||||
uniform sampler3D deltaSMTexture;
|
||||
|
||||
// Rayleigh phase
|
||||
float phaseFunctionR(const float mu) {
|
||||
return (3.0 / (16.0 * M_PI)) * (1.0 + mu * mu);
|
||||
}
|
||||
|
||||
// Mie phase
|
||||
float phaseFunctionM(const float mu) {
|
||||
return (3.0 / (8.0 * M_PI)) *
|
||||
( ( (1.0 - (mieG*mieG) ) * (1+mu*mu) ) /
|
||||
( (2+mieG*mieG) * pow(1+mieG*mieG - 2.0*mieG*mu, 3.0/2.0) ) );
|
||||
}
|
||||
|
||||
vec4 texture4D(sampler3D table, const float r, const float mu,
|
||||
const float muS, const float nu)
|
||||
{
|
||||
float H = sqrt(Rt * Rt - Rg * Rg);
|
||||
float rho = sqrt(r * r - Rg * Rg);
|
||||
float rmu = r * mu;
|
||||
float delta = rmu * rmu - r * r + Rg * Rg;
|
||||
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
|
||||
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
|
||||
float uMu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
|
||||
float uMuS = 0.5 / float(RES_MU_S) + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
|
||||
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
|
||||
float uNu = floor(lerp);
|
||||
lerp = lerp - uNu;
|
||||
return texture(table, vec3((uNu + uMuS) / float(RES_NU), uMu, uR)) * (1.0 - lerp) +
|
||||
texture(table, vec3((uNu + uMuS + 1.0) / float(RES_NU), uMu, uR)) * lerp;
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
float r = Rg + (gl_FragCoord.y - 0.5) / (float(SKY_H) - 1.0) * (Rt - Rg);
|
||||
float mu_s = -0.2 + (gl_FragCoord.x - 0.5) / (float(SKY_W) - 1.0) * (1.0 + 0.2);
|
||||
vec3 s = vec3(max(sqrt(1.0 - mu_s * mu_s), 0.0), 0.0, mu_s);
|
||||
|
||||
vec3 result = vec3(0.0);
|
||||
for (int iphi = 0; iphi < 2 * IRRADIANCE_INTEGRAL_SAMPLES; ++iphi) {
|
||||
float phi = (float(iphi) + 0.5) * dphi;
|
||||
for (int itheta = 0; itheta < IRRADIANCE_INTEGRAL_SAMPLES / 2; ++itheta) {
|
||||
float theta = (float(itheta) + 0.5) * dtheta;
|
||||
float dw = dtheta * dphi * sin(theta);
|
||||
vec3 w = vec3(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta));
|
||||
float nu = dot(s, w);
|
||||
if (first == 1.0) {
|
||||
float pr1 = phaseFunctionR(nu);
|
||||
float pm1 = phaseFunctionM(nu);
|
||||
vec3 ray1 = texture4D(deltaSRTexture, r, w.z, mu_s, nu).rgb;
|
||||
vec3 mie1 = texture4D(deltaSMTexture, r, w.z, mu_s, nu).rgb;
|
||||
result += (ray1 * pr1 + mie1 * pm1) * w.z * dw;
|
||||
} else {
|
||||
result += texture4D(deltaSRTexture, r, w.z, mu_s, nu).rgb * w.z * dw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderTableColor = vec4(result, 0.0);
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
31
modules/base/shaders/irradiance_sup_calc_vs.glsl
Normal file
31
modules/base/shaders/irradiance_sup_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
129
modules/base/shaders/shadow_fs.glsl
Normal file
129
modules/base/shaders/shadow_fs.glsl
Normal file
@@ -0,0 +1,129 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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;
|
||||
|
||||
in vec2 vs_st;
|
||||
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);
|
||||
|
||||
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 = daytex;
|
||||
|
||||
diffuse *= calcShadow(shadowDataArray, vs_posWorld.xyz);
|
||||
}
|
||||
|
||||
diffuse[3] = transparency;
|
||||
frag.color = diffuse;
|
||||
frag.depth = depth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
131
modules/base/shaders/shadow_nighttexture_fs.glsl
Normal file
131
modules/base/shaders/shadow_nighttexture_fs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
68
modules/base/shaders/shadow_nighttexture_vs.glsl
Normal file
68
modules/base/shaders/shadow_nighttexture_vs.glsl
Normal file
@@ -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);
|
||||
}
|
||||
68
modules/base/shaders/shadow_vs.glsl
Normal file
68
modules/base/shaders/shadow_vs.glsl
Normal file
@@ -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);
|
||||
}
|
||||
109
modules/base/shaders/transmittance_calc_fs.glsl
Normal file
109
modules/base/shaders/transmittance_calc_fs.glsl
Normal file
@@ -0,0 +1,109 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 "atmosphere_common.glsl"
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout(location = 1) out vec4 renderTableColor;
|
||||
|
||||
// In the following shaders r (altitude) is the length of vector/position x in the
|
||||
// atmosphere (or on the top of it when considering an observer in space),
|
||||
// where the light is comming from the opposity direction of the view direction,
|
||||
// here the vector v or viewDirection.
|
||||
// Rg is the planet radius
|
||||
|
||||
float rayDistance(const float r, const float mu) {
|
||||
// cosine law
|
||||
float distanceAtmosphereIntersect = -r * mu + sqrt(r * r * (mu * mu - 1.0) +
|
||||
(Rt + ATM_EPSILON)*(Rt + ATM_EPSILON));
|
||||
float distance = distanceAtmosphereIntersect;
|
||||
float delta = r * r * (mu * mu - 1.0) + Rg * Rg;
|
||||
// No imaginary numbers... :-)
|
||||
if (delta >= 0.0) {
|
||||
float distanceEarthIntersect = -r * mu - sqrt(delta);
|
||||
if (distanceEarthIntersect >= 0.0) {
|
||||
distance = min(distanceAtmosphereIntersect, distanceEarthIntersect);
|
||||
}
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
float opticalDepth(const float r, const float mu, const float scaleHeight) {
|
||||
|
||||
float r2 = r*r;
|
||||
// Is ray below horizon?
|
||||
// cosine law for triangles: y_i^2 = a^2 + b^2 - 2abcos(alpha)
|
||||
float cosZenithHorizon = -sqrt(1.0 - ((Rg*Rg)/r2));
|
||||
if (mu < cosZenithHorizon)
|
||||
return 1e9;
|
||||
|
||||
// Integrating using the Trapezoidal rule:
|
||||
// Integral(f(y)dy)(from a to b) = (b-a)/2n_steps*(Sum(f(y_i+1)+f(y_i)))
|
||||
float b_a = rayDistance(r, mu);
|
||||
float deltaStep = b_a / float(TRANSMITTANCE_STEPS);
|
||||
// cosine law
|
||||
float y_i = exp(-(r - Rg) / scaleHeight);
|
||||
|
||||
float x_step = 0.0;
|
||||
float accumulation = 0.0;
|
||||
for (int i = 1; i <= TRANSMITTANCE_STEPS; ++i) {
|
||||
float x_i = float(i) * deltaStep;
|
||||
// cosine law for triangles: y_i^2 = a^2 + b^2 - 2abcos(alpha)
|
||||
// In this case, a = r, b = x_i and cos(alpha) = cos(PI-zenithView) = mu
|
||||
float y_ii = exp(-(sqrt(r2 + x_i * x_i + 2.0 * x_i * r * mu) - Rg) / scaleHeight);
|
||||
accumulation += (y_ii + y_i);
|
||||
//x_step = x_i;
|
||||
y_i = y_ii;
|
||||
}
|
||||
return accumulation * (b_a/(2*TRANSMITTANCE_STEPS));
|
||||
}
|
||||
|
||||
void getRandMU(out float r, out float mu) {
|
||||
float u_mu = gl_FragCoord.x / float(TRANSMITTANCE_W);
|
||||
float u_r = gl_FragCoord.y / float(TRANSMITTANCE_H);
|
||||
|
||||
// In the paper u_r^2 = (r^2-Rg^2)/(Rt^2-Rg^2)
|
||||
r = sqrt(Rg*Rg + (u_r * u_r) * (Rt*Rt - Rg*Rg));
|
||||
|
||||
// In the paper the author suggest mu = dot(v,x)/||x|| with ||v|| = 1.0
|
||||
// Later he proposes u_mu = (1-exp(-3mu-0.6))/(1-exp(-3.6))
|
||||
// But the below one is better. See Colliene.
|
||||
mu = -0.15 + tan(1.5 * u_mu) / tan(1.5) * (1.0 + 0.15);
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
float r, mu;
|
||||
|
||||
getRandMU(r, mu);
|
||||
vec3 depth = betaMEx * opticalDepth(r, mu, HM) + betaR * opticalDepth(r, mu, HR);
|
||||
|
||||
renderTableColor = vec4(exp(-depth), 1.0);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(1.0);
|
||||
frag.depth = 1.0;
|
||||
|
||||
return frag;
|
||||
}
|
||||
31
modules/base/shaders/transmittance_calc_vs.glsl
Normal file
31
modules/base/shaders/transmittance_calc_vs.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
@@ -27,70 +27,74 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
set(HEADER_FILES
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/renderableglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/globemesh.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkedlodglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunknode.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkindex.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunk.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkedlodglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunknode.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkindex.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunk.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkrenderer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling.h
|
||||
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/trianglesoup.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/grid.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/basicgrid.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/skirtedgrid.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/ellipsoid.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodetic2.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/angle.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/ellipsoid.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/aabb.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunkrenderer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/culling.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/aabb.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/temporaltileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/asynctilereader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovidermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/layeredtextureshaderprovider.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/temporaltileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/asynctilereader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentqueue.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovidermanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/layeredtextureshaderprovider.h
|
||||
|
||||
|
||||
)
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/renderableglobe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/globemesh.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkedlodglobe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunknode.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkindex.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunk.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkedlodglobe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunknode.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkindex.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunk.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/chunkrenderer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chunk/culling.cpp
|
||||
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/trianglesoup.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/grid.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/basicgrid.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/meshes/skirtedgrid.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/ellipsoid.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/geodetic2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/angle.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/ellipsoid.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/geometry/aabb.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunkrenderer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/culling.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/aabb.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/temporaltileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tiledataset.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/asynctilereader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/tileprovidermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tile/layeredtextureshaderprovider.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/temporaltileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/asynctilereader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/lrucache.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/concurrentjobmanager.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/threadpool.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovidermanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/other/layeredtextureshaderprovider.cpp
|
||||
|
||||
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
@@ -98,7 +102,7 @@ source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/blending.hglsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/ellipsoid.hglsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/texturetile.hglsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/tile.hglsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/texturetilemapping.hglsl
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalchunkedlodpatch_vs.glsl
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunk.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/chunk/chunkedlodglobe.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Chunk";
|
||||
@@ -84,14 +84,26 @@ namespace openspace {
|
||||
return Status::WANT_MERGE;
|
||||
}
|
||||
|
||||
//int desiredLevel = desiredLevelByDistance(myRenderData);
|
||||
int desiredLevel = desiredLevelByProjectedArea(myRenderData);
|
||||
|
||||
// clamp level
|
||||
desiredLevel = glm::clamp(desiredLevel, _owner->minSplitDepth, _owner->maxSplitDepth);
|
||||
|
||||
if (desiredLevel < _index.level) return Status::WANT_MERGE;
|
||||
else if (_index.level < desiredLevel) return Status::WANT_SPLIT;
|
||||
else return Status::DO_NOTHING;
|
||||
}
|
||||
|
||||
int Chunk::desiredLevelByDistance(const RenderData& data) const {
|
||||
const Ellipsoid& ellipsoid = _owner->ellipsoid();
|
||||
Vec3 cameraPosition = myRenderData.camera.positionVec3();
|
||||
Vec3 cameraPosition = data.camera.positionVec3();
|
||||
Geodetic2 pointOnPatch = _surfacePatch.closestPoint(
|
||||
ellipsoid.cartesianToGeodetic2(cameraPosition));
|
||||
Vec3 globePosition = myRenderData.position.dvec3();
|
||||
ellipsoid.cartesianToGeodetic2(cameraPosition));
|
||||
Vec3 globePosition = data.position.dvec3();
|
||||
Vec3 patchPosition = globePosition + ellipsoid.cartesianSurfacePosition(pointOnPatch);
|
||||
Vec3 cameraToChunk = patchPosition - cameraPosition;
|
||||
|
||||
|
||||
|
||||
// Calculate desired level based on distance
|
||||
Scalar distance = glm::length(cameraToChunk);
|
||||
@@ -100,13 +112,84 @@ namespace openspace {
|
||||
Scalar scaleFactor = _owner->lodScaleFactor * ellipsoid.minimumRadius();;
|
||||
Scalar projectedScaleFactor = scaleFactor / distance;
|
||||
int desiredLevel = ceil(log2(projectedScaleFactor));
|
||||
return desiredLevel;
|
||||
}
|
||||
|
||||
// clamp level
|
||||
desiredLevel = glm::clamp(desiredLevel, _owner->minSplitDepth, _owner->maxSplitDepth);
|
||||
|
||||
if (desiredLevel < _index.level) return Status::WANT_MERGE;
|
||||
else if (_index.level < desiredLevel) return Status::WANT_SPLIT;
|
||||
else return Status::DO_NOTHING;
|
||||
int Chunk::desiredLevelByProjectedArea(const RenderData& data) const {
|
||||
const Ellipsoid& ellipsoid = _owner->ellipsoid();
|
||||
Vec3 cameraPosition = data.camera.positionVec3();
|
||||
Vec3 globePosition = data.position.dvec3();
|
||||
Vec3 cameraToEllipseCenter = globePosition - cameraPosition;
|
||||
|
||||
const Geodetic2 nwCorner = _surfacePatch.northWestCorner();
|
||||
const Geodetic2 neCorner = _surfacePatch.northEastCorner();
|
||||
const Geodetic2 swCorner = _surfacePatch.southWestCorner();
|
||||
const Geodetic2 seCorner = _surfacePatch.southEastCorner();
|
||||
|
||||
Geodetic2 camPos = ellipsoid.cartesianToGeodetic2(cameraPosition);
|
||||
|
||||
struct CornerDist {
|
||||
Geodetic2 corner;
|
||||
float dist;
|
||||
};
|
||||
|
||||
struct {
|
||||
bool operator()(const CornerDist& a, const CornerDist& b) {
|
||||
return a.dist < b.dist;
|
||||
}
|
||||
} byDist;
|
||||
|
||||
std::vector<CornerDist> cornerDists(4);
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
const Geodetic2& c = _surfacePatch.getCorner((Quad)i);
|
||||
Geodetic2 diff = (camPos - c);
|
||||
float latDiff = fAngle::fromRadians(diff.lat).getNormalizedAround(fAngle::ZERO).asRadians();
|
||||
float lonDiff = fAngle::fromRadians(diff.lon).getNormalizedAround(fAngle::ZERO).asRadians();
|
||||
cornerDists[i].corner = c;
|
||||
cornerDists[i].dist = latDiff*latDiff + lonDiff*lonDiff;;
|
||||
}
|
||||
|
||||
std::sort(cornerDists.begin(), cornerDists.end(), byDist);
|
||||
|
||||
BoundingHeights heights = getBoundingHeights();
|
||||
|
||||
const Geodetic3 c0 = { cornerDists[0].corner, heights.min };
|
||||
const Geodetic3 c1 = { cornerDists[1].corner, heights.min };
|
||||
const Geodetic3 c2 = { cornerDists[2].corner, heights.max };
|
||||
const Geodetic3 c3 = { cornerDists[3].corner, heights.max };
|
||||
|
||||
Vec3 A = cameraToEllipseCenter + ellipsoid.cartesianPosition(c0);
|
||||
Vec3 B = cameraToEllipseCenter + ellipsoid.cartesianPosition(c1);
|
||||
Vec3 C = cameraToEllipseCenter + ellipsoid.cartesianPosition(c2);
|
||||
Vec3 D = cameraToEllipseCenter + ellipsoid.cartesianPosition(c3);
|
||||
|
||||
// Project points onto unit sphere
|
||||
A = glm::normalize(A);
|
||||
B = glm::normalize(B);
|
||||
C = glm::normalize(C);
|
||||
D = glm::normalize(D);
|
||||
|
||||
|
||||
/*
|
||||
A-----____
|
||||
| '''-----B
|
||||
| __--' |
|
||||
| __--'' |
|
||||
C-----------------D
|
||||
*/
|
||||
|
||||
const Vec3 AB = B - A;
|
||||
const Vec3 AC = C - A;
|
||||
const Vec3 DC = C - D;
|
||||
const Vec3 DB = B - D;
|
||||
|
||||
double areaTriangle1 = 0.5 * glm::length(glm::cross(AC, AB));
|
||||
double areaTriangle2 = 0.5 * glm::length(glm::cross(DC, DB));
|
||||
double projectedChunkAreaApprox = areaTriangle1 + areaTriangle2;
|
||||
|
||||
double scaledArea = _owner->lodScaleFactor * projectedChunkAreaApprox;
|
||||
return _index.level + round(scaledArea - 1);
|
||||
}
|
||||
|
||||
Chunk::BoundingHeights Chunk::getBoundingHeights() const {
|
||||
@@ -30,10 +30,11 @@
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include <modules/globebrowsing/rendering/culling.h>
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkindex.h>
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
@@ -70,6 +71,9 @@ namespace openspace {
|
||||
|
||||
|
||||
private:
|
||||
int desiredLevelByDistance(const RenderData& data) const;
|
||||
int desiredLevelByProjectedArea(const RenderData& data) const;
|
||||
|
||||
ChunkedLodGlobe* _owner;
|
||||
ChunkIndex _index;
|
||||
bool _isVisible;
|
||||
@@ -22,10 +22,10 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/chunk/chunkedlodglobe.h>
|
||||
|
||||
#include <modules/globebrowsing/meshes/skirtedgrid.h>
|
||||
#include <modules/globebrowsing/rendering/culling.h>
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -38,10 +38,12 @@
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/globes/chunknode.h>
|
||||
#include <modules/globebrowsing/rendering/chunkrenderer.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunknode.h>
|
||||
#include <modules/globebrowsing/chunk/chunkrenderer.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -107,6 +109,7 @@ namespace openspace {
|
||||
bool blendWaterMask;
|
||||
bool blendOverlay;
|
||||
bool atmosphereEnabled;
|
||||
bool showChunkEdges;
|
||||
|
||||
private:
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkindex.h>
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
|
||||
namespace {
|
||||
@@ -29,9 +29,9 @@
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunknode.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/rendering/culling.h>
|
||||
#include <modules/globebrowsing/chunk/chunknode.h>
|
||||
#include <modules/globebrowsing/chunk/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
|
||||
|
||||
namespace {
|
||||
@@ -31,10 +31,12 @@
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkindex.h>
|
||||
#include <modules/globebrowsing/globes/chunk.h>
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/rendering/chunkrenderer.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/chunk/chunkrenderer.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <modules/globebrowsing/rendering/chunkrenderer.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/chunk/chunkrenderer.h>
|
||||
#include <modules/globebrowsing/chunk/chunkedlodglobe.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
@@ -187,6 +187,12 @@ namespace openspace {
|
||||
"useAtmosphere",
|
||||
std::to_string(chunk.owner()->atmosphereEnabled)));
|
||||
|
||||
layeredTexturePreprocessingData.keyValuePairs.push_back(
|
||||
std::pair<std::string, std::string>(
|
||||
"showChunkEdges",
|
||||
std::to_string(chunk.owner()->showChunkEdges)));
|
||||
|
||||
|
||||
// Now the shader program can be accessed
|
||||
ProgramObject* programObject =
|
||||
layeredTextureShaderProvider->getUpdatedShaderProgram(
|
||||
@@ -31,15 +31,15 @@
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
|
||||
#include <modules/globebrowsing/meshes/grid.h>
|
||||
|
||||
#include <modules/globebrowsing/other/tileprovidermanager.h>
|
||||
#include <modules/globebrowsing/other/layeredtextureshaderprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovidermanager.h>
|
||||
#include <modules/globebrowsing/tile/layeredtextureshaderprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunknode.h>
|
||||
#include <modules/globebrowsing/chunk/chunknode.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -23,10 +23,16 @@
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <modules/globebrowsing/rendering/culling.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/globes/chunk.h>
|
||||
|
||||
|
||||
|
||||
#include <modules/globebrowsing/chunk/culling.h>
|
||||
#include <modules/globebrowsing/chunk/chunkedlodglobe.h>
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
|
||||
#include <modules/globebrowsing/meshes/trianglesoup.h>
|
||||
|
||||
namespace {
|
||||
@@ -31,9 +31,9 @@
|
||||
// open space includes
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/rendering/aabb.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
#include <modules/globebrowsing/geometry/aabb.h>
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <modules/globebrowsing/rendering/aabb.h>
|
||||
#include <modules/globebrowsing/geometry/aabb.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -177,7 +177,7 @@ using fAngle = Angle<float>;
|
||||
|
||||
|
||||
|
||||
#include <modules/globebrowsing/geodetics/angle.inl>
|
||||
#include <modules/globebrowsing/geometry/angle.inl>
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __ELLIPSOID_H__
|
||||
#define __ELLIPSOID_H__
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkindex.h>
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
#include <modules/globebrowsing/globes/globemesh.h>
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
@@ -63,7 +62,6 @@ void GlobeBrowsingModule::internalInitialize() {
|
||||
ghoul_assert(fRenderable, "Renderable factory was not created");
|
||||
|
||||
fRenderable->registerClass<RenderableGlobe>("RenderableGlobe");
|
||||
fRenderable->registerClass<GlobeMesh>("GlobeMesh");
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 <modules/globebrowsing/globes/globemesh.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "GlobeMesh";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
GlobeMesh::GlobeMesh()
|
||||
: _programObject(nullptr)
|
||||
, _grid(10, 10, TriangleSoup::Positions::Yes, TriangleSoup::TextureCoordinates::No, TriangleSoup::Normals::No)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GlobeMesh::~GlobeMesh() {
|
||||
}
|
||||
|
||||
bool GlobeMesh::initialize() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject == nullptr) {
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"simpleTextureProgram",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/simple_vs.glsl",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/simple_fs.glsl");
|
||||
if (!_programObject) return false;
|
||||
}
|
||||
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool GlobeMesh::deinitialize() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GlobeMesh::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
return ready;
|
||||
}
|
||||
|
||||
void GlobeMesh::render(const RenderData& data)
|
||||
{
|
||||
// activate shader
|
||||
_programObject->activate();
|
||||
|
||||
// scale the planet to appropriate size since the planet is a unit sphere. Ehm no?
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
|
||||
// setup the data to the shader
|
||||
// _programObject->setUniform("camdir", camSpaceEye);
|
||||
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_programObject->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(*_programObject.get(), data.camera, data.position);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
|
||||
// render
|
||||
_grid.geometry().drawUsingActiveProgram();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void GlobeMesh::update(const UpdateData& data) {
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,66 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __GLOBEMESH_H__
|
||||
#define __GLOBEMESH_H__
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <modules/globebrowsing/meshes/trianglesoup.h>
|
||||
#include <modules/globebrowsing/meshes/basicgrid.h>
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class GlobeMesh : public Renderable {
|
||||
public:
|
||||
GlobeMesh();
|
||||
virtual ~GlobeMesh();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
|
||||
BasicGrid _grid;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __GLOBEMESH_H__
|
||||
@@ -23,9 +23,9 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/globes/globemesh.h>
|
||||
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
#include <modules/globebrowsing/other/temporaltileprovider.h>
|
||||
#include <modules/globebrowsing/tile/temporaltileprovider.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -68,6 +68,7 @@ namespace openspace {
|
||||
, blendOverlay(properties::BoolProperty("blendOverlay", "blendOverlay", true))
|
||||
, blendWaterMask(properties::BoolProperty("blendWaterMask", "blendWaterMask", true))
|
||||
, atmosphereEnabled(properties::BoolProperty("atmosphereEnabled", "atmosphereEnabled", false))
|
||||
, showChunkEdges(properties::BoolProperty("showChunkEdges", "showChunkEdges", false))
|
||||
{
|
||||
setName("RenderableGlobe");
|
||||
|
||||
@@ -86,6 +87,7 @@ namespace openspace {
|
||||
addProperty(blendOverlay);
|
||||
addProperty(blendWaterMask);
|
||||
addProperty(atmosphereEnabled);
|
||||
addProperty(showChunkEdges);
|
||||
|
||||
doFrustumCulling.setValue(true);
|
||||
doHorizonCulling.setValue(true);
|
||||
@@ -200,6 +202,7 @@ namespace openspace {
|
||||
_chunkedLodGlobe->blendOverlay = blendOverlay.value();
|
||||
_chunkedLodGlobe->blendWaterMask = blendWaterMask.value();
|
||||
_chunkedLodGlobe->atmosphereEnabled = atmosphereEnabled.value();
|
||||
_chunkedLodGlobe->showChunkEdges = showChunkEdges.value();
|
||||
|
||||
std::vector<TileProviderManager::TileProviderWithName>& colorTextureProviders =
|
||||
_tileProviderManager->getLayerCategory("ColorTextures");
|
||||
|
||||
@@ -35,13 +35,15 @@
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <modules/globebrowsing/meshes/trianglesoup.h>
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
#include <modules/globebrowsing/globes/globemesh.h>
|
||||
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/ellipsoid.h>
|
||||
#include <modules/globebrowsing/other/tileprovidermanager.h>
|
||||
#include <modules/globebrowsing/chunk/chunkedlodglobe.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/ellipsoid.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovidermanager.h>
|
||||
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -82,6 +84,7 @@ public:
|
||||
properties::BoolProperty blendOverlay;
|
||||
properties::BoolProperty blendWaterMask;
|
||||
properties::BoolProperty atmosphereEnabled;
|
||||
properties::BoolProperty showChunkEdges;
|
||||
|
||||
private:
|
||||
std::string _frame;
|
||||
|
||||
@@ -22,34 +22,34 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
#include "fragment.glsl"
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
|
||||
uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
uniform TextureTile colorTilesParent2[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile colorTiles[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile colorTilesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile colorTilesParent2[NUMLAYERS_COLORTEXTURE];
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#if USE_NIGHTTEXTURE
|
||||
uniform TextureTile nightTiles[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform TextureTile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform TextureTile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile nightTiles[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE];
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
#if USE_OVERLAY
|
||||
uniform TextureTile overlayTiles[NUMLAYERS_OVERLAY];
|
||||
uniform TextureTile overlayTilesParent1[NUMLAYERS_OVERLAY];
|
||||
uniform TextureTile overlayTilesParent2[NUMLAYERS_OVERLAY];
|
||||
uniform Tile overlayTiles[NUMLAYERS_OVERLAY];
|
||||
uniform Tile overlayTilesParent1[NUMLAYERS_OVERLAY];
|
||||
uniform Tile overlayTilesParent2[NUMLAYERS_OVERLAY];
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
#if USE_WATERMASK
|
||||
uniform TextureTile waterTiles[NUMLAYERS_WATERMASK];
|
||||
uniform TextureTile waterTilesParent1[NUMLAYERS_WATERMASK];
|
||||
uniform TextureTile waterTilesParent2[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTiles[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTilesParent1[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTilesParent2[NUMLAYERS_WATERMASK];
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
#if USE_ATMOSPHERE
|
||||
@@ -60,18 +60,20 @@ in vec3 ellipsoidNormalCameraSpace;
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
|
||||
in float tileInterpolationParameter;
|
||||
in LevelWeights levelWeights;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = vec4(0.1,0.1,0.1,1);
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
//LevelWeights levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
|
||||
frag.color = calculateColor(
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,//levelInterpolationParameter,
|
||||
colorTiles,
|
||||
colorTilesParent1,
|
||||
colorTilesParent2);
|
||||
@@ -83,7 +85,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateWater(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
waterTiles,
|
||||
waterTilesParent1,
|
||||
waterTilesParent2);
|
||||
@@ -95,7 +97,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateNight(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
nightTiles,
|
||||
nightTilesParent1,
|
||||
nightTilesParent2,
|
||||
@@ -112,14 +114,16 @@ Fragment getFragment() {
|
||||
frag.color = calculateOverlay(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
overlayTiles,
|
||||
overlayTilesParent1,
|
||||
overlayTilesParent2);
|
||||
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
//frag.color += patchBorderOverlay(fs_uv, vec3(0,1,0), 0.02);
|
||||
#if SHOW_CHUNK_EDGES
|
||||
frag.color += patchBorderOverlay(fs_uv, vec3(0,1,0), 0.02);
|
||||
#endif // SHOW_CHUNK_EDGES
|
||||
|
||||
frag.depth = fs_position.w;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
|
||||
uniform mat4 modelViewProjectionTransform;
|
||||
@@ -40,9 +40,9 @@ uniform int xSegments;
|
||||
uniform float skirtLength;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform TextureTile heightTiles[NUMLAYERS_HEIGHTMAP];
|
||||
uniform TextureTile heightTilesParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform TextureTile heightTilesParent2[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile heightTiles[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile heightTilesParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
uniform vec3 cameraPosition;
|
||||
@@ -54,9 +54,8 @@ layout(location = 1) in vec2 in_uv;
|
||||
out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
// tileInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
out float tileInterpolationParameter;
|
||||
|
||||
out LevelWeights levelWeights;
|
||||
|
||||
PositionNormalPair globalInterpolation() {
|
||||
vec2 lonLatInput;
|
||||
@@ -74,8 +73,8 @@ void main()
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
tileInterpolationParameter = chunkLevel - desiredLevel;
|
||||
|
||||
float levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
float height = 0;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
@@ -84,7 +83,7 @@ void main()
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
tileInterpolationParameter, // Variable to determine which texture to sample from
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
heightTiles, heightTilesParent1, heightTilesParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
@@ -22,38 +22,38 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
|
||||
uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
uniform TextureTile colorTilesParent2[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile colorTiles[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile colorTilesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile colorTilesParent2[NUMLAYERS_COLORTEXTURE];
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#if USE_NIGHTTEXTURE
|
||||
uniform TextureTile nightTiles[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform TextureTile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform TextureTile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile nightTiles[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE];
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
#if USE_OVERLAY
|
||||
uniform TextureTile overlayTiles[NUMLAYERS_OVERLAY];
|
||||
uniform TextureTile overlayTilesParent1[NUMLAYERS_OVERLAY];
|
||||
uniform TextureTile overlayTilesParent2[NUMLAYERS_OVERLAY];
|
||||
uniform Tile overlayTiles[NUMLAYERS_OVERLAY];
|
||||
uniform Tile overlayTilesParent1[NUMLAYERS_OVERLAY];
|
||||
uniform Tile overlayTilesParent2[NUMLAYERS_OVERLAY];
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
#if USE_WATERMASK
|
||||
uniform TextureTile waterTiles[NUMLAYERS_WATERMASK];
|
||||
uniform TextureTile waterTilesParent1[NUMLAYERS_WATERMASK];
|
||||
uniform TextureTile waterTilesParent2[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTiles[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTilesParent1[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTilesParent2[NUMLAYERS_WATERMASK];
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
// tileInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// levelInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
in float tileInterpolationParameter;
|
||||
in LevelWeights levelWeights;
|
||||
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
@@ -68,7 +68,7 @@ Fragment getFragment() {
|
||||
|
||||
frag.color = calculateColor(
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
colorTiles,
|
||||
colorTilesParent1,
|
||||
colorTilesParent2);
|
||||
@@ -81,7 +81,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateWater(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
waterTiles,
|
||||
waterTilesParent1,
|
||||
waterTilesParent2);
|
||||
@@ -94,7 +94,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateNight(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
nightTiles,
|
||||
nightTilesParent1,
|
||||
nightTilesParent2,
|
||||
@@ -111,14 +111,17 @@ Fragment getFragment() {
|
||||
frag.color = calculateOverlay(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelWeights,
|
||||
overlayTiles,
|
||||
overlayTilesParent1,
|
||||
overlayTilesParent2);
|
||||
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
//frag.color += patchBorderOverlay(fs_uv, vec3(1,0,0), 0.02);
|
||||
#if SHOW_CHUNK_EDGES
|
||||
frag.color += patchBorderOverlay(fs_uv, vec3(1,0,0), 0.02);
|
||||
#endif // SHOW_CHUNK_EDGES
|
||||
|
||||
|
||||
frag.depth = fs_position.w;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
|
||||
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1
|
||||
@@ -42,9 +42,9 @@ uniform vec3 p11;
|
||||
uniform vec3 patchNormalCameraSpace;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform TextureTile heightTiles[NUMLAYERS_HEIGHTMAP];
|
||||
uniform TextureTile heightTilesParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform TextureTile heightTilesParent2[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile heightTiles[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile heightTilesParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
uniform int xSegments;
|
||||
@@ -59,9 +59,7 @@ out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
|
||||
// tileInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
out float tileInterpolationParameter;
|
||||
out LevelWeights levelWeights;
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
// Bilinear interpolation
|
||||
@@ -84,7 +82,8 @@ void main()
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
tileInterpolationParameter = chunkLevel - desiredLevel;
|
||||
float levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
|
||||
@@ -92,7 +91,7 @@ void main()
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
tileInterpolationParameter, // Variable to determine which texture to sample from
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
heightTiles, heightTilesParent1, heightTilesParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
@@ -25,134 +25,62 @@
|
||||
#ifndef TEXTURETILEMAPPING_HGLSL
|
||||
#define TEXTURETILEMAPPING_HGLSL
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/blending.hglsl>
|
||||
|
||||
// First layer type from LayeredTextureShaderProvider is height map
|
||||
#ifndef NUMLAYERS_HEIGHTMAP
|
||||
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1
|
||||
#endif // NUMLAYERS_HEIGHTMAP
|
||||
|
||||
#ifndef USE_HEIGHTMAP
|
||||
#define USE_HEIGHTMAP #{useHeightMap}
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#ifndef HEIGHTMAP_BLENDING_ENABLED
|
||||
#define HEIGHTMAP_BLENDING_ENABLED #{heightMapBlendingEnabled}
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
// Second layer type from LayeredTextureShaderProvider is color texture
|
||||
#ifndef NUMLAYERS_COLORTEXTURE
|
||||
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1
|
||||
#endif // NUMLAYERS_COLORTEXTURE
|
||||
|
||||
#ifndef USE_COLORTEXTURE
|
||||
#define USE_COLORTEXTURE #{useColorTexture}
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#ifndef COLORTEXTURE_BLENDING_ENABLED
|
||||
#define COLORTEXTURE_BLENDING_ENABLED #{colorTextureBlendingEnabled}
|
||||
#endif // COLORTEXTURE_BLENDING_ENABLED
|
||||
|
||||
// Third layer type from LayeredTextureShaderProvider is water mask
|
||||
#ifndef NUMLAYERS_WATERMASK
|
||||
#define NUMLAYERS_WATERMASK #{lastLayerIndexWater} + 1
|
||||
#endif // NUMLAYERS_WATERMASK
|
||||
|
||||
#ifndef USE_WATERMASK
|
||||
#define USE_WATERMASK #{useWaterMask}
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
#ifndef WATERMASK_BLENDING_ENABLED
|
||||
#define WATERMASK_BLENDING_ENABLED #{waterMaskBlendingEnabled}
|
||||
#endif // WATERMASK_BLENDING_ENABLED
|
||||
|
||||
// Fourth layer type from LayeredTextureShaderProvider is night texture
|
||||
#ifndef NUMLAYERS_NIGHTTEXTURE
|
||||
#define NUMLAYERS_NIGHTTEXTURE #{lastLayerIndexNight} + 1
|
||||
#endif // NUMLAYERS_NIGHTTEXTURE
|
||||
|
||||
#ifndef USE_NIGHTTEXTURE
|
||||
#define USE_NIGHTTEXTURE #{useNightTexture}
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
#ifndef NIGHTTEXTURE_BLENDING_ENABLED
|
||||
#define NIGHTTEXTURE_BLENDING_ENABLED #{nightTextureBlendingEnabled}
|
||||
#endif // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
|
||||
// Fifth layer type from LayeredTextureShaderProvider is overlay
|
||||
#ifndef NUMLAYERS_OVERLAY
|
||||
#define NUMLAYERS_OVERLAY #{lastLayerIndexOverlay} + 1
|
||||
#endif // NUMLAYERS_OVERLAY
|
||||
|
||||
#ifndef USE_OVERLAY
|
||||
#define USE_OVERLAY #{useOverlay}
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
#ifndef OVERLAY_BLENDING_ENABLED
|
||||
#define OVERLAY_BLENDING_ENABLED #{overlayBlendingEnabled}
|
||||
#endif // OVERLAY_BLENDING_ENABLED
|
||||
|
||||
// Other key value pairs used for settings
|
||||
#ifndef USE_ATMOSPHERE
|
||||
#define USE_ATMOSPHERE #{useAtmosphere}
|
||||
#endif // USE_ATMOSPHERE
|
||||
#define SHOW_CHUNK_EDGES #{showChunkEdges}
|
||||
|
||||
float calculateHeight(
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const TextureTile heightTiles[NUMLAYERS_HEIGHTMAP],
|
||||
const TextureTile heightTilesParent1[NUMLAYERS_HEIGHTMAP],
|
||||
const TextureTile heightTilesParent2[NUMLAYERS_HEIGHTMAP]) {
|
||||
LevelWeights levelWeights,
|
||||
const Tile heightTiles[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent1[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP]) {
|
||||
|
||||
float height = 0;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if HEIGHTMAP_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
#else // HEIGHTMAP_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
#if !HEIGHTMAP_BLENDING_ENABLED
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexHeight}
|
||||
{
|
||||
vec2 samplePos =
|
||||
heightTiles[#{i}].uvTransform.uvScale * uv +
|
||||
heightTiles[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent1 =
|
||||
heightTilesParent1[#{i}].uvTransform.uvScale * uv +
|
||||
heightTilesParent1[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent2 =
|
||||
heightTilesParent2[#{i}].uvTransform.uvScale * uv +
|
||||
heightTilesParent2[#{i}].uvTransform.uvOffset;
|
||||
float untransformedHeight =
|
||||
levelWeights.w1 * getTexVal(heightTiles[#{i}], uv).r +
|
||||
levelWeights.w2 * getTexVal(heightTilesParent1[#{i}], uv).r +
|
||||
levelWeights.w3 * getTexVal(heightTilesParent2[#{i}], uv).r;
|
||||
|
||||
/*
|
||||
float sampledValue =
|
||||
w1 * textureLod(heightTiles[#{i}].textureSampler, samplePos, 0).r +
|
||||
w2 * textureLod(heightTilesParent1[#{i}].textureSampler, samplePosParent1, 0).r +
|
||||
w3 * textureLod(heightTilesParent2[#{i}].textureSampler, samplePosParent2, 0).r;
|
||||
*/
|
||||
/*
|
||||
float sampledValue =
|
||||
w1 * textureGrad(heightTiles[#{i}].textureSampler, samplePos, vec2(0), vec2(0)).r +
|
||||
w2 * textureGrad(heightTilesParent1[#{i}].textureSampler, samplePosParent1, vec2(0), vec2(0)).r +
|
||||
w3 * textureGrad(heightTilesParent2[#{i}].textureSampler, samplePosParent2, vec2(0), vec2(0)).r;
|
||||
*/
|
||||
|
||||
float sampledValue =
|
||||
w1 * texture(heightTiles[#{i}].textureSampler, samplePos).r +
|
||||
w2 * texture(heightTilesParent1[#{i}].textureSampler, samplePosParent1).r +
|
||||
w3 * texture(heightTilesParent2[#{i}].textureSampler, samplePosParent2).r;
|
||||
|
||||
// TODO : Some kind of blending here. Now it just writes over
|
||||
height = (sampledValue *
|
||||
heightTiles[#{i}].depthTransform.depthScale +
|
||||
heightTiles[#{i}].depthTransform.depthOffset);
|
||||
// OBS! Only the values from the last height map will be used!
|
||||
height = getTransformedTexVal(heightTiles[#{i}].depthTransform, untransformedHeight);
|
||||
}
|
||||
#endfor
|
||||
|
||||
@@ -161,54 +89,25 @@ float calculateHeight(
|
||||
|
||||
vec4 calculateColor(
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const TextureTile colorTiles[NUMLAYERS_COLORTEXTURE],
|
||||
const TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE],
|
||||
const TextureTile colorTilesParent2[NUMLAYERS_COLORTEXTURE]) {
|
||||
LevelWeights levelWeights,
|
||||
const Tile colorTiles[NUMLAYERS_COLORTEXTURE],
|
||||
const Tile colorTilesParent1[NUMLAYERS_COLORTEXTURE],
|
||||
const Tile colorTilesParent2[NUMLAYERS_COLORTEXTURE]) {
|
||||
|
||||
vec4 color = vec4(0);
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if COLORTEXTURE_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
#else // COLORTEXTURE_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
#if !COLORTEXTURE_BLENDING_ENABLED
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // COLORTEXTURE_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexColor}
|
||||
{
|
||||
vec2 samplePos =
|
||||
colorTiles[#{i}].uvTransform.uvScale * uv +
|
||||
colorTiles[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent1 =
|
||||
colorTilesParent1[#{i}].uvTransform.uvScale * uv +
|
||||
colorTilesParent1[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent2 =
|
||||
colorTilesParent2[#{i}].uvTransform.uvScale * uv +
|
||||
colorTilesParent2[#{i}].uvTransform.uvOffset;
|
||||
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureLod(colorTiles[#{i}].textureSampler, samplePos, 0) +
|
||||
w2 * textureLod(colorTilesParent1[#{i}].textureSampler, samplePosParent1, 0) +
|
||||
w3 * textureLod(colorTilesParent2[#{i}].textureSampler, samplePosParent2, 0);
|
||||
*/
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureGrad(colorTiles[#{i}].textureSampler, samplePos, vec2(0), vec2(0)) +
|
||||
w2 * textureGrad(colorTilesParent1[#{i}].textureSampler, samplePosParent1, vec2(0), vec2(0)) +
|
||||
w3 * textureGrad(colorTilesParent2[#{i}].textureSampler, samplePosParent2, vec2(0), vec2(0));
|
||||
*/
|
||||
|
||||
vec4 colorSample =
|
||||
w1 * texture(colorTiles[#{i}].textureSampler, samplePos) +
|
||||
w2 * texture(colorTilesParent1[#{i}].textureSampler, samplePosParent1) +
|
||||
w3 * texture(colorTilesParent2[#{i}].textureSampler, samplePosParent2);
|
||||
vec4 colorSample =
|
||||
levelWeights.w1 * getTexVal(colorTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(colorTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(colorTilesParent2[#{i}], uv);
|
||||
|
||||
color = blendOver(color, colorSample);
|
||||
}
|
||||
@@ -220,10 +119,10 @@ vec4 calculateColor(
|
||||
vec4 calculateNight(
|
||||
const vec4 currentColor,
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const TextureTile nightTiles[NUMLAYERS_NIGHTTEXTURE],
|
||||
const TextureTile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE],
|
||||
const TextureTile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE],
|
||||
LevelWeights levelWeights,
|
||||
const Tile nightTiles[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE],
|
||||
const vec3 ellipsoidNormalCameraSpace) {
|
||||
|
||||
vec3 lightDirection = normalize(vec3(-1,-1,-1));
|
||||
@@ -233,45 +132,16 @@ vec4 calculateNight(
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if NIGHTTEXTURE_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
#else // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
#if !NIGHTTEXTURE_BLENDING_ENABLED
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexNight}
|
||||
{
|
||||
vec2 samplePos =
|
||||
nightTiles[#{i}].uvTransform.uvScale * uv +
|
||||
nightTiles[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent1 =
|
||||
nightTilesParent1[#{i}].uvTransform.uvScale * uv +
|
||||
nightTilesParent1[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent2 =
|
||||
nightTilesParent2[#{i}].uvTransform.uvScale * uv +
|
||||
nightTilesParent2[#{i}].uvTransform.uvOffset;
|
||||
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureLod(nightTiles[#{i}].textureSampler, samplePos, 0) +
|
||||
w2 * textureLod(nightTilesParent1[#{i}].textureSampler, samplePosParent1, 0) +
|
||||
w3 * textureLod(nightTilesParent2[#{i}].textureSampler, samplePosParent2, 0);
|
||||
*/
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureGrad(nightTiles[#{i}].textureSampler, samplePos, vec2(0), vec2(0)) +
|
||||
w2 * textureGrad(nightTilesParent1[#{i}].textureSampler, samplePosParent1, vec2(0), vec2(0)) +
|
||||
w3 * textureGrad(nightTilesParent2[#{i}].textureSampler, samplePosParent2, vec2(0), vec2(0));
|
||||
*/
|
||||
|
||||
vec4 colorSample =
|
||||
w1 * texture(nightTiles[#{i}].textureSampler, samplePos) +
|
||||
w2 * texture(nightTilesParent1[#{i}].textureSampler, samplePosParent1) +
|
||||
w3 * texture(nightTilesParent2[#{i}].textureSampler, samplePosParent2);
|
||||
levelWeights.w1 * getTexVal(nightTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(nightTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(nightTilesParent2[#{i}], uv);
|
||||
|
||||
nightColor = blendOver(nightColor, colorSample);
|
||||
}
|
||||
@@ -286,54 +156,25 @@ vec4 calculateNight(
|
||||
vec4 calculateOverlay(
|
||||
const vec4 currentColor,
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const TextureTile overlayTiles[NUMLAYERS_OVERLAY],
|
||||
const TextureTile overlayTilesParent1[NUMLAYERS_OVERLAY],
|
||||
const TextureTile overlayTilesParent2[NUMLAYERS_OVERLAY]) {
|
||||
LevelWeights levelWeights,
|
||||
const Tile overlayTiles[NUMLAYERS_OVERLAY],
|
||||
const Tile overlayTilesParent1[NUMLAYERS_OVERLAY],
|
||||
const Tile overlayTilesParent2[NUMLAYERS_OVERLAY]) {
|
||||
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if OVERLAY_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
#else // OVERLAY_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
#if !OVERLAY_BLENDING_ENABLED
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // OVERLAY_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexOverlay}
|
||||
{
|
||||
vec2 samplePos =
|
||||
overlayTiles[#{i}].uvTransform.uvScale * uv +
|
||||
overlayTiles[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent1 =
|
||||
overlayTilesParent1[#{i}].uvTransform.uvScale * uv +
|
||||
overlayTilesParent1[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent2 =
|
||||
overlayTilesParent2[#{i}].uvTransform.uvScale * uv +
|
||||
overlayTilesParent2[#{i}].uvTransform.uvOffset;
|
||||
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureLod(overlayTiles[#{i}].textureSampler, samplePos, 0) +
|
||||
w2 * textureLod(overlayTilesParent1[#{i}].textureSampler, samplePosParent1, 0) +
|
||||
w3 * textureLod(overlayTilesParent2[#{i}].textureSampler, samplePosParent2, 0);
|
||||
*/
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureGrad(overlayTiles[#{i}].textureSampler, samplePos, vec2(0), vec2(0)) +
|
||||
w2 * textureGrad(overlayTilesParent1[#{i}].textureSampler, samplePosParent1, vec2(0), vec2(0)) +
|
||||
w3 * textureGrad(overlayTilesParent2[#{i}].textureSampler, samplePosParent2, vec2(0), vec2(0));
|
||||
*/
|
||||
|
||||
vec4 colorSample =
|
||||
w1 * texture(overlayTiles[#{i}].textureSampler, samplePos) +
|
||||
w2 * texture(overlayTilesParent1[#{i}].textureSampler, samplePosParent1) +
|
||||
w3 * texture(overlayTilesParent2[#{i}].textureSampler, samplePosParent2);
|
||||
levelWeights.w1 * getTexVal(overlayTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(overlayTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(overlayTilesParent2[#{i}], uv);
|
||||
|
||||
color = blendOver(color, colorSample);
|
||||
}
|
||||
@@ -345,54 +186,25 @@ vec4 calculateOverlay(
|
||||
vec4 calculateWater(
|
||||
const vec4 currentColor,
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const TextureTile waterTiles[NUMLAYERS_WATERMASK],
|
||||
const TextureTile waterTilesParent1[NUMLAYERS_WATERMASK],
|
||||
const TextureTile waterTilesParent2[NUMLAYERS_WATERMASK]) {
|
||||
LevelWeights levelWeights,
|
||||
const Tile waterTiles[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent1[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent2[NUMLAYERS_WATERMASK]) {
|
||||
|
||||
vec4 waterColor = vec4(0,0,0,0);
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if WATERMASK_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
#else // WATERMASK_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
#if !WATERMASK_BLENDING_ENABLED
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // WATERMASK_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexWater}
|
||||
{
|
||||
vec2 samplePos =
|
||||
waterTiles[#{i}].uvTransform.uvScale * uv +
|
||||
waterTiles[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent1 =
|
||||
waterTilesParent1[#{i}].uvTransform.uvScale * uv +
|
||||
waterTilesParent1[#{i}].uvTransform.uvOffset;
|
||||
vec2 samplePosParent2 =
|
||||
waterTilesParent2[#{i}].uvTransform.uvScale * uv +
|
||||
waterTilesParent2[#{i}].uvTransform.uvOffset;
|
||||
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureLod(waterTiles[#{i}].textureSampler, samplePos, 0) +
|
||||
w2 * textureLod(waterTilesParent1[#{i}].textureSampler, samplePosParent1, 0) +
|
||||
w3 * textureLod(waterTilesParent2[#{i}].textureSampler, samplePosParent2, 0);
|
||||
*/
|
||||
/*
|
||||
vec4 colorSample =
|
||||
w1 * textureGrad(waterTiles[#{i}].textureSampler, samplePos, vec2(0), vec2(0)) +
|
||||
w2 * textureGrad(waterTilesParent1[#{i}].textureSampler, samplePosParent1, vec2(0), vec2(0)) +
|
||||
w3 * textureGrad(waterTilesParent2[#{i}].textureSampler, samplePosParent2, vec2(0), vec2(0));
|
||||
*/
|
||||
|
||||
vec4 colorSample =
|
||||
w1 * texture(waterTiles[#{i}].textureSampler, samplePos) +
|
||||
w2 * texture(waterTilesParent1[#{i}].textureSampler, samplePosParent1) +
|
||||
w3 * texture(waterTilesParent2[#{i}].textureSampler, samplePosParent2);
|
||||
levelWeights.w1 * getTexVal(waterTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(waterTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(waterTilesParent2[#{i}], uv);
|
||||
|
||||
waterColor = blendOver(waterColor, colorSample);
|
||||
}
|
||||
|
||||
123
modules/globebrowsing/shaders/tile.hglsl
Normal file
123
modules/globebrowsing/shaders/tile.hglsl
Normal file
@@ -0,0 +1,123 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef TEXTURETILE_HGLSL
|
||||
#define TEXTURETILE_HGLSL
|
||||
|
||||
vec4 patchBorderOverlay(vec2 uv, vec3 borderColor, float borderSize) {
|
||||
vec2 uvOffset = uv - vec2(0.5);
|
||||
float thres = 0.5 - borderSize/2;
|
||||
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
|
||||
vec3 color = isBorder ? borderColor : vec3(0);
|
||||
return vec4(color, 0);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Tile Depth Transform //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct TileDepthTransform {
|
||||
float depthScale;
|
||||
float depthOffset;
|
||||
};
|
||||
|
||||
float getTransformedTexVal(const TileDepthTransform transform, const float val){
|
||||
return transform.depthOffset + transform.depthScale * val;
|
||||
}
|
||||
|
||||
vec4 getTransformedTexVal(const TileDepthTransform transform, const vec4 val){
|
||||
return transform.depthOffset + transform.depthScale * val;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Tile UV Transform //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct TileUvTransform {
|
||||
vec2 uvOffset;
|
||||
vec2 uvScale;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Tile //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
struct Tile {
|
||||
sampler2D textureSampler;
|
||||
|
||||
TileDepthTransform depthTransform;
|
||||
TileUvTransform uvTransform;
|
||||
};
|
||||
|
||||
|
||||
vec4 getTexVal(const Tile tile, const vec2 tileUV){
|
||||
vec2 samplePos = tile.uvTransform.uvOffset + tile.uvTransform.uvScale * tileUV;
|
||||
vec4 texVal = texture(tile.textureSampler, samplePos);
|
||||
return texVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Multi Level Tile //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
struct MultiLevelTile {
|
||||
Tile tile0;
|
||||
Tile tile1;
|
||||
Tile tile2;
|
||||
};
|
||||
|
||||
struct LevelWeights {
|
||||
float w1;
|
||||
float w2;
|
||||
float w3;
|
||||
};
|
||||
|
||||
LevelWeights getLevelWeights(float levelInterpolationParameter){
|
||||
LevelWeights levelWeights;
|
||||
levelWeights.w1 = clamp(1 - levelInterpolationParameter, 0 , 1);
|
||||
levelWeights.w2 = (clamp(levelInterpolationParameter, 0 , 1) - clamp(levelInterpolationParameter - 1, 0 , 1));
|
||||
levelWeights.w3 = clamp(levelInterpolationParameter - 1, 0 , 1);
|
||||
return levelWeights;
|
||||
}
|
||||
|
||||
LevelWeights getDefaultLevelWeights(){
|
||||
LevelWeights levelWeights;
|
||||
levelWeights.w1 = 1;
|
||||
levelWeights.w2 = 0;
|
||||
levelWeights.w3 = 0;
|
||||
return levelWeights;
|
||||
}
|
||||
|
||||
|
||||
vec4 getTexVal(const MultiLevelTile multiLevelTile, const LevelWeights w, const vec2 uv){
|
||||
return w.w1 * getTexVal(multiLevelTile.tile0, uv) +
|
||||
w.w2 * getTexVal(multiLevelTile.tile1, uv) +
|
||||
w.w3 * getTexVal(multiLevelTile.tile2, uv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // TEXTURETILE_HGLSL
|
||||
@@ -22,7 +22,8 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/other/tileprovidermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileprovidermanager.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include "cpl_minixml.h"
|
||||
@@ -26,8 +26,9 @@
|
||||
#define __TILE_PROVIDER_MANAGER_H__
|
||||
|
||||
|
||||
#include <modules/globebrowsing/other/temporaltileprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/tile/temporaltileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
@@ -27,9 +27,10 @@
|
||||
#include <ghoul/filesystem/filesystem.h> // abspath
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/globebrowsing/other/asynctilereader.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
#include <modules/globebrowsing/tile/asynctilereader.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "AsyncTextureDataProvider";
|
||||
@@ -30,11 +30,12 @@
|
||||
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/other/concurrentjobmanager.h>
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
#include <modules/globebrowsing/other/tiledataset.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
@@ -22,7 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/other/layeredtextureshaderprovider.h>
|
||||
#include <modules/globebrowsing/tile/layeredtextureshaderprovider.h>
|
||||
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -22,10 +22,11 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/temporaltileprovider.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/temporaltileprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/tileprovider.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -27,9 +27,10 @@
|
||||
#include <ghoul/filesystem/filesystem.h> // abspath
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/globebrowsing/other/tiledataset.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/geodetics/angle.h>
|
||||
#include <modules/globebrowsing/tile/tiledataset.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider.h>
|
||||
|
||||
#include <modules/globebrowsing/geometry/angle.h>
|
||||
|
||||
#include <float.h>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
|
||||
#include "gdal_priv.h"
|
||||
@@ -22,11 +22,12 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/other/tileprovider.h>
|
||||
#include <modules/globebrowsing/other/tileprovidermanager.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/globes/chunkindex.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileprovidermanager.h>
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunkindex.h>
|
||||
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
|
||||
@@ -35,9 +35,12 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
|
||||
#include <modules/globebrowsing/geodetics/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
|
||||
#include <modules/globebrowsing/tile/asynctilereader.h>
|
||||
|
||||
#include <modules/globebrowsing/other/lrucache.h>
|
||||
#include <modules/globebrowsing/other/asynctilereader.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TILE PROVIDER //
|
||||
@@ -7,10 +7,10 @@ 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}/default-moon.scene",
|
||||
-- Scene = "${SCENE}/default_nh.scene",
|
||||
-- Scene = "${SCENE}/default.scene",
|
||||
Scene = "${SCENE}/globebrowsing.scene",
|
||||
Scene = "${SCENE}/globebrowsing.scene",
|
||||
-- Scene = "${SCENE}/default-modified.scene",
|
||||
-- Scene = "${SCENE}/rosetta.scene",
|
||||
-- Scene = "${SCENE}/dawn.scene",
|
||||
|
||||
Reference in New Issue
Block a user