Raytracing: conversion issues

I'm having trouble converting. For some reason, everything is not as it seems to me, it should be, but, frankly, all the transformations back and forth make me pretty dizzy.

As I read everywhere (although explicit explanations are rare, imho), the basic transformation algorithm is as follows:

  • converts Ray (Origin and Direction) with the inverse of the transformation matrix
  • converts the resulting intersection point with the transformation matrix
  • converts the normal object to the point of intersection with the transposed inverse

From what I understood, this was supposed to do the trick. I am pretty sure that my problem is that I am trying to calculate the lighting, since both the initial intersection and the lighting algorithm use the same function ( obj.getIntersection() ). But then again, I have no idea .:(

Here you can read parts of my code:

main.cpp , scene.cpp , sphere.cpp , sdf-loader.cpp

Please let me know if you need more information to help me - and please help me!;)

EDIT:

I made some results, maybe someone β€œsees” (from the results) where I can be wrong:

untransformed scene:

untransformed scene

sphere scaled (2,4,2):

sphere scaled (2,4,2)

box translation (0, -200,0):

box translated (0, -200,0)

scope translated (-300,0,0):

sphere translated (-300,0,0)

ball x-rotated (45 Β°):

sphere x-rotated (45 Β°)

+4
source share
1 answer

Typically, for conversion to computer graphics, I would recommend that you take a look at scratchapixel.com and, in particular, this lesson:

http://scratchapixel.com/lessons/3d-basic-lessons/lesson-4-geometry/

and this one, where you can see how transformations (matrices) are used to transform rays and objects:

http://scratchapixel.com/lessons/3d-basic-lessons/lesson-8-putting-it-all-together-our-first-ray-tracer/

If you still do not know this amazing resource, I would advise you to use it and, possibly, to spread this word in your university. Your teacher should have pointed you out.

0
source

Source: https://habr.com/ru/post/1498722/


All Articles