mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-07 20:09:58 -05:00
Rendering using many layers.
This commit is contained in:
@@ -110,25 +110,9 @@ namespace openspace {
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
_shaderName,
|
||||
_vsPath,
|
||||
_fsPath);
|
||||
|
||||
_fsPath,
|
||||
shaderDictionary);
|
||||
|
||||
// TODO : THIS CAN'T BE DONE SINCE SHADER PROGRAM NEEDS TO RESOLVE FRAGMENTS
|
||||
// FIX. HOW CAN THE RENDERING MODE BE ABSTRACTED AWAY WHEN BUILDING USING
|
||||
// DICTIONARIES?
|
||||
|
||||
/*
|
||||
try {
|
||||
_programObject = ProgramObject::Build(
|
||||
_shaderName,
|
||||
_vsPath,
|
||||
_fsPath,
|
||||
shaderDictionary);
|
||||
}
|
||||
catch (ghoul::RuntimeError& error) {
|
||||
LERROR(error.message);
|
||||
}
|
||||
*/
|
||||
ghoul_assert(_programObject != nullptr, "Failed to initialize programObject!");
|
||||
using IgnoreError = ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
@@ -162,26 +162,31 @@ namespace openspace {
|
||||
// Activate the shader program
|
||||
programObject->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitHeight;
|
||||
ghoul::opengl::TextureUnit texUnitColor;
|
||||
std::vector<ghoul::opengl::TextureUnit> texUnitHeight;
|
||||
std::vector<ghoul::opengl::TextureUnit> texUnitColor;
|
||||
|
||||
texUnitHeight.resize(numHeightMapProviders);
|
||||
texUnitColor.resize(numColorTextureProviders);
|
||||
|
||||
|
||||
// Go through all the height map providers
|
||||
int i = 0;
|
||||
for (auto it = heightMapProviders.begin(); it != heightMapProviders.end(); it++)
|
||||
{
|
||||
texUnitHeight.push_back(ghoul::opengl::TextureUnit());
|
||||
auto tileProvider = it->second;
|
||||
// Get the texture that should be used for rendering
|
||||
Tile tile = tileProvider->getMostHiResTile(chunk.index());
|
||||
TileDepthTransform depthTransform = tileProvider->depthTransform();
|
||||
|
||||
// The texture needs a unit to sample from
|
||||
texUnitHeight.activate();
|
||||
texUnitHeight[i].activate();
|
||||
int hej = 0;
|
||||
tile.texture->bind();
|
||||
|
||||
std::string indexedTileKey = "heightTiles[" + std::to_string(i) + "]";
|
||||
// Send uniforms for the tile to the shader
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight);
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight[i]);
|
||||
|
||||
programObject->setUniform(
|
||||
indexedTileKey + ".uvTransform.uvScale",
|
||||
@@ -209,12 +214,12 @@ namespace openspace {
|
||||
Tile tile = tileProvider->getMostHiResTile(chunk.index());
|
||||
|
||||
// The texture needs a unit to sample from
|
||||
texUnitColor.activate();
|
||||
texUnitColor[i].activate();
|
||||
tile.texture->bind();
|
||||
|
||||
std::string indexedTileKey = "colorTiles[" + std::to_string(i) + "]";
|
||||
// Send uniforms for the tile to the shader
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor);
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor[i]);
|
||||
|
||||
programObject->setUniform(
|
||||
indexedTileKey + ".uvTransform.uvScale",
|
||||
@@ -355,25 +360,31 @@ namespace openspace {
|
||||
// Activate the shader program
|
||||
programObject->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitHeight;
|
||||
ghoul::opengl::TextureUnit texUnitColor;
|
||||
|
||||
std::vector<ghoul::opengl::TextureUnit> texUnitHeight;
|
||||
std::vector<ghoul::opengl::TextureUnit> texUnitColor;
|
||||
|
||||
texUnitHeight.resize(numHeightMapProviders);
|
||||
texUnitColor.resize(numColorTextureProviders);
|
||||
|
||||
|
||||
// Go through all the height map providers
|
||||
int i = 0;
|
||||
for (auto it = heightMapProviders.begin(); it != heightMapProviders.end(); it++)
|
||||
{
|
||||
auto tileProvider = it->second;
|
||||
|
||||
// Get the texture that should be used for rendering
|
||||
Tile tile = tileProvider->getMostHiResTile(chunk.index());
|
||||
TileDepthTransform depthTransform = tileProvider->depthTransform();
|
||||
|
||||
// The texture needs a unit to sample from
|
||||
texUnitHeight.activate();
|
||||
texUnitHeight[i].activate();
|
||||
tile.texture->bind();
|
||||
|
||||
std::string indexedTileKey = "heightTiles[" + std::to_string(i) + "]";
|
||||
// Send uniforms for the tile to the shader
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight);
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight[i]);
|
||||
|
||||
programObject->setUniform(
|
||||
indexedTileKey + ".uvTransform.uvScale",
|
||||
@@ -397,16 +408,17 @@ namespace openspace {
|
||||
for (auto it = colorTextureProviders.begin(); it != colorTextureProviders.end(); it++)
|
||||
{
|
||||
auto tileProvider = it->second;
|
||||
|
||||
// Get the texture that should be used for rendering
|
||||
Tile tile = tileProvider->getMostHiResTile(chunk.index());
|
||||
|
||||
// The texture needs a unit to sample from
|
||||
texUnitColor.activate();
|
||||
texUnitColor[i].activate();
|
||||
tile.texture->bind();
|
||||
|
||||
std::string indexedTileKey = "colorTiles[" + std::to_string(i) + "]";
|
||||
// Send uniforms for the tile to the shader
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor);
|
||||
programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor[i]);
|
||||
|
||||
programObject->setUniform(
|
||||
indexedTileKey + ".uvTransform.uvScale",
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 BLENDING_HGLSL
|
||||
#define BLENDING_HGLSL
|
||||
|
||||
vec4 blendOver(vec4 oldColor, vec4 newColor)
|
||||
{
|
||||
vec4 toReturn;
|
||||
toReturn.rgb =
|
||||
(newColor.rgb * newColor.a + oldColor.rgb * oldColor.a * (1 - newColor.a)) /
|
||||
(newColor.a + oldColor.a * (1 - newColor.a));
|
||||
toReturn.a = newColor.a + oldColor.a * (1 - newColor.a);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
vec4 blendMultiply(vec4 oldColor, vec4 newColor)
|
||||
{
|
||||
return oldColor * newColor;
|
||||
}
|
||||
|
||||
vec4 blendAdd(vec4 oldColor, vec4 newColor)
|
||||
{
|
||||
return oldColor + newColor;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -23,38 +23,30 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/blending.hglsl>
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
#define NUMLAYERS_COLORTEXTURE 1
|
||||
#define NUMLAYERS_HEIGHTMAP 1
|
||||
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
|
||||
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
|
||||
|
||||
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
|
||||
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
|
||||
vec4 blendOver(vec4 oldColor, vec4 newColor)
|
||||
{
|
||||
vec4 toReturn;
|
||||
toReturn.rgb =
|
||||
(newColor.rgb * newColor.a + oldColor.rgb * oldColor.a * (1 - newColor.a)) /
|
||||
(newColor.a + oldColor.a * (1 - newColor.a));
|
||||
toReturn.a = newColor.a + oldColor.a * (1 - newColor.a);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
//for (int i = 0; i < NUMLAYERS_COLORTEXTURE; ++i)
|
||||
//{
|
||||
vec2 samplePos =
|
||||
colorTiles[0].uvTransform.uvScale * fs_uv +
|
||||
colorTiles[0].uvTransform.uvOffset;
|
||||
vec4 colorSample = texture(colorTiles[0].textureSampler, samplePos);
|
||||
frag.color = blendOver(frag.color, colorSample);
|
||||
//}
|
||||
vec2 samplePos[NUMLAYERS_COLORTEXTURE];
|
||||
vec4 colorSample[NUMLAYERS_COLORTEXTURE];
|
||||
#for i in 0..#{numLayersColor}
|
||||
samplePos[#{i}] =
|
||||
colorTiles[#{i}].uvTransform.uvScale * fs_uv +
|
||||
colorTiles[#{i}].uvTransform.uvOffset;
|
||||
colorSample[#{i}] = texture(colorTiles[#{i}].textureSampler, samplePos[#{i}]);
|
||||
frag.color = blendAdd(frag.color, colorSample[#{i}]);
|
||||
#endfor
|
||||
|
||||
//frag.color.rgb *= 10;
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
|
||||
#define NUMLAYERS_COLORTEXTURE 1
|
||||
#define NUMLAYERS_HEIGHTMAP 1
|
||||
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
|
||||
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
|
||||
|
||||
uniform mat4 modelViewProjectionTransform;
|
||||
uniform vec3 radiiSquared;
|
||||
@@ -59,17 +59,20 @@ void main()
|
||||
float height = 0;
|
||||
//for (int i = 0; i < NUMLAYERS_HEIGHTMAP; ++i)
|
||||
//{
|
||||
vec2 samplePos =
|
||||
heightTiles[0].uvTransform.uvScale * in_uv +
|
||||
heightTiles[0].uvTransform.uvOffset;
|
||||
float sampledValue[NUMLAYERS_HEIGHTMAP];
|
||||
vec2 samplePos[NUMLAYERS_HEIGHTMAP];
|
||||
#for i in 0..#{numLayersHeight}
|
||||
samplePos[#{i}] =
|
||||
heightTiles[#{i}].uvTransform.uvScale * in_uv +
|
||||
heightTiles[#{i}].uvTransform.uvOffset;
|
||||
|
||||
float sampledValue = texture(heightTiles[0].textureSampler, samplePos).r;
|
||||
sampledValue[#{i}] = texture(heightTiles[#{i}].textureSampler, samplePos[#{i}]).r;
|
||||
|
||||
// TODO : Some kind of blending here. Now it just writes over
|
||||
height = (sampledValue *
|
||||
heightTiles[0].depthTransform.depthScale +
|
||||
heightTiles[0].depthTransform.depthOffset);
|
||||
//}
|
||||
height = (sampledValue[#{i}] *
|
||||
heightTiles[#{i}].depthTransform.depthScale +
|
||||
heightTiles[#{i}].depthTransform.depthOffset);
|
||||
#endfor
|
||||
|
||||
// Add the height in the direction of the normal
|
||||
pair.position += pair.normal * height;
|
||||
|
||||
@@ -23,38 +23,30 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/blending.hglsl>
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
#define NUMLAYERS_COLORTEXTURE 1
|
||||
#define NUMLAYERS_HEIGHTMAP 1
|
||||
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
|
||||
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
|
||||
|
||||
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
|
||||
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
|
||||
vec4 blendOver(vec4 oldColor, vec4 newColor)
|
||||
{
|
||||
vec4 toReturn;
|
||||
toReturn.rgb =
|
||||
(newColor.rgb * newColor.a + oldColor.rgb * oldColor.a * (1 - newColor.a)) /
|
||||
(newColor.a + oldColor.a * (1 - newColor.a));
|
||||
toReturn.a = newColor.a + oldColor.a * (1 - newColor.a);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
//for (int i = 0; i < NUMLAYERS_COLORTEXTURE; ++i)
|
||||
//{
|
||||
vec2 samplePos =
|
||||
colorTiles[0].uvTransform.uvScale * fs_uv +
|
||||
colorTiles[0].uvTransform.uvOffset;
|
||||
vec4 colorSample = texture(colorTiles[0].textureSampler, samplePos);
|
||||
frag.color = blendOver(frag.color, colorSample);
|
||||
//}
|
||||
vec2 samplePos[NUMLAYERS_COLORTEXTURE];
|
||||
vec4 colorSample[NUMLAYERS_COLORTEXTURE];
|
||||
#for i in 0..#{numLayersColor}
|
||||
samplePos[#{i}] =
|
||||
colorTiles[#{i}].uvTransform.uvScale * fs_uv +
|
||||
colorTiles[#{i}].uvTransform.uvOffset;
|
||||
colorSample[#{i}] = texture(colorTiles[#{i}].textureSampler, samplePos[#{i}]);
|
||||
frag.color = blendOver(frag.color, colorSample[#{i}]);
|
||||
#endfor
|
||||
|
||||
//vec2 samplePos =
|
||||
// colorTile.uvTransform.uvScale * fs_uv +
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
|
||||
|
||||
#define NUMLAYERS_COLORTEXTURE 1
|
||||
#define NUMLAYERS_HEIGHTMAP 1
|
||||
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
|
||||
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
|
||||
|
||||
uniform mat4 projectionTransform;
|
||||
|
||||
@@ -61,19 +61,21 @@ void main()
|
||||
vec3 p = bilinearInterpolation(in_uv);
|
||||
|
||||
float height = 0;
|
||||
//for (int i = 0; i < NUMLAYERS_HEIGHTMAP; ++i)
|
||||
//{
|
||||
vec2 samplePos =
|
||||
heightTiles[0].uvTransform.uvScale * in_uv +
|
||||
heightTiles[0].uvTransform.uvOffset;
|
||||
|
||||
vec2 samplePos[NUMLAYERS_HEIGHTMAP];
|
||||
float sampledValue[NUMLAYERS_HEIGHTMAP];
|
||||
#for i in 0..#{numLayersHeight}
|
||||
samplePos[#{i}] =
|
||||
heightTiles[#{i}].uvTransform.uvScale * in_uv +
|
||||
heightTiles[#{i}].uvTransform.uvOffset;
|
||||
|
||||
float sampledValue = texture(heightTiles[0].textureSampler, samplePos).r;
|
||||
sampledValue[#{i}] = texture(heightTiles[#{i}].textureSampler, samplePos[#{i}]).r;
|
||||
|
||||
// TODO : Some kind of blending here. Now it just writes over
|
||||
height = (sampledValue *
|
||||
heightTiles[0].depthTransform.depthScale +
|
||||
heightTiles[0].depthTransform.depthOffset);
|
||||
//}
|
||||
height = (sampledValue[#{i}] *
|
||||
heightTiles[#{i}].depthTransform.depthScale +
|
||||
heightTiles[#{i}].depthTransform.depthOffset);
|
||||
#endfor
|
||||
|
||||
// Translate the point along normal
|
||||
p += patchNormalCameraSpace * height;
|
||||
|
||||
Reference in New Issue
Block a user