TSE Simple Full Screen Shader Effect
by decryptoid · 11/15/2005 (2:49 pm) · 61 comments
Download Code File
Remember to back up your files before using this example code!
Files... You may also download the files here:
Code Files
Download the code file and unzip the files as follows:
-- Unzip fullscreenEffects.cs into example/[yourmod directory]/client/scripts/
where [yourmod directory] is the name of your mod directory
-- Unzip all four .hlsl files to the /example/shaders/
-- Unzip both gameTSCtrl files to /engine/game/
Now Compile!...
Script Changes...
-- Open example/[yourmod directory]/client/init.cs and add the following code right after the IdleTimeout line...
-- Open example/[yourmod directory]/client/scripts/default.bind.cs and add the following code to the end:
Now Delete all your dso files... if you don't know how to do this just do a search on your mod directory for "*.dso" and delete all the files.
Run the game... you should be done!
Pressing "v" on the keyboard should toggle between heatvision, nightvision and regular vision.
About the shaders...
The shaders (hlsl files) are very simple. You can open them up in a text editor and see how they work. All they really do is convert the image to black and white then invert for heatvision and add all color channels to green for nightvision.
About the engine changes
Look at the new gameRenderEffect function in gameTSCtrl.cpp file for most of the changes. It's basically a copy of the regular GameRender function, but it renders to a surface then back to the screen with the shader.
What else you can do...
-- Add Bitmap "static" to the shaders
-- Write a cool custom screen shader!!
-- Look at the other shaders in the shaders directory to see how they work
-- Look in other parts of the engine code to see how to pass additional values to a custom shader. All the glowbuffer stuff is good for this
-- Modify this example code to be more dynamic. The two shaders are kinda hardcoded in there and it would be better to pass shader names in a script... that way you wouldn't have to re-compile for every shader change
NOTE: Since every one was waiting I made this example fairly quick. There may be unused variables or errors I didn't catch. Hopefully I included all the right files!
Problems:
-- The game will crash if the two shaders do not get loaded. This will happen if you put the exec line for the fullscreenEffect.cs file in the wrong place.
Remember to back up your files before using this example code!
Files... You may also download the files here:
Code Files
Download the code file and unzip the files as follows:
-- Unzip fullscreenEffects.cs into example/[yourmod directory]/client/scripts/
where [yourmod directory] is the name of your mod directory
-- Unzip all four .hlsl files to the /example/shaders/
-- Unzip both gameTSCtrl files to /engine/game/
Now Compile!...
Script Changes...
-- Open example/[yourmod directory]/client/init.cs and add the following code right after the IdleTimeout line...
// full screen effects
exec("./scripts/fullscreenEffects.cs");It is important that you place it immediately after the IdleTimeout line because the fullscreenEffects file must be loaded before the PlayGui is loaded or it will not work.-- Open example/[yourmod directory]/client/scripts/default.bind.cs and add the following code to the end:
//---------------------------------------
// fullscreen shader effects
//---------------------------------------
moveMap.bind(keyboard, "v", toggleEffectMode);
function toggleEffectMode(%val)
{
if(%val)
{
PlayGui.toggleEffectMode(0);
}
}Now Delete all your dso files... if you don't know how to do this just do a search on your mod directory for "*.dso" and delete all the files.
Run the game... you should be done!
Pressing "v" on the keyboard should toggle between heatvision, nightvision and regular vision.
About the shaders...
The shaders (hlsl files) are very simple. You can open them up in a text editor and see how they work. All they really do is convert the image to black and white then invert for heatvision and add all color channels to green for nightvision.
About the engine changes
Look at the new gameRenderEffect function in gameTSCtrl.cpp file for most of the changes. It's basically a copy of the regular GameRender function, but it renders to a surface then back to the screen with the shader.
What else you can do...
-- Add Bitmap "static" to the shaders
-- Write a cool custom screen shader!!
-- Look at the other shaders in the shaders directory to see how they work
-- Look in other parts of the engine code to see how to pass additional values to a custom shader. All the glowbuffer stuff is good for this
-- Modify this example code to be more dynamic. The two shaders are kinda hardcoded in there and it would be better to pass shader names in a script... that way you wouldn't have to re-compile for every shader change
NOTE: Since every one was waiting I made this example fairly quick. There may be unused variables or errors I didn't catch. Hopefully I included all the right files!
Problems:
-- The game will crash if the two shaders do not get loaded. This will happen if you put the exec line for the fullscreenEffect.cs file in the wrong place.

Torque 3D Owner Eric den Boer