Home Technical Talk

spec map mask in alpha channel??

polycounter lvl 13
Offline / Send Message
breakneck polycounter lvl 13
i have seen this being used where the alpha channel of the diffuse is being used for the specular map.
Is this really as simple as making your diffuse black and white, doing a color range select then copying that into the alpha channel?? or is there another way to do this?

Replies

  • Ott
    Offline / Send Message
    Ott polycounter lvl 13
    The short answer is that yes, you can do this, but you also have to look at the expense of using an Alpha channel on your texture map as opposed to simply using a smaller, second texture map where you can use all 3 channels....the R,G,B.

    For example, you could dedicate your R to be your spec, G to be your emissive stuff, and B to indicate where you want to have a detail normal or not...etc.

    It also depends on your surfaces and whether or not a pure black and white will give you a decent spec result. In some surfaces it could, but on some you might need color. (Skin, copper, bronze, etc.)
  • Ryno
    Offline / Send Message
    Ryno polycounter lvl 18
    With alpha channel can require more expensive compression. Channel textures as Ott mentioned are an alternative.
  • EarthQuake
    One thing to note, at least in my experince when dealing with compression is that Diffuse + alpha = the same amount of texture memory compressed as diffuse, and full color spec compressed. The reason for this is that a standard 24 bit image will take 1/4th the amount of memory compressed, but a 32 bit image with alpha will take 1/2 the amount, which is equal to a 2nd full color image. So while this may make your shader a very small amount faster, you're losing quality by needing to have a greyscale spec, and not actually saving any memory if you're compressing your textures(as most every game does).

    So say you have a 1mb texture.
    Compressed this is 256kb
    Compressed with alpha this is 512kb

    Now say you have 1mb textures(diffuse and color spec)
    Compressed your diffuse will be 256kb
    Compressed your specular will be 256kb
    Total texture usage = 512kb

    And yeah, as Ott says, having seperate images gives you more flexability, some types of materials need less resolution for the spec, or less for the diffuse. If both are packed together it makes it harder to optimize.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    You would never want to use a greyscale version of your diffuse map as a specular map.
    You should always make a proper texture rather than just copying the diffuse map, regardless of whether it's going to be greyscale in the alpha channel or full colour on its own.
  • breakneck
    Offline / Send Message
    breakneck polycounter lvl 13
    also if i use the alpha for a texture, i lose the option to have transparency correct?
  • thomasp
    Offline / Send Message
    thomasp hero character
    that totally depends on what your target tech does with the alpha channel, you could store whatever in it and just put the alpha on another channel of one of the texture maps associated with your shader.
  • Mark Dygert
    Transparency is pretty engine specific. You can normally plug in a separate image or use the alpha. As EQ pointed out there could be pros and cons to doing either but it can be done with most tech.
  • breakneck
    Offline / Send Message
    breakneck polycounter lvl 13
    cool, thanks for the ideas!
  • Rob Galanakis
    EarthQuake wrote: »
    So say you have a 1mb texture.
    Compressed this is 256kb
    Compressed with alpha this is 512kb

    Now say you have 1mb textures(diffuse and color spec)
    Compressed your diffuse will be 256kb
    Compressed your specular will be 256kb
    Total texture usage = 512kb

    Correct, but it is also an extra texture sampler in the pixel shader.

    The issue of where to store what is completely driven by your needs- first come up with what you want the result to be, then figure out how to do it (including what maps are needed), then and only then figure out the best way to store textures. Not saying anyone is arguing against this, just worth pointing out. There are definite pros and cons of all these approaches and they are both equally valid (I don't usually say that about stuff), your needs will determine which to use.

    These are pretty technical things... to be safe, just use whatever is easiest for you (usually storing everything seperately) and focus on making the prettiest things, since you won't get much out of the nitty gritty aspects of this performance.
  • glib
    EarthQuake wrote: »
    One thing to note, at least in my experince when dealing with compression is that Diffuse + alpha = the same amount of texture memory compressed as diffuse, and full color spec compressed. The reason for this is that a standard 24 bit image will take 1/4th the amount of memory compressed, but a 32 bit image with alpha will take 1/2 the amount, which is equal to a 2nd full color image. So while this may make your shader a very small amount faster, you're losing quality by needing to have a greyscale spec, and not actually saving any memory if you're compressing your textures(as most every game does).

    So say you have a 1mb texture.
    Compressed this is 256kb
    Compressed with alpha this is 512kb

    Now say you have 1mb textures(diffuse and color spec)
    Compressed your diffuse will be 256kb
    Compressed your specular will be 256kb
    Total texture usage = 512kb

    And yeah, as Ott says, having seperate images gives you more flexability, some types of materials need less resolution for the spec, or less for the diffuse. If both are packed together it makes it harder to optimize.
    This is true if you're using an 8-bit alpha, but if you can somehow find a situation where a 1-bit alpha will work (which granted is almost never useful for a spec map, but would be useful for a glowmap or color variation mask or something of that sort) and you're using dds files, the alpha is essentially free after compression.

    I'm not 100% sure on how the compression works, but I believe it's something along the lines of sliding any pure black in the R,G,B to slightly grey (ie. 1% brightness) then multiplying the alpha into the R,G,B channels and treating anything in the resulting image that's pure black as one value while every other luminosity is treated as the other value which gives you your 1-bit image.

    In this case, you can have a 256kb texture WITH 1-bit alpha, and just saved 256kb. Again though, it's pretty useless for spec maps unless you can think of a situation where you want something fully specular and something completely unspecular on the same texture sheet.
  • Mark Dygert
    I don't think you can mix and match the bits-per-channel on an image? Maybe you can... on some kind of weird custom format.

    It seem more likely a 1 bit alpha on an 8 bit-per-channel image would still be 8 bits, but you're only using a tiny part of it? Kind of like having a 8 gallon gas tank with only 1 gallon in it? The only bonus I can think of in treating it that way would be compression... But then if you have 8 bits per pixel why not use them? I doubt the compression savings would be worth handicapping your artists.

    As for the 1 bit it would probably have to be in a separate 1bit texture, I could see that being most useful on transparencies that would be run through alpha-test, where each pixel is either on or off but then its a separate texture as Rob pointed out.

    I could be way off, this is just what I remember about images and bits...
  • Rick Stirling
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    I prefer two maps, using the alpha channel of the spec map as a specular falloff map.
  • ElysiumGX
    Offline / Send Message
    ElysiumGX polycounter lvl 18
    breakneck wrote: »
    also if i use the alpha for a texture, i lose the option to have transparency correct?

    As mentioned already, it depends on the Tech. For instance, in the Source engine, it's possible to use the alpha channel of the diffuse map for transparency, and the alpha channel of the normal map for specular.
  • breakneck
    Offline / Send Message
    breakneck polycounter lvl 13
    interesting info, never thought about using the alpha channel in the normal map.
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    Vig wrote: »
    I don't think you can mix and match the bits-per-channel on an image? Maybe you can... on some kind of weird custom format.


    The DXT1 format allows for an optional alpha which is 1bit. This is smaller in memory than having a DXT5 texture.

    I use the 3 channels thing all the time. It's much more important to save memory than to worry about the extra texture sample in my experience. I usually colour the specular using expressions inside the shader. Of course this isn't suited to some sitations or objects.
  • glib
    Vig wrote: »
    I don't think you can mix and match the bits-per-channel on an image? Maybe you can... on some kind of weird custom format.
    You're not really mixing bit-depths here. What it's doing is when you save an image with an alpha with DXT1 compression (thanks sprunghunt for the name, I'd forgotten) it multiplies your alpha into your RGB. Still three 8-bit channels, but containing four channels of information (three 8-bit and one 1-bit).
  • Mark Dygert
    The DXT1 format allows for an optional alpha which is 1bit. This is smaller in memory than having a DXT5 texture.
    Thanks for the info, I haven't used DXT1 before, other then a few tests, its color loss was astounding.

    I read up on how it works and from what I read, it looses 4 colors from the pallet if you add an alpha, 3 of them are just wasted, 1 is used for trans.
    I'm also not sure but I think it drops the 8bits down to 4bits per channel, ouch.

    Sounds like it works, but would only be used in very specific monochromatic cases, and the alpha would be used for alpha test transparency only?
    Hanging wires, plants, a poster and maybe garbage.

    It reads more like a rare case exception for really low end hardware, not really something I would want to use on characters, well maybe hair transparencies... maybe...
  • glib
    Vig wrote: »
    Sounds like it works, but would only be used in very specific monochromatic cases, and the alpha would be used for alpha test transparency only?
    Hanging wires, plants, a poster and maybe garbage.

    It reads more like a rare case exception for really low end hardware, not really something I would want to use on characters, well maybe hair transparencies... maybe...
    Pretty much those cases yes. However not necessarily just for low-end hardware, we were using it for a current-gen open-world game relatively recently.
  • Rob Galanakis
    There's also some good info on the TAO wiki- if anyone finds an inaccuracy, please fix or tell me:
    http://tech-artists.org/wiki/DirectDraw_Surface
    http://tech-artists.org/wiki/Normal_map_compression
  • Justin Meisse
    Offline / Send Message
    Justin Meisse polycounter lvl 19
    Tossing this out there > specular maps half the dimensions of the diffuse
  • Eric Chadwick
    if anyone finds an inaccuracy, please fix or tell me

    DXT compression analyzes the image in 2x2 pixel blocks, and creates a gradient and lookup table for each.


    All DXT algorithms are supposed to compress textures with the same algorithm for the color component,

    Both incorrect. It's in 4x4 blocks (16 pixels). DXT only stores two colors per block and interpolates the others, using 2 intermediate colors for DXT1, and either 4 or 6 (can't recall) for DXT2/3/4/5.

    Edit... made a quick edit of the page. Super busy, working the weekend in fact, but hope to add more later.
  • EarthQuake
    Tossing this out there > specular maps half the dimensions of the diffuse

    This is very poor general advice, and varies wildly on the material type and content of the textures(some textures can be resized easier without noticing a quality loss). After doing a texture optimization pass on basically every texture in a game, i can tell you that sometimes you will want to resize the diffuse, sometimes the spec, and sometimes the normal. A good example of a case where you would want to resize the diffuse before the spec is pretty much any type of metal texture, like a gun, where the diffuse is pretty simple and the specular really has most of the detail.
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    EarthQuake wrote: »
    This is very poor general advice, and varies wildly on the material type and content of the textures(some textures can be resized easier without noticing a quality loss). After doing a texture optimization pass on basically every texture in a game, i can tell you that sometimes you will want to resize the diffuse, sometimes the spec, and sometimes the normal. A good example of a case where you would want to resize the diffuse before the spec is pretty much any type of metal texture, like a gun, where the diffuse is pretty simple and the specular really has most of the detail.


    This is good advice.
    For some materials I will delete the diffuse texture altogether and just have spec+normal - especially if you have a very dark diffuse map.
  • breakneck
    Offline / Send Message
    breakneck polycounter lvl 13
    Ok, still going on this: say i "need" to put the spec in the alpha as a specular mask (*cough, cough, art test** cough**), whats the best way to do this??
    also i am doing the modeling in Maya. Will the color map with the spec in the alpha even work? or do i have to do some crazy shit in Hypershade??
    thanks for the help!!
  • Rick Stirling
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    No, you can't have a coloured spec if you need to store it in the alpha.

    Paint the grayscale spec map, get it looking right, then just create an alpha channel for the diffuse and paste the spec map in.
  • breakneck
    Offline / Send Message
    breakneck polycounter lvl 13
    Rick: cool thanks, Is this map something that is functional in my 3d modeling application for a render(i.e. Maya or Max), or is it only going to work in the engine i export my assets to?
  • Rick Stirling
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    Short answer: engine only.

    It's a shader thing, so I wouldn't expect any standard 3d package shaders to support it. We use the alpha in the diffuse in different ways, mostly for alpha but sometimes as a mask for a skin shader.
  • Mark Dygert
    In 3dsmax you can have any map use the alpha channel.

    In this case you would copy your diffuse to the spec slot, and Under Mono Channel Output, switch it from "RGB Intensity" to "Alpha".
    004.jpg
  • breakneck
    Offline / Send Message
    breakneck polycounter lvl 13
    Excellent! now if only my rendering skillz with max weren't total poo!! thanks for the help
  • glib
    Short answer: engine only.

    It's a shader thing, so I wouldn't expect any standard 3d package shaders to support it. We use the alpha in the diffuse in different ways, mostly for alpha but sometimes as a mask for a skin shader.
    Definitely not engine-only.

    breakneck: since you were asking about maya, yes it's possible to do in maya as well, drag in your texture and shift-right-click drag on your shader, connect the out-alpha to the spec. I can never remember, you may have to do the out-transparency to the spec, or perhaps connect the out alpha to each channel of the spec (R,G,B). Try it both ways if it won't let you connect the out alpha directly to the spec and see what works.

    That's also a pretty stupid requirement for an art test. They're making you spend time learning how to do technical stuff that is likely covered in their pipeline normally. It serves no purpose really, they should be more concerned with whether your spec map looks right than how you stored it.
  • Rick Stirling
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    I must have misunderstood the question. I took it as will this "single image as a diffuse work as a diffuse and spec map in my 3D package"? That's why I mentioned shaders. The engine the art test is for must have a shader that uses the diffuse alpha as a specular map.
  • glib
    Well you're right that it's a shader thing, but any standard 3d package should support it (at the very least, max, maya and xsi will do it).
  • EarthQuake
    MMmmm i dont know about that, i know in max's material system its easy to do, but i dont think i've ever come accross a .fx shader for max that lets you use specular from your diffuse alpha channel, i'm pretty sure you'de have to have something custom to accomplish this.
  • glib
    Ah my apologies, I was talking about a standard renderable shader in maya/max, not a cgfx one.

    Yes if you wanted a cgfx shader to do this, you would have to write one with that behavior.
  • vj_box
    as far i have seen,and i use,i put the spec map in the blue channel of the normal map,coz u can easily calculate blue channel,if u have red and green and the shader will do this.

    Vj
Sign In or Register to comment.