Sign in to follow this  
Yours3!f

OpenGL opengl 4 tessellation linker error

Recommended Posts

Hi,

I'm trying to do some basic tessellation, but I've ran into a strange problem. My glsl code compiles fine, but when I try to render some geometry with it, I get the invalid operation error. I tried to debug this issue with gdebugger, and interestingly it gives me a AP_PROGRAM_LINK_FAILED_ERROR. This is strange because I do check if the linking went right (GL_LINK_STATUS), and I get no errors even if I directly check the linking with glGetError. The geometry that I tried to render works fine with other shaders.
I followed this tutorial: [url="http://prideout.net/blog/?p=48"]http://prideout.net/blog/?p=48[/url]

Here's the glsl code:
[CODE]
[vertex shader]
#version 410

in vec4 in_vertex; //incoming vertex attribute in object space

out cross_shader_data
{
vec3 position;
} o;

void main()
{
o.position = in_vertex.xyz; //pass the data to the TC shader
}

[tessellation control shader]
#version 410

layout(vertices = 3) out; //a patch should consist of 3 vertices, thus essentially defining a vertex

in cross_shader_data
{
vec3 position;
} i[];

out cross_shader_data
{
vec3 position;
} o[];

uniform float tess_level_inner;
uniform float tess_level_outer;

void main()
{
o[gl_InvocationID].position = i[gl_InvocationID].position; //pass the vertex data to the TE shader

if(gl_InvocationID == 0) //define tessellation levels
{
gl_TessLevelInner[0] = tess_level_inner;

gl_TessLevelOuter[0] = tess_level_outer;
gl_TessLevelOuter[1] = tess_level_outer;
gl_TessLevelOuter[2] = tess_level_outer;
}
}

[tessellation evaluation shader]
#version 410

layout(triangles, equal_spacing, ccw) in; //process triangles, using equal spacing, and they'll be in counter-clockwise order

in cross_shader_data
{
vec3 position;
} i[];

out cross_shader_data
{
vec3 position;
vec3 patch_distance;
} o;

uniform mat4 modelviewproj;

void main()
{
vec3 p0 = gl_TessCoord.x * i[0].position;
vec3 p1 = gl_TessCoord.y * i[1].position;
vec3 p2 = gl_TessCoord.z * i[2].position;

o.patch_distance = gl_TessCoord;
o.position = normalize(p0 + p1 + p2); //create the new vertex
gl_Position = modelviewproj * vec4(o.position, 1); //do the transformation before passing to the geometry shader
}

[geometry shader]
#version 410

layout(triangles) in; //process triangles
layout(triangle_strip, max_vertices = 3) out; //spit out triangle strips that consist of max 3 vertices

in cross_shader_data
{
vec3 position;
vec3 patch_distance;
} i[3];

out cross_shader_data
{
vec3 face_normal;
vec3 patch_distance;
vec3 tri_distance;
} o;

uniform mat3 normal_mat;

void main()
{
vec3 a = i[2].position - i[0].position;
vec3 b = i[1].position - i[0].position;
o.face_normal = normal_mat * normalize(cross(a, b)); //transform face normal into view space

o.patch_distance = i[0].patch_distance;
o.tri_distance = vec3(1, 0, 0);
gl_Position = gl_in[0].gl_Position;
EmitVertex();

o.patch_distance = i[1].patch_distance;
o.tri_distance = vec3(0, 1, 0);
gl_Position = gl_in[1].gl_Position;
EmitVertex();

o.patch_distance = i[2].patch_distance;
o.tri_distance = vec3(0, 0, 1);
gl_Position = gl_in[2].gl_Position;
EmitVertex();
}

[pixel shader]
#version 410

in cross_shader_data
{
vec3 face_normal;
vec3 tri_distance;
vec3 patch_distance;
} i;

out vec4 color;

float amplify(float d, float scale, float offset)
{
d = scale * d + offset;
d = clamp(d, 0, 1);
d = 1 - exp2(-2 * d * d);
return d;
}

void main()
{
vec3 n = normalize(i.face_normal);
vec3 l = vec3(0, 1, 0);

float ndotl = max(dot(n, l), 0);

vec3 result = ndotl * vec3(1, 1, 1); //do some lighting

float d1 = min(min(i.tri_distance.x, i.tri_distance.y), i.tri_distance.z);
float d2 = min(min(i.patch_distance.x, i.patch_distance.y), i.patch_distance.z);

result *= amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5); //just some edge outlining

color = vec4(result, 1);
}
[/CODE]

Best regards,
Yours3!f Edited by Yours3!f

Share this post


Link to post
Share on other sites
Hi!

For some reason passing structs between shader stages doesn’t work anymore (at least the way you/I did it…). At some point it did. I remember it fairly well, since I was very happy to see that GLSL finally allowed it, too (like HLSL). But with current drivers it doesn’t work anymore. I had to rewrite some of my old shaders, too. Maybe it just wasn’t specification compliant and only nVidia drivers allowed it.

If you follow the tutorial you linked above, you should be fine. So, something like:
[CODE]in vec3 i_position[];
out vec3 o_position[];[/CODE]
And so on.

And yes, I was also confused that the GLSL compiler doesn't complain at all.

Cheers!

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1336123109' post='4937325']
Hi!

For some reason passing structs between shader stages doesn’t work anymore (at least the way you/I did it…). At some point it did. I remember it fairly well, since I was very happy to see that GLSL finally allowed it, too (like HLSL). But with current drivers it doesn’t work anymore. I had to rewrite some of my old shaders, too. Maybe it just wasn’t specification compliant and only nVidia drivers allowed it.

If you follow the tutorial you linked above, you should be fine. So, something like:
[CODE]in vec3 i_position[];
out vec3 o_position[];[/CODE]
And so on.

And yes, I was also confused that the GLSL compiler doesn't complain at all.

Cheers!
[/quote]

Thank you Tsus for the reply [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I tried to convert the interface blocks to traditional in-outs but somethings still wrong... What am I missing?

drivers... I even made a segfault to the compiler while converting the shaders... (I mean it segfaulted when linking, and the last function in the stack was somewhere in the catalyst drivers... 12.4 64bit linux)

this is how the shaders look like now:
[CODE]
[vertex shader]
#version 410
in vec4 in_vertex;
out vec3 v_position;
void main()
{
v_position = in_vertex.xyz;
}
[tessellation control shader]
#version 410
layout(vertices = 3) out;
in vec3 v_position[];
out vec3 tc_position[];
uniform float tess_level_inner;
uniform float tess_level_outer;
void main()
{
tc_position[gl_InvocationID] = v_position[gl_InvocationID];
if(gl_InvocationID == 0)
{
gl_TessLevelInner[0] = tess_level_inner;
gl_TessLevelOuter[0] = tess_level_outer;
gl_TessLevelOuter[1] = tess_level_outer;
gl_TessLevelOuter[2] = tess_level_outer;
}
}
[tessellation evaluation shader]
#version 410
layout(triangles, equal_spacing, ccw) in;
in vec3 tc_position[];
out vec3 te_position;
out vec3 te_patch_distance;
uniform mat4 modelviewproj;
void main()
{
vec3 p0 = gl_TessCoord.x * tc_position[0];
vec3 p1 = gl_TessCoord.y * tc_position[1];
vec3 p2 = gl_TessCoord.z * tc_position[2];

te_patch_distance = gl_TessCoord;
te_position = normalize(p0 + p1 + p2);
gl_Position = modelviewproj * vec4(te_position, 1);
}
[geometry shader]
#version 410
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in vec3 te_position[3];
in vec3 te_patch_distance[3];
out vec3 g_face_normal;
out vec3 g_patch_distance;
out vec3 g_tri_distance;
uniform mat3 normal_mat;
void main()
{
vec3 a = te_position[2] - te_position[0];
vec3 b = te_position[1] - te_position[0];
g_face_normal = normal_mat * normalize(cross(a, b));

g_patch_distance = te_patch_distance[0];
g_tri_distance = vec3(1, 0, 0);
gl_Position = gl_in[0].gl_Position;
EmitVertex();

g_patch_distance = te_patch_distance[1];
g_tri_distance = vec3(0, 1, 0);
gl_Position = gl_in[1].gl_Position;
EmitVertex();

g_patch_distance = te_patch_distance[2];
g_tri_distance = vec3(0, 0, 1);
gl_Position = gl_in[2].gl_Position;
EmitVertex();
}
[pixel shader]
#version 410
in vec3 g_face_normal;
in vec3 g_tri_distance;
in vec3 g_patch_distance;
out vec4 color;
float amplify(float d, float scale, float offset)
{
d = scale * d + offset;
d = clamp(d, 0, 1);
d = 1 - exp2(-2 * d * d);
return d;
}
void main()
{
vec3 n = normalize(g_face_normal);
vec3 l = vec3(0, 1, 0);

float ndotl = max(dot(n, l), 0);

vec3 result = ndotl * vec3(1, 1, 1);

float d1 = min(min(g_tri_distance.x, g_tri_distance.y), g_tri_distance.z);
float d2 = min(min(g_patch_distance.x, g_patch_distance.y), g_patch_distance.z);

result *= amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5);

color = vec4(result, 1);
}
[/CODE]

Best regards,
Yours3!f Edited by Yours3!f

Share this post


Link to post
Share on other sites
Hi!

The code you posted worked fairly well. I just changed some minor things to make it fit to my demo app, here.
In particular, I used explicit vertex attribute binding in the vertex shader:
[CODE]layout(location=0) in vec3 in_vertex;[/CODE]

For all uniform parameters I utilized a uniform buffer object, e.g.:
[CODE]layout(std140) uniform TessFactor
{
float tess_level_inner;
float tess_level_outer;
};[/CODE]

Eventually, I removed the normalization of te_position in your tessellation evaluation shader (barycentric interpolation doesn't require it).
[CODE]//te_position = normalize(p0 + p1 + p2);
te_position = p0 + p1 + p2;[/CODE]

It works on my end. I tested on a GeForce 460 GTX (Win 7, 64 Bit).

Good luck! Hopefully you find a way to get it running, too.
Best regards

Share this post


Link to post
Share on other sites
just a couple of questions in connection with your modifications:

[quote name='Tsus' timestamp='1336296166' post='4937734']
The code you posted worked fairly well. I just changed some minor things to make it fit to my demo app, here.
In particular, I used explicit vertex attribute binding in the vertex shader:
[CODE]layout(location=0) in vec3 in_vertex;[/CODE]
[/quote]

I use special "shader controller" files for this :) so I don't have to worry about which attribute belong to which location.

[quote]For all uniform parameters I utilized a uniform buffer object, e.g.:
[CODE]layout(std140) uniform TessFactor
{
float tess_level_inner;
float tess_level_outer;
};[/CODE]
[/quote]

is that a performance win, or you just like to use uniforms this way?

[quote]
Eventually, I removed the normalization of te_position in your tessellation evaluation shader (barycentric interpolation doesn't require it).
[CODE]//te_position = normalize(p0 + p1 + p2);
te_position = p0 + p1 + p2;[/CODE]
[/quote]

yeah I still need to dig deeper into the barycentric coordinates...

[quote]It works on my end. I tested on a GeForce 460 GTX (Win 7, 64 Bit).[/quote]

I guess this is the relevant bit. I have an AMD Radeon HD 5670 (Linux, 64 bit, same problem on Win 7 64 bit with same drivers) with newest drivers. So can you please verify the code on AMD as well? Because if thats the problem, then I guess I should contact the AMD dev guys to fix this...

Share this post


Link to post
Share on other sites
Hi,

I did the modifications only to get the code running in a small tessellation exercise I wrote a while back. I didn’t want to change much on the CPU side, so I just used the uniform buffer objects that were passed in already.
On the CPU side I didn’t specify the attribute binding, so I had to do it in GLSL. Doing this in GLSL is just a personal favor.

[quote name='Yours3!f' timestamp='1336304020' post='4937748']
[quote name='Tsus' timestamp='1336296166' post='4937734']
For all uniform parameters I utilized a uniform buffer object, e.g.:
[CODE]layout(std140) uniform TessFactor
{
float tess_level_inner;
float tess_level_outer;
};[/CODE]
[/quote]
is that a performance win, or you just like to use uniforms this way?
[/quote]
I think the performance win isn’t that big. It’s more that I like that sort of grouping as it reminds me of constant buffers in Dx.

[quote name='Yours3!f' timestamp='1336304020' post='4937748']
[quote name='Tsus' timestamp='1336296166' post='4937734']
It works on my end. I tested on a GeForce 460 GTX (Win 7, 64 Bit).
[/quote]
I guess this is the relevant bit. I have an AMD Radeon HD 5670 (Linux, 64 bit, same problem on Win 7 64 bit with same drivers) with newest drivers. So can you please verify the code on AMD as well? Because if thats the problem, then I guess I should contact the AMD dev guys to fix this...
[/quote]
Sorry, I neither have an AMD at home nor in the lab.
I attached the code so you can test it yourself.

Yes, you should probably report this to AMD if it turns out to be some sort of bug.

Cheers!

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1336306788' post='4937754']
Hi,

I did the modifications only to get the code running in a small tessellation exercise I wrote a while back. I didn’t want to change much on the CPU side, so I just used the uniform buffer objects that were passed in already.
On the CPU side I didn’t specify the attribute binding, so I had to do it in GLSL. Doing this in GLSL is just a personal favor.

[quote name='Yours3!f' timestamp='1336304020' post='4937748']
[quote name='Tsus' timestamp='1336296166' post='4937734']
For all uniform parameters I utilized a uniform buffer object, e.g.:
[CODE]layout(std140) uniform TessFactor
{
float tess_level_inner;
float tess_level_outer;
};[/CODE]
[/quote]
is that a performance win, or you just like to use uniforms this way?
[/quote]
I think the performance win isn’t that big. It’s more that I like that sort of grouping as it reminds me of constant buffers in Dx.

[quote name='Yours3!f' timestamp='1336304020' post='4937748']
[quote name='Tsus' timestamp='1336296166' post='4937734']
It works on my end. I tested on a GeForce 460 GTX (Win 7, 64 Bit).
[/quote]
I guess this is the relevant bit. I have an AMD Radeon HD 5670 (Linux, 64 bit, same problem on Win 7 64 bit with same drivers) with newest drivers. So can you please verify the code on AMD as well? Because if thats the problem, then I guess I should contact the AMD dev guys to fix this...
[/quote]
Sorry, I neither have an AMD at home nor in the lab.
I attached the code so you can test it yourself.

Yes, you should probably report this to AMD if it turns out to be some sort of bug.

Cheers!
[/quote]

Thank you [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] this saved me writing an example.

Well I had to do some modifications to get it running, but eventually it was running, so I guess I'm doing something wrong.
I've attached the modified code. (tessellation.dom, and Tessellation_end.cpp, plus file renamings and I added headers, libs and dlls) Edited by Yours3!f

Share this post


Link to post
Share on other sites
HEUREKA XD

SOLVED [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I examined your example, and found out one thing that's entirely different: how you draw your mesh.

so I just had to include the glPatchParameter function and change the glDrawElements from GL_TRIANGLES to GL_PATCHES... this is quite stupid... so this is what a working source does to me [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Thank your for the help!!! Edited by Yours3!f

Share this post


Link to post
Share on other sites
Hi,

just out of curiosity I tried the technique with interface blocks, and it worked, so that wasn't the problem [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] seems like the newest drivers are capable of this.

another thing is that the normalization in the tessellation evaluation shader IS needed, without it the geometry won't "emerge" out of the surface. (see pictures)

Share this post


Link to post
Share on other sites
Hi,

[quote name='Yours3!f' timestamp='1336324235' post='4937814']
just out of curiosity I tried the technique with interface blocks, and it worked, so that wasn't the problem [img]http://1.1.1.3/bmi/public.gamedev.net//public/style_emoticons/default/smile.png[/img] seems like the newest drivers are capable of this.
[/quote]
Nice! Thanks for the info! I’ll give it a try again, later.

[quote name='Yours3!f' timestamp='1336324235' post='4937814']
another thing is that the normalization in the tessellation evaluation shader IS needed, without it the geometry won't "emerge" out of the surface.
[/quote]
Wouldn't this only work for unit-spheres?
Most often, I just pick an easy tessellation scheme like [url="http://perso.telecom-paristech.fr/~boubek/papers/PhongTessellation/"]phong tessellation[/url]. Edited by Tsus

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1336328969' post='4937835']
[quote name='Yours3!f' timestamp='1336324235' post='4937814']
another thing is that the normalization in the tessellation evaluation shader IS needed, without it the geometry won't "emerge" out of the surface.
[/quote]
Wouldn't this only work for unit-spheres?
Most often, I just pick an easy tessellation scheme like [url="http://perso.telecom-paristech.fr/~boubek/papers/PhongTessellation/"]phong tessellation[/url].
[/quote]

hmmm... I don't know [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] well if no emerging happens then normalize otherwise don't. I'm not an expert in tessellation yet so I only wrote this by experience. Seems like for this scheme you do need normalization. Try it out with the elephant! Edited by Yours3!f

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1336333001' post='4937854']
Try it out with the elephant!
[/quote]
I did, that’s why I was asking. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I have the te_position in world space, thus normalizing it projects the elephant back on the unit sphere (looks funny [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]). If we’re trying to achieve a perfect sphere like in the example you linked, then sure, this is the best way to go, but in general it doesn’t seem right, I think.
Have you tried it with the elephant? (You probably have to change in the cpp-file the center to {0,0,0} and rStart to 10 in order to see something.)

Share this post


Link to post
Share on other sites
[quote name='Tsus' timestamp='1336335237' post='4937862']
[quote name='Yours3!f' timestamp='1336333001' post='4937854']
Try it out with the elephant!
[/quote]
I did, that’s why I was asking. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I have the te_position in world space, thus normalizing it projects the elephant back on the unit sphere (looks funny [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]). If we’re trying to achieve a perfect sphere like in the example you linked, then sure, this is the best way to go, but in general it doesn’t seem right, I think.
Have you tried it with the elephant? (You probably have to change in the cpp-file the center to {0,0,0} and rStart to 10 in order to see something.)
[/quote]

ummm... frankly? no I haven't XD but now I did and it does project back onto the unit sphere... is this a bug or feature >) ? Well you're right I guess.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627778
    • Total Posts
      2979025
  • Similar Content

    • By lonewolff
      Hi guys,
      With OpenGL not having a dedicated SDK, how were libraries like GLUT and the likes ever written?
      Could someone these days write an OpenGL library from scratch? How would you even go about this?
      Obviously this question stems from the fact that there is no OpenGL SDK.
      DirectX is a bit different as MS has the advantage of having the relationship with the vendors and having full access to OS source code and the entire works.
      If I were to attempt to write the most absolute basic lib to access OpenGL on the GPU, how would I go about this?
    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
  • Popular Now