Game Development Community

Specular Masking?

by Helk · in Torque 3D Professional · 06/04/2009 (12:56 pm) · 16 replies

Hey, Been trying to add a mask to a material for specularity, is this not supported in T3D?

I tried using the alpha channel of my png (used superpng) and tried .dds as well but I can't see any change.. although painting on the RGB channel of the texture updates in the engine real time.


Can anyone point me in the right direction on what I'm doing wrong? Thanks.

#1
06/04/2009 (1:28 pm)
Looking at the shadergen code for deferred specular, I think the specular mask goes in the normal map alpha, not the diffuse map alpha. Haven't tested it myself.
#2
06/04/2009 (1:51 pm)
Works perfectly now, that was it. Thanks :)


img41.imageshack.us/my.php?image=specworkssmall.jpg
#3
06/04/2009 (8:34 pm)
Yea... we moved that to the normal map alpha channel as it allows you to mix translucent materials with specularity now.
#4
06/04/2009 (9:24 pm)
We ran into issues in TGEA where we wanted both translucency and a specular map but couldn't get the results we were looking for (in this particular case it was for some hair styles that also had metal hair decorations on them -- the hair was translucent near the edges, but we wanted the metal to be shiny).

This is a nice change.
#5
06/05/2009 (12:20 am)
Is there any reason to not have a dedicated specular map slot in the material editor?
#6
06/05/2009 (3:20 am)
@Diesel - If you want to bind and sample 3 textures when doing a diffuse+normalmap+specular instead of 2... yea you could.

If Torque had a content processor (something under consideration for future versions) it may be more feasable as we could juggle the textures and where data is stored at build time.
#7
06/05/2009 (5:45 am)
It could be made more flexible by simply adding a drop down for "alpha channel mask", where one could select "diffuse alpha", "normalmap alpha", "specular mask rgb", and maybe even "detail map alpha" for extra fanciness, and have the shader gen generate the appropriate sampling and modulation instructions.

There is one case where having a separate specular mask might be useful:
1) Material is translucent, so diffuse alpha is already is use;
2) The normal map is DXT5-bump compressed (so the alpha is being used by normal data).

@Tom: by content processor you mean re-building textures at build/load time (like taking a dedicated specular mask texture and sticking it into the normal map alpha), or you mean having the shadergen be able to manage from which sampler/channels each data comes from?
#8
06/05/2009 (2:24 pm)
@Manoel

Quote:It could be made more flexible by simply adding a drop down for "alpha channel mask"

I was avoiding doing something like that as it makes material creation as well as the shaders alot more complex.

Is there really a bad case here that requires we further complicate the system?

Quote:DXT5-bump compressed
You cannot mix per-pixel specular and DXT5 compression.

Since there is no way to know a file is DXT5nm compressed we assume any DXT5 compressed texture as a normal map is in the DXT5nm format.

If we don't have per-pixel specular then we decode a DXT5 normal map as though its encoded in DXT5nm.

If we have per-pixel specular... no decoding is done even if you've bounda DXT5 texture.

Its all complex... but it stems from no having a way to detect DXT5nm compression.

Quote:by content processor you mean re-building textures at build/load time

Yes... i mean rebuilding textures.

Most users don't know how to generate a DDS or what formats to use. And honestly i don't know if we really should make it obligatory for an artist to know what a DDS is at all.

Crytek uses a specialized TIFF exporter for 3DSMax which embeds special markup within it for the content processor to read. It can then repackage textures for PC one way and XBox or PS3 another.

Not saying we'll be using TIFFs, but i'm thinking in the future Torque should head that direction.
#9
06/10/2009 (11:39 am)
Can I use the alpha channel of the diffuse map for specular mapping if there is no normal map in the material? Having to make a dummy normal map if there isn't one just to get specular mapping doesn't seem right to me. Maybe check for a normal map in the material, if none and the pixelSpecular value is on then look for a spec map in the diffuse texture?
#10
06/11/2009 (11:22 am)
when I try to save a DDS out of photoshop with a alpha channel it says: "too many channels 5"
#11
06/11/2009 (12:27 pm)
@Tom, I used something similar, but much more crude, in a DS project I worked a while ago. Artists saved everything in 32-bit PNG files, and the folder were a PNG was saved determined which format it was going to be converted to during build (we wanted a metadata tool... but time didn't allow for that). That way we didn't need to teach them how to use the converters and having them spend time palettizing their textures.

I know how complicated that can be. Oh well, I know if I really need specular+DXt5, its only a few lines here and there on the shadergen and materials, but yeah, for the "casual" Torque user DXT5n is quite a complicated beast. Maybe a resource for those who really want it should suffice.

@Andreas, that should be pretty easy to do by adding a couple lines of code to the shadergen, I think.

@James: Photoshop is terrible at handling alpha channels. When exporting a DDS, it exports your layer's composite transparency as alpha channel, not an explicit channel you create. The best way to have an independent "channel" you can edit later (since not even CS4 allows you to edit a layer's transparency independently of its color) is by grouping everything and giving the group a transparency mask.
#12
06/11/2009 (8:33 pm)
I have an old copy of Photoshop 6 with the SuperPNG plugin... IMO it was the last time PS did alpha well.
#13
06/11/2009 (8:41 pm)
Ahh no, Manoel actually specular + DXT5 is not a good idea. The DXT5 format is 5:6:5:8, compressed in blocks of 4. For DXTnm compression, the Red and Blue channels are set to 1, Y is stored in green, and X is stored in Alpha. The reason that Red and Blue are set to 1 is to increase the accuracy of the block compression. The quality would actually degrade significantly if you were to store 3 channels of normal information (rgb/xyz) + specular (alpha) the way a PNG formatted normal+specular mask texture would work.

Maybe I can take a look at providing a source for specular beyond assuming it's in the alpha channel of the normal map.
#14
06/11/2009 (9:08 pm)
@Pat - Actually the best thing we could do would be to be able to detect a DXT5nm normal map vs. regular DXT.

Last i checked there is nothing within the DXT format itself that defines this. I wonder if we just check to see if the red and blue channels are all set to 1... it might be better than assuming like we do now.
#15
06/12/2009 (6:50 am)
@Pat: I mean having the specular mask stored in the diffuse map alpha for DTX5n. I'm fully aware of the way DTX5n works, since a "certain TGEA 1.4 demo" I worked on used a lot of DXT5n. Back then I just added a flag called "compressed bump" to the Material class, and a CompressedBump material feature. If present the feature would cause the shaderGen to generate a different normal map decoding instruction.

And are you sure Red and Blue are set to 1? I just checked and the NVidia Photoshop plugin repeats the Y in the Red, Green and Blue channels. Auto-detecting a DXTn might be possible, but not trivial enough to be done in load time, I think. Maybe it could be done when using the material editor or loading a .DAE that is not cached/must be updated.

..or just add a checkbox to the Material ;)
#16
06/12/2009 (5:44 pm)
As much as i hate the idea of a checkbox for DXT5nm... it seems like the only good option.