【发布时间】:2021-01-15 10:44:19
【问题描述】:
我正在尝试在片段着色器中同时使用 samplerBuffer 和 sampler2D。
单独使用 samplerBuffer 可以正常工作,代码如下所示
#version 460
out vec4 FragColor;
in vec2 texcoord;
uniform sampler2D background;
uniform samplerBuffer OctreeData;
...
void main()
{
Ray ray = initRay();
/*this function does raytraycing in octree and retrieves data
from samplerBuffer using texelFetch function.*/
Contact res = iterativeHitNodes(ray);
if(res.hit)
FragColor = assignNodeColor(res); //sets color of the node
else
FragColor = getBackground(origin, ray);
}
然后,如果我在main 函数的开头添加FragColor = texture(background, texcoord.xy); return; 行,它会成功读取图像并显示它。 (A)
但是当在getBackground 中调用texture 时,它会显示灰屏。结果发现着色器根本不工作——当我故意加载重型模型时,帧率保持不变。但是没有着色器编译错误。
最大的“什么”是即使texture 从未被称为(B),屏幕仍然是灰色的。例如,当backgroundType 始终为 0 而getBackground 函数为:
vec3 getBackground(vec3 from, vec3 direction)
{
if(backgroundType == 0)
return getSkyBackground(from, direction);
else if(backgroundType == 1)
{
return texture(background, texcoord.xy).xyz;
}
return vec3(0);
}
似乎完全存在texture 调用丢弃片段。
- 这就是它在 A 案例https://imgur.com/5d2WaUT 中的样子
- 如果是B https://imgur.com/LEDDNht
- 这是它的外观以及它在 CPU 上的外观https://imgur.com/Gc2BUwa
P.S. 在调试中它按预期工作。由于某种原因,问题出现在Release模式
P.P.S大部分shader的代码https://pastebin.com/SWCQ9HUw
【问题讨论】: