Skip to main content
gamedev.net
🔒 Locked

Basic HLSL Vertex Shader Problem

Started by -indirectX- 1 reply 950+ views
Original Post
-indirectX-
-indirectX-
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
--------------------------------www.hughosborne.co.uk[email=hugh.osborne@googlemail.com]hugh.osborne@googlemail.com[/email]
Palish
Palish
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
-indirectX-
-indirectX-
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...
--------------------------------www.hughosborne.co.uk[email=hugh.osborne@googlemail.com]hugh.osborne@googlemail.com[/email]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.