Bug with Cg and DirectX ?

Problems building or running the engine, queries about how to use features etc.
User avatar
Thieum
Gnome
Posts: 342
Joined: Wed Apr 26, 2006 5:13 pm
Location: Bordeaux, France
x 2

Bug with Cg and DirectX ?

Post by Thieum »

Hi!

I have a very strange bug with my stereo manager I hadn't noticed with previous versions of ogre. (It does not work with ogre 1.4.7)

Let's say I have this very simple anaglyph material :

Code: Select all

fragment_program Anaglyph_fp cg
{
   source anaglyph.cg
   profiles ps_2_0 arbfp1
   entry_point Anaglyph_fp
}
material TestAnaglyph
{
	technique
	{
		pass
		{
			fragment_program_ref Anaglyph_fp
			{
			}
			
			texture_unit
			{
				tex_coord_set 0
				texture 10points.png
			}
			
			texture_unit
			{
				tex_coord_set 0
				texture ogrelogo-small.jpg
			}
		}
	}
}

Code: Select all

float4 Anaglyph_fp
(
	in float2 texCoord: TEXCOORD0,
	
	uniform sampler2D LeftTex : register(s0),
	uniform sampler2D RightTex : register(s1)

) : COLOR
{
	float4 left = tex2D(LeftTex, texCoord);
	float4 right = tex2D(RightTex, texCoord);

	
	return float4(left.r, right.g, right.b, 1); // does not work
//	return left * float4(1,0,0,1) + right * float4(0,1,1,1); // works
//	return float4(left.r, right.g, right.b, left.r); // works
}
In opengGL it works fine, but in DirectX it shows only the second texture :
Image
There is no error in the log and I'm sure the shader is executed because if I change the texture coordinates in the shader, the changes are visible.

More strangely, if i replace the last line with return left * float4(1,0,0,1) + right * float4(0,1,1,1); or return float4(left.r, right.g, right.b, left.r);, it works fine :
Image
if I change the components used in float4(left.r, right.g, right.b, left.r);, sometimes it shows a mix between the two images (what I want) but sometimes it only shows only one of the two images.

I tried this on a 8800GTX and a 7900GS and the shader worked before.
Did something changed in the Cg compiler with newer versions of ogre ? Is this a bug of the cg compiler or some sort of optimization ? Have you any idea ?

Thanks
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 »

Instead of trying to use fixed-function to route your texture coords through to the fragment program using tex_coord_set, use a vertex program. I've found it's most reliable not to mix the two.
User avatar
Thieum
Gnome
Posts: 342
Joined: Wed Apr 26, 2006 5:13 pm
Location: Bordeaux, France
x 2

Post by Thieum »

Thank you for the advice, I added StdQuad_vp to the material
But it does not fix my problem
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 »

That's the wrong vertex program anyway, if you used that your geometry would be completely wrong (it only works for full-screen quads specified in projection space). You want "Ogre/BasicVertexPrograms/AmbientOneTexture". By one texture it means one texture coordinate set.

Take out the tex_coord_set calls too. We use multiple texture, single UV set Cg programs in many of our demos.