Vertex shader output to Pixel shader input

Anything relating to the DirectX 10 & 11 families

Vertex shader output to Pixel shader input

Postby Hieran_Del8 » Fri Jul 16, 2010 6:27 am

Wow. I've been struggling to get a simple dx11 renderer to work for testing purposes for one day short of one month. The worst part of resolving this is I figured it out by accident. What a pain this has been!! :evil:

The problem is caused due to a difference in perspective in programming hlsl for dx9 vs 10+. Here's the situation:
Code: Select all
uniform extern float4x4 g_wvp;

struct VSInput
{
   float3 posL : POSITION0;
   float4 color : COLOR0;
};

struct VSOutput
{
   float4 posH : POSITION0;
   float4 color : TEXCOORD0;
};

VSOutput VShader(VSInput input)
{
   VSOutput output = (VSOutput)0;
   output.posH = mul(float4(input.posL, 1.0f), g_wvp);
   output.color = input.color;
   return output;
}

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

Yes, in this case, the pixel shader is pretty useless, but it's for simplicity. The vertex shader receives as input a float3 position, and float4 color. The output is a float4 transformed homogeneous position, and a float4 color.

The pixel shader receives only the float4 color as input because the extra data is not necessary.

However, this would be invalid for dx10+. Dx10+ requires that the vertex shader output match the pixel shader input. So the equivalent shaders would be:
Code: Select all
cbuffer ConstBuffer : register(b0)
{
   matrix g_wvp;
}

struct VSInput
{
   float3 posL : POSITION0;
   float4 color : COLOR0;
};

struct VStoPS
{
   float4 posH : SV_Position;
   float4 color : TEXCOORD0;
};

VStoPS VShader(VSInput input)
{
   VStoPS output = (VStoPS)0;
   output.posH = mul(float4(input.posL, 1.0f), g_wvp);
   output.color = input.color;
   return output;
}

float4 PShader(VStoPS input) : SV_Target
{
   return input.color;
}

Note that even though the positional data is not used, it must be passed to the pixel shader.

This has been the hangup for me successfully rendering a simple cube on the screen with position, color, and texture coordinate data. What a pain!!
Image
User avatar
Hieran_Del8
Most Valuble Contributor
 
Posts: 349
Joined: Thu Nov 06, 2008 4:59 am
Location: Marengo, IL

Return to DirectX 10+

Who is online

Users browsing this forum: No registered users and 1 guest

cron