Terrain occluding Portal
by Bill Vee · 02/11/2008 (7:03 am) · 10 comments
Download Code File
Updated 6/25/2008
First unzip portal.zip and find portalblock.cpp and portalblock.h and place them in you engine\terrain
folder of the TGEA source code then add the two files to the engine. It may not actually have to go there
but its how I did it.
Next.
Find the shaders folder from the zip and place its contents in the shaders folder of the example folder or wherever you tell your compiler to create the TGEA.exe. Make sure you copy the contents of this folder not the shaders folder itself. Just the portal folder and its contents.
Add
To your client\script\shaders.cs file
Example.
If your compiler makes the TGEA.exe file in c:\TGE\Example then place it in c:\TGE\Example\shaders
Find the data folder from the zip and place its contents in the data folder of the mod folder of your program, if your mod folder is starter.fps then place it in that folder.Make sure you copy the contents of this folder not the data folder itself. Just the portal folder and its contents.
6/30/2008
Just added a replacement resource for the terrain collision mask switcher here.
6/25/2008
The original code to turn player terrain collision on and off was fundamentally flawed and I am working on a better solution to fix it.
If you need to see the original method it is still in this resource's zip file.
The projectile's method works better.
Next we have to make triggers "aware" of projectiles.
Update
6/30/2008
I created a new resource to handle projectile aware triggers.
Now be careful as triggers will now "see" projectiles. If you have other triggers used to select targets
like the Paul Dana turrets do then you will have them targeting and fireing at projectiles , even there own.
Not a problem just add something like this to the :onEnterTrigger function at the beginning of the function.
This will effective filter Projectile.
Compile your code and that should do it.
Now for the script side.
Now to add PortalBlock to a mission you have to add it manually right now.
I just didn't have time to add the script to add them like the waterblock.
Just add the datablock to your .mis file.
The scale part is very important as it will determine how far in the portalblock will render the view
looking out.
In scale = "50 122 1000"; the last number is the "depth" or rather length of the portalblock.
What it basically means is if you are in the portalblock's worldbox looking at it from the side that
renders "out" it will display the portal if you are out of it's worldbox it won't render. Not a problem
unless you want to see the wave effects from the "inside" of the portal. The side looking in that will
render the scene minus the terrain will function regarless of if you are in the portalblocks worldbox or
not.
There are three BOOL type datablock variables that control what gets rendered in the portal.
They are RenderTerrain , RenderPlayers and RenderVehicles.
RenderTerrain controls if terrain is rendered
RenderPlayers controls if Player is rendered
RenderVehicles controls if Vehicles is rendered
also AnimateWaves will turn the animated waves on or off.
Did I really need to say that.
All you need todo now is add terain_mask_trigger.cs to your scrips folder and add it to your startup scrips like
exec("./terain_mask_trigger.cs");
Then startup you game add a trigger via the editor and assign the TerrainMaskTrigger datablock to it and place it around the part of the terrain you would like to be able to pass thru.
Be very careful to place in such a way the it won't extend into an area that will cause you player to fall thru the terrain. Just keep it around the terrain inside of the interior and you should be ok.
Now players and projectiles and vehicles should be able to enter a interior that extends underground.
One last thing is it appears this render to texture arrangement needs pixel shader 1.4 or higher to display correctly.
Updated 6/25/2008
First unzip portal.zip and find portalblock.cpp and portalblock.h and place them in you engine\terrain
folder of the TGEA source code then add the two files to the engine. It may not actually have to go there
but its how I did it.
Next.
Find the shaders folder from the zip and place its contents in the shaders folder of the example folder or wherever you tell your compiler to create the TGEA.exe. Make sure you copy the contents of this folder not the shaders folder itself. Just the portal folder and its contents.
Add
new ShaderData( PortalFres1_1 )
{
DXVertexShaderFile = "shaders/water/WaterFresV1_1.hlsl";
DXPixelShaderFile = "shaders/water/WaterFresP1_1.hlsl";
pixVersion = 1.1;
};
new ShaderData( PortalBlend )
{
DXVertexShaderFile = "shaders/water/WaterBlendV.hlsl";
DXPixelShaderFile = "shaders/water/WaterBlendP.hlsl";
pixVersion = 1.1;
};
new ShaderData( Portal1_1 )
{
DXVertexShaderFile = "shaders/water/WaterV1_1.hlsl";
DXPixelShaderFile = "shaders/water/WaterP1_1.hlsl";
pixVersion = 1.1;
};
new ShaderData( PortalCubeReflectRefract )
{
DXVertexShaderFile = "shaders/Portal/PortalCubeReflectRefractV.hlsl";
DXPixelShaderFile = "shaders/Portal/PortalCubeReflectRefractP.hlsl";
pixVersion = 2.0;
};
new ShaderData( PortalReflectRefract )
{
DXVertexShaderFile = "shaders/Portal/PortalReflectRefractV.hlsl";
DXPixelShaderFile = "shaders/Portal/PortalReflectRefractP.hlsl";
pixVersion = 2.0;
};
new ShaderData( PortalUnder2_0 )
{
DXVertexShaderFile = "shaders/Portal/PortalUnderV2_0.hlsl";
DXPixelShaderFile = "shaders/Portal/PortalUnderP2_0.hlsl";
pixVersion = 2.0;
};To your client\script\shaders.cs file
Example.
If your compiler makes the TGEA.exe file in c:\TGE\Example then place it in c:\TGE\Example\shaders
Find the data folder from the zip and place its contents in the data folder of the mod folder of your program, if your mod folder is starter.fps then place it in that folder.Make sure you copy the contents of this folder not the data folder itself. Just the portal folder and its contents.
6/30/2008
Just added a replacement resource for the terrain collision mask switcher here.
6/25/2008
The original code to turn player terrain collision on and off was fundamentally flawed and I am working on a better solution to fix it.
If you need to see the original method it is still in this resource's zip file.
The projectile's method works better.
Next we have to make triggers "aware" of projectiles.
Update
6/30/2008
I created a new resource to handle projectile aware triggers.
Now be careful as triggers will now "see" projectiles. If you have other triggers used to select targets
like the Paul Dana turrets do then you will have them targeting and fireing at projectiles , even there own.
Not a problem just add something like this to the :onEnterTrigger function at the beginning of the function.
function AITurretData::onEnterTrigger(%this,%turret,%obj)
{
if( %obj.getClassName() $= "Projectile")
return;
.....
}This will effective filter Projectile.
Compile your code and that should do it.
Now for the script side.
Now to add PortalBlock to a mission you have to add it manually right now.
I just didn't have time to add the script to add them like the waterblock.
Just add the datablock to your .mis file.
new PortalBlock() {
canSaveDynamicFields = "1";
position = "0 0 0";
rotation = "0 0 0 1";
scale = "50 122 1000";
waveDir[0] = "1 1";
waveDir[1] = "0 0";
waveDir[2] = "0 0";
waveDir[3] = "0 0";
waveSpeed[0] = "1";
waveSpeed[1] = "0";
waveSpeed[2] = "0";
waveSpeed[3] = "0";
waveTexScale[0] = "1 1";
waveTexScale[1] = "1 1";
waveTexScale[2] = "0 0";
waveTexScale[3] = "0 0";
RenderTexSize = "512";
baseColor = "5 1 1 1";
InPortalColor = "0 0 0 1";
gridSize = "5";
surfMaterial[0] = "Portal_Interior";
surfMaterial[1] = "UnderPortal";
surfMaterial[2] = "Portal1_1FogPass";
surfMaterial[3] = "PortalBlendMat";
surfMaterial[4] = "PortalFallback1_1";
clarity = "1";
AnimateWaves = "0";
RenderTerrain = "0";
RenderPlayers = "1";
RenderVehicles = "1";
renderFogMesh = "0";
};This will create a portalblock at position 0 0 0.The scale part is very important as it will determine how far in the portalblock will render the view
looking out.
In scale = "50 122 1000"; the last number is the "depth" or rather length of the portalblock.
What it basically means is if you are in the portalblock's worldbox looking at it from the side that
renders "out" it will display the portal if you are out of it's worldbox it won't render. Not a problem
unless you want to see the wave effects from the "inside" of the portal. The side looking in that will
render the scene minus the terrain will function regarless of if you are in the portalblocks worldbox or
not.
There are three BOOL type datablock variables that control what gets rendered in the portal.
They are RenderTerrain , RenderPlayers and RenderVehicles.
RenderTerrain controls if terrain is rendered
RenderPlayers controls if Player is rendered
RenderVehicles controls if Vehicles is rendered
also AnimateWaves will turn the animated waves on or off.
Did I really need to say that.
All you need todo now is add terain_mask_trigger.cs to your scrips folder and add it to your startup scrips like
exec("./terain_mask_trigger.cs");
Then startup you game add a trigger via the editor and assign the TerrainMaskTrigger datablock to it and place it around the part of the terrain you would like to be able to pass thru.
Be very careful to place in such a way the it won't extend into an area that will cause you player to fall thru the terrain. Just keep it around the terrain inside of the interior and you should be ok.
Now players and projectiles and vehicles should be able to enter a interior that extends underground.
One last thing is it appears this render to texture arrangement needs pixel shader 1.4 or higher to display correctly.
About the author
#2
02/12/2008 (5:26 pm)
Nicely done. Great resource.
#3
05/29/2008 (8:31 am)
Uhm, I wonder if this is still compatible with TGEA 1.7.0. ... Noone tried?
#4
06/14/2008 (10:01 am)
Such a shame this isn't available for TGE ;P
#5
Edit-> I have the collision part in TGE, but no terrain hiding yet.
06/15/2008 (3:41 am)
Has someone tried doing this for TGE? It looks like the 'no-terrain-collision' would work in TGE with no trouble, but I'm not sure how to go about with hiding the terrain...Edit-> I have the collision part in TGE, but no terrain hiding yet.
#6
The Interior portal code is very complex.
If you could do it in TGE then I think the Interior portal code would be your best bet.
06/15/2008 (1:32 pm)
I originally looked at using the portal/mirror code to accomplish the terrain occluding effect but couldn't get it to work in TGE.The Interior portal code is very complex.
If you could do it in TGE then I think the Interior portal code would be your best bet.
#7
06/16/2008 (8:40 am)
Ok, I'll try it. Thanks!
#8
06/18/2008 (2:46 pm)
Won't changing the global variable cause all players to fall though the terrain when only one enters a portal?
#9
You simple have to move the collisionmasks to the player class define in player.h then add it to the Player::packUpdate and Player::unpackUpdate.
Also make sure you setup default values in the player constructor.
I was working on the 1.7.1 version before I discovered my mistake.
06/18/2008 (5:11 pm)
I was wondering when someone would spot that.You simple have to move the collisionmasks to the player class define in player.h then add it to the Player::packUpdate and Player::unpackUpdate.
Also make sure you setup default values in the player constructor.
I was working on the 1.7.1 version before I discovered my mistake.
#10
Alternate Collision Masks
Projectile aware triggers
This corrects some issues and creates a much simpler method for Alternate Collision Masks.
06/30/2008 (7:23 pm)
Just updated the resource by splitting it into 3 resources like I should have done in the first place.Alternate Collision Masks
Projectile aware triggers
This corrects some issues and creates a much simpler method for Alternate Collision Masks.

Torque Owner Giorgio Zanetti ( JoZ )
Corona Team
:)