Shader Modding for GSB


#1

If you check this folder:

gratuitous space battles\data\shaders

you will find the fx files which are the games shaders. You can open them and save them using notepad. You can edit these, and they change the way the game looks. Some should be left alone, but some are scenario specific. Take a look at the ‘redden.fx’ one, which is used by the gravity well scenario: (check the bg9.txt scenario file to see where it is specified)

[code]sampler2D g_samSrcColor;

float4 Redden( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;
Color = tex2D( g_samSrcColor, Tex.xy);
Color.r = (Color.r * 1.4);
Color.g = (Color.g * 0.6);
Color.b = (Color.b * 0.6);
return Color;
}

technique PostProcess
{
pass p1
{
VertexShader = null;
PixelShader = compile ps_2_0 Redden();
}
}
[/code]

the bit that matters is this:

Color = tex2D( g_samSrcColor, Tex.xy); Color.r = (Color.r * 1.4); Color.g = (Color.g * 0.6); Color.b = (Color.b * 0.6);

That makes everything in the game world slightly redder, before the UI gets drawn on top. If you change any of those valeus and re-run the scenario, you can see the difference.
You might notice the ‘greyscale’ effect in there. Try substituting that into a modded scenario. You can have lots of fun with this stuff. This is worth reading:
facewound.com/tutorials/shader1/
If you come up with some cool effects, post them here for others to try :smiley:


#2

Thank you, Cliffski.


#3

Nobody’s tried this yet?
Well, here’s a distortion shader I cobbled together:

[code]sampler2D g_samSrcColor;

float4 Distort( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;
Tex.y = Tex.y + (sin(Tex.x*100)0.001);
Tex.x = Tex.x + (sin(Tex.y
100)*0.001);
Color = tex2D( g_samSrcColor, Tex.xy);
return Color;
}

technique PostProcess
{
pass p1
{
VertexShader = null;
PixelShader = compile ps_2_0 Distort();
}

}
[/code]

This creates a slight distortion effect when things move across the screen vertically and horizontally or while panning the camera.


#4

Great work! I can already see that effect being in use for a scenario with an alien gravity-bending generator of some sort on the planet surface :slight_smile: