Vertex/image shading (in 2d, based on faked 3d..)

BlitzMax Forums/BlitzMax Programming/Vertex/image shading (in 2d, based on faked 3d..)

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Thanks Warpy!

This code works perfect (light vector and colors will be initiated once in the near future):
Local lvec:TVec3, light:Float, dp:Float
lvec = New TVec3.Create(1 / Sqr(3), - 1 / Sqr(3), 1.0)

Local normal1:TVec3, normal2:TVec3, normal:TVec3
normal1 = _quad.topright.Copy()
normal2 = _quad.bottomright.Copy()
normal1.SubtractVec(_quad.topleft)
normal2.SubtractVec(_quad.topleft)

normal = TVec3.CrossProduct(normal1, normal2)
normal.Normalize()
dp = normal.DotProduct(lvec)

If dp < 0 Then dp = 0
light = dp * 0.4 + 0.6
SetColor(light * 255, light * 255, light * 255)


I also changed the quad positions used because they were slightly wrong (topleft = A, topright = B, bottomleft = C, bottomright = D).
I still haven't found the best light position, some seem to make the color change too intense, some not enough.
http://img252.imageshack.us/img252/2800/earlywithshadingmoew5.png
http://img252.imageshack.us/img252/7167/earlywithshadingdebuglizx0.png