#version 150 //OVE shader_name: bounce out //OVE shader_description: by Adrian Purser (Licence MIT) //OVE name: Shadow color //OVE type: COLOR //OVE default: RGBA(0.5, 0.5, 1, 1) //OVE description: uniform vec4 shadow_colour; //OVE name: Shadow height //OVE type: FLOAT //OVE flag: NOT_CONNECTABLE //OVE min: 0 //OVE max: 100 //OVE default: 7.5 //OVE description: uniform float shadow_height; //OVE name: Bounces //OVE type: FLOAT //OVE flag: NOT_CONNECTABLE //OVE min: 1 //OVE default: 3 //OVE description: number of bounces uniform float bounces; //OVE end #define LINEAR_CURVE 0 #define EXPONENTIAL_CURVE 1 #define LOGARITHMIC_CURVE 2 const float PI = 3.14159265358; uniform sampler2D out_block_in; uniform sampler2D in_block_in; uniform bool out_block_in_enabled; uniform bool in_block_in_enabled; uniform int curve_in; /* animated from 0 to 1 */ uniform float ove_tprog_all; in vec2 ove_texcoord; out vec4 frag_color; vec4 getFromColor( vec2 p) { return texture( out_block_in, p); } vec4 getToColor( vec2 p) { return texture( in_block_in, p); } float TransformCurve(float linear) { if (curve_in == EXPONENTIAL_CURVE) { return linear * linear; } else if (curve_in == LOGARITHMIC_CURVE) { return sqrt(linear); } else { return linear; } } vec4 transition (vec2 uv, float progress) { float time = progress; float stime = sin(time * PI / 2.); float phase = (1. - time) * PI * bounces; float y0 = (abs(cos(phase))) * (1. - stime); y0 = 1.0 - y0; // fade out shadow in last part of transition float shadow_factor = 1.0 - smoothstep( 0.8, 1.0, progress); return mix( mix( getToColor(uv), shadow_colour, smoothstep( y0 - uv.y - shadow_factor*shadow_height/100., y0 - uv.y + shadow_factor*shadow_height/100., 0.0) ), getFromColor(uv + vec2(0., - y0)), step( y0 - uv.y, 0.0) ); } void main(void) { frag_color = transition( ove_texcoord.xy, TransformCurve(ove_tprog_all)); }