# ray tracing : looking inside an object

This topic is 4917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
flip the normal towards the ray? (a dotproduct determines if you need to flip it..)

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

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
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 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 on other sites
Quote:
 Original post by takisI 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 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634115
• Total Posts
3015594
×