[Bf-committers] Bump mapping computation issue
Stephane SOPPERA
stephane.soppera at wanadoo.fr
Mon Dec 6 00:10:50 CET 2004
Ton Roosendaal wrote:
> Hi,
>
> Yes, bump mapping now happens in an object's local texture space,
> giving the errors as you've illustrated. This is an ancient issue in
> Blender.
>
>> It seems to me that the problem comes from perturbated normal
>> computation made by blender.
>> The formula for normal computation should be:
>> perturbated_normal=initial_normal+dI/du*dP/du+dI/dv*dP/dv
>> where dI/du and dI/dv are the partial derivates of the texture color
>> in texture plane (these are scalars), and where dP/du and dP/dv are
>> the partial derivates of the position against texture coordinates
>> (vector dP/du "points" in the direction of greater "u").
>
>
> Euh... I'm not sure about the notation you use here, but such parial
> derivates are used in Blender too. I think the only issue lacking is
> a proper transformation of the perturbation to global coordinates
> again, like the "shi->vn" is expressed in.
>
> I think it's an interesting quality issue for Blender to solve once.
> Lemme give it a try now!
If this can help you, the following python function:
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))
this function compute dP/du and dP/dv (u and v being the mapping
coordinates), also called tangent and binormal, for a triangle define by
points p0, p1, p2 points and uv0, uv1, uv2 texture coordinates. The
result will be expressed in the same coordinate system as p0, p1, p2.
dP/du and dP/dv vectors can be considered constant on a single triangle.
3DSmax scanline render is doing this assumption and this works nicely
for it.
Hope this helps.
Stéphane
--
Stephane SOPPERA
http://perso.wanadoo.fr/stephane.soppera
More information about the Bf-committers
mailing list