Change sampling of textures from array to be fixed.

This commit is contained in:
Kalle Bladin
2016-06-02 17:42:58 -04:00
parent 96c4f0e1c9
commit c891cc8d85
7 changed files with 64 additions and 69 deletions

View File

@@ -39,7 +39,7 @@ namespace openspace {
bool LayeredTextureInfo::operator==(const LayeredTextureInfo& other) const
{
return numLayers == other.numLayers && keyNumLayers == other.keyNumLayers;
return lastLayerIndex == other.lastLayerIndex && keyLastLayerIndex == other.keyLastLayerIndex;
}
bool LayeredTexturePreprocessingData::operator==(
@@ -104,7 +104,7 @@ namespace openspace {
for (size_t i = 0; i < textureTypes.size(); i++)
{
shaderDictionary.setValue(
textureTypes[i].keyNumLayers, textureTypes[i].numLayers);
textureTypes[i].keyLastLayerIndex, textureTypes[i].lastLayerIndex);
}
// Remove old program

View File

@@ -39,8 +39,8 @@ namespace openspace {
struct LayeredTextureInfo
{
std::string keyNumLayers;
int numLayers;
std::string keyLastLayerIndex;
int lastLayerIndex;
bool operator==(const LayeredTextureInfo& other) const;
};

View File

@@ -128,10 +128,10 @@ namespace openspace {
// Create information for the shader provider
LayeredTextureInfo layeredTextureInfoHeight;
LayeredTextureInfo layeredTextureInfoColor;
layeredTextureInfoHeight.keyNumLayers = "numLayersHeight";
layeredTextureInfoHeight.numLayers = numHeightMapProviders;
layeredTextureInfoColor.keyNumLayers = "numLayersColor";
layeredTextureInfoColor.numLayers = numColorTextureProviders;
layeredTextureInfoHeight.keyLastLayerIndex = "lastLayerIndexHeight";
layeredTextureInfoHeight.lastLayerIndex = numHeightMapProviders - 1;
layeredTextureInfoColor.keyLastLayerIndex = "lastLayerIndexColor";
layeredTextureInfoColor.lastLayerIndex = numColorTextureProviders - 1;
LayeredTexturePreprocessingData layeredTexturePreprocessingData;
layeredTexturePreprocessingData.layeredTextureInfo.push_back(
@@ -387,10 +387,10 @@ namespace openspace {
// Create information for the shader provider
LayeredTextureInfo layeredTextureInfoHeight;
LayeredTextureInfo layeredTextureInfoColor;
layeredTextureInfoHeight.keyNumLayers = "numLayersHeight";
layeredTextureInfoHeight.numLayers = numHeightMapProviders;
layeredTextureInfoColor.keyNumLayers = "numLayersColor";
layeredTextureInfoColor.numLayers = numColorTextureProviders;
layeredTextureInfoHeight.keyLastLayerIndex = "lastLayerIndexHeight";
layeredTextureInfoHeight.lastLayerIndex = numHeightMapProviders - 1;
layeredTextureInfoColor.keyLastLayerIndex = "lastLayerIndexColor";
layeredTextureInfoColor.lastLayerIndex = numColorTextureProviders - 1;
LayeredTexturePreprocessingData layeredTexturePreprocessingData;
layeredTexturePreprocessingData.layeredTextureInfo.push_back(

View File

@@ -27,8 +27,8 @@
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE];
@@ -47,23 +47,22 @@ Fragment getFragment() {
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
#for j in 1..#{numLayersColor}
#for i in 0..#{lastLayerIndexColor}
{
int i = #{j} - 1;
vec2 samplePos =
colorTiles[i].uvTransform.uvScale * fs_uv +
colorTiles[i].uvTransform.uvOffset;
colorTiles[#{i}].uvTransform.uvScale * fs_uv +
colorTiles[#{i}].uvTransform.uvOffset;
vec2 samplePosParent1 =
colorTilesParent1[i].uvTransform.uvScale * fs_uv +
colorTilesParent1[i].uvTransform.uvOffset;
colorTilesParent1[#{i}].uvTransform.uvScale * fs_uv +
colorTilesParent1[#{i}].uvTransform.uvOffset;
vec2 samplePosParent2 =
colorTilesParent2[i].uvTransform.uvScale * fs_uv +
colorTilesParent2[i].uvTransform.uvOffset;
colorTilesParent2[#{i}].uvTransform.uvScale * fs_uv +
colorTilesParent2[#{i}].uvTransform.uvOffset;
vec4 colorSample =
w1 * texture(colorTiles[i].textureSampler, samplePos) +
w2 * texture(colorTilesParent1[i].textureSampler, samplePosParent1) +
w3 * texture(colorTilesParent2[i].textureSampler, samplePosParent2);
w1 * texture(colorTiles[#{i}].textureSampler, samplePos) +
w2 * texture(colorTilesParent1[#{i}].textureSampler, samplePosParent1) +
w3 * texture(colorTilesParent2[#{i}].textureSampler, samplePosParent2);
frag.color = blendOver(frag.color, colorSample);
}
#endfor

View File

@@ -28,8 +28,8 @@
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1
uniform mat4 modelViewProjectionTransform;
uniform vec3 radiiSquared;
@@ -81,28 +81,27 @@ void main()
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
#for j in 1..#{numLayersHeight}
#for i in 0..#{lastLayerIndexHeight}
{
int i = #{j} - 1;
vec2 samplePos =
heightTiles[i].uvTransform.uvScale * in_uv +
heightTiles[i].uvTransform.uvOffset;
heightTiles[#{i}].uvTransform.uvScale * in_uv +
heightTiles[#{i}].uvTransform.uvOffset;
vec2 samplePosParent1 =
heightTilesParent1[i].uvTransform.uvScale * in_uv +
heightTilesParent1[i].uvTransform.uvOffset;
heightTilesParent1[#{i}].uvTransform.uvScale * in_uv +
heightTilesParent1[#{i}].uvTransform.uvOffset;
vec2 samplePosParent2 =
heightTilesParent2[i].uvTransform.uvScale * in_uv +
heightTilesParent2[i].uvTransform.uvOffset;
heightTilesParent2[#{i}].uvTransform.uvScale * in_uv +
heightTilesParent2[#{i}].uvTransform.uvOffset;
float sampledValue =
w1 * texture(heightTiles[i].textureSampler, samplePos).r +
w2 * texture(heightTilesParent1[i].textureSampler, samplePosParent1).r +
w3 * texture(heightTilesParent2[i].textureSampler, samplePosParent2).r;
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);
heightTiles[#{i}].depthTransform.depthScale +
heightTiles[#{i}].depthTransform.depthOffset);
// Skirts
int vertexIDx = gl_VertexID % (xSegments + 3);

View File

@@ -27,8 +27,8 @@
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE];
@@ -49,24 +49,22 @@ Fragment getFragment() {
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
#for j in 1..#{numLayersColor}
#for i in 0..#{lastLayerIndexColor}
{
int i = #{j} - 1;
vec2 samplePos =
colorTiles[i].uvTransform.uvScale * fs_uv +
colorTiles[i].uvTransform.uvOffset;
colorTiles[#{i}].uvTransform.uvScale * fs_uv +
colorTiles[#{i}].uvTransform.uvOffset;
vec2 samplePosParent1 =
colorTilesParent1[i].uvTransform.uvScale * fs_uv +
colorTilesParent1[i].uvTransform.uvOffset;
colorTilesParent1[#{i}].uvTransform.uvScale * fs_uv +
colorTilesParent1[#{i}].uvTransform.uvOffset;
vec2 samplePosParent2 =
colorTilesParent2[i].uvTransform.uvScale * fs_uv +
colorTilesParent2[i].uvTransform.uvOffset;
colorTilesParent2[#{i}].uvTransform.uvScale * fs_uv +
colorTilesParent2[#{i}].uvTransform.uvOffset;
vec4 colorSample =
w1 * texture(colorTiles[i].textureSampler, samplePos) +
w2 * texture(colorTilesParent1[i].textureSampler, samplePosParent1) +
w3 * texture(colorTilesParent2[i].textureSampler, samplePosParent2);
w1 * texture(colorTiles[#{i}].textureSampler, samplePos) +
w2 * texture(colorTilesParent1[#{i}].textureSampler, samplePosParent1) +
w3 * texture(colorTilesParent2[#{i}].textureSampler, samplePosParent2);
frag.color = blendOver(frag.color, colorSample);
}
#endfor

View File

@@ -28,8 +28,8 @@
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1
uniform mat4 projectionTransform;
@@ -84,28 +84,27 @@ void main()
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
#for j in 1..#{numLayersHeight}
#for i in 0..#{lastLayerIndexHeight}
{
int i = #{j} - 1;
vec2 samplePos =
heightTiles[i].uvTransform.uvScale * in_uv +
heightTiles[i].uvTransform.uvOffset;
heightTiles[#{i}].uvTransform.uvScale * in_uv +
heightTiles[#{i}].uvTransform.uvOffset;
vec2 samplePosParent1 =
heightTilesParent1[i].uvTransform.uvScale * in_uv +
heightTilesParent1[i].uvTransform.uvOffset;
heightTilesParent1[#{i}].uvTransform.uvScale * in_uv +
heightTilesParent1[#{i}].uvTransform.uvOffset;
vec2 samplePosParent2 =
heightTilesParent2[i].uvTransform.uvScale * in_uv +
heightTilesParent2[i].uvTransform.uvOffset;
heightTilesParent2[#{i}].uvTransform.uvScale * in_uv +
heightTilesParent2[#{i}].uvTransform.uvOffset;
float sampledValue =
w1 * texture(heightTiles[i].textureSampler, samplePos).r +
w2 * texture(heightTilesParent1[i].textureSampler, samplePosParent1).r +
w3 * texture(heightTilesParent2[i].textureSampler, samplePosParent2).r;
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);
heightTiles[#{i}].depthTransform.depthScale +
heightTiles[#{i}].depthTransform.depthOffset);
// Skirts
int vertexIDx = gl_VertexID % (xSegments + 3);