source: GTP/trunk/App/Demos/Illum/PathMap/TexturedMaterial.cpp @ 896

Revision 896, 1.1 KB checked in by szirmay, 18 years ago (diff)
Line 
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        unsigned int dataIndex = floor(fabsf(atPoint.x) * imageSize) * 4 +
21                floor(fabsf(1.0 - fabsf(atPoint.y)) * imageSize) * pitch;
22        if(dataIndex >= pitch * imageSize)
23                return Vector::RGBBLACK;
24        return Vector(
25                pdata[dataIndex+2] / 255.0,
26                pdata[dataIndex+1] / 255.0,
27                pdata[dataIndex] / 255.0);
28}
29
30Vector TexturedMaterial::getTextureIdealBrdf(const Vector& atPoint) const
31{
32        return Vector::RGBBLACK;
33}
34
35float TexturedMaterial::getTextureDiffuseAlbedo(const Vector& uv) const
36{
37        return getTextureDiffuseBrdf(uv).sum() / 3.0;
38}
39
40float TexturedMaterial::getTextureIdealAlbedo(const Vector& uv) const
41{
42        return getTextureIdealBrdf(uv).sum() / 3.0;
43}
Note: See TracBrowser for help on using the repository browser.