fade material's skin in/out

Posted By: 3run

fade material's skin in/out - 03/05/15 10:44

I've found a postprocessing shader (I guess it was made by Emre), which blinks the view, adds noise effect and so on.
I tried to remove everything (all effects), but to leave the noise effect, and I guess I've done it correctly, here the .fx:
Code:
texture TargetMap;
texture mtlSkin1;

float4 vecTime;

float noiseSize = 0.9f;

sampler View_Tex = sampler_state {
	texture = <TargetMap>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;  
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler Noise_Tex = sampler_state {
	texture = <mtlSkin1>;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = Linear;  
	AddressU = wrap;
	AddressV = wrap;
};

float4 Noise_Effect_PS( float2 Tex : TEXCOORD0 ) : COLOR {
	
	float4 Color = float4(1, 1, 1, 1);
	
	Tex.y = Tex.y + 0.05 * 0.01 * cos(vecTime.w);
	
	float4 CAMERA_VIEW = tex2D(View_Tex, Tex);
	
	float4 NOISE_EFFECT = tex2D(Noise_Tex, float3(2 * Tex * noiseSize + vecTime.w, 1)) + 0.5 * tex2D(Noise_Tex, float3(1.05 * Tex * noiseSize - vecTime.w, 1)) + 0.1;

	Color *= CAMERA_VIEW;
	Color *= NOISE_EFFECT;

	return(Color);
}

technique Noise_Effect
{
	pass one
	{
		PixelShader = compile ps_2_0 Noise_Effect_PS();
	}
}

But now, when I've ripped it out, I wanted to know, how to make the skin (Noise_Tex) fade in and out, when I need it to. So f.e. when I walk close up to something in my game, the noise effect will increase, and when I walk away then it should decrease... I'm pretty sure, that this is a very simple task, but I would really appreciate some advice or help (maybe there is a better way to archive what I'm looking for, I'm open for suggestions, I've tried example made by Slin which uses panels, but I didn't like it, so I guess I won't go panels way).

Thanks in advance! And best regards.
Posted By: Superku

Re: fade material's skin in/out - 03/05/15 10:53

Create a var variable (fade_progress) in your script which handles the fade in/ out stuff, then write
float fade_progress_var;
at the beginning of your fx file.
Now put
NOISE_EFFECT = lerp(NOISE_EFFECT,1,fade_progress);
before the Color *= NOISE_EFFECT line.

I assume that fade_progress is in 0..1, otherwise (if you want to keep it in the interval 0..100) write (fade_progress/100) as the 3rd argument in lerp.
Posted By: 3run

Re: fade material's skin in/out - 03/05/15 14:45

Works great, thank you very much!
© 2024 lite-C Forums