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