3

我正在尝试实现 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;

从顶部观看时,镜面高光有颜色,但随着相机靠近地面,颜色开始褪色。

镜面高光是彩色的 从放牧角度看,颜色被洗掉了

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

在此处输入图像描述

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

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

但我读过,非金属的 F0 值应该是 0.04 左右,并且我的镜面反射超出了我的边界球。

4

0 回答 0