diff --git a/res/shaders/TerrainPass.slang b/res/shaders/TerrainPass.slang index 21e2b37..cd287b8 100644 --- a/res/shaders/TerrainPass.slang +++ b/res/shaders/TerrainPass.slang @@ -32,7 +32,11 @@ VertexOutput vert(VertexInput input) // Which vertex should be read? local_vert_id = local_vert_id == 0 ? 2 : (local_vert_id == 2 ? 0 : 1); float3 positionRWS = pParams.currentVertexBuffer[output.triangleID * 3 + local_vert_id].xyz; + //positionRWS.y = pParams.displacementMap.SampleLevel(pParams.displacementSampler, positionRWS.xz, 0).r; + float2 texCoord = positionRWS.xz / 1000; + + positionRWS.y = pParams.displacementMap.SampleLevel(pParams.displacementSampler, texCoord, 0).r * 100; // Apply the view projection output.positionCS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(positionRWS, 1.0))); return output; diff --git a/res/shaders/terrain/Parameters.slang b/res/shaders/terrain/Parameters.slang index 896f079..4410e7d 100644 --- a/res/shaders/terrain/Parameters.slang +++ b/res/shaders/terrain/Parameters.slang @@ -86,6 +86,10 @@ struct ComputeParams // 22 StructuredBuffer lebMatrixCache; // 23 - globallycoherent RWStructuredBuffer debugBuffer; + RWStructuredBuffer debugBuffer; + // 24 + SamplerState displacementSampler; + // 25 + Texture2D displacementMap; }; ParameterBlock pParams; diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index e957624..0a022e7 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -106,13 +106,13 @@ int main() { //AssetImporter::importTexture(TextureImportArgs{ // .filePath = sourcePath / "import/textures/azeroth_height.png", //}); - //AssetImporter::importTexture(TextureImportArgs{ - // .filePath = sourcePath / "import/textures/wgen.png", - //}); - AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", - .importPath = "Whitechapel", + AssetImporter::importTexture(TextureImportArgs{ + .filePath = sourcePath / "import/textures/wgen.png", }); + //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", + // .importPath = "Whitechapel", + //}); // AssetImporter::importMesh(MeshImportArgs{521 // .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj", // .importPath = "suburbs", diff --git a/src/Engine/Graphics/CBT/CBT.cpp b/src/Engine/Graphics/CBT/CBT.cpp index 14e8629..b7792ae 100644 --- a/src/Engine/Graphics/CBT/CBT.cpp +++ b/src/Engine/Graphics/CBT/CBT.cpp @@ -1,5 +1,6 @@ #include "CBT.h" #include "Graphics/Shader.h" +#include "Asset/AssetRegistry.h" using namespace Seele; @@ -240,6 +241,8 @@ void MeshUpdater::init(Gfx::PGraphics gfx, Gfx::PDescriptorLayout viewParamsLayo layout->addDescriptorBinding(Gfx::DescriptorBinding{21, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); layout->addDescriptorBinding(Gfx::DescriptorBinding{22, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); layout->addDescriptorBinding(Gfx::DescriptorBinding{23, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); + layout->addDescriptorBinding(Gfx::DescriptorBinding{24, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER}); + layout->addDescriptorBinding(Gfx::DescriptorBinding{25, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE}); layout->create(); pipelineLayout = graphics->createPipelineLayout("ComputeLayout"); pipelineLayout->addDescriptorLayout(viewParamsLayout); diff --git a/src/Engine/Graphics/CBT/CBT.h b/src/Engine/Graphics/CBT/CBT.h index ce732ea..6c22279 100644 --- a/src/Engine/Graphics/CBT/CBT.h +++ b/src/Engine/Graphics/CBT/CBT.h @@ -30,6 +30,8 @@ constexpr auto MODIFIED_BISECTOR_INDICES = 20; constexpr auto LEB_POSITION_BUFFER = 21; constexpr auto LEB_MATRIX_CACHE = 22; constexpr auto DEBUG_BUFFER = 23; +constexpr auto SAMPLER_LOCATION = 24; +constexpr auto DISPLACEMENT_MAP = 25; constexpr uint64 WORKGROUP_SIZE = 64; template class CBT { diff --git a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp index 7cca862..5eef692 100644 --- a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp @@ -253,6 +253,8 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe .computeShader = deformCS, .pipelineLayout = meshUpdater.pipelineLayout, }); + sampler = graphics->createSampler({}); + displacementAsset = AssetRegistry::findTexture("", "wgen")->getTexture().cast(); meshUpdater.resetBuffers(plainMesh); meshUpdater.prepareIndirection(plainMesh, geometryBuffer); meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), true, true); @@ -273,6 +275,8 @@ Gfx::ORenderCommand TerrainRenderer::render(Gfx::PDescriptorSet viewParamsSet) { Gfx::PDescriptorSet set = meshUpdater.layout->allocateDescriptorSet(); set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer); set->updateBuffer(INDEXED_BISECTOR_BUFFER, 0, plainMesh.indexedBisectorBuffer); + set->updateSampler(SAMPLER_LOCATION, 0, sampler); + set->updateTexture(DISPLACEMENT_MAP, 0, displacementAsset); set->writeChanges(); Gfx::ORenderCommand command = graphics->createRenderCommand("TerrainRender"); command->setViewport(viewport); diff --git a/src/Engine/Graphics/RenderPass/TerrainRenderer.h b/src/Engine/Graphics/RenderPass/TerrainRenderer.h index 43bca35..b81b6ad 100644 --- a/src/Engine/Graphics/RenderPass/TerrainRenderer.h +++ b/src/Engine/Graphics/RenderPass/TerrainRenderer.h @@ -31,6 +31,7 @@ class TerrainRenderer { Gfx::PTexture2D displacementMap; Gfx::PTexture2D colorMap; Gfx::OSampler sampler; + Gfx::PTexture2D displacementAsset; Gfx::OUniformBuffer geometryBuffer; Gfx::OUniformBuffer updateBuffer;