1

I'm trying to create a ggx shader but when I run it at BRDF Explorer the main page remains white. I'm trying to find my error but I can't. Can anybody help me? below is my file

analytic

::begin parameters

float baseColor 0.001 .2 .1

float m 0.001 0.1 1.0 

::end parameters

::begin shader

    const float PI = 3.14;


    vec3 BRDF( vec3 N, vec3 V, vec3 L, float m, float baseColor)
        {

            vec3 H = normalize(V+L);

            float dotNL = clamp(dot(N,L), 0.0, 1.0);
            float dotLH = clamp(dot(L,H), 0.0, 1.0);
            float dotNH = clamp(dot(N,H), 0.0, 1.0);

            float DotNH2 = dotNH * dotNH;
            float m2 = m * m;
            float D =  m2 / (PI * pow(dotNH * dotNH * (m2 - 1) + 1, 2.0));


            float Fresnel(float baseColor, float l, float h)
        {
            return baseColor + ( 1 - baseColor ) * pow( 1 - (dotNH), 5);
        }
            float F = Fresnel(baseColor, dotNH);


            float ggx_visib(float dotNV, float m2) 
        { 
            return 1.0/(dotNV*(1.0-m2)+m2); 
        }                       

            float g1i =ggx_visib(m, dotLH);
            float g1o =ggx_visib(m, dotNV);
            float G = g1i * g1o;



        return D * G * F * (1.0 / (4.0 * dotNL * dotNV));


        }

::end shader

1 Answer 1

1

There are 2 function declarations in the middle of the function BRDF. This is not allowed. In GLSL a function definition has to be global.

See GLSL - The OpenGL Shading Language 4.6; 6.1. Function Definitions ; page 122:

As indicated by the grammar above, a valid shader is a sequence of global declarations and function definitions.

Move the declarations of Fresnel and ggx_visib before the declaration of BRDF to solve your issue.

The major issue is, that the BRDF explorer requires the keyword analytic at the begin of the file, to identify the file as a light model.

After the keyword is add add the file reloaded, the application will trace error cause by your GLSL code.

Fixing the errors results in the following code:

analytic

::begin parameters

float baseColor 0.001 .2 .1

float m 0.001 0.1 1.0

::end parameters

::begin shader

const float PI = 3.14;

float Fresnel(float baseColor, float l, float h)
{
    return baseColor + ( 1 - baseColor ) * pow( 1 - (h), 5);
}

float ggx_visib(float dotNV, float m2) 
{ 
    return 1.0/(dotNV*(1.0-m2)+m2); 
} 

vec3 BRDF( vec3 N, vec3 V, vec3 L, vec3 X, vec3 Y)
{
    vec3 H = normalize(V+L);

    float dotNL = clamp(dot(N,L), 0.0, 1.0);
    float dotLH = clamp(dot(L,H), 0.0, 1.0);
    float dotNH = clamp(dot(N,H), 0.0, 1.0);

    float DotNH2 = dotNH * dotNH;
    float m2 = m * m;
    float D =  m2 / (PI * pow(dotNH * dotNH * (m2 - 1) + 1, 2.0));

    float F = Fresnel(baseColor, dotNL, dotNH);

    float g1i =ggx_visib(m, dotLH);
    float g1o =ggx_visib(m, dotNH);
    float G = g1i * g1o;

    float k = D * G * F * (1.0 / (4.0 * dotNL * dotNH));
    return vec3(k);
}
::end shader
10
  • Hello, thank you for your help. I moved the declarations of Fresnel and ggx_visib before the declaration of BRDF as you mention my code now is excacly as you have edit it. However the I opened it on BRDF explorer I still get the same blanc page. It doesn't show nor a ball nor some kind of light. I don't know what I;m doing wrong here Dec 18, 2018 at 9:02
  • Hello, No it doesn't I modified the code to be Fresnel - return baseColor + ( 1 - baseColor ) * pow( 1 - (h), 5); but I don't get any result. Dec 18, 2018 at 9:12
  • When I opened it to BRDF explorer the page stay empty. It doesn't show anything Dec 18, 2018 at 9:15
  • From disneyanimation.com/technology/brdf.html I've dowloaded the win32binary. So I created my file at notepad and I tried to run it. I guess I'm doing something ridiculously wrong, but honestly I don't know what.. Dec 18, 2018 at 9:27
  • 1
    @user3052811 I downloaded the application and made your code run. The major issue is that the keyword analytic at the begin of the .brdf file was missing in your code. The code in my answer is the final code with all GLSL compile errors fixed.
    – Rabbid76
    Dec 18, 2018 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.