Home Unreal Engine

Custom Lighting with Anisotropic Specular?

How would one go about implementing anisotropic specular into a shader using custom lighting? I've tried searching for this myself but the only information I can find is how to recreate phong shading.

I need to use custom lighting in order to achieve toon shading.

Replies

  • Rekmar
    Options
    Offline / Send Message
    Rekmar polycounter lvl 19
    sorry to bump a somewhat old thread, but I'd love to know if there's a custom-lighting anisotropic implementation out there. my searches have been fruitless :/
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    Eh. I've tried to work it out for the past couple of hours for you. But something isn't working in this shader.

    I had been converting the HLSL from this site
    http://wiki.unity3d.com/index.php?title=Anisotropic_Highlight_Shader

    What I came up with was..

    anisotrophic.png


    A direct conversion ( assuming I did it correctly), gives some sort of antisotropic specular. But it's not the same as if you were to plug it into the antisotropic slot.

    A few things from the HLSL do not convert as well.
    Such as "s.AnisoDir.a"

    Since the value of the alpha channel is not stated. I just went with a constant.

    This is my first conversion, so I don't know if I did it right or not. Either way, it's 6 am.

    Maybe someone can come in and point out my flaw or something.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    UDK already Normalizes a majority of the Nodes, so try taking out the extraneous ones, but keep the one for the Blinn in the final part only.

    Also, for the Max node, just use a Custom node and declare the Max value.

    I think it's return; Max(A,B)?
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    Removing any of the Normalize nodes that isn't the light vector or camera vector wacks it out even worse.

    And wouldn't the clamp work as the Max? I don't know enough about HLSL to actually write code for it.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Not really, since UDK (IIRC for the open Clamp node) clamps it automatically between 1 and 0 again and you need to declare manually (or do it through the IF node) to get the correct math a la Max.

    Use a Custom node instead and put this in it:

    return max(A, B);

    Then expand in the input Bar in it, and Put in A and B for each Input slot.

    Now put in a 0 constant in A and the Sine formula in B.

    Voila, done. Much cleaner honestly, and costs the same as it would with an IF node.

    Lastly, take out the Aniso Map and instead put in the Green Color. Aniso maps (even for UDK) should be clamped between the RG colors and no White or Blue should be in it.

    Also, don't Normalize it, I don't think you need it for UDK, just put a Constant-Clamp instead. for the Aniso + Normal Add (please note I'm not sure, if the lighting looks wrong, then Normalize again, I'm not sure).
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    Well I made the custom node. I'm using a green color now. I tried turning off Normalize and used a clamp instead. But it created more lines.

    I've changed a few of the nodes parameters. Such as multiplying by 15 instead of 180. Since 180 made it repeat over and over.

    customaniso.png
    epicaniso.png

    Here is a comparison from the top. The only angle where it looks correct.. mostly.

    viewmidcustom.png wrong
    viewmidepic.pngright

    But farther down it does not bend the same was as it should.

    viewbotcustom.pngwrong
    viewbotepic.pngright

    And by the time we get to the bottom. Epics anisotropic has came back into itself. But the custom one has just barely straightened out.

    So solutions? I believe the problem might be something with the camera.

    Or maybe the HLSL code itself is wrong. I noticed on their page, their result was the same as mine in the beginning.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    So any thoughts at all? I think we're all close to a solution.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    day3.png

    The red line is where its supposed to be lined up at.

    I've cut out a lot of the nodes.

    If I crank up the anistropic direction to lik 20, it does go to the center. But its way too thin.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Ah, I see, I just tried recreating the shader from the snippet and you're right, I never noticed this, but it seems like the implementation on the Unity Wiki could actually be wrong, since at pure Horizontal, it still bends the highlight upwards.

    I also ran a few Max tests with their native Aniso shaders, seems like they backup the ones from Epic too.

    Apologies for not taking time to look the code and driving you in circles! My bad, I should have taken a harder look.

    I'm guessing the peeps at Epic used a Ward math to get the Aniso highlight?
    http://content.gpwiki.org/index.php/D3DBook:%28Lighting%29_Ward

    If you want, I could try and create the shader within the hour or so?
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    I don't have the slightest clue what a Ward math is.

    Take a shot at it if you want. I'm busy writing up a resume and I can't get back to unreal until I'm finished.

    Wow.. the math on that page looks evil.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Done and done:

    J8dXh.jpg
  • Rekmar
    Options
    Offline / Send Message
    Rekmar polycounter lvl 19
    hey guys you've been really helpful. I've been super-busy so I forgot about this thread, but now I'm glad I revived it :)

    Ace-Angel: does your implementation allow to change the specular direction? none of your nodes seem to be meant to be edited so where would you do it?
    All I ever got close to was an inexact aniso version for horizontal anisotropy, but anything I tried to rotate the anisotropy was a big fail
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    Ace, I didn't understand your version very well.

    So I just recreated it from the the HLSL code from that page.

    I didn't hook up the s_den from it though. Cause it just lightened the specular to basically nothing.

    anis.png

    This version is not as bright as if you were to hook it up the Antistropic Direction node. But I figure tweeking the settings can fix that eventually.


    -edit-
    Oh also Rekmar.

    The "Exp" node is a custom one.

    Just type in:
    return exp(A);
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Nice! I totally forgot about the Cross between the Normal Map and Aniso Direction.

    I have no idea what s_den is honestly...it adds about 9 extra instructions in my case and makes it darker for some reason.

    The only thing I'm worried about right now is how well something like this: http://www.polycount.com/forum/showthread.php?t=105399&page=3
    Will translate to this setup, since the original Epic map has blue in their map (and imported as a Normal Map compression). I tried importing a few crude example for a simple hair made with Lot's editor, and they didn't look too hot, but that could be my examples being rubbish.

    @Rekmar: 16bit put up names, if you look for anything with the name 'roughness' in it, that will allow you change the orientation, but you're limited to either going Horizontal or Vertical only.

    You could get fancy and get a Hue Rotate of the colors going on in Tangent/Bitangent sections, but I'm not sure if it would be worth since it could get pretty heavy pretty quick in that case.
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Great shader guys!
    Sorry noob question,,,any way to build the custom Exp out of nods ?
    my guess is no.

    also
    For the Black, 5e-005, how do you get the minus ?
    I can only seem to get the 5e+005 (with plus) and its white,
    (by typing in 500000.000000)
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    5e-005 is .00005, it doesn't matter what you put here just as long as it's really small. It's only there to keep the shader from dividing by zero.

    And the exp probably doesn't have to be made via a custom node, I just don't know how you would do it.
  • tuxmask75
    Options
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    16bit wrote: »
    5e-005 is .00005, it doesn't matter what you put here just as long as it's really small. It's only there to keep the shader from dividing by zero.

    And the exp probably doesn't have to be made via a custom node, I just don't know how you would do it.
    Thanks man, that one really kept me scratching my head. I was so close in trying 5.00005 lol which only returned a 5.0
    I'm learning a lot from you guys here on the forums. keep up the the good work!

    Also something that i noticed on the 2 above shaders is that they show off the UV unwrap seams.

    capturebsr.png
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    It's because the Aniso Term is always, and has always been based on UV's and the direction they have been unwrapped from, since more times then not people don't have access to Comb Maps, hence one color values.

    There are a few people who made UV'less Aniso's, but they screwed up the Normal Map parts, and cannot seem to find their sites anymore.
Sign In or Register to comment.