Page 1 of 1

Simple blending cg shader

Posted: Sat Feb 19, 2005 7:24 am
by asphodel
I'm trying to use a very simple cg shader that blends two textures based on vertex alpha. The shader works fine when used in a basic OpenGL application. When ran in OGRE, an exception is thrown saying that the compiler gave an error, that texture unit 0 is already bound to sampler 'testTexture'. Here are the offending cg shader and material:

Code: Select all

struct fragment
{
	float4 position  : POSITION;
	float4 color0    : COLOR0;
	float2 texcoord0 : TEXCOORD0;
};

struct pixel
{
	float4 color : COLOR;
};

//-----------------------------------------------------------------------------
pixel main( fragment IN,
            uniform sampler2D testTexture,
            uniform sampler2D checkerTexture )
{
	pixel OUT;

    float4 texelColor0 = tex2D( testTexture, IN.texcoord0 );
    float4 texelColor1 = tex2D( checkerTexture, IN.texcoord0 );

    OUT.color  = (1-IN.color0.a) * texelColor0 + IN.color0.a *texelColor1;

	return OUT;
}

Code: Select all

fragment_program adam/terrain cg
{
	source adam.cg
	entry_point main
	profiles ps_1_1 arbfp1 fp20
}

material adam
{
	technique
	{
		pass
		{
	
			// Fragment program
			fragment_program_ref adam/terrain
			{
			}
			
			texture_unit
			{
				texture checker.bmp
			}
			texture_unit
			{
				texture test.bmp
			}	
		}
	}
}
Anyone see anything wrong with that?

Posted: Sat Feb 19, 2005 9:36 am
by tuan kuranes
the way you use Fragment shader needs ps_2_0.
ps_1_1 means ONE texture Coord == 1 Access.
(you're doing 2 access with IN.texcoord0)