Search Unity

Question GGX Anisotropy BRDF

Discussion in 'Shaders' started by MatheusMarkies, Sep 17, 2020.

  1. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Good Morning.
    I am implementing a BRDF anisotropy model.
    However it was strange.

    GGX BRDF
    Code (CSharp):
    1.  
    2. //Anisotropy Surfaces
    3. float SpecularStrengthAnisotropy(Surface surface, BRDF brdf, Light light) {
    4.     float at = max(brdf.roughness * (1.0 + surface.anisotropic), 0.001);
    5.     float ab = max(brdf.roughness * (1.0 - surface.anisotropic), 0.001);
    6.  
    7.     float3 h = SafeNormalize(light.direction + surface.viewDirection);
    8.     float NoH = dot(surface.normal, h);
    9.     float ToH = dot(surface.tangent, h);
    10.  
    11.     float3 b = normalize(cross(surface.normal, surface.tangent));//normalize(cross(surface.normal, surface.tangent.xyz) * surface.tangent.w);
    12.  
    13.     float BoH = dot(b, h);
    14.     float a2 = at * ab;
    15.     float3 v = float3(ab * ToH, at * BoH, a2 * NoH);
    16.     float v2 = dot(v, v);
    17.     float w2 = a2 / v2;
    18.     return a2 * w2 * w2 * (1.0 / PI);
    19. }
    20.  
    Reference:
    https://google.github.io/filament/Filament.md.html#materialsystem/anisotropicmodel

    ghj.PNG hjk.PNG yy.PNG

    Where did I go wrong?
    How can I fix this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    No where, it's working properly.

    Use a mesh with more tessellation, or use a shader that doesn't depend directly on the mesh's tangents to determine the anisotropic angle.
     
    MatheusMarkies likes this.
  3. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Thanks for answering!
    Can you give me an example without a tangent?
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    And example is utilizing an aniso map instead of just the surface normals, like in this example:

    http://wiki.unity3d.com/index.php/Anisotropic_Highlight_Shader
    Basically a detail normal map meant for directing anisotropic direction.
     
    MatheusMarkies likes this.