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
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..
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.
Also, for the Max node, just use a Custom node and declare the Max value.
I think it's return; Max(A,B)?
And wouldn't the clamp work as the Max? I don't know enough about HLSL to actually write code for it.
Use a Custom node instead and put this in it:
return max(A, ;
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).
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.
Here is a comparison from the top. The only angle where it looks correct.. mostly.
wrong
right
But farther down it does not bend the same was as it should.
wrong
right
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.
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.
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?
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: 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
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.
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);
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.
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)
And the exp probably doesn't have to be made via a custom node, I just don't know how you would do it.
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.
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.