Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This shader will blend two textures using the vertex color as a guide.
- Shader "FX/Diffuse Blend"
- {
- // These are the fields that will appear for this Material in the Inspector - see Unity doc at http://docs.unity3d.com/Documentation/Components/SL-Properties.html
- // The first part is the property's variable, eg. "_MainTex" - Naming your main texture "_MainTex" signals to Unity that this Shader should be included in Lightmap calculations
- // Using the standard Unity property names also lets Unity apply a fallback Shader if the user's hardware can't handle this one
- // The second part in brackets is the name of the property in the Inspector, eg. "Main Texture" - This can be anything you like.
- // The third part in brackets is the variable type, eg. "2D" declares it to be a texture file -
- // The fourth part is the property's default value, eg. "white {}" - Textures are generally given default values of white, gray or black
- Properties
- {
- _MainTex ("Main Texture (vertex A = black)", 2D) = "gray" {} // This is the material's Texture property and we want it to be included in Lightmap calculations (especially LightProbes)
- _BlendTex ("Blend Texture (vertex A = white)", 2D) = "gray" {} // This shader is a little strange since we actually want to blend two textures, this is the texture we will blend in
- _ColorTint ("Main Color", Color) = (0.7, 0.7, 0.7, 0.1) // This is a color value we will use to tint the texture after it is blended, but before the light is applied
- }
- // The SubShader is where the Shader calculations actually happen
- SubShader
- {
- // This allows Unity to intelligently substitute this Shader when needed
- Tags { "RenderType"="Opaque" }
- Blend Off
- LOD 250
- // The syntax that was use after "pragma" tells Unity what kind of shader this is and how it should be applied, eg.
- // This shader is a surface Shader of type Lambert, and don't want Unity to bother with a prepass because we're not doing anything with light
- CGPROGRAM
- #pragma surface surf Lambert exclude_path:prepass
- //These match the shader properties
- uniform sampler2D _MainTex;
- uniform sampler2D _BlendTex;
- uniform fixed4 _ColorTint;
- // This contains the inputs to the surface function
- // Valid fields are listed at: http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaders.html
- // The color syntax is actually accessing the vertex color that we put in our object to guide the blend. You normally don't need this
- struct Input
- {
- float2 uv_MainTex;
- float2 uv_BlendTex;
- float4 color : COLOR;
- };
- // This is where we prepare the surface for lighting by propagating a SurfaceOutput structure, I'm going to breaqk it down so you know what's happening
- // In the first two lines, we're unwrapping both textures
- // "Lerp" is a word programmers use when they're blending between two sets of numbers, this is what we're doing with our textures
- // So we're Lerping between our main texture and our blend texture, and we're using the values of the vertex color to guide us... in theory this could be any value set
- void surf (Input IN, inout SurfaceOutput o)
- {
- fixed4 Tex2D0 = tex2D(_MainTex, IN.uv_MainTex);
- fixed4 Tex2D1 = tex2D(_BlendTex, IN.uv_BlendTex);
- fixed4 Lerp0 = lerp(Tex2D0, Tex2D1, IN.color);
- o.Albedo = Lerp0.rgb * _ColorTint; // We modulate our coloors by our main colour, BUT we also multiply it by our tint... this works a little like a color filtre in Photoshop
- o.Alpha = 1.0; // No alpha in this shader
- }
- ENDCG
- }
- FallBack "Mobile/Diffuse" // Shader to use if the user's hardware cannot incorporate this one
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement