浏览代码

Fix and improve shadows on the water (#130)

/main
GitHub 3 年前
当前提交
a7e98a33
共有 2 个文件被更改,包括 22 次插入15 次删除
  1. 26
      Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl
  2. 11
      Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl

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


IN.normal += half3(1-waterFX.y, 0.5h, 1-waterFX.z) - 0.5;
IN.normal = normalize(IN.normal);
// Distortion
half2 distortion = DistortionUVs(depth.x, IN.normal);
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.normal, IN.viewDir.xyz);
//return fresnelTerm.xxxx;
half shadow = SoftShadows(screenUV, IN.posWS);
half shadow = SoftShadows(screenUV, IN.posWS, IN.viewDir.xyz, depth.x);
half3 GI = SampleSH(IN.normal);
// SSS

half foamMask = saturate(length(foamMap * foamBlend) * 1.5 - 0.1);
// Foam lighting
half3 foam = foamMask.xxx * (mainLight.shadowAttenuation * mainLight.color + GI);
// Distortion
half2 distortion = DistortionUVs(depth.x, IN.normal);
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.normal, IN.viewDir.xyz);
//return fresnelTerm.xxxx;
BRDFData brdfData;
half alpha = 1;

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


}
//Soft Shadows
half SoftShadows(float3 screenUV, float3 positionWS)
half SoftShadows(float3 screenUV, float3 positionWS, half3 viewDir, half depth)
#if _MAIN_LIGHT_SHADOWS
half depthFrac = depth * loopDiv;
half3 lightOffset = -viewDir * depthFrac;
for (uint i = 0u; i < SHADOW_ITERATIONS; ++i)
{
#ifndef _STATIC_WATER

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
}
///////////////////////////////////////////////////////////////////////////////

正在加载...
取消
保存