Search Unity

Mix two or more shaders

Discussion in 'Shaders' started by VortexStudios, Jan 13, 2015.

  1. VortexStudios

    VortexStudios

    Joined:
    Jul 16, 2012
    Posts:
    84
    Hello everyone,

    I'm with a small issue, easy to solve, but I'm looking for a more user friendly way to solve...

    I'm made a pixelated and warp shader to port a game from constuct to unity, there any way to mix these two shaders os I just can do that with a multpass shader?
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Shaders are made of instructions. Mixing will involve combining instructions. However, mixing is not a defined term, so the question is unanswerable for now, in a way that will be useful to you.
     
  3. VortexStudios

    VortexStudios

    Joined:
    Jul 16, 2012
    Posts:
    84
    You can think about mix two shaders os two materials...
     
  4. TechnoCraft

    TechnoCraft

    Joined:
    Apr 6, 2012
    Posts:
    28
    Can you mix two shaders in a single material? No-t really in that sense. As Jessy said you can write a shader that uses shared cg instruction library (see UnityCG.cginc for example). You can use different "shader" functions for every pass and use shader blending to "mix" the resulting colors: http://docs.unity3d.com/Manual/SL-Blend.html
    DX11.1 has some nice features; exacly what you need, right? But these nice XOR features will not work on pre-DX11.1 graphic cards. The only way to do this is to rewrite and "merge" both shader functionality in one pass (shader program - dummy.shader). See vertex and fragment shader examples at http://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html.

    Further reading:
    https://cgcookie.com/unity/cgc-courses/noob-to-pro-shader-writing-for-unity-4-beginner/
    http://en.wikibooks.org/wiki/Cg_Programming/Unity
     
    Jessy likes this.