• 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 White fill shader that gradually increases opacity?

Divinik

Member
Basically when the game initiates battle mode, I want all involved actors to fill white, and then swap to their battle mode objects. I just don't know how to change the alpha of the shader from gml, or how to set up the shader to allow me to get the alpha variable from the shader.

Any help?
 
hmm... alpha?

you should be able to transition between the sprite's true color (rgb, not rgba) and white using the mix() function. And you should be able to control that using a uniform variable.

varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float amount;
void main() {
vec4 base_colour = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor = vec4( mix( base_colour.rgb, vec3(1.0), amount ), base_colour.a );
}

In gml, to get a pointer to the shader uniform:
uniform_amount = shader_get_uniform(shader,"amount")
and set the uniform:
shader_set_uniform_f( shader_amount, some_amount );

Anything you draw after setting the shader and the "amount" unform, and before resetting the uniform or resetting the shader, will be drawn using those settings.


Apart from shaders, it is also possible to get the same effect using the built in fog system.
 
Last edited:

Divinik

Member
hmm... alpha?

you should be able to transition between the sprite's true color (rgb, not rgba) and white using the mix() function. And you should be able to control that using a uniform variable.

varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float amount;
void main() {
vec4 base_colour = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor = vec4( mix( base_colour.rgb, vec3(1.0), amount ), base_colour.a );
}

In gml, use
uniform_amount = shader_get_uniform(shader,"amount")
to get a pointer to the shader uniform
and set the uniform with
shader_set_uniform_f( shader_amount, some_amount );

Anything you draw after setting the shader and the "amount" unform, and before resetting the uniform or resetting the shader, will be drawn using those settings.


Apart from shaders, it is also possible to get the same effect using the built in fog system.
Got it done man, thanks!
 
Top