Jump to content
  • Advertisement
Sign in to follow this  
-indirectX-

Basic HLSL Vertex Shader Problem

This topic is 4554 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'm following the book, "3D Game Engine Programming" but instead of the assembly shaders, I want to implement HLSL shaders. I have used a few tutorials to set them up and am using a basic position HLSL shader from RenderMonkey. Here are the vertex and pixel shaders:
float4x4 matViewProjection;

struct VS_INPUT 
{
   float4 Position : POSITION0;
   
};

struct VS_OUTPUT 
{
   float4 Position : POSITION0;
   
};

VS_OUTPUT vs_main( VS_INPUT Input )
{
   VS_OUTPUT Output;

   Output.Position = mul( matViewProjection, Input.Position );
   
   return( Output );
   
}


float4 ps_main() : COLOR0
{   
   return( float4( 1.0f, 0.0f, 0.0f, 1.0f ) );
   
}


When I run the program, the shaders compile fine and there are no complaints creating the shaders. However, I don't see any shapes ( I should see a box ). I have found that when rendering POINTS rather than SOLID, I can see one red point in the centre of the screen. As the pixel shader is set to change any input to red, I know the pixel shader is working. Perhaps there is something wrong with the way the vertices are sent to the shader? I think I am setting the matViewProjection correctly too. As I really have no idea where the problem is I can't post any more code. Just ask if you need to see more though. Help is much appreciated. All the best, Hugh Osborne

Share this post


Link to post
Share on other sites
Advertisement
The line

Output.Position = mul( matViewProjection, Input.Position );

Should be

Output.Position = mul(float4(Input.Position.xyz,1.0f),matViewProjection);

The order of multiplying a vertex by a matrix vs a matrix by a vertex matters, and the vertex must be in float4 format (even though yours is, the last value, the w-value, may not be 1.0f).

Shawn

Share this post


Link to post
Share on other sites
Hmm, no joy i'm afraid. It's more likely to be something wrong with my code although I don't know what. I tried setting up assembly shaders ( NOT using RenderMoney "Disassembeld shaders" ) and that worked fine, everything rendered properly...

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!