Shake

From GameStudio Wiki

Jump to: navigation, search

Lite-C:


Material and function to adjust the effect:

//Shaking of the Screen
MATERIAL* ScreenShaking_mat =
{
	effect = "shake.fx";
}

function ScreenShaking_set_Value(Speed,Amplitude)
{
	ScreenShaking_mat.skill1 = floatv(Speed);	// should be around 1
	ScreenShaking_mat.skill2 = floatv(Amplitude);	// this shouldn´t be higher than 0.1
}

The shake.fx file:

/////////////////////////////////////////////////////////////////////////////
/////The Screen is shaking (nice for earthquakes or underwater effects)./////
/////////////////////////////////////////////////////////////////////////////


float4 vecSkill1;
float4 vecTime;

texture TargetMap;

sampler postTex = sampler_state
{
   texture = (TargetMap);
   MinFilter = linear;
   MagFilter = linear;
   MipFilter = linear;
   AddressU = Clamp;
   AddressV = Clamp;
};

float4 Shake_PS( float2 Tex : TEXCOORD0 ) : COLOR0
{
	float4 Color;
	
	Tex.y = Tex.y + (sin(vecSkill1[0]*vecTime.w)*vecSkill1[1]);
	Tex.x = Tex.x + (cos(vecSkill1[0]*vecTime.w)*vecSkill1[1]);
	
	Color = tex2D( postTex, Tex.xy);
	
	return Color;
}

technique tech_00
{
	pass pass_00
	{
		VertexShader = null;
		PixelShader = compile ps_2_0 Shake_PS();
	}
}

technique fallback { pass one { } }


C-Script


Material and function to adjust the effect:

//Shaking of the Screen
material ScreenShaking_mat
{
	effect = "shake.fx";
}

function ScreenShaking_set_Value(Speed,Amplitude)
{
	ScreenShaking_mat.skill1 = floatv(Speed);	// should be around 1
	ScreenShaking_mat.skill2 = floatv(Amplitude);	// this shouldn´t be higher than 0.1
}

The shake.fx file:

/////////////////////////////////////////////////////////////////////////////
/////The Screen is shaking (nice for earthquakes or underwater effects)./////
/////////////////////////////////////////////////////////////////////////////


float4 vecSkill1;
float4 vecTime;

texture entSkin1;

sampler postTex = sampler_state
{
   texture = (entSkin1);
   MinFilter = linear;
   MagFilter = linear;
   MipFilter = linear;
   AddressU = Clamp;
   AddressV = Clamp;
};

float4 Shake_PS( float2 Tex : TEXCOORD0 ) : COLOR0
{
	float4 Color;
	
	Tex.y = Tex.y + (sin(vecSkill1[0]*vecTime.w)*vecSkill1[1]);
	Tex.x = Tex.x + (cos(vecSkill1[0]*vecTime.w)*vecSkill1[1]);
	
	Color = tex2D( postTex, Tex.xy);
	
	return Color;
}

technique tech_00
{
	pass pass_00
	{
		VertexShader = null;
		PixelShader = compile ps_2_0 Shake_PS();
	}
}

technique tech_01
{
	pass pass_00
	{
		Texture[0] = <entSkin1>;
	}
}

--Slin 01:30, 11 November 2007 (CET)

Personal tools