Waving Grass 1

From GameStudio Wiki

Jump to: navigation, search

Very basic "Waving Grass" shader. Adjust the speed and the range values to your needs. The material needs the TANGENT flag to be set.

texture   entSkin1;
float4x4  matWorldViewProj;
float4    vecTime;

#define speed 0.3
#define range 5

sampler grassSampler = sampler_state 
{
	Texture = <entSkin1>;
	
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};



struct VS_INPUT
{
	float3 Pos      : POSITION; 
	float2 Tex      : TEXCOORD0;
	float2 Rotation : TEXCOORD2;
};

struct VS_OUTPUT
{
	float4 Pos      : POSITION;
	float2 Tex      : TEXCOORD0;
};



// --- Technique GrassPS
VS_OUTPUT vs_grass(VS_INPUT IN) 
{
	
	VS_OUTPUT OUT;
	float4 pos = float4(IN.Pos,1);


	if( IN.Tex.y <= 0.5 )
	{
		pos.x += sin(IN.Rotation.x * vecTime.w * speed)*range;
		pos.z += sin(IN.Rotation.y * vecTime.w * speed)*range;
	}

	OUT.Pos = mul(pos, matWorldViewProj);
	OUT.Tex = IN.Tex;
	
	return OUT;
}


float4 ps_grass(VS_OUTPUT IN) : COLOR 
{	
	return tex2D(grassSampler,IN.Tex);
}


// Techniques
technique grass 
{
	pass p0 
	{
		zWriteEnable = true;
		alphaTestEnable = true;
		VertexShader = compile vs_1_1 vs_grass();
		PixelShader = compile ps_1_1 ps_grass();
	}
}

--Slin 22:06, 28 November 2007 (CET)

Personal tools