• Create Account

## Anisotropic Specular

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1Chris_F  Members

Posted 12 February 2013 - 08:04 PM

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, 12 February 2013 - 08:05 PM.

### #2Bacterius  Members

Posted 13 February 2013 - 01:21 AM

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).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #3Chris_F  Members

Posted 13 February 2013 - 01:09 PM

In that case, I'm not sure what I'm doing wrong. I don't have this issue with isotropic shaders.

### #4Bacterius  Members

Posted 13 February 2013 - 04:20 PM

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #5Chris_F  Members

Posted 13 February 2013 - 04:37 PM

Well, this is UDK that I'm working in ATM, so as far as I know I have no control over the tangents. The discontinuities seem to correlate to the UVs.

### #6ATEFred  Members

Posted 17 February 2013 - 12:28 PM

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

### #7Chris_F  Members

Posted 17 February 2013 - 03:13 PM

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).

### #8Vilem Otte  GDNet+

Posted 18 February 2013 - 05:47 AM

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:

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

### #9Chris_F  Members

Posted 18 February 2013 - 04:26 PM

Here I used a spherical unwrap.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.