AHA!
I figured out how to make the shader draw itself correctly, as in behind all objects!
Updated Dynamic Cloud Shader:
//--------------------------------------------------------------//
// Vertex Shader
//--------------------------------------------------------------//
string XFile = "default.x";
texture sky < string name = "sky.tga"; >;
texture cloud < string name = "cloud.tga"; >;
matrix wvp : worldViewProjection;
float time : Time0_X;
VertexShader Atmospheric_Effects_CloudsEffect_ASM_Single_Pass_Vertex_Shader_ = asm
{
vs.1.1
dcl_position v0
dcl_normal v1
dcl_texcoord v2
def c9, 0.005f, 0.02f, -0.004f, 0.002f
def c10, 0.878f, 0.33f, 2.5f, 2.5f
def c11, 0.009f, -0.017f, -0.015f, 0.007f
def c12, 1.0f, 1.02f, 4.17f, 4.1f
m4x4 oPos, v0, c0
mov r4, v2 // output base tex coord
mov oT4, r4
mov r0, c7.xxxx // (time*cloud0vel)
mul r1, c9.xyxy, r0
mul r2, c9.zwzw, r0 // (time*cloud0disvel)
mad oT0, r4.yx, c10.xyxy, r1.xy
mad oT1, r4.yx, c10.zwzw, r2.xy
mul r1, c11.xyxy, r0 // (time*cloud1vel)
mul r2, c11.zwzw, r0 // (time*cloud1disvel)
mad oT2, r4.yx, c12.xyxy, r1.xy
mad oT3, r4.yx, c12.zwzw, r2.xy
};
//--------------------------------------------------------------//
// Pixel Shader
//--------------------------------------------------------------//
PixelShader Atmospheric_Effects_CloudsEffect_ASM_Single_Pass_Pixel_Shader_ = asm
{
ps.1.4
def c0, 0.0f, 0.5f, 1.0f, 2.0f
def c1, -0.157f, 0.13f, 0.0f, 0.02f
def c2, 0.525f, 0.421f, 0.712f, 0.698f
def c3, 0.05f, -0.085f, 0.0f, 0.02f
def c4, 0.293f, 0.231f, 0.795f, 0.348f
def c5, 0.871f, 0.532f, 0.0863f, 0.77f
texld r0, t1
texld r1, t1
texcrd r2.rgb, t0
texcrd r3.rgb, t2
mad r0.rgb, c1, r0_bx2, r2 ; perturb base map coords by cloud coords
mad r1.rgb, c3, r1_bx2, r3 ; perturb base map coords by cloud coords
phase
texld r0, r0
texld r1, r1
texld r2, t4
mov_x2 r3.rgb, r2.a ; alpha of horizon (glow map)
+mul_sat r3.a, 1-r0.a, 1-r1.a ; mask edges for cloud glow
mad_sat r0.rgb, 1-r0.a, c2, c2.a ; scale and bias inverted clouds layer 0
+mov_x2_sat r0.a, r0.a ; boost cloud alpha 0
mad_sat r1.rgb, 1-r1.a, c4, c4.a ; scale and bias inverted clouds layer 1
+mov_x2_sat r1.a, r1.a ; boost cloud alpha 1
lrp r0.rgb, r1.a, r1, r0 ; combine cloud layers
+mov r4.a, c5.a ; ...
mul_x2 r3, r3.a, r3 ; multiply glow by edges of clouds
mad_x2 r3, r3, c5, r4.a ; scale and bias glowing sections of clouds
mul r0.rgb, r3, r0 ; multiply glow by combination of cloud layers
+add_d2_sat r0.a, r0.a, r1.a ; add alphas of cloud layers
lrp_sat r0, r0.a, r0, r2 ; lerp between clouds and horizon
};
//--------------------------------------------------------------//
// Technique Section for Atmospheric Effects
//--------------------------------------------------------------//
technique CloudsEffect_ASM
{
pass Single_Pass
{
VertexShaderConstant[0] = <wvp>;
VertexShaderConstant[7] = <time>;
Texture[0] = <cloud>;
Texture[1] = <cloud>;
Texture[2] = <sky>;
AddressU[2] = Wrap;
AddressV[2] = Wrap;
AddressU[1] = Wrap;
AddressV[1] = Wrap;
AddressU[0] = Wrap;
AddressV[0] = Wrap;
ZENABLE = TRUE;
FILLMODE = SOLID;
SHADEMODE = FLAT;
ZWRITEENABLE = FALSE;
ALPHATESTENABLE = FALSE;
LASTPIXEL = TRUE;
SRCBLEND = ONE;
DESTBLEND = ZERO;
CULLMODE = NONE;
ALPHAREF = 0x0;
ALPHAFUNC = LESS;
DITHERENABLE = FALSE;
ALPHABLENDENABLE = FALSE;
FOGENABLE = FALSE;
SPECULARENABLE = FALSE;
FOGCOLOR = 0xFFFFFFFF;
FOGTABLEMODE = NONE;
FOGSTART = 0.000000;
FOGEND = 0.000000;
FOGDENSITY = 5.000000;
STENCILENABLE = FALSE;
STENCILFAIL = KEEP;
STENCILZFAIL = KEEP;
STENCILPASS = KEEP;
STENCILFUNC = ALWAYS;
STENCILREF = 0x0;
STENCILMASK = 0xffffffff;
STENCILWRITEMASK = 0xffffffff;
TEXTUREFACTOR = 0x0;
CLIPPING = FALSE;
LIGHTING = FALSE;
AMBIENT = 0xffffffff;
FOGVERTEXMODE = NONE;
COLORVERTEX = TRUE;
LOCALVIEWER = TRUE;
NORMALIZENORMALS = FALSE;
DIFFUSEMATERIALSOURCE = COLOR1;
SPECULARMATERIALSOURCE = COLOR2;
AMBIENTMATERIALSOURCE = COLOR2;
EMISSIVEMATERIALSOURCE = COLOR2;
VERTEXBLEND = DISABLE;
CLIPPLANEENABLE = 0;
POINTSIZE = 0.000000;
POINTSIZE_MIN = 0.000000;
POINTSPRITEENABLE = FALSE;
POINTSCALEENABLE = FALSE;
POINTSCALE_A = 0.000000;
POINTSCALE_B = 0.000000;
POINTSCALE_C = 0.000000;
MULTISAMPLEANTIALIAS = TRUE;
MULTISAMPLEMASK = 0xffffffff;
COLORWRITEENABLE = RED | GREEN | BLUE | ALPHA;
TWEENFACTOR = 0.000000;
BLENDOP = ADD;
POSITIONDEGREE = CUBIC;
NORMALDEGREE = LINEAR;
VertexShader = (Atmospheric_Effects_CloudsEffect_ASM_Single_Pass_Vertex_Shader_);
PixelShader = (Atmospheric_Effects_CloudsEffect_ASM_Single_Pass_Pixel_Shader_);
}
}
I messed around with most of the variables with "Z" in their name, since obviously this is a ZBuffer issue. Turns out all you have to do is change
ZENABLE to
true, and
remove the line ZFUNC = ALWAYS;
Violin! It works.