[Bf-committers] Bump mapping computation issue

Stephane SOPPERA stephane.soppera at wanadoo.fr
Mon Dec 6 01:52:02 CET 2004


Ton Roosendaal wrote:

> Hi,
>
> Here's some results;
>
> ...
>
> Commit follows.

Ton,

Have you commited all your modifications?
The problem is still present, here is a new video I've made with the 
last CVS version:
http://perso.wanadoo.fr/stephane.soppera/blender/bump_bug/videos/bug_bump_p235.avi
As you can see at some camera angles, (ie view angles, since camera is 
orthographic), bump disappears, and it is flipped after that (look at 
the diagonal, its colors switches from light to dark).

I have had a look to what you modified and I don't understand what 
should have corrected the problem in case of UV coordinates defined with 
UV editor. The section where you apply a transformation is only executed if:
mtex->texco==TEXCO_ORCO
That's typically not the case for other UV mapping types, such as UV 
editor for example, isn't it?
(In my test, I use an UVMapped rectangle)

The solution used in 3DSMax for bumpmapping is that each texture has a 
function that compute the modification to apply to the normal. To 
compute this modification, vectors dPdu and dPdv (computed as shown in 
the script I put in my last mail) are given, expressed in an unspecified 
coordinates system, and are used by textures to compute a vector that 
will be added to the normal to compute the new normal.
So if I'm not wrong, textures in blender already returns a vector that 
contains the coordinates in texture space of the vector to add to the 
normal:

tex->nor[0]= (val1-val2);
tex->nor[1]= (val1-val3);

All that is needed is to compute dPdu and dPdv, and we will have:
normal[0]=normal[0]+tex->nor[0]*dPdu[0]+tex->nor[1]*dPdv[0]
normal[1]=normal[1]+tex->nor[0]*dPdu[1]+tex->nor[1]*dPdv[1]
normal[2]=normal[2]+tex->nor[0]*dPdu[2]+tex->nor[1]*dPdv[2]

Where dPdu and dPdv, considered constant on each triangle, are computed 
by (dPdu, dPdv)=computeTangentSpaceForTriangleOpt(...), with:

def computeTangentSpaceForTriangleOpt(p0, p1, p2, uv0, uv1, uv2):
   (x0, y0, z0)=p0
   (x1, y1, z1)=p1
   (x2, y2, z2)=p2
   (s0, t0)=uv0
   (s1, t1)=uv1
   (s2, t2)=uv2

   s01=s0-s1
   s02=s0-s2
   t01=t0-t1
   t02=t0-t2
   x02=x0-x2
   x01=x0-x1
   y02=y0-y2
   y01=y0-y1
   z02=z0-z2
   z01=z0-z1

   a=s01*t02-s02*t01
   b0=t01*x02-t02*x01
   c0=-s01*x02+s02*x01

   b1=t01*y02-t02*y01
   c1=-s01*y02+s02*y01

   b2=t01*z02-t02*z01
   c2=-s01*z02+s02*z01

   tangent =(-b0/a, -b1/a, -b2/a)
   binormal=(-c0/a, -c1/a, -c2/a)
     return (normalize(tangent), normalize(binormal))

Sorry if I misunderstood what you've done.

Thanks,
Stephane

-- 
Stephane SOPPERA
http://perso.wanadoo.fr/stephane.soppera 




More information about the Bf-committers mailing list