erebus

view liberebus/src/texture.h @ 31:53a98c148bf8

- introduced SurfaceGeometry to carry all the geometric information input to BRDF sampling and evaluation functions. - made Reflectance keep an (optional) pointer to its material - simplified PhongRefl::sample_dir, with the help of SurfaceGeometry - worked around microsoft's broken std::thread implementation's deadlock on join
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 07 Jun 2014 09:14:17 +0300
parents 4abdce1361b9
children
line source
1 #ifndef TEXTURE_H_
2 #define TEXTURE_H_
4 #include "image.h"
5 #include "color.h"
7 class Texture {
8 public:
9 Image<float> img;
11 inline Color lookup(float u, float v) const;
13 bool load(const char *fname) { return img.load(fname); }
14 };
17 inline Color Texture::lookup(float u, float v) const
18 {
19 int xsz = img.get_width();
20 int ysz = img.get_height();
22 int x = (float)u / (float)xsz;
23 int y = (float)v / (float)ysz;
25 float *pix = img.get_pixels() + ((y % ysz) * xsz + (x % xsz)) * 4;
26 return Color(pix[0], pix[1], pix[2]);
27 }
30 #endif // TEXTURE_H_