ray tracing : looking inside an object

Started by
5 comments, last by davepermen 18 years, 8 months ago
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?
Advertisement
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.
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?
flip the normal towards the ray? (a dotproduct determines if you need to flip it..)
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

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);
}
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.
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.
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement