Jump to content
  • Advertisement
Sign in to follow this  
shoez

Vertex Shader Vertex question

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

If i pass a custom vertex structure into my vertex shader is it assumed to be in worldspace,model space,view space, or projection space?

for example if i pass the following vertex structs into my vertex shader how do i know/assume what coordinate space they are currently in?


struct SVertex
{

float x, y, z;
int nColor;
};


struct SVertex2
{

float x, y;
int nColor;
};

Share this post


Link to post
Share on other sites
Advertisement
The vertex shader always received the coordinate in local space.

For example if you did something like this.

struct Vertex{
float x,y,z;
};
Vertex v[]={
{-1,0,0},
{1,0,0},
{0,1,0},
};
The shader will received the v info just just like the definition. Unless you modify the vertex data directly then the data will be changed when pass to the shader.

So to sum it the shader always received your data in local space.

Share this post


Link to post
Share on other sites
Vertex data is completely arbitrary, you can use whatever coordinate space you want. The runtime doesn't care what space you initially use (or even what data you have in your vertex), as long as the vertex shader outputs a position that can be used for rasterization onto the render target.

Share this post


Link to post
Share on other sites
Matt is right - your input vertex data is totally arbitrary and can be whatever you want it to be. The key is that the vertex shader outputs clip space vertices - but it doesn't matter how they are generated. Some examples that I can think of off the top of my head that show the diversity of this idea:

  1. Standard projection - input geometry is defined in object space (or local space if you like) and then gets projected to clip space. This is probably the most common method.
  2. Post projection - the input geometry is already in clip space, and the vertex shader just passes its input positions to its output. This is common for GUI elements that are static and are view independent.
  3. Customized - some vertex shaders don't even have input vertices! It is possible to just use the input system value for vertex ID and then generate the data from there.


So there is lots of different ways that you can make it work - its all a matter of the algorithm you are using and what you want to do.

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!