Jump to content
  • Advertisement
Sign in to follow this  

[HLSL] shader output question

This topic is 2684 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 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 rasterizer.

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
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!