• Advertisement
Sign in to follow this  

Pixel Shader Input

This topic is 4310 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

A quick question: how is the input to a pixel shader determined? I've pretty much got the hang of vertex shaders; vertex shader input is determined by and declared to be the type of vertex I'm using (usually position, normal, etc.). Is there a relationship between the output of a vertex shader and the input to a pixel shader?

Share this post


Link to post
Share on other sites
Advertisement
Yes there is a relationship but the detail depends on the shader model you use.

Up to the 2.X model the output register have a predefined usage (color, texture coordinates, …). The pixel shader have input registers for the matching usage.

The shader model 3 allows you to define the usage for the outputs on the vertex side and for the inputs on the pixel shader side. After you have selected a vertex and a pixel shader the output of the vertex shader will routed to the inputs with the same usage.

In the case you use HLSL you should read about “Shader Semantic Syntax” in the documentation. You have to use the same semantic on the vertex outputs and the pixel inputs to make sure that the connected correct.

Share this post


Link to post
Share on other sites
Thank you very much Demirug, I hadn't found that shader semantics stuff when I was looking through the docs. So if, say, I have a vertex shader output like so:

struct VS_OUTPUT {
vector position : POSITION;
vector color : COLOR;
float2 tutv : TEXCOORD;
};

Then if I declare a pixel shader input:

struct PS_INPUT {
vector color : COLOR;
float2 tutv : TEXCOORD;
}

The color and texture from the vertex shader output match up to the pixel shader input?

If I were to define a second texture coordinate in the pixel shader input, I'm guessing that would be undefined (since it wasn't output from the vertex shader)? If I were to instead add that second texture coordinate to the vs output and not declare it in the ps input would that output be thrown away?

Thanks for your time,
-- John

Share this post


Link to post
Share on other sites
Quote:
Original post by john_t
If I were to define a second texture coordinate in the pixel shader input, I'm guessing that would be undefined (since it wasn't output from the vertex shader)?
I'm pretty sure you'll get a shader linkage error reported via the debug runtimes, and the Draw**() call will fail.

Quote:
Original post by john_t
If I were to instead add that second texture coordinate to the vs output and not declare it in the ps input would that output be thrown away?
This is correct as the PS input is a subset of the VS output.

hth
Jack

Share this post


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

  • Advertisement