PDA

View Full Version : fragment * tex0 * constant * tex1



zed
08-30-2001, 01:05 PM
im trying to do either of these in a single pass
fragment * tex0 * constant * tex1
fragment * tex0 - constant * tex1

ie A*B * C*D or A*B - C*D

with either combine/nv_combine4 but have got the feeling its impossible, am i right?

cheers zed

DFrey
08-30-2001, 02:37 PM
Yes, both of those are impossible with just either of those extensions.

zed
08-30-2001, 07:11 PM
cheers DFrey i had a feeling you were gonna answer.
i sort of similated what i was wanting to do with the nvcombine4 + using A*B + C*D - 0.5 ( and careful chossing of textures http://www.opengl.org/discussion_boards/ubb/smile.gif) but still it wasn't 100%. looks like im gonna be forced to do multiple passes. bummer

ffish
08-30-2001, 08:08 PM
If you're using NV_texture_env_combine4 => you must have nVidia hardware => you could use register combiners. What about something like this:


// This one for fragment*tex0-const*tex1.
"!!RC1.0\n"
"const0 = (x, y, z, w);\n"
"final_product = -const0 * tex1;\n"
"out.rgb = col0 * tex0 + final_product;\n"
"out.a = ...;\n"

// Or this for the fragment*tex0*const*tex1.
"!!RC1.0\n"
"const0 = (x, y, z, w);\n"
"{\n"
" rgb {\n"
" spare0 = col0 * tex0;\n"
" }\n"
"final_product = const0*tex1;\n"
"out.rgb = spare0 * final_product;\n"
"out.a = ...;\n"
That's pretty quick, isn't it? One final combiner for the top one and a general and final for the second. Hopefully davepermen won't read this and rip my string to bits http://www.opengl.org/discussion_boards/ubb/wink.gif It should work, though, and should be done in one pass with no performance hit as well. Although, I have a funny idea you have a TNT in which case this is pretty useless so sorry it that's the case.

zed
08-31-2001, 02:25 PM
true i have a nvidia card (vanta) but unfortunately register combiners are only avialable with geforce1+ http://www.opengl.org/discussion_boards/ubb/frown.gif

zed
09-01-2001, 03:37 PM
cheers guys ive come up with a better solution that maybe of interest to yous.

let GL_TEXTURE_ENV_COLOR alpha be how much of tex0 u want to see.
this is ideal for fading in textures eg detailtextures without resorting to blending or fog http://www.opengl.org/discussion_boards/ubb/biggrin.gif

// tex0 * constant + tex1 * (1-constant) - 0.5

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, gradient_texture1); // detail
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD_SIGNED_EXT );
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE );
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT );
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_TEXTURE1_ARB );
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_RGB_EXT, GL_CONSTANT_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_RGB_EXT, GL_ONE_MINUS_SRC_ALPHA);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, colour);

// prev * frag + tex1 * frag

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE );
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_RGB_EXT, GL_SRC_COLOR);

zed
09-02-2001, 12:56 PM
ignore the above post hehe http://www.opengl.org/discussion_boards/ubb/smile.gif i had only tested it on a half yellow/red texture, thus it does appear to work but failed on 'normal textures'.
the above though is possible if u can do a subtract on the 2nd unit. which is part of the tex_env_combine (in opengl1.3) just need to wait for the drivers.