Images as Textures (5 pts)

Implementation

Added files:

  • imagetexture.cpp
  • lodepng.h
  • lodepng.cpp

For many interesting scenes, being able to replace constant colors for the albedo value with images is an essential feature. I have decided to add support for loading PNG files, since this is a common file format for textures when downloading them online. To load the PNG into a std::vector of RGBA values, I use the dependency-free lodepng PNG encoder/decoder. For debugging purposes, I set the texture to a constant pink in case an invalid texture is specified (no filename/incorrect filename), as is common in some computer games. I added support for adding an image texture as a child of a Diffuse BSDF as well as Microfacet BSDF.

The eval method maps from uv-space to image-space by scaling the uv coordinates appropriately and computing the correct index in the image vector. I have added support for additionally offsetting these uv coordinates or applying a custom scaling, which will be demonstrated below. A final noteworthy implementation detail is that we need to call toLinearRGB on our PNG colors, as these are in sRGB.

Validation

I validated my implementation by comparing with Mitsuba. These validations failed at first, only before I realised that Mitsuba uses a right-handed coordinate system in comparison to Nori using a left-handed one, which needs to be accounted for in the scene description.

Texture on a plane (no scaling or offset, but demonstrating how image texture gets repeated)

Mitsuba 3 Mine

Texture on a plane (offset = [0.5, 0.75])

Mitsuba 3 Mine

Texture on a plane (scale = [0.5, 0.25])

Mitsuba 3 Mine

Banana 3D model using image texture (model from TurboSquid)

Mitsuba 3 Mine