Page 1 of 1

Question about tangents and bump

Posted: Wed Dec 10, 2025 5:57 pm
by minimy
I got a extrange result when use bumpmapping over my own objects (created by me):
Well i got simple cubes creates with normals like ogre information say at respect to direction, all work nice without bumpmapping. But when apply bump the normals (shadow by face) is wrong.
Im using ccw for faces (standard face direction) and the table reference for face orientation (normals and tangents).
The weird thing is XY and Z normals like inverted, top is dark and bottom is light, left and front same...
Is a bug, is right my table, may be because im using UV globals (world coordinates)?
May be the moon is in aquarius and mars is in scorpius? :lol:

I can solve this with a var like Invert=1 but is not the right solution.
This is the table im using. May be interesting for any of you.

Code: Select all

Cara			Normal (N)	Tangente (T)	Binormal (B = N × T)
+X (right)		(1, 0, 0)	(0, 0, -1)		(0, 1, 0)
–X (left)		(-1, 0, 0)	(0, 0, 1)		(0, 1, 0)
+Y (top)		(0, 1, 0)	(1, 0, 0)		(0, 0, -1)
–Y (bottom)		(0, -1, 0)	(1, 0, 0)		(0, 0, 1)
+Z (front)		(0, 0, 1)	(1, 0, 0)		(0, 1, 0)
–Z (rear/back)	(0, 0, -1)	(-1, 0, 0)		(0, 1, 0)

Re: Question about tangents and bump

Posted: Wed Dec 10, 2025 6:01 pm
by miso
minimy wrote: Wed Dec 10, 2025 5:57 pm I got a extrange result when use bumpmapping over my own objects (created by me):
Well i got simple cubes creates with normals like ogre information say at respect to direction, all work nice without bumpmapping. But when apply bump the normals (shadow by face) is wrong.
Im using ccw for faces (standard face direction) and the table reference for face orientation (normals and tangents).
The weird thing is XY and Z normals like inverted, top is dark and bottom is light, left and front same...
Is a bug, is right my table, may be because im using UV globals (world coordinates)?
May be the moon is in aquarius and mars is in scorpius? :lol:

I can solve this with a var like Invert=1 but is not the right solution.
This is the table im using. May be interesting for any of you.

Code: Select all

Cara			Normal (N)	Tangente (T)	Binormal (B = N × T)
+X (right)		(1, 0, 0)	(0, 0, -1)		(0, 1, 0)
–X (left)		(-1, 0, 0)	(0, 0, 1)		(0, 1, 0)
+Y (top)		(0, 1, 0)	(1, 0, 0)		(0, 0, -1)
–Y (bottom)		(0, -1, 0)	(1, 0, 0)		(0, 0, 1)
+Z (front)		(0, 0, 1)	(1, 0, 0)		(0, 1, 0)
–Z (rear/back)	(0, 0, -1)	(-1, 0, 0)		(0, 1, 0)
Are your models handmade? I wanted to ask, if you use clockwise or anticlockwise or both when rendering. Isn't the face triangle vertex order is the culprit?
(maybe it isn't, but that was my first guess.)

Edit, Ah I see, you use ccw. I'm tired.

Re: Question about tangents and bump

Posted: Wed Dec 10, 2025 6:31 pm
by minimy
Hi miso, im using only anticlockwise for every face.
Hahaha me to, close to christmas tired me.
Is really weird because if i use BuildMeshTangents the rresult is the same, this is an indicator what my manual tangents are right. But if my faces and normals are right, what´s the problem?, is crazy.

Re: Question about tangents and bump

Posted: Wed Dec 10, 2025 6:34 pm
by miso
And just to close out everything, it is not turned on in the materials to show both side.

1. If it is, then turn it off, to see if theres a hole somewhere.

2. Is your models created outside of pb? Maybe one is created with blender, one is created with another one, and maybe their coordinate system order is different.

Re: Question about tangents and bump

Posted: Thu Dec 11, 2025 9:38 am
by threedslider
@minimy : Are you adding for isosurface to Bump mapping (adding geometry?) ? What difference from Normal mapping to Bump mapping ?

Your models are from Blender ? Any screenshot to show here :mrgreen: ?

Re: Question about tangents and bump

Posted: Thu Dec 11, 2025 10:42 am
by pf shadoko
to show normal:

Code: Select all

Procedure debugnormal(mesh,color1.l,color2.l,lenth.f=1)
	Protected i,j,ns,nv,mi,nmesh,nmat
	
	nmesh=CreateMesh(-1,#PB_Mesh_LineList)
	For j=0 To SubMeshCount(mesh)-1
		nv=MeshVertexCount(mesh,j)-1
		Dim v.MeshVertex(nv)
		GetMeshData(mesh,j,v(),#PB_Mesh_Vertex|#PB_Mesh_Normal,0,nv) 
		For i=0 To nv
			With v(i)
				MeshVertex(\x,\y,\z,0,0,color1)
				MeshVertex(\x+\NormalX*lenth,\y+\Normaly*lenth,\z+\NormalZ*lenth,0,0,color2)
				MeshIndex(mi):mi+1
				MeshIndex(mi):mi+1
			EndWith
		Next
	Next
	FinishMesh(1)
	DisableDebugger:nmat=CreateMaterial(-1,0):EnableDebugger
	DisableMaterialLighting(nmat, #True)
	CreateEntity(-1,MeshID(nmesh),MaterialID(nmat))
EndProcedure
ex:
CreateCube(0,2)
debugnormal(0,$ff,$ffff,0.5)

you must see 24 lines

d'ont calculate tangent, and don't define them
use BuildMeshTangents

Re: Question about tangents and bump

Posted: Fri Dec 12, 2025 3:52 am
by minimy
Thank you! Nice code!