Jump to content
  • Advertisement
Sign in to follow this  
dAND3h

HLSL POSITION question

This topic is 2321 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, I was following riemers HLSL series here: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series3/Vertex_shader.php

I don't understand something. In his vertex declaration, he declared a Vector3 for position and a colour. But then, for the input into the vertex shader, and in the structure for the vertex shader, he has an input requesting a float4 position.

I don't get it, I thought the point of the vertex declaration was to tell the GPU exactly what information was coming, or am I missing something?

Share this post


Link to post
Share on other sites
Advertisement
I do not see what you are talking about. It looks like he is declaring float4 for Input vertex and in teh Output vertex structure he also has an float4

Share this post


Link to post
Share on other sites

I do not see what you are talking about. It looks like he is declaring float4 for Input vertex and in teh Output vertex structure he also has an float4


In his vertex declaration, he had this:

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0)
);


so, he used a vector3, which is same as a float3 here, but in the hlsl, he used a float4 for position. What is the actual meaning of position then? What is the 4th element?

Share this post


Link to post
Share on other sites
It's legal to do that in HLSL. The input assembler will set the w component to 1.0, which is convenient for a position since you want w to be 1 anyway so that you can transform it by a 4x4 matrix. If you want your shader to be more explicit, you can just have your shader take a float3 and add the 1 yourself.

Share this post


Link to post
Share on other sites
Ok, Makes sense. Another question, If I wanted to manipulate a triangles position over time on using the GPU for calculation, would I have my vertex input accepting another float4 : POSITION for the direction I want to move in, or how should I go about that?

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!