References:
http://github.com/spring/spring/blob/7c ... Drawer.cpp
http://github.com/spring/spring/blob/7c ... andler.cpp
http://github.com/spring/spring/blob/7c ... Drawer.cpp
http://github.com/spring/spring/blob/7c ... andler.cpp
Also see treeShadow.vp vs. unit_genshadow.vp, in the shaders directory.
I started with what I know: tree shadows still work. Nothing else does. I've been staring at the sourcecode and the shaders, and I'm rather puzzled by several things:
1. The Unit code reinitializes ARB values 16,17 and 18, which ShadowHandler says aren't supposed to be touched by anything else.
2. The difference between the TreeShadow.vp and UnitGenShadow.vp is that there is a difference between the use of ARB values 11 and 12.
The Unit code refers to it thus:
Code: Select all
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,11, unitSunColor.x,unitSunColor.y,unitSunColor.z,0);
Code: Select all
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,11, mapInfo->light.groundSunColor.x,mapInfo->light.groundSunColor.y,mapInfo->light.groundSunColor.z,0.85f);
As for 12... I think that's where the issue is. Here's the tree code:
Code: Select all
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,12, 0,0,0,0.20f*(1.0f/MAX_TREE_HEIGHT)); //w=alpha/height modifier
Whereas 12 gets used for something Entirely Else in UnitDrawer.cpp:
Code: Select all
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,12, unitAmbientColor.x,unitAmbientColor.y,unitAmbientColor.z,1);
Then there's this mystery:
Code: Select all
// When rendering shadows, we just want to take extraColor.alpha (tex2) into account,
// so textures with masked texels create correct shadows.
if (shadowHandler->inShadowPass)
{
// Instead of enabling GL_TEXTURE1_ARB i have modified CTextureHandler.SetS3oTexture()
// to set texture 0 if shadowHandler->inShadowPass is true.
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER, 0.5f);
glEnable(GL_ALPHA_TEST);
return;
}
And this, in the texture handler, a somewhat-anomalous thing:
Code: Select all
//if(unitDrawer->advShading)
{
CBitmap bm;
// No error checking here... other code relies on an empty texture
// being generated if it couldn't be loaded.
// Also many map features specify a tex2 but don't ship it with the map,
// so throwing here would cause maps to break.
if(!bm.Load(string("unittextures/"+tex2))) {
bm.Alloc(1,1);
bm.mem[3] = 255;//file not found, set alpha to white so unit is visible
}
tex.tex2 = bm.CreateTexture(true);
tex.tex2SizeX = bm.xsize;
tex.tex2SizeY = bm.ysize;
}
So... we know that tex2 is getting loaded, otherwise the existing fragment programs wouldn't work. Using the value of the tex2.w at a given position is trivial, so surely that's not what's wrong. Or at least, all that's wrong- I see no sign that tex2 is being used during the shadowmapping step on Units.
I am fairly certain that the step referring to ARB value 12 is key here. The vertex program for Units just refers back to the texture coordinate value, but doesn't use that value to alter the final result, like the tree version does.
Then we have this major difference:
Tree:
Code: Select all
glBindTexture(GL_TEXTURE_2D,shadowHandler->shadowTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_ALPHA);
Code: Select all
glBindTexture(GL_TEXTURE_2D,shadowHandler->shadowTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);