- Home /
Help with Snow Shader!
Hello everyone,
I'm trying to create a snow shader that I can use as a secondary material on any object that already has a material on it. I sort of want to just add it to assets that I already have but were not made with snow environments in mind. I'm very new to scripting shaders so i'm also very lost. I have started with the snow shader found on Unity Gems, but I'm pretty much stuck.
There are a few things that I would like to do. 1. I'd like to make the texture reference the first materials normal map and blend it with my own snow normal map on the second material. 2. I'd also like the snow to have a texture rather than just a flat color, and a spectacular map.
Any help you could provide would be much appreciated! Or if you have any shader scripting references that I could look at to try and learn it myself I would be happy with that too!
Shader "Custom/SnowShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Bump ("Bump", 2D) = "bump" {}
_Snow ("Snow Level", Range(0,1) ) = 0
_SnowColor ("Snow Color", Color) = (1.0,1.0,1.0,1.0)
_SnowDirection ("Snow Direction", Vector) = (0,1,0)
}
SubShader {
Tags { "RenderType"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
sampler2D _Bump;
float _Snow;
float4 _SnowColor;
float4 _SnowDirection;
struct Input {
float2 uv_MainTex;
float2 uv_Bump;
float3 worldNormal;
INTERNAL_DATA
};
void vert (inout appdata_full v) {
//Convert the normal to world coortinates
float4 sn = mul(UNITY_MATRIX_IT_MV, _SnowDirection);
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Normal = UnpackNormal (tex2D (_Bump, IN.uv_Bump));
if(dot(WorldNormalVector(IN, o.Normal), _SnowDirection.xyz)>=lerp(1,-1,_Snow))
o.Albedo = _SnowColor.rgb;
else
o.Albedo = c.rgb;
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}
Thanks Guys!
Answer by CathChapo101 · Jun 16, 2015 at 02:54 PM
Hey there!
I think your questions have been answered in an other thread (if I did understand them well). Here's the link:
http://forum.unity3d.com/threads/snow-up-vector-shader.177606/
They started with the same UnityGem snow shader but the second version implements everything you asked for!
Hope it helps!
Your answer
Follow this Question
Related Questions
Snow deformation 1 Answer
Dynamic snow & sand 1 Answer
SpeedTree dynamic seasons 0 Answers
Overwrite directional light locally with a pointlight 0 Answers
Snow scene in unity 2 Answers