mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 01:09:34 -05:00
Prototyping with four textures for clipmap rendering.
This commit is contained in:
@@ -99,6 +99,12 @@ namespace openspace {
|
||||
return x == other.x && y == other.y && level == other.level;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const GeodeticTileIndex& ti)
|
||||
{
|
||||
os << "{ x = " << ti.x << ", y = " << ti.y << ", level = " << ti.level << " }";
|
||||
return os;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// GEODETICPATCH //
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -99,7 +99,7 @@ struct GeodeticTileIndex {
|
||||
bool operator==(const GeodeticTileIndex& other) const;
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const GeodeticTileIndex& ti);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace openspace {
|
||||
// init Renderer
|
||||
auto outerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<OuterClipMapGrid>(new OuterClipMapGrid(256)));
|
||||
_outerPatchRenderer.reset(outerPatchRenderer);
|
||||
auto innerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<InnerClipMapGrid>(new InnerClipMapGrid(256 )));
|
||||
auto innerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<InnerClipMapGrid>(new InnerClipMapGrid(256)));
|
||||
_innerPatchRenderer.reset(innerPatchRenderer);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace openspace {
|
||||
void ClipMapGlobe::render(const RenderData& data)
|
||||
{
|
||||
// TODO : Choose the max depth and the min depth depending on the camera
|
||||
int maxDepth = 3;
|
||||
int maxDepth = 10;
|
||||
int minDepth = 0;
|
||||
// render patches
|
||||
for (size_t i = minDepth; i < maxDepth; i++)
|
||||
|
||||
@@ -61,13 +61,13 @@ namespace openspace {
|
||||
level = glm::min(level, _depth);
|
||||
|
||||
// Calculate the index in x y where the tile should be positioned
|
||||
Vec2 tileSize = _sizeLevel0.toLonLatVec2() / pow(2, level);
|
||||
Vec2 nw = patch.northWestCorner().toLonLatVec2();
|
||||
Vec2 offset = _offsetLevel0.toLonLatVec2();
|
||||
glm::ivec2 tileIndexXY = (nw - offset) / tileSize;
|
||||
Geodetic2 tileSize = _sizeLevel0 / pow(2, level);
|
||||
Geodetic2 nw = patch.northWestCorner();
|
||||
glm::ivec2 tileIndexXY =
|
||||
(nw.toLonLatVec2() - _offsetLevel0.toLonLatVec2()) / tileSize.toLonLatVec2();
|
||||
|
||||
// Flip y since indices increase from top to bottom
|
||||
//tileIndexXY.y = pow(2, level - 1) - tileIndexXY.y;
|
||||
tileIndexXY.y = pow(2, level) - 1 - tileIndexXY.y;
|
||||
|
||||
// Create the tileindex
|
||||
GeodeticTileIndex tileIndex = { tileIndexXY.x, tileIndexXY.y, level };
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace openspace {
|
||||
//auto texture = _converter.convertToOpenGLTexture(_gdalDataSet, tileIndex, GL_UNSIGNED_BYTE);
|
||||
auto texture = getTileInternal(tileIndex, GL_UNSIGNED_BYTE);
|
||||
texture->uploadTexture();
|
||||
texture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToEdge);
|
||||
texture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
_tileCache.put(hashkey, texture);
|
||||
return texture;
|
||||
|
||||
@@ -146,8 +146,8 @@ namespace openspace {
|
||||
ghoul::opengl::TextureUnit texUnit;
|
||||
texUnit.activate();
|
||||
tile00->bind();
|
||||
_programObject->setUniform("textureSampler", texUnit);
|
||||
_programObject->setUniform("uvTransformPatchToTile", uvTransform);
|
||||
_programObject->setUniform("textureSampler00", texUnit);
|
||||
_programObject->setUniform("uvTransformPatchToTile00", uvTransform);
|
||||
|
||||
Geodetic2 swCorner = newPatch.southWestCorner();
|
||||
_programObject->setUniform("segmentsPerPatch", _grid->xSegments());
|
||||
@@ -176,6 +176,7 @@ namespace openspace {
|
||||
: PatchRenderer()
|
||||
, _grid(grid)
|
||||
, _tileProvider("map_service_configs/TERRAIN.wms", 5000)
|
||||
, _patchCoverageProvider(Geodetic2(M_PI * 2, M_PI * 2), Geodetic2(-M_PI -M_PI/2, -M_PI), 10)
|
||||
{
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
"LatLonSphereMappingProgram",
|
||||
@@ -234,20 +235,49 @@ namespace openspace {
|
||||
|
||||
|
||||
// Get the textures that should be used for rendering
|
||||
GeodeticTileIndex tileIndex = _tileSet.getTileIndex(newPatch);
|
||||
GeodeticPatch tilePatch = _tileSet.getTilePositionAndScale(tileIndex);
|
||||
GeodeticTileIndex tileIndex00 = _patchCoverageProvider.getTileIndex(newPatch);
|
||||
GeodeticTileIndex tileIndex10 = tileIndex00; tileIndex10.x += 1;
|
||||
GeodeticTileIndex tileIndex01 = tileIndex00; tileIndex01.y += 1;
|
||||
GeodeticTileIndex tileIndex11 = tileIndex00; tileIndex11.x += 1; tileIndex11.y += 1;
|
||||
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileProvider.getTile(tileIndex);
|
||||
glm::mat3 uvTransform = _tileSet.getUvTransformationPatchToTile(newPatch, tileIndex);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileProvider.getTile(tileIndex00);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile10 = _tileProvider.getTile(tileIndex10);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile01 = _tileProvider.getTile(tileIndex01);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile11 = _tileProvider.getTile(tileIndex11);
|
||||
|
||||
glm::mat3 uvTransform00 = _patchCoverageProvider.getUvTransformationPatchToTile(newPatch, tileIndex00);
|
||||
glm::mat3 uvTransform10 = _patchCoverageProvider.getUvTransformationPatchToTile(newPatch, tileIndex10);
|
||||
glm::mat3 uvTransform01 = _patchCoverageProvider.getUvTransformationPatchToTile(newPatch, tileIndex01);
|
||||
glm::mat3 uvTransform11 = _patchCoverageProvider.getUvTransformationPatchToTile(newPatch, tileIndex11);
|
||||
|
||||
//std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileSet.getTile(tileIndex);
|
||||
|
||||
// Bind and use the texture
|
||||
ghoul::opengl::TextureUnit texUnit;
|
||||
texUnit.activate();
|
||||
ghoul::opengl::TextureUnit texUnit00;
|
||||
texUnit00.activate();
|
||||
tile00->bind();
|
||||
_programObject->setUniform("textureSampler", texUnit);
|
||||
_programObject->setUniform("uvTransformPatchToTile", mat3(uvTransform));
|
||||
_programObject->setUniform("textureSampler00", texUnit00);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnit10;
|
||||
texUnit10.activate();
|
||||
tile10->bind();
|
||||
_programObject->setUniform("textureSampler10", texUnit10);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnit01;
|
||||
texUnit01.activate();
|
||||
tile01->bind();
|
||||
_programObject->setUniform("textureSampler01", texUnit01);
|
||||
|
||||
ghoul::opengl::TextureUnit texUnit11;
|
||||
texUnit11.activate();
|
||||
tile11->bind();
|
||||
_programObject->setUniform("textureSampler11", texUnit11);
|
||||
|
||||
|
||||
_programObject->setUniform("uvTransformPatchToTile00", mat3(uvTransform00));
|
||||
_programObject->setUniform("uvTransformPatchToTile10", mat3(uvTransform10));
|
||||
_programObject->setUniform("uvTransformPatchToTile01", mat3(uvTransform01));
|
||||
_programObject->setUniform("uvTransformPatchToTile11", mat3(uvTransform11));
|
||||
|
||||
_programObject->setUniform(
|
||||
"modelViewProjectionTransform",
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <modules/globebrowsing/meshes/clipmapgrid.h>
|
||||
#include <modules/globebrowsing/rendering/frustumculler.h>
|
||||
#include <modules/globebrowsing/other/texturetileset.h>
|
||||
#include <modules/globebrowsing/other/patchcoverageprovider.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -113,6 +114,7 @@ namespace openspace {
|
||||
|
||||
private:
|
||||
TileProvider _tileProvider;
|
||||
PatchCoverageProvider _patchCoverageProvider;
|
||||
shared_ptr<ClipMapGrid> _grid;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,11 +31,17 @@ uniform vec2 minLatLon;
|
||||
uniform vec2 lonLatScalingFactor;
|
||||
uniform ivec2 contraction; // [-1, 1]
|
||||
|
||||
uniform mat3 uvTransformPatchToTile;
|
||||
uniform mat3 uvTransformPatchToTile00;
|
||||
uniform mat3 uvTransformPatchToTile10;
|
||||
uniform mat3 uvTransformPatchToTile01;
|
||||
uniform mat3 uvTransformPatchToTile11;
|
||||
|
||||
uniform int segmentsPerPatch;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform sampler2D textureSampler00;
|
||||
uniform sampler2D textureSampler10;
|
||||
uniform sampler2D textureSampler01;
|
||||
uniform sampler2D textureSampler11;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
@@ -107,9 +113,19 @@ void main()
|
||||
|
||||
PositionNormalPair pair = globalInterpolation(fs_uv);
|
||||
|
||||
vec4 textureColor = texture(textureSampler, vec2(uvTransformPatchToTile * vec3(fs_uv.s, fs_uv.t, 1)));
|
||||
|
||||
vec4 textureColor = vec4(0);
|
||||
|
||||
pair.position += pair.normal * textureColor.r * 3e4;
|
||||
vec2 uv00 = vec2(uvTransformPatchToTile00 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
textureColor += texture(textureSampler00, uv00);
|
||||
vec2 uv10 = vec2(uvTransformPatchToTile10 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
textureColor += texture(textureSampler10, uv10);
|
||||
vec2 uv01 = vec2(uvTransformPatchToTile01 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
textureColor += texture(textureSampler01, uv01);
|
||||
vec2 uv11 = vec2(uvTransformPatchToTile11 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
textureColor += texture(textureSampler11, uv11);
|
||||
|
||||
pair.position += pair.normal * textureColor.r * 1e4;
|
||||
|
||||
vec4 position = modelViewProjectionTransform * vec4(pair.position, 1);
|
||||
fs_position = pair.position;
|
||||
|
||||
@@ -35,8 +35,14 @@ uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform mat3 uvTransformPatchToTile;
|
||||
uniform sampler2D textureSampler00;
|
||||
uniform sampler2D textureSampler10;
|
||||
uniform sampler2D textureSampler01;
|
||||
uniform sampler2D textureSampler11;
|
||||
uniform mat3 uvTransformPatchToTile00;
|
||||
uniform mat3 uvTransformPatchToTile10;
|
||||
uniform mat3 uvTransformPatchToTile01;
|
||||
uniform mat3 uvTransformPatchToTile11;
|
||||
|
||||
uniform int segmentsPerPatch;
|
||||
|
||||
@@ -51,8 +57,21 @@ in vec2 fs_uv;
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = texture(textureSampler, vec2(uvTransformPatchToTile * vec3(fs_uv.s, fs_uv.t, 1)));
|
||||
frag.color = vec4(0);
|
||||
|
||||
vec2 uv00 = vec2(uvTransformPatchToTile00 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
frag.color += texture(textureSampler00, uv00);
|
||||
|
||||
vec2 uv10 = vec2(uvTransformPatchToTile10 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
frag.color += texture(textureSampler10, uv10);
|
||||
|
||||
vec2 uv01 = vec2(uvTransformPatchToTile01 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
frag.color += texture(textureSampler01, uv01);
|
||||
|
||||
vec2 uv11 = vec2(uvTransformPatchToTile11 * vec3(fs_uv.s, fs_uv.t, 1));
|
||||
frag.color += texture(textureSampler11, uv11);
|
||||
//frag.color = frag.color * 0.5 + 0.999*texture(textureSampler, fs_uv);
|
||||
//frag.color /= 4;
|
||||
|
||||
vec4 uvColor = vec4(fract(fs_uv * segmentsPerPatch), 0.4,1);
|
||||
frag.color = frag.color.a < 0.1 ? uvColor * 0.5 : frag.color;
|
||||
|
||||
Reference in New Issue
Block a user