简体   繁体   English

GLSL - PBR 着色器 - 漫反射 IBL 组件无法渲染

[英]GLSL - PBR Shader - Diffuse IBL component failing to render

I have put together a program partially based on learnopengl.com.我整理了一个部分基于 learnopengl.com 的程序。

The part that fails is in the fragment shader of a PBR shader when calculating the ambient component using an irradianceMap.当使用 irradianceMap 计算环境分量时,失败的部分是在 PBR 着色器的片段着色器中。 I have already verified the map is being sent to the shader correctly, as well as all the other maps.我已经验证 map 以及所有其他贴图已正确发送到着色器。

When run without IBL the scene looks like this:在没有 IBL 的情况下运行时,场景如下所示:

But when run with IBL it looks like this:但是当使用 IBL 运行时,它看起来像这样:

As you can see, the spheres with the PBR shader disappear.如您所见,带有 PBR 着色器的球体消失了。

The section which causes the problem is as follows:导致问题的部分如下:

vec3 kS = fresnelSchlick(max(dot(N, V), 0.0), F0);
vec3 kD = 1.0 - kS;
kD *= 1.0 - metallic;     
vec3 irradiance = texture(irradianceMap, N).rgb;
vec3 diffuse = irradiance * albedo;
vec3 ambient = kD * vec3(diffuse) * ao;

colour = ambient +Lo;

Specifically the problem lies with the irradiance variable, which when I perform normal operations on it, it works fine for example if I multiply it by 0.01 it will darken significantly, as expected.具体来说,问题在于辐照度变量,当我对它执行正常操作时,它工作正常,例如,如果我将它乘以 0.01,它会像预期的那样显着变暗。 However when I add or multiply for example the albedo variable with the irradiance it fails, and nothing is output. I have tried 1000 different combinations and variables, and I simply cannot understand why it won't allow this variable to combine with others.但是,当我将反照率变量与辐照度相加或相乘时,它会失败,没有任何东西是 output。我已经尝试了 1000 种不同的组合和变量,我只是不明白为什么它不允许这个变量与其他变量组合。 I don't see why multiplying irradiance.r by albedo.r somehow produces nothing.我不明白为什么将 irradiance.r 乘以 albedo.r 以某种方式产生任何结果。 Even if both were 0 the result would be black, not the spheres disappearing entirely.即使两者都为 0,结果也会是黑色,而不是球体完全消失。

This for example works:这例如有效:

vec3 irradiance = texture(irradianceMap, N).rgb;

colour = irradiance;

As well as this:以及这个:

vec3 irradiance = texture(irradianceMap, N).rgb;

colour = irradiance*0.01;

But this fails:但这失败了:

vec3 irradiance = texture(irradianceMap, N).rgb;

colour = irradiance*albedo;

As well as this:以及这个:

vec3 irradiance = texture(irradianceMap, N).rgb;

colour = vec3(irradiance.r,albedo.g,albedo.b);

Or any combination of the above you can dream of.或者您可以想到的上述任何组合。 All the other variables around it work and output correctly.它周围的所有其他变量都有效,并且 output 正确。 It's only when operations are performed with that specific variable that things go wrong.只有当使用该特定变量执行操作时,才会出现 go 错误。 I literally cannot fathom why not, and have found few answers online.我真的无法理解为什么不这样做,并且在网上找到的答案很少。

Most likely shader compilation is failing due to albedo being undefined, wrong type, etc. You have uniform vec3 albedo; 由于albedo未定义,类型错误等,最有可能的着色器编译失败uniform vec3 albedo; or equivalent defined in the shader? 或在着色器中定义的等效项?

From the examples you've shown, it certainly looks to be a problem with albedo and not irradiance . 从您显示的示例来看, albedo当然是问题,而不是irradiance

I solved this problem, you must add this code when you load texture:我解决了这个问题,你必须在加载纹理时添加这段代码:

shader.setInt("albedoMap", 0);
shader.setInt("normalMap", 1);
shader.setInt("metallicMap", 2);
shader.setInt("roughnessMap", 3);
shader.setInt("aoMap", 4);
shader.setInt("irradianceMap", 5);

Here is what i did before:这是我之前所做的:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, albedoMap);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, normalMap);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, metallicMap);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, roughnessMap);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, aoMap);
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_CUBE_MAP, irradianceMap);

It's working fine, but in this section, you must use both.它工作正常,但在本节中,您必须同时使用两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM