Original Post
Hi! I'm quite new to fragment and vertex program, and I want to use them to do texture splatting in one pass. I had maybe the stupid idea to try to do it in one pass (I only found post/article with multipass on low end hardware). To do so, I pack 4 detail images in one texture, using one mixmap, and later one color map to modulare detail image and containing lighting (shadow etc), why not using the alpha channel to use another set of 4 image (in one texture). All this by using 4 texture unit (I though the radeon 9550 I work on has only 6 TU). I said I done it in one pass, it's not really true, I make a first pass just with the color map, and a second one with the fragment program (glTest = GL_EQUAL). Well, by now I manage to get the basics version to work (getting texture reading right without texture indirection was a little bit tricky). Unfortunately, I didn't get good performance. I try on "large terrain" (1025x1025, using geo mipmapping), even by reducing the number of detail textured triangle (but they are in front of camera so cover a lot of screen space), my frame rate drop. Without the detail pass everything is fine. Here's the fragment program code : The code is maybe not very clear... Anyway, I try to comment out some part, to see what's taking execution time (as I don't have a profiler for this), and removing the MAD for doing blending seems to make it faster (but removing texture reading, or detail image alpha doesn't improve anything). I hope someone can tell me what I can expect from this... Maybe trying to do so (having a large amount of detail texture) is stupid on such low end card, or maybe multipass texture splatting is faster? (as far as I have tried, it doesn't seems really, but I didn't try too much). The last solution I have is to use 6 texture unit without the 4 images in one texture trick? Thank you! Pilo
!!ARBfp1.0
# Texture splatting, using 2 textures (one mixmap + 4 images packed in on detail texture)
ATTRIB tex0 = fragment.texcoord[0]; # mixmap
ATTRIB tex1_coord = fragment.texcoord[1]; # detail 1
ATTRIB tex2_coord = fragment.texcoord[2]; # detail 2
ATTRIB tex3_coord = fragment.texcoord[3]; # detail 3
ATTRIB tex4_coord = fragment.texcoord[4]; # detail 4
ATTRIB dist = fragment.texcoord[5]; # distance
TEMP mixmap;
TEMP detail1;
TEMP detail2;
TEMP detail3;
TEMP detail4;
OUTPUT out = result.color;
TEX mixmap, tex0, texture[0], 2D;
# read detail texture
TEX detail1, tex1_coord, texture[1], 2D;
TEX detail2, tex2_coord, texture[1], 2D;
TEX detail3, tex3_coord, texture[1], 2D;
TEX detail4, tex4_coord, texture[1], 2D;
# texture coef = (1, 0, 0, 0) if tex is detail1, = (0, 1, 0, 0) if tex is detail2 etc
TEMP t1, t2, t3, t4;
FRC t1, tex1_coord;
FRC t2, tex2_coord;
FRC t3, tex3_coord;
FRC t4, tex4_coord;
TEMP tex1_coef, tex2_coef, tex3_coef, tex4_coef;
SGE tex1_coef, t1, 0.5;
SGE tex2_coef, t2, 0.5;
SGE tex3_coef, t3, 0.5;
SGE tex4_coef, t4, 0.5;
TEMP U, V;
TEMP R0, R1;
PARAM U_ = {1, 0, 1, 0};
PARAM V_ = {1, 1, 0, 0};
TEMP tex1_alpha, tex2_alpha, tex3_alpha, tex4_alpha;
# tex1 alpha
SWZ U, tex1_coef, -x, x, -x, x;
SWZ V, tex1_coef, -y, -y, y, y;
ADD R0, U_, U;
ADD R1, V_, V;
MUL R0, R0, R1;
DP4 tex1_alpha, mixmap, R0;
# tex2 alpha
SWZ U, tex2_coef, -x, x, -x, x;
SWZ V, tex2_coef, -y, -y, y, y;
ADD R0, U_, U;
ADD R1, V_, V;
MUL R0, R0, R1;
DP4 tex2_alpha, mixmap, R0;
# tex3 alpha
SWZ U, tex3_coef, -x, x, -x, x;
SWZ V, tex3_coef, -y, -y, y, y;
ADD R0, U_, U;
ADD R1, V_, V;
MUL R0, R0, R1;
DP4 tex3_alpha, mixmap, R0;
# tex4 alpha
SWZ U, tex4_coef, -x, x, -x, x;
SWZ V, tex4_coef, -y, -y, y, y;
ADD R0, U_, U;
ADD R1, V_, V;
MUL R0, R0, R1;
DP4 tex4_alpha, mixmap, R0;
# compute final blending
TEMP final_color;
MUL final_color, tex1_alpha, detail1;
MAD final_color, tex2_alpha, detail2, final_color;
MAD final_color, tex3_alpha, detail3, final_color;
MAD final_color, tex4_alpha, detail4, final_color;
# apply per vertex lighting...
MUL final_color, final_color, fragment.color;
# compute alpha based on distance to camera
TEMP alpha_coef;
TEMP G;
MOV G.a, 2048.0;
RCP alpha_coef, G.a;
MUL final_color.a, dist, alpha_coef;
MIN final_color.a, final_color.a, 1.0;
SUB final_color.a, 1.0, final_color.a;
MOV out, final_color;
END