Add in Z scaling to texture map
This commit is contained in:
@@ -3,13 +3,15 @@
|
||||
layout(location = 0) in vec3 in_normal[];
|
||||
layout(location = 1) in vec3 in_color[];
|
||||
layout(location = 2) in vec2 in_uv[];
|
||||
layout(location = 3) in uint in_tex_idx[];
|
||||
layout(location = 3) in flat uint in_tex_idx[];
|
||||
layout(location = 4) in flat float in_scale_z[];
|
||||
|
||||
layout(vertices = 4) out;
|
||||
|
||||
layout(location = 0) out vec3 out_normal[4];
|
||||
layout(location = 1) out vec2 out_uv[4];
|
||||
layout(location = 2) out uint out_tex_idx[4];
|
||||
layout(location = 2) out flat uint out_tex_idx[4];
|
||||
layout(location = 3) out flat float out_scale_z[4];
|
||||
|
||||
layout (set = 0, binding = 0) uniform CameraInfo {
|
||||
mat4 projection;
|
||||
@@ -50,4 +52,5 @@ void main()
|
||||
out_normal[gl_InvocationID] = in_normal[gl_InvocationID];
|
||||
out_uv[gl_InvocationID] = in_uv[gl_InvocationID];
|
||||
out_tex_idx[gl_InvocationID] = in_tex_idx[gl_InvocationID];
|
||||
out_scale_z[gl_InvocationID] = in_scale_z[gl_InvocationID];
|
||||
}
|
||||
@@ -5,7 +5,8 @@ layout(quads, equal_spacing, cw) in;
|
||||
|
||||
layout(location = 0) in vec3 in_normal[];
|
||||
layout(location = 1) in vec2 in_uv[];
|
||||
layout(location = 2) in uint in_tex_idx[];
|
||||
layout(location = 2) in flat uint in_tex_idx[];
|
||||
layout(location = 3) in flat float in_scale_z[];
|
||||
|
||||
layout(location = 0) out vec3 out_normal;
|
||||
layout(location = 1) out vec2 out_uv;
|
||||
@@ -39,7 +40,8 @@ void main()
|
||||
|
||||
vec4 world_pos = ubo.projection * ubo.view * pos;
|
||||
|
||||
world_pos.y -= (texture(tex[out_tex_idx], out_uv).r - 0.5);
|
||||
// Doesn't matter which in_scale_z we take since it'll be the same for the entire model.
|
||||
world_pos.y -= (texture(tex[out_tex_idx], out_uv).r - 0.5) * in_scale_z[0];
|
||||
|
||||
out_world_pos = vec3(world_pos);
|
||||
gl_Position = world_pos;
|
||||
|
||||
@@ -12,11 +12,14 @@ layout (location = 8) in uint in_texture_id;
|
||||
layout (location = 0) out vec3 out_normal;
|
||||
layout (location = 1) out vec3 out_color;
|
||||
layout (location = 2) out vec2 out_tex_coord;
|
||||
layout (location = 3) out uint out_texture_idx;
|
||||
layout (location = 3) out flat uint out_texture_idx;
|
||||
layout (location = 4) out flat float out_scale_z;
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = instance_model_matrix * vec4(position, 1.0f);
|
||||
//We want to grab the scale value
|
||||
out_scale_z = length(instance_model_matrix[2]);
|
||||
|
||||
mat3 normal_matrix = transpose(inverse(mat3(instance_model_matrix)));
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <tracy/TracyVulkan.hpp>
|
||||
|
||||
#include "engine/model/prebuilt/terrainModel.hpp"
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
@@ -291,25 +292,9 @@ namespace fgl::engine
|
||||
}*/
|
||||
|
||||
{
|
||||
std::vector< Vertex > verts {};
|
||||
|
||||
verts.emplace_back(
|
||||
glm::vec3( -1.0f, -1.0f, 0.0f ), glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 0.0f, 0.5f ) );
|
||||
verts.emplace_back(
|
||||
glm::vec3( -1.0f, 1.0f, 0.0f ), glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 0.5f, .5f ) );
|
||||
verts.emplace_back(
|
||||
glm::vec3( 1.0f, 1.0f, 0.0f ), glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 0.5f, 0.0f ) );
|
||||
verts.emplace_back(
|
||||
glm::vec3( 1.0f, -1.0f, 0.0f ), glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 0.0f, 0.0f ) );
|
||||
|
||||
std::vector< std::uint32_t > indicies { 0, 1, 2, 3 };
|
||||
|
||||
std::shared_ptr< Model > model { Model::createModelFromVerts(
|
||||
Device::getInstance(),
|
||||
std::move( verts ),
|
||||
std::move( indicies ),
|
||||
m_terrain_system.getVertexBuffer(),
|
||||
m_terrain_system.getIndexBuffer() ) };
|
||||
auto model {
|
||||
generateTerrainModel( m_terrain_system.getVertexBuffer(), m_terrain_system.getIndexBuffer() )
|
||||
};
|
||||
|
||||
Texture texture { Texture::loadFromFile( "models/textures/heightmap.png" ) };
|
||||
Sampler sampler { vk::Filter::eLinear,
|
||||
|
||||
37
src/engine/model/prebuilt/terrainModel.cpp
Normal file
37
src/engine/model/prebuilt/terrainModel.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by kj16609 on 3/16/24.
|
||||
//
|
||||
|
||||
#include "terrainModel.hpp"
|
||||
|
||||
#include "engine/model/Model.hpp"
|
||||
#include "engine/rendering/Device.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
std::shared_ptr< Model > generateTerrainModel( Buffer& vertex_buffer, Buffer& index_buffer )
|
||||
{
|
||||
std::vector< Vertex > verts {};
|
||||
|
||||
constexpr glm::vec3 TOP_LEFT { -0.5f, 0.5f, 0.0f };
|
||||
constexpr glm::vec3 TOP_RIGHT { 0.5f, 0.5f, 0.0f };
|
||||
constexpr glm::vec3 BOTTOM_RIGHT { 0.5f, -0.5f, 0.0f };
|
||||
constexpr glm::vec3 BOTTOM_LEFT { -0.5f, -0.5f, 0.0f };
|
||||
constexpr float dist_mulpt { 2.0f };
|
||||
|
||||
verts.emplace_back( TOP_LEFT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 0.0f, 0.0f ) );
|
||||
verts.emplace_back( TOP_RIGHT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 1.0f, 0.0f ) );
|
||||
verts
|
||||
.emplace_back( BOTTOM_RIGHT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 1.0f, 1.0f ) );
|
||||
verts.emplace_back( BOTTOM_LEFT * dist_mulpt, glm::vec3( 1.0f ), constants::WORLD_UP, glm::vec2( 0.0f, 1.0f ) );
|
||||
|
||||
std::vector< std::uint32_t > indicies { 0, 1, 2, 3 };
|
||||
|
||||
std::shared_ptr< Model > model { Model::createModelFromVerts(
|
||||
Device::getInstance(), std::move( verts ), std::move( indicies ), vertex_buffer, index_buffer ) };
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
} // namespace fgl::engine
|
||||
17
src/engine/model/prebuilt/terrainModel.hpp
Normal file
17
src/engine/model/prebuilt/terrainModel.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by kj16609 on 3/16/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
class Model;
|
||||
|
||||
class Buffer;
|
||||
|
||||
std::shared_ptr< Model > generateTerrainModel( Buffer& vertex_buffer, Buffer& index_buffer );
|
||||
|
||||
} // namespace fgl::engine
|
||||
@@ -15,18 +15,9 @@ namespace fgl::engine
|
||||
|
||||
//TODO: This uses the Tait-Bryan angles stuff, It should use the respective function.
|
||||
// Or maybe something else can be done here
|
||||
return glm::mat4 { { scale.x * rotation_mat[ 0 ][ 0 ],
|
||||
scale.x * rotation_mat[ 0 ][ 1 ],
|
||||
scale.x * rotation_mat[ 0 ][ 2 ],
|
||||
0.0f },
|
||||
{ scale.y * rotation_mat[ 1 ][ 0 ],
|
||||
scale.y * rotation_mat[ 1 ][ 1 ],
|
||||
scale.y * rotation_mat[ 1 ][ 2 ],
|
||||
0.0f },
|
||||
{ scale.z * rotation_mat[ 2 ][ 0 ],
|
||||
scale.z * rotation_mat[ 2 ][ 1 ],
|
||||
scale.z * rotation_mat[ 2 ][ 2 ],
|
||||
0.0f },
|
||||
return glm::mat4 { { scale.x * rotation_mat[ 0 ], 0.0f },
|
||||
{ scale.y * rotation_mat[ 1 ], 0.0f },
|
||||
{ scale.z * rotation_mat[ 2 ], 0.0f },
|
||||
{ translation.vec().x, translation.vec().y, translation.vec().z, 1.0f } };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user