I am trying to use both samplerBuffer and sampler2D in fragment shader.
With samplerBuffer alone it works fine and code looks like this
#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);
}
Then if I add FragColor = texture(background, texcoord.xy); return; line at the beginning of main function, it successfully reads the image and displays it. (A)
But when texture is called in getBackground it shows gray screen. And turns out shader is not working at all — When I intentionally load heavy models framerate stays the same. But there are no shader compile errors.
And the biggest "what" is that screen remains gray even when texture is never called (B). For example when backgroundType is always 0 and getBackground function is:
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);
}
Seems like a sheer presence of texture call discards fragments.
- this is how it looks in A case https://imgur.com/5d2WaUT
- in case of B https://imgur.com/LEDDNht
- this is how it should look and how it looks on CPU https://imgur.com/Gc2BUwa
P.S. In Debug it works as intended. For some reason, the problem appears in Release mode
P.P.S Most of the shader's code https://pastebin.com/SWCQ9HUw