pouët.net

Raymarching Beginners' Thread

category: code [glöplog]
Dabbling in raymarching is the new thing for everyone :]

Post & discuss your stuff here, even if it's in its infancy. No making fun of newbies! Everybody needs encouragement.

Here's my first attempt, simple but clean:

BB Image

And here's how you define a cube in good old Java.

Code: private Dist blackToWhiteCube(V v, double size) { double c = ((Math.max(-size, Math.min(size, v.y))/size)+1)/2; return new Dist(new RGB(c), cube(v, size)); } /* a cube centered at 0,0,0 with a length of size*2 in all 3 dimensions */ private double cube(V v, double size) { double x = Math.abs(v.x)-size, y = Math.abs(v.y)-size, z = Math.abs(v.z)-size; return new V(Math.max(x, 0), Math.max(y, 0), Math.max(z, 0)).len(); }
added on the 2011-02-04 15:38:52 by vibrator vibrator
Haha, no FPS counter but rather a "Next frame"-button :)
Only Java makes it possible!
added on the 2011-02-04 16:02:19 by Duckers Duckers
I'm really slow with that kinda stuff but I think I got the idea now.

So "raymarching" is just rendering a "volumetric" screenspace plane and calcing the shape's depth, color and transparency based on a mathematical expression and some modulation textures rather than moving vertices to define the shape.

Sure not too complex.
added on the 2011-02-04 16:34:24 by yumeji yumeji
No, there's no marching in that description...
added on the 2011-02-04 17:27:53 by Psycho Psycho
wait, are those new() really allocating memory and constructing an object in it, or are just a formalism of the language to build a logical object, but not physically? i will never understand java. also, it scares the shit out of me.
added on the 2011-02-04 17:29:29 by iq iq
iq: MUHAHAH, my first thought... "what the fuck... hell of a leak!" - than I noticed it's Java - my next thought was "haha, it's frakking slow that you need a 'Next frame' button".
GC will clean that up... please don't use Java for RM.

Anyways - nice cube!
added on the 2011-02-04 17:36:49 by las las
BB Image
My first attempt.
added on the 2011-02-04 17:40:13 by las las
Quote:
i will never understand java. also, it scares the shit out of me.

+1

java has no garbage collection, java is a collection of garbage!
added on the 2011-02-04 19:03:06 by gopher gopher
Quote:

java has no garbage collection, java is a collection of garbage!

+1
added on the 2011-02-04 19:11:04 by las las
BB Image
added on the 2011-02-04 19:12:05 by w00t! w00t!
yumeji: your doin' it wrong!! ..jargon, that is :)
added on the 2011-02-04 19:12:20 by ferris ferris
Quote:
Post & discuss your stuff here, even if it's in its infancy. No making fun of newbies! Everybody needs encouragement.


My next demo runs at 5MHz. Someone told me that it was *not* silly to think about whether raymarching was possible on such a platform. I tend to use C64 as a benchmark of whether or not something is possible on my platform, and I haven't seen raymarching in any C64 demo...
added on the 2011-02-05 06:32:25 by trixter trixter
BB Image
added on the 2011-02-05 09:46:41 by mudlord mudlord
Quote:
and I haven't seen raymarching in any C64 demo...

Really?
added on the 2011-02-05 09:51:06 by w00t! w00t!
amazing, for once i'm actually with vibrator.

what's up with the attitude guys. vibrator wants to discuss the concepts behind raymarching, and gets dissed because he uses a programming language you're unfamiliar with.

iq, yes, every time you do "new" a true, physical new object gets created. However, if it's a small simple object (e.g. two or three integer fields used as a return value) the VM may well allocate the object on the stack and not the heap. thus, i don't see how that necessarily makes things slow. true, you lose this control in java (can't choose where the object goes), but the VMs and their JITs have been getting pretty decent lately.

so while java might not be ideal for guaranteeing absolute speed, it's great for figuring conceptual stuff since you avoid the headaches of memory management and whatnot. since clearly vibrator is in the "figuring stuff out" stage, i don't see the problem at all.

vibrator, if you intend to try to actually make stuff speedy in java, consider reusing preallocated arrays for large chunks of data. i.e. in a simple software rendering, simply keep two arrays for double buffering to draw in, and don't "new" one each time. do it first with the larger data structures and the ones that there will be many of, and you may get stuff speedier quite easily. and sorry if you already knew this :)
added on the 2011-02-05 10:22:43 by skrebbel skrebbel
Quote:
VMs and their JITs have been getting pretty decent lately.

Sorry for going offtopic still, but I'm pretty sure I've heard that said over a decade ago already.. so the VMs should be getting pretty damn amazing by now..

It's also funny that all this performance talk still orbits around java; I haven't heard similar bitching about .net or flash..
added on the 2011-02-05 10:41:24 by sol_hsa sol_hsa
Who cares what language is used. Let him use Java, or whatever language he feels comfortable with.

So basically what skrebbel said.
added on the 2011-02-05 10:56:50 by Rob Rob
What kind of data type is V?
added on the 2011-02-05 11:17:40 by Adok Adok
Conversations about programming languages:

- Java sucks.
- Why?
- It's soooo slow.
- blabla
- oh I also use Python
- Python is good!
- And Perl
- And some others..
- it's not bad, I like this and that, blabla

Talking negatively about Java because it's slooooow and then favouring languages that are as far as I know much slower than Java. The old myth of a slow Java has been retained while the JRE has been going through changes and is quite optimized since a long time ago and improves. I know because I have been involved in two big Java projects myself (<shameless ad> 1 and 2 </shameless ad>). Java is definitelly not slow anymore, I would only agree it takes more memory and the garbage collection can be unpredictable. It's just that the word "Java" is associate with "slow" and "sucks" and "collection of garbage" apart from an island and the coffee since 199x.

Sorry for the interruption. My next post will be about raymarching.
added on the 2011-02-05 11:29:41 by Optimus Optimus
Quote:
What kind of data type is V?
- facepalm.

Regarding to language dissing - help Vibrator out with the concepts and he will eventually end up using another programming language, or do teh awesomes in Java ;)
added on the 2011-02-05 11:30:36 by Puryx Puryx
- *knock knock*
- Who is it?
- *long pause* ..Java!
added on the 2011-02-05 11:32:16 by kbi kbi
mudlord: cute! formula? code?

Tiny hsv2rgb:
Code: vec3 hsv(float h, float s, float v) { vec3 r; if (s==0.) return vec3(v); float b,e,w,z,y,x; e=6.*h; b=floor(e); e-=b; w=v*s; x=y=v; x-=w; z=x+w*e; y+=x-z; vec4 f = vec4(x,y,z,v); if (b<1.)r=f.wzx; else if (b<2.)r=f.ywx; else if (b<3.)r=f.xwz; else if (b<4.)r=f.xyw; else if (b<5.)r=f.zxw; else r=f.wxy; return r; }

Improve it!

Simple RM-loop
Code: vec4 rm(vec3 p, vec3 d) { float i = 0.0; do { float l = field(p); p += l * d * 0.25; if (l < 0.01) { vec3 n = grad(p); float r = max(-dot(n,d), 0.0); return vec4(ao(p,n) * hsv(i, 0.8, 1.0).xyzz); } i += 1.0/512.0; } while (i < 1.); return hsv(1.0, 0.8, 1.0).xyzz; }


BB Image

And for the Java discussion: Please open another thread.
added on the 2011-02-05 12:16:58 by las las
This were my first attempts I did a long time inspiried by the old thread about raymarching. They are certainly much worse than most things posted, full of visual bugs I couldn't figure out how to solve them, boring scenes too, but I abandoned trying to make them look good because all I just wanted at the time was to see that the things discussed in the forum are really working.

Typical raymarching on some kind of 3d plasma. What I still can't figure out is how to make the artifacts further away dissapear. I can have very small steps but it makes it much much slower to not have those artifacts. I have also tried increasing the step by Z. I have seen many of those 3d plasmalike formations in various 4ks, for example dollop and I can't figure why they look so good and yet they are fast. Also my lighting is wrong but I can figure this out easilly.
BB Image

Distance field method. Well, it works, It just needs correction to the horizon, some texture and a more interesting scene.
BB Image

Just a test with 2d heightmap and a lot of bugs. Ugh :P
BB Image
added on the 2011-02-05 12:26:36 by Optimus Optimus
Quote:
Tiny hsv2rgb:


Code:float3 h2r(float h,float s,float v){return lerp(saturate((abs(frac(h+float3(1,2,3)/3)*6-3)-1)),1,s)*v;}
added on the 2011-02-05 12:32:38 by unc unc

login