Sign in to follow this  
  • entries
    56
  • comments
    80
  • views
    41534

Shaders are fun

Sign in to follow this  
bladerunner627

153 views

A few days ago my MDX book arrived. Managed DirectX 9 Graphics and Game Programming.

I've been reading it thoroughly. I was really surprised how easy shader implementation is. I probably need to write a shader manager etc, but I've just been playing around with them in Kill Shit. I still haven't found a list of all the different built in functions and data types you can use in HLSL, but thats something a little googleing could solve.

One thing that I'm quite ticked off about is that there is no built in hardware HLSL function for rand(), Cade said it should work in Software.

I'm still new to the HLSL language, but he mentioned that I could write my own rand() function, but I don't know if you could just write a separate shader file with that in it and include it into the other one? I'm not sure. I are noob.

I managed to wip up a splash screen shader, which does a weird wiggle/static effect while fading the splash image in and out. One of my friends 'b4nny' on IRC made this image for me, I think it works quite well :).

Here's a screeny:
Kill Shit Screen Shot

Also, here's the shader source..it's not much

sampler2D g_samSrcColor;

float random = 0.0;
float PercentElapsed = 0.0;

float4 SplashLogoShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;
float2 TexB = Tex;

if( PercentElapsed < 0.5 )
{
Color = tex2D( g_samSrcColor, Tex.xy ) * ( PercentElapsed * 2 ) * 0.5;
float origTexy = Tex.y;
Tex.y = Tex.y + random / 1000;
//Color += tex2D( g_samSrcColor, Tex.xy ) * ( PercentElapsed * 2 ) * 0.25;
//Tex.y = origTexy * ( 1 - ( PercentElapsed / 2 ) );
//Tex.xy *= 0.5;
Tex.x += (cos( Tex.y * random ) * random / 1000) * 0.5;
Tex.y += (sin( Tex.x * random ) * random / 1000) * 0.5;
Color += tex2D( g_samSrcColor, Tex.xy ) * ( PercentElapsed * 2 ) * 0.20;
}
else
{
Color = tex2D( g_samSrcColor, Tex.xy ) * ( 2.0 - PercentElapsed * 2 ) * 0.5;
float origTexy = Tex.y;
Tex.y = Tex.y + random/ 1000;
//Color += tex2D( g_samSrcColor, Tex.xy ) * ( 2.0 - PercentElapsed * 2 ) * 0.25;
//Tex.y = origTexy * ( 1 - ( PercentElapsed / 2 ) );
//Tex.xy *= 0.5;
Tex.x += (cos( Tex.y * random ) * random / 1000) * 0.5;
Tex.y += (sin( Tex.x * random ) * random / 1000) * 0.5;
Color += tex2D( g_samSrcColor, Tex.xy ) * ( 2.0 - PercentElapsed * 2 ) * 0.20;
}

return Color * 1.5;
}


technique PostProcess
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 SplashLogoShader();
}

}






Does anyone have any tips when writing shaders, best practices, What NOT to do?

I should probably get a hang of NVIDIA's FX Composer, or ATI's RenderMonkey.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now