조각 쉐이더를 통해 내 자신의 사용자 지정 glBlendFunc를 수행하려고하지만 정확한 혼합 기능을 수행 할 때도 내 솔루션이 기본 glBlendFunc보다 훨씬 느립니다.사용자 지정 glBlendFunc 훨씬 네이티브보다 느림
누구든지보다 효율적인 방법으로이 작업을 수행하는 방법에 대한 제안이 있는지 궁금합니다. '혼합 작업은 GPU 하드웨어에 직접 내장되어 있기 때문에 아마 당신은 때로 믿을 수 있도록이 훨씬 더 효율적입니다
void draw(fbo fbos[2], render_item item)
{
// fbos[0] is the render target
// fbos[1] is the previous render target used to read "background" to blend against in shader
// Both fbos have exactly the same content, however they need to be different since we can't both read and write to the same texture. The texture we render to needs to have the entire content since we might not draw geometry everywhere.
fbos[0]->attach(); // Attach fbo
fbos[1]->bind(1); // Bind as texture 1
render(item);
glCopyTexSubImage2D(...); // copy from fbos[0] to fbos[1], fbos[1] == fbos[0]
}
fragment.glsl
vec4 blend_color(vec4 fore)
{
vec4 back = texture2D(background, gl_TexCoord[1].st); // background is read from texture "1"
return vec4(mix(back.rgb, fore.rgb, fore.a), back.a + fore.a);
}
NV_texture_barrier를 사용하면 동일한 텍스처를 동시에 렌더링하고 읽을 수 있습니다. – ronag
@ronag : 일종의. 확장 스펙을 읽는 것이 가장 좋지만, 일반적인 개념은 _same 장소에서 그렇게하지 않는 한 동일한 텍스처를 읽고 쓸 수 있다는 것입니다. 그리고 당신은 장벽을 적절히 사용합니다. –