Game Development Community

dev|Pro Game Development Curriculum

Basic TSE Shader Templates

by Entr0py · 12/14/2006 (2:59 pm) · 2 comments

I made these basic shaders for when I need to make a new shader from scratch. Since all the shader code I could find on this site was for a specific use, I decided to go ahead and submit this as a resource. I tried to stick with the general format of the other shaders in TSE.


Basic Color Shader
This shader will apply a flat color to an object.

Vertex Shader:
uniform float4x4 view_proj_matrix: register(C0);

struct FragOut {
   float4 Pos:     POSITION;
   float3 uv:      TEXCOORD0;
   float3 normal:  TEXCOORD1;
};

FragOut  main(float4 Pos: POSITION, float3 normal: NORMAL, float3 uv: TEXCOORD0){
   FragOut OUT;

   OUT.Pos = mul(view_proj_matrix, Pos);
   OUT.normal = normal;
   OUT.uv = uv;

   return OUT;
}

Pixel Shader:
struct ConnectData
{
	    float4 position           : POSITION; 
	    float2 uv			: TEXCOORD0;  
	    float3 normal             : TEXCOORD1;  
};

struct FragOut
{
float4 color : COLOR0;
};

FragOut main(ConnectData IN, float4 color	: COLOR0)
{
FragOut OUT;

OUT.color = float4(0.564, 0.284, 0.867, 1.0);

return OUT;
}

Basic Texture Shader
This shader will apply a basic texture to an object.

Vertex Shader:
uniform float4x4 modelview: register(C0);

struct FragOut
{
   float4 Pos 	: POSITION;
   float2 uv 	: TEXCOORD; 
};

FragOut main(	float4 pos 	: POSITION,
			float2 uv 	: TEXCOORD
			)
{
   FragOut OUT;
   OUT.Pos = mul( modelview, pos);
   OUT.uv = uv;

   return (OUT);
}

Pixel Shader:
uniform sampler2D diffuseMap: register(S0);

struct ConnectData
{
float2 uv			: TEXCOORD0;
float3 pos			: POSITION;
};

struct FragOut
{
float4 color		: COLOR0;
};

FragOut main( ConnectData IN, float4 color : COLOR0 )
{
	FragOut OUT;

    	OUT.color = color * (float4)tex2D(diffuseMap, IN.uv);
	return OUT;
}

#2
01/22/2007 (4:37 pm)
Very Sweet. I've been working with TGE for a while now but just purchases TSE/TGEA and I know nothing of shaders. I was looking for something just like this.