I have 2 visual objects, the 1st contains a background image, the 2nd overlays this with information. Now I would need for each pixel in the fragment shader of the 2nd, the underlying color value of the 1st object. The construction is done with Qt Qml, (1st object = image, 2nd object a qquickframebufferobject) and I use defeered rendering. Does maybe someone knows how to go there?
How do get the pixel color of the underlying object inside my offscreen framebuffer in opengl es 3+?
9
-
Generally, you don't have the access to previously rendered samples, unless it was rendered to a texture, and you're doing second pass with that texture binded for sampling. Why do you need that info anyway? Is alpha blending/clipping not enough for your task?– VladNov 26, 2019 at 13:44
-
Thxs Vlad! I'would use the underlying pixel color to get for my pixel the color with the highest contrast. E.g. If the underlying pixel color = white then my one should be black. Is there maybe another way?– PowerNowNov 26, 2019 at 14:21
-
1Isn't this what khronos.org/registry/OpenGL/extensions/EXT/… is for?– AndreaNov 30, 2019 at 22:24
-
@Andrea: Thats exactly what I'm looking for. But if I want to include GL_EXT_shader_framebuffer_fetch via #extension in my fragment shader i always get the error "Warning: Extension 'GL_ARB_fragment_coord_conventions' not supported". I checked the extensions via app and found only GL_EXT_shader_framebuffer_fetch. So why exists GL_EXT_shader_framebuffer_fetch but can't use the features of it?– PowerNowDec 6, 2019 at 9:21
-
@PowerNow Is that just from adding the #extension line? It could be some other change you made which causes the error.– AndreaDec 6, 2019 at 11:34
|
Show 4 more comments
2 Answers
I believe you can use the EXT_shader_framebuffer_fetch extension for this.
In OpenGL ES 2.x the usage is something like this (silly shader I know, just for example):
#extension GL_EXT_shader_framebuffer_fetch : require
precision mediump float;
void main()
{
gl_FragColor = gl_LastFragData[0] * 0.5;
}
In OpenGL ES 3.x the usage is something like this:
#version 300 es
#extension GL_EXT_shader_framebuffer_fetch : require
precision mediump float;
inout vec4 fragColor;
void main()
{
fragColor = fragColor * 0.5;
}
-
I tried both versions but unfortunately I always get the same message with 'GL_ARB_fragment_coord_conventions' is not supported. It seems so as you mentioned that's something with Qt settings. I also wondering why I can't found this package on my smartphones with opengl es +3.1, probable they are already included in the core package?– PowerNowDec 12, 2019 at 11:57
-
Is it a warning or an error, though? If it's a warning then you can just ignore it.– AndreaDec 12, 2019 at 16:44
-
Here from my console...
W Camara : QOpenGLShader::compile(Fragment): 1:2: P0003: Warning: Extension 'GL_ARB_fragment_coord_conventions' not supported
W Camara : 4:1: P0003: Extension 'GL_EXT_shader_framebuffer_fetch' not supported
W Camara : *** Problematic Fragment shader source code ***
W Camara : #version 300 es
W Camara : #ifdef GL_KHR_blend_equation_advanced
W Camara : #extension GL_ARB_fragment_coord_conventions : enable
W Camara : #extension GL_KHR_blend_equation_advanced : enable
W Camara : #endif
W Camara : #ifndef GL_FRAGMENT_PRECISION_HIGH
W Camara : #define highp mediump
W Camara : #endif
W Camara : #line 1
W Camara : #extension GL_EXT_shader_framebuffer_fetch : require