source: GTP/trunk/App/Demos/Illum/pathmap/TexturedMaterial.cpp @ 2197

Revision 2197, 1.2 KB checked in by szirmay, 18 years ago (diff)
RevLine 
[2197]1#include "dxstdafx.h"
2#include "texturedmaterial.h"
3
4TexturedMaterial::TexturedMaterial(void* pdata, int pitch, int textureSize)
5:Material(Vector::RGBLIGHTYELLOW, Vector::RGBLIGHTYELLOW, 4.0)
6{
7        this->pdata = new unsigned char[pitch * textureSize];
8        memcpy(this->pdata, pdata, pitch * textureSize);
9        this->pitch = pitch;
10        this->imageSize = textureSize;
11}
12
13TexturedMaterial::~TexturedMaterial(void)
14{
15        delete pdata;
16}
17
18Vector TexturedMaterial::getTextureDiffuseBrdf(const Vector& atPoint) const
19{
20        Vector qp = atPoint;
21        qp.x -= floor(qp.x);
22        qp.y -= floor(qp.y);
23        unsigned int dataIndex = floor(fabsf(qp.x) * imageSize) * 4 +
24                floor(fabsf(1.0 - fabsf(qp.y)) * imageSize) * pitch;
25        if(dataIndex >= pitch * imageSize)
26                return Vector::RGBBLACK;
27        return Vector(
28                pdata[dataIndex+2] / 255.0,
29                pdata[dataIndex+1] / 255.0,
30                pdata[dataIndex] / 255.0);
31}
32
33Vector TexturedMaterial::getTextureIdealBrdf(const Vector& atPoint) const
34{
35        return Vector::RGBBLACK;
36}
37
38float TexturedMaterial::getTextureDiffuseAlbedo(const Vector& uv) const
39{
40        return getTextureDiffuseBrdf(uv).sum() / 3.0;
41}
42
43float TexturedMaterial::getTextureIdealAlbedo(const Vector& uv) const
44{
45        return getTextureIdealBrdf(uv).sum() / 3.0;
46}
Note: See TracBrowser for help on using the repository browser.