snogglethorpe / snogray

Snogray renderer

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redo the way bump-mapping interacts with Material class

snogglethorpe opened this issue · comments

The actual bump-mapping code works OK, but the way bump-mapping is sort of shoved into Material is pretty ugly. It's a public field containing a float texture, which the Intersect initialization code using to do bump mapping. Any Material classes that wrap another class or do any transformation need to copy this field around in their constructor etc. The fact that all this copying takes place in constructors means that the mutability of the field isn't useful.

It would be cleaner and more flexible to add a Material::pertub_normal_frame method, and just call that from Intersect. A special-purpose BumpMap wrapper subclass of Material could then just overwride that method and pass through everything else to its wrapped material. This would also have the advantage of moving the actual bump-mapping code out of Intersect into a more focused class, and making it easy to add other classes that perturb the normal in other ways (e.g. normal-mapping).