🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

glsl u_time

Started by
12 comments, last by MikeCyber 4 years, 2 months ago

Hi, why is the color not animated:

#ifdef GL_ES

precision mediump float;

#endif

uniform vec2 u_resolution;

uniform float u_time;

vec3 colorA = vec3(0.912,0.411,0.288);

vec3 colorB = vec3(1.000,0.833,0.224);

void main() {

vec3 color = vec3(0.0);

float pct = abs(sin(u_time));

// Mix uses pct (a value from 0-1) to

// mix the two colors

color = mix(colorA, colorB, pct);

gl_FragColor = vec4(color,1.0);

}

Many thanks

Advertisement

sigh let's do this step by step:

Print out the values of abs(sin(u_time)) in your application and report outcome.

I've just installed nvdia nsight but have not found out how to step throught the shaders.

How to print out the value?

Thanks

You don't need nvidia insight or step through the shader. Just print out abs(sin(time)) in the main loop of your application to see if it really oscillates between 0 and 1.

You must have the time value anyway because you need to update the uniform, so this is just a std::cout or printf.

Hint: The “problem” as actually visible with one short look. But we do it step by step just for the lulz.

in the main loop

printf(abs(sin(u_time)));

I get:

ERROR::SHADER_COMPILATION_ERROR of type: FRAGMENT

0(13) : error C1503: undefined variable "printf"

0(13) : error C1503: undefined variable "u_time"

-- --------------------------------------------------- --

ERROR::PROGRAM_LINKING_ERROR of type: PROGRAM

Fragment info

-------------

0(13) : error C1503: undefined variable "printf"

0(13) : error C1503: undefined variable "u_time"

(0) : error C2003: incompatible options for link

for the shader I use:

// build and compile our shader zprogram

Shader ourShader("4.2.texture.vs", "4.2.texture.fs");

why can't I set a breakpoint in nsight nor view values?

Thanks

You apparently don't know the difference between a shader program and the calling application. The shader has no main loop, it is being called from outside the loop of your application. printf is not a glsl but a c function. Apart from that, pls. read up on shader uniforms. You must set the value of u_time (it is a uniform) in the shader from out of your application, it is not a built-in of glsl.

The mix function is actually used very often. Get one ready for use in C or C++ (the OpenGL documentation has the trivial formula), so you can test things like these from outside of your application. That would have shown you that it works, but little happens, because with the given values it interpolates between two very similar colours and the difference is not easily recognizable.

MikeCyber said:
Hi, why is the color not animated:

Works for me, shifts from yellow to reddish.

@Green_Baron I don't know if he has an app. Looks like it's an online tut for shaders only. https://thebookofshaders.com/glossary/?search=mix

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

It seems to me like he's copied together stuff from learnopengl .com, e.g.

 // build and compile our shader zprogram
Shader ourShader("4.2.texture.vs", "4.2.texture.fs");

and the book of shaders.

Interesting though that you see a change, it's only the green channel that changes and i had to choose two more distinctive colors to atcually realize something.

Will take this as an excuse to buy me a new monitor when the shops open again. Something huge :-)

it interpolates between two very similar colours and the difference is not easily recognizable

The difference between the two colors seems pretty big to me:

vec3 colorA = vec3(0.912,0.411,0.288);

vec3 colorB = vec3(1.000,0.833,0.224);

I think it's much more likely that the value of u_time either doesn't change, or it doesn't change ENOUGH.

One way to debug this is to temporarily replace u_time with 0.0, 0.5, and 1.0 as example inputs, and see if the color is different. Another would be to use something like abs(sin(u_time*10)) to make it change faster.

A third way to debug this would be to set the output color to something like (u_time*0.01, u_time, u_time * 100.0, 1.0) and see what the color channels come out as.

As for why u_time might not change, or not change enough, that's up to the hosting application. If you're using some kind of shader editor online, you have to look at the documentation for that application.

enum Bool { True, False, FileNotFound };

Yeah, the uniform doesn't change. That's where i wanted to go with him with debugging stepwise. But printf in the shader drove me off.

I tried the colour change with a text shader i just had open, and believe it or not, the difference between the two colours is only very hard to see with text in small letters over a foggy landscape :-)

This topic is closed to new replies.

Advertisement