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.
[Image: systw4yz.jpg]

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
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.
Quote this message in a reply
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!
Quote this message in a 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!
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #5
Skorche: cool idea, mind if I extend it a bit?

Unknown: Grab this: [Image: one-d-texture.png] 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.
Quote this message in a reply
DoG
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.
Quote this message in a reply
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!
Quote this message in a reply
Moderator
Posts: 434
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.
Quote this message in a reply
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."
Quote this message in a reply
DoG
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.
Quote this message in a reply
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. Smile
Quote this message in a reply
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. Grin

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. Grin

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Temple Run Magnet Effect anmetv 2 1,219 Dec 1, 2013 05:24 PM
Last Post: JustinFic
  Using blending for a text fading effect. cjcaufield 2 4,269 Jun 30, 2010 08:21 PM
Last Post: cjcaufield
  Halo-Effect in 3D OpenGL ES Bersaelor 4 5,697 Dec 17, 2009 11:54 AM
Last Post: Mark Levin
  How to do a Quick, Dirty bloom effect FAST! Oddity007 12 7,837 May 9, 2009 09:42 AM
Last Post: aardvarc
  malloc particle effect (glDrawArray) Graphic Ace 1 3,071 Mar 15, 2009 03:13 PM
Last Post: maximile