Mirror mirror on the wall...
by kc_0045 · in Torque Game Engine · 09/19/2006 (4:30 pm) · 9 replies
I am trying to create a way of Rendering a Camaras view onto a 3d plane in the game world. Iv done some basic render to texture work in opengl before but before I start to dig into adding this to torque(which iv got noo idea how to :S) I was wondering if it would be possable to use the same code that the mirrors in .dif use?(just "Hack" it to render at a forced position) because from what iv heard, Render to texture can lower fps alot and the torque mirrors seem very high quality yet cause no fps lag.
any ideas how this can be done?
any ideas how this can be done?
About the author
#2
To render the entire scene, I would look at void SceneGraph::renderScene(const U32 objectMask) for starters. Put a breakpoint in there, see where it's called from, and then trace through it to see what it calls.
10/01/2006 (7:59 pm)
You can do mirrors without render-to-texture, using scissoring, stenciling, and user clip planes.To render the entire scene, I would look at void SceneGraph::renderScene(const U32 objectMask) for starters. Put a breakpoint in there, see where it's called from, and then trace through it to see what it calls.
#3
10/03/2006 (6:39 pm)
......
#4
gClientSceneGraph->renderScene();
seems to be the function i need to use, but how do I change the camara, then change it back to the normal position?
10/23/2006 (4:08 pm)
Okay iv got it all set up, now all I need to do is render the scence at some given position normaly on the screen...how do I do this from within another objects render function?gClientSceneGraph->renderScene();
seems to be the function i need to use, but how do I change the camara, then change it back to the normal position?
#5
Each object, when rendering, may set up the camera transform. Just trace through renderScene() in the debugger, and see how the MODELVIEW matrix is determined in various objects. That should teach you where the camera parameters are stored. Then just change that source of information.
10/23/2006 (8:04 pm)
Quote:how do I change the camara, then change it back to the normal position
Each object, when rendering, may set up the camera transform. Just trace through renderScene() in the debugger, and see how the MODELVIEW matrix is determined in various objects. That should teach you where the camera parameters are stored. Then just change that source of information.
#6
--EDIT--
Sorry, now I see you've mentioned the DIF mirrors. Is there a reason you can't use them? Are you really doing mirrors, or something else, like remote cameras?
Use the search function and look fot the shaderized TGE water upgrade. It renders the scene to a texture using another GameTSCtrl and can provide a basis for getting different views from the scene into a texture.
10/24/2006 (6:28 am)
Wait, TGE already has built-in mirrors. DIF files support mirror surfaces, and they reflect everything. There is an example mirror in the starter.fps interior folder.--EDIT--
Sorry, now I see you've mentioned the DIF mirrors. Is there a reason you can't use them? Are you really doing mirrors, or something else, like remote cameras?
Use the search function and look fot the shaderized TGE water upgrade. It renders the scene to a texture using another GameTSCtrl and can provide a basis for getting different views from the scene into a texture.
#7
10/24/2006 (8:09 am)
I think he is trying to do the Closed Cercet TV, security thing...
#8
11/08/2006 (4:15 pm)
Sorry for the late reply, its hard to explain what im doing without explaining my whole idea. but pretty much it would be a Closed Circuit TV type idea its just a little project so im in no hurry(its just me working on it and im a noob :P)
#9
Anyway, when I get this working I'll write up a resource to save people some headaches in the future. Your list of the major steps is pretty good. So lets try to figure out how/where each step is carried out.
1) Create texture
2) Render the first Camara
3) Copy it
4) Setup normal Player camara
5) Render normal world.
Here's what I have so far on each step.
1) Create texture: so I guess the choices are:
a) just use any texture for which you have a material defined in your game data folder. Not sure if this will require any special material properties or not.
b) Or maybe it would be easier to just declare some global texture in the engine somewhere and use that. But that might limit you to one remote camera per level.
2) render the remote camera: several steps here:
2a) move the camera to the position of the remote camera: i have only figured this out in Torque script where you can move the camera to, and control any object without mounting your player model on it. Look in "commands.cs":
"CAMERA1" must a shape placed in your map and named in the level editor. Havent figured out how to reference an object named "CAMERA1" in the scene via engine .cpp code though.
2b) set the rendering target to the texture: In glowbuffer.cpp there is this function:
Glowbuffer.cpp has a lot of functionality that looks similar to rendering a remote camera.
2c) render the scene : gClientSceneGraph->renderScene(); Ok in this part it would be nice if you could change resolution for performance reasons, and because your textured video screen in the game isn't going to be 1024*768 or higher. Also in glowbuffer.cpp are these lines, that have something to do with the rez of the camera and texture.
3) Copy it: Not sure what you mean by this step. If the material we render to is textured on some object in the world, it should show up right?
4) Setup normal Player camera:
4a) move the camera back: reverse 2a
4b) go back to the default rendering surface: reversing what happened in 2b
5) Render normal world: Shouldn't have to do anything here right? We just added that extra render in before we rendered the game world from the player's perspective.
Another big issue is just getting this into the game in any useful manner. I assume you will have multiple remote cameras in the world. So I think we will need 2 classes:
remote camera class just a normal shape class that level designers place in the world. They must have a name, like camera1, camera2, etc...
camera monitor class a shape class with a simple plane for a .dts file. It must be associated with the name of a camera in the map.
11/09/2006 (8:46 am)
Hey KC, I'm working on remote cameras too. I'm running into the same issues as well hehe. WHAT to do isn't an issue, I could code this in OpenGL in a couple hours. HOW to do it in torque is the huge problem since there isnt much documentation. =(Anyway, when I get this working I'll write up a resource to save people some headaches in the future. Your list of the major steps is pretty good. So lets try to figure out how/where each step is carried out.
1) Create texture
2) Render the first Camara
3) Copy it
4) Setup normal Player camara
5) Render normal world.
Here's what I have so far on each step.
1) Create texture: so I guess the choices are:
a) just use any texture for which you have a material defined in your game data folder. Not sure if this will require any special material properties or not.
b) Or maybe it would be easier to just declare some global texture in the engine somewhere and use that. But that might limit you to one remote camera per level.
2) render the remote camera: several steps here:
2a) move the camera to the position of the remote camera: i have only figured this out in Torque script where you can move the camera to, and control any object without mounting your player model on it. Look in "commands.cs":
function serverCmdToggleCamera(%client)
{
%control = %client.getControlObject();
if (%control == %client.player)
{
// move camera to CAMERA1 object
%control = CAMERA1;
%control.mode = toggleCameraFly;
}
else
{
// move camera back to player model
%control = %client.player;
%control.mode = observerFly;
}
%client.setControlObject(%control);
}"CAMERA1" must a shape placed in your map and named in the level editor. Havent figured out how to reference an object named "CAMERA1" in the scene via engine .cpp code though.
2b) set the rendering target to the texture: In glowbuffer.cpp there is this function:
GFX->setActiveRenderSurface( mSurface[1] );
Glowbuffer.cpp has a lot of functionality that looks similar to rendering a remote camera.
2c) render the scene : gClientSceneGraph->renderScene(); Ok in this part it would be nice if you could change resolution for performance reasons, and because your textured video screen in the game isn't going to be 1024*768 or higher. Also in glowbuffer.cpp are these lines, that have something to do with the rez of the camera and texture.
GFXVideoMode vm = GFX->getVideoMode(); mSurface[2].set( vm.resolution.x, vm.resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, 1 );
3) Copy it: Not sure what you mean by this step. If the material we render to is textured on some object in the world, it should show up right?
4) Setup normal Player camera:
4a) move the camera back: reverse 2a
4b) go back to the default rendering surface: reversing what happened in 2b
GFX->setActiveRenderSurface( whatever the default is in torque);
5) Render normal world: Shouldn't have to do anything here right? We just added that extra render in before we rendered the game world from the player's perspective.
Another big issue is just getting this into the game in any useful manner. I assume you will have multiple remote cameras in the world. So I think we will need 2 classes:
remote camera class just a normal shape class that level designers place in the world. They must have a name, like camera1, camera2, etc...
camera monitor class a shape class with a simple plane for a .dts file. It must be associated with the name of a camera in the map.
Torque Owner kc_0045
Default Studio Name
Create texture
Render the first Camara
Copy it
Setup normal Player camara
Render normal world.
Im just wondering, Where is sorta the "Main loop" for the rendering part of torque called? and where should i define the texture to keep the first viewpoint in?(what file/class) I dont really no how to go about this in torque :S