snogglethorpe / snogray

Snogray renderer

Home Page:http://www.nongnu.org/snogray

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add indirection level that allows a material to pertub texture coordinates

snogglethorpe opened this issue · comments

This allows materials to transform texture coordinates for any surface they are used on. Currently textures themselves can do such transformations, but there's no way to transform every texture in a material, and in many cases, we only have access to a material, and cannot affect its component textures.

It shouldn't be too hard:

  1. Add a virtual method Material::tex_coords(Pos, UV) which by default just returns a TexCoords object containing its arguments.
  2. All places that currently create a TexCoords object during intersections would then call Material::tex_coords instead (the material should be available everywhere relevant).

... Ok, it's not quite that easy. Because materials are potentially arranged in a tree (various materials have "underlying" materials, and we'd like add more, including those with multiple children, like a "mix" material), and we'd like to allow texture-coordinate transformation at any point in that tree, there's no single correct set of texture coordinates. The best thing seems to be to get rid of the Intersect::tex_coords field, and rearrange the interfaces to always pass the texture-coordinates as an argument. This is straightforward for most uses... The hard bit is dealing with textures that get evaluated before Intersect is created, in Material::transmittance, when we want to avoid calculating texture-coordinates unless necessary.

After doing all that, using it is easy: we just create some new material classes that just expose an underlying material with transformed texture-coordinates. Probably there should be separate materials for transforming 2d and 3d coordinates, or one material with two transform matrices, as it's probably desirable to do only one or the other (e.g., changing the UV mapping of a mterials without affecting 3d textures).