Search Unity

Please help me!

Discussion in 'Shaders' started by thedawn, Mar 28, 2017.

  1. thedawn

    thedawn

    Joined:
    Mar 28, 2017
    Posts:
    8
    I want to write a multiPass shader.And I want to use Shader.EnableKeyword or Shader.DisableKeyword to control What pass I will use. How can i achieving it?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Not possible.
     
  3. thedawn

    thedawn

    Joined:
    Mar 28, 2017
    Posts:
    8
    Enn....Do u have any good idea to switch Pass runtime?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Depends on what you're trying to do. If you're rendering a mesh manually using GL, Graphics, or CommandBuffers you can use SetPass or the command buffer draw commands let you set a pass.
    https://docs.unity3d.com/ScriptReference/Material.SetPass.html
    https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.DrawMesh.html

    I don't think SetPass does anything for an object placed in the scene, but it might. I believe internally Unity is already doing these kinds of SetPass commands for rendering objects so it might blow away your setting, but it's worth a try.
     
    Last edited: Mar 28, 2017
  5. thedawn

    thedawn

    Joined:
    Mar 28, 2017
    Posts:
    8
    Very thanks for your answer.But maybe you don't understand my mind.I write a shader.The shader contain 2 Pass.Sometines I want to use Pass 1 and 2 render,but sometimes I want to only use Pass 1 to render.How to switch the two situations?
     
  6. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    you can only wait for Unity 5.6
    if your second pass is not coupled with the first pass(something like selection outline),
    CommandBuffer.DrawRenderer
    is the way to go.

    for example you can use command buffer to add layered effect to a skinned mesh.

     
    Last edited: Mar 28, 2017
  7. thedawn

    thedawn

    Joined:
    Mar 28, 2017
    Posts:
    8
    Very Thanks,the second way looks so difficult.I just wait for Unity 5.6,It looks so cool!