117 lines
4.1 KiB
Plaintext
Raw Normal View History

2026-01-28 15:51:45 +05:30
Shader "LowPolyWater/WaterShaded_Ortho_Final" {
2026-01-22 11:16:28 +05:30
Properties {
2026-01-28 15:51:45 +05:30
_BaseColor ("Base color", COLOR) = ( .54, .95, .99, 0.5)
_SpecColor ("Specular Material Color", Color) = (1,1,1,1)
2026-01-22 11:16:28 +05:30
_Shininess ("Shininess", Float) = 10
2026-01-28 15:51:45 +05:30
_FoamColor ("Foam Color", Color) = (1,1,1,1)
_ShoreTex ("Shore & Foam texture ", 2D) = "black" {}
_InvFadeParemeter ("Shore Thickness (X), Foam Spread (Y)", Vector) = (5.0 ,2.0, 0.5, 1.0)
2026-01-22 11:16:28 +05:30
2026-01-28 15:51:45 +05:30
_BumpTiling ("Foam Tiling", Vector) = (1.0 ,1.0, -2.0, 3.0)
_BumpDirection ("Foam movement", Vector) = (1.0 ,1.0, -1.0, 1.0)
2026-01-22 11:16:28 +05:30
2026-01-28 15:51:45 +05:30
_Foam ("Foam (intensity, cutoff)", Vector) = (0.5, 0.375, 0.0, 0.0)
[MaterialToggle] _isInnerAlphaBlendOrColor("Fade inner to color or alpha?", Float) = 0
2026-01-22 11:16:28 +05:30
}
2026-01-28 15:51:45 +05:30
Subshader {
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
Lod 500
2026-01-22 11:16:28 +05:30
2026-01-28 15:51:45 +05:30
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ZTest LEqual
ZWrite Off
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile WATER_EDGEBLEND_ON WATER_EDGEBLEND_OFF
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _ShoreTex;
sampler2D_float _CameraDepthTexture;
float4 _BaseColor;
float4 _FoamColor;
float _SpecColor;
float _Shininess;
float4 _InvFadeParemeter;
float4 _BumpTiling;
float4 _BumpDirection;
float4 _Foam;
float _isInnerAlphaBlendOrColor;
struct v2f {
float4 pos : SV_POSITION;
float4 screenPos : TEXCOORD3;
float4 bumpCoords : TEXCOORD4;
float3 worldPos : TEXCOORD5;
float3 worldNormal : TEXCOORD6;
UNITY_FOG_COORDS(7)
};
v2f vert(appdata_full v) {
v2f o;
// The vertex position here will include any changes made by your C# script
// if you are modifying the mesh filter's vertices.
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.pos);
COMPUTE_EYEDEPTH(o.screenPos.z);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.bumpCoords.xyzw = (o.worldPos.xzxz + _Time.xxxx * _BumpDirection.xyzw) * _BumpTiling.xyzw;
UNITY_TRANSFER_FOG(o, o.pos);
return o;
}
half4 frag(v2f i) : SV_Target {
// 1. Calculate Depth for Ortho
float rawDepth = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos));
float sceneZ = LinearEyeDepth(rawDepth);
float waterZ = i.screenPos.z;
float diff = sceneZ - waterZ;
// 2. Foam Factors
// edgeFactor is the solid line. foamFactor is the textured area.
float edgeFactor = saturate(_InvFadeParemeter.x * diff);
float foamFactor = saturate(_InvFadeParemeter.y * diff);
// 3. Lighting
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
float diffExp = max(0.1, dot(i.worldNormal, lightDir)); // Simple wrap lighting
float4 finalCol = float4(_BaseColor.rgb * diffExp, _BaseColor.a);
// 4. Foam Texturing
float4 foamTex = (tex2D(_ShoreTex, i.bumpCoords.xy) * tex2D(_ShoreTex, i.bumpCoords.zw));
// Add the "Shore Line" using the Foam Color (White by default)
float shoreStrength = (1.0 - edgeFactor);
finalCol.rgb = lerp(finalCol.rgb, _FoamColor.rgb, shoreStrength);
// Add the "Foam Bubbles" texture near the edges
float texturedFoam = foamTex.r * (1.0 - foamFactor) * _Foam.x;
finalCol.rgb += _FoamColor.rgb * texturedFoam;
// 5. Alpha handling
if(_isInnerAlphaBlendOrColor > 0) {
finalCol.a = edgeFactor;
2026-01-22 11:16:28 +05:30
}
2026-01-28 15:51:45 +05:30
UNITY_APPLY_FOG(i.fogCoord, finalCol);
return finalCol;
}
ENDCG
}
2026-01-22 11:16:28 +05:30
}
Fallback "Transparent/Diffuse"
2026-01-28 15:51:45 +05:30
}