ocean update

This commit is contained in:
turanszkij
2017-11-14 16:02:15 +00:00
parent 75363c33fc
commit 9caf25a529
4 changed files with 14 additions and 13 deletions
+3 -4
View File
@@ -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_
+5 -5
View File
@@ -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
}
+2 -2
View File
@@ -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:
+4 -2
View File
@@ -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);