Change the color of the caustics postFX in script
by Richard Marrevee · 05/30/2013 (1:57 pm) · 7 comments
Torque 3D 3.0 comes with a nice shader that shows the caustics effect, but unfortunately it uses the color of the textures used to generate this effect. With this resource you are able to change the color of the effect in TorqueScript. The changes are minimal, so let's go and add this nice feature to a very nice effect.
First, we add a few lines to the shader causticsP.hlsl. You can find this file in shaders\common\caustics in your project folder.
Add the marked lines:
Save this file.
Now we add some lines to caustics.cs which you can find in the core\scripts\client\postFx in your project folder.
Now it is possible to change the color of the effect in script by changing the value of the global $CausticsPFX::color as shown below.
Now to see it working watch the vid (I suggest the HD quality):
Have fun.
Richard.
Edit: fixed typo's.
First, we add a few lines to the shader causticsP.hlsl. You can find this file in shaders\common\caustics in your project folder.
Add the marked lines:
uniform float3 eyePosWorld;
uniform float4 rtParams0;
uniform float4 waterFogPlane;
uniform float accumTime;
uniform float4 colorize;//<=========== Add this line
float4 main( PFXVertToPix IN,
uniform sampler2D prepassTex :register(S0),
uniform sampler2D causticsTex0 :register(S1),
uniform sampler2D causticsTex1 :register(S2),
uniform float2 targetSize : register(C0) ) : COLOR
.
.
.
//Sample caustics texture
float4 caustics = tex2D(causticsTex0, causticsUV0);
caustics *= tex2D(causticsTex1, causticsUV1);
caustics *= colorize;//<============= Add this line
//Use normal Z to modulate causticsSave this file.
Now we add some lines to caustics.cs which you can find in the core\scripts\client\postFx in your project folder.
// this effects the timing of the animation -
$CausticsPFX::refTime = getSimTime();
$CausticsPFX::color = "1.0 1.0 1.0 1.0";//<=========== Add this line, 1 1 1 1 give no colorization
function CausticsPFX::setShaderConsts(%this)
{
//echo($Sim::time - %this.timeStart);
//echo(%this.timeConst);
%this.setShaderConst( "$refTime", $CausticsPFX::refTime );
%this.setShaderConst( "$colorize", $CausticsPFX::color );//<============== Add this line
}Now it is possible to change the color of the effect in script by changing the value of the global $CausticsPFX::color as shown below.
$CausticsPFX::color = "1.0 0.7 1.0 1.0";// red green blue alphaThe value for the alpha component is arbitrary.
Now to see it working watch the vid (I suggest the HD quality):
Have fun.
Richard.
Edit: fixed typo's.
About the author
Started programming in 1984 on an Oric, when time progressed switched to MSX, Amiga and finally the Windows PC with T3D. Now developing an epic fantasy game: The Master's Eye. Creator of the DoorClass pack and VolumetricFog pack @ richardsgamestudio.com
#2
05/30/2013 (7:22 pm)
Very nice work Richard!
#3
05/31/2013 (2:06 am)
Nice work! Thanks for share, Richard.
#4
05/31/2013 (6:10 am)
Thumbs up. Good thinking there, Batman.
#5
06/02/2013 (7:35 pm)
Nice one! This will add another level of customizability, and a nifty one at that.
#7
06/10/2013 (8:58 am)
This sort of thing would be a perfect example of a Community Addition of a feature/improvement if it was contributed as a Pull Request on Github... 
Associate Ron Kapaun
3tdstudios.com
Ron