3D Graphics

The above videos show the real-time capabilities of my graphics software.

I've put this section in here because a lot of people I speak to seem to be interested in 3D graphics development and have asked me how I've gone about achieving it. If you too are interested then I hope this section can give you a few starting tips.

The GGS graphics system is a multiple hybrid real-time system. 

That is, it uses a combination of 3D and 2D graphics models, real photos and ground surface textures. 

Horizons and Trees are usually photos (although trees can also be 3D models), Skies are 3D model sky domes, ground surfaces are 3D models generated from 2D height maps combined with 2D surface textures or pure 3D models, water reflections are flat 3D models and buildings, bridges, benches etc are also all pure 3D models.

OpenGL terrain lighting is used throughout, calculated from terrain normals.

It was found that this combination proved to produce the best results while keeping scene rendering processing time within the time limits required for real-time rendering. ie. 24 frames per second.

Real-time rendering means that the time required to render (or draw) the scene is so fast that you can walk or fly around the course without the system requiring you to wait until the new view of the scene is re-calculated.  

All of the 3D graphics programming done in GGS was made with the OpenGL graphics library which comes with the Windows operating system. Another well known graphics library is DirectX from MicroSoft which is also an intergral part of the Windows operating system. With OpenGL or MS DirectX there is a somewhat conflict of opinion about which is the best path to choose. Both are designed to and do a great job of assisting  the graphics programmer but which is really the better I really couldn't say. However, from my own personal experience using both systems, I would recommend the Silicon Graphics OpenGL.system. I was up and running developing 3D graphics with OpenGL so much easier and faster than with DirectX.  

The following is a basic description of the methods I used to create the GGS 3D graphics using the OpenGL graphics library of functions.

Basic course layout

For the course layouts, I use a professional graphics tool to paint the course holes (rough, water ponds, fairway, footpaths, bunkers, tee areas and greens etc.) and define the surface structures.

I determined that I would need a 4096 (width) by 8196 (length) matrix to represent a single hole on the course. That amounts to more than 33 million elements per hole. Each pixel in the bitmap file that the graphic tool creates, represents a surface element and is mapped to the OpenGL 3D matrixes using the texturing method. The OpenGL "Depth buffer" is used to eliminate rendered surfaces that are behind surfaces in front. i.e. The terrain behind a hill will not be shown.

Terrain definition 

A Gray Scale Height map is used to define the terrain. For this I also used the graphics tool to create height  map bmp files. The brightness and color of each pixel in the height map file is used to define the height of each matrix element. 

Terrain Lighting and Shading

OpenGL lighting is used to automatically create terrain lighting and shading in the GGS system. However, gray scale light maps can optionally be used.

Reflections in Water

In order to realize this feature in a 3D terrain scene, you have to determine what part of the reflective surface - i.e. water- is actually visible to the user. This is where the OpenGL "Stencil buffer" comes in. The idea is to render (draw) the terrain scene to the stencil buffer but without the reflective surface. You then draw the objects, sky and terrain inverted and darkened to the color buffer using the stencil buffer as a template that only allows drawing where the stencil buffer has no entries. 

This is what the reflections in water look like when only the trees are reflected without the sky and terrain and a too high alpha channel. Very dramatic but the pond looks more like a swimming pool. 

With Sky and Terrain and the correct alpha channel set things start to look a little more realistic.

In order to draw the terrain to the stencil buffer without the reflective surface, I use an extra "Reflection map" that contains only two colors. One color is chosen to represent non reflective terrain and the other to represent the reflective surface part of the terrain. When drawing the "reflective" terrain map to the stencil buffer, a filter is set to only allow the non-reflective surfaces through. 

Splash in the water using a Particle System

In contrast to really playing golf, I quite enjoy hitting my ball in the water with the simulator. I've ridiculously over done the splash here of course and made it very dramatic with a big splosh sound. But it's fun to watch and was fun to program as well.

 

In order to create this effect I've used a so called "Particle System". 

A particle system is a collection of elements -or particles - that each have a life of their own and have attributes such as velocity, color, life span, position, size and weight. Each particle represents a water droplet here and there are 4000 of them in my rendering of a splash. Each of the water droplet's attributes are re-calculated on every frame rendering until they eventually die (evaporate) or hit the water.

A particle system contains an "Emitter" that has a 3D position in the scene (i.e. the co-ordinates of where the ball entered the water) and controls the number of particles that are shot into the air per frame update. A particle update manager controls  each of the particles' attributes - current velocity, 3D position, color -  which are calculated by the forces (i.e. gravity and wind strength/direction) acting on the particle. 

Of course, the splash wouldn't be complete without a ring wave on the water emitting from the position of the ball entry into the water. To create this effect I blended in a "Disk" with a big hole in the middle thus creating a ring. The ring's radius is expanded on each frame update and it's view is set to that of the water.

Water ripple is achieved by blending a wave texture to the reflection model and slowly moving the texture co-ordinates on every frame update.

Large landscape rendering is possible with the new GGS-ProX version of the software.

I use a Level-of-Detail method to render the ground surfaces so that ground/grass detail is greater when near to the camera and less when further away from the camera.

This saves a lot of grahics processing time while still looking good.

Multi-texturing is used to obtain ground detail. This is achieved by rendering a large global texture for the enitire course hole and then repeat-rendering a suitable small grass structure texture on top of this.

Surface Texture Objects are used to create clear surface transistions-  ie. rough grass to sand bunkers.

 Sky Domes

                

Skies are done with either sky boxes or Sky Domes (Hemispherical skies). As oposed to sky boxes,  sky domes are seamless no matter where you point the camera. (Even straight up). They take quite a lot more processing to render though.

 

Coordinate system

GGS uses the above shown coordinate system. 

 

The entire simulator and golf course 3D graphics software is written in Microsoft C++ 6.0 using Silicon Graphics OpenGL libraries for Graphics and MS DirectX 8.0 for Sounds.

"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."

To learn more please see the Tutorials sections on this site.

I hope that this little 3D graphics insight and the tutorials have been of some interest to you.

Programming 3D graphics is hard work at times but if you are keen the rewards are tremendous.

see AboutMe for more fun