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.

Shader results, darker than built-in shaders.

Discussion in 'Shaders' started by Ian Smithers, Jan 11, 2015.

  1. Ian Smithers

    Ian Smithers

    Joined:
    Mar 15, 2011
    Posts:
    68
    Hi all,

    I'm working through some material on creating my own shaders in Unity. It was written for Unity 4.0, and I am using 4.6 (not sure if that makes any difference).

    I wish to know why my shader results appear much darker than the examples in the material and also the built in Unity shaders of the same type, for example Diffuse.

    I've done some research and it appears that often the results need to be multiplied by 2 - I'm not sure of the motivation behind this however. Also, where do I draw the line? Do I double all the modifications or only some - for example if I have a two-pass shader which works out diffuse, specular, rim-lighting, ambient and takes into account multiple lights, which of these should be doubled and in which passes?

    Thanks!
     
  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Why not just look into Unitys default diffuse shader and compare?
     
  3. Ian Smithers

    Ian Smithers

    Joined:
    Mar 15, 2011
    Posts:
    68
    Because that doesn't answer my question.
     
  4. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,878
    Why doesn't that answer your question?

    Study the normal diffuse and maybe you can begin to understand why it works the way it does.

    Everything is multiplied by the power of 2 for a reasoning, one it's easier to work with, two, it's mathematically more stable and easier to calculate.

    It would be like okay, I'm multiplied by the power of 1, I need to reach a power of 10 for full effect, well then that's 10 calculations instead of 5. Why not just calculate it on a power of 5 or 10, because not every number fits into them. What if you need a power of 8 instead of 5, 2 fits perfectly into it, and if you need something like 8.5, the 2 can just round it out to the nearest power.

    You could easily do 1, but then it's more calculations, 2 is just overall easier to work with than 1 or more than 2.
     
  5. Ian Smithers

    Ian Smithers

    Joined:
    Mar 15, 2011
    Posts:
    68
    Great that answers my question, thank you.
     
  6. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,878

    No problem lol....

    I wondered the same thing at first, then I started studying all the shaders Unity did, and everything was *2, at least the parts I worried about, didn't really look at anything else lol.

    Just started tweaking numbers and was like AHHH okay, makes sense lol.