@Alfonse -
Dude.
I can post the code, if you feel it’s important.
The code works. If you’d read what I’ve written, I’m not asking for help with the code.
What I’m asking is if there is some other interrogative besides GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, or GL_MAX_UNIFORM_LOCATIONS, etc, which might define the number of independent (non-block) uniforms available.
That’s all I’m asking. It doesn’t require a code sample. All the code samples in the world aren’t going to provide an answer to the question.
Perhaps I didn’t state it clearly enough.
Is there some other parameter (besides the ones I’ve already mentioned) I might use with glGetxx, or getProgramiv, or some other interrogative, that would define a limit on the number of available uniform slots?
@arekkusu
Thanks - that’s helpful. glGetUniform is worth investigating. Like I said, though, if I limit the number of uniforms to 16, all work. If I add a 17th, it behaves as if it’s value is undefined - the one line of code where it’s used gives invalid results. If I remove a different uniform, returning the number of active uniforms to 16, the last one, the one that wouldn’t work when it was 17th in line, now works.
And since you seem to have actually read what I’ve written, here’s the code. This is the working variant - there are only 16 uniforms, and it works as intended. If I modify the code such that the array of floats ‘Weight[10]’ is a uniform, that will make a total of 17, and the last one assigned an index when the program is compiled is ‘White’, and I can no longer pass a value to it.
So. Is there some interrogative that would reveal a relevant limit to the number of uniforms available?
(And did seeing the code really help?)
[HR][/HR]
(EDIT - If there is no other relevant limit, I’ll look elsewhere for a problem. As I said, the implication seemed to be that there was some limit at 16 uniforms. (Just as the GPU in question limits the number of vertex attributes to 16.) Maybe that isn’t the issue, though - maybe it’s something else. And that’s fine - I’m willing to spend some time investigating. I just thought that maybe there was some defined limit that I was unaware of, and which one of you might know about.)
[HR][/HR]
#version 330 core
#pragma debug(on)
#pragma optimize(off)
in vec3 Position;
in vec3 Normal;
in vec2 TexCoords;
uniform int RenderPass;
uniform sampler2D HDRTex;
uniform sampler2D FilterTex;
uniform float White;
uniform float Exposure;
uniform float AveLum;
uniform float LumThreshold;
struct LightInfo
{
vec4 Position; // Light position in eye coords.
vec3 Intensity; // Light intensity
};
uniform LightInfo Light;
struct MaterialInfo
{
vec3 Ka; // Ambient reflectivity
vec3 Kd; // Diffuse reflectivity
vec3 Ks; // Specular reflectivity
float Shininess; // Specular shininess factor
};
uniform MaterialInfo Material;
layout( location = 0 ) out vec4 FragColor;
float Weight[10] = float[] (0.084612906, 0.082937457, 0.078107551, 0.070674635, 0.061441574,
0.051320318, 0.041185521, 0.031756159, 0.023525544, 0.016744783);
float PixOffset[10] = float[](0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0);
mat3 rgb2xyz = mat3(
0.4124564, 0.2126729, 0.0193339,
0.3575761, 0.7151522, 0.1191920,
0.1804375, 0.0721750, 0.9503041 );
mat3 xyz2rgb = mat3(
3.2404542, -0.9692660, 0.0556434,
-1.5371385, 1.8760108, -0.2040259,
-0.4985314, 0.0415560, 1.0572252 );
float luminance( vec3 color )
{
return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
}
vec3 phongModel( )
{
vec3 n = normalize( Normal );
vec3 s = normalize( vec3( Light.Position) - Position );
vec3 v = normalize( vec3(-Position));
vec3 total = vec3(0.0f, 0.0f, 0.0f);
vec3 r = reflect( -s, n );
//for (int i = 0; i < 3; i++)
total += (Light.Intensity * ( Material.Ka + Material.Kd * max( dot( s, n), 0.0 ) +
Material.Ks * pow( max( dot( r, v), 0.0 ), Material.Shininess ) ));
return(total);
}
void main()
{
vec4 texColor;
vec4 texColor2;
vec2 tc = TexCoords;
vec4 sum;
tc.x *= -1.0;
tc.x += 1.0;
switch(RenderPass)
{
case 1:
FragColor = vec4(phongModel(), 1.0);
break;
case 2:
texColor = texture(HDRTex, tc);
if (luminance(texColor.rgb) > LumThreshold)
FragColor = texColor;
else
FragColor = vec4(0.0);
break;
case 3:
float dy = 1.0 / (textureSize(FilterTex, 0)).y;
sum = texture(FilterTex, tc) * Weight[0];
for( int i = 1; i < 10; i++ )
{
sum += texture( FilterTex, tc + vec2(0.0,PixOffset[i]) * dy ) * Weight[i];
sum += texture( FilterTex, tc - vec2(0.0,PixOffset[i]) * dy ) * Weight[i];
}
FragColor = sum;
break;
case 4:
float dx = 1.0 / (textureSize(FilterTex,0)).x;
sum = texture(FilterTex, tc) * Weight[0];
for( int i = 1; i < 10; i++ )
{
sum += texture( FilterTex, tc + vec2(PixOffset[i],0.0) * dx ) * Weight[i];
sum += texture( FilterTex, tc - vec2(PixOffset[i],0.0) * dx ) * Weight[i];
}
FragColor = sum ;
break;
case 5:
///////////////// Tone mapping ///////////////
//// Retrieve high-res color from texture
vec4 color = texture( HDRTex, tc );
vec4 blurTex = texture(FilterTex, tc);
// Convert to XYZ
vec3 xyzCol = rgb2xyz * vec3( color);
// Convert to xyY
float xyzSum = xyzCol.x + xyzCol.y + xyzCol.z;
vec3 xyYCol = vec3( 0.0);
if( xyzSum > 0.0 ) // Avoid divide by zero
xyYCol = vec3( xyzCol.x / xyzSum, xyzCol.y / xyzSum, xyzCol.y);
// Apply the tone mapping operation to the luminance
// (xyYCol.z or xyzCol.y)
float L = (Exposure * xyYCol.z) / AveLum;
L = (L * ( 1.0 + L / (White * White) )) / ( 1.0 + L );
// Using the new luminance, convert back to XYZ
if( xyYCol.y > 0.0 )
{
xyzCol.x = (L * xyYCol.x) / (xyYCol.y);
xyzCol.y = L;
xyzCol.z = (L * (1.0 - xyYCol.x - xyYCol.y))/ xyYCol.y;
}
////// Convert back to RGB
vec4 toneMapColor = vec4(( xyz2rgb * xyzCol), 1.0);
/////////////// Combine with blurred texture /////////////
//// We want linear filtering on this texture access so that
//// we get additional blurring.
FragColor = toneMapColor + blurTex;
break;
}
}