Spherical Reflection Maping

Blitz3D Forums/Blitz3D Programming/Spherical Reflection Maping

Crazidemon(Posted 2006) [#1]
I was searching these forums, and there seems to be very little about spherical reflection mapping. I'm in the middle of making a racing game, and was wondering how to make the cars reflect their environment and other entities. I was thinking of using another camera to take a spherical image around the car, and use it as the Spherical Reflection Map. Any ideas?


jfk EO-11110(Posted 2006) [#2]
spherical reflection is a built in feature, simply use Texture Flag 64. Search your blitz installation for the file "teapot.x", there's an example.

While this is some kind of fake reflection that is looking pretty good, you would need to use cubic enviroment maps to get (more or less) accurate reflections. Cubic enviroment mapping is also built in, but harder to implement and most of all it's much slower because in theory you need to take 6 renders (left, right,front,back,top, bottom). The renders will then be copied to the six buffers of a texture that was created using the cubic mapping flag.

For a nice looking car racing game you would probably use this as one texture layer, and an additional material on the other texture layer.

Check out my water example, it's using a cubic reflection method that is highly optimized in speed: http://www.melog.ch/dl/cubem_ter_water_jfk.zip


sswift(Posted 2006) [#3]
If you want the cars to reflect their environment, you need to render one cubic map from each car's location every frame. Then they will reflect everything around them as they move, including other cars. You will want to optimize this by rendering smaller cubic maps as the cars move into the distance though. That way you can have detailed reflections on cars which are up close and not waste so much time on distant cars.


VP(Posted 2006) [#4]
not even PGR3 on Xbox360 does cubic mapping per car (i.e. cars not reflected in bodywork). You probably could implement it on fast graphics cards, but you would have to trade off against something else (antialiasing, use a lower screen res).

Newer cards are fast, but even simple things like generating and mapping 48 (6 * 8 cars) textures every frame can have an impact.


Naughty Alien(Posted 2006) [#5]
..in your case, best solution will be to apply cubic map on to closest car in order to see proper reflections...you could apply same map to closest car on scene so reflection will be aprox. ok...for distanced cars it doesnt matter since you cant see that anyway...if you do update every 2-3 frames, it will be good enough for your game FPS and proper environment reflection..


sswift(Posted 2006) [#6]
Well, if you want to optimize things, then what you could do is calculate maybe one or two cubemaps somewhere on the track ahead and use those for all cars in that area.

Another way you can cheat would be to simply render a spherical environment map each frame and apply that to the cars. Since either way you have to update the map each frame, the spherical map only requires one render per car and will give you the same view as a cubic map. The real advantage of cubic maps is really when you don't need to update it every frame, and other special cases. Otherwise you'll get pretty much the same visual result from a spherical map.


Crazidemon(Posted 2006) [#7]
JFK EO-11110-The water doesn't come up on my computer, and the submarine is really dark. If you could post some screenshots that would be great. In my game there wont be more than 10 cars on the screen at once, but that's still 60 shots. As in my original question, how would I make a camera take a spherical image of the surroundings? Could I take one capture looking straight at the camera? Or would that not reflect at angles? The cube mapping seems like a good idea, but I'm not sure I want my game any slower.

Grant


jfk EO-11110(Posted 2006) [#8]


Well I hate to say it but contrary to what other poeple said in this thread, cubic enviroment mapping should notbe performed per object, but per camera.

The reason why is what you see on the surface of the object is not reflected from the surfaces normal angle, but from the mirrored angle relative to the camera.

I don't know hy my water example don't work on you machine, probably your card don't support some kind of mltitexture tha is used in the demo, but if cubic envifoment mapping works at all on your machine, then you may try to adopt my code of positioning the cubemap camera and use only one cubemap for the entire world.

while it's true that some things won't be correct due to logical reasons (camera cannot look behind things), the angles used are most accurate.

In may example, the cubemap camera is alsways relative to the camera, hence the reflections on the water are (more or less) correct. Now imageine if I ouwld position the cubemap camera in the middle of the sea and then move the player camera around - the result would be a mess.

However, even when you use only 1 cubemap, it's still 6 renderworlds and even with small cameraviewports this may still be very slow, especially in the wild, where tiny polycount Lab/Demo-conditions are illusionary.

So in your case, I would say WTF do I need accurate reflections? Did you ever see anybody style their hair in the reflections of a lamborghini that is driving with 300 mph?

Did you try the teapot demo? I would suggest: use spherical mapping as the teapot demo does, but use it as a second texture layer, so it's only a sideeffect and the main car color may be anything.

At least that's what I would do. I just try to imagine how that would look, a decent spherical reflection map, plus some ferrari red, plus a ton of Bloom FX - well pretty much like NFS.

BTW did you know project gotham racing on the Xbox360 runs at 30fps o_O (But at the ohter hand they got true motionblur, I guess they do 300fps, then create a blured frame out of 10 renders or something)


Crazidemon(Posted 2006) [#9]
Wow, wish my game would run at 300fps. I got the cubemapping working, but since it doesn't work on my computer, it just comes up blank. Will try it on another computer to see if it works.
Thanks for the help,

Grant


Picklesworth(Posted 2006) [#10]
A little example of faster cubemapping:
The Source engine (Half-Life 2) has a number of different pre-rendered cubemaps for areas on a map. When an object comes into the range of a particular cubemap node, it is set to use that cubemap.
(Of course, it's far more varied than this, I probably got some of it wrong, and there are lots of fancy details).


Braincell(Posted 2006) [#11]
Or you can build copies of your cars and a whole "subscene", where anything reflective is made out of stencil mirrors, then do that render pass and slap it on top of the real render with alpha. It would still be faster and you'd get top quality reflections on all cars. Theres a stencil mirror demo somewhere around here, but you'd need to know how to do multiple renders propperly :)

just a fun idea


BlackJumper(Posted 2006) [#12]
Did you ever see anybody style their hair in the reflections of a lamborghini that is driving with 300 mph?



... No ! Most women driving that fast are usually using the passenger sunscreen mirror - thank g0d they are so good at multi-tasking or they would make a mess with the lipstick they are also applying.


Crazidemon(Posted 2006) [#13]
Hmmm, I think I'll do what they do in Half Life, with the different cube maps for different areas. I'm about to go round to a friends house to try the cubemapping. Will post the result.

Grant


Sir Gak(Posted 2006) [#14]
Did you ever see anybody style their hair in the reflections of a lamborghini that is driving with 300 mph?




... No ! Most women driving that fast are usually using the passenger sunscreen mirror - thank g0d they are so good at multi-tasking or they would make a mess with the lipstick they are also applying.



LOL.