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.8k stars 429 forks source link

Fix displacement for plymesh #363

Closed kingiler closed 10 months ago

kingiler commented 1 year ago

This patch attempts to fix the bug when displacing plymesh containing a quad. The bug only exists when running with CPU only.

Example scene (taken from pbrt.org):

LookAt 3 4 1.5  # eye
       .5 .5 0  # look at point
       0 0 1    # up vector
Camera "perspective" "float fov" 45

Sampler "halton" "integer pixelsamples" 128
Integrator "volpath"
Film "rgb" "string filename" "simple.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

Texture "white"
  "float" "imagemap"
  "string filename" "white.png"

AttributeBegin
  Material "coateddiffuse"
  Shape "plymesh"
    "string filename" "sphere.ply"
    "texture displacement" "white"
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

where white.png is a grayscale png file with all pixel value 255. sphere.ply is a UV sphere generated by Blender.

Current image gives: current Expected image: expected

The difference is due to quad meshes are not rendered after displacement.

mmp commented 10 months ago

(Sorry for not merging this sooner!)

Nice fix--thanks for chasing that down!