Fixed normal generation (for real this time).
Issue was in sampling texture on the CPU side.
This commit is contained in:
parent
90d04c2d9f
commit
dfd0c57c59
@ -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/gooch.frag.spv", vk::ShaderStageFlagBits::eFragment },
|
{ dev, "assets/shaders/terrain.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);
|
||||||
|
|||||||
@ -13,7 +13,14 @@ float Terrain::getHeight(int32_t x, int32_t y) {
|
|||||||
x %= 64;
|
x %= 64;
|
||||||
y %= 64;
|
y %= 64;
|
||||||
|
|
||||||
return heightmap_tex->image_data[(y * heightmap_tex->extent.height * heightmap_tex->extent.width / 64 + x * heightmap_tex->extent.width / 64) * 4];
|
float xf = x;
|
||||||
|
float yf = y;
|
||||||
|
xf /= 64.0;
|
||||||
|
xf *= heightmap_tex->extent.width;
|
||||||
|
yf /= 64.0;
|
||||||
|
yf *= heightmap_tex->extent.height;
|
||||||
|
|
||||||
|
return static_cast<float>(heightmap_tex->image_data[static_cast<int>(static_cast<int>(yf) * heightmap_tex->extent.width + xf) * 4]) / 256.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Terrain::Terrain(vk::PhysicalDevice phys_dev, vk::Device dev, Texture& tex) : phys_dev(phys_dev), dev(dev) {
|
Terrain::Terrain(vk::PhysicalDevice phys_dev, vk::Device dev, Texture& tex) : phys_dev(phys_dev), dev(dev) {
|
||||||
@ -73,9 +80,9 @@ 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 = 15.0 * glm::sqrt(glm::abs(1.0 - normal.x*normal.x - normal.z*normal.z));
|
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::vec3(getHeight(x, y));
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,19 +16,13 @@ layout (set = 0, binding = 0) uniform Matrices {
|
|||||||
float tess_edge_size;
|
float tess_edge_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (set = 0, binding = 1) uniform sampler2D heightmap;
|
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 = vec3(10.0*cos(time), 10.0, 0.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, N), 0.0, 1.0) * 20.0/(r*r);
|
float t = clamp(dot(L, norm), 0.0, 1.0) * 20.0/(r*r);
|
||||||
|
|
||||||
FragColor = vec4(1.0);
|
FragColor = vec4(t, t/2.0, t*2.0, 1.0);
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user