Dark Bit Factory & Gravity

GENERAL => Challenges & Competitions => Topic started by: hellfire on May 01, 2008

Title: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 01, 2008
Hi everybody,

here's an effect inspired by monkey (http://www.nullsoft.com/free/monkey), a winamp-plugin by Ryan Geiss.

Unlike the original, I wanted to give it a more "realistic" look with smoother surface, proper texturing and a more organic touch.
I already wanted to try this for years, but never really found time until yesterday.
The implementation was pretty straight forward, I did the geometry-generation (including parameter tweaking) yesterday evening and - 1st of may is holiday here :) - a *very* simple texture-generator with gui today.

So what it does is twirling a set of intersecting pipes into a volume (effectively a 64x64x128 grid) and generating the iso-surface using a marching cubes algorithm.
The shading is done by simple vertex-coloring using some kind of local ambient-occlusion approach - since I got the volume-grid anyway, I simply look for potential occluders in the vertex' surrounding.
Texturing is done using one simple generated 2D texture which is mapped from all three canonical axes and blended over at the cross-sections - which works pretty well as long as the texture has rather low contrast.
Since this is done at per-pixel-level it requires ps 2.0 to run (actually it *would* work with ps 1.1 but glsl doesn't really support those).
The texture itself is generated from a set of differently coloured and blended plasmaclouds (and looks like this (http://hellfire.untergrund.net/projekte/texgen.gif)).
When I have some spare time again, I will definetly try to improve it, as it still looks somewhat too ... generated.
But since this will probably not happen before the end of the challenge, I'm already posting it now.

I didn't go for much size-optimizing here, but then again it isn't actually big either.
At the moment the source is probably way too messy to be of any use, but if anyone is interested in details, I'm willingly telling.

Enjoy.


If, for whatever reason, it won't run on your machine, here (http://hellfire.untergrund.net/videos/cave.avi) is a video, too.
Also attached a shot of the current texture (downsampled, "actual size" is 2048x2048).
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Clyde on May 02, 2008
Wow! Thats amazingly awesome. Welldone dude :)
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: rain_storm on May 02, 2008
Yeah very impressive beautiful textures, this is an awesome entry hellfire
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Rbz on May 02, 2008
Really good one, well done  :cheers:
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Voltage on May 02, 2008
Jeepers!  Great entry, this is fantastic.  Very professional. 

I like the geometry the most, although the textures and shading are funky too. 

Excuse me while I go and look up marching cubes....
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: va!n on May 02, 2008
@hellfire:
wow! its fucking great and kicking ass! :goodpost:
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Pixel_Outlaw on May 02, 2008
Marching cubes algorithm is now free for public implementation. There was a time when it was protected.

GREAT Work!
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 02, 2008
Thanks for your appreciation!
At the moment it's a bit boring to look at, guess I should add some dynamic lighting or something...
I'm open to any ideas :)

A comprehensive article about marching cubes can be found here (http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise).
Patents aren't of much concern for uncommercial home-dev - at the end we're using mp3 (http://mp3licensing.com/royalty/software.html), too...
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Optimus on May 02, 2008
Wow! Nice, very nice!!!
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Shockwave on May 02, 2008
What can I say except it looks fabulous!
Thanks for entering the challenge and good luck with the voting, this will do well in the voting I think.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: mind on May 02, 2008
damn, thats pretty damn funky :D good job

and speaking of beeing interested, i wouldnt mind taking a peek at your texture code.. those clouds look pretty nifty :)
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 02, 2008
Quote
i wouldnt mind taking a peek at your texture code..
Oh well, there's absolutely nothing special about that, except maybe that I'm working at 16bit-precision per channel, so I can mess with the levels without running into colour-banding.
The "cloud" is generated recursively:
starting from a flat (all 4 corners have equal colour) 0,0..512,512 image, a new point is created in the center which gets the average of the corner-colours plus/minus some randomness. The resulting four sub-images are then subdivided again until a 1x1 area is reached where the current colour is stored.
All the rest is just some histogram-equalization (of the simplest form), colouring and alpha-blending between layers.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: mind on May 02, 2008
Quote
i wouldnt mind taking a peek at your texture code..
Oh well, there's absolutely nothing special about that, except maybe that I'm working at 16bit-precision per channel, so I can mess with the levels without running into colour-banding.
The "cloud" is generated recursively:
starting from a flat (all 4 corners have equal colour) 0,0..512,512 image, a new point is created in the center which gets the average of the corner-colours plus/minus some randomness. The resulting four sub-images are then subdivided again until a 1x1 area is reached where the current colour is stored.
All the rest is just some histogram-equalization (of the simplest form), colouring and alpha-blending between layers.


ohh a normal recursive subdivision plasma :) it looked very different from those plasmas, but i guess its the histogram levels and blending used :)
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Jim on May 03, 2008
Very nice indeed!
Jim
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Dr_D on May 03, 2008
Wow. That's just... Wow.  :cheers:
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: stormbringer on May 03, 2008
Fantastic indeed! Maybe it just misses a starship and some aliens to blast! Never saw a shoot'em up usin this.....
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: benny! on May 05, 2008
Awesome effect. Runs very smooth here!
Well done, hellfire!!!

Keep us informed with any new version you produce!


@Stormbringer:
That would be indeed interesting to see a game like
this. Remember DESCENT ?
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 09, 2008
Since you asked, here's a different version ;D
Played a bit with light, color and texture - not exactly what I was looking for, but what the hell...
Now looks different every time you run it.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Rbz on May 09, 2008
Should it look like this image ???
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 09, 2008
Err, well... no!
But to be honest I somewhat like that, too :)
What card is that?

Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: benny! on May 09, 2008
@hellfire:

same fx like rbz reported here.

card: NVIDIA GeFroce 7600 GT.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 09, 2008
An interesting bug :)
I use the z-component of the reflection-vector (which can be negative) as a fresnel-factor and take it ^12 to make it a bit shiny.
So - I thought - an even exponent should give a positive result, no matter what the sign is.
At least that's the case on ATI.
Nvidia, however, seems to use a very different approximation of pow() which is dropping negative at some point.
Negative factors don't work so well on colours, though ;)
Going to fix that later...
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: benny! on May 09, 2008
@hellfire:
Maybe these links help:

http://lists.apple.com/archives/quartzcomposer-dev/2008/Apr/msg00062.html (http://lists.apple.com/archives/quartzcomposer-dev/2008/Apr/msg00062.html)
http://lists.apple.com/archives/quartzcomposer-dev/2008/Apr/msg00064.html (http://lists.apple.com/archives/quartzcomposer-dev/2008/Apr/msg00064.html)
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 09, 2008
Thanks Benny. Thought it was only somewhat unprecise but Nvidia gives even NAN for pow() on negative numbers - good to know.
Reattached a (hopefully) fixed version.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Rbz on May 10, 2008
Hmm, I know it's hard to hear this but it crashes here after precalc... :(

I wonder when shaders will be compatible everywhere  :-\



P4 2.8Ghz - Nvidia 6600GT
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Jim on May 10, 2008
I my glsl manual it says this
Quote
genType pow (genType x, genType y)
  Returns x raised to the y power, i.e., x ^ y
  Results are undefined if x < 0.
  Results are undefined if x = 0 and y <= 0.
Even though, mathematically speaking, x need not be positive.

Jim
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Shockwave on May 10, 2008
Crashes here too P4 3ghz, ATI X1650.

The screenshot looks exceptional.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 10, 2008
Oh dear, I've probably screwed something up, but at the moment I've got no idea what and where (runs fine here, also in debugger)...
Attached (up) a version which displays some debug-output.
Would be nice if someone could tell me where the crash happens.

Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Rbz on May 10, 2008
Yeah, "test.zip" with debug info works like a charm, "test2.zip" crashes

It looks really cool

Take some karma for fixing it :)
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Deleter on May 10, 2008
test works for me just fine, but it looks no where as cool as that screenshot. When I run it it just looks gray white and black, no cool colors
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Shockwave on May 11, 2008
test works for me just fine, but it looks no where as cool as that screenshot. When I run it it just looks gray white and black, no cool colors

In that case it's fuxxored on your machine.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Deleter on May 11, 2008
test works for me just fine, but it looks no where as cool as that screenshot. When I run it it just looks gray white and black, no cool colors

In that case it's fuxxored on your machine.

Yeah, just like the spiders entry...its all the in the shaders, stupid ati...maybe I should try updating mine...
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Pixel_Outlaw on May 12, 2008
This actually marks my first time seeing the algorithm implimented in real time! I'm just shocked at how you pulled off this advanced programming algorithm. Damn nice sir, DAMN nice.  :goodpost:
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 12, 2008
Thanks for testing and feedback!
Though, I've a bit lost track of what version is now running on which hardware...

Quote
When I run it it just looks gray white and black
That probably means you don't have shaders 2.0...
At least that's what it does on a geforce4mx: the driver successfully compiles the shader, but totally fails in activating the fragment program (and keeps in fixed-function-mode). The vertex program is emulated in software though.

Quote
"test.zip" with debug info works like a charm, "test2.zip" crashes
That's wicked since both version only differ in shaders.
Could you please post what the crashing version outputs into the console window?
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Shockwave on May 12, 2008
Quote
When I run it it just looks gray white and black
That probably means you don't have shaders 2.0...

So does that mean that GLSL is not backwards compatible? I have shaders 3.0 here and get grey shapes. Same happens with Jim's entry too.

XTI X1650
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 12, 2008
Quote
does that mean that GLSL is not backwards compatible? I have shaders 3.0 here
No, that's certainly not the case, ShaderModel 2 is just a subset of Model 3.
What I wrote above applies to old Geforces/Radeons (not supporting fragment programs or just Shader-Model 1.x): The driver exposes all functionality (all extensions are available) and the shader compiler is able to produce valid code, but the card just can't handle it in hardware.
In that case, Geforces don't activate the fragment program and just use parameters (coming from the Vertex-Shader) affecting the fixed-function pipeline for rendering - in my case that's just the vertex-colour (resulting in a grey gradient from front to back).
The same happens on ati with non-conform shader-code (the compiler won't produce code from the fragment-program and leaves the fixed-function-pipeline active on rendering) - there should be a message about that in the console-window...
If the shader-code exceeds the size-limit on shader2-hardware, ati falls back to software-rendering (I'm not quite sure what Nvidias does - this only applies to Geforce5xxx-based cards).
The vertex-program is seldom a problem since it can be emulated in software without such a big performance-penalty (mapped to sse/3dnow, just producing heavy bus-traffic).

What's the actual problem here is still a bit out of my understanding.
I've tested both versions on Radeon 9600 (Shader 2.0) & Geforce 7600 (Shader 3.0) and they both work fine. If the shader doesn't work on your Radeon, it's probably because of different driver version (I'm using Catalyst 8.4 from September 2007) which might include a somewhat different shader-compiler or just features new bugs...
A crash, however, is most probably caused by my sucking code ;)

Edit: Updated drivers to current version and can't see any difference, still it's not impossible that some other code-path for other/newer hardware might cause trouble of some kind...

Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Shockwave on May 12, 2008
Thanks for the information. I have never tried shader language so it's all a bit of an enigma to me.

Strangely I tried running test2 again and this time it ran perfectly. Maybe there was something else interfering with it on my system as I have had a little bit of a clean-up tonight.

It looks really impressive, like wet stones. fantastic to look at.



Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Jim on May 12, 2008
On my Vista, 8600GT the first post didn't have any colours, just grainy grey, it still looks cool so I didn't notice anything wrong.  test.exe works brilliantly, and makes the effect even better with the specular colours.  test2.exe crashes immediately.

Jim
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Rbz on May 13, 2008
Quote
"test.zip" with debug info works like a charm, "test2.zip" crashes
That's wicked since both version only differ in shaders.
Could you please post what the crashing version outputs into the console window?
After a fast precalc "test2.zip" crashes at position:4700~4900, and there's no console window opened  ???.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 13, 2008
Quote
there's no console window opened  Huh.
Oh, true... stupid me :whack:
Now attached a version that actually opens a console-window ;)
Moved all attachment to the first post for less confusion.
Also forgot to mention that "Cursor Up" moves faster...

Quote from: Deleter
When I run it it just looks gray white and black, no cool colors
Could you please tell what gfxboard, driver and os?

Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: benny! on May 13, 2008
@hellfire:

wasn't able to test test.zip and test2.zip earlier.
Both run smooth and look like their screenshot !!!

Very well done !!!
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Deleter on May 14, 2008
What's the actual problem here is still a bit out of my understanding.
I've tested both versions on Radeon 9600 (Shader 2.0) & Geforce 7600 (Shader 3.0) and they both work fine. If the shader doesn't work on your Radeon, it's probably because of different driver version (I'm using Catalyst 8.4 from September 2007) which might include a somewhat different shader-compiler or just features new bugs...
A crash, however, is most probably caused by my sucking code ;)

Edit: Updated drivers to current version and can't see any difference, still it's not impossible that some other code-path for other/newer hardware might cause trouble of some kind...



Well if it helps any, I actually have a FireGL 5200 (which played crysis just fine ;) and supports shadermodel 3.0). The fireGL is just a mobility radeon x1600 with certain features downgraded and others upgraded. The driver is from may 2007 and I cannot upgrade it (some stupid hp laptop thing I guess...)
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 17, 2008
Thanks for the information. Does "test" look like this then?
And does the text-window say "shader compiled" (twice) or is there some error message?
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Jojo on May 17, 2008
this looks great, dude O0
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Deleter on May 19, 2008
No the shaders fail to compile and it looks like the attached jpg. It does say "shader compiled" and then right after it says "shader compile error: ERROR: 0:1: 'uniform' : cannot initialize this type of qualifier" "ERROR: 1 compilation errors. No code generated"
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on May 19, 2008
Quote
it says "shader compile error..."
Thank you very much!
Could you please try again with this (attached) version?
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: Deleter on May 19, 2008
works  :clap:
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: neriakX on October 29, 2011
it's looking cool, unfortunately I'm not an alien .. it runs with approx 1300 fps!!!! :)
it speaks for your code, but I can't see much of the cave, it's spinning so freaking fast :) I think I've got vsync application controlled.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: hellfire on October 29, 2011
True, I just ran it on my HD6850 and it's unwatchable with default driver settings.
When I coded this I still had a lusty Radeon 9600 and was happy to make it run fluidly at all ;)
If you force vsync in the driver settings it runs properly, though.
Title: Re: [PROCEDURAL] Cave (ps 2.0)
Post by: neriakX on October 29, 2011
I've changed driver settings to Vsync: "Always on, unless application specifies". Both tests are running like a charm now. Very good work, hellfire!  :clap: