Does PVRShaderEditor support gl_LastFragData?

Greetings,

trying to compile a simple gl_LastFragData example with PVRShaderEditor 2.12, but it doesn’t seem to recognize gl_LastFragData. Is this normal?

#version 310 es
#extension GL_EXT_shader_framebuffer_fetch : require
precision mediump float;
uniform sampler2D sampler;
in vec2 textureCoordinate;
out vec4 fragmentColor;

void main()
{   
	fragmentColor = texture(sampler, textureCoordinate) + gl_LastFragData;
}

ERROR: 15:0: ‘gl_LastFragData’ : undeclared identifier
Compile failed.

Regards

Hi desperado,

Many thanks for your message, we’ll look into the issue you’re experiencing and come back to you soon,

Best regards,
Alejandro

Hi desperado,

According to the GL_EXT_shader_framebuffer_fetch specification, in ES 3.0 the built-in gl_LastFragData output is replaced by user-declared outputs marked with the ‘inout’ keyword:

#version 310 es
#extension GL_EXT_shader_framebuffer_fetch : require
precision mediump float;
uniform sampler2D sampler;
in vec2 textureCoordinate;

layout(location = 0) inout vec4 fragmentColor; 

void main()
{   
	fragmentColor = texture(sampler, textureCoordinate) + fragmentColor;
}

Regards,
Dihara

Greetings,

thanks. Can you tell me if the

layout(location = 0) 

qualifier is mandatory for it to work correctly? I try to discard pixels based on the alpha value of the framebuffer pixel.

flat vec4 vColor;
...
if ( vColor.a < color.a ) discard;

This works on PVRTaceGUI 3.13 but not on PowerVR GX6250.

Ok, it seems that color.a always returns 0 on PowerVR GX6250 no matter what the alpha in the framebuffer is. Any more ideas?

#version 300 es
#extension GL_EXT_shader_framebuffer_fetch : require
precision highp float;
uniform lowp vec4 u_color;
flat in  vec4 vColor;
inout vec4 color;

void main()
{
	if ( vColor.a < color.a ) discard;
    color = vColor;
}

Hi desperado,

Firstly, you might find inaccuracies in PVRTrace as we’ve stopped supporting it in favour of PVRCabon, which is a feature expanded version of Trace. You might find more accurate information while using that.

Looking into the alpha value issue there are a couple of potential things that might be the issue, do you know the texture format of your framebuffer? if for example it’s sRGB the framebuffer wouldn’t store an alpha channel and so when you cast it to a vec4 vColor.a will always be 0.
The other potential cause could be that blending is not enabled, and there might be a driver optimisation that uses the alpha value to blend the colours in the framebuffer and then discard them, if your framebuffer has an alpha channel and you’re still not getting any information from the fragment shader try enabling blending with:

     glEnable(GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Hopefully this might help resolve your issues
All the best,
Lawrence

Hello,

I render into an FBO. The setup code is as follows if it helps:

#407 glBindFramebuffer(GL_FRAMEBUFFER,1) Error: GL_NO_ERROR
#408 glGenTextures(1,1) Error: GL_NO_ERROR
#409 glActiveTexture(GL_TEXTURE7) Error: GL_NO_ERROR
#410 glBindTexture(GL_TEXTURE_2D,1) Error: GL_NO_ERROR
#411 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,1280,640,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL) Error: GL_NO_ERROR
#412 glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,1,0,4) Error: GL_NO_ERROR
#413 glGenTextures(1,2) Error: GL_NO_ERROR
#414 glBindTexture(GL_TEXTURE_2D,2) Error: GL_NO_ERROR
#415 glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH24_STENCIL8,1280,640,0,GL_DEPTH_STENCIL,GL_UNSIGNED_INT_24_8,NULL) Error: GL_NO_ERROR
#416 glGenRenderbuffers(1,1) Error: GL_NO_ERROR
#417 glBindRenderbuffer(GL_RENDERBUFFER,1) Error: GL_NO_ERROR
#418 glRenderbufferStorageMultisample(GL_RENDERBUFFER,4,GL_DEPTH24_STENCIL8,1280,640) Error: GL_NO_ERROR
#419 glGetRenderbufferParameteriv(GL_RENDERBUFFER,GL_RENDERBUFFER_SAMPLES,4) Error: GL_NO_ERROR
#420 glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,1) Error: GL_NO_ERROR
#421 glGetError() ==> GL_NO_ERROR Error: GL_NO_ERROR
#422 glCheckFramebufferStatus(GL_FRAMEBUFFER) ==> GL_FRAMEBUFFER_COMPLETE Error: GL_NO_ERROR
#423 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT) Error: GL_NO_ERROR
#424 eglGetCurrentSurface(EGL_READ) ==> EGLSurface(0x7fac47c090) Error: EGL_SUCCESS
#425 eglGetCurrentSurface(EGL_DRAW) ==> EGLSurface(0x7fac47c090) Error: EGL_SUCCESS
#426 eglGetError() ==> EGL_SUCCESS Error: EGL_SUCCESS
#427 eglGetCurrentSurface(EGL_READ) ==> EGLSurface(0x7fac47c090) Error: EGL_SUCCESS
#428 eglGetCurrentSurface(EGL_DRAW) ==> EGLSurface(0x7fac47c090) Error: EGL_SUCCESS
#429 eglGetCurrentContext() ==> EGLContext(0x7fac26ad80) Error: EGL_SUCCESS

I want the new pixel alpha value to completely replace the value in the framebuffer if the new pixel is not discarded. That would be

glBlendFunc(GL_ONE, GL_ZERO);

Right? Would it still work then?

Hi,

Looking at the example for version 300es here it looks like the following qualifier is required:

layout(location = 0)

I need to correct a previous statement, following the example at this page; blending should actually be actively disabled, this is because we’re doing the blending manually in the fragment stage.

glDisable(GL_BLEND);

All the best,
Lawrence

Looking around I’ve seen some other people experiencing getting all 0’s on other vendor’s hardware. is it just the alpha channel giving all 0s? are you able to get any input from the other colour channels? If you find that the problem still persists you can open a ticket with us here, and we can analyse the application to remove some of the guess work.
(Apologies for splitting the reply)

So I disabled the blending and added the layout qualifier. Makes no difference, the pixels with supposedly lower alpha are still not discarded. Any more ideas?

I already opened a ticket with reference 1163 btw.

Thank you for the ticket reference, I’ve sent a reply and hopefully we can resolve the issue there.
Thank you