0

How can I output something from the vertex shader to the pixel shader multiple times. Eg I need to output the vertex color as a float 4 to the pixel shader 4 times after performing some different math operations on the vertex color in the vert shader?

can I do this? I tried creating an empty float4 color2, reading the In.vertcolor from In.color and outputing that... I dont get any errors but my texture is white. Its just reading any empty float 4...

here is my code for this section. Thanks!

//////////////////////////////////////////////////////////////
// Structs section 
// input from application
struct a2v {
float4 position  : POSITION;
float4 normal    : NORMAL;
float2 texCoord : TEXCOORD0;
float2 secondUV : TEXCOORD1;
float4 color: COLOR;
float4 color2;

};

// output to fragment program
struct v2f {
    float4 position        : POSITION;
    float2 texCoord : TEXCOORD0;

    float2 secondUV : TEXCOORD1;
    float3 worldNormal     : TEXCOORD2;
    float4 color: COLOR;
    float4 color2;

};



//////////////////////////////////////////////////////////////
// Vertex Shader 

v2f vShader(a2v In)
{
v2f Out;
Out.texCoord = In.texCoord;
Out.secondUV = In.secondUV;

float4 Mask1 = floor ((fmod((In.color  * 100f ), 10f))) *.111f;
float4 Mask2 = floor ((fmod((In.color2  * 100f ), 10f))) *.111f;
Out.color = Mask1;
Out.color2 = Mask2;


Out.position = mul(WorldViewProjection, In.position);
Out.worldNormal = mul(WorldInverseTranspose, In.normal).xyz;

return Out;
}
fghajhe
  • 239
  • 1
  • 2
  • 8

1 Answers1

0

There is a COLOR1 binding attribute which you can assign to the 'color2' field in a2v and v2f structures.

Be sure to allocate the secondary color (COLOR1) as an attribute stream in you application.

Viktor Latypov
  • 14,289
  • 3
  • 40
  • 55
  • Edit: Thanks so much! I spent a couple hours stuck on this. Is there anyway to output the color multiple more times or is 2 the limit? I ask becuase Unity Game Engine seems to stop working after COLOR1, eg COLOR2 doesnt work. Well at least I can output it twice thanks to you. One of the shaders I want to port needs me to perform some math on the vertex colors in the vertex shader 4 times and output their different results to the pixel shader. Maya cgfx is fine becuase it supports multiple color sets so it can take COLOR4 etc. But Unity on the other hand... seems to only take COLOR, COLOR1 – fghajhe Jun 27 '12 at 14:25
  • Sorry, not an expert on unity. Look for every possible Aux streams. Maybe you can pack the Color2 into tangent/binormal arrays if you don't use them for other stuff. – Viktor Latypov Jun 27 '12 at 14:29
  • Okay no problem. Just being able to output it twice helps me out alot! I will look into packing in other arrays too – fghajhe Jun 27 '12 at 14:32