Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Optimized GGX in Shader Graph

Discussion in 'Shader Graph' started by GilG, Feb 27, 2020.

  1. GilG

    GilG

    Joined:
    Jan 30, 2017
    Posts:
    27
    Hello,

    I'm trying to implement an optimized version of the GGX specularity from http://filmicworlds.com/blog/optimizing-ggx-shaders-with-dotlh/

    Here is the code I'm trying to replicate :

    ```
    float LightingFuncGGX_OPT5(float3 N, float3 V, float3 L, float roughness, float F0)
    {
    float3 H = normalize(V+L);
    float dotNL = saturate(dot(N,L));
    float dotLH = saturate(dot(L,H));
    float dotNH = saturate(dot(N,H));
    float D = g_txGgxDFV.Sample(g_samLinearClamp,float2(Pow4(dotNH),roughness)).x;
    float2 FV_helper =
    g_txGgxDFV.Sample(g_samLinearClamp,float2(dotLH,roughness)).yz;
    float FV = F0*FV_helper.x + FV_helper.y;
    float specular = dotNL * D * FV;
    return specular;
    }
    ```

    You can download the Subgraph I made for this here : https://files.cynaptek.com/GGX Specular.shadersubgraph
    The difficulty I'm having is with the use of g_txGgxDFV.Sample(g_samLinearClamp, ***).x and
    g_txGgxDFV.Sample(g_samLinearClamp, ***).yz

    I tried to put them in an hlsl script function but then I have the error "Undeclared identifier g_txGgxDFV".
    What am I missing ? Do I need to import something from Unity ?

    Any help appreciated !
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Those are textures it's trying to sample, you can just slam some code off the web and expect it to work without understanding what the code is actually doing.
     
  3. GilG

    GilG

    Joined:
    Jan 30, 2017
    Posts:
    27
    Hello jbooth,
    Thanks for the reply. I know and that's why I posted here. I would like to know how I can use them inside shader graph.
    Is it a new texture he is creating?
    How can I do the same ?

    Is it just a combine ?
     
    Last edited: Feb 28, 2020
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    make a texture, and sample it like you would any other texture in the graph.