peliosis Posted February 17, 2009 Share Posted February 17, 2009 Hello, I'm trying to render object thickness. The final idea is to cast rays from camera or a given point and calculate thickness of objects being passed. Something like prman gummi light shader (from pixar ratatouille's paper). This is my not working attempt, I get a nice shrunk image if thickness returns dist2 and a nice normal sized image when it returns dist1 : float thickness(float maxhitdist; float bias; vector pHit; vector nHit;) { float dist1 = rayhittest(Eye,normalize(I)*maxhitdist,pHit, nHit, bias); vector pHitW = ptransform("space:camera","space:world",pHit); float dist2 = rayhittest(pHitW,normalize(I)*maxhitdist,bias); return dist2; } surface gummiTest(float maxhitdist = 20; float bias = 0.005; float thickmin = 15; float thickmax = 19;) { vector pHit = 0; vector nHit = 0; float objThickness = thickness(maxhitdist, bias, pHit, nHit); //printf("objthickness: %f",objThickness ); Cf = fit(objThickness,thickmin,thickmax,0,1); } Both are wrong. Ofcourse ray depth should be in the UI but it's just a beginning and I'm not sure if it is possible this way. Do you guys have a clue? I'm a noob shader writer runner up gummiTest_01.hipnc Quote Link to comment Share on other sites More sharing options...
peliosis Posted February 24, 2009 Author Share Posted February 24, 2009 I had some more time and came up with this: vector castray ( vector rayorigin; float maxhitdist; float bias; ) { vector pHit; vector nHit; vector out; float rayhitdist = rayhittest(rayorigin, normalize(I)*maxhitdist, pHit, nHit, bias); if (rayhitdist < 0) {out = rayorigin;} else {out = pHit;} return out; } surface gummiTest(float maxhitdist = 20; float bias = 0.005; float thickmin = 0; float thickmax = 10; int raydepth = 4;) { vector nextorigin = 0; int raynum = 0; float raydist = 0; vector rayorigin =P; for (raynum = 1; raynum <= raydepth; raynum++) { nextorigin = castray(rayorigin, maxhitdist, bias); raydist += distance(rayorigin,nextorigin); rayorigin = nextorigin; } Cf = fit(raydist,thickmin,thickmax,0,1); } It doesn't calculate the exact thickness yet because it counts empty space also. Works good when no more than two polys overlap (or with raydepth of 1), but with more overlapping polys or higher depth it creates some crazy mess. Maybe it's easier to calculate thickness using light shader or shadow shader? I've created this also in SOPs using intersect() function, but a shader should be more precise. Please share your thoughts. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.