small displacements
This commit is contained in:
parent
82f0785cae
commit
7aa5d04e4e
@ -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]
|
- moores_heights[0][2] - 2.0f * moores_heights[1][2] - moores_heights[2][2]
|
||||||
);
|
);
|
||||||
/* fill in missing component, first scalar scales bump */
|
/* 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));
|
vertices[x + y * patch_size].norm = glm::normalize(normal * glm::vec3(2.0f, 1.0f, 2.0f));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,7 @@ void UI::newFrame() {
|
|||||||
ImGui::Text("FPS: %f", info.fps);
|
ImGui::Text("FPS: %f", info.fps);
|
||||||
ImGui::Text("Time: %f", info.time);
|
ImGui::Text("Time: %f", info.time);
|
||||||
ImGui::Checkbox("Fly Camera", &info.flycam);
|
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::SliderFloat("Edge Size", &info.tess_edge_size, 0.0, 40.0);
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@ -18,5 +18,10 @@ layout (set = 0, binding = 0) uniform Matrices {
|
|||||||
layout (set = 0, binding = 1) uniform sampler2D tex;
|
layout (set = 0, binding = 1) uniform sampler2D tex;
|
||||||
|
|
||||||
void main() {
|
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);
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -23,6 +23,7 @@ layout (location = 0) out vec3 _norm;
|
|||||||
layout (location = 1) out vec2 _texCoord;
|
layout (location = 1) out vec2 _texCoord;
|
||||||
layout (location = 2) out vec3 _pos;
|
layout (location = 2) out vec3 _pos;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
/* interpolation of UV coordinates */
|
/* interpolation of UV coordinates */
|
||||||
vec2 uv1 = mix(texCoord[0], texCoord[1], gl_TessCoord.x);
|
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 pos2 = mix(gl_in[3].gl_Position, gl_in[2].gl_Position, gl_TessCoord.x);
|
||||||
|
|
||||||
vec4 fpos = mix(pos1, pos2, gl_TessCoord.y);
|
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;
|
_pos = fpos.xyz;
|
||||||
gl_Position = proj * view * fpos;
|
gl_Position = proj * view * fpos;
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user