Sei sulla pagina 1di 4

//Ice shader.

//_Thickness = Thickness texture (invert normals, bake AO).


//_Power = "Sharpness" of translucent glow.
//_Distortion = Subsurface distortion, shifts surface normal, effectivel
y a refractive index.
//_Scale = Multiplier for translucent glow - should be per-light, really
.
//_SubColor = Subsurface colour.
Shader "MAP/Complex/SceneIceComplex" {
Properties {
//RAMP
w ("w", Float) = 1.4
n ("n", Float) = 3.0
_AlbedoIn ("_AlbedoIn", Range(1.0,4.0)) = 2.0
_RampR ("Ramp", 2D) = "gray" {}
//DISTORTION
_BumpAmt("Distortion", range (0,128)) = 0.1
_TransAmount ("Transparency amount", Range (0.03, 3)) = 0.078125
_BorderPower ("Border distortion", Range(0.5,4.0)) = 3.0
_Pow0AIn ("Border distortion amount", Range(0.5,4.0)) = 2.0
_RimPower ("Border rim", Range(0.5,4.0)) = 3.0
_Pow0BIn ("Border rim amount", Range(0.0,4.0)) = 2.0
//BASE
_MainTex ("Main Texture", 2D) = "white" {}
//BUMP MAP
_BumpMap ("Normalmap", 2D) = "bump" {}
//SPECULAR
_Shininess ("Shininess", Range (0.03, 3)) = 0.078125
_ShininessIn ("Shininess Intensity", Range (0, 1)) = 0.3
//TRANSLUCETY
_Power ("Subsurface Power", Float) = 1.0
_Distortion ("Subsurface Distortion", Float) = 0.0
_Scale ("Subsurface Scale", Float) = 0.5
//TRANSLUCETY
_Power2 ("Subsurface Power2", Float) = 1.0
_Distortion2 ("Subsurface Distortion2", Float) = 0.0
_Scale2 ("Subsurface Scale2", Float) = 0.5
}
SubShader {
Tags{
"Queue"="Transparent"
"IgnoreProjector"="False"
"RenderType"="Eye"
}
LOD 200
Cull Back
GrabPass { }
//BASE PASS
CGPROGRAM
#pragma target 3.0
#pragma exclude_renderers d3d11 d3d11_9x xbox360 gles flash
#pragma surface surf TEST vertex:vert addshadow fullforwardshado
ws
struct MAPSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;

half Specular;
half Gloss;
half Alpha;
};
struct Input {
half2 uv_MainTex;
half3 viewDir;
half4 GrabUV;
half4 proj : TEXCOORD;
half4 screenPos;
};
void vert (inout appdata_full v, out Input o){
half4 oPos = mul(UNITY_MATRIX_MVP, v.vertex);
#if UNITY_UV_STARTS_AT_TOP
half scale = -1.0;
#else
half scale = 1.0;
#endif
o.proj.xy = (half2(oPos.x, oPos.y*scale) + oPos.
w) * 0.5;
o.proj.zw = oPos.zw;
}
sampler2D _GrabTexture;
float4 _GrabTexture_TexelSize;
half w;
half n;
half _AlbedoIn;
sampler2D _RampR;
half
half
half
half
half
half

_BumpAmt;
_TransAmount;
_BorderPower;
_Pow0AIn;
_RimPower;
_Pow0BIn;

sampler2D _MainTex;
sampler2D _BumpMap;
half _Shininess;
half _ShininessIn;
half _Power;
half _Distortion;
half _Scale;
half _Power2;
half _Distortion2;
half _Scale2;
half4 LightingTEST (MAPSurfaceOutput s, half3 lightDir,
half3 viewDir, half atten) {
// Translucency.
half3 transLightDir = lightDir + s.Normal * _Dis
tortion;
float transDot1 = pow ( max (0, dot ( viewDir, -

transLightDir ) ), _Power ) * _Scale;


fixed3 transAlbedo = s.Albedo * transDot1 * s.Al
pha;
half3 transLightDir2 = -lightDir + s.Normal * _D
istortion2;
float transDot2 = pow ( max (0, dot ( -lightDir,
-transLightDir2 ) ), _Power2 ) * _Scale2 * s.Alpha;
//Light Ecuations
half3 h = normalize( lightDir + viewDir );
half nh = saturate( dot( h, s.Normal ) );
half diff = pow(saturate((dot(s.Normal, h) + w)
/ (1.0f + w)), n) * (n + 1) / (2 * (1 + w));
//Specular
half spec = pow( nh, s.Gloss*512) * s.Specular;
//Ramp
float transDot=(pow(saturate((dot(viewDir, -ligh
tDir-s.Normal*_Distortion) + w) / (1.0f + w)), n) * (n + 1) / (2 * (1 + w)))*_Sc
ale;
half diffB = pow(saturate((dot(s.Normal, lightDi
r) + w) / (1.0f + w)), n) * (n + 1) / (2 * (1 + w));
float2 brdfUV=float2(diffB, dot(_LightColor0.rgb
,fixed3(0.22,0.707,0.071)) )*lerp(1,1+transDot,transDot);
half3 rampR=tex2D(_RampR,brdfUV).rgb;
//Result
half4 c=half4(0,0,0,0);
c.rgb = (saturate(s.Albedo*(rampR + transDot2)*_
AlbedoIn) + transAlbedo + spec*saturate(diff*1.3)) * (_LightColor0.rgb * atten *
2);
c.a = 1;
return c;
}
void surf (Input IN, inout MAPSurfaceOutput o) {
//Albedo
half4 c=tex2D(_MainTex, IN.uv_MainTex);
o.Albedo=c.rgb;
//Normal
o.Normal=UnpackNormal(tex2D(_BumpMap, IN.uv_Main
Tex));
//Specular Map
o.Gloss=_ShininessIn;
o.Specular=_Shininess;
//Refraction
half Fresnel0=(1.0 - dot( normalize(IN.viewDir),
normalize(o.Normal) ) );
half Pow0A=1-saturate(pow(Fresnel0,_BorderPower)
*_Pow0AIn);
half Pow0B=1-saturate(pow(Fresnel0,_RimPower)*_P
ow0BIn);
half3 DistortNormal=UnpackNormal(tex2D(_BumpMap,
IN.uv_MainTex)+(1-Pow0A)*float4(1,1,1,1));

half2 offset = DistortNormal.xy * _BumpAmt * _Gr


abTexture_TexelSize.xy;
IN.proj.xy = offset * IN.proj.z + IN.proj.xy;
half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_
COORD(IN.proj));
o.Emission = col.rgb*_TransAmount*Pow0B*(1-satur
ate(c.a*2));
//Alpha
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

Potrebbero piacerti anche