• 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 Greyscale Gradient Shader Transitions

NeoShade

Member
Hi all,

I've been using Gamemaker for years and I'm reasonably confident with GML, but I've very rarely touched shaders.

I found a fantastic tutorial on how to create a transition using a greyscale gradient image, which works perfectly as described, but I would like to expand upon it a little.

The tutorial is available here: https://gdpalace.wordpress.com/2017/10/07/transitions/

Currently, the system allows transitioning from a room into black (or white, or any other colour), but I'd like to transition directly into another room. I understand that to do this I'll need to have a persistent object save the current room as a sprite and then move to the next room before performing the transition, but how do I go about replacing the part of the shader responsible for drawing black pixels?

Hope that somebody can shed some light on this for me.

Thanks
 

NightFrost

Member
You can do it easier by first running the transition in first room, then switching the room, then running the transition backwards in the new room. The transition object should be persistent so it can do this all without having to pass information between rooms. If you're familiar with state machines, you can code your transitioner into one. It would have the following states:
  • Idle state: does nothing. Default state where the object waits until an external request kicks it to next state.
  • Fade out: runs the screen transition to given color. Switches to next state when transition counter equals or exceeds transition time.
  • Room switch: runs a room_goto. Draws a fullscreen colored rectangle to preserve the feel of the transition. Switches to next state after running.
  • Fade in: Same as fade out, but the counter runs backwards to zero. When counter is below or equals zero, switches to back idle state.
 

NeoShade

Member
@NightFrost I'm aware that this is an option, and it may well be what I end up doing, but I would like to still explore the possibility of transitioning directly without a solid colour between rooms if possible.
 

NightFrost

Member
Oh, you want to transition directly from one color to another without a fade in between? You'll have to save the current room as a sprite, then jump to the other room. There, you run a transition timer from 0 to 1 and send that value to transition shader, plus set the sprite as sampler2D resource for it. Since the new room needs to be fully drawn you'd do this this in Post Draw and run the app surface to back buffer draw through the shader. In the shader, you'd sample the sprite for color, the app surface for other color, then lerp between the colors by the timer's value. You'll have to do some math there as the sampler2D coords will be in 0-1 range but v_vPosition / gl_fragCoord will give you coords in room / view dimensions.
 

NeoShade

Member
Hi @NightFrost. Thanks again for the help there. In the end, I think I'm going to stick with fading through a solid colour, but I'm glad to have the optopn of going directly between, and it looks like you've pointed me in the right direction, so thanks for that.
 
Top