Search Unity

Setting shader parameters

Discussion in 'Shaders' started by cranky, Apr 18, 2015.

  1. cranky

    cranky

    Joined:
    Jun 11, 2014
    Posts:
    180
    Hey guys, I'm a little bit of a shader noob, but I am experienced with C#. I am creating post-processing screen tint shaders (so your screen tints red and quickly fades back to normal when you take damage, for example). These effects use an enumeration to determine the fade out curve, a float for the fade out speed, and a float for the overall intensity. This is working just fine now, but I am setting the shader parameters every frame with OnRenderImage because the intensity is modulated by the fade out curve in real time. I feel this is inefficient. Also, I want to be able to have multiple screen tints going on at once, with maybe different colors being blended together.

    My problem lies with passing this information to the shader. Is it fine to pass this information every frame? Or should I only pass information when it changes and let the GPU calculate the fade function itself (which still requires me to pass time as parameter every frame...)?

    Also, I want to be able to support at LEAST 3 different tints at once. Should I use an array, or multiple parameters? Does CG have a parameter limit?

    Thanks for reading!
     
  2. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    how about calculate the multiple tints in CPU(C#),
    and only send it(1 final color) to GPU for the changing frames ?
    So when no damage/buff/other effect is present, just don't send anything to GPU
     
  3. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Send them every frame, you can't guarantee your data will be valid the next frame.
    (Obviously don't do anything if the effect doesn't actually run)