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:
And here's how you define a cube in good old Java.
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:
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();
}
Haha, no FPS counter but rather a "Next frame"-button :)
Only Java makes it possible!
Only Java makes it possible!
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.
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.
No, there's no marching in that description...
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.
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!
GC will clean that up... please don't use Java for RM.
Anyways - nice cube!
My first attempt.
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!
Quote:
java has no garbage collection, java is a collection of garbage!
+1
yumeji: your doin' it wrong!! ..jargon, that is :)
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...
Quote:
and I haven't seen raymarching in any C64 demo...
Really?
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 :)
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 :)
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..
Who cares what language is used. Let him use Java, or whatever language he feels comfortable with.
So basically what skrebbel said.
So basically what skrebbel said.
What kind of data type is V?
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.
- 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.
Quote:
- facepalm. What kind of data type is V?
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 ;)
- *knock knock*
- Who is it?
- *long pause* ..Java!
- Who is it?
- *long pause* ..Java!
mudlord: cute! formula? code?
Tiny hsv2rgb:
Improve it!
Simple RM-loop
And for the Java discussion: Please open another thread.
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;
}
And for the Java discussion: Please open another thread.
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.
Distance field method. Well, it works, It just needs correction to the horizon, some texture and a more interesting scene.
Just a test with 2d heightmap and a lot of bugs. Ugh :P
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.
Distance field method. Well, it works, It just needs correction to the horizon, some texture and a more interesting scene.
Just a test with 2d heightmap and a lot of bugs. Ugh :P
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;}