64 lines
2.9 KiB
GLSL
64 lines
2.9 KiB
GLSL
Shader "Soundings/Harbor Surface"
|
|
{
|
|
Properties
|
|
{
|
|
_Color ("Paint", Color) = (1,1,1,1)
|
|
_Roughness ("Roughness", Range(.02,1)) = .42
|
|
_Metal ("Metal", Range(0,1)) = 0
|
|
_Emissive ("Emission", Range(0,1)) = 0
|
|
_Weather ("Weathering", Range(0,1)) = .1
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" }
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
|
|
fixed4 _Color;
|
|
float _Roughness, _Metal, _Emissive, _Weather;
|
|
struct Input { float4 vertex : POSITION; float3 normal : NORMAL; };
|
|
struct Output { float4 clip : SV_POSITION; float3 normal : TEXCOORD0; float3 world : TEXCOORD1; };
|
|
|
|
Output vert(Input input)
|
|
{
|
|
Output output;
|
|
output.clip = UnityObjectToClipPos(input.vertex);
|
|
output.normal = UnityObjectToWorldNormal(input.normal);
|
|
output.world = mul(unity_ObjectToWorld, input.vertex).xyz;
|
|
return output;
|
|
}
|
|
|
|
fixed4 frag(Output input) : SV_Target
|
|
{
|
|
float3 p = input.world;
|
|
float3 normal = normalize(input.normal);
|
|
float3 eye = normalize(_WorldSpaceCameraPos.xyz - p);
|
|
float3 sun = normalize(float3(-.69,.40,-.43));
|
|
float3 halfVector = normalize(sun + eye);
|
|
float sunlight = saturate(dot(normal,sun));
|
|
float sky = saturate(normal.y * .5 + .5);
|
|
float fresnel = pow(1 - saturate(dot(eye,normal)), 3.5);
|
|
float roughExponent = lerp(220, 9, _Roughness);
|
|
float specular = pow(saturate(dot(normal,halfVector)), roughExponent) * (1 - _Roughness * .65);
|
|
float3 reflected = reflect(-eye,normal);
|
|
float sunsetStripe = smoothstep(-.08,.13,reflected.y) * (1 - smoothstep(.13,.42,reflected.y));
|
|
float3 skyReflection = lerp(float3(.11,.19,.27), float3(.39,.48,.60), saturate(reflected.y))
|
|
+ sunsetStripe * float3(.20,.12,.061);
|
|
float3 light = lerp(float3(.25,.34,.46),float3(.61,.68,.77),sky) + sunlight * float3(.62,.44,.30);
|
|
float micro = sin(p.x * 13.7 + p.y * 19.3) * sin(p.z * 15.4 - p.x * 8);
|
|
float abrasion = sin(p.x * .82 + p.z * 1.7) * sin(p.y * 3.5 + p.z * 4.8);
|
|
float surfaceGrain = 1 + _Weather * (.055 * micro + .10 * abrasion);
|
|
float3 diffuse = _Color.rgb * light * surfaceGrain;
|
|
float3 shine = skyReflection * (.07 + fresnel * .24 + _Metal * .21) * (1 - _Roughness * .48)
|
|
+ specular * float3(.72,.51,.34) * (.14 + .59 * _Metal);
|
|
return fixed4(saturate(diffuse + shine + _Color.rgb * _Emissive * .60), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|