Fixed it!

Holy shit all it was really was performing a computation without assigning the result (x *= n instead of x * n).
This commit is contained in:
connellpaxton 2024-02-05 23:32:54 -05:00
parent 7aa5d04e4e
commit 7fd68abcf9
9 changed files with 28 additions and 31 deletions

View File

@ -95,7 +95,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
.depthClampEnable = vk::False,
.polygonMode = type == Type::eGLTF? vk::PolygonMode::eFill : vk::PolygonMode::eLine,
.cullMode = vk::CullModeFlagBits::eNone,
.frontFace = vk::FrontFace::eCounterClockwise,
.frontFace = Type::eGLTF ? vk::FrontFace::eClockwise : vk::FrontFace::eCounterClockwise,
.depthBiasEnable = vk::False,
.lineWidth = 1.0,
};

View File

@ -53,12 +53,20 @@ Renderer::Renderer(Window& win) : win(win) {
Log::info("\t\"%s\"\n", layer.layerName.data());
}
vk::ValidationFeatureEnableEXT enabled[] = { vk::ValidationFeatureEnableEXT::eDebugPrintf, vk::ValidationFeatureEnableEXT::eBestPractices };
vk::ValidationFeaturesEXT validation_features{ };
validation_features.disabledValidationFeatureCount = 0;
validation_features.enabledValidationFeatureCount = std::size(enabled);
validation_features.pDisabledValidationFeatures = nullptr;
validation_features.pEnabledValidationFeatures = enabled;
const char* my_layers[] = {
// "VK_LAYER_LUNARG_api_dump",
"VK_LAYER_KHRONOS_validation",
};
auto inst_info = vk::InstanceCreateInfo{
.pNext = &validation_features,
.pApplicationInfo = &app_info,
.enabledLayerCount = std::size(my_layers),
.ppEnabledLayerNames = my_layers,
@ -125,6 +133,7 @@ Renderer::Renderer(Window& win) : win(win) {
std::vector<const char*> req_dev_extensions;
req_dev_extensions.push_back("VK_KHR_swapchain");
req_dev_extensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
req_dev_extensions.push_back("VK_KHR_shader_non_semantic_info");
auto dev_extentions = phys_dev.enumerateDeviceExtensionProperties();
Log::info("%zu available device extensions\n", dev_extentions.size());
@ -184,7 +193,7 @@ Renderer::Renderer(Window& win) : win(win) {
textures = createResources({
"assets/textures/oil.jpg",
"assets/textures/heightmap.png",
"assets/textures/eire.png",
});
std::vector<Shader> shaders = {
@ -208,7 +217,7 @@ Renderer::Renderer(Window& win) : win(win) {
pipeline = std::make_unique<GraphicsPipeline>(dev, shaders, swapchain->extent, *render_pass, bindings, *models[0]->vertex_buffer);
pipeline->update(0, *uniform_buffer);
pipeline->update(1, textures[0]);
pipeline->update(1, textures[1]);
/* create Terrain */
@ -223,6 +232,7 @@ Renderer::Renderer(Window& win) : win(win) {
terrain_pipeline = std::make_unique<GraphicsPipeline>(dev, terrain_shaders, swapchain->extent, *render_pass, bindings, *terrain->vertex_buffer, GraphicsPipeline::eTERRAIN);
terrain_pipeline->update(0, *uniform_buffer);
terrain_pipeline->update(1, textures[1]);
for (auto& shader : shaders)
@ -324,22 +334,10 @@ void Renderer::draw() {
/* no secondary command buffers (yet), so contents are passed inline */
command_buffer->command_buffer.beginRenderPass(render_pass_info, vk::SubpassContents::eInline);
command_buffer->bind(*pipeline);
command_buffer->command_buffer.setViewport(0, viewport);
command_buffer->command_buffer.setScissor(0, scissor);
command_buffer->bind(models[0]);
command_buffer->bind(pipeline->layout, pipeline->desc_set);
auto sz = win.getDimensions();
const auto p = glm::perspective(glm::radians(90.0f), static_cast<float>(sz.width) / static_cast<float>(sz.height), 0.01f, 2000.0f);
uniform_buffer->upload(UniformData {
.view = cam.view(),
.proj = p,
@ -350,12 +348,11 @@ void Renderer::draw() {
.tess_edge_size = tess_edge_size,
});
//command_buffer->command_buffer.drawIndexed(models[0]->indices.size(), 10, 0, 0, 0);
command_buffer->bind(*terrain_pipeline);
command_buffer->command_buffer.setViewport(0, viewport);
command_buffer->command_buffer.setScissor(0, scissor);
command_buffer->bind(terrain_pipeline->layout, terrain_pipeline->desc_set);
command_buffer->bind(terrain.get());
command_buffer->command_buffer.drawIndexed(terrain->indices.size(), 1, 0, 0, 0);

View File

@ -23,5 +23,5 @@ void main() {
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);
FragColor = vec4(norm * texture(tex, texCoord).xyz + t, 1.0);
}

Binary file not shown.

View File

@ -1,4 +1,5 @@
#version 450 core
#extension GL_EXT_debug_printf : enable
layout (set = 0, binding = 0) uniform Matrices {
mat4 view;
@ -25,42 +26,41 @@ layout (location = 2) out vec3 _pos[4];
float screen_space_tess(vec4 p0, vec4 p1) {
/* calc midpoint + distance btw the two points */
vec4 mid = (p0+p1) * 0.5;
vec4 midp = 0.5*(p0+p1);
float r = distance(p0, p1) / 2.0;
vec4 v0 = view * mid;
vec4 v0 = view * midp;
/* projevt into clip spaace */
vec4 clip0 = proj * (v0 - vec4(r, 0.0, 0.0, 0.0));
vec4 clip1 = proj * (v0 + vec4(r, 0.0, 0.0, 0.0));
/* project into clip spaace */
vec4 clip0 = proj * (v0 - vec4(r, vec3(0.0)));
vec4 clip1 = proj * (v0 + vec4(r, vec3(0.0)));
clip0 /= clip0.w;
clip1 /= clip1.w;
/* convert to viewport coords */
clip0.xy * viewport;
clip1.xy * viewport;
clip0.xy *= viewport;
clip1.xy *= viewport;
return clamp(distance(clip0, clip0) / tess_edge_size * tess_factor, 1.0, 64.0);
return clamp(distance(clip0, clip1) / tess_edge_size * tess_factor, 1.0, 64.0);
}
void main() {
if(gl_InvocationID == 0) {
/*
gl_TessLevelOuter[0] = screen_space_tess(gl_in[3].gl_Position, gl_in[0].gl_Position);
gl_TessLevelOuter[1] = screen_space_tess(gl_in[0].gl_Position, gl_in[1].gl_Position);
gl_TessLevelOuter[2] = screen_space_tess(gl_in[1].gl_Position, gl_in[2].gl_Position);
gl_TessLevelOuter[3] = screen_space_tess(gl_in[2].gl_Position, gl_in[3].gl_Position);
gl_TessLevelInner[0] = mix(gl_TessLevelOuter[0], gl_TessLevelOuter[3], 0.5);
gl_TessLevelInner[1] = mix(gl_TessLevelOuter[2], gl_TessLevelOuter[1], 0.5);*/
gl_TessLevelInner[1] = mix(gl_TessLevelOuter[2], gl_TessLevelOuter[1], 0.5);
gl_TessLevelOuter[0] = tess_factor;
/*gl_TessLevelOuter[0] = tess_factor;
gl_TessLevelOuter[1] = tess_factor;
gl_TessLevelOuter[2] = tess_factor;
gl_TessLevelOuter[3] = tess_factor;
gl_TessLevelInner[0] = mix(gl_TessLevelOuter[0], gl_TessLevelOuter[3], 0.5);
gl_TessLevelInner[1] = mix(gl_TessLevelOuter[2], gl_TessLevelOuter[1], 0.5);
gl_TessLevelInner[1] = mix(gl_TessLevelOuter[2], gl_TessLevelOuter[1], 0.5);*/
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;

Binary file not shown.

View File

@ -40,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 + cos(fpos.x*fpos.y);
fpos.y += 15.0 * texture(heightmap, _texCoord).r; //+ cos(fpos.x*fpos.y);
_pos = fpos.xyz;
gl_Position = proj * view * fpos;

Binary file not shown.

BIN
assets/textures/eire.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB