Search Unity

Getting current pass number into a vertex shader

Discussion in 'Shaders' started by Jonathan Czeck, Apr 12, 2007.

  1. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Is this doable? Say I wanted to call a vertex shader over and over using UsePass and just change a value based on the pass number. (Yeah for a basic fur shader)

    Or would I need to have duplicate the vertex shader a bunch of times and change one number?

    -Jon
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Directly - not really. What you can do is define the vertex shader code in separate .cginc file and include that (take a look at grass shaders for example). Or there is an almost-hidden feature with using Cg between CGINCLUDE/ENDCG blocks (not CGPROGRAM/ENDCG); the contents will be "pasted" into any further CGPROGRAM blocks (Reflective water shader uses that).
     
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I'll do something like that. I'm kind of curious as to how the fur shader code shaunis pasted uses PASSCOUNT and PASSINDEX. It looked like Cg from here.

    Thanks for the response!
    -Jon
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    It does look like an .fx file; however there's no automated way to use pass count/index in .fx files either. Of course, if that shader is from some tech demo, then the tech demo can just set passcount/passindex properties before drawing each pass.
     
  5. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Its a DX9 HLSL shader and has a number of input paramters, namely;
    1. Fur Length (A float between 0.5 and 3)
    2. Fur Thickness (A float between 1 and 5)
    3. A Noise texture for generating the "fibers"

    The nearest light and lightcolor parameters are automatically passed from the object.
     
  6. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    How is the pass number passed in? I assume it's also passed in somewhere from "the code"
     
  7. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    When writing the Shader - certain manually exposed parameters can be defined, for example:
    Code (csharp):
    1.  
    2. float myTestParam <float UIMin=0.1; UIMax=5.0;> = 3.0;
    3.  
    UImin and max define the limits of the parameter and the final value is the default.

    Other parameters are exposed automatically and change depending on the material and object binding.

    This can be modified at runtime. It a Virtools specific feature and not related to standard shader code AFAIK.

    Cheers
    Shaun