PDA

View Full Version : Some clarification needed regarding geometry shader



Lee_Jennifer_82
03-16-2016, 12:46 PM
I encountered some problem while using geometry shader. Usually input from the vertex shader should be passed via geometry shader (if used) to the fragment shader. But is it possible that geometry shader (when used in a program) can be bypassed and output from the vertex shader can be directly sent to fragment shader bypassing the geometry shader?

Any clarification will be highly appreciated.

Thanks in advance!

carsten neumann
03-18-2016, 10:46 AM
A shader program either contains a geometry stage or it does not. If it does contain a geometry stage you cannot disable that stage (without re-linking the program). You could either make two programs that contain the same vertex and fragment stages and one has a geometry stage while the other does not or alternatively use Separable Programs together with Program Pipeline objects, see Wiki: Separate Programs (https://www.opengl.org/wiki/Shader_Compilation#Separate_programs).

Lee_Jennifer_82
03-18-2016, 01:15 PM
Thank for the reply. Does the order of attachment among the shaders matter? For example, instead of writing as follows:



//Attach the shaders to their respective programs
glAttachShader(vertexProgram , vertShader);
glAttachShader(geomFragProgram, geomShader);
glAttachShader(geomFragProgram, fragShader);


Is it okay to write like the following:


glAttachShader(vertexProgram , vertShader);
glAttachShader(geomFragProgram, fragShader);
glAttachShader(geomFragProgram, geomShader);


I'm asking as I've encountered an unusual problem. Geometry shader is attached after the fragment shader as mentioned above. And the output from the vertex shader does not go through the geometry shader to fragment shader. In one platform when I run the program, it shows the following linking error (What I consider should be right):

Linking program
The fragment shader uses varying Position, but previous shader does not write to it.
The fragment shader uses varying Normal, but previous shader does not write to it.


In another platform it works fine, without showing any error.How can this work?

I'm very much confused. Any clarification/ explanation will be highly appreciated!

Alfonse Reinheart
03-18-2016, 01:31 PM
Geometry shader is attached after the fragment shader as mentioned above.

Exactly how much "as mentioned above"? Because "above" contains an obvious issue: you're not linking the vertex shader into the same program as the fragment and geometry shaders.

So unless you're using separate programs, that code shouldn't work.

So if that's not your actual code, show us your actual code.

Lee_Jennifer_82
03-18-2016, 03:25 PM
Two separate programs were used:



programOne = shaderLoad("shader.vs", "shader.fs", "geometry.gs"); // fragment shader before geometry shader
programTwo = shaderLoad("shaderOne.vs", "shader.fs");



For programOne, the follwoing order maintained:



glAttachShader(programOne , vertShader);
glAttachShader(programOne, fragShader);
glAttachShader(programOne, geomShader);


For programTwo, we did as usual (there was no geometry shader):


glAttachShader(programTwo , vertShader);
glAttachShader(programTwo, fragShader);


The first one (programOne) is supposed to render the points to display normals through geometry shaders.
The second one (programTwo) displays the original model.
One thing to note, same fragment shader is used in both programs.

Now, programOne just pass the points from vertex shader to geometry shader to display normals, but does not forward position, normal etc from geometry shader to fragment shader which deal with basically lighting/shading issue. So I got linking errors as mentioned above which I'm supposed to. And no normal is displayed.

But in another platform, it is working fine (shows normals) without showing any linking error which it should not be for programOne.
Here one thing to note that fragment shader just deal with lighting issue, but when geometry shader is used, those normals, position were not forwarded via geometry shader to fragment shader. While dealing with displaying normals, main issue with the fragment shader is to just color the normals.

I'm confused whether the problem is something with OpenGL version or graphics platform.

Lee_Jennifer_82
03-21-2016, 02:30 PM
It seems to me some thing goes with the version. OpenGL 4.5 allows vertex shader output to be bypassed by the geometry shader (even when geometry shader is linked) and fragment shader can work with directly from the geometry shader though no output from geometry shader to fragment shader is made. But with OpenGL 4.3 it shows linking error as I mentioned above. Any way, I'd like to hear from others regarding this whether I'm right or not.
Thank you!

Lee_Jennifer_82
03-28-2016, 11:51 PM
Hello, I didn't get any clarification. I'd like to hear from others whether they have similar problem or I am wrong.
Thanks in advance.

poll john poll
04-02-2016, 03:06 AM
I've encountered some unusual problem. Geometry shader is not set to NULL. In one platform when I run the program, it shows the following linking error:

Linking program
The fragment shader uses varying Position, but previous shader does not write to it.
The fragment shader uses varying Normal, but previous shader does not write to it.


In another platform it works fine, without showing any error. (https://shiromaniakalidalofficial.blog.com)

I'm very much confused.