cancel
Showing results for 
Search instead for 
Did you mean: 

OpenGL & Vulkan

dgholz
Adept I

Help needed working out why a uniform is not active when used to set gl_ClipDistance

Hello,

I'm using a Radeon RX 580 with version 18.9.3 of the drivers from AMD. I have a small shader that has some uniforms that do not get assigned a location, and I need help working out why they aren't/how to get them assigned to a location.

The vertex shader looks like this:

#version 430

in vec4 inVertex;

//out gl_PerVertex { vec4 gl_Position; float gl_PointSize; float gl_ClipDistance[2]; };

out float gl_ClipDistance[2];

uniform mat4 u_ModelView;

uniform mat4 u_Projection;

uniform vec4 u_plane0;

uniform vec4 u_plane1 = vec4(0,-1,0,0);

void main(){

    vec4 vsPos = u_ModelView * inVertex;

    gl_Position = u_Projection * vsPos;

    gl_ClipDistance[0] = dot(u_plane0, vsPos);

    gl_ClipDistance[1] = dot(u_plane1, vsPos);

}

I enable the clip planes before creating the shader like this:

for (int i = 0; i < 2; i++) {

    glEnable(GL_CLIP_DISTANCE0 + i);

}

The shader compiles without error, but when I call glGetUniformLocation(hShader, "u_plane0") I get -1 back (same for u_plane1). I don't understand exactly why the uniforms are not considered to be active, as gl_ClipDistance can definitely affect the rendered output. The commented-out gl_PerVertex line was me checking that I explicitly declared the size of gl_ClipDistance correctly (it doesn't affect the behaviour regardless of how I declare gl_ClipDistance, explicit or implicit).

When I roll back the drivers to before 18.7.1, the uniforms are assigned a location. Also if I leave the drivers at 18.9.3 and change the version to '#version 330'.

Can someone point me in the right direction to work out why these uniforms aren't assigned a location?

7 Replies
dgholz
Adept I

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

Whichever mod moved this to this forum: thank you!

xhuang
Staff
Staff

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

Hello,

Just to double-confirm that your shader works well under one of the following conditions?

  1. 18.7.1 with #version 430
  2. 18.9.3 with #version 330

Also, it'll be more efficient if you could share your source code with me, thanks.

dgholz
Adept I

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

I published a version of the code at GitHub - dgholz/AMDClipDistanceUniform: Demonstration code for https://community.amd.com/thread/2327...

This is a simplification of a bigger project which has weird behaviour with #version 460 shaders with drivers newer than 18.6.1. I think the inactive uniforms are the cause of it, so I wrote the above code to try to understand more about why the uniforms were not assigned a location.

Here's a combatibility matrix:

Driver Version    /    GLSL version ->#version 330#version 430
18.6.1Uniform got a locationUniform got a location
18.7.1Uniform got a locationNo location
18.9.3Uniform got a locationNo location

The bigger project didn't change any of the shader or app code; running a previous release with the later drivers causes the weird behaviour (and the associated inactive uniforms).

0 Likes
Reply
dgholz
Adept I

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

The original shader looks somewhat like this:

uniform vec2 uClipSplit;

...

void main() {

   ...

   gl_ClipDistance[1] = worldcoord.y - uClipSplit.x;

   gl_ClipDistance[2] = uClipSplit.y - worldcoord.y;

}

Where uClipSplit is set to vec2(-1000000.0, 1000000) by the app, and represents the height that in-app sprites should not be drawn below (for .x) or above (for .y). Since the uniform is not assigned a location, the app fails to set it to the correct value and it retains its default from GLSL of a vec2(0.0, 0.0), which causes all sprites to be clipped.

0 Likes
Reply
xhuang
Staff
Staff

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

Thanks for you information, that'll be very helpful. I will investigate the problem soon and get you back. Thanks again!

dgholz
Adept I

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

Another data point: I installed 18.10.1 and see that the uniform is always assigned a location, with both #version 330 and #version 430/440/450/etc. That matches what I think should happen. so I'm happy to use this version of the drivers.

0 Likes
Reply
xhuang
Staff
Staff

Re: Help needed working out why a uniform is not active when used to set gl_ClipDistance

Good to know that.

0 Likes
Reply