Jump to content
  • entries
    743
  • comments
    1924
  • views
    583687

Vertex shader success

Sign in to follow this  
Aardvajk

78 views

Well, I've just written my very first ever vertex shader. All a lot easier than I thought it would be really.


// Paul's first shader

matrix world;
matrix view;
matrix viewproj;

vector lightdir=vector(-1,1,-1,0);

bool do_light=true;

struct VS_INPUT
{
vector position : POSITION;
vector normal : NORMAL;
vector diffuse : COLOR;
float2 texcoord : TEXCOORD;
};

struct VS_OUTPUT
{
vector position : POSITION;
vector diffuse : COLOR;
float2 texcoord : TEXCOORD;
};

VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output=(VS_OUTPUT)0;

output.position=mul(input.position,world);
output.position=mul(output.position,viewproj);

output.texcoord=input.texcoord;

if(do_light)
{
vector light=mul(lightdir,view);

input.normal.w=0;
input.normal=mul(input.normal,view);

float s=dot(light,input.normal);
if(s<=0) s=0.1;

output.diffuse=input.diffuse*s;
}
else
{
output.diffuse=input.diffuse;
}

return output;
}



It just does a very simple light calculation, which I can switch on and off so that I can draw the bone triangles with the same shader without lighting.

This is moving towards doing the posing inside a shader. I think all I need to do is have a global array of matrices in the shader that I set in the program, then extend my vertex declaration to include two bone indices and weights.

I should then be able to just do the same calculations in the shader that I currently do in the program.

Exciting stuff.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!