diff --git a/application/lucre/models/assets b/application/lucre/models/assets index f910d4e9..5d8de711 160000 --- a/application/lucre/models/assets +++ b/application/lucre/models/assets @@ -1 +1 @@ -Subproject commit f910d4e98739eeb741c90d7b4f5b904554d6b1b9 +Subproject commit 5d8de7112ed127391780a2bc2e4f6d2070766497 diff --git a/application/lucre/terrainDescriptions/lucre island.json b/application/lucre/terrainDescriptions/lucre island.json index 114b99a0..005c143e 100644 --- a/application/lucre/terrainDescriptions/lucre island.json +++ b/application/lucre/terrainDescriptions/lucre island.json @@ -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": { diff --git a/engine/platform/Vulkan/shaders/grass.vert b/engine/platform/Vulkan/shaders/grass.vert index 561f551a..8080b4aa 100644 --- a/engine/platform/Vulkan/shaders/grass.vert +++ b/engine/platform/Vulkan/shaders/grass.vert @@ -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 @@ -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; diff --git a/engine/renderer/builder/terrainBuilder.cpp b/engine/renderer/builder/terrainBuilder.cpp index 40c6f0ab..b02089a8 100644 --- a/engine/renderer/builder/terrainBuilder.cpp +++ b/engine/renderer/builder/terrainBuilder.cpp @@ -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; { @@ -321,7 +321,7 @@ namespace GfxRenderEngine auto& transform = registry.get(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}); } } } diff --git a/engine/scene/terrain.h b/engine/scene/terrain.h index fa72fbd2..7b8b400f 100644 --- a/engine/scene/terrain.h +++ b/engine/scene/terrain.h @@ -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; }; diff --git a/engine/scene/terrainLoaderDeserializeJSON.cpp b/engine/scene/terrainLoaderDeserializeJSON.cpp index c54d7049..a99ed409 100644 --- a/engine/scene/terrainLoaderDeserializeJSON.cpp +++ b/engine/scene/terrainLoaderDeserializeJSON.cpp @@ -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), diff --git a/engine/scene/terrainLoaderJSON.h b/engine/scene/terrainLoaderJSON.h index ed298bb4..993ddf4a 100644 --- a/engine/scene/terrainLoaderJSON.h +++ b/engine/scene/terrainLoaderJSON.h @@ -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;