Update
BIN
resources/terrain/Bricks076C_diffspec.dds
Normal file
BIN
resources/terrain/Bricks076C_normheight.dds
Normal file
BIN
resources/terrain/Ground23_col.jpg
Normal file
|
After Width: | Height: | Size: 506 KiB |
BIN
resources/terrain/Ground23_normheight.dds
Normal file
BIN
resources/terrain/Ground23_spec.png
Normal file
|
After Width: | Height: | Size: 676 KiB |
BIN
resources/terrain/Ground37_diffspec.dds
Normal file
BIN
resources/terrain/Ground37_normheight.dds
Normal file
1
resources/terrain/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Textures are CC0 from https://cc0textures.com/ adapted for Ogre
|
||||
BIN
resources/terrain/Rock20_diffspec.dds
Normal file
BIN
resources/terrain/Rock20_normheight.dds
Normal file
83
resources/terrain/TerrainSurface.glsl
Normal file
@@ -0,0 +1,83 @@
|
||||
void transformToTS(in vec3 TSnormal, in mat3 normalMatrix, inout vec3 normal)
|
||||
{
|
||||
// derive the tangent space basis
|
||||
// we do this in the pixel shader because we don't have per-vertex normals
|
||||
// because of the LOD, we use a normal map
|
||||
// tangent is always +x or -z in object space depending on alignment
|
||||
#ifdef TERRAIN_ALIGN_Y_Z
|
||||
vec3 tangent = vec3(0, 0, -1);
|
||||
#else
|
||||
vec3 tangent = vec3(1, 0, 0);
|
||||
#endif
|
||||
normal = normalize(normal);
|
||||
tangent = normalize(mul(normalMatrix, tangent));
|
||||
vec3 binormal = cross(tangent, normal);
|
||||
// note, now we need to re-cross to derive tangent again because it wasn't orthonormal
|
||||
tangent = cross(normal, binormal);
|
||||
// derive final matrix
|
||||
mat3 TBN = mtxFromCols(tangent, binormal, normal);
|
||||
|
||||
normal = mul(TBN, TSnormal);
|
||||
}
|
||||
|
||||
void getShadowFactor(in sampler2D lightmap, in vec2 uv, inout float shadowFactor)
|
||||
{
|
||||
float lmShadow = texture2D(lightmap, uv).x;
|
||||
shadowFactor = min(shadowFactor, lmShadow);
|
||||
}
|
||||
|
||||
#define MIN_BLEND_WEIGHT 0.0039 // 1/255
|
||||
|
||||
void blendTerrainLayer(in float blendWeight, in f32vec2 uv0, in float uvMul,
|
||||
#ifdef TERRAIN_PARALLAX_MAPPING
|
||||
in vec3 viewPos, in float scaleBias, in mat3 TBN,
|
||||
#endif
|
||||
#ifdef TERRAIN_NORMAL_MAPPING
|
||||
in sampler2D normtex, inout vec3 normal,
|
||||
#endif
|
||||
in sampler2D difftex, inout vec4 diffuseSpec)
|
||||
{
|
||||
if(blendWeight < MIN_BLEND_WEIGHT)
|
||||
return;
|
||||
|
||||
// generate UV
|
||||
vec2 uv = mod(uv0 * uvMul, 1.0);
|
||||
|
||||
#ifdef TERRAIN_PARALLAX_MAPPING
|
||||
SGX_Generate_Parallax_Texcoord(normtex, uv, viewPos, scaleBias, TBN, uv);
|
||||
#endif
|
||||
|
||||
// sample diffuse texture
|
||||
vec4 diffuseSpecTex = texture2D(difftex, uv);
|
||||
// apply to common
|
||||
diffuseSpec = mix(diffuseSpec, diffuseSpecTex, blendWeight);
|
||||
|
||||
#ifdef TERRAIN_NORMAL_MAPPING
|
||||
vec3 TSnormal;
|
||||
// access TS normal map
|
||||
SGX_FetchNormal(normtex, uv, TSnormal);
|
||||
// Partial Derivative Blending https://blog.selfshadow.com/publications/blending-in-detail/
|
||||
normal = normalize(vec3(mix(normal.xy*TSnormal.z, TSnormal.xy*normal.z, blendWeight), TSnormal.z*normal.z));
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SGX_CalculateTerrainTBN(in vec3 normal, in mat3 normalMatrix, out mat3 TBN)
|
||||
{
|
||||
// derive the tangent space basis
|
||||
// we do this in the pixel shader because we don't have per-vertex normals
|
||||
// because of the LOD, we use a normal map
|
||||
// tangent is always +x or -z in object space depending on alignment
|
||||
#ifdef TERRAIN_ALIGN_Y_Z
|
||||
vec3 tangent = vec3(0, 0, -1);
|
||||
#else
|
||||
vec3 tangent = vec3(1, 0, 0);
|
||||
#endif
|
||||
normal = normalize(normal);
|
||||
tangent = normalize(mul(normalMatrix, tangent));
|
||||
vec3 binormal = cross(tangent, normal);
|
||||
// note, now we need to re-cross to derive tangent again because it wasn't orthonormal
|
||||
tangent = cross(normal, binormal);
|
||||
// derive final matrix
|
||||
TBN = mtxFromCols(tangent, binormal, normal);
|
||||
}
|
||||
36
resources/terrain/TerrainTransforms.glsl
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @param delta: lodDelta, lodThreshold (vertex attribute)
|
||||
* @param lodMorph: morph amount, morph targetLOD (uniform)
|
||||
*/
|
||||
void applyLODMorph(vec2 delta, vec2 lodMorph, inout float height
|
||||
#ifdef TERRAIN_DEBUG
|
||||
, out vec2 lodInfo
|
||||
#endif
|
||||
)
|
||||
{
|
||||
// determine whether to apply the LOD morph to this vertex
|
||||
// we store the deltas against all vertices so we only want to apply
|
||||
// the morph to the ones which would disappear.
|
||||
// If we subtract
|
||||
// the lodThreshold from the targetLOD, and arrange to only morph if the
|
||||
// result is negative (it will only be -1 in fact, since after that
|
||||
// the vertex will never be indexed), we will achieve our aim.
|
||||
// sign(lodThreshold - targetLOD) == -1 is to morph
|
||||
|
||||
// this will either be 1 (morph) or 0 (don't morph)
|
||||
float toMorph = -min(0.0, sign(delta.y - lodMorph.y));
|
||||
height += delta.x * toMorph * lodMorph.x;
|
||||
|
||||
#ifdef TERRAIN_DEBUG
|
||||
// LOD level (-1 since value is target level, we want to display actual)
|
||||
lodInfo.x = (lodMorph.y - 1) / NUM_LODS;
|
||||
// LOD morph
|
||||
lodInfo.y = toMorph * lodMorph.x;
|
||||
#endif
|
||||
}
|
||||
|
||||
void expandVertex(mat4 idxToObjectSpace, float baseUVScale, vec2 idx, float height, out vec4 position, out vec2 uv)
|
||||
{
|
||||
position = mul(idxToObjectSpace, vec4(idx, height, 1));
|
||||
uv = vec2(idx.x * baseUVScale, 1.0 - idx.y * baseUVScale);
|
||||
}
|
||||
BIN
resources/terrain/terr_dirt-grass.jpg
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
resources/terrain/terr_rock-dirt.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
resources/terrain/terr_rock6.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
resources/terrain/terrain.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
BIN
resources/terrain/terrain_detail.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resources/terrain/terrain_texture.jpg
Normal file
|
After Width: | Height: | Size: 70 KiB |