Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question What other shaders are available besides "Transparent/Diffuse"?

Discussion in 'Scripting' started by JeffreyVentrella, Oct 5, 2023 at 10:50 PM.

  1. JeffreyVentrella

    JeffreyVentrella

    Joined:
    Jun 16, 2016
    Posts:
    12
    A while back I was looking for a way to make an object translucent, and I came across some example code that uses "Transparent/Diffuse"...like this:

    Renderer r = myObject.GetComponent<Renderer>();
    r.material.shader = Shader.Find("Transparent/Diffuse");
    r.material.SetColor( "_Color", myColor );

    It works like a charm! Are there other cool shader options (with various properties) that I can find where that came from? Like in some local library? Sorry if this is a naive question - it might be right under my nose somewhere. Before I start looking for (or making) new shaders, I just wanted to check and see what else is easily available.

    Thanks!
    -j
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,283
    Beware this one... like GameObject.Find() it is EXTREMELY tricky and advanced.

    Obviously there's the naming typo you are even bringing up, finding and using.

    But also, if you don't have at least ONE object in your scenes / prefabs, eg, what actually makes it into the build binary that actually USES that shader in a Material, Shader.Find() will FAIL to find it because it will have been stripped.

    You will never be aware of this behaviour until you see it on device.

    Build early, build often, test widely.
     
  3. JeffreyVentrella

    JeffreyVentrella

    Joined:
    Jun 16, 2016
    Posts:
    12
    Thanks for the warning.

    BTW - everything in my project is being generated in scripts. I don't know if this makes a difference in regards to your comment.

    **My question was in regards to accessing other shaders, as I have this one. If you believe your warning nullifies my question, that's fine. That shader is working for me at the moment, and this is for a video, not for a shipped game. If you are not able to address my question, no worries. I'll carry on. It's not a show-stopper.

    Thanks!
    -j
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,283
    Gotcha... I understood you didn't have an actual problem, just wanted to point out potential bites-you-down-the-line issues.

    Just remember, you saying "I have this one" is not the criteria that Unity uses for deciding to strip the asset. If you don't understand what I mean by this then you have not understood the purpose of my first warning.

    In that case I suppose, carry on as you go and hope for the best! :)