mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 01:09:34 -05:00
Render patches locally (camera space).
This commit is contained in:
@@ -96,6 +96,7 @@ set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalchunkedlodpatch_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalclipmappatch_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalclipmappatch_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/localclipmappatch_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/simple_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/simple_fs.glsl
|
||||
)
|
||||
|
||||
@@ -206,9 +206,9 @@ namespace openspace {
|
||||
ghoul_assert(_programObjectGlobalRendering != nullptr, "Failed to initialize programObject!");
|
||||
|
||||
_programObjectLocalRendering = OsEng.renderEngine().buildRenderProgram(
|
||||
"GlobalClipMapPatch",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/globalclipmappatch_vs.glsl",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/globalclipmappatch_fs.glsl");
|
||||
"LocalClipMapPatch",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/localclipmappatch_vs.glsl",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/localclipmappatch_fs.glsl");
|
||||
ghoul_assert(_programObjectLocalRendering != nullptr, "Failed to initialize programObject!");
|
||||
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
@@ -221,7 +221,12 @@ namespace openspace {
|
||||
const RenderData& data,
|
||||
const Ellipsoid& ellipsoid)
|
||||
{
|
||||
renderPatchGlobally(patchSize, data, ellipsoid);
|
||||
if (max(patchSize.lat, patchSize.lon) > M_PI / 200) {
|
||||
renderPatchGlobally(patchSize, data, ellipsoid);
|
||||
}
|
||||
else {
|
||||
renderPatchLocally(patchSize, data, ellipsoid);
|
||||
}
|
||||
}
|
||||
|
||||
void ClipMapPatchRenderer::renderPatchGlobally(
|
||||
@@ -376,13 +381,13 @@ namespace openspace {
|
||||
_programObjectGlobalRendering->deactivate();
|
||||
}
|
||||
|
||||
void ClipMapPatchRenderer::renderPatchCameraSpace(
|
||||
void ClipMapPatchRenderer::renderPatchLocally(
|
||||
const Geodetic2& patchSize,
|
||||
const RenderData& data,
|
||||
const Ellipsoid& ellipsoid)
|
||||
{
|
||||
// activate shader
|
||||
_programObjectGlobalRendering->activate();
|
||||
_programObjectLocalRendering->activate();
|
||||
using namespace glm;
|
||||
|
||||
mat4 viewTransform = data.camera.combinedViewMatrix();
|
||||
@@ -390,6 +395,8 @@ namespace openspace {
|
||||
// TODO : Model transform should be fetched as a matrix directly.
|
||||
mat4 modelTransform = translate(mat4(1), data.position.vec3());
|
||||
|
||||
mat4 modelViewTransform = viewTransform * modelTransform;
|
||||
|
||||
// Snap patch position
|
||||
int segmentsPerPatch = _grid->segments();
|
||||
Geodetic2 stepSize = Geodetic2(
|
||||
@@ -411,9 +418,27 @@ namespace openspace {
|
||||
|
||||
ivec2 contraction = ivec2(intSnapCoord.y % 2, intSnapCoord.x % 2);
|
||||
|
||||
// Get global positions of the four control points
|
||||
Vec3 patchSw = ellipsoid.geodetic2ToCartesian(newPatch.southWestCorner());
|
||||
Vec3 patchSe = ellipsoid.geodetic2ToCartesian(newPatch.southEastCorner());
|
||||
Vec3 patchNw = ellipsoid.geodetic2ToCartesian(newPatch.northWestCorner());
|
||||
Vec3 patchNe = ellipsoid.geodetic2ToCartesian(newPatch.northEastCorner());
|
||||
|
||||
// Transform all control points to camera space
|
||||
patchSw = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchSw, 1));
|
||||
patchSe = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchSe, 1));
|
||||
patchNw = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchNw, 1));
|
||||
patchNe = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchNe, 1));
|
||||
|
||||
|
||||
// Send control points to shader
|
||||
_programObjectLocalRendering->setUniform("p00", vec3(patchSw));
|
||||
_programObjectLocalRendering->setUniform("p10", vec3(patchSe));
|
||||
_programObjectLocalRendering->setUniform("p01", vec3(patchNw));
|
||||
_programObjectLocalRendering->setUniform("p11", vec3(patchNe));
|
||||
|
||||
vec3 patchNormal = normalize(cross(patchSe - patchSw, patchNw - patchSw));
|
||||
_programObjectLocalRendering->setUniform("patchNormal", patchNormal);
|
||||
|
||||
// For now just pick the first one from height maps
|
||||
auto heightMapProviders = _tileProviderManager->heightMapProviders();
|
||||
@@ -424,34 +449,34 @@ namespace openspace {
|
||||
ghoul::opengl::TextureUnit texUnitHeight00;
|
||||
texUnitHeight00.activate();
|
||||
patchCoverage.textureTransformPairs[0].first->bind(); // tile00
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerHeight00", texUnitHeight00);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerHeight00", texUnitHeight00);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitHeight10;
|
||||
texUnitHeight10.activate();
|
||||
patchCoverage.textureTransformPairs[1].first->bind(); // tile10
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerHeight10", texUnitHeight10);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerHeight10", texUnitHeight10);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitHeight01;
|
||||
texUnitHeight01.activate();
|
||||
patchCoverage.textureTransformPairs[2].first->bind(); // tile01
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerHeight01", texUnitHeight01);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerHeight01", texUnitHeight01);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitHeight11;
|
||||
texUnitHeight11.activate();
|
||||
patchCoverage.textureTransformPairs[3].first->bind(); // tile11
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerHeight11", texUnitHeight11);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerHeight11", texUnitHeight11);
|
||||
|
||||
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileHeight00",
|
||||
patchCoverage.textureTransformPairs[0].second);
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileHeight10",
|
||||
patchCoverage.textureTransformPairs[1].second);
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileHeight01",
|
||||
patchCoverage.textureTransformPairs[2].second);
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileHeight11",
|
||||
patchCoverage.textureTransformPairs[3].second);
|
||||
|
||||
@@ -473,34 +498,34 @@ namespace openspace {
|
||||
ghoul::opengl::TextureUnit texUnitColor00;
|
||||
texUnitColor00.activate();
|
||||
patchCoverageColor.textureTransformPairs[0].first->bind(); // tile00
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerColor00", texUnitColor00);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerColor00", texUnitColor00);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitColor10;
|
||||
texUnitColor10.activate();
|
||||
patchCoverageColor.textureTransformPairs[1].first->bind(); // tile10
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerColor10", texUnitColor10);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerColor10", texUnitColor10);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitColor01;
|
||||
texUnitColor01.activate();
|
||||
patchCoverageColor.textureTransformPairs[2].first->bind(); // tile01
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerColor01", texUnitColor01);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerColor01", texUnitColor01);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnitColor11;
|
||||
texUnitColor11.activate();
|
||||
patchCoverageColor.textureTransformPairs[3].first->bind(); // tile11
|
||||
_programObjectGlobalRendering->setUniform("textureSamplerColor11", texUnitColor11);
|
||||
_programObjectLocalRendering->setUniform("textureSamplerColor11", texUnitColor11);
|
||||
|
||||
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileColor00",
|
||||
patchCoverageColor.textureTransformPairs[0].second);
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileColor10",
|
||||
patchCoverageColor.textureTransformPairs[1].second);
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileColor01",
|
||||
patchCoverageColor.textureTransformPairs[2].second);
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"uvTransformPatchToTileColor11",
|
||||
patchCoverageColor.textureTransformPairs[3].second);
|
||||
|
||||
@@ -508,14 +533,11 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
_programObjectGlobalRendering->setUniform(
|
||||
"modelViewProjectionTransform",
|
||||
data.camera.projectionMatrix() * viewTransform * modelTransform);
|
||||
_programObjectGlobalRendering->setUniform("segmentsPerPatch", segmentsPerPatch);
|
||||
_programObjectGlobalRendering->setUniform("minLatLon", vec2(newPatch.southWestCorner().toLonLatVec2()));
|
||||
_programObjectGlobalRendering->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
|
||||
_programObjectGlobalRendering->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));
|
||||
_programObjectGlobalRendering->setUniform("contraction", contraction);
|
||||
_programObjectLocalRendering->setUniform(
|
||||
"projectionTransform",
|
||||
data.camera.projectionMatrix());
|
||||
_programObjectLocalRendering->setUniform("segmentsPerPatch", segmentsPerPatch);
|
||||
_programObjectLocalRendering->setUniform("contraction", contraction);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
@@ -525,7 +547,7 @@ namespace openspace {
|
||||
_grid->geometry().drawUsingActiveProgram();
|
||||
|
||||
// disable shader
|
||||
_programObjectGlobalRendering->deactivate();
|
||||
_programObjectLocalRendering->deactivate();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace openspace {
|
||||
const Geodetic2& patchSize,
|
||||
const RenderData& data,
|
||||
const Ellipsoid& ellipsoid);
|
||||
void renderPatchCameraSpace(
|
||||
void renderPatchLocally(
|
||||
const Geodetic2& patchSize,
|
||||
const RenderData& data,
|
||||
const Ellipsoid& ellipsoid);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
/*
|
||||
// Heightmap coverage
|
||||
uniform sampler2D textureSamplerHeight00;
|
||||
uniform sampler2D textureSamplerHeight10;
|
||||
uniform sampler2D textureSamplerHeight01;
|
||||
uniform sampler2D textureSamplerHeight11;
|
||||
uniform mat3 uvTransformPatchToTileHeight00;
|
||||
uniform mat3 uvTransformPatchToTileHeight10;
|
||||
uniform mat3 uvTransformPatchToTileHeight01;
|
||||
uniform mat3 uvTransformPatchToTileHeight11;
|
||||
*/
|
||||
|
||||
// Colortexture coverage
|
||||
uniform sampler2D textureSamplerColor00;
|
||||
uniform sampler2D textureSamplerColor10;
|
||||
uniform sampler2D textureSamplerColor01;
|
||||
uniform sampler2D textureSamplerColor11;
|
||||
uniform mat3 uvTransformPatchToTileColor00;
|
||||
uniform mat3 uvTransformPatchToTileColor10;
|
||||
uniform mat3 uvTransformPatchToTileColor01;
|
||||
uniform mat3 uvTransformPatchToTileColor11;
|
||||
|
||||
//uniform int segmentsPerPatch;
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec3 fs_position;
|
||||
in vec2 fs_uv;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = vec4(0);
|
||||
vec4 color00, color10, color01, color11;
|
||||
|
||||
vec2 uv00 = vec2(uvTransformPatchToTileColor00 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
color00 = texture(textureSamplerColor00, uv00);
|
||||
|
||||
vec2 uv10 = vec2(uvTransformPatchToTileColor10 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
color10 += texture(textureSamplerColor10, uv10);
|
||||
|
||||
vec2 uv01 = vec2(uvTransformPatchToTileColor01 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
color01 += texture(textureSamplerColor01, uv01);
|
||||
|
||||
vec2 uv11 = vec2(uvTransformPatchToTileColor11 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
color11 += texture(textureSamplerColor11, uv11);
|
||||
|
||||
frag.color = max(color00, max(color10, max(color01, color11))) * 10;
|
||||
frag.color = vec4(frag.color.r, frag.color.r, frag.color.r, 1);
|
||||
|
||||
frag.depth = vs_position.w;
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 projectionTransform;
|
||||
|
||||
uniform ivec2 contraction; // [-1, 1]
|
||||
|
||||
uniform vec3 p00;
|
||||
uniform vec3 p10;
|
||||
uniform vec3 p01;
|
||||
uniform vec3 p11;
|
||||
uniform vec3 patchNormal;
|
||||
|
||||
uniform int segmentsPerPatch;
|
||||
|
||||
uniform mat3 uvTransformPatchToTileHeight00;
|
||||
uniform mat3 uvTransformPatchToTileHeight10;
|
||||
uniform mat3 uvTransformPatchToTileHeight01;
|
||||
uniform mat3 uvTransformPatchToTileHeight11;
|
||||
|
||||
uniform sampler2D textureSamplerHeight00;
|
||||
uniform sampler2D textureSamplerHeight10;
|
||||
uniform sampler2D textureSamplerHeight01;
|
||||
uniform sampler2D textureSamplerHeight11;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
out vec4 vs_position;
|
||||
out vec3 fs_position;
|
||||
out vec2 fs_uv;
|
||||
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
// Bilinear interpolation
|
||||
vec3 p0 = (1 - uv.x) * p00 + uv.x * p10;
|
||||
vec3 p1 = (1 - uv.x) * p01 + uv.x * p11;
|
||||
vec3 p = (1 - uv.y) * p0 + uv.y * p1;
|
||||
return p;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
fs_uv = in_uv;
|
||||
|
||||
// Contract
|
||||
vec2 scaledContraction = contraction / float(segmentsPerPatch);
|
||||
fs_uv += scaledContraction;
|
||||
fs_uv = clamp(fs_uv, 0, 1);
|
||||
fs_uv -= scaledContraction;
|
||||
|
||||
// Position in cameraspace
|
||||
vec3 p = bilinearInterpolation(fs_uv);
|
||||
|
||||
float sampledHeight00, sampledHeight10, sampledHeight01, sampledHeight11;
|
||||
|
||||
vec2 uv00 = vec2(uvTransformPatchToTileHeight00 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
|
||||
vec2 uv10 = vec2(uvTransformPatchToTileHeight10 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
|
||||
vec2 uv01 = vec2(uvTransformPatchToTileHeight01 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
|
||||
vec2 uv11 = vec2(uvTransformPatchToTileHeight11 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
|
||||
|
||||
float sampledHeight = max(sampledHeight00, max(sampledHeight10, max(sampledHeight01, sampledHeight11)));
|
||||
|
||||
p += patchNormal * sampledHeight * pow(2,15);
|
||||
|
||||
vec4 position = projectionTransform * vec4(p, 1);
|
||||
fs_position = p;
|
||||
|
||||
gl_Position = z_normalization(position);
|
||||
vs_position = gl_Position;
|
||||
}
|
||||
Reference in New Issue
Block a user