mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.89k stars 454 forks source link

Animating camera leads to unexpected results #444

Open lijenicol opened 1 month ago

lijenicol commented 1 month ago

Consider the following pbrt scene (modified off the example here), where the transformations for the camera at the start and end times are the same, and the x-axis is flipped using Scale:

# Camera transformations ------------

Scale -1 1 1
LookAt 3 4 1.5  # eye
       .5 .5 0  # look at point
       0 0 1    # up vector
ActiveTransform StartTime
Translate 1 0 0
ActiveTransform EndTime
Translate 1 0 0
ActiveTransform All

# End camera transformations ------

Camera "perspective" "float fov" 45

Sampler "halton" "integer pixelsamples" 4
Integrator "volpath"
Film "rgb" "string filename" "/tmp/testRender.png"
     "integer xresolution" [400] "integer yresolution" [400]

WorldBegin

# uniform blue-ish illumination from all directions
LightSource "infinite" "rgb L" [ .4 .45 .5 ]

# approximate the sun
LightSource "distant"  "point3 from" [ -30 40  100 ]
   "blackbody L" 3000 "float scale" 1.5

AttributeBegin
  Material "dielectric"
  Shape "sphere" "float radius" 1
AttributeEnd

AttributeBegin
  Texture "checks" "spectrum" "checkerboard"
          "float uscale" [16] "float vscale" [16]
          "rgb tex1" [.1 .1 .1] "rgb tex2" [.8 .8 .8]
  Material "diffuse" "texture reflectance" "checks"
  Translate 0 0 -1
  Shape "bilinearmesh"
      "point3 P" [ -20 -20 0   20 -20 0   -20 20 0   20 20 0 ]
      "point2 uv" [ 0 0   1 0    1 1   0 1 ]
AttributeEnd

That produces this image: testRender

Now, modify the start or end time transform slightly, and all of a sudden the camera flips unexpectedly. In this case I changed the end time from above by adding 0.1 to the x-axis:

ActiveTransform EndTime
Translate 1.1 0 0

With that adjustment, I get: testRender

This oddity seems to only happen when any of the Scale axes are negative. If all the scale axes are positive, then the animated camera doesn't do the strange flip.

(My pbrt version is based off the most recent commit on master: 39e01e6)

pbrt4bounty commented 1 month ago

@lijenicol I think the culprit is the 'Scale -1 1 1' statement in your scene.. try to remove and render again

lijenicol commented 1 month ago

@pbrt4bounty Yes that Scale -1 1 1 directive is part of the problem, and removing it "fixes" the render, but what remains a question is why the mixture of all the things I said above produces unexpected results.