Shader "Soundings/Service Deck Surface" { Properties { _Color ("Finish", Color) = (1,1,1,1) _Roughness ("Roughness", Range(.02,1)) = .58 _Metal ("Metal", Range(0,1)) = 0 _Emissive ("Emission", Range(0,1)) = 0 _BayLength ("Compartment length", Float) = 6 _RoomLight ("Compartment fixture offset", Float) = 4 _DeckTread ("Deck surface", Float) = 0 } SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" fixed4 _Color; float _Roughness, _Metal, _Emissive, _BayLength, _RoomLight, _DeckTread; struct Input { float4 vertex : POSITION; float3 normal : NORMAL; }; struct Output { float4 clip : SV_POSITION; float3 local : TEXCOORD0; float3 normal : TEXCOORD1; }; Output vert(Input input) { Output output; output.clip = UnityObjectToClipPos(input.vertex); output.local = input.vertex.xyz; output.normal = input.normal; return output; } float3 fixture(float3 delta, float3 viewDirection, float3 normal, float3 tint) { float distanceSq = max(.19, dot(delta, delta)); float3 incident = delta * rsqrt(distanceSq); float diffuse = saturate(dot(normal, incident)); float3 halfVector = normalize(incident + viewDirection); float specular = pow(saturate(dot(normal, halfVector)), lerp(104, 12, _Roughness)); return tint * (diffuse * .69 + specular * lerp(.12, .64, _Metal)) / (1 + distanceSq * .21); } fixed4 frag(Output input) : SV_Target { float3 p = input.local; float3 normal = normalize(input.normal); float3 eye = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1)).xyz; float3 viewDirection = normalize(eye - p); float interval = _BayLength * .5; float dx = (frac(p.x / interval) - .5) * interval; float nearestRoom = p.z < 0 ? -_RoomLight : _RoomLight; float3 corridor = fixture(float3(-dx, 2.85 - p.y, -p.z), viewDirection, normal, float3(1.00, .87, .67)); float3 work = fixture(float3(-dx, 2.89 - p.y, nearestRoom - p.z), viewDirection, normal, float3(.90, .94, .93)); corridor *= 1 - .62 * smoothstep(1.10, 2.25, abs(p.z)); work *= smoothstep(.35, 1.88, abs(p.z)); float fill = lerp(.72, 1, saturate(p.y * .72)); float grain = p.x * 112 + p.y * 91; float matte = .98 + .018 * (1 - smoothstep(.5, 2.4, fwidth(grain))) * sin(grain) * sin(p.z * 87 - p.y * 30); float2 treadCoord = p.xz / .145; float2 cell = abs(frac(treadCoord) - .5); float relief = 1 - smoothstep(.30, .46, cell.x + cell.y); float detail = 1 - smoothstep(.45, 1.3, fwidth(treadCoord.x) + fwidth(treadCoord.y)); matte += .086 * relief * detail * _DeckTread * saturate(normal.y); float3 diffuse = _Color.rgb * (float3(.34, .40, .42) * fill + corridor + work) * matte; float fresnel = pow(1 - saturate(dot(viewDirection, normal)), 3); float3 bounce = float3(.14, .20, .23) * fresnel * (.20 + _Metal * .40); return fixed4(saturate(diffuse + bounce + _Color.rgb * _Emissive * .66), 1); } ENDCG } } }