Different texture coordinates in OpenGL and DirectX

Problems building or running the engine, queries about how to use features etc.
rincewind
Kobold
Posts: 33
Joined: Tue Jan 04, 2005 5:57 pm

Different texture coordinates in OpenGL and DirectX

Post by rincewind »

Hi,

I'm currently trying to get some bumpmapping effect to work. guiver6 already posted about this in the Practice-Forum. I finally managed to hunt down the problem and have a very simple test case that shows what is happing, using the following two shaders, I basicly just pass on the tangent from the mesh texcoord-set 1 down to the fragment shader and display it there.
The weird thing is, I get different results in OpenGL vs. DirectX. The DirectX-one seems to be correct, while the OpenGL-one shows abrupt changes on submesh borders.

Thanks for any help.

Greetings,

Rincewind

Here are the shaders:

Code: Select all

//Vertex-shader
void main(
		//my inputs
		float4 Position : POSITION,
		float2 TexCoord0 : TEXCOORD0,
		float3 tangent : TEXCOORD1,
		
		//my outputs
		out float4 oPosition : POSITION,
		out float4 oColor : COLOR,
		out float2 oTexCoord0 : TEXCOORD0,
		out float3 oTexCoord1 : TEXCOORD1,
		
		//uniform state
		uniform float4x4 ModelViewProj
		)
{
	oPosition = mul(ModelViewProj, Position);
	oTexCoord0 = TexCoord0;
	oColor = float4(1.0, 1.0, 1.0, 1.0);
	
	oTexCoord1 = tangent;
	
}

//FragmentShader
void main(
		float2 TexCoord0 : TEXCOORD0,
		float3 L : TEXCOORD1,
		
		//my outputs
		out float4 oColor : COLOR
		)
{
  oColor = float4(L, 1.0);
}

Here's the DirectX-image:
Image

And here the OpenGL-image:
Image[/img]
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

How odd, I've not seen anything like that before. Can you post the .mesh so we can try it?
rincewind
Kobold
Posts: 33
Joined: Tue Jan 04, 2005 5:57 pm

Post by rincewind »

Thanks for the quick reply.

Here's the mesh:

http://www.framesys.de/~je/globe.mesh

you have to assign the material manually (or convert mesh to XML and change material reference for each submateriel) as currently our code takes a material template and assigns it to the submeshes while changing the textures.

Greetings,

Rincewind
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

Ok, I've recreated this here. It looks like every submesh has the same texture coordinates, for reasons I can't explain right now. It can't be referencing the same vertex data because the positions are different, but somehow the same set of texture coords are in use for all the submeshes. :?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

Ok, I fixed it. I made the same mistake you did and was sloppy about declaring which texture coord set applied to each texture unit. D3D happens to default to texture coord set 1 if it's there in texture unit 1, GL defaults to texture coord set 0. So you were getting the 2D texture coordinates in GL.

You didn't post your .material, but I bet you didn't use 'tex_coord_set 1' in your second texture unit. I added that and GL became the same as D3D. Like so:

Code: Select all

material Test/Globe
{
	technique
	{
		pass
		{
			vertex_program_ref GlobeVP
			{
				param_named_auto ModelViewProj worldviewproj_matrix
			}
			fragment_program_ref GlobeFP
			{
			}
			texture_unit
			{
			}
			texture_unit
			{
				tex_coord_set 1
			}
		}
		
	}
}
rincewind
Kobold
Posts: 33
Joined: Tue Jan 04, 2005 5:57 pm

Post by rincewind »

Cool, that did it.

Thanks a lot.

Rincewind
User avatar
guyver6
Greenskin
Posts: 106
Joined: Mon Dec 23, 2002 10:16 pm
Location: Warsaw, Poland

Post by guyver6 »

Sinbad, you're the Man!

All Hail Sinbad :D

Thanks dude, you've solved problem we've been thinking of for few days.

Guyver
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Shouldn't we use the same default convention for both GL and D3D?
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

:wumpus: wrote:Shouldn't we use the same default convention for both GL and D3D?
Perhaps, although I believe this is just the way the API behaves; we don't set the texture coord to 1 deliberately in D3D (in fact, I always thought it defaulted to 0 if not set).