Jump to content

Path tracing possible in CYOS?


babbleon
 Share

Recommended Posts

Hello,

I have been thinking about how best to get a scene to render a single frame as photo-realistically as possible without any prior baking etc. I am not necessarily looking for realtime photorealism, but if it take a few mins to render out that would be fine.

There are a number of webgl path tracing examples online:

My question is: would it be possible to implement path tracing using CYOS or am I coming at this from the wrong angle?

Many thanks.

Link to comment
Share on other sites

Just a copy & paste exercise from here to http://cyos.babylonjs.com/#177L7P#1,

this from here to http://cyos.babylonjs.com/#J2ULBB

& this from here to http://cyos.babylonjs.com/#SQ9JCC#1 (very dark for reasons not yet understood by me)

but, I guess it wouldn't be rocket science to have it render stuff in the scene rather than just the primitives.

Link to comment
Share on other sites

Yes the challenge with primitives from the CPU, is not do to a basic Ray/Pathtracing. It is about make it fast, acceleration structures KD, SVO, BVH , and best way to send the mesh data via textures ect. If you are not a computer sience student, this is a long term project. 

Link to comment
Share on other sites

@babbleon Drawing primitive is easy as you can think about them as parametric shapes well defined by maths. 

Drawing loaded model through path tracing on gpu would be as @Nabroski said way tougher as you would need to path down the shapes off your entire scene to the shader to detect collision and intersetction on the light path.

This is usually done on CPU and some light part like sampling and so on could still be highly optimised on gpu.

Link to comment
Share on other sites

Hello
you have to bypass the Vertexshader be course down the pipeline your polygone would be rasterized (broken down in little fragments, reason why it’s called fragment or sometimes p i x e l shader) , one way of doing it is to pack meshdata in RGBA textures and unpack them in the fragmentshader. This would be step one, and now you on the playground to implement a Raytracer / Rasterizer. You need a Ray Triangle Intersection Test.
And so forth ..you step  slowly forward an through computer graphic history ‘til Monte Carlo or Russian Roulette . : ) 

So i'm learing all that stuff too, it's my passion. I use this a good free learning recourse: https://www.scratchapixel.com/
Here is the bible of pathtracers: http://www.pbrt.org/

So i would go an implement a Rasterizer first. Then you have an an idea how everything works, and when you feel comfortable, copy paste stuff from shadertoy. The magic here is, to have an basic idea, what you are doing. 

 

 

Link to comment
Share on other sites

Hi @Nabroski, I think for the time being I will not have the time to implement this assuming it's as complicated as I am told.

Thank you for the offer of guiding me - it is much appreciated.

If someone wants to sort this, then that would be great as I'm sure it would help others, but it was not my intention to get others to do my work. I can't mark as solved, but maybe it's a 'postponed for a rainy day'.

Link to comment
Share on other sites

@babbleon If i told you how to ride a bicycle, i also would sound complicated. No need to worry, we all learning here. 

The best offer i can make right now, is to do it as a community project. (I'm right now into physics :) and 5 other projects, zero time for pulling anything on github, also going though process of debug and so on)
I understand. In long term maybe 2 months it more possible from my side. Meanwhile our prayers go to Pryme8. 
 

Have a nice day. 

Link to comment
Share on other sites

If you want to do "Physical" Meshs with ray-marching the solution it to iterate though each polygonal face and use one of these equations:

Triangle - unsigned - exact
float dot2( in vec3 v ) { return dot(v,v); }
float udTriangle( vec3 p, vec3 a, vec3 b, vec3 c )
{
    vec3 ba = b - a; vec3 pa = p - a;
    vec3 cb = c - b; vec3 pb = p - b;
    vec3 ac = a - c; vec3 pc = p - c;
    vec3 nor = cross( ba, ac );

    return sqrt(
    (sign(dot(cross(ba,nor),pa)) +
     sign(dot(cross(cb,nor),pb)) +
     sign(dot(cross(ac,nor),pc))<2.0)
     ?
     min( min(
     dot2(ba*clamp(dot(ba,pa)/dot2(ba),0.0,1.0)-pa),
     dot2(cb*clamp(dot(cb,pb)/dot2(cb),0.0,1.0)-pb) ),
     dot2(ac*clamp(dot(ac,pc)/dot2(ac),0.0,1.0)-pc) )
     :
     dot(nor,pa)*dot(nor,pa)/dot2(nor) );
}

Quad - unsigned - exact
float dot2( in vec3 v ) { return dot(v,v); }
float udQuad( vec3 p, vec3 a, vec3 b, vec3 c, vec3 d )
{
    vec3 ba = b - a; vec3 pa = p - a;
    vec3 cb = c - b; vec3 pb = p - b;
    vec3 dc = d - c; vec3 pc = p - c;
    vec3 ad = a - d; vec3 pd = p - d;
    vec3 nor = cross( ba, ad );

    return sqrt(
    (sign(dot(cross(ba,nor),pa)) +
     sign(dot(cross(cb,nor),pb)) +
     sign(dot(cross(dc,nor),pc)) +
     sign(dot(cross(ad,nor),pd))<3.0)
     ?
     min( min( min(
     dot2(ba*clamp(dot(ba,pa)/dot2(ba),0.0,1.0)-pa),
     dot2(cb*clamp(dot(cb,pb)/dot2(cb),0.0,1.0)-pb) ),
     dot2(dc*clamp(dot(dc,pc)/dot2(dc),0.0,1.0)-pc) ),
     dot2(ad*clamp(dot(ad,pd)/dot2(ad),0.0,1.0)-pd) )
     :
     dot(nor,pa)*dot(nor,pa)/dot2(nor) );
}

Which honestly to me sounds pretty intensive, but has been done.

 

http://iquilezles.org/www/articles/raytracing/raytracing.htm

I could hit up IQ and see if he can point me in the right direction.  Hes usually pretty good about getting back to people.

Link to comment
Share on other sites

@Pryme8 Babylon has already everything implemented it is just on the CPU. :) https://github.com/BabylonJS/Babylon.js/blob/9824853960fc2a4be97b1acb6907244c8df9f05e/src/Culling/babylon.ray.ts#L132

So i lean back for quite a while. I created a template. 
Tipp: first go with the Rasterizer Triangel it is - l i t e r a l l y -  2 lines of code!  inspiration (reference, reference)

Link to comment
Share on other sites

32 minutes ago, Nabroski said:

Tipp: first go with the Rasterizer Triangel it is - l i t e r a l l y -  2 lines of code!  inspiration (reference, reference)

The second one is going with Signed distance Functions like with the code snippets I posted above.

I "know" how to pull it off, the problem is going to be efficiency.

Link to comment
Share on other sites

https://www.babylonjs-playground.com/#ZUMAGX#41

Here you go, Ill do a real mesh here during lunch.  

anybody got a  CORS safe link for like the budda model or the rabbit obj?

https://www.babylonjs-playground.com/#ZUMAGX#43
can anyone get this to compile?

 

https://www.babylonjs-playground.com/#ZUMAGX#44
*ACK* ill need to pass the buffer as a texture, or a custom attribute.

https://www.babylonjs-playground.com/#ZUMAGX#50 <- DO NOT CLICK UNLESS YOU WANT TO CRASH YOUR BROWSER.

Ehhh... im gonna need a different approach.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...