Shader "BigShipTycoon/Port Scenery Surface" { Properties { _Color ("Material color", Color) = (.65,.64,.58,1) _HazeColor ("Harbor atmosphere", Color) = (.60,.63,.66,1) _Detail ("Surface finish", Float) = 0 _Glow ("Window light", Range(0,1)) = 0 } SubShader { Tags { "RenderType"="Opaque" } Cull Off Pass { CGPROGRAM #pragma target 3.0 #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "TycoonTexturing.cginc" float4 _Color, _HazeColor; float _Detail, _Glow; struct Input { float4 position : POSITION; float3 normal : NORMAL; }; struct Output { float4 screen : SV_POSITION; float3 position : TEXCOORD0; float3 normal : TEXCOORD1; }; Output vert(Input input) { Output output; output.screen = UnityObjectToClipPos(input.position); output.position = mul(unity_ObjectToWorld, input.position).xyz; output.normal = UnityObjectToWorldNormal(input.normal); return output; } float GroundNoise(float2 position) { float2 cell = floor(position); float2 blend = frac(position); blend *= blend * (3 - 2 * blend); return lerp(lerp(TycoonCell(cell), TycoonCell(cell + float2(1,0)), blend.x), lerp(TycoonCell(cell + float2(0,1)), TycoonCell(cell + 1), blend.x), blend.y); } fixed4 frag(Output input, fixed side : VFACE) : SV_Target { float3 p = input.position; float3 n = normalize(input.normal) * (side >= 0 ? 1 : -1); float3 view = normalize(_WorldSpaceCameraPos.xyz - p); float3 sun = normalize(float3(-.69,.40,-.43)); float2 face = TycoonPlane(p, n); float2 samplePosition = p.xz + p.y * float2(.42,.76); float relief = GroundNoise(samplePosition * .22) - .5; float fine = (GroundNoise(face * 1.25) - .5) * TycoonDetail2(face * 1.25); float coarse = GroundNoise(samplePosition * .071) - .5; float3 albedo = _Color.rgb * (1 + relief * .10 + fine * .075); if (_Detail == 1) { float stone = smoothstep(-.23,.29, .55 * relief + .24 * fine + .42 * coarse); albedo *= .79 + .30 * stone + coarse * .19 + TycoonStipple(face, 6.8) * .13; albedo *= lerp(.72, 1, smoothstep(-.12, 1.4, p.y)); } else if (_Detail == 2) { float tileShade; float joint = TycoonPanel(face, float2(3.5, 5.2), .5, .016, tileShade); albedo *= 1 + fine * .10 + tileShade * .22 - joint * .27; } else if (_Detail == 4) albedo *= .87 + relief * .16 + fine * .12 + coarse * .13 + TycoonStipple(face, 7.1) * .115; else if (_Detail == 5) { float board; float seam = TycoonPanel(face, float2(.40, 5.8), .39, .0032, board); albedo *= 1 + board * .21 + TycoonGrain(face, 11) * .055 - seam * .27; } else if (_Detail == 6) albedo *= 1 + TycoonStipple(face, 18) * .17 + TycoonStipple(face, 7.8) * .070; else if (_Detail == 7) albedo *= 1 + TycoonGrain(face, 33) * .105; else if (_Detail == 8) { float reeds = smoothstep(-.27,.24, coarse * .67 + relief * .51); float thatch = TycoonStipple(face + fine, 20) * .13 + TycoonGrain(face, 13) * .09; albedo = lerp(albedo * float3(.71,.84,.79), albedo * float3(1.16,1.07,.87), reeds) * (1 + fine * .20 + thatch); } float diffuse = saturate(dot(n, sun)); float sky = n.y * .5 + .5; float3 bounce = lerp(float3(.28,.32,.43),float3(.67,.71,.78),sky); float3 color = albedo * (bounce + diffuse * float3(.71,.51,.33)); if (_Detail == 3) { float reflectedSky = saturate(reflect(-view, n).y * 2 + .11); float edge = pow(1 - saturate(dot(n, view)), 2.4); float3 reflection = lerp(float3(.13,.22,.27), _HazeColor.rgb * .85, reflectedSky); color = lerp(color, reflection, (.44 + .51 * edge) * (1 - _Glow)) + _Color.rgb * _Glow; } float distance = length(_WorldSpaceCameraPos.xyz - p); float haze = smoothstep(120, 640, distance) * .87; return fixed4(TycoonHighlightRollOff(lerp(color, _HazeColor.rgb, haze)), 1); } ENDCG } } }