浏览代码

Squashed commit of the following:

commit 4b92a5e6dcb7b9b9386283a4d0d19fd5a3b22633
Author: Andre McGrail <andrem@unity3d.com>
Date:   Wed Dec 2 15:50:55 2020 +0100

    Fix and improve shadows on the water (#130)

commit 88679d7ebeeae4be30f43ebe88cba830f363803b
Author: Andre McGrail <andrem@unity3d.com>
Date:   Mon Nov 23 11:27:01 2020 +0100

    Removed variable 'loop' as itwas causing issues for PS4 compiling (#129)

commit 60b6bc595f20b29f4869d3236ce1aa91a490ef6b
Author: Andre McGrail <andrem@unity3d.com>
Date:   Mon Nov 9 17:32:00 2020 +0100

    Update README.md

commit 87dc01efaab4c7911d5af79355707930b4b4b00b
Author: Andre McGrail <andrem@unity3d.com>
Date:   Mon Nov 9 17:27:13 2020 +0100

    Update README.md

commit 35e7524eded7d0d639332bfb4a17547481aaa91d
Author: Andre McGrail <andrem@unity3d.com>
Date:   Mon Nov 9 17:26:53 2020 +0100

    Update README.md

commit 46718e5dc3772f43ef0b159d75e96588514a68c5
Author: Andre McGrail <andrem@unity3d.com>
Date:   Wed Nov 4 16:29:21 ...
/feature-infinite-sea
Andre McGrail 4 年前
当前提交
485253b7
共有 2 个文件被更改,包括 40 次插入24 次删除
  1. 42
      Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl
  2. 22
      Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl

42
Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl


{
// Lighting
Light mainLight = GetMainLight(TransformWorldToShadowCoord(input.positionWS));
half shadow = SoftShadows(screenUV, input.positionWS);
half shadow = SoftShadows(screenUV, input.positionWS, input.viewDirectionWS, input.depth);
half3 GI = SampleSH(input.normalWS);
// SSS

return MixFog(output, input.fogCoord);
}
float WaterNearFade(float3 positionWS)
{
float3 camPos = GetCameraPositionWS();
camPos.y = 0;
return 1 - saturate((distance(positionWS, camPos) - 50) * 1);
}
///////////////////////////////////////////////////////////////////////////////
// Vertex and Fragment functions //
///////////////////////////////////////////////////////////////////////////////

InitializeSurfaceData(inputData, surfaceData);
half4 current;
current.a = 1;
current.a = WaterNearFade(IN.positionWS);
//return color;
return current;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

// Detail waves
DetailNormals(IN.normalWS, IN.uv, waterFX, depth.x);
// Distortion
half2 distortion = DistortionUVs(depth.x, IN.normalWS);
distortion = screenUV.xy + distortion;// * clamp(depth.x, 0, 5);
float d = depth.x;
depth.xz = AdjustedDepth(distortion, IN.additionalData);
distortion = depth.x < 0 ? screenUV.xy : distortion;
depth.x = depth.x < 0 ? d : depth.x;
// Fresnel
half fresnelTerm = CalculateFresnelTerm(IN.normalWS, IN.viewDirectionWS.xyz);
//return fresnelTerm.xxxx;
half shadow = SoftShadows(screenUV.xy, IN.positionWS);
half shadow = SoftShadows(screenUV, IN.positionWS, IN.viewDirectionWS.xyz, depth.x);
half3 GI = SampleSH(IN.normalWS);
// SSS

// Foam lighting
half3 foam = foamMask.xxx * (mainLight.shadowAttenuation * mainLight.color + GI);
// Distortion
half2 distortion = DistortionUVs(depth.x, IN.normalWS);
distortion = screenUV.xy + distortion;// * clamp(depth.x, 0, 5);
float d = depth.x;
depth.xz = AdjustedDepth(distortion, IN.additionalData); // only x y
distortion = depth.x < 0 ? screenUV.xy : distortion;
depth.x = depth.x < 0 ? d : depth.x;
// Fresnel
half fresnelTerm = CalculateFresnelTerm(IN.normalWS, IN.viewDirectionWS.xyz);
half3 spec = DirectBDRF(brdfData, IN.normalWS, mainLight.direction, IN.viewDirectionWS.xyz) * shadow * mainLight.color;
half3 spec = DirectBDRF(brdfData, IN.normalWS, mainLight.direction, IN.viewDirectionWS) * shadow * mainLight.color;
#ifdef _ADDITIONAL_LIGHTS
uint pixelLightCount = GetAdditionalLightsCount();
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)

#endif
}
#endif // WATER_COMMON_INCLUDED
#endif // WATER_COMMON_INCLUDED

22
Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl


#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#define SHADOW_ITERATIONS 4
half CalculateFresnelTerm(half3 normalWS, half3 viewDirectionWS)
{
return saturate(pow(1.0 - dot(normalWS, viewDirectionWS), 5));//fresnel TODO - find a better place

}
//Soft Shadows
half SoftShadows(float2 screenUV, float3 positionWS)
half SoftShadows(float3 screenUV, float3 positionWS, half3 viewDir, half depth)
half2 jitterUV = screenUV * _ScreenParams.xy * _DitherPattern_TexelSize.xy;
#if _MAIN_LIGHT_SHADOWS
half2 jitterUV = screenUV.xy * _ScreenParams.xy * _DitherPattern_TexelSize.xy;
uint loop = 4;
float loopDiv = 1.0 / loop;
for (uint i = 0u; i < loop; ++i)
float loopDiv = 1.0 / SHADOW_ITERATIONS;
half depthFrac = depth * loopDiv;
half3 lightOffset = -viewDir * depthFrac;
for (uint i = 0u; i < SHADOW_ITERATIONS; ++i)
float3 lightJitter = positionWS + jitterTexture.xzy * 2;
half3 j = jitterTexture.xzy * depthFrac * i * 0.1;
float3 lightJitter = (positionWS + j) + (lightOffset * (i + jitterTexture.y));
#else
return 1;
#endif
}
///////////////////////////////////////////////////////////////////////////////

return reflection;
}
#endif // WATER_LIGHTING_INCLUDED
#endif // WATER_LIGHTING_INCLUDED
正在加载...
取消
保存