|
Post by jamesmcm on Nov 22, 2019 20:02:37 GMT
Hi, My refraction results seem slightly strange: But all the tests pass. Is it possible to get the environment set up for the example in the book: So it could be compared more directly?
|
|
|
Post by Jamis on Nov 22, 2019 23:21:04 GMT
Certainly! Here's the scene description, in YAML:
# ====================================================== # refraction-bend.yml # # This file describes the scene illustrated at the start # of the "Transparency and Refraction" section, in # chapter 11 ("Reflection and Refraction") of # "The Ray Tracer Challenge" # # by Jamis Buck <jamis@jamisbuck.org> # ======================================================
# ====================================================== # the camera # ======================================================
- add: camera width: 200 height: 200 field-of-view: 0.5 from: [-4.5, 0.85, -4] to: [0, 0.85, 0] up: [0, 1, 0]
# ====================================================== # light sources # ======================================================
- add: light at: [-4.9, 4.9, 1] intensity: [1, 1, 1]
# ====================================================== # define some constants to avoid duplication # ======================================================
- define: wall value: pattern: type: checkers colors: - [ 0.00, 0.00, 0.00 ] - [ 0.75, 0.75, 0.75 ] transform: - [ scale, 0.5, 0.5, 0.5 ] specular: 0
# ====================================================== # describe the scene # ======================================================
# floor - add: plane transform: - [ rotate-y, 0.31415 ] material: pattern: type: checkers colors: - [0.00, 0.00, 0.00] - [0.75, 0.75, 0.75] ambient: 0.5 diffuse: 0.4 specular: 0.8 reflective: 0.1
# ceiling - add: plane transform: - [ translate, 0, 5, 0 ] material: pattern: type: checkers colors: - [0.85, 0.85, 0.85] - [1.00, 1.00, 1.00] transform: - [ scale, 0.2, 0.2, 0.2 ] ambient: 0.5 specular: 0
# west wall - add: plane transform: - [ rotate-y, 1.5708 ] # orient texture - [ rotate-z, 1.5708 ] # rotate to vertical - [ translate, -5, 0, 0 ] material: wall
# east wall - add: plane transform: - [ rotate-y, 1.5708 ] # orient texture - [ rotate-z, 1.5708 ] # rotate to vertical - [ translate, 5, 0, 0 ] material: wall
# north wall - add: plane transform: - [ rotate-x, 1.5708 ] # rotate to vertical - [ translate, 0, 0, 5 ] material: wall
# south wall - add: plane transform: - [ rotate-x, 1.5708 ] # rotate to vertical - [ translate, 0, 0, -5 ] material: wall
# background ball - add: sphere transform: - [ translate, 4, 1, 4 ] material: color: [ 0.8, 0.1, 0.3 ] specular: 0
# background ball - add: sphere transform: - [ scale, 0.4, 0.4, 0.4 ] - [ translate, 4.6, 0.4, 2.9 ] material: color: [ 0.1, 0.8, 0.2 ] shininess: 200
# background ball - add: sphere transform: - [ scale, 0.6, 0.6, 0.6 ] - [ translate, 2.6, 0.6, 4.4 ] material: color: [ 0.2, 0.1, 0.8 ] shininess: 10 specular: 0.4
# glass ball - add: sphere transform: - [ scale, 1, 1, 1 ] - [ translate, 0.25, 1, 0 ] material: color: [ 0.8, 0.8, 0.9 ] ambient: 0 diffuse: 0.2 specular: 0.9 shininess: 300 transparency: 0.8 refractive-index: 1.57
|
|
|
Post by jamesmcm on Nov 23, 2019 10:57:10 GMT
Thanks! Are all of the demo YAMLs available somewhere btw? Also the refraction works okay: But I have some issues with the walls (adding the walls behind the camera made the spheres invisible, I'll try to debug that now)
|
|
|
Post by jamesmcm on Nov 23, 2019 10:58:06 GMT
Also for anyone reading this, note that the order of transformations matters!
Scaling * Translation != Translation * Scaling (since the Scaling would affect the amount translated)
Use Scaling * Translation for the yaml example.
|
|
|
Post by jamesmcm on Nov 23, 2019 14:30:46 GMT
Working (although the specular reflection is in a slightly different place wrt. the demo for some reason): In the end all of the issues were related to the order of transformation matrices, and the code was fine
|
|
|
Post by manxome on Nov 23, 2019 21:05:45 GMT
I think the light moved! I am trying to gain confidence in my RayTracer implementation so I hope this doesn't just seem like nit-picking. Jamesmcm, thank you for posting your results. Jamis, thanks for the awesome book! OK, I just rendered this image using Jamis's yaml and noticed that I had shadows and speculars that were slightly off compared to the book picture that jamesmcm posted above. Here are the comparison pics: If the light didn't move somehow, I have some serious debugging to do...
|
|
|
Post by accolon on Nov 23, 2019 22:16:18 GMT
Using the YAML file in this thread, my Python implementation produces an image that looks exactly like those posted by you, manxome, and jamesmcm. I suppose that the image from the book is based on a slightly different YAML.
|
|
|
Post by Jamis on Nov 24, 2019 3:07:05 GMT
Good catch! I must have changed the position of the light source after rendering the image for the book...I don't know why. I suspect maybe I didn't like how the specular highlight was positioned over the image of the green ball, but then I never got around to replacing the image itself in the book.
|
|
|
Post by Jamis on Nov 24, 2019 3:08:33 GMT
Oh, and to answer your question about other YAML files: if you look in the "Gallery" forum and find the threads created by me, most of them include YAML files for recreating the images there.
|
|