Game Development Community

dev|Pro Game Development Curriculum

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...
// 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.

About the author

Recent Blogs

Page «Previous 1 2 3 4 Last »
#1
11/04/2005 (8:19 pm)
Remember to add
moveMap.bind(keyboard, "v", toggleEffectMode);
to the bottom of example\[your mode name]\client\config.cs
#2
11/05/2005 (2:02 am)
Thank you. This is a great resource. It compiled and tested fine on my rig.
#3
11/05/2005 (7:27 am)
Great, just the sort of thing i have been looking for :)
#4
11/05/2005 (9:25 am)
Ok I did find one issue. When I put it into the terrain_water_demo the cube with the numbers does not show up under the green night shader.
But it does appear under the grey screen.

Edit: Here is a little shockwave of the bug www.noobgames.com/fsbug01.swf
#5
11/05/2005 (4:56 pm)
Ok I swapped the P files around and the first effect works in green. So the problem is in the C code somewhere, looking at it now.

Or was the second shader meant to do that?
Quote: U32 mask = StaticObjectType | VehicleObjectType | InteriorObjectType | PlayerObjectType | EnvironmentObjectType | TerrainObjectType;
renderWorldEffect(updateRect,mNightEffectShader, mask, GFXFillSolid);
#6
11/07/2005 (7:30 am)
I'll check this tonight.... the original point of the object mask was so that the heat vision would "see through" smoke (particles in other words). It may have to have the object mask defined in all cases.
#7
11/19/2005 (10:47 pm)
(Edit) Never mind -- it appears as though this were just a driver problem (damned Catalyst 5.10/11s).
#8
01/23/2006 (2:22 am)
Hi

After updating the latest CVS head, the modified gameTSCtrl.cpp for full screen will compile with errors.

I guess they replace the startActiveRenderSurface and endActiveRenderSurface for GFX.

What I did in renderWorldEffect was
Replace
GFX->startActiveRenderSurface(mSurface[0]);
with
GFX->pushActiveRenderSurfaces();

and
GFX->endActiveRenderSurface();
with
GFX->popActiveRenderSurfaces();

I manage to compile successfully with these changes but shader doesn't work properly. Basically, it filled the screen with solid white or black.

Guess I have to burn mid-night oil to play around.
^_^
#9
01/23/2006 (9:35 pm)
Silly me. I entirely forget about the GFXTexHandle.

Right after the
GFX->pushActiveRenderSurfaces();
Add
GFX->setActiveRenderSurface(mSurface[0]);

It works fine for me now.
Hope this help those having problem getting it work in the latest TSE head.
#10
04/08/2006 (11:42 pm)
For our project, the fullscreen shading stopped working with the release of Milestone 3 (MS3). It looks like the GameTSCtrl constructor is called before the GFXDevice is properly initialized. I added the following check to GameTSCtrl::GameTSCtrl() around line 69 in gameTSCtrl.cpp and everything works again.

if( GFXDevice::devicePresent() )   //test to determine of GFX Device is initialized...
{
    GFXVideoMode mode = GFX->getVideoMode();
    mSurface[0].set( mode.resolution.x, mode.resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, 1 );
}

John K.
#11
07/24/2006 (3:31 pm)
Here are my errors.
C:\Torque\tse\engine\game\gameTSCtrl.cpp(155): error C2039: 'getServerConnection' : is not a member of 'GameConnection'
C:\Torque\tse\engine\game\gameTSCtrl.cpp(155): error C3861: 'getServerConnection': identifier not found, even with argument-dependent lookup
C:\Torque\tse\engine\game\gameTSCtrl.cpp(217): error C2039: 'startActiveRenderSurface' : is not a member of 'GFXDevice'
C:\Torque\tse\engine\game\gameTSCtrl.cpp(238): error C2039: 'endActiveRenderSurface' : is not a member of 'GFXDevice'
#12
07/26/2006 (10:15 am)
There are changes in the new head that make it fail to compile....

See the changes above by Haider and John. As well, "getServerConnection" is now "getConnectionToServer" if I remember correctly.

I have not had time to work on this lately, but I have a good excuse..... will have a snapshot of my latest Neural Network system up soon that will blow your mind.
#13
07/31/2006 (2:59 pm)
I made some changes to the code to get it to compile...

email me if you want my code which is working...

but on the heat shader, I get some weird pink artifacts sometimes.

Also, tried to use the wavesP.hlsl and got a lot of pink artifacts...

Clues?

:)
Sumner
#14
10/28/2006 (4:21 am)
Hmmmm,

GFXD3DDevice::SetActiveRenderSurface - Cannot have an active render target bound to a texture sampler!

Excellent resource, just the last hurdle i'm hitting here. =]
#15
10/28/2006 (7:16 pm)
Got it, while i still dont understand while this check is done, while you are running the debug build it will run this check and give the Assert Fatal on line 837-843 in gfxD3DDevice.cpp:
// In debug, iterate over everything and make sure this isn't bound to a
   // texture sampler yet.
   for(S32 i=0; i<TEXTURE_STAGE_COUNT; i++)
   {
     AssertFatal(mCurrentTexture[i] != surface, 
        "GFXD3DDevice::setActiveRenderSurface - Cannot have an active render target bound to a texture sampler!");
   }

I commented it out for while we are debugging, can someone kindly explain this check to me?
#16
11/27/2006 (2:28 pm)
When I set this up it compiles fine, but gives a GPF right when I run TSE.exe
#17
02/12/2007 (1:37 pm)
Finally got it compiled properly, but I also get the crash on application start....

Im actually trying to implement optional Depth of Field, has anyone achieved this already?
#18
02/12/2007 (2:40 pm)
I haven't been able to get this working in MS 4.1 +. (compiles fine, but attempting to render it crashes TSE) I think it must be a GFXDevice problem, though I really haven't looked into it.
#19
02/20/2007 (6:12 pm)
I would really appreciate if anyone knows a simple way to apply fullscreen shader effects, all the info ive found is to apply it to a specific model. I would like to implement DOF and Color Tint shader over the full screen. Is there an easy way to script that?

Thanks

addikt
#20
02/23/2007 (7:58 pm)
I'm receiving the following error on compile, Ive added the necessary edits to solve the other aformentioned errors, just this last one has me stumped. Help would be much appreciated ;)

gameTSCtrl.cpp
..\engine\game\gameTSCtrl.cpp(164) : error C3861: 'GameRenderFilters': identifier not found

addikt
Page «Previous 1 2 3 4 Last »