繁体   English   中英

'纹理' function 在 glsl 中调用 sampler2D 使整个屏幕变灰

[英]'texture' function call on sampler2D in glsl makes entire screen gray

我正在尝试在片段着色器中同时使用samplerBuffersampler2D

单独使用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);
}

然后如果我添加FragColor = texture(background, texcoord.xy); return; FragColor = texture(background, texcoord.xy); return; main function 开头的行,它成功读取图像并显示它。 (一个)

但是当在getBackground中调用texture时,它会显示灰屏。 结果发现着色器根本不工作——当我故意加载重型模型时,帧率保持不变。 但是没有着色器编译错误。

最大的“什么”是即使从不调用texture (B) ,屏幕仍然是灰色的。 例如,当backgroundType始终为 0 并且getBackground function 为:

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调用会丢弃片段。

PS在调试中它按预期工作。 由于某种原因,问题出现在发布模式

PPS大部分着色器的代码https://pastebin.com/SWCQ9HUw

请参阅OpenGL 着色语言 4.60 规范 (HTML) - 纹理功能

一些纹理函数(非“Lod”和非“Grad”版本)可能需要隐式导数。 在非统一控制流和非片段着色器纹理提取中未定义隐式导数。

如果您使用纹理和texture进行纹理查找,请确保调用组中的所有调用都执行相同的控制流路径:

vec3 getBackground(vec3 from, vec3 direction, vec3 backgroundColor)
{
    if (backgroundType == 0)
        return getSkyBackground(from, direction);
    else if (backgroundType == 1)
        return backgroundColor;

    return vec3(0);
}
void main()
{
    vec3 backgroundColor = texture(background, texcoord.xy).xyz;
    
    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, backgroundColor);
}

暂无
暂无

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

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