How to acheive this effect with shaders

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
Is it possible to make 3d objects using opengl and shaders look something like this, I know you could do it by calculating the lighting yourself and drawing lines instead of polygons, but I wonder if there's a way you could do it in realtime with shaders.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Sage
Posts: 1,487
Joined: 2002.09
Post: #2
Automatic texture coordinate generation perhaps?
Use it to map a 1D contour texture onto the pipes. There's an example of that near the end of the red book's texturing chapter.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
yes, I think this might be just the thing.
Thanks!

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
After a bit of reading about the various ways to do texture generation I think what I need to do is texture projection.
Im having a lot of trouble finding anything useful on the net about this though, anyone know any good resources where I can learn how to do this?

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Oldtimer
Posts: 834
Joined: 2002.09
Post: #5
Skorche: cool idea, mind if I extend it a bit?

Unknown: Grab this: 1D texture. (It's not really 1D - just scale it down or crop it. I had to make it wider to show up in Safari) Then, you generate your texture coordinates by hand. It will be really simple.

You want the texture coordinates to run from 0 to 1 over the "depth" of your pipe. So, the furthermost vertex of your pipe should have a texture coordinate of zero, and the closest 1. To do this, just iterate over the object's vertices and find the min and max Z values. Then, calculate the "thickness" or "depth" of the pipe: float thickness = maxZ - minZ; Then, iterate over the vertices again, and find the texture coordinate like so: texCoord = (currZ - minZ) / thickness;

This will texture your object as if the texture was projected from above. (This assumes that Z is pointing into the screen, and you may have to swizzle the coordinates or rotate the texture 90Â°, but you'll figure it out). What's even cooler: lighting will work, as will vertex coloring.
Moderator
Posts: 869
Joined: 2003.01
Post: #6
You could also render edges in OpenGL with rounded blocks, that oughta look just like it, the impossible intersections might be a bit tricky though.
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
I've had some success trying to render a torus with Fenris's idea, I haven't managed to get it looking quite right though. I think I need to take surface normals into account instead of z components but I get strange results when putting the dot product of the normal and lightsource direction normal into the range 0-1.
What do you mean by rounded blocks DoG, would I draw each curved part as a seperate block and have it already texture mapped or something else?

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Moderator
Posts: 455
Joined: 2002.09
Post: #8
I believe he's saying that you could light the scene from all 4 sides rather than from above, and where you want the contour lines to appear you would put a little ridge in the geometry. The cross-section of the pipe might look something like this:
Code:
```_____|   _| _| |```
But the verticals would have to be slightly slanted rather than vertical, so that from above you'd see them catching the light.

Textures would be a computationally cheaper solution if you can get them to work.

With either technique once you got some building blocks done you could build up a larger scene without too much effort, assuming the geometry is fairly repetative (which the picture above isn't.)

Measure twice, cut once, curse three or four times.
Moderator
Posts: 529
Joined: 2003.03
Post: #9
I hope this means your making an OS X sequel to System's Twilight.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Moderator
Posts: 869
Joined: 2003.01
Post: #10
I meant that you can get OpenGL to render edges of polygons you specify, so if you draw cylinders, viewed from the side, and you use a regular subdivision, then you could just draw all the lines along the length of it. Or, you could just draw the lines separately and fill in the z-buffer with black polygons so that occlusion is right.
Oldtimer
Posts: 834
Joined: 2002.09
Post: #11
unknown: I just wanted to clarify: you'll need the normals for lighting, but the texturing should be done in z-space only.
Sage
Posts: 1,403
Joined: 2005.07
Post: #12
Lesure Suit Lurie Wrote:I hope this means your making an OS X sequel to System's Twilight.
Well, I know I couldn't match up to the greatness of System's Twilight but I am thinking about making a story based puzzle game of the same ilk.

I think I just worked out how to do it, its a combination of Fenris and DoG's methods.
I can get the polygon edges z-depth and then use the texture for a lookup to decide whether or not to draw an edge.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!