diff options
author | M.G. Kishalmi <lmg@kishalmi.net> | 2011-02-23 14:58:36 +0300 |
---|---|---|
committer | M.G. Kishalmi <lmg@kishalmi.net> | 2011-02-23 14:58:36 +0300 |
commit | d7c29a0310f3709395a6de2a1ace6da395770aa6 (patch) | |
tree | a0804c0c7ae61b08a01b3b0f73bc1503f8f14ea8 /source/blender/render | |
parent | 5b607701a7541c328cc058e10bd7a8c6d0c998ab (diff) |
since the introduction of 'newbump' blender
was exporting normal maps with red and green channel inverted
relative to the geometry it actually exports.
This change makes blender export normal maps
which are very similar to most tools out there.
patch by Morten S. Mikkelsen
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/intern/source/imagetexture.c | 30 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 10 |
2 files changed, 32 insertions, 8 deletions
diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index e8392b20331..4baa3480ae9 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -210,8 +210,14 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, TexResult *texre if(texres->nor) { if(tex->imaflag & TEX_NORMALMAP) { // qdn: normal from color - texres->nor[0] = 2.f*(texres->tr - 0.5f); - texres->nor[1] = 2.f*(0.5f - texres->tg); + // The invert of the red channel is to make + // the normal map compliant with the outside world. + // It needs to be done because in Blender + // the normal used in the renderer points inward. It is generated + // this way in calc_vertexnormals(). Should this ever change + // this negate must be removed. + texres->nor[0] = -2.f*(texres->tr - 0.5f); + texres->nor[1] = 2.f*(texres->tg - 0.5f); texres->nor[2] = 2.f*(texres->tb - 0.5f); } else { @@ -1348,8 +1354,14 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, ibuf->rect -= ibuf->x*ibuf->y; if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { // normal from color - texres->nor[0] = 2.f*(texres->tr - 0.5f); - texres->nor[1] = 2.f*(0.5f - texres->tg); + // The invert of the red channel is to make + // the normal map compliant with the outside world. + // It needs to be done because in Blender + // the normal used in the renderer points inward. It is generated + // this way in calc_vertexnormals(). Should this ever change + // this negate must be removed. + texres->nor[0] = -2.f*(texres->tr - 0.5f); + texres->nor[1] = 2.f*(texres->tg - 0.5f); texres->nor[2] = 2.f*(texres->tb - 0.5f); } @@ -1728,8 +1740,14 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *DXT, f if(texres->nor && (tex->imaflag & TEX_NORMALMAP)) { // qdn: normal from color - texres->nor[0] = 2.f*(texres->tr - 0.5f); - texres->nor[1] = 2.f*(0.5f - texres->tg); + // The invert of the red channel is to make + // the normal map compliant with the outside world. + // It needs to be done because in Blender + // the normal used in the renderer points inward. It is generated + // this way in calc_vertexnormals(). Should this ever change + // this negate must be removed. + texres->nor[0] = -2.f*(texres->tr - 0.5f); + texres->nor[1] = 2.f*(texres->tg - 0.5f); texres->nor[2] = 2.f*(texres->tb - 0.5f); } diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 290157354a7..52a80fba5bf 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2180,8 +2180,14 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int quad, int normalize_v3(nor); /* in case object has scaling */ - shr.combined[0]= nor[0]/2.0f + 0.5f; - shr.combined[1]= 0.5f - nor[1]/2.0f; + // The invert of the red channel is to make + // the normal map compliant with the outside world. + // It needs to be done because in Blender + // the normal used in the renderer points inward. It is generated + // this way in calc_vertexnormals(). Should this ever change + // this negate must be removed. + shr.combined[0]= (-nor[0])/2.0f + 0.5f; + shr.combined[1]= nor[1]/2.0f + 0.5f; shr.combined[2]= nor[2]/2.0f + 0.5f; } else if(bs->type==RE_BAKE_TEXTURE) { |