Jump to content
  • Advertisement
Sign in to follow this  
ajithk

Communication between shaders

This topic is 983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,

I have defined a struct VS_OUT
{
float4 clip_pos : SV_POSITION;
float2 vtex : PXTEX;
float3 l_vec : LIGHT_VECTOR;
float3 n_vec : NOR_VECTOR;
};

The vertex shader passes this structure to next stage. In pixel shader I declared the following struct as input

struct PS_IN
{
float2 vtex : PXTEX;
float3 pl_vec : LIGHT_VECTOR;
float4 clip_pos : SV_POSITION;
float3 pn_vec : NOR_VECTOR;
};

It didn't work as expected. When I checked articles on msdn and in Frank Luna book, I came to know of the requirement that output and input structs of consecutive stages should be same. So in pixel shader input struct, I shifted third variable clip_pos to the first place. Everything worked fine.

Which brings me to the question, if the same struct is to be used between the shaders, how am I supposed to use SV_semantics corresponding to a particular shader. For example, if a geometry shader comes after vertex shader, how can I use SV_GSInstanceID.

Typically geometry shader looks like this

void GS(triangle VS_OUT input[3], inout TriangleStream Tristream)

Now how do I declare a input variable with SV_GSInstanceID. More generally, how am I supposed to access SV_semantics corresponding to a particular shader? Btw, I am using shader model 5.0, if that makes a difference

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

You can (and probably have to) tell your geometry shader the vertex layout struct of your output stream; going by your example it would look like so:

void GS(triangle VS_OUT input[3], inout TriangleStream<GS_OUT> Tristream);

As for getting the system value, since this is an input to the shader stage itself rather than coming from the input vertices, I believe it should be declared as its own input to the geometry shader function:

void GS(triangle VS_OUT input[3], uint gsId : SV_GSInstanceId, inout TriangleStream<GS_OUT> Tristream);

This works for other types of shader / system-values as well:

hs_out HS(InputPatch<vs_out, 6> p, uint i : SV_OutputControlPointID, uint patchId : SV_PrimitiveID);

For a shader type that takes its input as the direct output of the previous stage, for example vertex to pixel shaders, you should be able to declare the system value semantic as part of the output from your vertex shader and simply not set it from your vertex shader. The above approach of adding it as another input argument should also work however, and probably looks cleaner.

Edited by Husbjörn

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!