gnysek
Member
Hi,
I'm trying to change "Transitions Demo" CircleFadeTransition shader, to make sprites vanishing in a circle. I've copied shader code:
And then make an object with sprite, and put in draw:
however, looks that proportions are wrong (it's like shader sees more pixels on left and bottom):
also, when I add another sprite, it starts to works strangely, like size of texture is taken into account instead of sprite size:
Anybody is able to help me to fix this? What should I change to pass proper sprite size (especially when drawing stretched) so this shader works properly?
I'm trying to change "Transitions Demo" CircleFadeTransition shader, to make sprites vanishing in a circle. I've copied shader code:
Code:
//
// Simple circle transition with fade effect
//
attribute vec3 in_Position; // (x,y,z)
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}
Code:
//
// Simple circle transition with fade effect
//
uniform vec4 f_Time; // time, mode, 0, band_width
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
float final_alpha = 1.0;
float tt = 30.0-clamp(f_Time.x, 0.0, 30.0);
// Get MAX radius - from center to corner (bounding box)
float rad = sqrt( 0.5*0.5 + 0.5*0.5 );
vec2 center = v_vTexcoord - vec2(0.5,0.5);
float dist = sqrt((center.x*center.x)+(center.y*center.y));
// Work out a single step
float single_step = rad/30.0;
float thickness = (rad/1000.0)*f_Time.w;
float kill = (single_step*tt);
// Inside or outside revel?
if( f_Time.y<0.5 )
{
// If past the cut off, discard pixel
if( dist>kill ) discard;
if(dist>(kill-thickness) ) {
float dd = (dist-(kill-thickness));
final_alpha = 1.0-(1.0/thickness)*dd;
}
}else{
// If past the cut off, discard pixel
if( dist<kill ) discard;
if(dist<(kill+thickness) ) {
float dd = ((kill+thickness)-dist);
final_alpha = 1.0-(1.0/thickness)*dd;
}
}
// The surface will have varying alpha values that we DON'T want., so FORCE full alpha.
gl_FragColor.a = final_alpha;
}
And then make an object with sprite, and put in draw:
Code:
var fade_time = shader_get_uniform(shaderCut, "f_Time");
shader_set(shaderCut);
shader_set_uniform_f(fade_time, mouse_x/room_width * 30, 0.0, 0.0, 20.0 );
draw_self();
draw_sprite_stretched_ext(sprite_index, 0, 250, 250, 128, 128, c_white, 1);
shader_reset();
draw_text(10, 10, string(mouse_x/room_width*100)+'% hidden');
also, when I add another sprite, it starts to works strangely, like size of texture is taken into account instead of sprite size:
Anybody is able to help me to fix this? What should I change to pass proper sprite size (especially when drawing stretched) so this shader works properly?