diff --git a/Scene/Terrain.cpp b/Scene/Terrain.cpp index ffede70..00c8cef 100644 --- a/Scene/Terrain.cpp +++ b/Scene/Terrain.cpp @@ -73,7 +73,8 @@ Terrain::Terrain(vk::PhysicalDevice phys_dev, vk::Device dev, Texture& tex) : ph - moores_heights[0][2] - 2.0f * moores_heights[1][2] - moores_heights[2][2] ); /* fill in missing component, first scalar scales bump */ - normal.y = 0.25 * glm::sqrt(1.0 -glm::dot(normal, normal)); + normal.y = 0.25 * glm::sqrt(glm::abs(1.0 - normal.x*normal.x - normal.z*normal.z)); + vertices[x + y * patch_size].norm = glm::normalize(normal * glm::vec3(2.0f, 1.0f, 2.0f)); } diff --git a/UI/UI.cpp b/UI/UI.cpp index dc3accc..8a84fb4 100644 --- a/UI/UI.cpp +++ b/UI/UI.cpp @@ -92,7 +92,7 @@ void UI::newFrame() { ImGui::Text("FPS: %f", info.fps); ImGui::Text("Time: %f", info.time); ImGui::Checkbox("Fly Camera", &info.flycam); - ImGui::SliderFloat("Tessellation Factor", &info.tess_factor, 0.0, 20.0); + ImGui::SliderFloat("Tessellation Factor", &info.tess_factor, 0.0, 100.0); ImGui::SliderFloat("Edge Size", &info.tess_edge_size, 0.0, 40.0); ImGui::End(); diff --git a/assets/shaders/terrain.frag b/assets/shaders/terrain.frag index c5bd585..333da3b 100644 --- a/assets/shaders/terrain.frag +++ b/assets/shaders/terrain.frag @@ -18,5 +18,10 @@ layout (set = 0, binding = 0) uniform Matrices { layout (set = 0, binding = 1) uniform sampler2D tex; void main() { - FragColor = vec4(1.0); + vec3 light_pos = normalize(vec3(cos(time), sin(time), 0.0))*10.0; + vec3 L = normalize(light_pos-pos); + float r = length(light_pos-pos); + float t = clamp(dot(L, norm), 0.0, 1.0) * 20.0/(r*r); + + FragColor = vec4(vec3(t * 0.8) + vec3(0.2, 0.0, 0.1), 1.0); } \ No newline at end of file diff --git a/assets/shaders/terrain.frag.spv b/assets/shaders/terrain.frag.spv index 13e9814..ee0651b 100644 Binary files a/assets/shaders/terrain.frag.spv and b/assets/shaders/terrain.frag.spv differ diff --git a/assets/shaders/terrain.tese b/assets/shaders/terrain.tese index 614c8b3..3d4813f 100644 --- a/assets/shaders/terrain.tese +++ b/assets/shaders/terrain.tese @@ -23,6 +23,7 @@ layout (location = 0) out vec3 _norm; layout (location = 1) out vec2 _texCoord; layout (location = 2) out vec3 _pos; + void main() { /* interpolation of UV coordinates */ vec2 uv1 = mix(texCoord[0], texCoord[1], gl_TessCoord.x); @@ -39,7 +40,7 @@ void main() { vec4 pos2 = mix(gl_in[3].gl_Position, gl_in[2].gl_Position, gl_TessCoord.x); vec4 fpos = mix(pos1, pos2, gl_TessCoord.y); - fpos.y += 5.0 * textureLod(heightmap, _texCoord, 0.0).r; + fpos.y += 5.0 * textureLod(heightmap, _texCoord, 0.0).r + cos(fpos.x*fpos.y); _pos = fpos.xyz; gl_Position = proj * view * fpos; diff --git a/assets/shaders/terrain.tese.spv b/assets/shaders/terrain.tese.spv index 2c6ff04..12f4f3c 100644 Binary files a/assets/shaders/terrain.tese.spv and b/assets/shaders/terrain.tese.spv differ