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

Why could we have more than one forwardbase pass in a shader

Discussion in 'Shaders' started by Lulucifer, Feb 17, 2013.

  1. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    Why could we have more than one forwardbase pass in a SubShader,
    and they will all be executed,
    could we have more than one ForwardAdd or PrePass in a SubShader?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes, you could have multiple passes of the same type, and they will all be executed.

    However I'm not sure why you would want that - it's almost always more efficient to do stuff in one pass compared to multiple passes. Except if you're trying to do something really exotic.
     
  3. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    Thank you for your answer,
    Yes , it means more trick available for a new bie :)
     
  4. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    My first thought would be depth priming.
     
  5. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    But apparently,Unity dont set up Light inform frequently for each time send a pass to GPU, ie, it does not clear up used light data after a pass has been executed, it just set up light data before a pass will be executed,but dont clear when finished! so when it comes to lighting caculation, i dont think multiple passes of the same type is reliable when out of Unity's build in process
     
    Last edited: Feb 18, 2013
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Are you expecting light information to be different between two passes with the same tag?
     
  7. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    Not exaclty,
    Ie : I delete a light, but it's inform is still there, In the array ,not updated, Unitl the next time Unity prepare data for the same type pass before send data to GPU, so the situation could forsee, but sometimes when comes to many different type passes, this could get you messed up,
    especially when you dont work with surface shader, write your own vertex+fragment shader
     
  8. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    There's zero difference between a surface shader and a hand-written shader that does exactly the same thing.

    Anyway, if you delete a light, Unity should not set it's information to the shader. If you see other behavior, please file a bug with a repro project.
     
  9. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    There no bug there, Sorry about my poor expression,
    My mean is A Light First exist, in an array like unity_LightPosition[3] ,
    and late change it, so it moved to unity_LightPosition[2],if there is no another light has been set to unity_LightPosition[3], the old light is still there,maybe the unity_LightPosition[].w component or correspond unity_LightColor[] declares it is a invalid data
    It would be a little confusion for a guy who dont use func like ShadeVertexLights(),directly access the lights in array,

    After all there is still a big question confused me, about unity's cache,
    It is delivered herehttp://forum.unity3d.com/threads/170662-One-mat-applied-twice-with-porblem-happens

    Maybe there is a lot place available to cache things for performance,
    So it could be a big maze when data is cahced, when is not,
    Or maybe all cache is designed works perfectly fine, but something unexcepted happens, like Unity crashed,so the links broken
    and then it lead to something like link i provide
    and some times the cache still streched to Build

    so the problem is how do we know ,or could we disable the cache mechanism in the future edition
    or tell us how does Unity's cache works, so when problem happens , we could have a good guess to exclude possible cause

    Sorry about my boresome expression :)
     
    Last edited: Feb 19, 2013
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    unty_LightPosition/Color array will be filled with lights starting with the brightest one. If there are no more lights, the rest of the unity_LightColor array will be set to black color.