Change the body tofloat4 PS_light_SHADOW(...) : COLOR
{
return tex2D(g_texturemap_sampler, a_texcoord0);
}
float4 col = tex2D(g_texturemap_sampler, a_texcoord0);
return float4(col.rgb/col.a, col.a);
Change the body tofloat4 PS_light_SHADOW(...) : COLOR
{
return tex2D(g_texturemap_sampler, a_texcoord0);
}
I don't know if the alpha texture is pre-made or you made it your self. If you made it your self try saving the texture as grayscale and not RGB, if possible when you convert your image to grayscale one save it with DXT format that uses alpha channel, and than see what happens. Also if that doesn't help, then try to use that alpha texture (grayscale one) with one of the shaders from above to see if that fixes the problem, for you.
This looks like the classic problem of background colors getting blended into the edges of mipmaps. I spent a significant amount of time on this topic when it arose in my project. In short, what happens is that directx blends the background pixels at the edge of the visible part of the image into the edge pixels of the visible part of the image, resulting in a usually black or dark border around the visible part of the image. It appears to be a weakness or flaw in the mipmap generation algorithm in DirectX. Only pixels with alpha > threshold value should be blended. I'll dig up my notes and post the results. I tested just about every possible combo. point sampling removes the edges, but as i recall, the image disappears at certain viewing angles. this effect can be seen in some plants in Oblivion by Bethesda Softworks. I'll check my notes and post my findings. While my work is done in retained mode, not HLSL, you should be able to easily implement it in HLSL, perhaps with some help from folks here.
Norm Barrows
Rockland Software Productions
"Building PC games since 1988"
As eppo said, you can use PIX to capture a frame of your game while it's running, and then view the it's resources. That will let you see what your texture looks like after it's been loaded into the GPU.
God knows what D3DXCreateTextureFromFileEx does internally... From the looks of it, it is "pre-multiplying" your RGB values with your alpha values... which as Daaark said, is helpful if you want to use alpha blending, but isn't helpful if you just want to use alpha-testing.
You could try loading the TGA file yourself instead of using the D3DX helper library to do it...
http://nothings.org/stb_image.c
http://nehe.gamedev.net/tutorial/loading_compressed_and_uncompressed_tga's/22001/
QFT. Given the texture that we've seen (which does have correctly painted RGB channels extending outside the opaque portions), I strongly suspect D3DX is either explicitly pre-multiplying the alpha channel *or* the texture is ending up as DXT1 (BC1), which implicitly does the same thing.
From "Norm's DirectX Tips":
Do you render the alpha tested geometry before or after you render opaque geometry?
If you render it first, it'll still write the depth values for pixels with alpha < 1.0. The terrain would then fail the depth comparison for those pixels and your clearcolor would become visible.
This is only true for alpha blending. For alpha testing each pixel is either opaque or clipped. Of course its possible to enable both in which case your point is valid.Do you render the alpha tested geometry before or after you render opaque geometry?
If you render it first, it'll still write the depth values for pixels with alpha < 1.0. The terrain would then fail the depth comparison for those pixels and your clearcolor would become visible.
I am hard at work testing different approaches. I got drowned in suggestions here
My first attempt will be to write my own loader, so I can be sure D3DX is not messing with me.
I will get back with a full report when I come out of the pixel mines again
EDIT:
Actually Im gonna install PIX first, it looks like it can save me the trouble, if D3DX is actually doing its job properly.
Much easier than writing your own loader would be to just take a few minutes and take frame capture in PIX to see the exact pixel values of the source texture and make sure they're right.My first attempt will be to write my own loader, so I can be sure D3DX is not messing with me.