• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# refraction

## Recommended Posts

I''m trying to debug refraction in a photonmap-implementation. Something is wrong, though. See http://www.student.kuleuven.ac.be/~m9817401/snapshot2.png for a picture. The sphere is the problem, obviously. Does anybody recognize an obvious mistake. Any suggestions are very welcome. Thanks.

##### Share on other sites
I don''t see any refraction mapping... I''m a bit confused. Describe what it''s supposed to do.

-~-The Cow of Darkness-~-

##### Share on other sites
Sorry forgot to mention the sphere is made of glass. It''s supposed to be transparant. You should see the scene (distorted, but nog foggy :-) ) through it. Like this: http://graphics.ucsd.edu/~henrik/images/imgs/cbox_with_sphere.jpg

##### Share on other sites
Well, it looks like the sphere is environment mapped, not refraction mapped. Also, is th nois(looks like glitter) intentional?

-~-The Cow of Darkness-~-

##### Share on other sites
The noise is not intentional. It''s caused by a small number of samples.

##### Share on other sites
quote:
Original post by cowsarenotevil
Well, it looks like the sphere is environment mapped, not refraction mapped. Also, is th nois(looks like glitter) intentional?

-~-The Cow of Darkness-~-

Dude, that glass sphere is refraction mapped. I''ve got a pretty good paper on refraction mapping if i can hunt it out for you...

##### Share on other sites
this is raytraced i suppose? it definitly looks like it is. anyway doing such effects with a raytracer is actually quite simple, if you know the also simple physics behind it. ive got totally no idea how to do this with a normal projection renderer though, that would be really hard im affraid.

##### Share on other sites
quote:
Original post by Eelco
this is raytraced i suppose? it definitly looks like it is. anyway doing such effects with a raytracer is actually quite simple, if you know the also simple physics behind it. ive got totally no idea how to do this with a normal projection renderer though, that would be really hard im affraid.

Dont quote me on this, but i think it can be done with photon mapping. Im no expert, and haven''t really looked into the field much, but maybe one of the more experienced members will be able to help out.

##### Share on other sites
quote:
Original post by Hairybudda

Dude, that glass sphere is refraction mapped. I''ve got a pretty good paper on refraction mapping if i can hunt it out for you...

No, I meant his... It looks like he''s reflecting it onto a gray texture...

-~-The Cow of Darkness-~-

##### Share on other sites
As i''ve said in my first (!! ;-) ) post, the image was generated using photon mapping. But that doesn''t matter for the refraction. You could consider it to be raytraced. The problem is the refraction in the glass sphere is wrong. I know Snell''s law, but something is wrong with the implementation (we''re using some external libraries, so maybe something is wrong with the normals).

##### Share on other sites
Well, the rays are definetly not going in the right direction, but that''s all I can say for sure.

-~-The Cow of Darkness-~-

##### Share on other sites
sorry i should read better i suppose.

anyway if you have the refraction value of your sphere, break towards the normal when entering, and away from it when leaving the sphere, accoring to the formula. you knew that much i suppose, but it looks a bit like you inverted breaking towards the normal and breaking away from it.
i doubt the problem is the normal youre using. how hard can it be to calculate the normal on a sphere? maybe show some code so we can have a look at it?

##### Share on other sites
Something was wrong with the scene: the index of refraction was 1.5 for the glass. Oops. I''ve set it to 0.54, and this results in http://www.student.kuleuven.ac.be/~m9817401/snapshot3.png
Still not correct. The code used to compute the refracted direction (inDir points away from the surface):

Vec3 PhotonCasting:erfectRefractedDirection(const Vec3& inDir2,const Vec3& normal2,const complex& indexIn, const complex& indexOut) {	Vec3 inDir=inDir2;	Vec3 normal=normal2;	inDir.normalize();	normal.normalize();	double zi = inDir & normal;	class Vec3 inortho = zi * normal;       // component orthogonal surface	class Vec3 inpar = inDir - inortho;     // component in tangent plane	double n = (zi > 0.) ? indexOut.r / indexIn.r : indexIn.r / indexOut.r;	double zo2 = 1. - (1. - zi * zi) * (n * n);	return (zo2 > 0.)		? ((-n) * inpar + ((zi > 0.) ? -sqrt(zo2) : sqrt(zo2)) * normal)		: (-inpar + inortho);                 // total internal reflection

##### Share on other sites
well... the refraction of the raytracing looks fine, right? so... if you can get it right for the raytracer, why not for the photons?

• ### Forum Statistics

• Total Topics
627697
• Total Posts
2978680

• 20
• 14
• 12
• 10
• 12