Pocketmnky

Something strange is happening in my ConvertMaterial override. Here's my build process in pseudo code:

  1. I place the normal texture in the same directory as the diffuse texture with a simliar naming convention (eg. diffuse=BumpWall01_rgb.png normal=BumpWall01_nrm.tga)
  2. My ConvertMaterial override scans the directory of each diffuse texture it converts to find whether it has a normal file.
  3. If one is found, I create ExternalReference <TextureContent> objects for the diffuse texture, and normal texture.
  4. I Add my ExternalReference <TextureContent> normalTexture to my MaterialContent.Textures Dictionary.
  5. I create a new EffectMaterialContent object "normalMaterial" for output.
  6. I create an ExternalReference<EffectContent> "normalEffect" of my existing normal.fx hlsl file.
  7. I build the normalEffect reference into a ExternalReference<CompiledEffect> using context.BuildAsset<> with the "EffectProcessor"
  8. I pack the normalEffect into normalMaterial.Effect, and compiledNormalEffect into normalMaterial.CompiledEffect.

    So far as I can tell, this all works fine.

  9. now I pack all of the relavent data from the input material (including the two textures) into my output normalMaterial such as difffuseColor, EmiisiveColor, etc.

  10. finally I chain down to base.ConvertMaterial((MaterialContent)normalMaterial, context); to build my ExternalReference<TextureContent>'s into their built versions and return normalMaterial.

The problem is this: After all of that is done, the .xnb file representing my normalTexture is there in /bin/x86/debug/ etc, but it is full of zero values. Or at the very least it is full of the same value and when I go to render the texture, it's all black.

What would cause that to happen is it because I'm using context.BuildAsset but not storing the result the way base.ConvertMaterial would




Re: XNA Framework TextureImporter returning a Zero'd texture

Shawn Hargreaves - MSFT

Your process seems reasonable.

What format is your normalTexture building as What kind of data does it originally contain Have you tried just rendering it directly as RGB values rather than using it as a normalmap





Re: XNA Framework TextureImporter returning a Zero'd texture

Pocketmnky

Yeah that's how I guessed it was returning all black; I had my fx file return tex2D(NormalSampler, IN.texCoord1) and I got nothing so I checked the xnb file in notepad and saw the problem.

Originally the file was a .TGA file, I'm pretty sure it was RGBA 8-bit, but I don't have any DXTools here to check it (just photoshop). it was 1024x1024 so it came out to a .TGA 4MB file.

I just confirmed that it's something with the .TGA importer by converting the orginals to .PNG and running the same process at it all worked fine.

Another question; similar vein: My normal maps are looking like they're being mipmapped down pretty fiecely, or maybe it's just the compression. At any rate, I'm seeing alot less detail than I would have thought a 1024x1024 texture would render. I have my mipfilter=LINEAR, and my min and magfilter=ANISOTROPIC but I'm not sure what miplevel is being used at what time, or even if the importer is keeping my 1024x1024 as the top level. Is there somewhere that I can specify or check that






Re: XNA Framework TextureImporter returning a Zero'd texture

Shawn Hargreaves - MSFT

Interesting - could you send me the TGA file that was going wrong, so we can look into this Easiest way to do that is open a connect bug, attach the file (you can set it to be private if you don't want other people to have access) and paste in the above description of your problem

Regarding the compression, that sounds like DXT artifacts, which will make a real mess of normalmap data. Running your texture through the "TextureProcessor" (not the default "ModelTextureProcessor" will keep it in a straight 32 bit format, or for even better results, you might want to write a custom processor to use one of the signed normalmap texture formats.





Re: XNA Framework TextureImporter returning a Zero'd texture

needforhint

I have the same problem as you describe. I am rendering through a fx. file which contains my v and p shaders.

From some reason, with having correctly sat al the uniform variables and input streams, I get a black model, obviously my tex2d()function on my bump map fails (have not debugged it but I now it from experimenting with color outputs from pixel shader, which were fine, I also dont get anny compile shader errors). So the technique settings are bad see the technique 4 your self, it is simple, no variations I found works:

technique textureTechnique
{
pass p0
{

// Set up texture stage 0


// Use the texture parameter defined above
Texture[0] = <tex0>;
ColorOp[0] = Modulate;// also used Dot3 as well here
ColorArg1[0] = Texture;
ColorArg2[0] = Diffuse;
AlphaOp[0] = Modulate;
AlphaArg1[0] = Texture;
AlphaArg2[0] = Diffuse;
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MipFilter[0] = Linear;

// Disable texture stage 1
ColorOp[1] = Disable;
AlphaOp[1] = Disable;

VertexShader = compile vs_2_0 mainV();
PixelShader = compile ps_2_0 mainP();
}
}

................

hm, I also declare the texture in front of my vertex shader uniforms "texture tex0;"

and I set it successfully with my effet pointer (I hope) in my exe source

so why tex2D(tex, Tex) ; with correct coordinates (I have them) and a texture resource (.bmp biased normal map) fails






Re: XNA Framework TextureImporter returning a Zero'd texture

Shawn Hargreaves - MSFT

Assuming your game is for Windows, try capturing a frame using PIX, then debugging into one of the meshes that is rendering wrong. You can choose to debug a single pixel, examine exactly what was in the textures set on the device at this point, and see exactly what values the pixel shader looked up at every instruction. At least that will narrow down whether the shader is going wrong, or if the texture is somehow containing the wrong data, or maybe if the wrong texture is set entirely.