PDA

View Full Version : multi texture - trilinear lerp



seen
12-12-2006, 01:25 PM
Couple of questions. I'm using multi-texturing and a cg fragment shader to perform a tri-linear interpolation between two textures. The program works at home but not at work. I have an nVidia 3400 @ home and a nVidia Quadro 4 980 @ work.

This is the code I use to determine which profile, but it returns FP20 for the Quadro 4 980.

if(cgGLIsProfileSupported(CG_PROFILE_ARBFP1) )
_CGprofile_pixel = CG_PROFILE_ARBFP1;
else if(cgGLIsProfileSupported(CG_PROFILE_FP30) )
_CGprofile_pixel = CG_PROFILE_FP30;
else if(cgGLIsProfileSupported(CG_PROFILE_FP20) )
_CGprofile_pixel = CG_PROFILE_FP20;
else
{
return false;
}


OK, when I use cgc to compile this program using the FP20 profile it dies:

trilinear.cg
trilinear.cg(8) : error C6028: Texture unit 0 already bound to sampler 'texUV'
trilinear.cg(9) : error C6028: Texture unit 0 already bound to sampler 'texUV'
trilinear.cg(8) : error C6028: Texture unit 0 already bound to sampler 'texUV'
trilinear.cg(9) : error C6028: Texture unit 0 already bound to sampler 'texUV'
15 lines, 4 errors.


Questions:
- How do I perform this task when I'm stuck on a fp20 profile.
- Is the code above matching the card to the correct profile?

Thanks


float4 main(half3 texUV : TEXCOORD0,
uniform sampler2D texture0,
uniform sampler2D texture1) : COLOR
{
//two blinear fetches
float4 tex0 = tex2D(texture0, texUV.xy);
float4 tex1 = tex2D(texture1, texUV.xy);

//liner interpolation
float4 result = lerp(tex0, tex1, texUV.z);

return result;
}

jra101
12-12-2006, 01:47 PM
With the fp20 profile the texture coordinates and texture image units are bound together (i.e. you must use TEXCOORD0 to sample from TEXUNIT0, TEXCOORD1 to sample from TEXUNIT1, etc).

To make your program work with both the fp20 and arbfp1 profiles you would modify it to accept two texture coordinates (TEXCOORD0 and TEXCOORD1) then either use a vertex program to write your incoming texture coordinate to the TEXCOORD0 and TEXCOORD1 outputs, or send two copies of your texture coordinates using:

glMultiTexCoord*f(GL_TEXTURE0, ...);
glMultiTexCoord*f(GL_TEXTURE1, ...);