Sign in to follow this  

Anisotropic Specular

Recommended Posts

I'm trying to implement an anisotropic version of GGX in UDK. Here is what the shader looks like:



float3 H = normalize(L + V);
float NdotL = saturate(dot(N, L));
float NdotV = dot(N, V);
float NdotH = dot(N, H);
float LdotH = dot(L, H);
float HdotX = dot(H, X);
float HdotY = dot(H, Y);

float NdotH_2 = NdotH * NdotH;
float HdotX_2 = HdotX * HdotX;
float HdotY_2 = HdotY * HdotY;
float ax_2 = ax * ax;
float ay_2 = ay * ay;

float GGX = (ax * ay * pow(HdotX_2 / ax_2 + HdotY_2 / ay_2 + NdotH_2, 2.0));

float3 F = Ks + (1.0 - Ks) * exp(-6 * LdotH);

float3 Rs = F / (4 * GGX * LdotH * LdotH);
float3 Rd = Kd * (1 - Ks);

return (Rs + Rd) * NdotL;


The problem is I'm not sure what to use for vectors X and Y. Because this is UDK, vectors L and V are relative to the surface (tangent space), so would I simply use X = [1, 0, 0], Y = [0, 1, 0]?

Edited by Chris_F

Share this post

Link to post
Share on other sites

I believe X and Y should be set to your tangent and bitangent vectors. So if your L and V vectors are already in TBN space, then yes, you should set them to the tangent and bitangent's representation in this coordinate space, which is just (1, 0, 0) and (0, 1, 0).

Share this post

Link to post
Share on other sites

That because isotropic shaders don't care about the tangent and bitangent, all they need is the normal (since they are isotropic about the normal axis). Are you sure your TBN matrix is correct for every face here? The bottom looks good but there's a discontinuity.

Share this post

Link to post
Share on other sites

Tangents are usually generated from the UVs, so that makes sense. Fixing up the mesh should solve the issue.


I've UV unwrapped the meshes six ways from Sunday, and I have found no unwrap that doesn't produce a horrible discontinuity along the UV seam(s).

Share this post

Link to post
Share on other sites

I've rewritten your code into my own game engine, that has correct tangent space vectors computation from UV coordinates, here are the results for different UV coordinate modes (just quickly made sphere in 3D modeller and used 3 different UV mappings). Note that I don't transform light and view vectors into tangent space (I keep them in view space), but this won't make a difference (as I use actual tangent & bitangent vectors in world space).


In your case (when you transfer light and view vectors to tangent space, your tangent and bitangent vectors in that space are tangent space basis -> tangent = (1, 0, 0), bitangent = (0, 1, 0) and normal = (0, 0, 1).


1. Correct one (spherical UV coordinates - works fine):



2. Box UV coordinates (obviously wrong)



3. Face unwrap (e.g. each face is mapped between 0.0 - 1.0 UV coordinates) - again obviously wrong:


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this