Rev | Line | |
---|
[896] | 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 | 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 |
|
---|
| 30 | Vector TexturedMaterial::getTextureIdealBrdf(const Vector& atPoint) const
|
---|
| 31 | {
|
---|
| 32 | return Vector::RGBBLACK;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | float TexturedMaterial::getTextureDiffuseAlbedo(const Vector& uv) const |
---|
| 36 | { |
---|
| 37 | return getTextureDiffuseBrdf(uv).sum() / 3.0; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | float 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.