Fixed normal generation (forgot to properly bump scale).
This commit is contained in:
parent
eeb923067f
commit
90d04c2d9f
@ -93,7 +93,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
|
|||||||
|
|
||||||
const auto raster_info = vk::PipelineRasterizationStateCreateInfo {
|
const auto raster_info = vk::PipelineRasterizationStateCreateInfo {
|
||||||
.depthClampEnable = vk::False,
|
.depthClampEnable = vk::False,
|
||||||
.polygonMode = type == Type::eGLTF? vk::PolygonMode::eFill : vk::PolygonMode::eLine,
|
.polygonMode = type == Type::eGLTF? vk::PolygonMode::eFill : vk::PolygonMode::eFill,
|
||||||
.cullMode = vk::CullModeFlagBits::eNone,
|
.cullMode = vk::CullModeFlagBits::eNone,
|
||||||
.frontFace = Type::eGLTF ? vk::FrontFace::eClockwise : vk::FrontFace::eCounterClockwise,
|
.frontFace = Type::eGLTF ? vk::FrontFace::eClockwise : vk::FrontFace::eCounterClockwise,
|
||||||
.depthBiasEnable = vk::False,
|
.depthBiasEnable = vk::False,
|
||||||
|
|||||||
@ -230,7 +230,7 @@ Renderer::Renderer(Window& win) : win(win) {
|
|||||||
{ dev, "assets/shaders/terrain.vert.spv", vk::ShaderStageFlagBits::eVertex },
|
{ dev, "assets/shaders/terrain.vert.spv", vk::ShaderStageFlagBits::eVertex },
|
||||||
{ dev, "assets/shaders/terrain.tesc.spv", vk::ShaderStageFlagBits::eTessellationControl },
|
{ dev, "assets/shaders/terrain.tesc.spv", vk::ShaderStageFlagBits::eTessellationControl },
|
||||||
{ dev, "assets/shaders/terrain.tese.spv", vk::ShaderStageFlagBits::eTessellationEvaluation },
|
{ dev, "assets/shaders/terrain.tese.spv", vk::ShaderStageFlagBits::eTessellationEvaluation },
|
||||||
{ dev, "assets/shaders/terrain.frag.spv", vk::ShaderStageFlagBits::eFragment },
|
{ dev, "assets/shaders/gooch.frag.spv", vk::ShaderStageFlagBits::eFragment },
|
||||||
};
|
};
|
||||||
|
|
||||||
terrain_pipeline = std::make_unique<GraphicsPipeline>(dev, terrain_shaders, swapchain->extent, *render_pass, bindings, *terrain->vertex_buffer, GraphicsPipeline::eTERRAIN);
|
terrain_pipeline = std::make_unique<GraphicsPipeline>(dev, terrain_shaders, swapchain->extent, *render_pass, bindings, *terrain->vertex_buffer, GraphicsPipeline::eTERRAIN);
|
||||||
|
|||||||
@ -73,7 +73,7 @@ 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(glm::abs(1.0 - normal.x*normal.x - normal.z*normal.z));
|
normal.y = 15.0 * 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, 100.0);
|
ImGui::SliderFloat("Tessellation Factor", &info.tess_factor, 0.1, 10.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();
|
||||||
|
|||||||
@ -6,9 +6,14 @@ layout (location = 2) in vec3 pos;
|
|||||||
layout (location = 0) out vec4 FragColor;
|
layout (location = 0) out vec4 FragColor;
|
||||||
|
|
||||||
layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
mat4 mvp;
|
mat4 view;
|
||||||
|
mat4 proj;
|
||||||
float time;
|
float time;
|
||||||
vec3 cam_pos;
|
vec3 cam_pos;
|
||||||
|
vec4 frustum[6];
|
||||||
|
vec2 viewport;
|
||||||
|
float tess_factor;
|
||||||
|
float tess_edge_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (set = 0, binding = 1) uniform sampler2D tex;
|
layout (set = 0, binding = 1) uniform sampler2D tex;
|
||||||
|
|||||||
Binary file not shown.
@ -16,13 +16,19 @@ layout (set = 0, binding = 0) uniform Matrices {
|
|||||||
float tess_edge_size;
|
float tess_edge_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (set = 0, binding = 1) uniform sampler2D tex;
|
layout (set = 0, binding = 1) uniform sampler2D heightmap;
|
||||||
|
|
||||||
|
float height(vec2 uv) {
|
||||||
|
return 15.0 * texture(heightmap, uv).r;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
vec3 N = norm;
|
||||||
|
|
||||||
vec3 light_pos = normalize(vec3(cos(time), sin(time), 0.0))*10.0;
|
vec3 light_pos = normalize(vec3(cos(time), sin(time), 0.0))*10.0;
|
||||||
vec3 L = normalize(light_pos-pos);
|
vec3 L = normalize(light_pos-pos);
|
||||||
float r = length(light_pos-pos);
|
float r = length(light_pos-pos);
|
||||||
float t = clamp(dot(L, norm), 0.0, 1.0) * 20.0/(r*r);
|
float t = clamp(dot(L, N), 0.0, 1.0) * 20.0/(r*r);
|
||||||
|
|
||||||
FragColor = vec4(1.0);
|
FragColor = vec4(1.0);
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user