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;
}
// ...
}