Simple blending cg shader

Problems building or running the engine, queries about how to use features etc.
Post Reply
asphodel
Gnoblar
Posts: 9
Joined: Tue Jan 11, 2005 5:55 am

Simple blending cg shader

Post 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?
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post 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)
Post Reply