Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Materials with Both Transparency and Self-Illumination?

Discussion in 'Editor & General Support' started by marty, Mar 30, 2006.

  1. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Is it possible to create a Unity material that has both transparent and self-illuminated pixels in it?

    I can make materials with alpha transpraency, and self-illuminated materials, but don't see how I can get both. Is there a multi-texturing solution? Or some other way to do this?

    TIA
     
  2. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Well Marty give this a whirl, I think this is what you want

    [Edit: ZWrite should be off, fixed]

    Code :

    Code (csharp):
    1.  
    2. Shader "AlphaSelfIllum" {
    3.     Properties {
    4.         _Color ("Color Tint", Color) = (1,1,1,1)
    5.         _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
    6.     }
    7.     Category {
    8.        Lighting On
    9.        ZWrite Off
    10.        Cull Back
    11.        Blend SrcAlpha OneMinusSrcAlpha
    12.        Tags {Queue=Transparent}
    13.        SubShader {
    14.             Material {
    15.                Emission [_Color]
    16.             }
    17.             Pass {
    18.                SetTexture [_MainTex] {
    19.                       Combine Texture * Primary, Texture * Primary
    20.                 }
    21.             }
    22.         }
    23.     }
    24. }
    25.  
    And the shader:

    PS: David can you allow .shader as a extension? Thanks.
     

    Attached Files:

    adrianzarp and Ex6tra like this.
  3. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Cool!

    Thanks, Bill.

    Let's give this whirl ...
     
  4. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
  5. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Thanks that was a easy shader. Hard part was getting it before peter did.

    <.< | >.>

    He always nabs them before I do... :wink:

    ...and you are very welcome :D

    Bill
     
  6. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    Thanks for the heads-up, .shader now allowed in the forum.

    ... cool shader by the way.

    d.
     
    psychentist likes this.
  7. Loftless

    Loftless

    Joined:
    Mar 20, 2011
    Posts:
    16
    Yay for resurrecting old threads!

    Sorry, but obviously I can't get this shader to work in 3.2

    Anyone know an easy way to make this kind of shader, but for use in 3.2?
     
  8. Spinland

    Spinland

    Joined:
    Jan 13, 2011
    Posts:
    77
  9. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    What doesn't work about it? Are you trying to use it with lightmapping? It's not equipped for that, but otherwise, it ought to work fine.
     
  10. paulygons

    paulygons

    Joined:
    May 6, 2010
    Posts:
    164
    Rise ye dead thread! Sync1B's shader is great! When I build my project using this shader for Android, I get this warning:

    Shader is using clip instruction (usually caused by alpha test). It might cause problems on some Qualcomm/Adreno drivers.
    UnityEditor.HostView:OnGUI()

    I was wondering if any shader that uses transparency will warn me about this, or if there is something about this particular shader's design that is wrong for mobile devices? Everything runs fine on the Android hardware I have access to, and virtual devices. If it isn't obvious, I have a long way to go before I'll be writing my own shaders.

    Is there a better Alpha-Self-Illuminated to use on mobiles? My current project is a side scroller, with lots of flat planes to simulate depth, so I'm surprised this shader isn't in the standard assets... or did I have a synapse-lapse and just overlook something? Thanks!

    on further testing, I think I'm wrong about this being the shader that was causing the complaint. I'll update this I figure anything else out about it. For now it looks like this is fine.
     
    Last edited: Feb 25, 2012
  11. MaxSilva

    MaxSilva

    Joined:
    Jul 25, 2012
    Posts:
    8
    This thread appears when googling this shader so i'm posting a working version here. The version posted above it's not working in newer versions of Unity.

    Cheers,

    Max.
     

    Attached Files:

    Last edited: Jul 31, 2012
    alex2008wxyz likes this.
  12. Seth-Bergman

    Seth-Bergman

    Joined:
    Jul 4, 2012
    Posts:
    4
    I know this is an old thread, but in response to the "shader is using clip instruction" warning, I have observed that this is given when using transparent CUTOUT, but regular transparency shaders do not throw this warning

    not sure exactly how this relates to custom shaders though

    @MaxSilva, that one's not working for me, I get:

    shader has errors or is not supported by your graphics card

    and I KNOW my graphics card is good
     
    Last edited: Jul 30, 2012
  13. MaxSilva

    MaxSilva

    Joined:
    Jul 25, 2012
    Posts:
    8
    @Seth Bergman What graphics card model you have? It's a PC or Mac? OS?
    I used this shader in various machines with Nvidia chipsets. The shader it's just a modification of the Transparent/Diffuse built-in shader without the light calculation, it should work as well as the built-in shader.

    Maybe it's a compilation error but i just downloaded it and it works fine. Did someone else tried it out?
     
  14. MaxSilva

    MaxSilva

    Joined:
    Jul 25, 2012
    Posts:
    8
    @Seth Bergman
    You may try again, i uploaded a new version because i was doing something veeery wrong before. It is coded in CG rather than being a ShaderLab surface shader.
     
  15. foosart

    foosart

    Joined:
    Jun 6, 2012
    Posts:
    66
    Wow, thank you for posting this shader. Does exactly what I needed.
     
  16. MadRobot

    MadRobot

    Joined:
    Jul 12, 2011
    Posts:
    339
    Is there a way to make the illumination brighter? I had a look at the source and didn't see any numbers to change...
     
  17. MaxSilva

    MaxSilva

    Joined:
    Jul 25, 2012
    Posts:
    8
    You could multiply the color in the fragment shader by a vector

    e.g
    Code (csharp):
    1.  
    2. half4 frag (v2f i) : COLOR
    3. {
    4.     half4 texcol = tex2D (_MainTex, i.uv);
    5.     return texcol * _Color * intensity; // This is the final color
    6. }
    7.  
    intensity must be a float4 vector. Refer to HLSL docs for more information.

    It may saturate with a high number though.
    You may also do the calculation directly in the vertex shader and pass the final color for performance, i guess.
     
  18. LuisDeliz

    LuisDeliz

    Joined:
    Nov 27, 2012
    Posts:
    24
    Old topic but I figure I might get lucky.

    I'm trying to used this AlphaSelfIllum on particles. But the alpha doesn't seem to work. I have my particles set to fade out over time but they stay constant until they die. Is there any change that needs to be done in order for it to work with Particles? Using Unity 4 Pro.
     
  19. EthanWoo

    EthanWoo

    Joined:
    Aug 20, 2013
    Posts:
    1
    If you have a problem with shader due to building adk.

    Try to build Android with Texture compression : Adreon ATC that is in the build setting
    you won't find any more " Shader is using clip instruction (usually caused by alpha test).
    It might cause problems on some Qualcomm/Adreno drivers."
     
  20. bustedkrutch

    bustedkrutch

    Joined:
    Jun 24, 2013
    Posts:
    20
    This sounds exactly what I'm looking for also, however I'm not sure what to do with the "shader" file.
    I found other shader files and put it in the same directory. Do I also have to import it ??? Would I need Pro to be able to do this?

    Thank you.

    Doh, after a bit-o-fiddlin you just import new asset into a reasonable folder in unity, no pro required.

    For the nuubs like me :)
     
    Last edited: Aug 28, 2013
  21. MaxSilva

    MaxSilva

    Joined:
    Jul 25, 2012
    Posts:
    8
    The shader has to be assigned to the material of your object
     
  22. qchots

    qchots

    Joined:
    Jun 28, 2013
    Posts:
    1

    can you give the screenshot ?? i have a same problem with "bustedkrutch"..
    i did'n know how to use "AlphaSelfIllum.shader"..

    really nee your help..

    thanks..
     
  23. Edudjr

    Edudjr

    Joined:
    Nov 6, 2013
    Posts:
    2
    You just need to put the shader into any file of your game and then it will appear at the scrowbar shader in the materials (like Diffuse, etc).

    Can anyone tell me what to do to change the 'brightness' of the shader? I know someone posted the code, but I don't get it.
     
  24. JNetRocks1316

    JNetRocks1316

    Joined:
    Aug 25, 2013
    Posts:
    1
    Is there any way to setup a shader that uses two textures, one with the alpha information and one with the illumination information?

    If I use the shader provided here the whole thing glows rather than just the areas that I want, and also it has some weird see-through effect sometimes.

    I was hoping to have it like:

    _MainTex("Diffuse(RGB) Alpha(A)", 2D) = "white"
    _BlendTex("Bump(RGB) Illum(A)",2D) = "white"

    Haven't been able to figure it out yet though :C
     
  25. GlitchInTheMatrix

    GlitchInTheMatrix

    Joined:
    Apr 12, 2010
    Posts:
    285
    Hi, Im looking for something similar to this shader. Anyone figure out how to have the transparency of the shader and the Self Illumination intensity for separate?

    IE. I have my Self Illumination intensity Map into the Alpha Channel of my texture, and want to use a Transparency value to animate my object to become transparent when it get destroyed.

    Any help?

    Thanks
     
  26. Dubious-Drewski

    Dubious-Drewski

    Joined:
    Aug 19, 2012
    Posts:
    51
    This looks so promising! But for some reason, I can't affect this shader's alpha value at all. What am I doing wrong?

    Code (CSharp):
    1. Color thingColour;
    2. GameObject thing;
    3.  
    4. thingColour.a = 0.5f;
    5. thing.renderer.material.color = thingColour;
    6. Debug.Log(thing.renderer.material.color);  //this confirms that the colour has been changed... but nothing visually changes
    7.  
    This code works fine with the built-in Transparent/Diffuse shader, but it has no effect on this AlphaSelfIllum.Shader, and I can't tell why. Both of them have the same "_Color" property, so what is different?
     
  27. flapyfox

    flapyfox

    Joined:
    Sep 9, 2008
    Posts:
    408
    This shader is promesing but is not working as its supposed to. Unlike the self_illumin shader family its is not affected by the lightmap.The main power of self_illumin shaders is that with the ``main color`` knob, you can control how much its self illuminated vs how much its affected by the lightmap besides it also misses the use of an illumination map in the alpha. So is there a way to make it influenced by the lightmap like the other self-illumin shaders do?
     
  28. chillyche

    chillyche

    Joined:
    Dec 26, 2013
    Posts:
    2
    This shader worked for me! Glowing exhaust. Thanks. But I can see how people need more control over it for other needs.
     
  29. leoxs

    leoxs

    Joined:
    Jul 22, 2014
    Posts:
    21
    woooow, thanks sync1b I love you xD
     
  30. belamessex

    belamessex

    Joined:
    May 12, 2015
    Posts:
    12
    So good thanks! Now to figure how to get a normal map on it...
     
  31. alex2008wxyz

    alex2008wxyz

    Joined:
    Jul 1, 2020
    Posts:
    5
    I know I'm late, but can you post it on Unify (Unity wiki)?