PBR GGX镜面不饱和色

时间:2016-10-23 20:33:00

标签: java opengl lwjgl shading pbr

我正在尝试实现PBR渲染器。我的镜面高光具有不饱和的颜色(特别是在掠射角度)并且逃离了我的光体积边界。为什么会这样?

我用来计算GGX镜面反射的函数:

vec3 shadingSpecularGGX(vec3 N, vec3 V, vec3 L, float roughness, vec3 F0)
{
    vec3 H = normalize(V + L);
    float dotLH = max(dot(L, H), 0.0);
    float dotNH = max(dot(N, H), 0.0);
    float dotNL = max(dot(N, L), 0.0);
    float dotNV = max(dot(N, V), 0.0);
    float alpha = roughness * roughness;
    // D (GGX normal distribution)
    float alphaSqr = alpha * alpha;
    float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
    float D = alphaSqr / (denom * denom);
    // no pi because BRDF -> lighting
    // F (Fresnel term)
    float F_a = 1.0;
    float F_b = pow(1.0 - dotLH, 5); // manually?
    vec3 F = mix(vec3(F_b), vec3(F_a), F0);
    // G (remapped hotness, see Unreal Shading)
    float k = (alpha + 2 * roughness + 1) / 8.0;
    float G = dotNL / (mix(dotNL, 1, k) * mix(dotNV, 1, k));

    return D * F * G / 4.0;
}

然后我将它与漫反射的朗伯术语合并在一起:

float lambert = max(0.0, dot(lightDir, normal));
vec3 diffuse = albedo * (1 - metallic);
vec3 specular = mix(vec3(0.04), albedo, metallic) * light.color;

float distance = length(light.position - worldPos);
float attenuation = clamp(1.0 / (distance * distance * light.atten.quadratic + distance * light.atten.linear + light.atten.constant), 0.0, 1.0);

gl_FragColor.rgb = (diffuse * lambert * light.color * light.intensity) + shadingSpecularGGX(normal, viewDir, lightDir, roughness, specular) * light.intensity;

gl_FragColor.rgb *= attenuation;
gl_FragColor.a = 1.0;

从顶部观看时,镜面反射高光有颜色,但随着相机移近地面,颜色开始消失。

Specular highlight is colored When viewed from grazing angle, the color is washed out

这是正确的行为吗?因为在看湿沥青的照片时,反射的颜色似乎得以保留。

enter image description here

我设法通过将F0颜色更改为light.color

来获得彩色反射

vec3 specular = mix(light.color, albedo * light.color, metallic);

但是我已经读过,F0值应该是非金属的0.04左右,而我的镜面反射会逃脱我的边界球。

0 个答案:

没有答案