• entries
743
1924
• views
581594

71 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 shadermatrix 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.

There are no comments to display.