G3D 6.07 3D Engine

F6ad85487ec271d99a0ef7a4e1b426d6
0
corey 101 Oct 09, 2005 at 14:00

05-10-07.jpg

Description

This is a rendering of a simple scene using the ArticulatedModel class - a new contributed code class that will soon move into the library after refining. This class is a wrapper for 3DS model loading, posing, shading and shadows. Each of the objects in the scene are dynamically shaded and shadowed using 2.0 pixel shaders with GLSL. The demo that renders this scene is available in /contrib/ArticulatedModel/demo.

G3D 3D Engine

The G3D 3D Engine has just released version 6.07 and is available at http://www.graphics3d.com. This is one of the last releases in the 6 series and includes several performance improvements, common geometry rendering, and enhancements to the application and window frameworks such as multiple context support. A complete list is available at http://g3d-cpp.sourceforge.net/.

G3D is an open-source, multi-platform 3D engine that currently provides two libraries: G3D and GLG3D. G3D is a support library that includes matricies, vectors, common shape geometries, coordinate frames, image loading and saving, 3D mathematics and debugging utilies and much more! It can be use separate from the rendering and application framework code for those wanting to develop their own engine or non-OpenGL based renderer. GLG3D is the OpenGL wrapper and application framework library. This library include an OpenGL wrapper, model architecture, ARB shader object wrappers with support for Cg, GLSL and ARB assembly, VAR support, camera control, lighting and sky helpers, multi-platform window and context creation and management and a simplified application framework. The GLG3D library especially allows developers to rapidly design a complete system.

Documentation for the current release is available at http://g3d-cpp.sourceforge.net/html/index.html and is something we are constantly trying to improve. One of the more useful areas is the topic index and quickly shows the way the classes are split up.

Technical Sample

I think a sample of the basic functionality provided for shaders should be simple enough to follow in this context. There are more complex and larger features being designed through the ArticulatedModel and SuperShader classes. This is the description we provide for the main G3D::Shader class.

Abstraction of the programmable hardware pipeline. Use with G3D::RenderDevice::setShader. G3D::Shader allows you to specify C++ code (by overriding the methods) that executes for each group of primitives and OpenGL Shading Language (GLSL) code that executes for each vertex and each pixel.

Uses G3D::VertexAndPixelShader internally. What we call pixel shaders are really “fragment shaders” in OpenGL terminology.

Unless DO_NOT_DEFINE_G3D_UNIFORMS is specified to the static constructor, the following additional variables will be available inside the shaders:

    uniform mat4 g3d_WorldToObjectMatrix;
    uniform mat4 g3d_ObjectToWorldMatrix;
    uniform mat4 g3d_WorldToCameraMatrix;
    uniform mat4 g3d_CameraToWorldMatrix;
    uniform int  g3d_NumLights;        // 1 + highest index of the enabled lights
    uniform int  g3d_NumTextures;      // 1 + highest index of the enabled textures
    uniform vec4 g3d_ObjectLight0;     // g3d_WorldToObject * gl_LightState[0].position

If your shader begins with include or define the line numbers will be off by one in error messages because the G3D uniforms are inserted on the first line.

ATI’s RenderMonkey is an excellent tool for writing GLSL shaders under an IDE. You can then load those shaders into G3D::Shader and use them with your application.

Example

The following example computes lambertian + ambient shading in camera space, on the vertex processor. Although the shader could easily have been loaded from a file, the example loads it from a string (which is conveniently created with the STR macro)

Vertex shaders are widely supported, so this will run on any graphics card produced since 2001 (e.g. GeForce3 and up). Pixel shaders are only available on newer cards (e.g. GeForceFX 5200 and up).

Note: IFSModelRef and ShaderRef are reference counted and provide a pointer to the respective object. This the typical way of passing around objects in G3D.

   IFSModelRef model;
   ShaderRef   lambertian;

   ...

Initialization

   model = IFSModel::create(app->dataDir + "ifs/teapot.ifs");
   lambertian = Shader::fromStrings(STR(

     uniform vec3 k_A;

     void main(void) {
        gl_Position = ftransform();
        gl_FrontColor.rgb = max(dot(gl_Normal, g3d_ObjectLight0.xyz), 0.0) * gl_LightSource[0].diffuse + k_A;
     }), "");

    ...

Rendering loop
    app->renderDevice->setLight(0, GLight::directional(Vector3(1,1,1), Color3::white() - Color3(.2,.2,.3)));

    app->renderDevice->setShader(lambertian);
    lambertian->args.set("k_A", Color3(.2,.2,.3));
    model->pose()->render(app->renderDevice);

This example explicitly sets the ambient light color to demonstrate how arguments are used. That could instead have been read from gl_LightModel.ambient. Note the use of g3d_ObjectLight0. Had we not used that variable, Shader would not have computed or set it.

Finishing up

I hope this gives some insight into the current development and depth of G3D. The basics provided are quite extensive and are improving with each release. The more users develop and provide feedback, the more we refine and add.

As you can see above, modern features such as shader objects are incorporated and rapidly improving. All a developer really has to do is provide the vertex or fragment shader and any user defined variables. G3D will then load, compile and set the variables. The ability to easily use tone maps and shadow maps will soon be out of development and into the main library. Only user development and tests can help.

There are many features that have been in G3D that are just as useful. The built-in fast shadow renderer was developed between our project owner, Morgan McGuire and others including NVIDIA. More information on that is available at http://g3d-cpp.sourceforge.net/html/namespaceG3D.html#a340. This is for stencil based shadows without the use of shaders. Along with this, an easy to use wrapper for VAR objects is available and is our preferred rendering method. If VAR objects are not available, a fallback system is automatically applied. Details information on the use of VAR objects is available at http://g3d-cpp.sourceforge.net/html/classG3D_1_1VARArea.html.

6 Replies

Please log in or register to post a reply.

F6ad85487ec271d99a0ef7a4e1b426d6
0
corey 101 Oct 09, 2005 at 17:37

Unfortunately, this is about as quick of a description as I could write and without a way to preview and refine :) You’re basically seeing a description of our base shader class.

It doesn’t really go into detail on the implementation of shaders, VAR/VBO’s and new shadow features. Hopefully, we’ll pique interest and have more inquiries on the forums or to Morgan.

corey

3c6597370b476903ed475f70b4b3ce31
0
john 102 Oct 09, 2005 at 19:13

This engine looks impressive. I really like the design of the engine.

I never took a look at how your rendering interfaces are designed. How hard would it be to add a DirectX renderer? Or is it solely optimized for OpenGL?

Ea1e202bbd97524308adb219c6c33a73
0
Methulah 101 Oct 09, 2005 at 23:59

Well done on the detail and depth of your description.

F6ad85487ec271d99a0ef7a4e1b426d6
0
corey 101 Oct 10, 2005 at 00:57

@john

I never took a look at how your rendering interfaces are designed. How hard would it be to add a DirectX renderer? Or is it solely optimized for OpenGL?

GLG3D is optimized for OpenGL. However, the G3D (math, support) library is complete independent of the rendering library GLG3D.

One could write a DirectX renderer. It would have to be from scratch though. There are many people who use the engine just for the non-rendering library but I’ve not had feedback on directly mapping that to a DirectX interface.

corey

2ec18ba309975c5a64859a8e0ec9265b
0
Hodge 101 Oct 11, 2005 at 00:47

It’s a great thing your team decided to release the engine under the gpl. The 3d engine doesn’t look bad at all.

F6ad85487ec271d99a0ef7a4e1b426d6
0
corey 101 Oct 11, 2005 at 01:01

It’s under the BSD license.

The engine can generate a .txt file of the license if needed.

corey