|
|
|
|
|
|
void InitializeInputData(Varyings input, out WaterInputData inputData, float2 screenUV) |
|
|
|
{ |
|
|
|
float3 depth = WaterDepth(input.positionWS, input.additionalData, screenUV);// TODO - hardcoded shore depth UVs |
|
|
|
// Sample water FX texture |
|
|
|
inputData.waterFX = WaterFX(input.preWaveSP.xy); |
|
|
|
|
|
|
|
// Detail waves |
|
|
|
DetailNormals(inputData.normalWS, input.uv, inputData.waterFX, depth); |
|
|
|
|
|
|
|
inputData.reflectionUV = 0; |
|
|
|
|
|
|
|
half2 distortion = DistortionUVs(depth.x, inputData.normalWS); |
|
|
|
distortion = screenUV.xy + distortion;// * clamp(depth.x, 0, 5); |
|
|
|
float d = depth.x; |
|
|
|
depth.xz = AdjustedDepth(distortion, input.additionalData); // only x y |
|
|
|
distortion = depth.x < 0 ? screenUV.xy : distortion; |
|
|
|
inputData.refractionUV = distortion; |
|
|
|
depth.x = depth.x < 0 ? d : depth.x; |
|
|
|
// Sample water FX texture |
|
|
|
inputData.waterFX = WaterFX(input.preWaveSP.xy); |
|
|
|
|
|
|
|
inputData.depth = 0; |
|
|
|
inputData.refractionUV = DistortionUVs(inputData.depth, inputData.normalWS); |
|
|
|
inputData.depth = depth.x; |
|
|
|
inputData.reflectionUV = 0; |
|
|
|
void InitializeSurfaceData(WaterInputData input, out WaterSurfaceData surfaceData) |
|
|
|
void InitializeSurfaceData(inout WaterInputData input, out WaterSurfaceData surfaceData) |
|
|
|
// Detail waves |
|
|
|
DetailNormals(input.normalWS, input.detailUV, input.waterFX, input.depth); |
|
|
|
surfaceData.normalWS = 0; |
|
|
|
/* |
|
|
|
// Foam |
|
|
|
half3 foamMap = SAMPLE_TEXTURE2D(_FoamMap, sampler_FoamMap, IN.uv.zw).rgb; //r=thick, g=medium, b=light |
|
|
|
|
|
|
surfaceData.foam = 0; |
|
|
|
} |
|
|
|
|
|
|
|
float3 WaterShading(WaterInputData input, WaterSurfaceData surfaceData, float2 screenUV) |
|
|
|
float3 WaterShading(WaterInputData input, WaterSurfaceData surfaceData, float4 additionalData, float2 screenUV) |
|
|
|
{ |
|
|
|
// Lighting |
|
|
|
Light mainLight = GetMainLight(TransformWorldToShadowCoord(input.positionWS)); |
|
|
|
|
|
|
// SSS |
|
|
|
half3 directLighting = dot(mainLight.direction, half3(0, 1, 0)) * mainLight.color; |
|
|
|
//directLighting += saturate(pow(dot(input.viewDirectionWS.xyz, -mainLight.direction) * IN.additionalData.z, 3)) * 5 * mainLight.color; |
|
|
|
//half3 sss = directLighting * shadow + GI; |
|
|
|
directLighting += saturate(pow(dot(input.viewDirectionWS.xyz, -mainLight.direction) * additionalData.z, 3)) * 5 * mainLight.color; |
|
|
|
|
|
|
|
half3 spec = DirectBDRF(brdfData, input.normalWS, mainLight.direction, input.viewDirectionWS);// * shadow * mainLight.color; |
|
|
|
half3 spec = DirectBDRF(brdfData, input.normalWS, mainLight.direction, input.viewDirectionWS) * mainLight.color * shadow; |
|
|
|
half3 sss = 0; |
|
|
|
half3 sss = directLighting * shadow + GI; |
|
|
|
sss *= Scattering(input.depth); |
|
|
|
|
|
|
|
// Reflections |
|
|
|
|
|
|
// Do compositing |
|
|
|
half3 output = lerp(lerp(refraction, reflection, fresnelTerm) + sss + spec, surfaceData.foam, surfaceData.foamMask); |
|
|
|
|
|
|
|
//return refraction; |
|
|
|
return MixFog(output, input.fogCoord); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
WaterSurfaceData surfaceData; |
|
|
|
InitializeSurfaceData(inputData, surfaceData); |
|
|
|
|
|
|
|
half4 color; |
|
|
|
color.a = 1; |
|
|
|
color.rgb = WaterShading(inputData, surfaceData, screenUV.xy); |
|
|
|
half4 current; |
|
|
|
current.a = 1; |
|
|
|
current.rgb = WaterShading(inputData, surfaceData, IN.additionalData, screenUV.xy); |
|
|
|
|
|
|
|
//return color; |
|
|
|
|
|
|
|
|
|
|
float3 camPos = GetCameraPositionWS(); |
|
|
|
camPos.y = 0; |
|
|
|
float alpha = 1 - saturate((distance(IN.positionWS, camPos) - 50) * 1); |
|
|
|
|
|
|
|
//return half4(IN.additionalData.www, alpha); |
|
|
|
|
|
|
|
half3 old = comp; |
|
|
|
half fiftyfifty = round(screenUV.x); |
|
|
|
return half4(lerp(old, current.rgb, fiftyfifty), alpha); |
|
|
|
|
|
|
|
#if defined(_DEBUG_FOAM) |
|
|
|
return half4(foamMask.xxx, 1); |
|
|
|