Fix normal map mipmap generation.

This commit is contained in:
castano
2007-05-18 02:19:51 +00:00
parent 5135f30d8e
commit de94fce1ce
13 changed files with 76 additions and 27 deletions

View File

@ -181,7 +181,7 @@ void FloatImage::packNormals(uint base_component)
void FloatImage::expandNormals(uint base_component)
{
scaleBias(base_component, 3, 2, 0.5);
scaleBias(base_component, 3, 2, -0.5);
}
void FloatImage::scaleBias(uint base_component, uint num, float scale, float bias)

View File

@ -133,6 +133,8 @@ FloatImage * nv::createNormalMap(const Image * img, FloatImage::WrapMode wm, Vec
void nv::normalize(FloatImage * img)
{
nvCheck(img != NULL);
img->expandNormals(0);
img->normalize(0);
img->packNormals(0);
}

View File

@ -226,6 +226,12 @@ void InputOptions::setQuantization(bool colorDithering, bool alphaDithering, boo
}
/// Indicate whether input is a normal map or not.
void InputOptions::setNormalMap(bool b)
{
m.normalMap = b;
}
/// Enable normal map conversion.
void InputOptions::setConvertToNormalMap(bool convert)
{

View File

@ -1,24 +1,24 @@
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#ifndef NV_TT_INPUTOPTIONS_H
@ -64,6 +64,7 @@ namespace nvtt
MipmapFilter mipmapFilter;
// Normal map options.
bool normalMap;
bool normalizeMipmaps;
bool convertToNormalMap;
nv::Vector4 heightFactors;

View File

@ -255,8 +255,14 @@ static FloatImage * toFloatImage(const Image * image, const InputOptions::Privat
FloatImage * floatImage = new FloatImage(image);
// Convert to linear space.
if (inputOptions.inputGamma != 1.0f) {
if (inputOptions.normalMap)
{
// Expand normals. to [-1, 1] range.
// floatImage->expandNormals(0);
}
else if (inputOptions.inputGamma != 1.0f)
{
// Convert to linear space.
floatImage->toLinear(0, 3, inputOptions.inputGamma);
}

View File

@ -172,6 +172,7 @@ namespace nvtt
NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127);
// Set normal map options.
NVTT_API void setNormalMap(bool b);
NVTT_API void setConvertToNormalMap(bool convert);
NVTT_API void setHeightEvaluation(float redScale, float greenScale, float blueScale, float alphaScale);
NVTT_API void setNormalFilter(float small, float medium, float big, float large);

View File

@ -98,6 +98,7 @@ struct MyErrorHandler : public nvtt::ErrorHandler
// Set color to normal map conversion options.
void setColorToNormalMap(nvtt::InputOptions & inputOptions)
{
inputOptions.setNormalMap(false);
inputOptions.setConvertToNormalMap(true);
inputOptions.setHeightEvaluation(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 0.0f);
//inputOptions.setNormalFilter(1.0f, 0, 0, 0);
@ -109,6 +110,7 @@ void setColorToNormalMap(nvtt::InputOptions & inputOptions)
// Set options for normal maps.
void setNormalMap(nvtt::InputOptions & inputOptions)
{
inputOptions.setNormalMap(true);
inputOptions.setConvertToNormalMap(false);
inputOptions.setGamma(1.0f, 1.0f);
inputOptions.setNormalizeMipmaps(true);
@ -117,6 +119,7 @@ void setNormalMap(nvtt::InputOptions & inputOptions)
// Set options for color maps.
void setColorMap(nvtt::InputOptions & inputOptions)
{
inputOptions.setNormalMap(false);
inputOptions.setConvertToNormalMap(false);
inputOptions.setGamma(2.2f, 2.2f);
inputOptions.setNormalizeMipmaps(false);
@ -333,7 +336,8 @@ int main(int argc, char *argv[])
}
else
{
inputOptions.setMipmapping(true, nvtt::MipmapFilter_Kaiser);
inputOptions.setMipmapping(true, nvtt::MipmapFilter_Box);
//inputOptions.setMipmapping(true, nvtt::MipmapFilter_Kaiser);
}
if (wrapRepeat)