From 0878c0e96791ca207b3575ceb2a6e1b0f77a6207 Mon Sep 17 00:00:00 2001 From: castano Date: Sun, 18 Oct 2009 20:04:39 +0000 Subject: [PATCH] Add expand and pack normal methods. Set normal map flag. --- src/nvtt/TexImage.cpp | 40 ++++++++++++++++++++++++++++------------ src/nvtt/nvtt.h | 2 ++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/nvtt/TexImage.cpp b/src/nvtt/TexImage.cpp index 51cf103..962c14c 100644 --- a/src/nvtt/TexImage.cpp +++ b/src/nvtt/TexImage.cpp @@ -758,6 +758,21 @@ void TexImage::scaleBias(int channel, float scale, float bias) } } +void TexImage::packNormal() +{ + scaleBias(0, 0.5f, 0.5f); + scaleBias(1, 0.5f, 0.5f); + scaleBias(2, 0.5f, 0.5f); +} + +void TexImage::expandNormal() +{ + scaleBias(0, 2.0f, -1.0f); + scaleBias(1, 2.0f, -1.0f); + scaleBias(2, 2.0f, -1.0f); +} + + void TexImage::blend(float red, float green, float blue, float alpha, float t) { detach(); @@ -909,12 +924,22 @@ void TexImage::toNormalMap(float sm, float medium, float big, float large) { detach(); + const Vector4 filterWeights(sm, medium, big, large); + foreach (i, m->imageArray) { if (m->imageArray[i] == NULL) continue; - // @@ Not implemented. + const FloatImage * img = m->imageArray[i]; + m->imageArray[i] = nv::createNormalMap(img, (FloatImage::WrapMode)m->wrapMode, filterWeights); + +#pragma messsage(NV_FILE_LINE "Pack and expand normals explicitly") + m->imageArray[i]->packNormals(0); + + delete img; } + + m->isNormalMap = true; } void TexImage::toHeightMap() @@ -927,6 +952,8 @@ void TexImage::toHeightMap() // @@ Not implemented. } + + m->isNormalMap = false; } void TexImage::normalizeNormalMap() @@ -943,17 +970,6 @@ void TexImage::normalizeNormalMap() } } -// Compress. -/*void TexImage::outputCompressed(const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) -{ - foreach (i, m->imageArray) - { - if (m->imageArray[i] == NULL) continue; - - // @@ Not implemented. - } -}*/ - float TexImage::rootMeanSquaredError_rgb(const TexImage & reference) const { int totalCount = 0; diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 902e8f5..520ecfd 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -424,6 +424,8 @@ namespace nvtt NVTT_API void transform(const float w0[4], const float w1[4], const float w2[4], const float w3[4], const float offset[4]); NVTT_API void swizzle(int r, int g, int b, int a); NVTT_API void scaleBias(int channel, float scale, float bias); + NVTT_API void packNormal(); + NVTT_API void expandNormal(); NVTT_API void blend(float r, float g, float b, float a, float t); NVTT_API void premultiplyAlpha(); NVTT_API void toGreyScale(float redScale, float greenScale, float blueScale, float alphaScale);