From 9caf25a52996c6c62fc39f10784d8951f715b05d Mon Sep 17 00:00:00 2001 From: turanszkij Date: Tue, 14 Nov 2017 16:02:15 +0000 Subject: [PATCH] ocean update --- WickedEngine/ShaderInterop_Ocean.h | 7 +++---- WickedEngine/oceanSurfacePS.hlsl | 10 +++++----- WickedEngine/oceanSurfaceVS.hlsl | 4 ++-- WickedEngine/wiOcean.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/WickedEngine/ShaderInterop_Ocean.h b/WickedEngine/ShaderInterop_Ocean.h index 9e4c1f97a..37bc4c326 100644 --- a/WickedEngine/ShaderInterop_Ocean.h +++ b/WickedEngine/ShaderInterop_Ocean.h @@ -31,14 +31,13 @@ CBUFFER(Ocean_Simulation_PerFrameCB, CBSLOT_OTHER_OCEAN_SIMULATION_PERFRAME) CBUFFER(Ocean_RenderCB, CBSLOT_OTHER_OCEAN_RENDER) { - float3 xOceanWaterColor; - float xOceanTexelLengthMul2; - float4 xOceanTexMulAdd; + float xOceanTexelLength; float4 xOceanScreenSpaceParams; + float xOceanPatchSizeRecip; + float xOceanMapHalfTexel; float xOceanWaterHeight; float xOceanSurfaceDisplacementTolerance; - float2 xOcean_padding; }; #endif // _SHADERINTEROP_OCEAN_H_ diff --git a/WickedEngine/oceanSurfacePS.hlsl b/WickedEngine/oceanSurfacePS.hlsl index 7d92d4b03..305f8681d 100644 --- a/WickedEngine/oceanSurfacePS.hlsl +++ b/WickedEngine/oceanSurfacePS.hlsl @@ -6,10 +6,10 @@ #define xGradientMap texture_0 [earlydepthstencil] -GBUFFEROutputType_Thin main(PSIn input) +float4 main(PSIn input) : SV_TARGET { float2 gradient = xGradientMap.Sample(sampler_aniso_wrap, input.uv).xy; - float3 N = normalize(float3(gradient.x, 1, gradient.y)); + float3 N = normalize(float3(gradient.x, xOceanTexelLength * 2, gradient.y)); float4 baseColor = float4(xOceanWaterColor, 1); float opacity = 1; // keep edge diffuse shading @@ -41,10 +41,10 @@ GBUFFEROutputType_Thin main(PSIn input) //REFLECTION float2 RefTex = float2(1, -1)*input.ReflectionMapSamplingPos.xy / input.ReflectionMapSamplingPos.w / 2.0f + 0.5f; - float4 reflectiveColor = xReflection.SampleLevel(sampler_linear_mirror, RefTex + N.xz, 0); + float4 reflectiveColor = xReflection.SampleLevel(sampler_linear_mirror, RefTex + N.xz * 0.04f, 0); //REFRACTION - float2 perturbatedRefrTexCoords = ScreenCoord.xy + N.xz; + float2 perturbatedRefrTexCoords = ScreenCoord.xy + N.xz * 0.04f; float refDepth = (texture_lineardepth.Sample(sampler_linear_mirror, ScreenCoord)); float3 refractiveColor = xRefraction.SampleLevel(sampler_linear_mirror, perturbatedRefrTexCoords, 0).rgb; float NdotV = abs(dot(N, V)) + 1e-5f; @@ -69,7 +69,7 @@ GBUFFEROutputType_Thin main(PSIn input) OBJECT_PS_FOG - OBJECT_PS_OUT_FORWARD + OBJECT_PS_OUT_FORWARD_SIMPLE } diff --git a/WickedEngine/oceanSurfaceVS.hlsl b/WickedEngine/oceanSurfaceVS.hlsl index d7f51ee7b..96b35a077 100644 --- a/WickedEngine/oceanSurfaceVS.hlsl +++ b/WickedEngine/oceanSurfaceVS.hlsl @@ -50,8 +50,8 @@ PSIn main(uint fakeIndex : SV_VERTEXID) float3 worldPos = intersectPlaneClampInfinite(o, d, float3(0, 1, 0), xOceanWaterHeight); // Displace surface: - float2 uv = worldPos.xz * xOceanTexMulAdd.xy + xOceanTexMulAdd.zw; - float3 displacement = xDisplacementMap.SampleLevel(sampler_point_wrap, uv, 0).xyz; + float2 uv = worldPos.xz * xOceanPatchSizeRecip; + float3 displacement = xDisplacementMap.SampleLevel(sampler_point_wrap, uv + xOceanMapHalfTexel, 0).xyz; worldPos.xzy += displacement.xyz; // Reproject displaced surface and output: diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index ffdc4119f..3f7e5ec32 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -333,6 +333,7 @@ void wiOcean::Render(const Camera* camera, float time, GRAPHICSTHREAD threadID) device->BindRasterizerState(wire ? wireRS : rasterizerState, threadID); device->BindDepthStencilState(depthStencilState, 0, threadID); + device->BindBlendState(blendState, threadID); @@ -340,9 +341,10 @@ void wiOcean::Render(const Camera* camera, float time, GRAPHICSTHREAD threadID) Ocean_RenderCB cb; cb.xOceanWaterColor = waterColor; - cb.xOceanTexMulAdd = XMFLOAT4(1.0f / m_param.patch_length, 1.0f / m_param.patch_length, 0.5f / m_param.dmap_dim, 0.5f / m_param.dmap_dim); - cb.xOceanTexelLengthMul2 = m_param.patch_length / m_param.dmap_dim * 2; + cb.xOceanTexelLength = m_param.patch_length / m_param.dmap_dim; cb.xOceanScreenSpaceParams = XMFLOAT4((float)dim.x, (float)dim.y, 1.0f / (float)dim.x, 1.0f / (float)dim.y); + cb.xOceanPatchSizeRecip = 1.0f / m_param.patch_length; + cb.xOceanMapHalfTexel = 0.5f / m_param.dmap_dim; cb.xOceanWaterHeight = waterHeight; cb.xOceanSurfaceDisplacementTolerance = max(1, surfaceDisplacementTolerance);