• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders Cannot pass in uniform values to shaders

E

E.M.I

Guest
[RESOLVED] Hi! I'm trying to create a day-night cycle for my game. I plan to do this by using a shader to change the color of a transparent sprite that stretches across the whole room. Though for now, I'm only trying to pass in a uniform value that I'll use for the color. My code is:

In the Create event of my weather object:
Code:
spriteBlue = 255.0;
In the Draw event of my weather object:
Code:
spriteBlue -= 0.1;
shaderColor = shader_get_uniform(shd_weather, "spriteColor");
shader_set_uniform_f(shaderColor, 0, 0, 255.0);

shader_set(shd_weather);
draw_sprite_ext(spr_weather_overlay, -1, x, y, 1, 1, 0, c_white, 0.05);
shader_reset();
In my fragment weather shader (vertex shader is the default):

Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec3 spriteColor;

void main()
{
    vec4 originalColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
   
    gl_FragColor = vec4(spriteColor.r, spriteColor.g, spriteColor.b, originalColor.a);
}
I've tried changing it inside the shader and it works, so the issue is definitely the uniform vec3 spriteColor not being changed. Am I doing something wrong? Still very new to shaders in GMS2 so maybe it's a dumb mistake. Thanks a lot for the help in advance!
 
Last edited by a moderator:
You have spriteBlue which lowers, but you never actually use it... :p

I'd also just place the "get" in the Create event and set the uniform after the shader.
 
  • shader_get_uniform can be called in create event. Although thats not solving your Problem
  • shader_set_uniform_f must be called after shader_set and before draw_sprite_ext
  • You shouldnt set a constant but rather use spriteBlue in shader_set_uniform_f
  • shader colours range from 0 to 1, not 0 to 255. So spriteBlue should start at 1 and the decrement should be much smaller than 0.1
 
E

E.M.I

Guest
  • shader_get_uniform can be called in create event. Although thats not solving your Problem
  • shader_set_uniform_f must be called after shader_set and before draw_sprite_ext
  • You shouldnt set a constant but rather use spriteBlue in shader_set_uniform_f
  • shader colours range from 0 to 1, not 0 to 255. So spriteBlue should start at 1 and the decrement should be much smaller than 0.1
Thanks for the advice everyone! Now it works perfectly. Though I'm not sure what you mean about not using 0 to 255, it works regardless.
 
E

E.M.I

Guest
  • shader_get_uniform can be called in create event. Although thats not solving your Problem
  • shader_set_uniform_f must be called after shader_set and before draw_sprite_ext
  • You shouldnt set a constant but rather use spriteBlue in shader_set_uniform_f
  • shader colours range from 0 to 1, not 0 to 255. So spriteBlue should start at 1 and the decrement should be much smaller than 0.1
Nvm, I tested it out and get what you mean. Thanks a lot!!
 
Top