Shaders White fill shader that gradually increases opacity?

Discussion in 'Programming' started by Divinik, Jun 11, 2019.

  1. Divinik

    Divinik Member

    Sep 25, 2017
    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?
  2. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Jun 20, 2016
    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: Jun 12, 2019
  3. Divinik

    Divinik Member

    Sep 25, 2017
    Got it done man, thanks!

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice