Created
August 14, 2014 21:40
-
-
Save bcatcho/c25f172361aca17abb19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "insula/env/outdoor" { | |
Properties { | |
_texture ("texture", 2D) = "white" {} | |
_fakeshadowcolor ("fake shadow color", Color) = (0.5,0.5,0.5,1) | |
_fakeshadowfacenormal ("fake shadow face normal", Vector) = (0,0,0,0) | |
_shadowspread ("shadow spread", Float ) = 0.95 | |
_bgcolor ("bg color", Color) = (0.5,0.5,0.5,1) | |
_silhouette ("silhouette value", Range(0, 1)) = 1 | |
_waterLevel ("water level", Float) = -2 | |
_waterDepth ("water depth", Float) = 4 | |
_waterMarkColor ("water mark color", Color) = (0,0,0,0) | |
} | |
SubShader { | |
Tags { | |
"Queue"="Geometry" | |
"RenderType" = "Opaque" | |
} | |
Fog { Mode Off } | |
CGPROGRAM | |
#pragma surface surf Lambert vertex:vert | |
sampler2D _texture; | |
float4 _fakeshadowcolor; | |
float4 _fakeshadowfacenormal; | |
half3 _bgcolor; | |
float _shadowspread; | |
float _silhouette; | |
float _sceneDepth; | |
float _waterLevel; | |
float _waterDepth; | |
half3 _waterMarkColor; | |
struct Input { | |
float2 uv_texture : TEXCOORD0; | |
float3 vertPos; | |
}; | |
void vert (inout appdata_full v, out Input o) { | |
// fancy unity stuff to calculate a bunch of things for us | |
UNITY_INITIALIZE_OUTPUT(Input,o); | |
// the direction from the vertex in world space to the camera | |
float3 dir = normalize((_WorldSpaceCameraPos - mul(_Object2World,v.vertex)).xyz ); | |
// store the original vertex position in a variable that we can use later | |
o.vertPos = mul(_Object2World,v.vertex).xyz; | |
// push the vertex back into the scene according to this fany variable | |
v.vertex.xyz -= dir * _sceneDepth ; // move the object back and scale | |
} | |
void surf (Input i, inout SurfaceOutput o) { | |
// grab texture color for this fragment | |
half3 c = tex2D (_texture, i.uv_texture).rgb; | |
// calculate a fancy shadow thing that is really custom | |
float shadowAmt = max(0,dot(normalize(_fakeshadowfacenormal.rgb),o.Normal)); | |
// combine them | |
c = lerp(c.rgb, lerp(c,_fakeshadowcolor.rgb,(_fakeshadowcolor.a*shadowAmt)),step(_shadowspread,shadowAmt)); | |
// calculate how far below the water line we are | |
float waterDepth = (_silhouette)* saturate(pow(max((_waterLevel - i.vertPos.y)/_waterDepth, 0),2)); | |
// for fragments above the water line this will be the color | |
o.Albedo = lerp(c, half3(0,0,0), 1-_silhouette ); | |
// calculate the color by lerping according to the distance below the water line | |
o.Albedo = lerp(o.Albedo, _waterMarkColor, waterDepth); | |
// do the same for emission | |
o.Emission = lerp(lerp(half3(0,0,0),_bgcolor, 1-_silhouette ), _waterMarkColor, waterDepth ); | |
o.Alpha = 1; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment