Home Dota 2

How does dota2 engine interpret the $SPECULARCOLOR variable?

Ifurzzar
null
Offline / Send Message
Ifurzzar null
Hi everyone, could anyone help me clarify the mystery of how source engine convert the $SPECULARCOLOR parameter to rgb?
we know by default the base specular color is white, and the blue channel of mask2 (the specular tint mask) determines how much the texture contributes to the specular color.


but in the vmt file you can change the base specular color, like in ember spirit:
"CustomHero"
{
...
$SPECULARSCALE 1
$SPECULARCOLOR "[2.5 6.8 15.4]"

$RIMLIGHTSCALE 5
$RIMLIGHTCOLOR "[1 .2 0]"
...
}

and the ingame effect is like below:


CHDqf3s.jpg?1


you can see on this arm the specular light is an orange color instead of pure white.
here comes the problem: [2.5 6.8 15.4] is definitely not rgb, it exceeds the 0-1 range, but too small for the 0-256 range to be orange, then how does source engine interpret this to rgb color? I know many of you have been making items for dota2 for years, tweaking with vmt is definitely not new to you. pls help me out from this pain, it's actually decimating my brain cells.
Or, if in the most unfortunate case, you usually just ignore this parameter and leave it to default, do you know any way to ask a valve guy? their source engine documentation is years back, and astonishingly I totally can't find any info on the internet.
I sincerely hope experts like you guys can help clarify this question, since a solid understanding and control over the base specular color can definitely benefit this whole community.

sincere thanks to all!

Replies

  • pior
    Online / Send Message
    pior grand marshal polycounter
    Hello - I think you might want to contact the Marmoset Toolbag guys, as they ran into the same puzzle when writing their Dota2 shader.
  • ReMixx
    I handled it on the Hattery by normalizing the values to be between 0 and 1. Otherwise they supersaturate the specular color, essentially increasing the brightness in addition to adding color. It caused a weird "oil spill" looking effect on Ember Spirit when I used those default values.

    As far as I can tell, they're still 0-1 RGB values. Anything greater than one supersaturates that channel. Maybe someone else can provide actual knowledge, but that's my observation.
  • pior
    Online / Send Message
    pior grand marshal polycounter
    Also, if I am not mistaken : there are some weird things going on with the way the engine interprets values that are commented out, like reverting to a default value rather than using 0.0.0. But this might have been addressed since then, as the materials values of some heroes seem to be updated from time to time, and the more recent VMTs tend to use more conservative numbers than the older ones.
  • Hawt Koffee
    Offline / Send Message
    Hawt Koffee polycounter lvl 13
    I thought there were just custom cubemaps
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    I thought there were just custom cubemaps
    I have not yet got a chance to view the cube map's color, so maybe the orange is from cubemap. But still, I want to know how this parameter is used, or if it's used at all.
  • BlueFlytrap
    Offline / Send Message
    BlueFlytrap polycounter lvl 9
    Registered just to answer your question.


    $SPECULARCOLOR is a command that multiplies the rgb value of the specular highlight by the values you input. The default is not "[0 0 0]" but instead "[1 1 1]". Each value affects the colors red, green, and blue in that order.

    Since it acts as a multiplier "[5 5 5]" will create a significantly brighter highlight than just "[1 1 1]" would create.

    Basetint from mask2's blue channel will apply to whatever colour the specular is set to. 100% basetint will completely override any specularcolur value regardless of what it is (though full basetint can make highlights pretty dim).

    In the case of emberspirit his specular highlights are a saturated blue. The orange you see is a cubemap that is mapped to mask1's blue channel, the metallic mask. Mask2's blue channel will tint cubemaps but $SPECULARCOLOR doesn't have any effect on them.
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    Registered just to answer your question.


    $SPECULARCOLOR is a command that multiplies the rgb value of the specular highlight by the values you input. The default is not "[0 0 0]" but instead "[1 1 1]". Each value affects the colors red, green, and blue in that order.

    Since it acts as a multiplier "[5 5 5]" will create a significantly brighter highlight than just "[1 1 1]" would create.

    Basetint from mask2's blue channel will apply to whatever colour the specular is set to. 100% basetint will completely override any specularcolur value regardless of what it is (though full basetint can make highlights pretty dim).

    In the case of emberspirit his specular highlights are a saturated blue. The orange you see is a cubemap that is mapped to mask1's blue channel, the metallic mask. Mask2's blue channel will tint cubemaps but $SPECULARCOLOR doesn't have any effect on them.


    Thanks a lot BlueFlytrap. I see the cubmap in vmt:
    $ENVMAP "models/cubemaps/glossy_orange"

    But now I am mroe confused. In the official doc it says: 'The Metalness Mask reduces and darkens the color and rimlight in order to simulate a real work metal look', so in my blender cycles material setting I use an RGB curve to dark the color texture, then use mask 1 blue channel (the metallic mask) to map the darkened color on the original color, then apply the specular tint mask to map #SPECULARCOLOR to the combined color texture, then feed the resulting color to a specular(glossy) shader. But you say it works with cubemap, I can't imagine how that goes, can you give more details? like:

    1> how does metallic mask work if there is no cubemap specified in .vmt?
    2> does metallic mask map cubemap to the color texture like the way I described?


    your help is very much appreciated, sincere thanks!
  • BlueFlytrap
    Offline / Send Message
    BlueFlytrap polycounter lvl 9
    I'll first explain how the metallic mask works before explaining how cubemaps interact with it.


    The metallic mask will simply darken the diffuse where it is applied. How much the diffuse is darkened depends on how white the metallic mask is for that texel. The intensity of this effect gradually ramps up the closer to white the mask is. A pure white metallic mask will turn the diffuse pure black so try to avoid that.
    If you would like to get an accurate preview of how the metallic mask will affect your diffuse just place it above your diffuse in an image editor, invert it, and then set it to multiply at an opacity around 40%.

    The metallic mask will only darken the diffuse (and some rimlight though it's barely noticeable) and will pretty much negate frensel values. It will not darken cubemaps, details, selfilluminated areas, specular, or specular basetint.

    That last one is the important one. Highlights tinted by the diffuse are tinted by the original diffuse and not the darkened diffuse. They completely ignore any effect the metallic mask had. This is how you achieve a metallic effect ingame. A good example of this is the gold on naga siren's default armour.
    Keep in mind there has to be at least some basetint present else the highlight will remain it's initial white colour.


    Now cubemaps in dota2 are very restricted. All of them are premade save for the one's used on Axe's default axe. That one in particular samples cubemaps from the map itself. Like specular, cubemaps are affected by the basetint mask and will tint to the diffuse colour. Also like specular, they ignore the effects of the metallic mask when doing so.

    By default the cubemap is masked to the specular mask. However, in the case of ember spirit and a handful of others, the cubemap can also be masked to the metallic mask by having $MASKENVBYMETALNESS 1 in the vmt. This is the only way cubemaps interact with the metallic mask.


    Aside from that the two don't interact.
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    I'll first explain how the metallic mask works before explaining how cubemaps interact with it.


    The metallic mask will simply darken the diffuse where it is applied. How much the diffuse is darkened depends on how white the metallic mask is for that texel. The intensity of this effect gradually ramps up the closer to white the mask is. A pure white metallic mask will turn the diffuse pure black so try to avoid that.
    If you would like to get an accurate preview of how the metallic mask will affect your diffuse just place it above your diffuse in an image editor, invert it, and then set it to multiply at an opacity around 40%.

    The metallic mask will only darken the diffuse (and some rimlight though it's barely noticeable) and will pretty much negate frensel values. It will not darken cubemaps, details, selfilluminated areas, specular, or specular basetint.

    That last one is the important one. Highlights tinted by the diffuse are tinted by the original diffuse and not the darkened diffuse. They completely ignore any effect the metallic mask had. This is how you achieve a metallic effect ingame. A good example of this is the gold on naga siren's default armour.
    Keep in mind there has to be at least some basetint present else the highlight will remain it's initial white colour.


    Now cubemaps in dota2 are very restricted. All of them are premade save for the one's used on Axe's default axe. That one in particular samples cubemaps from the map itself. Like specular, cubemaps are affected by the basetint mask and will tint to the diffuse colour. Also like specular, they ignore the effects of the metallic mask when doing so.

    By default the cubemap is masked to the specular mask. However, in the case of ember spirit and a handful of others, the cubemap can also be masked to the metallic mask by having $MASKENVBYMETALNESS 1 in the vmt. This is the only way cubemaps interact with the metallic mask.


    Aside from that the two don't interact.

    I know very few about gaming rendering techniques, so took some time reading valve's doc. It seems to me a way to fake environment reflection on an object, since it's a simulation of the real physical reflection, does it mean I can't put it to use in blender cycles, which uses ray tracing? or should I apply cubemap to the color texture and use the combined color map to a glossy shader? or apply it to an emission shader to hang it over the character as a light source?

    Oh, also, if no cubemap is specified in an item's vmt, what happens? does it default to white or black? or doing something else?
  • BlueFlytrap
    Offline / Send Message
    BlueFlytrap polycounter lvl 9
    I can't answer your question regarding blender since I don't know enough about how blender handles reflections. I can only answer your second question.

    Parameters are options. Only a handful are really needed.
    If no cubemap is specified there's no cubemap. That's it.

    Like so. Cubemap is applied to the right but disabled on the left.


    nyx000000_by_blueflytrap998-d8m0lnf.jpg
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    I can't answer your question regarding blender since I don't know enough about how blender handles reflections. I can only answer your second question.

    Parameters are options. Only a handful are really needed.
    If no cubemap is specified there's no cubemap. That's it.

    Like so. Cubemap is applied to the right but disabled on the left.


    nyx000000_by_blueflytrap998-d8m0lnf.jpg

    Thanks for the example, BlueFlytrap! I think I probably will leave out cubemap in blender, better not to use a thing I don't fully understand. But your explaination about other maps are pretty helpful, they do notablly improve the render result, I am so lucky this thread can attract the the attention of an awesome expert like you, many many thanks! I will post the final result in this thread after tweaking the material more.
    ps: how I wish valve can at least double the textures resolution (I know you can download the original stuff for basic model from the official site, but not workshop items, now I just extracted them from game archive), the low quality of the normal map results conspicuous bands on the object, which is definitely a killing blow to scorpio like me :(
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    Got one other question, see the specular color on the shoulder piece:
    ycbsNH3.png
    the shoulder's vmt does not specify the specular color, a normal thinking is it defaults to [1, 1, 1], but in the picture you can see it's a blue tint, which is very similar to the specular value of the main body: [2.5 6.8 15.4]

    So here comes the question, if not specified in its vmt, the individual piece's specular color defaults to white or the color specified in the main body's vmt? and how about rim light color?
  • BlueFlytrap
    Offline / Send Message
    BlueFlytrap polycounter lvl 9
    Ember Spirit's default items aren't set to highlight blue. All of his other cosmetics are though.

    That blue would be the result of one of two things. The first of which being the map lighting should you be previewing while a map is loaded. All maps in dota2 are lit with a sort of blueish light. The second being the modelcombiner applying the parameters of Ember Spirit's basemodel to his cosmetics. You could disable the modelcombiner to see if it still occurs.


    Either way any cosmetics you run through the importer for ember spirit will end up with that blue tint regardless. Valve doesn't seem too fond of custom parameters from community members so you're stuck with what they give you.
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    Ember Spirit's default items aren't set to highlight blue. All of his other cosmetics are though.

    That blue would be the result of one of two things. The first of which being the map lighting should you be previewing while a map is loaded. All maps in dota2 are lit with a sort of blueish light. The second being the modelcombiner applying the parameters of Ember Spirit's basemodel to his cosmetics. You could disable the modelcombiner to see if it still occurs.


    Either way any cosmetics you run through the importer for ember spirit will end up with that blue tint regardless. Valve doesn't seem too fond of custom parameters from community members so you're stuck with what they give you.

    Interesting, I don't make cosmetics so I did not know the vmt is generated by the importer, it's sad, I believe it'd be more fun if cosmetics authors can customise things like specular color and rim light color.
    Also, I searched online but not got useful thing about how to disable model combiner, is it a console command?
  • BlueFlytrap
    Offline / Send Message
    BlueFlytrap polycounter lvl 9
    It is indeed a console command. It is also absolutely useless.

    dota_combine_models 0
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    It is indeed a console command. It is also absolutely useless.

    dota_combine_models 0

    Did the test, result showing below:
    WHkZW2c.png?1jHjAtNy.png?1

    The first one is modelcombiner up, next is down. Notice not only specular light, but also rimlight of the component items changes to [1,0,0], which conforms with what their vmt says (clarify another mystery for me). so it seems what model combiner does is change individual item's vmt settings to the main body.

    all appreciations to BlueFlytrap :)
  • Ifurzzar
    Offline / Send Message
    Ifurzzar null
    Got a new question, when I use the two masks, should I use without gamma value or not? that is, when source engine uses the channels of the mask, does it apply gamma correction to them or not?
    thanks in advance :)
Sign In or Register to comment.