Skip to content

Commit

Permalink
adding a smaller height map for grass
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumanvienna committed Jun 19, 2024
1 parent 2250b17 commit e55832f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion application/lucre/models/assets
1 change: 1 addition & 0 deletions application/lucre/terrainDescriptions/lucre island.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "height map 2",
"author": "Copyright (c) 2024 Engine Development Team",
"heightMapPath": "application/lucre/models/assets/terrain/lucreIsland1 heightmap.png",
"grassHeightMapPath": "application/lucre/models/assets/terrain/lucreIsland1 heightmap2.png",
"colorMapPath": "application/lucre/models/assets/terrain/lucreIsland1 colormap.png",
"material":
{
Expand Down
21 changes: 12 additions & 9 deletions engine/platform/Vulkan/shaders/grass.vert
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ layout(set = 2, binding = 0) uniform InstanceUniformBuffer
InstanceData m_InstanceData;
} baseTransform;

#define WIDTH 1024 // row
#define HEIGHT 750 // col
#define WIDTH 512 // row
#define HEIGHT 375 // col
#define NUM_HEIGHT_VALUES WIDTH*HEIGHT // 768000
#define INSTANCE_COUNT NUM_HEIGHT_VALUES

Expand All @@ -92,16 +92,19 @@ void main()
float row = floor(index / WIDTH);
float col = floor((index - WIDTH * row));

mat4 localTranslation = mat4
float theta = sin(hgt+gl_InstanceIndex); // random
float s = sin(theta); // sine
float c = cos(theta); // cosine
mat4 localTransform = mat4
(
vec4(4.0, 0.0, 0.0, 0.0), // first column
vec4(0.0, 4.0, 0.0, 0.0), // second column
vec4(0.0, 0.0, 4.0, 0.0), // third column
vec4(col, row, -hgt, 1.0) // fourth column
);
vec4(5.0 * c, s, 0.0, 0.0), // first column
vec4( -s, 5.0 * c, 0.0, 0.0), // second column
vec4( 0.0, 0.0, 5.0, 0.0), // third column
vec4( col, row, -hgt, 1.0) // fourth column
);

// projection * view * model * position
gl_Position = ubo.m_Projection * ubo.m_View * baseModelMatrix * localTranslation * vec4(position, 1.0);
gl_Position = ubo.m_Projection * ubo.m_View * baseModelMatrix * localTransform * vec4(position, 1.0);

vec4 positionWorld = baseModelMatrix * vec4(position, 1.0);
fragPosition = positionWorld.xyz;
Expand Down
4 changes: 2 additions & 2 deletions engine/renderer/builder/terrainBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace GfxRenderEngine
!EngineCore::IsDirectory(terrainSpec.m_FilepathGrassModel);
if (fileExists)
{
Image& heightMap = *terrainComponent.m_HeightMap.get();
Image heightMap(terrainSpec.m_FilepathGrassHeightMap);
uint heightMapSize = heightMap.Size();
Resources::ResourceBuffers resourceBuffers;
{
Expand Down Expand Up @@ -321,7 +321,7 @@ namespace GfxRenderEngine
auto& transform = registry.get<TransformComponent>(grassEntityRoot);
transform.SetRotation({3.14159f, 0.767164f, 3.14159f});
transform.SetTranslation({4.37885f, -1.14346f, 59.3405f});
transform.SetScale({0.0649992f, 0.0376f, 0.0649992f});
transform.SetScale({0.1299984f, 0.0376f, 0.1299984f});
}
}
}
Expand Down
1 change: 1 addition & 0 deletions engine/scene/terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace GfxRenderEngine
Material::PbrMaterial m_PbrMaterial{};
std::string m_FilepathTerrainDescription;
std::string m_FilepathHeightMap;
std::string m_FilepathGrassHeightMap;
std::string m_FilepathColorMap;
std::string m_FilepathGrassModel;
};
Expand Down
9 changes: 9 additions & 0 deletions engine/scene/terrainLoaderDeserializeJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ namespace GfxRenderEngine
terrainSpec.m_FilepathHeightMap = m_TerrainDescriptionFile.m_FilepathHeightMap;
LOG_CORE_INFO("Heightmap Path: {0}", m_TerrainDescriptionFile.m_FilepathHeightMap);
}
else if (terrainAttributesKey == "grassHeightMapPath")
{
CORE_ASSERT((terrainAttributes.value().type() == ondemand::json_type::string),
"grass heightmap path must be string");
std::string_view grassHeightMapPath = terrainAttributes.value().get_string();
m_TerrainDescriptionFile.m_FilepathGrassHeightMap = std::string(grassHeightMapPath);
terrainSpec.m_FilepathGrassHeightMap = m_TerrainDescriptionFile.m_FilepathGrassHeightMap;
LOG_CORE_INFO("Heightmap Path: {0}", m_TerrainDescriptionFile.m_FilepathGrassHeightMap);
}
else if (terrainAttributesKey == "colorMapPath")
{
CORE_ASSERT((terrainAttributes.value().type() == ondemand::json_type::string),
Expand Down
1 change: 1 addition & 0 deletions engine/scene/terrainLoaderJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace GfxRenderEngine
std::string m_Description;
std::string m_Author;
std::string m_FilepathHeightMap;
std::string m_FilepathGrassHeightMap;
std::string m_FilepathColorMap;
std::string m_FilepathGrassModel;
Material::PbrMaterial m_PbrMaterial;
Expand Down

0 comments on commit e55832f

Please sign in to comment.