From ee3e03564fb31195b94de0e3375b2c70ca6b7bbd Mon Sep 17 00:00:00 2001 From: Anders Pistol Date: Wed, 22 May 2024 22:11:01 +0200 Subject: [PATCH] Traktor: One layer of FFT waves working; need a lot of cleanup. --- code/Terrain/OceanComponent.cpp | 39 +++- .../System/Terrain/Ocean/Shaders/Ocean.xdi | 64 +++--- .../System/Terrain/Ocean/Shaders/Wave/FFT.xdi | 48 +++-- .../Terrain/Ocean/Shaders/Wave/Wave.xdi | 185 ++++++++++++++++-- 4 files changed, 262 insertions(+), 74 deletions(-) diff --git a/code/Terrain/OceanComponent.cpp b/code/Terrain/OceanComponent.cpp index 8133608cdb..6279226c97 100644 --- a/code/Terrain/OceanComponent.cpp +++ b/code/Terrain/OceanComponent.cpp @@ -228,7 +228,7 @@ void OceanComponent::setup( renderBlock->programParams->endParameters(renderContext); renderContext->compute(renderBlock); - renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Vertex, nullptr, 0); + renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Compute, nullptr, 0); }); context.getRenderGraph().addPass(rp); } @@ -253,7 +253,7 @@ void OceanComponent::setup( renderBlock->programParams->endParameters(renderContext); renderContext->compute(renderBlock); - renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Vertex, nullptr, 0); + renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Compute, nullptr, 0); }); context.getRenderGraph().addPass(rp); } @@ -281,7 +281,7 @@ void OceanComponent::setup( renderBlock->programParams->endParameters(renderContext); renderContext->compute(renderBlock); - renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Vertex, nullptr, 0); + renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Compute, nullptr, 0); }); context.getRenderGraph().addPass(rp); } @@ -307,7 +307,7 @@ void OceanComponent::setup( renderBlock->programParams->endParameters(renderContext); renderContext->compute(renderBlock); - renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Vertex, nullptr, 0); + renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Compute, nullptr, 0); }); context.getRenderGraph().addPass(rp); } @@ -333,11 +333,39 @@ void OceanComponent::setup( renderBlock->programParams->endParameters(renderContext); renderContext->compute(renderBlock); - renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Vertex, nullptr, 0); + renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Compute, nullptr, 0); + }); + context.getRenderGraph().addPass(rp); + } + + { + Ref< render::RenderPass > rp = new render::RenderPass(L"Ocean compute generate"); + rp->addBuild([=, this](const render::RenderGraph&, render::RenderContext* renderContext) { + auto renderBlock = renderContext->allocNamed< render::ComputeRenderBlock >(L"Ocean generate"); + + const render::Shader::Permutation perm(render::getParameterHandle(L"Generate")); + + renderBlock->program = m_shaderWave->getProgram(perm).program; + renderBlock->workSize[0] = 512; + renderBlock->workSize[1] = 512; + renderBlock->workSize[2] = 1; + + renderBlock->programParams = renderContext->alloc< render::ProgramParameters >(); + renderBlock->programParams->beginParameters(renderContext); + renderBlock->programParams->setFloatParameter(s_handleWorld_Time, worldRenderView.getTime()); + renderBlock->programParams->setFloatParameter(s_handleOcean_TileIndex, 0); + renderBlock->programParams->setImageViewParameter(s_handleOcean_WaveTexture, m_evolvedSpectrumTexture, 0); + renderBlock->programParams->endParameters(renderContext); + + renderContext->compute(renderBlock); + renderContext->compute< render::BarrierRenderBlock >(render::Stage::Compute, render::Stage::Compute, nullptr, 0); }); context.getRenderGraph().addPass(rp); } + for (int32_t i = 0; i < sizeof_array(m_waveTextures); ++i) + m_waveTextures[i] = m_evolvedSpectrumTexture; +/* for (int32_t i = 0; i < sizeof_array(m_waveTextures); ++i) { Ref< render::RenderPass > rp = new render::RenderPass(L"Ocean compute waves"); @@ -360,6 +388,7 @@ void OceanComponent::setup( }); context.getRenderGraph().addPass(rp); } + */ } void OceanComponent::build( diff --git a/data/Source/System/Terrain/Ocean/Shaders/Ocean.xdi b/data/Source/System/Terrain/Ocean/Shaders/Ocean.xdi index c53a4c9d1d..4d2e3112d4 100644 --- a/data/Source/System/Terrain/Ocean/Shaders/Ocean.xdi +++ b/data/Source/System/Terrain/Ocean/Shaders/Ocean.xdi @@ -16,8 +16,8 @@ {28DF02C7-A4C6-FE49-A2AF-1C3067BDCC63} - 655 - -51 + 586 + -33 Ocean_Eye Vector @@ -27,8 +27,8 @@ {5EB1A808-AB18-EE45-9E22-B94DF9FE5976} - 825 - -75 + 817 + -47 x0z @@ -36,8 +36,8 @@ {8AA18707-44AC-2644-8B41-ED4A2140AB74} - 186 - -139 + 118 + -171 World_World Matrix @@ -47,8 +47,8 @@ {C8A35F03-174D-CD40-B5D7-753769D81BF5} - 402 - -169 + 342 + -164 @@ -1478,7 +1478,7 @@ Detail normal -392 524 - 0.8 + 1 {C71CF517-7DAB-AB47-A04C-BA343330BEEB} @@ -1487,7 +1487,7 @@ Detail normal -392 559 - 0.6 + 0 {CD2AF069-3EE5-3A47-A4F9-E4FEB0F022D9} @@ -1496,7 +1496,7 @@ Detail normal -392 594 - 0.5 + 0 {10BB71A4-62CD-D84D-90BB-A3EAA6273E2A} @@ -1505,7 +1505,7 @@ Detail normal -392 636 - 0.4 + 0 @@ -1559,26 +1559,6 @@ Detail normal {3DE04294-4DEA-4A13-A460-2274647357EA} - - - - {9E839249-E9B9-4736-8BDD-A95A1C892B42} - - - - {F2E22CA6-DFF3-4B20-A70A-0D7A44EACD8C} - - - - - - {BD91C9E9-9950-4EC8-BAD2-60D2E8699107} - - - - {69997292-C813-490C-910C-620B9AD3A2BB} - - @@ -2869,6 +2849,26 @@ Detail normal {FE413452-19EB-4DC9-B724-2984FA17CC20} + + + + {BD91C9E9-9950-4EC8-BAD2-60D2E8699107} + + + + {69997292-C813-490C-910C-620B9AD3A2BB} + + + + + + {9E839249-E9B9-4736-8BDD-A95A1C892B42} + + + + {F2E22CA6-DFF3-4B20-A70A-0D7A44EACD8C} + + diff --git a/data/Source/System/Terrain/Ocean/Shaders/Wave/FFT.xdi b/data/Source/System/Terrain/Ocean/Shaders/Wave/FFT.xdi index 3257e402c2..3498c6c2cf 100644 --- a/data/Source/System/Terrain/Ocean/Shaders/Wave/FFT.xdi +++ b/data/Source/System/Terrain/Ocean/Shaders/Wave/FFT.xdi @@ -241,8 +241,8 @@ void ButterflyValues(uint step, uint index, out uvec2 indices, out vec2 twiddle) uint i = (w + index) % SIZE; // sincos(-twoPi / SIZE * w, twiddle.y, twiddle.x); - twiddle.x = cos(-twoPi / SIZE * w); twiddle.y = sin(-twoPi / SIZE * w); + twiddle.x = cos(-twoPi / SIZE * w); // This is what makes it the inverse FFT twiddle.y = -twiddle.y; @@ -280,13 +280,23 @@ vec4 FFT(Configuration configuration, uint threadIndex, vec4 inputData) } // Displacement -/* -void GenerateDisplacement(Configuration configuration, ivec3 id, uint tile) + +vec4 Permutate(vec4 data, ivec3 id) +{ + return data * (1.0f - 2.0f * ((id.x + id.y) % 2)); +} + +vec4 GenerateDisplacement(Configuration configuration, ivec3 id, uint tile, vec4 htildeDisplacement, vec4 htildeSlope) { const int i = 0; // Tile - vec4 htildeDisplacement = Permute(_SpectrumTextures[uvec3(id.xy, i * 2)], id); - vec4 htildeSlope = Permute(_SpectrumTextures[uvec3(id.xy, i * 2 + 1)], id); + //vec4 htildeDisplacement = Permute(_SpectrumTextures[uvec3(id.xy, i * 2)], id); + //vec4 htildeSlope = Permute(_SpectrumTextures[uvec3(id.xy, i * 2 + 1)], id); + + htildeDisplacement = Permutate(htildeDisplacement, id); + htildeSlope = Permutate(htildeSlope, id); + + vec2 _Lambda = vec2(1.0f, 1.0f); vec2 dxdz = htildeDisplacement.rg; vec2 dydxz = htildeDisplacement.ba; @@ -295,29 +305,31 @@ void GenerateDisplacement(Configuration configuration, ivec3 id, uint tile) float jacobian = (1.0f + _Lambda.x * dxxdzz.x) * (1.0f + _Lambda.y * dxxdzz.y) - _Lambda.x * _Lambda.y * dydxz.y * dydxz.y; - vec3 displacement = float3(_Lambda.x * dxdz.x, dydxz.x, _Lambda.y * dxdz.y); + vec3 displacement = vec3(_Lambda.x * dxdz.x, dydxz.x, _Lambda.y * dxdz.y); + + return vec4(displacement, 0.0f); - vec2 slopes = dyxdyz.xy / (1 + abs(dxxdzz * _Lambda)); - float covariance = slopes.x * slopes.y; +// vec2 slopes = dyxdyz.xy / (1 + abs(dxxdzz * _Lambda)); +// float covariance = slopes.x * slopes.y; - float foam = _DisplacementTextures[uint3(id.xy, i)].a; - foam *= exp(-_FoamDecayRate); - foam = saturate(foam); +// float foam = _DisplacementTextures[uint3(id.xy, i)].a; +// foam *= exp(-_FoamDecayRate); +// foam = saturate(foam); - float biasedJacobian = max(0.0f, -(jacobian - _FoamBias)); +// float biasedJacobian = max(0.0f, -(jacobian - _FoamBias)); - if (biasedJacobian > _FoamThreshold) - foam += _FoamAdd * biasedJacobian; +// if (biasedJacobian > _FoamThreshold) +// foam += _FoamAdd * biasedJacobian; - _DisplacementTextures[uint3(id.xy, i)] = float4(displacement, foam); - _SlopeTextures[uint3(id.xy, i)] = float2(slopes); +// _DisplacementTextures[uint3(id.xy, i)] = float4(displacement, foam); +// _SlopeTextures[uint3(id.xy, i)] = float2(slopes); // if (i == 0) { // _BuoyancyData[id.xy] = displacement.y; // } - } +// } } -*/ + // Old float CalculateDisplacement(vec2 position, float time) diff --git a/data/Source/System/Terrain/Ocean/Shaders/Wave/Wave.xdi b/data/Source/System/Terrain/Ocean/Shaders/Wave/Wave.xdi index a99fb3f5ed..2e56fc429e 100644 --- a/data/Source/System/Terrain/Ocean/Shaders/Wave/Wave.xdi +++ b/data/Source/System/Terrain/Ocean/Shaders/Wave/Wave.xdi @@ -5,8 +5,8 @@ {095A17AD-C3B2-4D45-BD20-E7FACDCC696F} - 693 - 183 + 742 + 1777 Default @@ -19,8 +19,8 @@ {3CDB2372-CEE8-FC46-ACD2-740B4FE1D4E1} - 360 - 199 + 409 + 1793 Ocean_WaveTexture Image2D @@ -244,17 +244,17 @@ configuration.depth = 20.0f; configuration.gravity = 9.81f; configuration.lowCutoff = 0.0001f; configuration.highCutoff = 9000.0f; -configuration.lengthScales = vec4(256.0f, 1.0f, 1.0f, 1.0f); +configuration.lengthScales = vec4(100.0f, 1.0f, 1.0f, 1.0f); SpectrumParameters spectrum; -spectrum.scale = 1.0f; +spectrum.scale = 0.02f; spectrum.angle = 0.0f; spectrum.spreadBlend = 0.5f; spectrum.swell = 0.5f; spectrum.alpha = 0.5f; spectrum.peakOmega = 1.0f; spectrum.gamma = 0.5f; -spectrum.shortWavesFade = 0.5f; +spectrum.shortWavesFade = 0.15f; $Output = CalculateSpectrum( configuration, @@ -262,6 +262,7 @@ $Output = CalculateSpectrum( ivec3(position, 0), 0 ); + ]]> @@ -602,8 +603,8 @@ $Output = FFT(configuration, $Index, inputData); {83090577-C7BC-464E-8FC8-B7CF8CDDBDE1} - -208 - 1228 + -157 + 1239 x @@ -664,6 +665,102 @@ $Output = FFT(configuration, $Index, inputData); ]]> + + {4DFB091D-8730-4548-A500-22D99D929C05} + + + 178 + 1639 + + Generate displacement + + + 16 + 16 + 1 + + + {E21A21CC-F70C-474E-87DD-9D7B89AAC05F} + + + + {3528ECFC-7D5A-5B42-93F2-31E805AC690F} + Position + + + {A100C668-C7CE-47C8-8EAE-2AADAA14123B} + Texture + + + + + {BEA4FC3C-DC18-F842-9721-2BF4E52B8C42} + Output + Vector + + + + + + {AF4BAE1E-B542-42C0-9EAB-E4CB9B563AC6} + + + 708 + 1564 + + Generate + + 16 + 16 + 1 + + + + {8BC51D82-38FC-45A0-BDDA-629C402DCF7B} + + + 421 + 1566 + + Ocean_WaveTexture + Image2D + Once + + + {BAE9354B-059B-4513-B205-385F37871512} + + + -117 + 1630 + + Ocean_WaveTexture + Image2D + Once + @@ -716,16 +813,6 @@ $Output = FFT(configuration, $Index, inputData); {F2E22CA6-DFF3-4B20-A70A-0D7A44EACD8C} - - - - {ADB4FC1D-3726-4CC5-B4D5-1E2468274325} - - - - {4356E929-19D3-45DD-8143-0168015DB701} - - @@ -1096,6 +1183,66 @@ $Output = FFT(configuration, $Index, inputData); {4356E929-19D3-45DD-8143-0168015DB701} + + + + {1E6639B6-8B58-4694-99E7-C058E3583522} + + + + {60D25829-A948-4883-B26F-F2BE12B49891} + + + + + + {ADB4FC1D-3726-4CC5-B4D5-1E2468274325} + + + + {3528ECFC-7D5A-5B42-93F2-31E805AC690F} + + + + + + {1E6639B6-8B58-4694-99E7-C058E3583522} + + + + {A100C668-C7CE-47C8-8EAE-2AADAA14123B} + + + + + + {ADB4FC1D-3726-4CC5-B4D5-1E2468274325} + + + + {0907D535-A1B6-409A-A70A-C250D3CDCD58} + + + + + + {BEA4FC3C-DC18-F842-9721-2BF4E52B8C42} + + + + {4356E929-19D3-45DD-8143-0168015DB701} + + + + + + {BEA4FC3C-DC18-F842-9721-2BF4E52B8C42} + + + + {4356E929-19D3-45DD-8143-0168015DB701} + +