moved ocean simulator texture updates to compute shader
This commit is contained in:
@@ -73,7 +73,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
|
||||
|
||||
|
||||
|
||||
cameraWindow->Translate(XMFLOAT3(760, 500, 0));
|
||||
cameraWindow->Translate(XMFLOAT3(800, 500, 0));
|
||||
cameraWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1402,6 +1402,13 @@ void EditorComponent::Compose()
|
||||
{
|
||||
renderPath->Compose();
|
||||
|
||||
if (wiRenderer::GetOcean())
|
||||
{
|
||||
wiImageEffects fx(500, 500, 500, 500);
|
||||
fx.blendFlag = BLENDMODE_OPAQUE;
|
||||
wiImage::Draw(wiRenderer::GetOcean()->getDisplacementMap(), fx, GRAPHICSTHREAD_IMMEDIATE);
|
||||
}
|
||||
|
||||
//__super::Compose();
|
||||
|
||||
for (auto& x : wiRenderer::GetScene().models)
|
||||
|
||||
@@ -9,6 +9,9 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
|
||||
float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth();
|
||||
float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight();
|
||||
|
||||
//params.patch_length = 200.0f;
|
||||
//params.wave_amplitude = 0.0f;
|
||||
|
||||
oceanWindow = new wiWindow(GUI, "Ocean Window");
|
||||
oceanWindow->SetSize(XMFLOAT2(600, 300));
|
||||
GUI->AddWidget(oceanWindow);
|
||||
|
||||
@@ -452,9 +452,6 @@
|
||||
<FxCompile Include="objectVS_voxelizer.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanGradientFoldingPS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanQuadVS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
@@ -471,8 +468,13 @@
|
||||
<FxCompile Include="oceanSurfaceVS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanUpdateDisplacementPS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
<FxCompile Include="oceanUpdateDisplacementMapCS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanUpdateGradientFoldingCS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="outlinePS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
|
||||
@@ -666,12 +666,6 @@
|
||||
<FxCompile Include="oceanQuadVS.hlsl">
|
||||
<Filter>VS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanGradientFoldingPS.hlsl">
|
||||
<Filter>PS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanUpdateDisplacementPS.hlsl">
|
||||
<Filter>PS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanSurfaceVS.hlsl">
|
||||
<Filter>VS</Filter>
|
||||
</FxCompile>
|
||||
@@ -681,6 +675,12 @@
|
||||
<FxCompile Include="oceanSurfaceSimplePS.hlsl">
|
||||
<Filter>PS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanUpdateDisplacementMapCS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="oceanUpdateGradientFoldingCS.hlsl">
|
||||
<Filter>CS</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="PS">
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#include "oceanWaveGenHF.hlsli"
|
||||
|
||||
// Displacement -> Normal, Folding
|
||||
float4 main(VS_QUAD_OUTPUT In) : SV_Target
|
||||
{
|
||||
// Sample neighbour texels
|
||||
float2 one_texel = float2(1.0f / (float)g_OutWidth, 1.0f / (float)g_OutHeight);
|
||||
|
||||
float2 tc_left = float2(In.TexCoord.x - one_texel.x, In.TexCoord.y);
|
||||
float2 tc_right = float2(In.TexCoord.x + one_texel.x, In.TexCoord.y);
|
||||
float2 tc_back = float2(In.TexCoord.x, In.TexCoord.y - one_texel.y);
|
||||
float2 tc_front = float2(In.TexCoord.x, In.TexCoord.y + one_texel.y);
|
||||
|
||||
float3 displace_left = g_samplerDisplacementMap.Sample(LinearSampler, tc_left).xyz;
|
||||
float3 displace_right = g_samplerDisplacementMap.Sample(LinearSampler, tc_right).xyz;
|
||||
float3 displace_back = g_samplerDisplacementMap.Sample(LinearSampler, tc_back).xyz;
|
||||
float3 displace_front = g_samplerDisplacementMap.Sample(LinearSampler, tc_front).xyz;
|
||||
|
||||
// Do not store the actual normal value. Using gradient instead, which preserves two differential values.
|
||||
float2 gradient = { -(displace_right.z - displace_left.z), -(displace_front.z - displace_back.z) };
|
||||
|
||||
|
||||
// Calculate Jacobian corelation from the partial differential of height field
|
||||
float2 Dx = (displace_right.xy - displace_left.xy) * g_ChoppyScale * g_GridLen;
|
||||
float2 Dy = (displace_front.xy - displace_back.xy) * g_ChoppyScale * g_GridLen;
|
||||
float J = (1.0f + Dx.x) * (1.0f + Dy.y) - Dx.y * Dy.x;
|
||||
|
||||
// Practical subsurface scale calculation: max[0, (1 - J) + Amplitude * (2 * Coverage - 1)].
|
||||
float fold = max(1.0f - J, 0);
|
||||
|
||||
// Output
|
||||
return float4(gradient, 0, fold);
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
#include "oceanWaveGenHF.hlsli"
|
||||
#include "fullScreenTriangleHF.hlsli"
|
||||
|
||||
VS_QUAD_OUTPUT main(float4 vPos : POSITION)
|
||||
VS_QUAD_OUTPUT main(uint vI : SV_VertexID)
|
||||
{
|
||||
VS_QUAD_OUTPUT Output;
|
||||
VS_QUAD_OUTPUT Out;
|
||||
|
||||
Output.Position = vPos;
|
||||
Output.TexCoord.x = 0.5f + vPos.x * 0.5f;
|
||||
Output.TexCoord.y = 0.5f - vPos.y * 0.5f;
|
||||
FullScreenTriangle(vI, Out.Position, Out.TexCoord);
|
||||
|
||||
return Output;
|
||||
return Out;
|
||||
}
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
#ifndef _OCEAN_SURFACE_HF_
|
||||
#define _OCEAN_SURFACE_HF_
|
||||
#include "globals.hlsli"
|
||||
#include "ShaderInterop_Ocean.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global variables
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define PATCH_BLEND_BEGIN 800
|
||||
#define PATCH_BLEND_END 20000
|
||||
#define PATCH_BLEND_BEGIN 100
|
||||
#define PATCH_BLEND_END 2000
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
// Texture & Samplers
|
||||
//-----------------------------------------------------------------------------------
|
||||
#define g_texDisplacement texture_0 // FFT wave displacement map in VS
|
||||
#define g_texPerlin texture_1 // FFT wave gradient map in PS
|
||||
#define g_texGradient texture_2 // Perlin wave displacement & gradient map in both VS & PS
|
||||
TEXTURE1D(g_texFresnel, float4, TEXSLOT_ONDEMAND3); // Fresnel factor lookup table
|
||||
#define g_texReflectCube texture_env_global
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: OceanSurfVS
|
||||
// Type: Vertex shader
|
||||
// Desc: Ocean shading vertex shader. Check SDK document for more details
|
||||
//-----------------------------------------------------------------------------
|
||||
struct VS_OUTPUT
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "oceanWaveGenHF.hlsli"
|
||||
|
||||
STRUCTUREDBUFFER(g_InputDxyz, float2, TEXSLOT_ONDEMAND0);
|
||||
RWTEXTURE2D(output, float4, 0);
|
||||
|
||||
[numthreads(32, 32, 1)]
|
||||
void main(uint3 DTid : SV_DispatchThreadID)
|
||||
{
|
||||
uint addr = g_OutWidth * DTid.y + DTid.x;
|
||||
|
||||
// cos(pi * (m1 + m2))
|
||||
int sign_correction = ((DTid.x + DTid.y) & 1) ? -1 : 1;
|
||||
|
||||
float dx = g_InputDxyz[addr + g_DtxAddressOffset].x * sign_correction * g_ChoppyScale;
|
||||
float dy = g_InputDxyz[addr + g_DtyAddressOffset].x * sign_correction * g_ChoppyScale;
|
||||
float dz = g_InputDxyz[addr].x * sign_correction;
|
||||
|
||||
output[DTid.xy] = float4(dx, dy, dz, 1);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "oceanWaveGenHF.hlsli"
|
||||
|
||||
// Post-FFT data wrap up: Dx, Dy, Dz -> Displacement
|
||||
float4 main(VS_QUAD_OUTPUT In) : SV_Target
|
||||
{
|
||||
uint index_x = (uint)(In.TexCoord.x * (float)g_OutWidth);
|
||||
uint index_y = (uint)(In.TexCoord.y * (float)g_OutHeight);
|
||||
uint addr = g_OutWidth * index_y + index_x;
|
||||
|
||||
// cos(pi * (m1 + m2))
|
||||
int sign_correction = ((index_x + index_y) & 1) ? -1 : 1;
|
||||
|
||||
float dx = g_InputDxyz[addr + g_DtxAddressOffset].x * sign_correction * g_ChoppyScale;
|
||||
float dy = g_InputDxyz[addr + g_DtyAddressOffset].x * sign_correction * g_ChoppyScale;
|
||||
float dz = g_InputDxyz[addr].x * sign_correction;
|
||||
|
||||
return float4(dx, dy, dz, 1);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "oceanWaveGenHF.hlsli"
|
||||
|
||||
#define xDisplacementMap texture_0
|
||||
RWTEXTURE2D(output, float4, 0);
|
||||
|
||||
[numthreads(32, 32, 1)]
|
||||
void main( uint3 DTid : SV_DispatchThreadID )
|
||||
{
|
||||
// Sample neighbour texels
|
||||
float2 one_texel = float2(1.0f / (float)g_OutWidth, 1.0f / (float)g_OutHeight);
|
||||
|
||||
float2 uv = (float2)DTid.xy / float2(g_OutWidth, g_OutHeight);
|
||||
|
||||
float2 tc_left = float2(uv.x - one_texel.x, uv.y);
|
||||
float2 tc_right = float2(uv.x + one_texel.x, uv.y);
|
||||
float2 tc_back = float2(uv.x, uv.y - one_texel.y);
|
||||
float2 tc_front = float2(uv.x, uv.y + one_texel.y);
|
||||
|
||||
float3 displace_left = xDisplacementMap.SampleLevel(sampler_linear_clamp, tc_left, 0).xyz;
|
||||
float3 displace_right = xDisplacementMap.SampleLevel(sampler_linear_clamp, tc_right, 0).xyz;
|
||||
float3 displace_back = xDisplacementMap.SampleLevel(sampler_linear_clamp, tc_back, 0).xyz;
|
||||
float3 displace_front = xDisplacementMap.SampleLevel(sampler_linear_clamp, tc_front, 0).xyz;
|
||||
|
||||
// Do not store the actual normal value. Using gradient instead, which preserves two differential values.
|
||||
float2 gradient = { -(displace_right.z - displace_left.z), -(displace_front.z - displace_back.z) };
|
||||
|
||||
|
||||
// Calculate Jacobian corelation from the partial differential of height field
|
||||
float2 Dx = (displace_right.xy - displace_left.xy) * g_ChoppyScale * g_GridLen;
|
||||
float2 Dy = (displace_front.xy - displace_back.xy) * g_ChoppyScale * g_GridLen;
|
||||
float J = (1.0f + Dx.x) * (1.0f + Dy.y) - Dx.y * Dy.x;
|
||||
|
||||
// Practical subsurface scale calculation: max[0, (1 - J) + Amplitude * (2 * Coverage - 1)].
|
||||
float fold = max(1.0f - J, 0);
|
||||
|
||||
// Output
|
||||
output[DTid.xy] = float4(gradient, 0, fold);
|
||||
}
|
||||
@@ -12,12 +12,10 @@ struct VS_QUAD_OUTPUT
|
||||
|
||||
//----------------------------------------- Pixel Shaders ------------------------------------------
|
||||
|
||||
// Textures and sampling states
|
||||
#define g_samplerDisplacementMap texture_0
|
||||
//// Textures and sampling states
|
||||
//#define g_samplerDisplacementMap texture_0
|
||||
//
|
||||
//SAMPLERSTATE(LinearSampler, SSLOT_ONDEMAND0);
|
||||
|
||||
SAMPLERSTATE(LinearSampler, SSLOT_ONDEMAND0);
|
||||
|
||||
// The following three should contains only real numbers. But we have only C2C FFT now.
|
||||
STRUCTUREDBUFFER(g_InputDxyz, float2, TEXSLOT_ONDEMAND0);
|
||||
|
||||
#endif // _OCEAN_SIMULATOR_HF_
|
||||
|
||||
@@ -1405,7 +1405,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo
|
||||
}
|
||||
|
||||
UINT createDeviceFlags = 0;
|
||||
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
|
||||
D3D_DRIVER_TYPE driverTypes[] =
|
||||
{
|
||||
|
||||
+24
-139
@@ -7,13 +7,11 @@ using namespace wiGraphicsTypes;
|
||||
using namespace std;
|
||||
|
||||
ComputeShader* wiOcean::m_pUpdateSpectrumCS = nullptr;
|
||||
VertexShader* wiOcean::m_pQuadVS = nullptr;
|
||||
PixelShader* wiOcean::m_pUpdateDisplacementPS = nullptr;
|
||||
PixelShader* wiOcean::m_pGenGradientFoldingPS = nullptr;
|
||||
ComputeShader* wiOcean::m_pUpdateDisplacementMapCS = nullptr;
|
||||
ComputeShader* wiOcean::m_pUpdateGradientFoldingCS = nullptr;
|
||||
VertexShader* wiOcean::g_pOceanSurfVS = nullptr;
|
||||
PixelShader* wiOcean::g_pWireframePS = nullptr;
|
||||
PixelShader* wiOcean::g_pOceanSurfPS = nullptr;
|
||||
VertexLayout* wiOcean::m_pQuadLayout = nullptr;
|
||||
VertexLayout* wiOcean::g_pMeshLayout = nullptr;
|
||||
|
||||
// Disable warning "conditional expression is constant"
|
||||
@@ -112,7 +110,7 @@ void createTextureAndViews(UINT width, UINT height, FORMAT format, Texture2D** p
|
||||
tex_desc.SampleDesc.Count = 1;
|
||||
tex_desc.SampleDesc.Quality = 0;
|
||||
tex_desc.Usage = USAGE_DEFAULT;
|
||||
tex_desc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET;
|
||||
tex_desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS | BIND_RENDER_TARGET;
|
||||
tex_desc.CPUAccessFlags = 0;
|
||||
tex_desc.MiscFlags = RESOURCE_MISC_GENERATE_MIPS;
|
||||
|
||||
@@ -197,46 +195,6 @@ wiOcean::wiOcean(const wiOceanParameter& params)
|
||||
createTextureAndViews(hmap_dim, hmap_dim, FORMAT_R32G32B32A32_FLOAT, &m_pDisplacementMap);
|
||||
createTextureAndViews(hmap_dim, hmap_dim, FORMAT_R16G16B16A16_FLOAT, &m_pGradientMap);
|
||||
|
||||
// Samplers
|
||||
SamplerDesc sam_desc;
|
||||
sam_desc.Filter = FILTER_MIN_MAG_LINEAR_MIP_POINT;
|
||||
sam_desc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
sam_desc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
sam_desc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
sam_desc.MipLODBias = 0;
|
||||
sam_desc.MaxAnisotropy = 1;
|
||||
sam_desc.ComparisonFunc = COMPARISON_NEVER;
|
||||
sam_desc.BorderColor[0] = 1.0f;
|
||||
sam_desc.BorderColor[1] = 1.0f;
|
||||
sam_desc.BorderColor[2] = 1.0f;
|
||||
sam_desc.BorderColor[3] = 1.0f;
|
||||
sam_desc.MinLOD = -FLT_MAX;
|
||||
sam_desc.MaxLOD = FLT_MAX;
|
||||
wiRenderer::GetDevice()->CreateSamplerState(&sam_desc, &m_pPointSamplerState);
|
||||
|
||||
|
||||
// Quad vertex buffer
|
||||
GPUBufferDesc vb_desc;
|
||||
vb_desc.ByteWidth = 4 * sizeof(XMFLOAT4);
|
||||
vb_desc.Usage = USAGE_IMMUTABLE;
|
||||
vb_desc.BindFlags = BIND_VERTEX_BUFFER;
|
||||
vb_desc.CPUAccessFlags = 0;
|
||||
vb_desc.MiscFlags = 0;
|
||||
|
||||
float quad_verts[] =
|
||||
{
|
||||
-1, -1, 0, 1,
|
||||
-1, 1, 0, 1,
|
||||
1, -1, 0, 1,
|
||||
1, 1, 0, 1,
|
||||
};
|
||||
SubresourceData init_data;
|
||||
init_data.pSysMem = &quad_verts[0];
|
||||
init_data.SysMemPitch = 0;
|
||||
init_data.SysMemSlicePitch = 0;
|
||||
|
||||
m_pQuadVB = new GPUBuffer;
|
||||
wiRenderer::GetDevice()->CreateBuffer(&vb_desc, &init_data, m_pQuadVB);
|
||||
|
||||
// Constant buffers
|
||||
UINT actual_dim = m_param.dmap_dim;
|
||||
@@ -282,8 +240,6 @@ wiOcean::~wiOcean()
|
||||
SAFE_DELETE(m_pBuffer_Float2_Ht);
|
||||
SAFE_DELETE(m_pBuffer_Float_Dxyz);
|
||||
|
||||
SAFE_DELETE(m_pQuadVB);
|
||||
|
||||
SAFE_DELETE(m_pDisplacementMap);
|
||||
SAFE_DELETE(m_pGradientMap);
|
||||
|
||||
@@ -356,7 +312,6 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
|
||||
device->EventBegin("OceanSimulator", threadID);
|
||||
|
||||
// ---------------------------- H(0) -> H(t), D(x, t), D(y, t) --------------------------------
|
||||
// Compute shader
|
||||
device->BindCS(m_pUpdateSpectrumCS, threadID);
|
||||
|
||||
// Buffers
|
||||
@@ -383,13 +338,6 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
|
||||
UINT group_count_y = (m_param.dmap_dim + BLOCK_SIZE_Y - 1) / BLOCK_SIZE_Y;
|
||||
device->Dispatch(group_count_x, group_count_y, 1, threadID);
|
||||
|
||||
//// Unbind resources for CS
|
||||
//cs0_uavs[0] = NULL;
|
||||
//m_pd3dImmediateContext->CSSetUnorderedAccessViews(0, 1, cs0_uavs, (UINT*)(&cs0_uavs[0]));
|
||||
//cs0_srvs[0] = NULL;
|
||||
//cs0_srvs[1] = NULL;
|
||||
//m_pd3dImmediateContext->CSSetShaderResources(0, 2, cs0_srvs);
|
||||
|
||||
device->UnBindUnorderedAccessResources(0, 1, threadID);
|
||||
device->UnBindResources(TEXSLOT_ONDEMAND0, 2, threadID);
|
||||
|
||||
@@ -397,80 +345,34 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
|
||||
// ------------------------------------ Perform FFT -------------------------------------------
|
||||
fft_512x512_c2c(&m_fft_plan, m_pBuffer_Float_Dxyz, m_pBuffer_Float_Dxyz, m_pBuffer_Float2_Ht, threadID);
|
||||
|
||||
// --------------------------------- Wrap Dx, Dy and Dz ---------------------------------------
|
||||
// Push RT
|
||||
//ID3D11RenderTargetView* old_target;
|
||||
//ID3D11DepthStencilView* old_depth;
|
||||
//m_pd3dImmediateContext->OMGetRenderTargets(1, &old_target, &old_depth);
|
||||
//VIEWPORT old_viewport;
|
||||
//UINT num_viewport = 1;
|
||||
//m_pd3dImmediateContext->RSGetViewports(&num_viewport, &old_viewport);
|
||||
|
||||
ViewPort new_vp;
|
||||
new_vp.TopLeftX = 0;
|
||||
new_vp.TopLeftX = 0;
|
||||
new_vp.Width = (float)m_param.dmap_dim;
|
||||
new_vp.Height = (float)m_param.dmap_dim;
|
||||
new_vp.MinDepth = 0.0f;
|
||||
new_vp.MaxDepth = 1.0f;
|
||||
device->BindViewports(1, &new_vp, threadID);
|
||||
|
||||
// Set RT
|
||||
device->BindRenderTargets(1, (Texture**)&m_pDisplacementMap, nullptr, threadID);
|
||||
device->BindConstantBufferCS(m_pImmutableCB, CB_GETBINDSLOT(Ocean_Simulation_ImmutableCB), threadID);
|
||||
device->BindConstantBufferCS(m_pPerFrameCB, CB_GETBINDSLOT(Ocean_Simulation_PerFrameCB), threadID);
|
||||
|
||||
// VS & PS
|
||||
device->BindVS(m_pQuadVS, threadID);
|
||||
device->BindPS(m_pUpdateDisplacementPS, threadID);
|
||||
|
||||
device->BindConstantBufferPS(m_pImmutableCB, CB_GETBINDSLOT(Ocean_Simulation_ImmutableCB), threadID);
|
||||
device->BindConstantBufferPS(m_pPerFrameCB, CB_GETBINDSLOT(Ocean_Simulation_PerFrameCB), threadID);
|
||||
// Update displacement map:
|
||||
device->BindCS(m_pUpdateDisplacementMapCS, threadID);
|
||||
GPUUnorderedResource* cs_uavs[] = { m_pDisplacementMap };
|
||||
device->BindUnorderedAccessResourcesCS(cs_uavs, 0, 1, threadID);
|
||||
GPUResource* cs_srvs[1] = { m_pBuffer_Float_Dxyz };
|
||||
device->BindResourcesCS(cs_srvs, TEXSLOT_ONDEMAND0, 1, threadID);
|
||||
device->Dispatch(m_param.dmap_dim / 32, m_param.dmap_dim / 32, 1, threadID);
|
||||
|
||||
// Buffer resources
|
||||
GPUResource* ps_srvs[1] = { m_pBuffer_Float_Dxyz };
|
||||
device->BindResourcesPS(ps_srvs, TEXSLOT_ONDEMAND0, 1, threadID);
|
||||
|
||||
// IA setup
|
||||
GPUBuffer* vbs[1] = { m_pQuadVB };
|
||||
UINT strides[1] = { sizeof(XMFLOAT4) };
|
||||
UINT offsets[1] = { 0 };
|
||||
device->BindVertexBuffers(&vbs[0], 0, 1, &strides[0], &offsets[0], threadID);
|
||||
|
||||
device->BindVertexLayout(m_pQuadLayout, threadID);
|
||||
device->BindPrimitiveTopology(TRIANGLESTRIP, threadID);
|
||||
|
||||
// Perform draw call
|
||||
device->Draw(4, 0, threadID);
|
||||
// Update gradient map:
|
||||
device->BindCS(m_pUpdateGradientFoldingCS, threadID);
|
||||
cs_uavs[0] = { m_pGradientMap };
|
||||
device->BindUnorderedAccessResourcesCS(cs_uavs, 0, 1, threadID);
|
||||
cs_srvs[0] = m_pDisplacementMap;
|
||||
device->BindResourcesCS(cs_srvs, TEXSLOT_ONDEMAND0, 1, threadID);
|
||||
device->Dispatch(m_param.dmap_dim / 32, m_param.dmap_dim / 32, 1, threadID);
|
||||
|
||||
// Unbind
|
||||
device->UnBindUnorderedAccessResources(0, 1, threadID);
|
||||
device->UnBindResources(TEXSLOT_ONDEMAND0, 1, threadID);
|
||||
|
||||
|
||||
// ----------------------------------- Generate Normal ----------------------------------------
|
||||
// Set RT
|
||||
device->BindRenderTargets(1, (Texture**)&m_pGradientMap, nullptr, threadID);
|
||||
|
||||
// VS & PS
|
||||
device->BindVS(m_pQuadVS, threadID);
|
||||
device->BindPS(m_pGenGradientFoldingPS, threadID);
|
||||
|
||||
// Texture resource and sampler
|
||||
ps_srvs[0] = m_pDisplacementMap;
|
||||
device->BindResourcesPS(ps_srvs, TEXSLOT_ONDEMAND0, 1, threadID);
|
||||
|
||||
device->BindSamplerPS(&m_pPointSamplerState, SSLOT_ONDEMAND0, threadID);
|
||||
|
||||
// Perform draw call
|
||||
device->Draw(4, 0, threadID);
|
||||
|
||||
// Unbind
|
||||
device->UnBindResources(TEXSLOT_ONDEMAND0, 1, threadID);
|
||||
|
||||
//// Pop RT
|
||||
//m_pd3dImmediateContext->RSSetViewports(1, &old_viewport);
|
||||
//m_pd3dImmediateContext->OMSetRenderTargets(1, &old_target, old_depth);
|
||||
//SAFE_DELETE(old_target);
|
||||
//SAFE_DELETE(old_depth);
|
||||
|
||||
device->GenerateMips(m_pGradientMap, threadID);
|
||||
|
||||
|
||||
@@ -1403,22 +1305,8 @@ void wiOcean::LoadShaders()
|
||||
{
|
||||
|
||||
m_pUpdateSpectrumCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanSimulatorCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
|
||||
{
|
||||
VertexLayoutDesc layout[] =
|
||||
{
|
||||
{ "POSITION", 0, FORMAT_R32G32B32A32_FLOAT, 0, 0, INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
UINT numElements = ARRAYSIZE(layout);
|
||||
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanQuadVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
|
||||
if (vsinfo != nullptr) {
|
||||
m_pQuadVS = vsinfo->vertexShader;
|
||||
m_pQuadLayout = vsinfo->vertexLayout;
|
||||
}
|
||||
}
|
||||
|
||||
m_pUpdateDisplacementPS = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanUpdateDisplacementPS.cso", wiResourceManager::PIXELSHADER));
|
||||
m_pGenGradientFoldingPS = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanGradientFoldingPS.cso", wiResourceManager::PIXELSHADER));
|
||||
m_pUpdateDisplacementMapCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanUpdateDisplacementMapCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
m_pUpdateGradientFoldingCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "oceanUpdateGradientFoldingCS.cso", wiResourceManager::COMPUTESHADER));
|
||||
|
||||
|
||||
{
|
||||
@@ -1448,11 +1336,8 @@ void wiOcean::SetUpStatic()
|
||||
void wiOcean::CleanUpStatic()
|
||||
{
|
||||
SAFE_DELETE(m_pUpdateSpectrumCS);
|
||||
SAFE_DELETE(m_pQuadVS);
|
||||
SAFE_DELETE(m_pUpdateDisplacementPS);
|
||||
SAFE_DELETE(m_pGenGradientFoldingPS);
|
||||
|
||||
SAFE_DELETE(m_pQuadLayout);
|
||||
SAFE_DELETE(m_pUpdateDisplacementMapCS);
|
||||
SAFE_DELETE(m_pUpdateGradientFoldingCS);
|
||||
|
||||
SAFE_DELETE(g_pMeshLayout);
|
||||
|
||||
|
||||
@@ -93,21 +93,14 @@ protected:
|
||||
// Height & choppy buffer in the space domain, corresponding to H(t), Dx(t) and Dy(t)
|
||||
wiGraphicsTypes::GPUBuffer* m_pBuffer_Float_Dxyz;
|
||||
|
||||
wiGraphicsTypes::GPUBuffer* m_pQuadVB;
|
||||
|
||||
// Shaders, layouts and constants
|
||||
static wiGraphicsTypes::ComputeShader* m_pUpdateSpectrumCS;
|
||||
static wiGraphicsTypes::VertexShader* m_pQuadVS;
|
||||
static wiGraphicsTypes::PixelShader* m_pUpdateDisplacementPS;
|
||||
static wiGraphicsTypes::PixelShader* m_pGenGradientFoldingPS;
|
||||
|
||||
static wiGraphicsTypes::VertexLayout* m_pQuadLayout;
|
||||
static wiGraphicsTypes::ComputeShader* m_pUpdateDisplacementMapCS;
|
||||
static wiGraphicsTypes::ComputeShader* m_pUpdateGradientFoldingCS;
|
||||
|
||||
wiGraphicsTypes::GPUBuffer* m_pImmutableCB;
|
||||
wiGraphicsTypes::GPUBuffer* m_pPerFrameCB;
|
||||
|
||||
wiGraphicsTypes::Sampler m_pPointSamplerState;
|
||||
|
||||
// FFT wrap-up
|
||||
CSFFT512x512_Plan m_fft_plan;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user