Search Unity

StereoCombiner help

Discussion in 'Shaders' started by Jonathan Czeck, Oct 20, 2005.

  1. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Hello, I have a fixed function subshader working with two passes how I want just fine and am trying to do a one pass shader using an ATI fragment program. (I'm on a 9200 and can't play with the Cg :( (Gonna borrow someone's laptop this weekend a bit for that 8) ) )

    Anyways, I can't get this new and improved subshader to be called! It will only use the second fixed function one.

    What am I doing incorrectly?

    Code (csharp):
    1.  
    2. Shader "Graveck/StereoCombiner"
    3. {
    4.     Properties
    5.     {
    6.         _TexL ("Left Eye Render Texture", RECT) = "white" {}
    7.         _TexR ("Right Eye Render Texture", RECT) = "white" {}
    8.         _LColor ("Left Eye Component Modifier", Color) = (1,0,0,0)
    9.         _RColor ("Right Eye Component Modifier", Color) = (0,1,1,0)
    10.     }
    11.     SubShader
    12.     {
    13.         Pass
    14.         {
    15.             Program ""
    16.             {
    17.                 SubProgram
    18.                 {
    19.                     Local 0, [_LColor]
    20.                     Local 1, [_RColor]
    21. "!!ATIfs1.0
    22. StartConstants;
    23.     CONSTANT c0 = program.local[0];
    24.     CONSTANT c1 = program.local[1];
    25. EndConstants;
    26.  
    27. StartOutputPass;
    28.     SampleMap r0, t0.stq_dq;
    29.     SampleMap r1, t1.stq_dq;           
    30.     MUL r0, r0, c0
    31.     MAD r0, r1, c1, r0
    32. EndPass;
    33. "
    34.                 }
    35.             }
    36.             SetTexture [_TexL]  { combine texture }
    37.             SetTexture [_TexR]  { combine texture }
    38.         }
    39.     }
    40.     SubShader
    41.     {
    42.         cull off
    43.         Lighting off
    44.         ZTest Always
    45.         ZWrite Off
    46.         Blend One One
    47.        
    48.         Pass
    49.         {
    50.             SetTexture [_TexL]
    51.             {
    52.                 constantColor [_LColor]
    53.                 combine constant * texture
    54.             }
    55.         }
    56.        
    57.         Pass
    58.         {
    59.             SetTexture [_TexR]
    60.             {
    61.                 constantColor [_RColor]
    62.                 combine constant * texture
    63.             }
    64.         }
    65.     }
    66. }
    67.  
    Thank you!
    -Jon

    p.s. Peter, you wanted ShaderLab questions? Here's your ShaderLab questions! :p ;)

    edit: updated output pass
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    For starters I think my output pass may be incorrect.

    I had:
    Code (csharp):
    1.  
    2. StartOutputPass;
    3.     SampleMap r1, t0.stq_dq;
    4.     SampleMap r2, t1.stq_dq;           
    5.     MUL r0, r1, c0
    6.     MAD r0, r2, c1, r0
    7. EndPass;
    8.  
    But should have:
    Code (csharp):
    1.  
    2. StartOutputPass;
    3.     SampleMap r0, t0.stq_dq;
    4.     SampleMap r1, t1.stq_dq;           
    5.     MUL r0, r0, c0
    6.     MAD r0, r1, c1, r0
    7. EndPass;
    8.  
    I think it should be like that because the destination of SampleMap determines which texture unit to sample from. Am I on the correct path?

    -Jon
     
  3. PeterDahl

    PeterDahl

    Joined:
    Jun 13, 2005
    Posts:
    61
    Hi Aarku, and thanks for the question...

    Yep, its correct that the destination of SampleMap should be the same af the register which the texture is bound to. What do you see on the screen, the result from the fixed function pass ?

    I would put in a vertex program too, so you make sure that you get the correct texture coordinates into those two registers you sample from.

    Have you tried to output a fixed color only in the fragment program, just to make sure that everything else is ok ? When you see the fixed color you can try to put your other code back...

    One thing though, from where I sit it seems like the MUL and MAD lines in the program is missing semi colon at the end, might want to fix that first, if it is not only a misprint in the post ;-)

    - Peter
     
  4. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    It was a dratted semi colon problem. :)

    That fixed it.

    I was confirming that the fixed function one was getting called by commenting out the Blend line (makes it nice and blue/green)

    Thanks!
    -Jon