Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/TestOulineSnow" {
- Properties {
- _Color ("Main Color", Color) = (1,1,1,1)
- _OutlineColor ("Outline Color", Color) = (0.8,0.5,0,0.8)
- _Outline ("Outline width", Range (.002, 0.03)) = .003
- _MainTex ("Texture", 2D) = "white" { }
- _BumpMap ("Bumpmap", 2D) = "bump" {}
- }
- CGINCLUDE
- #include "UnityCG.cginc"
- struct appdata {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- };
- struct v2f {
- float4 pos : POSITION;
- float4 color : COLOR;
- };
- uniform float _Outline;
- uniform float4 _OutlineColor;
- v2f vert(appdata v) {
- v2f o;
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
- float2 offset = TransformViewToProjection(norm.xy);
- o.pos.xy += offset * o.pos.z * _Outline;
- o.color = _OutlineColor;
- return o;
- }
- ENDCG
- SubShader {
- Tags { "Queue"="AlphaTest"}
- //UsePass "Diffuse/BASE"
- Pass {
- Name "OUTLINE"
- Tags { "LightMode" = "Always" }
- Cull off
- ZWrite Off
- ColorMask RGB
- Blend SrcAlpha OneMinusSrcAlpha
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- half4 frag(v2f i) :COLOR { return i.color; }
- ENDCG
- }
- Tags { "RenderType"="Opaque" }
- LOD 300
- CGPROGRAM
- #pragma surface surf Lambert vertex:snow addshadow
- #pragma exclude_renderers flash
- //#pragma target 3.0
- sampler2D _MainTex;
- sampler2D _SnowTex;
- sampler2D _BumpMap;
- fixed4 _Color;
- float _snowShininess;
- float _SnowAmount;
- float _SnowStartHeight;
- sampler2D _SnowTexture;
- struct Input {
- float2 uv_MainTex;
- float2 uv_BumpMap;
- fixed4 color : COLOR;
- float3 worldPos;
- fixed3 MyWorldNormal;
- };
- void snow (inout appdata_full v, out Input o) {
- o.MyWorldNormal = normalize(mul((float3x3)_Object2World, v.normal));
- }
- void surf (Input IN, inout SurfaceOutput o) {
- fixed4 col = tex2D(_MainTex, IN.uv_MainTex) * _Color;
- fixed4 snow = tex2D(_SnowTex, IN.uv_MainTex);
- o.Alpha = col.a;
- o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
- // get snow texture // distribution might be stored in alpha
- half4 snowtex = tex2D( _SnowTexture, IN.uv_MainTex);
- // clamp(IN.MyWorldNormal.y + 0.6, 0, 1) = allows snow even on orthogonal surfaces // (1-col.b) = take the blue channel to get some kind of heightmap
- float snowAmount = (_SnowAmount * (clamp(IN.MyWorldNormal.y + 0.6, 0, 1)) * (1-col.b) *.8 + clamp(o.Normal.y, 0, 1) * _SnowAmount * .25);
- // clamp snow to _SnowStartHeight
- snowAmount = snowAmount * clamp((IN.worldPos.y - _SnowStartHeight)*.0125, 0, 1);
- // sharpen snow mask
- snowAmount = clamp(pow(snowAmount,6)*256, 0, 1);
- o.Alpha = 0.0;
- // mix
- o.Albedo = col.rgb * (1-snowAmount) + snowtex.rgb*snowAmount;
- o.Gloss = half(snowAmount*(1-snowtex.rgb));
- o.Specular = _snowShininess;
- // smooth normal
- o.Normal = normalize(lerp(o.Normal, float3(0,0,1), snowAmount*.50));
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement