Jump to content
  • Advertisement
Sign in to follow this  
shoez

D3D11 Drawing a simple line

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

Why do examples specify the position as having 4 float values in the shader when in the code it is only using a 3 element vector? whats with this?



struct SVertex
{
D3DXVECTOR3 position;
D3DXVECTOR4 color;
};




PS_Shader code



////////////////////////////////////////////////////////////////////////////////
// Filename: color.ps
////////////////////////////////////////////////////////////////////////////////


//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float4 color : COLOR;
};


////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 PS_Main(PixelInputType input) : SV_TARGET
{
return input.color;
}

Share this post


Link to post
Share on other sites
Advertisement
The vertex shader can take in the position with 3 floats. This is totally fine.
The output of the last shader stage before the rasterizer must contain the SV_Position semantic. If you don't use tessellation of geometry shaders that would be your vertex shader. At this point the position is in homogeneous coordinates, which means it is lifted from 3D to 4D to allow projections and affine transformations.
The pixel shader can also get a SV_Position as input, but now the xy components store the screen coordinate in (0.5,0.5) to (screenWidth+0.5, screenHeight+0.5) and the z component is the non-linear depth in [0..1] (already divided by w). The w component stores 1/w = 1/viewSpaceDepth. In OpenGL-land it is the reciprocal by the way…

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!