XNA hlsl tex2D() only reads 3 channels from normal maps and specular maps
Posted
by
cubrman
on Game Development
See other posts from Game Development
or by cubrman
Published on 2013-08-23T06:07:00Z
Indexed on
2013/10/29
16:15 UTC
Read the original article
Hit count: 287
Our engine uses deferred rendering and at the main draw phase gathers plenty of data from the objects it draws.
In order to save on tex2D calls, we packed our objects' specular maps with all sorts of data, so three out of four channels are already taken. To make it clear: I am talking about the assets that come with the models and are stored in their material's Specular Level channel, not about the RenderTarget. So now I need another information to be stored in the alpha channel, but I cannot make the shader to read it properly! Nomatter what I write into alpha it ends up being 1 (255)! I tried:
saving the textures in PNG/TGA formats.
turning off pre-computed alpha in model's properties.
Out of every texture available to me (we use Diffuse map, Normal Map and Specular Map) I was only able to read alpha successfully from the Diffuse Map!
Here is how I add specular and normal maps to my model's material in the content processor:
if (geometry.Material.Textures.ContainsKey(normalMapKey))
{
ExternalReference<TextureContent> texRef = geometry.Material.Textures[normalMapKey];
geometry.Material.Textures.Remove("NormalMap");
geometry.Material.Textures.Add("NormalMap", texRef);
}
...
foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture
in material.Textures)
{
if ((texture.Key == "Texture") ||
(texture.Key == "NormalMap") ||
(texture.Key == "SpecularMap"))
mat.Textures.Add(texture.Key, texture.Value);
}
In the shader I obviously use:
float4 data = tex2D(specularMapSampler, TexCoords);
so data.a
is always 1 in my case, could you suggest a reason?
© Game Development or respective owner