Example/Dynamically Uniform Expression: Difference between revisions
< Example
Dynamically uniform expressions examples |
No edit summary |
||
(3 intermediate revisions by one other user not shown) | |||
Line 13: | Line 13: | ||
void main() | void main() | ||
{ | { | ||
foo; //constant expressions are dynamically uniform. | foo; // constant expressions are dynamically uniform. | ||
uint value = 21; //value is dynamically uniform. | uint value = 21; // 'value' is dynamically uniform. | ||
value = range.x; //still dynamically uniform. | value = range.x; // still dynamically uniform. | ||
value = range.y + fromRange.y; //not dynamically uniform; current | value = range.y + fromRange.y; // not dynamically uniform; current contents come from a non-dynamically uniform source. | ||
value = 4; //dynamically uniform again. | value = 4; // dynamically uniform again. | ||
if(fromPrevious.y < 3.14) | if (fromPrevious.y < 3.14) | ||
value = 12; | value = 12; | ||
value; //NOT dynamically uniform. | value; // NOT dynamically uniform. Current contents depend on 'fromPrevious', an input variable. | ||
float number = abs(pairs.x); //number is dynamically uniform. | float number = abs(pairs.x); // 'number' is dynamically uniform. | ||
number = sin(pairs.y); //still dynamically uniform. | number = sin(pairs.y); // still dynamically uniform. | ||
number = cos(fromPrevious.x); //not dynamically uniform. | number = cos(fromPrevious.x); // not dynamically uniform. | ||
vec4 colors = texture(tex, pairs.xy); //dynamically uniform, even though it comes from a texture. | vec4 colors = texture(tex, pairs.xy); // dynamically uniform, even though it comes from a texture. | ||
//It uses the same texture coordinate, thus getting the same texel every time. | // It uses the same texture coordinate, thus getting the same texel every time. | ||
colors = texture(tex, fromPrevious.xy); //not dynamically uniform. | colors = texture(tex, fromPrevious.xy); // not dynamically uniform. | ||
for(int i = range.x; i < range.y; ++i) | for(int i = range.x; i < range.y; ++i) | ||
{ | { | ||
//loop initialized with, compared against, and incremented by dynamically uniform expressions. | // loop initialized with, compared against, and incremented by dynamically uniform expressions. | ||
i; //Therefore, | i; // Therefore, 'i' is dynamically uniform, even though it changes. | ||
} | } | ||
for(int i = fromRange.x; i < fromRange.y; ++i) | for(int i = fromRange.x; i < fromRange.y; ++i) | ||
{ | { | ||
i; // | i; // 'i' is not dynamically uniform; 'fromRange' is not dynamically uniform. | ||
} | } | ||
} | } | ||
</source> | </source> | ||
<noinclude>[[Category:Example Code]]</noinclude> |
Latest revision as of 11:17, 3 January 2018
This example code shows what are and are not dynamically uniform expressions.
in vec3 fromPrevious;
in uvec2 fromRange;
const int foo = 5;
const uvec2 range = uvec2(2, 5);
uniform vec2 pairs;
uniform sampler2d tex;
void main()
{
foo; // constant expressions are dynamically uniform.
uint value = 21; // 'value' is dynamically uniform.
value = range.x; // still dynamically uniform.
value = range.y + fromRange.y; // not dynamically uniform; current contents come from a non-dynamically uniform source.
value = 4; // dynamically uniform again.
if (fromPrevious.y < 3.14)
value = 12;
value; // NOT dynamically uniform. Current contents depend on 'fromPrevious', an input variable.
float number = abs(pairs.x); // 'number' is dynamically uniform.
number = sin(pairs.y); // still dynamically uniform.
number = cos(fromPrevious.x); // not dynamically uniform.
vec4 colors = texture(tex, pairs.xy); // dynamically uniform, even though it comes from a texture.
// It uses the same texture coordinate, thus getting the same texel every time.
colors = texture(tex, fromPrevious.xy); // not dynamically uniform.
for(int i = range.x; i < range.y; ++i)
{
// loop initialized with, compared against, and incremented by dynamically uniform expressions.
i; // Therefore, 'i' is dynamically uniform, even though it changes.
}
for(int i = fromRange.x; i < fromRange.y; ++i)
{
i; // 'i' is not dynamically uniform; 'fromRange' is not dynamically uniform.
}
}