Game Development Community

dev|Pro Game Development Curriculum

Image Effect Scope / Night Vision

by Jonathan Farris · 06/02/2005 (1:50 am) · 23 comments

Download Code File

All of this code was inspired by froggy on the IRC channel, so credit is given to him for inspiring this work.

Installation

MAKE A BACKUP OF YOUR SOURCE BEFORE DOING ANY MOD

Download the zip file, and move the files into your source tree. Add GuiViewport.cc in the gui directory, and all of the files in the gui/IProc directory to your project. Compile, and you are done.

Fire up your script editor and open up example/starter.fps/client/ui/playGui.gui

Before the line
new GuiBitmapCtrl(CenterPrintDlg) {
Add:
new GuiViewport(EffWin) {
      profile = "GuiDefaultProfile";
      horizSizing = "width";
      vertSizing = "height";
      position = "160 100";
      extent = "320 240";
      minExtent = "240 240";
      visible = "1";
      cameraZRot = "0";
      forceFOV = "0";
      isOverlay = "true";
   };

Launch torque, enter your mission, and you should have a big green box!
Wow.... thats because the default mode is night vision.

Open up the console and type:
effWin.setEffect(3);
You should now be treated to some trippy graphics.... unless my code is broken which is entirely possible. Good thing you made a backup eh?

Using the Effect Window in script

The follow script commands are supplied:
obj.setEffect( index or name )
- This selects the current effect.

obj.getEffectIndex()
- Retruns the index of the current effect.

obj.getEffectName( [index] )
- Return the name of the effect index, or if index is not supplied, the name of the current effect.

obj.getEffectParamName( param_index )
- param_index is an integer. This function returns the name of the param_index'th parameter.

obj.getEffectParam( param_name )
- Returns the value of the specified effect parameter.

obj.setEffectParam( param_name, param_value )
- Set the value of an effect parameter.

So for example, say you are using the night vision mode...
effWin.setEffectParam( border_size, 2 );
  effWin.setEffectParam( border_color, "1.0, 0, 0, 0.80");
  effWin.setEffectParam( color, "1.0, 0, 0, 1.0" );
Would draw a 2 pixel border in slightly transparent red around the window, and change
the scope color to red.

Most transforms support the following parameters:
border_size - specifies the border width in pixels.
border_color - color of the border.
interlace_size - erases every nth row.
interlace_alpha - The alpha of the erasure.

The Night vision scope supports:
color - color of the scope output.

The Video effect supports:
ChanceOfNoise - (-1 - 100) percent chance of the transmission having noise. -1 disables
ChanceOfFailure - (-1 - 100) percent chance of the transmission having a failure -1 disables
FailureDelay - number of frames before the effect re-draws after a failure.
StandardDelay - number of frames before the effect re-draws normally.
ForceError - (boolean) set to true to force Error blocks.
ForceFailure - (boolean) set to true to force transmission errors to occur.


Notes
The camera code for camera mode really needs some work, but overlay mode works very well.
To add a new effect take a look at ImageProcessor.h, IP_Config.cc, and IP_Null.cc in the IProc directory.
Page «Previous 1 2
#1
06/02/2005 (1:51 am)
Thanks for submitting this as a resource Jonathan!
#2
06/02/2005 (4:06 am)
I really like the look of this but the link above just redirects me back to this page. If I right-cliock and choose "Save Target As..." I get an error saying that the file is missing. Resource looks cool though!!
#3
06/02/2005 (7:13 am)
Re-uploaded code zip file, so the link should work now.
#4
06/02/2005 (7:17 am)
Got it. Thanks a lot!
#5
06/02/2005 (9:47 am)
Wow, works great. Thanks for sharing!
#6
06/02/2005 (1:14 pm)
Hey Jonathon

I seem to be having a problem compiling one of the files. The error I am getting is

\engine\gui\GuiViewport.cc(278) : error C2653: 'Parent' : is not a class or namespace name

It is on Parent::resize( newPosition, realExtent );

My brain is fried from all these late night sessions. This looks like a cool resource.

Thanks
#7
06/02/2005 (1:25 pm)
Jackie:

Not sure why it would complain there, and not for a previous usage of Parent

At the very least, you can try changing the line to:

GuiTSCtrl::resize( newPosition, realExtent );
#8
06/02/2005 (1:56 pm)
Hmm. That fixed it..:) Not sure why it bailed on that statement. It looks fine to me also. I am not sure what you are trying to do with these statement:

GuiControl *Root, *Parent;
      Root = getParent();
      Parent = Root->getParent();
         while( Parent ) {
            Root = Parent;
            Parent = Parent->getParent();
            }

Since it is bailing on the Parent statement at the end of the void.

Anyway thanks man!! I'll give it a try.
#9
06/02/2005 (3:30 pm)
Ok, it's interesting what different compilers will do...
here is a simpler, replacement.

in gui/GuiViewport.cc find the resize function, and replace it's contents with:

basis = Platform::getWindowSize();
	
	// Make ourself a multiple of 8.
	Point2I realExtent;
	realExtent.x = (newExtent.x>>3)<<3;
	realExtent.y = (newExtent.y>>3)<<3;
	
	mRebuild = (lastSize.x != realExtent.x || lastSize.y != realExtent.y ); 
	lastSize = realExtent;
	updateBreak = 0; 
	Parent::resize( newPosition, realExtent );
#10
06/02/2005 (10:08 pm)
I had the same error as Jackie Hayes
\engine\gui\GuiViewport.cc(278) : error C2653: 'Parent' : is not a class or namespace name

Compiling under vc6.

Anyhow, it's fixed now.
#11
06/03/2005 (10:19 am)
Jonathan
How do you think is it possible to create human eye accomodation effect using this resource. I mean when you walk into the interrior from outside, you get you eyes slow addapting for interrior lighting and image of all thet not inside interrior get brighter when you look outside throw window or door. Sorry for bed english :)
#12
06/03/2005 (11:53 am)
I'm getting horrible frame rates in all modes with this. I go from about 50-70 FPS to less than 15.
#13
06/03/2005 (12:24 pm)
@Josh
Hmm. I am getting about the same thing. I am on a P4 - 2.8ghz with a gig of ram and a GForce FX 5200 with 128 meg. I know this video card is not much but I am at my office. I updated the video drivers and still the same. Mine goes form 75 to 120 fps normally to around 12 to 15 fps while testing this resource. Maybe Jonathan can give us some insite if we are doing anything wrong.
#14
06/03/2005 (2:05 pm)
Ok, first, here is everything that happens (when in overlay mode for a non-alpha process):

The main guiTSCtrl renders the scene into the mystical open-gl buffers (possibly using hardware).
The view port grabs the pixels from the guiTSCtrl.
The selected processor transform the pixels.
The pixels are written back into open-gl.

The good/bad news is that about half of the time is spent in the processor, unfortunaly, half the time is spent converting the open-gl colors to rgb/rgba format and back.

Playin around changing the pixel format gave me some improvement, but broke the transforms.

Some simple things that you can do to improve performance of the night-vision:

In IProc/IP_LightBleed.cc

comment-out the line:
#define OPTIMIZE_CONFIG

This will drop the ability to change the night vision scope color, but reduce some computation.

You can also change the return value of IP_LightBleed::process from 0 to another positive integer. The return value is the delay between updates to the image buffer, so if you return 1, it will process the first frame, draw the results, but on the next update, it will not re-process, and just re-use the results of the last process.

It won't totally fix the problem, but may make it more acceptable.
short of re-writing the transforms to work with the open-gl color index mode, or perform the transform on the GPU itself, I'm not sure what else you can try.
#15
06/06/2005 (4:28 am)
Got it working. No framerate problems.

Many thanks!!
#16
06/06/2005 (7:15 am)
Yeah, no framerate problems at all.

P4 @ 2.4 Ghz
768 MB RAM
128 MB GeForce 6800 OC
WinXP w/ SP2
#17
06/07/2005 (2:57 pm)
When I compiled it in VC 6, After fixing the resize error, It said that
ConsoleMethod( GuiViewport, setEffect, S32, 3, 3, "obj.setEffect( proc_index or name )" )
needed to return something.
I managed to fix this by adding
return numProc;
to the end of the block.
#18
11/20/2005 (8:17 am)
I added this resource and made the speed changes suggested by Johathon and framerate drops from 90 to 12.
Also when I fire up the game the effect does not take place until I use the gui editor then it runs fine. I added a effwin.setEffect(3) to the playgui::onWake() but it still doesn't run when I launch the game.
#19
09/11/2007 (5:56 pm)
Hello. I had some troubles using this resource in my project (see here for details).
I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.

Bye, Berserk.
.
#20
08/17/2008 (9:58 pm)
Has anyone got this towork with TGE 1.5.2 in conjunction with the lighting Kit?
Page «Previous 1 2