Sign in to follow this  

[HLSL] shader output question

Recommended Posts

hi all specially to directx and graphics master :)

I'm having confusion on why is POSITION is always required to be outputted in vertex shader (Input in pixel shader)?

I am trying to build a shadow depth map texture in HLSL.
The pixel shader of this only outputs the depth in the rendertarget.

[source lang="C"]

struct SMapVertexToPixel
float4 Position : POSITION; //<-- why is this needed?

float4 Position2D : TEXCOORD0;

struct SMapPixelToFrame
float4 Color : COLOR0;

SMapVertexToPixel ShadowMapVertexShader( float4 inPos : POSITION)
SMapVertexToPixel Output = (SMapVertexToPixel)0;

Output.Position = mul(inPos, xLightsWorldViewProjection); //<-- why is this needed?
Output.Position2D = Output.Position;

return Output;

SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
SMapPixelToFrame Output = (SMapPixelToFrame)0;

Output.Color = PSIn.Position2D.z/PSIn.Position2D.w;

return Output;


I have questions;

- In the above code, why is it POSITION is needed to be outputted in the vertex shader when it is not needed in the pixel shader?

- After Vertex shader outputs the POSITION, what will happen to this value since it is not used in Pixel shader?

-I experimented and tried a VS output structure without POSITION semantic, but it does not compile in shader, and i tried it WITH the POSITION semantic, and just set
any value, but it does not have render the correct depth,
it is when I output the correct POSITION semantic by multiplying it with its world matrix against viewProjection matrix of light,
then i got the correct result.
Why is this?

-Will the pixel shader be called in a Pixel that is not on the CLIP or viewport after clipping/view port stage?

Just clear my confusion dx masters? :)

thanks in advance

Share this post

Link to post
Share on other sites
The vertex position is sent to the [url=""]rasterizer[/url].

If the vertex shader didn't output a position, then where is the vertex on the screen?
If you don't know where the vertices are on the screen, then how do you know which pixels are covered by a triangle?
If you don't know which pixels are covered, which pixels should the pixel-shader be run on?

Hope that makes sense.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this