Multitexture terrain with lighting using 2 texture units in 1 pass

Hi all,
I implemented a multitexture terrain engine
(based on the nice article at
that uses two base textures and interpolates between them depedning on slope, height etc. The problem is that I wanted to also use lighting (standard opengl per vertex lighting) while doing it one a single pass in a 2 texture unit hardware like my crappy GF4 go (obviously this hardware does not support pixel shaders).

Lets say that L is the light, C the intepolating value at that vertex, and T1 and T2 the two textures. The correct result is L*(T1*(1-c)+T2c).The problem is that if you multiply the first texture unit with the light, when the second texture unit comes in (which uses the GL_INTERPOLATE_ARB) you will get
T1*(1-c)+T2*c. I searched but I haven’t seen any demo or tutorial that achieves that.

My solution is simple: using a vertex program store in the rgb component of the primary color the value L*(1-c)/(1-LC) and in the alpha component the value LC. Then in the interpolation use as Arg2 the GL_SRC_ALPHA. The result will be

I don’t know if anyone finds it usefull, but I think it is a good way to handle multitexture terrain in an engine’s ‘lower end’ path.