Sign in to follow this  
takis

ray tracing : looking inside an object

Recommended Posts

Hello, I am simulating corrosion on 3D objects. The corrosion can make holes into an object. How can i raytrace so that i can look inside the object. Now i make the corresponding pixel in the hole as black?

Share this post


Link to post
Share on other sites
it all depends on how youre doing your corrosion.

since youre talking about full-blown holes, i assume the objects youre doing your corrosion simulation on are represented as some sort of voxel field? there should be plenty of information on how to raytrace those. ken silverman's work would be good to draw inspiration from.

Share this post


Link to post
Share on other sites
I am using a voxelgrid to speed up the raytracing and i hit the triangle at the back. If i use phong, i see the back of the object instead of the interior surface. How can i use phong to render the inside of an object?

Share this post


Link to post
Share on other sites
I flip the normal, but i dont see any changes?
Here is my code, perhaps i am doing something wrong.




// Phong shading model
const Vec3 Renderer::phong(Vec3 n, // shading normal
const Vec3& l, // light direction
const Vec3& v, // direction to viewer
const Vec3& rd, // diffuse color
const Vec3& rs, // specular color
const float ns) // shininess (Phong exponent)
{
// diffuse term: Rd times absolute value of cosine between light
// direction and shading normal
Vec3 color = rd * fabs(n & l);

if (ns > 0.) { // specular term
Vec3 r = n*2*(n&v) - v; // ideal reflected direction
float a = r&l;
if (a>0.)
color += rs * powf(a, ns);
}

return color;
}


Vec3 Renderer::headlight_phong(Ray* ray, Hit* hit)
{
Vec3 n(hit->getShadingNormal()); // shading normal
Vec3 v = -Vec3(ray->dir); // direction to viewer
Vec3 l = -Vec3(ray->dir); // direction to light (at viewer)

Texture* txt = sim->getObject()->getTexture();
Material* mat = sim->getObject()->getMaterial();
Vec3 rd(txt // diffuse color: hit surface has texture?
? txt->lookup(hit->getTexCoord()) // yes: use texture color
: mat->diffuse); // no: use diffuse material
Vec3 rs(mat->specular); // specular color
float ns = mat->shininess; // shininess

Vec3 ed(mat->emissivity); // emissivity

return ed + phong(n, l, v, rd, rs, ns);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by takis
I am using a voxelgrid to speed up the raytracing and i hit the triangle at the back. If i use phong, i see the back of the object instead of the interior surface. How can i use phong to render the inside of an object?


youll have to use your imagination, since nature doesnt provide an answer. there is no such thing as an interior surface of a solid piece of metal as far as light is concerned, so there is no way to tell what it should look like.

Share this post


Link to post
Share on other sites
you want the triangles to be two-sided.. so you have to provide two normals as well, depending on the side you look at. once you hit your surface, just check the provided normal. if it's facing the same direction as your ray, it's facing away from it => invert the normal. that way, you always provide the normal facing your ray, resulting in correct shading for all sides.

but it does not have to do anything with your shading code, or lighting code. just the intersectioncode, that returns intersectionpoint + normal. you have to alter that piece of code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this