Home Technical Talk

Shader FX - Partial recoloring of diffuse sheet

Spicypixel
polycounter lvl 6
Offline / Send Message
Spicypixel polycounter lvl 6
I'm having trouble working out the correct combination of nodes to effectively green screen a texture, I've been using 100% magenta as a block color on the UV sheet to indicate a texture I want to be replaced via the shader settings but I've yet to find out a way to convert magenta areas of a sheet into a mask before replacing the colors with variable defined ones.

Just a simple case of adding programmatic team colours to a uniform but I'm unsure how to go about it, any help would be useful.

Replies

  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Did you figure out a way to cast bool -> float?

    I might know a way, but would be highly inefficient.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Is using a separate texture channel to indicate team-color an option? Or does it have to be a certain distinct color in the RGB-space?
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    I'm new to Shader FX in Maya and 3dsmax so I'm not really skilled enough to say, and the tutorials or guides for it are woeful and completely non existent.

    I understand how to make a greyscale emissive map and multiply it with a colour value to make different glowing lights and such but was hoping to just have a diffuse colour reassignment option.
  • tharle
    Options
    Offline / Send Message
    tharle polycounter lvl 9
    disclaimer: i havent used shader fx but i presume it has similar options to unreal...

    i presume you cant do something as simple as an if node?

    if not then there's a dirty hacky way to do it - multiply your blue and red channels together and you'll have pure white where you had pure magenta. multiply this output by 100 then clamp the resulting texture to the range 99-100. then just subtract 99 and you will have a black and white mask where you had pure magenta with a 1% margin of error. if its not accurate enough you can start using bigger numbers but that should be more than enough.

    hope that helps
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    It has an if/else node but it's a little outside my understanding without a flowchart of what I'm trying to get out of it. Not sure how to set the condition to "if this RGB value, set to this RGB value" which is seemingly more complicated than I expected.

    Honestly just wished the documentation was far more detailed.

    Edit: Could use two UV sheets, and keep the areas I want to color in the shader on sheet 2 but it's really a pain.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    There's a ComparisonOp and an IfElseBasicOp. So yeah, there's the basic branching possibilities.

    Although without the ComparisonOp taking a float3 as an input or being able to cast between bool-int-float data types it's not all too easy to compare two colors. "Is this pixel colored with the predefined team color"?
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    As someone starting their introduction to game shaders via ShaderFX it's proving difficult to wrap my head around the possibilities the toolset they offer provides. I'll keep plugging at it but I'd have thought it was a pretty common thing to ask from a game shader - having team specific colorings on a texture sheet.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    My intial idea is, compare color A to color B and feed that output to a lerp node which lerps between the unmodified texture and the modified texture(or straight up solid team color).

    ShaderFX is still quite new to me. But from what I see, when it comes to creating this with the set of nodes available it's clunky.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Spicypixel> Imo what you are asking for shouldn't be all that hard to create.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    This section of the ShaderFX shows how to set up what you are looking for but only for one color channel. It's the part where you want to check three channels for a specific color which gets tricky. You can do it with several If-statements. But not really all that optimal performance wise I think.

    http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=GUID-355DCB0C-D9A6-4B59-8AFB-CBA7E1067D60
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    Perfect I'll have a look, not knowing which node I needed prevented a good read of the documentation. I'll report back when I get chance. Thanks!
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Hey,

    Turns out you don't have to worry about casting as much as I had believed. Guess I'm stuck in my old Mental Mill habits. I gave it a go just now and here's a way you could go. Although as you can see this only handles just the very exact color. So as long as it's entire UV-islands it's no issue, otherwise you'd have to improve on this or find a different way about it. Hope it helps.

    hHhr0i.jpg
    dqTbsg.jpg
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    Yeah while you were checking it out I played around with it and got some results that were useful albeit not perfect but it's nice to play around to follow how the tools work step by step.

    Posted the Texture sheet, the node graph and the result. There's an annoying 1px outline stroke which according to Photoshop is 100% Red (at first assumed it was aliasing blending with the text). I'll look at your node graph and method and give it a shot. Might turn out to be a productive thread after all :D

    6I0ZSNJl.png

    PChBLDM.png

    x7PC6lX.png
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Do you have a specific end goal here? I mean like a game asset you want to add the team-color functionality to? Because the way we are going at it now we only get solid color on this area and we'll be struggling with the texture filtering adding those semi-mask-colored pixels around the area.

    Maybe sacrifice the Alpha channel to store a mask for what should be team color areas? That way we could still keep brightness values in the RGB channels for these areas. Also deal with the unwanted pixels at the perimeter easily if we go 8-bit alpha. There's loads of way to optimize on this concept though.
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    Yeah I was using a cube since I didn't have my mesh and texture sheet to hand and it was a quick and dirty way to do it. End goal is pretty much what your node graph defines, It'll be block colored areas of the sheet, nothing more complicated in terms of blending the defined color into the existing stuff.

    Alpha channel masking is an option too, but now I know the rough logical layout of what was done in your node graph I can look up the documentation for each node and tweak it accordingly to needs. Thanks, you've been a big help.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    No worries. Good luck and please do share your results :)
  • Eric Chadwick
    Options
    Offline / Send Message
    I did something similar in a past job, where we used the alpha channel to define masks for three team colors. Each mask used 1/3 of the range within the alpha: 0-85, 86-143, 144-255.

    Here's an example with just two ranges instead of three, made with the old Shader FX in 3ds Max. Might give you some ideas. I can probably dig up a higher-resolution shot if you need one.

    robotrising_utility_shader.jpg
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Here's another idea. Use Vertex Colors to paint whatever "Team Color" you want anywhere on the model. I set it up so that black(0,0,0) vertex color = texture color, anything brighter than black vertex color = desaturated texture color * vertex color.

    The model in the GIF is one of my talented students model(with borked shading atm) from a few years back.

    IAWb7h.gif

    Ba6VNZ.jpg
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    I would suggest vertex colors too. Getting ranges of an image is okay but you run into a lot of filtering and compression problems. Another thing you might be able to do is an atlas alpha (though you might run into filtering problems again. There are ways around this)
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    I like the solutions offered, I guess this can turn into a general ShaderFX thread on team coloring. Interested on the triple stage alpha blending above and would appreciate a higher resolution node graph to examine closer. It's just a case of experimenting now with different ideas.
  • shaderfx
    Options
    Offline / Send Message
    shaderfx polycounter lvl 9
    Spicypixel wrote: »
    the tutorials or guides for it are woeful and completely non existent.

    We can definitely do better there.
    Try starting at: http://www.shaderfx.com/

    There is also a new Gnomon workshop for ShaderFX / VP 2.
    I have not seen it myself, so hope its good.

    The Maya help docs have basic help to get started and quite a lot of Unreal tutorials can be applied in ShaderFX with some adjusting.

    Hope that helps a little.

    -Kees
  • Spicypixel
    Options
    Offline / Send Message
    Spicypixel polycounter lvl 6
    Thanks for this direct response! Might be useful to set up a UDK style community wiki? Just spitballing ideas - I'd love to be able to contribute after stumbling on successful node graph layouts!
    It's an excellent bit of software and having done basic GLSL before I'm glad I don't have to touch it as much any more.
    Keep up the good work, I'll look at the Gnomon course for sure.
Sign In or Register to comment.