Default value for uniform?

Can uniforms use a default value, so that if the uniform is not set, a default value will be used? This would be very convenient.

I think this should be done in your application before using a program calling glUniform* with the current default values.

That is gay.

Spec 2.1 page 79:

“When a program is successfully linked, all active uniforms belonging to the program object are initialized to zero (FALSE for booleans).”

Note: in the spec, the term “initial” is preferred over “default”. Once you know that, searching in this document is much easier.

Your question is malformed I think. Default values in a shader doesn’t make sense while the shader has no idea of what default values you need. This should be set in your application

Like overlay said, I think you are more talking about INITIAL values and I don’t think you should rely on it, since default values may match initial values…
Maybe you should expose us why this is so important for you.

Initial, like this:

uniform float bloomstrength = 1.0;

It would avoid a lot of errors when a user forgets to set a required value in a post-filter. If you are writing a real quick test program maybe you don’t want to have to remember to set a bunch of values, or maybe you will forget one of them because you don’t care what they are, and then you spend time trying to figure out where the “bug” is.

As dletozeun said, it’s meaningless for GL to have this, you could implement it your own in your shadermanager-whatever class at shader loading time.

Besides specifying the source you could also specify a section which has uniform names, their types and their default values. Then when you compile-link the shader, set also whatever uniforms exist in that section.

In GLSL v1.20 uniforms can use default value: http://ogltotd.blogspot.com/2007/12/default-uniform-values.html

Bitchin’!

Hmmmm, I wonder if people still think this feature is “meaningless”?

In GLSL 1.20 all uniforms, except for samplers, can have an initializer,

I like that. But I wonder, why samplers are excluded. Usually, you set them one-time and to always the same value (i.e. the texture unit you want to use). In my case, I tend to number them from 0 to n.

Instead, the ATI driver tends to complain after linking (before I had the chance to initialize the sampler uniforms), that two diferrent samplers (2D and cubemap) use the same texture unit. :-/

Your question is malformed I think. Default values in a shader doesn’t make sense while the shader has no idea of what default values you need. This should be set in your application

In my opinion, the shader is the best place to set default values, since the shader has the best idea of what it is doing. Usually, the application has no idea what a user-provided shader is doing, so how would it initialize meaningful default values without having extra meta iformation about the shader?

As dletozeun said, it’s meaningless for GL to have this, you could implement it your own in your shadermanager-whatever class at shader loading time. Besides specifying the source you could also specify a section which has uniform names, their types and their default values. Then when you compile-link the shader, set also whatever uniforms exist in that section.

So you want everyone to implement some kind of effect framework, just to set uniforms to default values?

On the other hand, uniforms (except samplers) are values that are suppoed to change regularly. And the code that does those changes (i.e. the application) must have some kind of idea when, how and why to change them. And if that code exists anyway, why not call it just once after the shader got loaded up?

To sum itup, I think, default values for uniforms are useful and impose no burden on the opengl driver.

This is just my opinion, but if you declare uniforms in a shader these are application parameters. This is a way for communicating between a shader and a opengl program.
If you don’t want to communicate, you simply don’t set the variable as uniforms.
This way I think that the application should know uniforms parameters as well as the shader itself. The shader is just here to do a specific task, but don’t know the purpose of this one which depend on the application state, and thus uniforms.

I mean that following your opinion the shader is bound to the application and you would have to rewrite the shader for each specific program that use it but don’t need the same default values.

When you put default values in the application, the developers don’t even have to know the shader language used, but just need a knowlegde of the opengl API to set uniforms that are the interface between the program and the shader.

I like that. But I wonder, why samplers are excluded. Usually, you set them one-time and to always the same value (i.e. the texture unit you want to use). In my case, I tend to number them from 0 to n.

Yeah, I finally learned to just call them texture0-texturen and let the shader loader automatically set them. You are right, it should be allowed to just set the values in the shader.

This is just my opinion, but if you declare uniforms in a shader these are application parameters. This is a way for communicating between a shader and a opengl program.
If you don’t want to communicate, you simply don’t set the variable as uniforms.
This way I think that the application should know uniforms parameters as well as the shader itself. The shader is just here to do a specific task, but don’t know the purpose of this one which depend on the application state, and thus uniforms.

I mean that following your opinion the shader is bound to the application and you would have to rewrite the shader for each specific program that use it but don’t need the same default values.

When you put default values in the application, the developers don’t even have to know the shader language used, but just need a knowlegde of the opengl API to set uniforms that are the interface between the program and the shader.

Face it, you just got PWNED!!!

LOL! :smiley: And you will soon face your misconception problem.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.