Followers 0

# Anisotropic Specular

## 8 posts in this topic

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
0

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

1

##### Share on other sites

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

[attachment=13625:aniso.png]

0

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

0

##### Share on other sites

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.

0

##### Share on other sites

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

0

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

0

##### 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:

2

##### Share on other sites

Here I used a spherical unwrap.

[attachment=13707:sphere.png]

0

## Create an account

Register a new account