I've made a test program that works for both a shader with transparency, and for regular textured objects! It sorts by texture number, and you can even mix and match shader and no shader objects!
It seems all is required is transparency mode 1.
Here's my test program:
Rem Project: shader render order test
Rem Created: 08/01/2011 04:06:29
Rem ***** Main Source File *****
sync on
sync rate 0
autocam off
`want to get 2 rendered over 1 regardless of distance between them
`load image "sports.png",1
`load image "toys.png",2
_make_test_image(1, 0x80FF0000)
_make_test_image(2, 0x8000FF00)
`make 2 test plains
make object plain 1,10,10:texture object 1,1
make object plain 2,10,10:texture object 2,2
`need transparency shader.
load effect "transp_shader.fx",1,0
set object effect 1,1 `still works without shader applied! try it!
set object effect 2,1 `also works if mix and match shader/ no shader!
`with transparency mode 0 - no transparency seen, even when using shader. sorts by tex number.
`with mode 1, seems to sort by tex number, with transparency.
`with modes 2,3, seems to sort by distance.
tmode=1
set object transparency 1,tmode
set object transparency 2,tmode
disable object zwrite 1 `only need this if rendering stuff in front before stuff at back.
disable object zwrite 2 `however still might be worth keeping anyway, because not writing to zbuffer may be faster.
do
if spacekey() `hold space to make 2 closer than 1
position object 1, 2,2, 20
position object 2, -2,-2, 15
else
position object 1, 2,2, 15
position object 2, -2,-2, 20
endif
sync:loop:end
function _make_test_image(im, col as dword)
make memblock 1,12+4*(64*64)
write memblock dword 1,0,64 `width
write memblock dword 1,4,64 `height
write memblock dword 1,8,32 `depth
mbpos=12
for n=0 to 63:nsq=(n-32)*(n-32)
for m=0 to 63:msq=(m-32)*(m-32)
if nsq+msq < 1000
write memblock dword 1,mbpos,col
else
write memblock dword 1,mbpos,0
endif
inc mbpos,4
next m
next n
make image from memblock im,1
delete memblock 1
endfunction
Here's the shader, although you can just comment out the shader bits in the above and that will work OK anyway!
// The following lines are variables which are recognised and passed by the
// application and often referred to as "untweaks".
matrix wvp : WorldViewProjection;
//matrix WorldViewProj : WorldViewProjection;
matrix World : World;
matrix ViewInv : ViewInverse;
float3x3 rotmatrix : World; // hopefully can get 3x3 rot matrix? - HELL YES YOU CAN
// The following lines are variables which can be set by the application
// (these are usually variables which the user may want to adjust from
// their program).
// The following lines define structures that are used as input and output
// to the vertex and pixel shader functions.
struct VSInput {
float4 Pos : Position;
//float3 Norm : Normal;
float2 Tex : TEXCOORD0;
};
struct VSOutput {
float4 Pos : Position;
float2 Tex : TEXCOORD0;
//float3 Norm : Texcoord1;
};
// The pixel shader does not need an input structure for this example.
struct PSOutput { float4 Col : Color; };
// texture stuff
texture Tex0 <
string texturetype = "2D" ;
string name = "";
>;
sampler Sampler = sampler_state
{
Texture = (Tex0);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
// The vertex shader code:
VSOutput VShader (VSInput In, VSOutput Out)
{ // Transforms the objects model coordinates to
// screen space coordinates
Out.Pos = mul(In.Pos, wvp);
//Out.Norm=mul(In.Norm,rotmatrix); //don't need this
Out.Tex=In.Tex;
return Out;
};
// The pixel shader code:
PSOutput PShader (VSOutput In,PSOutput Out)
{ Out.Col=tex2D(Sampler, In.Tex); //base texture.
//Out.Col.a=0.5; //test
return Out;
};
// The following lines just put this together as a single technique
// with a single pass.
technique simplyOneColour
{
pass p1
{
VertexShader = compile vs_1_1 VShader();
PixelShader = compile ps_2_0 PShader();
}
}
It doesn't work with DBP ghosted objects. Going to try and write a shader for that. Alternatively, I think one transparency mode works over everything, and I only want one object in front of my ghost stuff, so maybe I'll go with that.
BTW I also noticed there's a "nosort" flag in texture object, but haven't played with that.