99 lines
4.6 KiB
GLSL
99 lines
4.6 KiB
GLSL
Shader "BigShipTycoon/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
|
|
_BulkheadLining ("Bulkhead panel joints", Float) = 0
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" }
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "TycoonTexturing.cginc"
|
|
|
|
fixed4 _Color;
|
|
float _Roughness, _Metal, _Emissive, _BayLength, _RoomLight, _DeckTread, _BulkheadLining;
|
|
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));
|
|
float2 gauge = TycoonPlane(p, normal);
|
|
float matte = .995 + TycoonStipple(gauge, 93) * .061;
|
|
if (_Metal > .5)
|
|
matte += TycoonGrain(gauge, 41) * .067;
|
|
if (_BulkheadLining > .5)
|
|
{
|
|
float plate;
|
|
float seam = TycoonPanel(gauge, float2(1, .55), .5, .0038, plate);
|
|
matte += plate * .085 - seam * .26;
|
|
}
|
|
if (_DeckTread > .5)
|
|
{
|
|
float up = saturate(normal.y);
|
|
float2 grain = p.xz * float2(10.8, 16.4);
|
|
float row = floor(grain.y);
|
|
float2 stamp = abs(frac(grain + float2(frac(row * .5), 0)) - .5);
|
|
float bolt = (1 - smoothstep(.28, .43, stamp.x + stamp.y * .82)) * TycoonDetail2(grain);
|
|
float deckPlate;
|
|
float joints = TycoonPanel(p.xz, float2(.52, .83), .5, .006, deckPlate);
|
|
matte += up * (bolt * .16 + deckPlate * .067 - joints * .21);
|
|
if (_DeckTread > 1.5)
|
|
{
|
|
float grids = max(TycoonJoint(p.x * 8.1, .068), TycoonJoint(p.z * 15.7, .082));
|
|
matte = lerp(matte, .68 + grids * .42, TycoonDetail2(p.xz * 9.5) * up * .83);
|
|
}
|
|
}
|
|
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(TycoonHighlightRollOff(diffuse + bounce + _Color.rgb * _Emissive * .66), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|