Game Development Community

Specular Water update

by Sam Guffey · in Torque Game Engine · 11/17/2003 (5:16 pm) · 15 replies

We are gonna update the specular settings for the waterBlock so it "can" use the fxSun as its source for color and vector.

First off open WaterBlock.cc

1.)
Add #include "game/fx/fxSunLight.h"

2.)
in function "void WaterBlock::UpdateFluidRegion( void )"
Below "mSurfaceZ = P.z + mObjScale.z;"
Add...
// We need to get the flareColor and Brightness from the fxSun.
   fxSunLight* fxSun = (fxSunLight*)Sim::findObject("fxSun");
   if(fxSun)
   {
      mSpecColor = fxSun->getFlareColour();
      mSpecPower = fxSun->getFlareBrightness() * 15;
   }

3.)
In RenderObject at the bottom but above the assert add..
// Now we need a constant update when we look at the waterSurface.
   UpdateFluidRegion();

Aight now close WaterBlock.cc and open fluidRender.cc
1.)
Add #include "math/mathUtils.h"
Add #include "game/fx/fxSunLight.h"

2.)
In function "void fluid::CalcVertSpecular()"
Replace everything above "lightDir.normalize();" with...
// get sun direction   
	Point3F lightDir;
   
	// Grab the fxSun pos if possible otherwise use the default settings. SG   
   fxSunLight* fxSun = (fxSunLight*)Sim::findObject("fxSun");
   if(fxSun)
   {
      F32 azi = fxSun->getSunAzimuth();
	  F32 ele = fxSun->getSunElevation();   
      azi = mDegToRad(azi);
      ele = mDegToRad(ele);   
      MathUtils::getVectorFromAngles(lightDir, azi, ele);
      lightDir.neg();
   }
   else
	   lightDir.set(0.5, 0.5, -0.5);

Close fluidRender.cc and open fxSunLight.h
1.)
Below "void setFlareColour(ColorF Colour);"
add..
ColorF getFlareColour() { return mFlareColour; }
and below "void setFlareBrightness(F32 Brightness);"
add..
F32  getFlareBrightness() { return mFlareBrightness; }

*Update*
2.)
Below "void setSunElevation(F32 Elevation);"
add..
F32 getSunAzimuth() { return mSunAzimuth; }
F32 getSunElevation() { return mSunElevation; }
*End Update*

Close fxSunLight.h and open fxSunLight.cc
in Function onAdd..

Here we have to assign a name to the fxSun object so we can find it later.. Make the function look like this.
// Only on client.
	if (isClientObject())
	{
		// Fetch Textures.
		setFlareBitmaps(mLocalFlareTextureName, mRemoteFlareTextureName);
	}
	else
		assignName("fxSun");

Thats it, do a rebuild and try it out by changing the azimuth, elevation, flare color and brightness of your fxSunLight to see the changes made on the waterBlock.

This should also work well with dayLightCycle after a few tweaks.

If you have a question about this let me know here.
Sam G

#1
11/17/2003 (7:19 pm)
That's pretty awesome... And should probably be in head.

Thanks!
#2
11/18/2003 (12:09 am)
Hmm,

Strange, I already did this and submitted it to Tim a little while ago because I was too busy; I've not actually checked the head recently.

I also had the the main 'sun' linked to the 'fxSunLight' so that it also controlled shadows.

- Melv.
#3
11/18/2003 (12:21 am)
I was pretty sure you comitted this Melv, at least read you saying you did, or maybe read it in the cvs change log. I thought this was in already.

EDIT: (In the head)

Just looked in the cvs change log and can't find it, weird, I was so sure it was there :\
#4
11/18/2003 (1:04 am)
Hi Melv,

did you mean this change ???

Quote:
Change #: 3575
Committed by: Tim Gift
Date: 2003/10/02 17:47:07

Description:

Integrated a patch from Melv May which adds depth translucency to the water's specular highlight. The patch also ties together the position of the sun, fx sun flare's and water specular. The sun itself now takes azimuth and elevation instead of the earlier direction vector. All missions will have to have their sun position reset, as the direction vector is no longer supported.

Modified Files:

torque/engine/game/fx/fxSunLight.cc (1.6)
torque/engine/game/fx/fxSunLight.h (1.3)
torque/engine/sceneGraph/lightManager.h (1.7)
torque/engine/terrain/fluidRender.cc (1.10)
torque/engine/terrain/sun.cc (1.8)
torque/engine/terrain/sun.h (1.6)
torque/example/demo/data/missions/features.mis (1.3)
torque/example/demo/data/missions/fps.mis (1.4)
torque/example/demo/data/missions/racing.mis (1.3)

#5
11/18/2003 (6:00 am)
Sven,

Yes; I think that's the one. I need to check when I get home.

@Sam: I don't want to sound like I'm taking anything away from your great work here, it's just that I thought I did this already. :)

I must admit that it was a rushed thing for v1.2 for Tim and I can't quite remember what I did.

- Melv.
#6
11/18/2003 (6:15 pm)
Its no big deal it only took about 5 mins but I didnt think anyone had done it since I had a late Oct head version and it wasnt included. Im sure your version is more complete anyhow.
#7
11/19/2003 (2:42 pm)
I tried to add this code, and I am getting that the getSunAzimuth and getSunElevation are undefined. I've checked in the latest head, and these routines are not there. I must have missed something. Perhaps these is another resource that this one relies on that I have not added?
#8
11/19/2003 (3:23 pm)
I knew there was something.. In fxSunLight.h below "void setSunElevation(F32 Elevation)" add these two..

F32 getSunAzimuth() { return mSunAzimuth; }
F32 getSunElevation() { return mSunElevation; }

The main tut at top has been updated and I also checked head and there doesnt seem to be an update on the specular effects.
#9
11/19/2003 (3:48 pm)
@sam

Thanks, that works now. I am seeing something I don't quite get, however. I see the sunlight glowing off the water, but I am seeing it on the side of my POV that is away from the sun, and not on the other side. I.e. if I stand on a point with the sun to the north, I am seeing the sun on the water to the south of me, and not on the water between me and the sun to the north. This is a bit the opposite of what I was expecting to see.

Just curious. Also the effect seems a bit strong, although that may have to do with the color of my sun.
#10
11/22/2003 (12:43 pm)
P = player,
< | > = direction facing,
S = sun,
0 = water.

If (P> 0
Its a sorry example I know, explain a bit more on what is happening Steve.
#11
11/24/2003 (8:50 am)
What I am seeing, is O > P < O > S , the sunlight is showing on the first O , and not on the second. I.E. if I face toward the sun, I do not see sunlight on the water, if I face away from the sun, I do. It's not that critical a question for me, as I believe that I am going to take this code out, as my project will not actually include any water surfaces for the most part.
#12
11/25/2003 (3:55 pm)
Screen please :)
#13
12/03/2003 (8:46 pm)
Steve, Im not sure why you are having problems with multiple waterBlocks not showing the specular correctly. I have had up to 4 blocks setup N-S-E-W just to test this and they all show correctly. Now if you were between the water and the sun you will not see the specular since it is a reflection based off your view of the sun and water.

@elettrozero, the only difference this as compaired to the standard version is the specular position on the water, the color of the specular and the specular power are now all based on the fxSun object by Melv May. If you move the fxSun then you move the specular as well, its all dynamic so you wouldnt not need to restart the mission to see the changes plus with a few changes you can easily add it in with the daylightCycle.

Sam G
#14
12/04/2003 (8:50 am)
@sam

Sorry, I haven't been looking at this, as I took the code out. As I mentioned, for our project it won't be significant, I was just looking at it for curiousity. I did see what I was describing, and my project is mostly just standard HEAD, but I have no idea why.
#15
12/04/2003 (9:06 am)
The fxSun has been linked to the invisible Sun light vector since 1.2 was released, if not a bit earlier, ie if you change azimuth and elevation in the Sun properties, the fxSun moves.
So that definitely made it into HEAD.
The shadow stuff didn't : there are quite a few places where you have to change that code, and I had to do it by hand, at least in two or three places, using Hobbs example from somewhere in the forums...