- Aug 26, 2016
- 164
- 803
Is there a better way to apply a color gradient shader to a screen?
What I tried works, but it's not pretty. It also only correctly works when all elements are the same size.
I tried giving the transform to the vbox, but it repeated the gradient on each child element instead.
What I tried works, but it's not pretty. It also only correctly works when all elements are the same size.
I tried giving the transform to the vbox, but it repeated the gradient on each child element instead.
Python:
init:
transform shader_menu(step, max):
shader "example.gradient"
u_color_top (0.984+0.016/max*step, 0.565-0.102/max*step, 0.208+0.694/max*step, 1.0)
u_color_bottom (0.984+0.016/max*(step+1), 0.565-0.102/max*(step+1), 0.208+0.694/max*(step+1), 1.0)
init python:
renpy.register_shader("example.gradient", variables="""
uniform vec4 u_color_top;
uniform vec4 u_color_bottom;
uniform vec2 u_model_size;
varying float v_gradient_done;
attribute vec4 a_position;
""", vertex_300="""
v_gradient_done = a_position.y / u_model_size.y;
""", fragment_300="""
float gradient_done = v_gradient_done;
gl_FragColor *= mix(u_color_top, u_color_bottom, gradient_done);
""")
screen navigation():
vbox:
spacing 5
style_prefix "navigation"
imagebutton auto "start_%s" background "buttons_bg" action Start() at shader_menu(0,7)
imagebutton auto "load_%s" background "buttons_bg" action ShowMenu("load") at shader_menu(1,7)
imagebutton auto "prefs_%s" background "buttons_bg" action ShowMenu("preferences") at shader_menu(2,7)
imagebutton auto "about_%s" background "buttons_bg" action ShowMenu("about") at shader_menu(3,7)
imagebutton auto "help_%s" background "buttons_bg" action ShowMenu("help") at shader_menu(4,7)
imagebutton auto "creds_%s" background "buttons_bg" action ShowMenu("credits") at shader_menu(5,7)
imagebutton auto "quit_%s" background "buttons_bg" action Quit(confirm=not main_menu) at shader_menu(6,7)
Last edited: