|
Post by totally on Sept 1, 2019 4:00:02 GMT
Hello! Loving the book so far, things have been going very well. So far I have finished Chapter 11 and all the provided tests are passing. I really wanted to create the sphere within sphere image that a few people here have been able to do. It is not working as well as I would like and would love to know if I am setting up the scene wrong or if I have an issue in my rendering code somewhere. Currently my scene renders like this: With the one in the book and others here in the image gallery there is a lot more going on inside there This is my scene code: const floor = new Plane(); floor.transform = Transform.translation(0, -10, 0); floor.material.pattern = new Checker(Colour.black(), Colour.white(), false); floor.material.pattern.transform = Transform.translation(0, 0, 0); floor.material.specular = 0;
const bigger = new Sphere(); bigger.material.diffuse = 0.1; bigger.material.shininess = 300; bigger.material.reflective = 1; bigger.material.transparency = 1; bigger.material.refractiveIndex = 1.52; bigger.material.colour = new Colour(0, 0, 0.1);
const smaller = new Sphere(); smaller.transform = Transform.scaling(0.5, 0.5, 0.5); smaller.material.diffuse = 0.1; smaller.material.shininess = 300; smaller.material.reflective = 1; smaller.material.transparency = 1; smaller.material.refractiveIndex = 1; smaller.material.colour = new Colour(0, 0, 0.1);
const light = new PointLight(Tuple.point(2, 10, -5), new Colour(0.9, 0.9, 0.9)); const world = new World(light, [floor, smaller, bigger]); world.shadowEnabled = false;
const camera = new Camera(512, 512, Math.PI / 3); const from = Tuple.point(0, 2.5, 0); const to = Tuple.point(0, 0, 0); const up = Tuple.vector(1, 0, 0); camera.transform = Transform.viewTransform(from, to, up);
Any help or places to look would be most helpful! I have compared my implementation of schlick, prepareComps, colourAt, reflect and refract against a bunch of other implementations, though I would be happy to have another set of eyes on what I might be missing. Thanks!
|
|
|
Post by Jamis on Sept 2, 2019 1:31:04 GMT
Hello totally! It looks like your renderer is on the right track, but yeah, something's not quite right. Do you have your source code anywhere I could take a look at it? - Jamis
|
|
|
Post by totally on Sept 2, 2019 6:14:36 GMT
I sure do, its all up here on github: github.com/jarrodconnolly/js-rtcThanks for the fantastic book! I have learned so much going through this from the unit test point of view.
|
|
|
Post by chrisd on Sept 2, 2019 20:30:13 GMT
Your world.js refractedColour(comps, remaining) looks the same as mine. I also checked prepareComputations in intersect.js, which also looks the same. Nothing is popping out for me, sorry. Hopefully someone else will be able to figure out what is going on.
I translated your scene to YAML so others might be able to help out more easily, as well. Here's the code.
- add: camera width: 512 height: 512 field-of-view: 1.0471975511965977461542144610932 from: [ 0, 2.5, 0 ] to: [ 0, 0, 0 ] up: [ 1, 0, 0 ]
- add: light at: [ 2, 10, -5 ] intensity: [ 0.9, 0.9, 0.9 ]
# FLOOR - a plane - add: plane transform: - [ translate, 0.0, -10.0, 0 ] material: pattern: type: checker colors: - [0.0, 0.0, 0.0] - [1.0, 1.0, 1.0]
# GLASS SPHERE - add: sphere material: diffuse: 0.1 shininess: 300.0 reflective: 1.0 transparency: 1.0 refractive-index: 1.52 color: [ 0.0, 0.0, 0.1 ]
# AIR SPHERE - add: sphere transform: - [ scale, 0.5, 0.5, 0.5 ] material: diffuse: 0.1 shininess: 300.0 reflective: 1.0 transparency: 1.0 refractive-index: 1.0 # Note: the following would be air # refractive-index: 1.00029 color: [ 0.0, 0.0, 0.1 ]
In your scene, I like how you translated the plane instead of the spheres as I did (see below). I also had trouble reproducing the scene to be similar to what was in the book, but I eventually got close. Here was my attempt at creating the spheres:
# Ray Tracing Challenge - Chapter 11 Reflection and Refraction # a glass sphere, with an air bubble in the middle of it # demonstrates when total internal reflection comes into play
- add: camera width: 300 height: 300 field-of-view: 1.0471975511965977461542144610932 from: [ 0, 8, 0 ] to: [ 0, 0, 0 ] up: [ -1, 0, 0 ]
- add: light at: [ -8, 10, -8 ] intensity: [ 1, 1, 1 ]
# FLOOR - a plane - add: plane material: pattern: type: checker colors: - [0.15, 0.15, 0.15] - [0.95, 0.95, 0.95] transform: - [ scale, 0.70, 0.70, 0.70 ] ambient: 0.7
# GLASS SPHERE - add: sphere material: color: [ 0.3, 0.3, 0.3 ] refractive-index: 1.52 reflective: 0.5 transparency: 1.0 diffuse: 0.8 specular: 0.1 transform: - [ scale, 1.0, 1.0, 1.0 ] - [ translate, 0.0, 4.0, 0 ]
# AIR SPHERE - add: sphere material: color: [ 0.3, 0.3, 0.3 ] refractive-index: 1.00029 reflective: 0.5 transparency: 1.0 diffuse: 0.8 specular: 0.1 transform: - [ scale, 0.5, 0.5, 0.5 ] - [ translate, 0.0, 4.0, 0 ]
|
|
|
Post by Jamis on Sept 3, 2019 14:48:09 GMT
Thanks for translating the scene to YAML, chrisd! That helps a lot. I've also looked at your code, totally, and like chrisd, I'm not seeing anything obviously out of place. For the purposes of troubleshooting this, here's the scene I used for the image in the book: - add: camera width: 300 height: 300 field-of-view: 0.45 from: [ 0, 0, -5 ] to: [ 0, 0, 0 ] up: [ 0, 1, 0 ]
- add: light intensity: [ 0.9, 0.9, 0.9 ] at: [ 2, 10, -5 ]
# wall - add: plane transform: - [ rotate-x, 1.5708 ] - [ translate, 0, 0, 10 ] material: pattern: type: checkers colors: - [ 0.15, 0.15, 0.15 ] - [ 0.85, 0.85, 0.85 ] ambient: 0.8 diffuse: 0.2 specular: 0
# glass ball - add: sphere material: color: [ 1, 1, 1 ] ambient: 0 diffuse: 0 specular: 0.9 shininess: 300 reflective: 0.9 transparency: 0.9 refractive-index: 1.5
# hollow center - add: sphere transform: - [ scale, 0.5, 0.5, 0.5 ] material: color: [ 1, 1, 1 ] ambient: 0 diffuse: 0 specular: 0.9 shininess: 300 reflective: 0.9 transparency: 0.9 refractive-index: 1.0000034
With the scene defined like that, and rendering the scene at 300x300, I took a snapshot of some of the values in the "reflected_color" function, for the pixel at x=125, y=125. (Note that because it's called recursively, the output gets a bit messy. I've indicated the value of the "remaining" parameter to help identify where in the recursion each snapshot occurs.) == remaining 1 == n1: 1.5 n2: 1 eyev: v(0.6371,-0.6371,0.4337) normalv: v(0.5732,-0.5732,0.5856) under point: p(-0.5733,0.5733,-0.5856) n_ratio: 1.5 cos_i: 0.9843875779711537 sin2_t: 0.06970746675619283 cos_t: 0.9645167355955039 refract direction: v(-0.6622,0.6622,-0.3508) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == n1: 1.0000034 n2: 1.5 eyev: v(-0.1449,0.1449,-0.9788) normalv: v(0.2423,-0.2423,-0.9395) under point: p(-0.1212,0.1212,0.4698) n_ratio: 0.6666689333333333 cos_i: 0.8493497525679515 sin2_t: 0.12382528547998457 cos_t: 0.9360420474102727 refract direction: v(0.0070,-0.0070,1.0000) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == n1: 1.5 n2: 1.0000034 eyev: v(-0.2772,0.2772,-0.9200) normalv: v(-0.4884,0.4884,-0.7231) under point: p(-0.2442,0.2442,-0.3615) n_ratio: 1.49999490001734 cos_i: 0.9360155818910421 sin2_t: 0.2787164732534013 cos_t: 0.8492841260418086 refract direction: v(0.1449,-0.1449,0.9788) refracted color: v(0.0000,0.0000,0.0000)
== remaining 3 == n1: 1.5 n2: 1 eyev: v(0.4854,-0.4854,0.7271) normalv: v(0.3874,-0.3874,0.8366) under point: p(-0.3874,0.3874,-0.8367) n_ratio: 1.5 cos_i: 0.984390724110604 sin2_t: 0.06969353014125149 cos_t: 0.9645239602305111 refract direction: v(-0.5298,0.5298,-0.6623) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == n1: 1.0000034 n2: 1.5 eyev: v(0.4866,-0.4866,0.7256) normalv: v(0.1426,-0.1426,0.9794) under point: p(-0.0713,0.0713,-0.4898) n_ratio: 0.6666689333333333 cos_i: 0.8495136704509465 sin2_t: 0.12370151837357306 cos_t: 0.9361081570130809 refract direction: v(-0.3771,0.3771,-0.8459) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == n1: 1.5 n2: 1 eyev: v(-0.7033,0.7033,0.1032) normalv: v(-0.7052,0.7052,-0.0734) under point: p(0.7053,-0.7053,0.0734) n_ratio: 1.5 cos_i: 0.984403306680672 sin2_t: 0.06963779204135742 cos_t: 0.9645528538958571 refract direction: v(0.6939,-0.6939,-0.1924) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == n1: 1.0000034 n2: 1.5 eyev: v(-0.6756,0.6756,0.2953) normalv: v(-0.6840,0.6840,-0.2533) under point: p(0.3421,-0.3421,0.1267) n_ratio: 0.6666689333333333 cos_i: 0.8494481221743096 sin2_t: 0.12375101382906421 cos_t: 0.936081719814534 refract direction: v(0.7033,-0.7033,-0.1032) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == n1: 1.5 n2: 1.0000034 eyev: v(-0.4605,0.4605,0.7588) normalv: v(-0.2422,0.2422,0.9395) under point: p(-0.1211,0.1211,0.4696) n_ratio: 1.49999490001734 cos_i: 0.936042047410272 sin2_t: 0.2786049978127631 cos_t: 0.8493497525679494 refract direction: v(0.5564,-0.5564,-0.6171) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == n1: 1.5 n2: 1 eyev: v(0.2461,-0.2461,-0.9375) normalv: v(0.3589,-0.3589,-0.8616) under point: p(-0.3590,0.3590,0.8617) n_ratio: 1.5 cos_i: 0.9843970166741242 sin2_t: 0.06966565551693923 cos_t: 0.9645384100610306 refract direction: v(-0.1854,0.1854,0.9650) refracted color: v(0.6692,0.6692,0.6692)
== remaining 3 == n1: 1.0000034 n2: 1.5 eyev: v(0.1120,-0.1120,-0.9874) normalv: v(0.4636,-0.4636,-0.7551) under point: p(-0.2319,0.2319,0.3776) n_ratio: 0.6666689333333333 cos_i: 0.8493825426089872 sin2_t: 0.12380052908867871 cos_t: 0.936055271290815 refract direction: v(-0.2461,0.2461,0.9375) refracted color: v(0.5782,0.5782,0.5782)
== remaining 4 == n1: 1.5 n2: 1.0000034 eyev: v(-0.0265,0.0265,-0.9993) normalv: v(-0.2734,0.2734,-0.9222) under point: p(-0.1367,0.1367,-0.4610) n_ratio: 1.49999490001734 cos_i: 0.9360288114367313 sin2_t: 0.27866074946444747 cos_t: 0.8493169317372358 refract direction: v(-0.1120,0.1120,0.9874) refracted color: v(0.4995,0.4995,0.4995)
== remaining 5 == n1: 1 n2: 1.5 eyev: v(0.0373,-0.0373,-0.9986) normalv: v(-0.1504,0.1504,-0.9771) under point: p(-0.1504,0.1504,-0.9770) n_ratio: 0.6666666666666666 cos_i: 0.9645311833669982 sin2_t: 0.030968709472292525 cos_t: 0.9843938696109944 refract direction: v(0.0265,-0.0265,0.9993) refracted color: v(0.4316,0.4316,0.4316)
I don't know if that'll be helpful, but maybe it'll help you identify where your results are diverging from my own. - Jamis
|
|
|
Post by totally on Sept 3, 2019 16:05:04 GMT
Thank you so much for the help chrisd & Jamis I will try to see how my numbers compare to those. I did also notice trying to play with a simpler scene that things appear to start going wrong when I enable Schlick in the refraction / reflection calculation. I believe that is where I should investigate further. I can post a better image later of what is happening. Thanks again for the help!
|
|
|
Post by totally on Oct 1, 2019 5:20:45 GMT
I built a quick and dirty loader for the scenes you posted to try to debug this issue further. Jamis I am guessing that you mean the debug output is from the refract method not the reflect method as you have the refract data in there? I tried to mimic this output to compare and get something somewhat different. Using the scene yaml Jamis posted I get the following image and debug output: I added an object id to my scene description to aid in this debug output. Right from the first hit things are incorrect I see that n1 and n2 are reversed from what you have. I have fewer hits in total than in your output as well. Something must be wrong in how I am calculating hits and intersections. I will post more details as I debug further, just wanted to get this first part out in case anyone sees anything obvious. == remaining 1 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(0.6371,-0.6371,0.4337) normalv: v(0.5732,-0.5732,0.5856) under point: p(-0.5733,0.5733,-0.5856) n_ratio: 0.6666666666666666 cos_i: 0.9843875779711537 sin2_t: 0.013769376149371421 cos_t: 0.9930914478791107 refract direction: v(-0.6178,0.6178,-0.4864) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.2772,0.2772,-0.9200) normalv: v(-0.4884,0.4884,-0.7231) under point: p(-0.2442,0.2442,-0.3615) n_ratio: 0.99999660001156 cos_i: 0.9360155818910421 sin2_t: 0.12387398811262282 cos_t: 0.9360160318538231 refract direction: v(0.2772,-0.2772,0.9200) refracted color: v(0.5508,0.5508,0.5508)
== remaining 3 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(0.4854,-0.4854,0.7271) normalv: v(0.3874,-0.3874,0.8366) under point: p(-0.3874,0.3874,-0.8367) n_ratio: 0.6666666666666666 cos_i: 0.984390724110604 sin2_t: 0.01376662323777807 cos_t: 0.9930928339094094 refract direction: v(-0.4541,0.4541,-0.7665) refracted color: v(0.0000,0.0000,0.0000)
== remaining 4 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.0265,0.0265,-0.9993) normalv: v(-0.2734,0.2734,-0.9222) under point: p(-0.1367,0.1367,-0.4610) n_ratio: 0.99999660001156 cos_i: 0.9360288114367313 sin2_t: 0.12384922198419888 cos_t: 0.936029261303193 refract direction: v(0.0265,-0.0265,0.9993) refracted color: v(0.5508,0.5508,0.5508)
== remaining 5 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(0.0373,-0.0373,-0.9986) normalv: v(-0.1504,0.1504,-0.9771) under point: p(-0.1504,0.1504,-0.9770) n_ratio: 0.6666666666666666 cos_i: 0.9645311833669982 sin2_t: 0.030968709472292525 cos_t: 0.9843938696109944 refract direction: v(0.0265,-0.0265,0.9993) refracted color: v(0.4957,0.4957,0.4957)
|
|
|
Post by Jamis on Oct 1, 2019 15:15:31 GMT
That is really strange! Looking through your code, I'm not seeing anything obviously incorrect. What values for t do you get at that first intersection? And what is the index of refraction for the shape at each intersection? Here's what I get, iterating over xs just before computing n1 and n2 at the pixel at 125,125:
t(4.028495994977554) ior(1.5) t(4.568385678150166) ior(1.0000034) t(5.4176686785389325) ior(1.0000034) t(5.957558361711545) ior(1.5) t(15.020949740457555) ior(1)
|
|
|
Post by totally on Oct 4, 2019 7:39:02 GMT
Ok so I found a couple smaller issues in my scene loader and currently I am here: My first hit intersections match: t(4.028495994977554) ior(1.5) ID:BIG-SPHERE t(4.568385678150166) ior(1.0000034) ID:SMALL-SPHERE t(5.4176686785389325) ior(1.0000034) ID:SMALL-SPHERE t(5.957558361711545) ior(1.5) ID:BIG-SPHERE t(15.020949740457555) ior(1) ID:WALL
The log from the refraction looks better, but still not at all correct For example the very first intersection there. n1 is 1 and n2 is 1.5 and do not match what you have. In my prepare computations, the first time through i notice that my xs list is already sorted so the first time through the xs loop the first object is the current intersection and then n1 gets a 1.0 I can not see how yours would end up otherwise unless xs is not supposed to be sorted here yet or something. I will keep looking in this area, it must be something about how im getting my xs hits into prepare computations to get n1 and n2. == remaining 1 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(0.6371,-0.6371,0.4337) normalv: v(0.5732,-0.5732,0.5856) under point: p(-0.5733,0.5733,-0.5856) n_ratio: 0.6666666666666666 cos_i: 0.9843875779711537 sin2_t: 0.013769376149371421 cos_t: 0.9930914478791107 refract direction: v(-0.6178,0.6178,-0.4864) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.2772,0.2772,-0.9200) normalv: v(-0.0306,0.0306,-0.9991) under point: p(0.0153,-0.0153,0.4996) n_ratio: 0.99999660001156 cos_i: 0.9360424971803698 sin2_t: 0.12382360147041596 cos_t: 0.9360429469471921 refract direction: v(0.2772,-0.2772,0.9200) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.2772,0.2772,-0.9200) normalv: v(-0.4884,0.4884,-0.7231) under point: p(-0.2442,0.2442,-0.3615) n_ratio: 0.99999660001156 cos_i: 0.9360155818910421 sin2_t: 0.12387398811262282 cos_t: 0.9360160318538231 refract direction: v(0.2772,-0.2772,0.9200) refracted color: v(0.0000,0.0000,0.0000)
== remaining 3 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(0.4854,-0.4854,0.7271) normalv: v(0.3874,-0.3874,0.8366) under point: p(-0.3874,0.3874,-0.8367) n_ratio: 0.6666666666666666 cos_i: 0.984390724110604 sin2_t: 0.01376662323777807 cos_t: 0.9930928339094094 refract direction: v(-0.4541,0.4541,-0.7665) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(0.6969,-0.6969,-0.1693) normalv: v(0.6945,-0.6945,0.1881) under point: p(-0.3473,0.3473,-0.0941) n_ratio: 0.99999660001156 cos_i: 0.9361086063018874 sin2_t: 0.12369983604722289 cos_t: 0.9361090555874231 refract direction: v(-0.6969,0.6969,0.1693) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(-0.4455,0.4455,0.7765) normalv: v(-0.5352,0.5352,0.6536) under point: p(0.5352,-0.5352,-0.6536) n_ratio: 0.6666666666666666 cos_i: 0.9844035204742151 sin2_t: 0.013755426167987354 cos_t: 0.9930984713672721 refract direction: v(0.4773,-0.4773,-0.7378) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.4455,0.4455,0.7765) normalv: v(-0.6102,0.6102,0.5052) under point: p(0.3052,-0.3052,-0.2527) n_ratio: 0.99999660001156 cos_i: 0.9360821692958039 sin2_t: 0.12374933082958174 cos_t: 0.9360826187738015 refract direction: v(0.4455,-0.4455,-0.7765) refracted color: v(0.0000,0.0000,0.0000)
== remaining 1 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.2200,0.2200,0.9504) normalv: v(0.0306,-0.0306,0.9991) under point: p(0.0153,-0.0153,0.4994) n_ratio: 0.99999660001156 cos_i: 0.9360429469471918 sin2_t: 0.12382275947422079 cos_t: 0.9360433967107397 refract direction: v(0.2200,-0.2200,-0.9504) refracted color: v(0.0000,0.0000,0.0000)
== remaining 2 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(-0.0265,0.0265,-0.9993) normalv: v(0.0983,-0.0983,-0.9903) under point: p(-0.0983,0.0983,0.9904) n_ratio: 0.6666666666666666 cos_i: 0.9843972305545773 sin2_t: 0.013760929989545959 cos_t: 0.9930957003282483 refract direction: v(-0.0155,0.0155,0.9998) refracted color: v(0.6653,0.6653,0.6653)
== remaining 3 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.0265,0.0265,-0.9993) normalv: v(0.2239,-0.2239,-0.9486) under point: p(-0.1120,0.1120,0.4744) n_ratio: 0.99999660001156 cos_i: 0.9360557209646366 sin2_t: 0.12379884541579436 cos_t: 0.9360561706351845 refract direction: v(0.0265,-0.0265,0.9993) refracted color: v(0.5748,0.5748,0.5748)
== remaining 4 == object: SMALL-SPHERE n1: 1 n2: 1.0000034 eyev: v(-0.0265,0.0265,-0.9993) normalv: v(-0.2734,0.2734,-0.9222) under point: p(-0.1367,0.1367,-0.4610) n_ratio: 0.99999660001156 cos_i: 0.9360288114367313 sin2_t: 0.12384922198419888 cos_t: 0.936029261303193 refract direction: v(0.0265,-0.0265,0.9993) refracted color: v(0.5174,0.5174,0.5174)
== remaining 5 == object: BIG-SPHERE n1: 1 n2: 1.5 eyev: v(0.0373,-0.0373,-0.9986) normalv: v(-0.1504,0.1504,-0.9771) under point: p(-0.1504,0.1504,-0.9770) n_ratio: 0.6666666666666666 cos_i: 0.9645311833669982 sin2_t: 0.030968709472292525 cos_t: 0.9843938696109944 refract direction: v(0.0265,-0.0265,0.9993) refracted color: v(0.4656,0.4656,0.4656)
|
|
|
Post by totally on Oct 4, 2019 7:56:11 GMT
A little more detail in this specific area Jamis My first time into prepareComputations things look like this: The value of intersection which is my hit is the large sphere with: t = 4.028495994977554 xs is as i posted above: t(4.028495994977554) ior(1.5) ID:BIG-SPHERE t(4.568385678150166) ior(1.0000034) ID:SMALL-SPHERE t(5.4176686785389325) ior(1.0000034) ID:SMALL-SPHERE t(5.957558361711545) ior(1.5) ID:BIG-SPHERE t(15.020949740457555) ior(1) ID:WALL So on the loop through the xs intersections, the first time through hit matches the first item. This is the loop i have there that gives the n1 and n2 values from this data: This is where I can not see how I would get something other can 1.0 for n1 Any thoughts would be greatly appreciated! for (let n = 0; n < xs.length; n++) { const i = xs[n]; if (i === intersection) { if (containers.length === 0) { comps.n1 = 1.0; } else { comps.n1 = containers[containers.length - 1].material.refractiveIndex; } } const objectIndex = containers.indexOf(i.object); if (objectIndex !== -1) { containers.splice(objectIndex, 1); } else { containers.push(i.object); } if (i === intersection) { if (containers.length === 0) { comps.n2 = 1.0; } else { comps.n2 = containers[containers.length - 1].material.refractiveIndex; } break; } }
|
|
|
Post by tdaines on Oct 5, 2019 7:32:50 GMT
I think I know what your problem is because I was doing the same thing. The problem for me was that I was filtering out intersections where `time < 0` when intersecting a ray with the world. It looks like you're doing the same thing in world.js, line 18. Take out the `filter`, leave the `sort`, and I think you're good to go.
|
|
|
Post by Jamis on Oct 14, 2019 17:34:04 GMT
I think tdaines might have nailed it. Good catch! Definitely preserve all intersections, even those behind the eye (t < 0). They're used here to determine which shapes you're inside of, so that the initial refractive index is initialized correctly. (They'll be used later, too, when you get to the chapter on CSG.)
|
|
|
Post by jdunlap on Jan 22, 2021 23:49:20 GMT
In case anyone else comes across this problem, I found that I was not passing my intersections in. Since I had used a default parameter so that tests would still pass, I wasn't catching the problem! I wasn't ignoring negative intersections, but I also wasn't passing any.
|
|
|
Post by auctux on Mar 18, 2021 16:19:52 GMT
can you let me know if you found what was the problem because I tried to render the scene that jamis gave to you but i ended up with the scene image with yours: Floor = Plane() Floor.material = Material() Floor.transform = NumpyMatrixMultiply(rotation_x(pi/2), translationMatrix(0, 0, 10)) Floor.material.pattern = CheckerPattern(Color(0.15, 0.15, 0.15), Color(0.85,0.85, 0.85)) Floor.material.ambient = 0.8 Floor.material.diffuse = 0.2 Floor.material.specular = 0; glassSphere = Sphere() glassSphere.material = Material() glassSphere.material.diffuse = 0.1 glassSphere.material.shininess = 300.0 glassSphere.material.transparency = 0.9 glassSphere.material.reflective = 0.9 glassSphere.material.refractive_index = 1.52 glassSphere.material.ambient = 0 glassSphere.material.color = Color.White() glassSphere.material.specular = 0.9 # glassSphere.transform = scaling(0.5, 0.5, 0.5) airSphere = Sphere() airSphere.transform = scaling(0.5, 0.5, 0.5) airSphere.material = Material() airSphere.material.color = Color.White() airSphere.material.diffuse = 0 airSphere.material.shininess = 300.0 airSphere.material.reflective = 0.9 airSphere.material.transparency = 0.9 airSphere.material.ambient = 0 airSphere.material.specular = 0.9 airSphere.material.refractive_index = 1.0000034 world = World() world.Objects = [Floor, airSphere, glassSphere] world.light = PointLight(Point(2, 10, -5), Color(0.9, 0.9, 0.9)) cam = Camera(800, 800, 0.45) cam.transform = view_transform(Point(0,0, -5), Point(0, 0, 0), Vector3(0, 1, 0))
|
|
|
Post by Jamis on Mar 18, 2021 16:57:08 GMT
Hello auctux! It looks like you're close. Check the three posts just above yours for some suggestions; it might very well be that you're stumbling on the same thing.
|
|