Search Unity

2 channel Self Illuminating Shader request.

Discussion in 'Shaders' started by TIGGYsmalls, Jun 25, 2013.

  1. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    I just don't get shaders or any sort of programming (I'm using Playmaker). So I'm just going to be cheeky and ask for a shader as I cant find what I'm looking for.

    http://docs.unity3d.com/Documentation/Components/shader-SelfIllumDiffuse.html

    What I want is something like the self illuminating shader, a Main Colour but with 2 seperate textures with alpha channels, so still with 2 textures, not ending up with 4. Then I want the textures to multiply together.

    So, any help?
     
  2. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Well I gave it a go and got this far but how do you get the colour tint to work?

    Code (csharp):
    1. Shader "Custom/IlumBlend" {
    2.  
    3. Properties {
    4.     _Color ("Color Tint", Color) = (1,1,1,1)
    5.     _MainTex ("Texture 1", 2D) = ""
    6.     _Texture2 ("Texture 2", 2D) = ""
    7. }
    8.  
    9. SubShader {
    10.     Pass {
    11.         SetTexture[_MainTex]
    12.         SetTexture[_Texture2] {
    13.             combine texture * primary + previous
    14.         }      
    15.     }
    16. }
    17.  
    18. }
     
  3. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    I downloaded the shaders and opened up the Illumin diffuse to edit.

    But it's still not right. The textures don't blend properly.

    Code (csharp):
    1. Shader "IllumBlend2" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _Tex1 ("Texture1 (RGB) Gloss (A)", 2D) = "white" {}
    5.     _Tex2 ("Texture2 (RGB) Gloss (A)", 2D) = "white" {}
    6.     _EmissionLM ("Emission (Lightmapper)", Float) = 0
    7. }
    8. SubShader {
    9.     Tags { "RenderType"="Opaque" }
    10.     LOD 200
    11.    
    12. CGPROGRAM
    13. #pragma surface surf Lambert
    14.  
    15. sampler2D _Tex1;
    16. sampler2D _Tex2;
    17. fixed4 _Color;
    18.  
    19. struct Input {
    20.     float2 uv_Tex1;
    21.     float2 uv_Tex2;
    22. };
    23.  
    24. void surf (Input IN, inout SurfaceOutput o) {
    25.     fixed4 tex = tex2D(_Tex1, IN.uv_Tex1);
    26.     fixed4 c = tex * _Color;
    27.     o.Albedo = c.rgb;
    28.     o.Emission = c.rgb * UNITY_SAMPLE_1CHANNEL(_Tex2, IN.uv_Tex2);
    29.    
    30. }
    31. ENDCG
    32. }
    33. FallBack "Self-Illumin/VertexLit"
    34. }
    35.  
     
  4. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Code (csharp):
    1.        
    2.  
    3. Shader "Custom/IlumBlend" {
    4.      
    5.     Properties {
    6.             _Color ("Color (RGB)", Color) = (1,1,1,1)
    7.             _Texture1 ("Texture1 (RGB) Texture (A)", 2D) = "white" {}
    8.             _Texture2 ("Texture2 (RGB) Texture (A)", 2D) = "white" {}
    9.      }
    10.         SubShader {
    11.         Pass {
    12.          
    13.             Lighting Off
    14.  
    15.             SetTexture [_Texture1] {
    16.             constantColor [_Color]
    17.                 combine constant lerp(texture) previous
    18.             }
    19.              SetTexture [_Texture2]{
    20.                 combine texture lerp (texture) previous
    21.              }
    22.         }
    23.     }
    24. }
    25.  
    26.  
    27.  
    Ok, this is the closest I've gotten. I don't understand or know if you can combine both textures and the colour in 1st set of {}?
     
  5. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Have you tried to write an actual shader?
     
  6. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Well I got told to look at this:

    http://docs.unity3d.com/Documentation/Components/SL-SetTexture.html

    So I just copied and pasted. Deleted the bits that I didn't seem to need.

    Then I looked at this:

    http://answers.unity3d.com/questions/377481/2-texture-blend-shader.html

    When I take out the _Blend or try anything with it, I get the pink error. I don't know how to use Lerp(constant) previous or SetTexture[_] {Combine previous * primary Double} or any combination of these magic words. So I have been moving lines around to no avail.

    So write, no. Amalgamate, yes.