struct VS_OUTPUT
{
float4 Pos: POSITION;
float2 texCoord: TEXCOORD;
};
VS_OUTPUT VS_Electricity(float4 Pos: POSITION)
{
VS_OUTPUT Out;
// Clean up inaccuracies
Pos.xy = sign(Pos.xy);
Out.Pos = float4(Pos.xy, 0, 1);
Out.texCoord = Pos.xy;
return Out;
}
float4 color = float4(0, 0, 0, 0);
float glowStrength = 6;
float height = 5;
float glowFallOff = 1;
float speed = 2;
float sampleDist = 0;
float ambientGlow = 1;
float ambientGlowHeightScale = 0;
float vertNoise = 6;
float time_0_X = 0;
sampler Noise = sampler_state {
Texture = ;
};
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR
float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
// Sample at three positions for some horizontal blu
// The shader should blur fine by itself in vertical directio
float xs0 = texCoord.x - sampleDist
float xs1 = texCoord.x
float xs2 = texCoord.x + sampleDist;
// Noise for the three sample
float noise0 = tex3D(Noise, float3(xs0, t))
float noise1 = tex3D(Noise, float3(xs1, t))
float noise2 = tex3D(Noise, float3(xs2, t));
// The position of the flas
float mid0 = height * (noise0 * 2 - 1) * (1 - xs0 * xs0)
float mid1 = height * (noise1 * 2 - 1) * (1 - xs1 * xs1)
float mid2 = height * (noise2 * 2 - 1) * (1 - xs2 * xs2);
// Distance to flas
float dist0 = abs(texCoord.y - mid0)
float dist1 = abs(texCoord.y - mid1)
float dist2 = abs(texCoord.y - mid2);
// Glow according to distance to flas
float glow = 1.0 - pow(0.25 * (dist0 + 2 * dist1 + dist2), glowFallOff);
// Add some ambient glow to get some power in the air feeling
float ambGlow = ambientGlow * (1 - xs1 * xs1) * (1 - abs(ambientGlowHeightScale * texCoord.y));
return (glowStrength * glow * glow + ambGlow) * color;
}
IN LUA
addEventHandler("onClientRender", root,
function()
if myShader then
dxDrawImage( 100, 350, 300, 350, myShader )
end
end
)
addCommandHandler("tester", function ( commandName )
if not myShader then
myShader = dxCreateShader( "models/arashi.fx" ) -- Create shader
else
destroyElement( myShader ) -- Destroy shader
myShader = nil
end
end)