1
Freebasic / Re: little 3d cube with bumpmapping.
« Last post by ninogenio on Today at 02:59 AM »sorry i realise that was very wrong
.
im now creating a tangent binormal and normal for each vertex like this.
this just feeds the T B N Vectors back to the 3dobject struct and they sit alongside the vertex's. now that i have 1 T B N vector per vertex im not 100% sure how too use all three too rotate the normals. Maybe Feed them into the rasterizer and interpolate?.
im trying the lighting like so too
each SetUvLight now gets its own T B N Vectors that correspond too the vertex. for some reason though the light is always offset too the left of the texture its like im missing another step. i tried a few things like translating and rotating the direction vector but with no luck. i think im definitly missing something but cant think what.
the reason im trying too do it on this way having a T B N Vector for each vertex is simply because all the examples out there are in glsl so im having too try and follow them but im not so good at shaders so its a bit sketchy for me.
.im now creating a tangent binormal and normal for each vertex like this.
Code: [Select]
Sub ComputeTangentMatrix( Tangent As Vector4d, BiNorm As Vector4d, TangNorm As Vector4d, Vec1 As Vector4d, Vec2 As Vector4d, Vec3 As Vector4d _
, Uv1 As Vector2d, Uv2 As Vector2d, Uv3 As Vector2d )
Dim As Double v1x, v1y, v1z, v2x, v2y, v2z, u1x, u1y, u2x, u2y, Recip
v1x = Vec2.x - Vec1.x
v1y = Vec2.y - Vec1.y
v1z = Vec2.z - Vec1.z
v2x = Vec3.x - Vec1.x
v2y = Vec3.y - Vec1.y
v2z = Vec3.z - Vec1.z
u1x = Uv2.x - Uv1.x
u1y = Uv2.y - Uv1.y
u2x = Uv3.x - Uv1.x
u2y = Uv3.y - Uv1.y
Recip = 1.0/(u1x * u2y - u2x * u1y)
Tangent.X = (v1x * u2y - v2x * u1y) * Recip
Tangent.Y = (v1y * u2y - v2y * u1y) * Recip
Tangent.Z = (v1z * u2y - v2z * u1y) * Recip
Binorm.X = (-v1x * u2x + v2x * u1x) * Recip
Binorm.Y = (-v1y * u2x + v2y * u1x) * Recip
Binorm.z = (-v1z * u2x + v2z * u1x) * Recip
TangNorm.X = BiNorm.Y * tangent.Z - BiNorm.z * Tangent.Y
TangNorm.Y = BiNorm.Z * tangent.X - BiNorm.x * Tangent.Z
TangNorm.Z = BiNorm.X * tangent.Y - BiNorm.y * Tangent.X
NormilizeVec( @Tangent )
NormilizeVec( @binorm )
NormilizeVec( @TangNorm )
End Sub
this just feeds the T B N Vectors back to the 3dobject struct and they sit alongside the vertex's. now that i have 1 T B N vector per vertex im not 100% sure how too use all three too rotate the normals. Maybe Feed them into the rasterizer and interpolate?.
im trying the lighting like so too
Code: [Select]
Sub SetUvLight1( Vertex As Vector4d, Light As Vector4d, T As Vector4d, B As Vector4d, N As Vector4d )
Ind0.Lx = (Light.X - Vertex.X)
Ind0.Ly = (Light.Y - Vertex.Y)
Ind0.Lz = (Light.Z - Vertex.Z)
NormilizeVec( @Ind0 )
'tx.bx.nx column major
'ty.by.ny
'tz.bz.nz
'inv = row major
'tx.ty.tz
'bx.by.bz
'nx.ny.nz
'tried inverting the ind vectors also too see if it would work
Ind0.Lx = (T.X*Ind0.Lx + T.Y*Ind0.Lx + T.Z*Ind0.Lx)
Ind0.Ly = (B.X*Ind0.Ly + B.Y*Ind0.Ly + B.Z*Ind0.Ly)
Ind0.Lz = (N.X*Ind0.Lz + N.Y*Ind0.Lz + N.Z*Ind0.Lz)
End Sub
each SetUvLight now gets its own T B N Vectors that correspond too the vertex. for some reason though the light is always offset too the left of the texture its like im missing another step. i tried a few things like translating and rotating the direction vector but with no luck. i think im definitly missing something but cant think what.
the reason im trying too do it on this way having a T B N Vector for each vertex is simply because all the examples out there are in glsl so im having too try and follow them but im not so good at shaders so its a bit sketchy for me.
Recent Posts