Rev | Line | |
---|
[2197] | 1 | #include "dxstdafx.h"
|
---|
| 2 | #include "texturedmaterial.h"
|
---|
| 3 |
|
---|
| 4 | TexturedMaterial::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 |
|
---|
| 13 | TexturedMaterial::~TexturedMaterial(void)
|
---|
| 14 | {
|
---|
| 15 | delete pdata;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | Vector 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 |
|
---|
| 33 | Vector TexturedMaterial::getTextureIdealBrdf(const Vector& atPoint) const
|
---|
| 34 | {
|
---|
| 35 | return Vector::RGBBLACK;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | float TexturedMaterial::getTextureDiffuseAlbedo(const Vector& uv) const |
---|
| 39 | { |
---|
| 40 | return getTextureDiffuseBrdf(uv).sum() / 3.0; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | float 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.