PDA

View Full Version : 3D Texturing and Lighting



Chalnoth
11-05-2002, 07:25 PM
More 3D texturing fun! Now I'd like to see if I can add more of a 3D effect to my program. Specifically, I'd like it to get darker with depth. Does anybody have any ideas about what the best way to do this might be?

Just for reference, here's my program (for as long as my IP address remains the same...):
http://64.165.70.131/orbital.exe

This is essentially a view of one of the P-orbitals of a hydrogen atom (an excited electron state for this atom). You can use the arrow keys and the delete/insert keys to rotate the orbital. There will be a delay at load time while the program calculates the probability distribution for the orbital. Additionally, this program will crash if your video card doesn't support glTexImage3D. I've only tested it on my GeForce4, so I would only recommend attempting it if you have a GeForce3 or GeForce4 (though it *should* work on any Radeon as well).

Any ideas on the best way to create the effect of depth?

yakuza
11-05-2002, 08:48 PM
That's pretty cool looking! When I first started the program, and was looking at it sitting there with no movement, I got the illusion that it was moving away into the screen. http://www.opengl.org/discussion_boards/ubb/smile.gif

Incidentally, I ran it on my Radeon 8500 with no problems, and it didn't take any noticeable time to load (1.1 ghz Athlon).

I've never tried 3d textures before, so I'm afraid I don't have any input about your question, sorry. I enjoyed trying your app, though! Thanks!

Edit: Maybe light attenuation would give the desired effect? I'm not sure how that works with 3d textures...

[This message has been edited by yakuza (edited 11-05-2002).]

harsman
11-06-2002, 05:07 AM
The standard OpenGL way to color things based on their depth (in eye space) is fog. Look it up in the spec, it's pretty simple. I'm sure you can find tutorials on OpenGL fog via google if you find the spec a bit hard to read.

Chalnoth
11-06-2002, 05:24 AM
Well, light attenuation shouldn't work any differently on a 3D texture than it does on a 2D texture. You always apply a 3D texture as a 2D cross section of the texture onto a 2D polygon.

[This message has been edited by Chalnoth (edited 11-06-2002).]

Chalnoth
11-06-2002, 05:49 AM
Well, after a little bit of playing around with various settings, I can't get the fog to look very good. While it's obvious that with the fog enabled, the scene is darker, depth is not very apparent.

I'd like to try light attenuation. How would I accomplish this?

yakuza
11-06-2002, 07:16 AM
I'm sure there are a ton of resources out there for info on light attenuation, here's one of the first links that turned up doing a Google search on "opengl light attenuation":
http://tc1.chemie.uni-bielefeld.de/doc/OpenGL/hp/Reference/glLight.html

Chalnoth
11-06-2002, 06:24 PM
Hrm, still having a hard time.

For some reason, with fog, I can't get any sense of depth. And I can't seem to get the standard OpenGL lights to light my surface. Here is my current lighting code:



float difcolor[4] = {0.0, 0.0, 1.0, 1.0};
float difpos[4] = {0.0, 0.0, 2.0, 1.0};
float ambient[4] = {0.0, 1.0, 0.0, 1.0};
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, difcolor);
glLightfv(GL_LIGHT1, GL_POSITION, difpos);
glEnable(GL_LIGHT1);

Since most of this is the same as seen in Nehe's tutorials, I really don't see why it wouldn't work. I tried to use colorful lights to be certain whether or not I was getting any lighting...

Any ideas?

yakuza
11-06-2002, 08:20 PM
Well, you don't have a glEnable(GL_LIGHTING) in there, perhaps a typo?

Chalnoth
11-06-2002, 11:18 PM
Argh. Geez...

yakuza
11-07-2002, 06:51 AM
Hehe, I take it by your comment that you had forgotten that. http://www.opengl.org/discussion_boards/ubb/smile.gif Did enabling lighting get the results you were looking for? I'd like to take a look at the demo if/when you update it.