3D Programming

  • #1
Was just wondering if anyone here has tried 3D programming. If you have, what language did you write in, what difficulties did you have, and what did you find interesting about it?

As of now I know of Direct3D and OpenGL, but, if I'm not mistaken, you can use different languages to write shaders for these different APIs. For example, the Cg language can be used to write shader programs for both APIs, while HLSL is used for Direct3D specifically, and GLSL for OpenGL specifically.

That's the extent of what I 'think' I know.
 

Answers and Replies

  • #2
54
0
I very briefly did some exploration working directly with OpenGL, but it seemed like a ton of work to handle things at that level. So then I learned 3D in Java using java3d. I found a tutorial and very diligently followed it step by step. A few days in, I was able to do some cool stuff from scratch.

This was several years ago, so I'm sure a lot has changed. But the key concepts that one should know, like what a "scene graph" is, how to handle lighting, building surfaces with triangles, etc... stuck with me and I think translates from one environment to another.
 
  • #3
chiro
Science Advisor
4,797
132
Was just wondering if anyone here has tried 3D programming. If you have, what language did you write in, what difficulties did you have, and what did you find interesting about it?

As of now I know of Direct3D and OpenGL, but, if I'm not mistaken, you can use different languages to write shaders for these different APIs. For example, the Cg language can be used to write shader programs for both APIs, while HLSL is used for Direct3D specifically, and GLSL for OpenGL specifically.

That's the extent of what I 'think' I know.

I used to do this kind of thing daily in a job. Here's my advice:

Understand the math

Things involving geometry like:

Convex Hulls, different types of projections (orthographic,perspective),Splines in different dimensions (curves,surfaces,volumes),other interpolation techniques (Catmull-rom,Hermite,etc),matrix and vector techniques, and quaternions are things you should know.

Although you don't have to do this anymore, its helpful to understand triangle rendering, sampling techniques (texture sampling that is) things like filtering (anti aliasing) and if you're keen ray-tracing and radiosity (not required by any means though).

Understand the architecture of GPU's and standards

DirectX and OpenGL do have differences but the fact is that rendering a triangle in OpenGL is going to be the same as rendering one in DirectX and both standards are often motivated by the same ideas (both have a matrix pipeline, both have shader standards and so on).

One thing that is different is when you get into extensions (like in OpenGL). When a GPU adheres to a standard its guaranteed to have all of the functionality in that standard. But GPU cards also offer extra things that are on top of the standard. One example is with Doom 3: The nVidia cards like Geforce 2 offered a texture operation called DOT3 which is basically a vector dot product operation. You use this for the normal mapping technique which takes the dot product of a lighting vector and another texture to give the sense that a surface "looks like a complex surface" rather than a plane.

Using something like Cg can greatly speed up development time and I don't hesitate in recommending something like that.

One last piece of advice: simulation engines (whether its a game engine like Unreal or some scientific visualization package) are complex systems. When you're writing these kinds of things try to think about the right kind of interfacing/encapsulation that say a renderer should have and say a geometric primitive should have.

For example a geometric primitive should have a function that exports its geometric structure to triangles since that is the standard primitive that GPU's use. You would probably also benefit by adding a standardized ray-intersection function that returns the point of intersection and the reflection vector from that surface.

When GPU's offer support for non-linear objects (ie objects other than triangles) like for example splines, then you can add something in your renderer to override behaviour for spline rendering.

Its a lot to take in I know, but if you get your hands dirty, you'll understand what I mean and you'll no doubt get better with progression of time.
 
  • #4
Awesome. Thanks for the great information.

Would it be silly to think that I could learn the basics of 3d programming while still working my way through c++? Which is to say I'm still a beginner in c++, but I know the basics of functions and variables and different statements. Did you find that knowledge of a prior knowledge helped out a lot?
 
  • #5
chiro
Science Advisor
4,797
132
Awesome. Thanks for the great information.

Would it be silly to think that I could learn the basics of 3d programming while still working my way through c++? Which is to say I'm still a beginner in c++, but I know the basics of functions and variables and different statements. Did you find that knowledge of a prior knowledge helped out a lot?

Absolutely, I see no problem learning 3D specific stuff, while you hone your skills in programming.

There are quite a few open source projects that are 3D engines that are well designed and coded.

One piece of advice though: 3D engines are complex projects. If all you do is display an object rotating in a window you could get away from using something like GLUT (OpenGL Utility Library), but if you want to use your 3D code as part of something else (like say a game, 3D editing software like 3DSMAX, or for visualization for some other purpose), then you will need to design something that is complete, yet flexible enough to do what you want to do and integrate into your other code.

If you asked my what is the most important thing in design, I would say standardization and flexibility. It may seem like an oxymoron answer but I'll explain it.

In programming we typically have standards. It could be a network protocol like FTP or HTML, or it could be a standard for GPU rendering primitives (ie triangles).

You have to be aware of current standards when you are designing things. If you want to take advantage of the hardware on graphics cards, you need to know the standards. You are already aware of this since you know about OpenGL and DirectX. Explore these standards to get a feel for the standard rendering process and use that to design your appropriate data structures.

The next is flexibility. An example of this is say a primitive class and a class factory. Your primitive class will convert your geometric object to a set of triangles which the renderer will use to render the object on the screen. But the real reason to use a primitive class is to allow you to use custom objects where say in a Sphere class you use parametric formula to generate triangles with some specified resolution level.

Now the class factory part helps you have a system that is extendable. For example if you have a plugin system that is integrated with a class factory system, you can for example create a SDK (software development kit) that allows other users to extend the system without needing to touch the main engine executable.

The kind of extensibility I'm talking about is crucial to any decent application. You learn this kind of thing by looking at standards like COM, OLE, CORBA and similar frameworks.

While you are learning C++, I would look at something like COM and look at the main interfaces that are used. You will see a lot of concepts that are the result of designers getting better with newer systems.

I wish you the best of luck. Sometimes you will hit walls and bang your head, but there's nothing like the feeling of getting everything to work and seeing the result of a program you made actually work the way it was intended.
 

Related Threads on 3D Programming

  • Last Post
Replies
1
Views
577
  • Last Post
Replies
4
Views
6K
  • Last Post
Replies
3
Views
637
  • Last Post
Replies
4
Views
734
Replies
18
Views
3K
Replies
32
Views
3K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
16
Views
2K
  • Last Post
Replies
1
Views
576
Top