Added resources for dynamic terrain tessellation example
This commit is contained in:
parent
0f66037da0
commit
555a1e8f3d
5 changed files with 15 additions and 12 deletions
|
|
@ -16,22 +16,24 @@ layout (location = 0) out vec4 outFragColor;
|
||||||
vec4 sampleTerrainLayer()
|
vec4 sampleTerrainLayer()
|
||||||
{
|
{
|
||||||
// Define some layer ranges for sampling depending on terrain height
|
// Define some layer ranges for sampling depending on terrain height
|
||||||
vec2 layers[4];
|
vec2 layers[6];
|
||||||
layers[0] = vec2(0.0, 5.0);
|
layers[0] = vec2(-10.0, 10.0);
|
||||||
layers[1] = vec2(5.0, 50.0);
|
layers[1] = vec2(5.0, 35.0);
|
||||||
layers[2] = vec2(50.0, 120.0);
|
layers[2] = vec2(30.0, 70.0);
|
||||||
layers[3] = vec2(120.0, 255.0);
|
layers[3] = vec2(60.0, 95.0);
|
||||||
|
layers[4] = vec2(85.0, 140.0);
|
||||||
|
layers[5] = vec2(140.0, 190.0);
|
||||||
|
|
||||||
vec3 color = vec3(0.0);
|
vec3 color = vec3(0.0);
|
||||||
|
|
||||||
// Get height from displacement map
|
// Get height from displacement map
|
||||||
float height = textureLod(displacementMap, inUV, 0.0).r * 255.0;
|
float height = textureLod(displacementMap, inUV, 0.0).r * 255.0;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
float range = layers[i].y - layers[i].x;
|
float range = layers[i].y - layers[i].x;
|
||||||
float weight = (range - abs(height - layers[i].y)) / range;
|
float weight = (range - abs(height - layers[i].y)) / range;
|
||||||
weight = max(0.05, weight);
|
weight = max(0.0, weight);
|
||||||
color += weight * texture(terrainLayers, vec3(inUV * 16.0, i)).rgb;
|
color += weight * texture(terrainLayers, vec3(inUV * 16.0, i)).rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
data/textures/terrain_heightmap_r8.ktx
Normal file
BIN
data/textures/terrain_heightmap_r8.ktx
Normal file
Binary file not shown.
BIN
data/textures/terrain_texturearray_bc3.ktx
Normal file
BIN
data/textures/terrain_texturearray_bc3.ktx
Normal file
Binary file not shown.
|
|
@ -66,7 +66,7 @@ public:
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 modelview;
|
glm::mat4 modelview;
|
||||||
glm::vec4 lightPos = glm::vec4(0.0f, -2.0f, 0.0f, 0.0f);
|
glm::vec4 lightPos = glm::vec4(0.0f, -2.0f, 0.0f, 0.0f);
|
||||||
float displacementFactor = 16.0f;
|
float displacementFactor = 16.0f * 2.0f;
|
||||||
float tessellationFactor = 0.75f;
|
float tessellationFactor = 0.75f;
|
||||||
glm::vec2 viewportDim;
|
glm::vec2 viewportDim;
|
||||||
// Desired size of tessellated quad patch edge
|
// Desired size of tessellated quad patch edge
|
||||||
|
|
@ -146,9 +146,10 @@ public:
|
||||||
void loadTextures()
|
void loadTextures()
|
||||||
{
|
{
|
||||||
textureLoader->loadTexture(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.skySphere);
|
textureLoader->loadTexture(getAssetPath() + "textures/skysphere_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.skySphere);
|
||||||
textureLoader->loadTexture(getAssetPath() + "textures/terrain_desert_heightmap.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.heightMap);
|
// Height data is stored in a one-channel texture
|
||||||
|
textureLoader->loadTexture(getAssetPath() + "textures/terrain_heightmap_r8.ktx", VK_FORMAT_R8_UNORM, &textures.heightMap);
|
||||||
textureLoader->loadTextureArray(getAssetPath() + "textures/terrain_array_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.terrainArray);
|
// Terrain textures are stored in a texture array with layers corresponding to terrain height
|
||||||
|
textureLoader->loadTextureArray(getAssetPath() + "textures/terrain_texturearray_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.terrainArray);
|
||||||
|
|
||||||
VkSamplerCreateInfo samplerInfo = vkTools::initializers::samplerCreateInfo();
|
VkSamplerCreateInfo samplerInfo = vkTools::initializers::samplerCreateInfo();
|
||||||
|
|
||||||
|
|
@ -270,7 +271,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PATCH_SIZE 64
|
#define PATCH_SIZE 64
|
||||||
#define UV_SCALE 2.0f
|
#define UV_SCALE 1.0f
|
||||||
|
|
||||||
Vertex *vertices = new Vertex[PATCH_SIZE * PATCH_SIZE * 4];
|
Vertex *vertices = new Vertex[PATCH_SIZE * PATCH_SIZE * 4];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue