0

I have this vertex shader in GLSL which I'm using with a Qt3D custom effect/material:

attribute vec3 vertexPosition;
attribute vec3 vertexNormal;

varying vec3 worldPosition;
varying vec3 worldNormal;

uniform mat4 modelMatrix;
uniform mat3 modelNormalMatrix;
uniform mat4 modelViewProjection;

void main()
{
    worldNormal = normalize( modelNormalMatrix * vertexNormal );
    worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );

    gl_Position = modelViewProjection * vec4( vertexPosition, 1.0 );
}

I understand that the varying data (out data in newer versions if GLSL) is passed from my vertex shader to fragment shader.

Is it possible for me to go in-between vertex-fragment shaders and access the varying/out data in my C++ code? Is there any practical example which I can refer to?


My objective is to detect and get global/world positions with a specific condition, like having z which is larger than 10 like below. I need to be able to access these z > 10 positions on my C++ code.

// ...
varying vec3 higherThanTen;
// ...
void main()
{
    // ...
    if ( worldPosition.z > 10 ) {
        higherThanTen = worldPosition;
    }
    // ...
}
Megidd
  • 7,089
  • 6
  • 65
  • 142
  • @Rabbid76 I added my objective to my post – Megidd Dec 01 '18 at 12:46
  • 1
    The only thing what can be accessed is the depth buffer and the color buffer after the drawing has been finished (flushed). Are you searching for some kind of collision detection? It is still unclear what you want to do. Possibly you want to wirte something [Atomic](https://www.khronos.org/opengl/wiki/Atomic_Counter)? Or maybe you want to se the [Stencil buffer](https://www.khronos.org/opengl/wiki/Stencil_Test) on a certain condition? – Rabbid76 Dec 01 '18 at 13:07
  • @Rabbid76 Thanks! I'm going to study `Atomic` and `Stencil buffer`. Then I will revise my question to make it more clear. Thanks again :) – Megidd Dec 01 '18 at 13:19
  • 1
    If you are using OpenGL version >= 4.3 you can have a look at [this example](https://github.com/qt/qt3d/tree/5.11/tests/manual/buffercapture-qml). I think the minimum version of 4.3 comes from the compute shader. They only used this because they didn't need any actual 3D scene for this test and computed the data "offscreen". – Florian Blume Dec 04 '18 at 19:07
  • @FlorianBlume Thanks. I'm going to check it out. – Megidd Dec 05 '18 at 06:50
  • @FlorianBlume I tried to test [Qt3D buffer-capture approach](https://github.com/qt/qt3d/tree/5.11/tests/manual/buffercapture-qml) with older versions of OpenGL, but looks like that GLSL `buffer` qualifier can only be used on **OpenGL 4.3** and later as mentioned [here](https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Buffer) =( – Megidd Jan 21 '19 at 09:42

0 Answers0