• Create Account

## DX11 - Vertex To Pixel Shaders - Return Types

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Migi0027 (肉コーダ)  Members

Posted 24 May 2013 - 11:44 AM

Hello once again!

I have a question that hasn't really been bothering me, but it interests me!

So consider the following simple shader:

cbuffer ConstantObjectBuffer : register(c1)
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;

matrix rotationMatrix;
}

cbuffer ConstantFrameBuffer : register(c0)
{
float4 lDir;
float4 lColor;
}

struct VOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 normal : NORMAL)
{
VOut output;
output.position = mul(position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);

float4 n = normalize(mul(rotationMatrix, normal));
float diffusebrightness = saturate(dot(n, lDir));
output.color = lColor * diffusebrightness;

return output;
}

float4 PShader(VOut input) : SV_TARGET
{
return input.color;
}


Now in the vertex shaders parameters, it has the vertex position and normal, simple right? But these needs to be defined in the input layout, which I fully understand. But the structure that the vertex shader returns to the pixel shader, called VOut, also have these type definitions. Now what I mean with 'type definitions' (NOT A REAL THING  ), is the following:

In the vertex function VOut VShader(float4 position : POSITION, float4 normal : NORMAL), you see that we have a 4 component float called position, and after that we define the input layout schematic: "POSITION". Now the "POSITION" is what I call a type definition  .

So back to the vertex returning VOut. In the structure VOut I also define different variables, like .color, and give it a schematic : COLOR, now if I did this in the vertex shader it would crash! But not in this return structure.... So what is the point in defining the non-existing schematic in the vertex return structure?

PS. I know that you have to define SV_POSITION as a schematic, as it's kinda fundamental!

THANKS!

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/cuboidzone.wordpress.com/

### #2Racoonacoon  Members

Posted 24 May 2013 - 02:29 PM

Hey Migi0027,

The semantic does exist. It exists for the pixel shader.

You could write the pixel shader like this if you wanted:

float4 PShader(float4 color : COLOR) : SV_TARGET
{
return color;
}


The SV_POSITION semantic exists for the non-programmable rasterization stage.

Edited by Racoonacoon, 24 May 2013 - 02:30 PM.

### #3Migi0027 (肉コーダ)  Members

Posted 24 May 2013 - 03:08 PM

So the semantic is automatically created for each variable, which is sen't to the pixel shader?

Because I could type in some crazy names and it would still work.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/cuboidzone.wordpress.com/

### #4insan3  Members

Posted 26 May 2013 - 09:01 AM

float5(shaderspixel  color: COLOR) :SV TARGET

{

return COLOR;

}

if (COLOR == !=COLOR)

return 0;

}

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.