Full Screen Shaders + Manager in TGEA 1.8.1
by Eric den Boer · 06/06/2009 (2:00 pm) · 12 comments
Hi everyone,
If you would please refer back to my old post here, you'll see that I posted a fix to a fix of a 1.7 resource. This resource provides full screen shaders.
However it only provides two hard-coded shaders: "nightVision" and "heatVision". Not liking this, I continued to create a Shader Pool Manager.
Instead of having everyone refer back to the billion resources and keep fixing eachother, I'll just post the final code right here. This code replaces your gameTSCtrl.cpp and gameTSCtrl.h files in the T3D folder of your engine directory.
For clarity sake, I removed all old code. However I do want to mention that this was possible due to decryptoid and Siddartha. Thanks guys!
If you wish to review the old code, please refer back to my old post where you'll find links to the older resources.
Usage
1. First define a shader like you normally would. This shader should contain post-processing effects.
2. Then use the following to activate or just load the shader into memory:
When calling the same shader name twice or more, it'll just look up the ShaderData in the shader pool, instead of define a new one. So in other words, you can use this function to init all your shaders or to activate them right away!
Code Files
Mirror 1
Mirror 2
Additional Functionality
Silly me, I forgot to add a disableEffect() function.
Add the following static function to the gameTSCtrl.cpp file:
Now add the following console function entry to the gameTSCtrl::consoleInit() function:
This will disable the current active effect. You may also remove the old functions, I did. All you really need are these two.
If you would please refer back to my old post here, you'll see that I posted a fix to a fix of a 1.7 resource. This resource provides full screen shaders.
However it only provides two hard-coded shaders: "nightVision" and "heatVision". Not liking this, I continued to create a Shader Pool Manager.
Instead of having everyone refer back to the billion resources and keep fixing eachother, I'll just post the final code right here. This code replaces your gameTSCtrl.cpp and gameTSCtrl.h files in the T3D folder of your engine directory.
For clarity sake, I removed all old code. However I do want to mention that this was possible due to decryptoid and Siddartha. Thanks guys!
If you wish to review the old code, please refer back to my old post where you'll find links to the older resources.
Usage
1. First define a shader like you normally would. This shader should contain post-processing effects.
2. Then use the following to activate or just load the shader into memory:
// DEFINITION
loadEffectByName(String shaderName, bool activateShader);
// USAGE
PlayGui.loadEffectByName("shaderName", true); // This both loads the shader into memory and activates it.
PlayGui.loadEffectByName("shaderName", false); // This just loads the shader into memory, but doesn't activate it.When calling the same shader name twice or more, it'll just look up the ShaderData in the shader pool, instead of define a new one. So in other words, you can use this function to init all your shaders or to activate them right away!
Code Files
Mirror 1
Mirror 2
Additional Functionality
Silly me, I forgot to add a disableEffect() function.
Add the following static function to the gameTSCtrl.cpp file:
static void DisableEffect(SimObject* obj, S32, const char** argv)
{
GameTSCtrl *ctrl = static_cast<GameTSCtrl*>(obj);
// do we have an active effect?
ctrl->effectMode = -1;
}Now add the following console function entry to the gameTSCtrl::consoleInit() function:
Con::addCommand("GameTSCtrl", "disableEffect", DisableEffect, "GameTSCtrl.disableEffect()", 2, 2);This will disable the current active effect. You may also remove the old functions, I did. All you really need are these two.
#3
Do you know how hard it would be to also render out the depth/normals of the scene in addition to the render target? There are a lot of nice postFX shaders you can implement with depth/normal information.
06/07/2009 (1:23 am)
Thanks bud.Do you know how hard it would be to also render out the depth/normals of the scene in addition to the render target? There are a lot of nice postFX shaders you can implement with depth/normal information.
#4
06/07/2009 (2:43 am)
@Mike: No, I've been looking for the same thing, but look up depth of field in the search, I saw some articles on the subject and people making several layers of render targets. However, I didn't implement them yet, nor have I really taken a good look at them.
#5
That said hooking up another render bin and texture target isn't that difficult either.
06/07/2009 (2:43 am)
@Mike - Ubiq Visuals did it for their SSAO and DoF TGEA shaders. Now i'm not sure if they capture normals... you should ask... but they do have depth. If i were to be trying to do this for TGEA and wanted to get a quick leg up i would buy their kit and modifiy it for my own needs.That said hooking up another render bin and texture target isn't that difficult either.
#6
I'm glad people enjoy this resource!
06/07/2009 (6:40 am)
I added functionality to disable the current active effect. I hope the instructions are clear and all. :)I'm glad people enjoy this resource!
#7
06/08/2009 (1:46 pm)
I would have liked to purchase the SSAO and DoF shaders from Ubiq, but they don't support Mac... they told me they have no intention of doing so on SSAO, anyway.
#8
08/29/2009 (12:50 am)
Anyone have any more full screen shaders they would share? I was really wanting to find sepia, spotlight, and black and white from the older resources. They seem to have disappeared.
#9
09/06/2009 (3:15 am)
To get this working in TGEA 1.8.1 on a Mac is it as simple as finding or creating glsl versions of these shaders? It compiled fine, but I realized I don't have any shaders to test it with.
#10
09/07/2009 (9:38 am)
Ehy Ron, here the download link seems to be valid www.garagegames.com/community/resources/view/13430... it contains default, sepia, spot and wawe... by the way in my TGEA project i had also nightvision and heatvision... if you want them I can drop you a mail with them attached... :-)
#11
I'm new to shaders, I have created my shader in the shader.cs correctly link them to the files.
However where do i put
loadEffectByName(String Motion, bool activateShader);
PlayGui.loadEffectByName("Motion", true);
I don't know where to make this call
Cheers Luke
11/11/2009 (10:21 pm)
Ok thank you very much for this great post.I'm new to shaders, I have created my shader in the shader.cs correctly link them to the files.
However where do i put
loadEffectByName(String Motion, bool activateShader);
PlayGui.loadEffectByName("Motion", true);
I don't know where to make this call
Cheers Luke
#12
Works fine in afx btw
12/23/2009 (4:05 am)
You can make this call in the Console or in script when the game loads.Works fine in afx btw
Torque 3D Owner Ron Nelson