Scratched Film
From GameStudio Wiki
[edit]
Lite-C:
Material and function to adjust the effect:
//Scrached Film
BMAP* Noise2_bmap = "noise1.jpg";
MATERIAL* ScrachedFilm_mat =
{
skin1 = Noise2_bmap;
effect = "ScrachedFilm.fx";
}
function ScrachedFilm_set_Value(SideScrollSpeed)
{
ScrachedFilm_mat.skill1 = floatv(SideScrollSpeed); //usually a small value like 0.01
}
The ScrachedFilm.fx file:
//////////////////////////////////////////////////////////
////Scrached Film Effect from the Nvidia Shaderlibrary////
//////////////////////////////////////////////////////////
float4 vecSkill1; //Side Scroll Speed
float4 vecTime;
float Speed = 10.0f; //Speed (Slower=Longer Scratches)
//float Speed2 = 0.005f; //Side Scroll Speed
float ScratchIntensity = 0.65f; //Scratch Threshhold
float IS = 0.01f; //Scratch Width
static float ScanLine = (vecTime.w*Speed);
static float Side = (vecTime.w*vecSkill1.x);
texture TargetMap;
sampler postTex = sampler_state
{
texture = (TargetMap);
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = clamp;
AddressV = clamp;
};
texture mtlSkin1;
sampler Noise2DSamp = sampler_state
{
texture = (mtlSkin1);
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = Wrap;
AddressV = clamp;
};
float4 Scratch_PS(float2 TexCoord : TEXCOORD0) : COLOR
{
float4 img = tex2D(postTex,TexCoord);
float2 s = float2(TexCoord.x+Side,ScanLine);
float scratch = tex2D(Noise2DSamp,s).x;
scratch = 2.0f*(scratch - ScratchIntensity)/IS;
scratch = 1.0-abs(1.0f-scratch);
//scratch = scratch * 100.0f;
scratch = max(0,scratch);
//scratch = min(scratch,1.0f);
return img + float4(scratch.xxx,0);
}
technique Main
{
pass p001
{
VertexShader = null;
PixelShader = compile ps_2_0 Scratch_PS();
}
}
technique fallback { pass one { } }
You also need this image "noise1.jpg":
[edit]
C-Script
Material and function to adjust the effect:
//Scrached Film
bmap Noise2_bmap = "noise1.jpg";
material ScrachedFilm_mat
{
skin1 = Noise2_bmap;
effect = "ScrachedFilm.fx";
}
function ScrachedFilm_set_Value(SideScrollSpeed)
{
ScrachedFilm_mat.skill1 = floatv(SideScrollSpeed); //usually a small value like 0.01
}
The ScrachedFilm.fx file:
//////////////////////////////////////////////////////////
////Scrached Film Effect from the Nvidia Shaderlibrary////
//////////////////////////////////////////////////////////
float4 vecSkill1; //Side Scroll Speed
float4 vecTime;
float Speed = 10.0f; //Speed (Slower=Longer Scratches)
//float Speed2 = 0.005f; //Side Scroll Speed
float ScratchIntensity = 0.65f; //Scratch Threshhold
float IS = 0.01f; //Scratch Width
static float ScanLine = (vecTime.w*Speed);
static float Side = (vecTime.w*vecSkill1.x);
texture entSkin1;
sampler postTex = sampler_state
{
texture = (entSkin1);
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = clamp;
AddressV = clamp;
};
texture mtlSkin1;
sampler Noise2DSamp = sampler_state
{
texture = (mtlSkin1);
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = Wrap;
AddressV = clamp;
};
float4 Scratch_PS(float2 TexCoord : TEXCOORD0) : COLOR
{
float4 img = tex2D(postTex,TexCoord);
float2 s = float2(TexCoord.x+Side,ScanLine);
float scratch = tex2D(Noise2DSamp,s).x;
scratch = 2.0f*(scratch - ScratchIntensity)/IS;
scratch = 1.0-abs(1.0f-scratch);
//scratch = scratch * 100.0f;
scratch = max(0,scratch);
//scratch = min(scratch,1.0f);
return img + float4(scratch.xxx,0);
}
technique Main
{
pass p001
{
VertexShader = null;
PixelShader = compile ps_2_0 Scratch_PS();
}
}
You also need this image "noise1.jpg":
--Slin 01:41, 11 November 2007 (CET)
