GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2009-12-20 04:17:52

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Liitle Help on TunnelVision

I have a tunnel vision blur effect in my upcomming DistortEngine

Expandset_automatic_draw(0);
if(!surface_exists(s))
{
    if(view_enabled)
    {
        s = surface_create(view_wview, view_hview);
    }
    else
    {
        s = surface_create(room_width, room_height);
    }
}
if(!surface_exists(s))
{
    s = -100;
    instance_destroy();
    exit;
}

if(!surface_exists(s2))
{
    s2 = surface_create(param4,param5);
}
if(!surface_exists(s2))
{
    s2 = -100;
    instance_destroy();
    exit;
}

texture_set_interpolation(param1);
surface_set_target(s);
draw_clear(background_color);
screen_redraw();
surface_set_target(s2);
draw_clear_alpha(c_black,1)
draw_set_blend_mode(bm_add)

alpha = 1/param6;
if(view_enabled)
{
    v = 0;
    d = 0;
    if(view_wport<view_wview)
        d = (view_wview-view_wport)/2;
        
    if(view_hport<view_hview)
        d = (view_hview-view_hport)/2;


    repeat(param6)
    {
        draw_surface_ext(s,-v,-v, (param4 + v*2)/(view_wview), (param5 + v*2)/(view_hview),0,c_white,alpha);
        v +=1;
    }
}
else
{
    v = 0;
    repeat(param6)
    {
        draw_surface_ext(s,-v,-v, (param4 + v*2)/(room_width), (param5 + v*2)/(room_height),0,c_white,alpha);
        v +=1;
    }
}
draw_set_color(c_black)
draw_rectangle(0,0,param4,param5,0)

surface_reset_target();
texture_set_interpolation(param2);
draw_set_blend_mode(bm_normal)
if(view_enabled)
{
    if(view_wport<view_wview)
        xs = view_wview/param4;
    else
        xs = view_wport/param4;
        
    if(view_hport<view_hview)
        ys = view_hview/param5;
    else
        ys = view_hport/param5;

        
    draw_surface_ext(s2,0,0, xs, ys,0,c_white,1);
}
else
    draw_surface_ext(s2,0,0, room_width/param4, room_height/param5,0,c_white,1);


texture_set_interpolation(param3);

were param4 and 5 are the size of the survace and param 6 is the number of iteration or radius of the blurr

THis one blurs by stretching-zomming, where the center of the texture should remain relatively unstreched...

The problem is that when teh port is smaller than the view (zoomed out) the lesser strechech part of the image is located at the bottom right of the screen instead of being centered.


I would also like your code review on the engine if you want to double check what I did, perhaps ensure that I did it right, the effects mostly...

The way it works it you call a function that instanciates the distortion effect object, passing it the arguments which I later use in the effect.

The effect is in the end step. I disable auto-redraw and take charge of the drawing. This should be seamless to the user. The effect support views and no views room, zoomed in or out via the view and port settings...

Also check out my hack that I came up with to make sure the end step of the distorter is called last!

Download icuDistortEngine.gmk

Last edited by icuurd12b42 (2009-12-20 04:18:52)

Offline

#2 2009-12-20 13:43:52

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Liitle Help on TunnelVision

I'm also having trouble with the flip system (Updated the gmk)... Again, I can't figure out what's going on when the view is large and the port smaller...

I use a bunch of ifs in the other methods (the Blurr for example) to decide what to use for the scaling to match the specs of the view and port. But I'm sure it's a hack. There should be a standard equation to handle this...

Offline

#3 2009-12-21 13:04:18

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Liitle Help on TunnelVision

Well, I came up with this kludge, but it's not very satisfying. I seem to remember having a problem like this before. There should be a general solution but I don't think I ever found it.

Expand// if (view_enabled) 
// ...
    f = min(1,view_wport/view_wview);

    repeat(param6)
    {
        draw_surface_ext(s,-v*f,-v*f, (param4 + v*2)/(view_wview), (param5 + v*2)/(view_hview),0,c_white,alpha);
        v +=1;
    }

Abusing forum power since 1986.

Offline

#4 2009-12-21 19:25:54

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Liitle Help on TunnelVision

Thanks!

Offline

#5 2009-12-21 20:33:26

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Liitle Help on TunnelVision

Can you take a look at the
FLipObj?

There is in there another dumbfounding odity going on in there

Download icuDistortEngine.gmk


I line draw to vertices for debug.

The odd thing is the redraw redirect; when the port is smaller than the view (large view, Zoomed Out view in the demo), the redirected draw seems to apply the port onto the surface. I don't know how else to explain it. It's all so confusing. Anyway, the result is that the screen is only copied to the upper left side of the surface.

I guess I'll have to reset the port settings before doing the screen redraw. But that does not make any sense to me. because the zoomed in method seems to work.

However... I think this is the key why I have to do a buch of offsets here and there in the other effects. It's a major clue (methinks)...

Download icuDistortEngine.gmk


In short, I suspect I'm not doing it right from the start, in the other ones as well. Copying more than what I need the surface, the size of it clips the extra data instead of copying exactly what I need. Don't know if what I just said actually makes sense to you.


Changing the port to match the view before the redraw redirected seem to fix some things. Hoever, as you will see
Download icuDistortEngine2.gmk
this only seems to fix it on the horizontal...

Last edited by icuurd12b42 (2009-12-21 20:43:06)

Offline

#6 2009-12-21 20:56:35

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Liitle Help on TunnelVision

I think the best thing is to rethink the whole thing.

1) The target surface should be the size of the port; currently I create the surface the size of the view. which is a big nono (could be huge)
2) I need a way to force the redraw to fit that port size view. perhapse with d3d_stransform push pop and scaling. But I think that GM nukes this...
3) the effect would be done on the port sized surface
4) then the port sized surface is transfered onto the screen.

Offline

#7 2009-12-21 22:03:53

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Liitle Help on TunnelVision

Have you ever looked at ChevyRay's "Seamless Screen-Scaling" system? I'm not sure it's applicable, but your system reminded me of it.

http://forums.tigsource.com/index.php?t … 9#msg86809


Abusing forum power since 1986.

Offline

#8 2009-12-22 00:46:44

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Liitle Help on TunnelVision

Yeah, but you see that uses a surface based on the view size.  And note his example is smoll view larger port. What I'm figuring out is that I must use the port size for the surface and Scale the screen_redraw somehow...

I'll experiment some more when I sober up

Offline

Board footer

Powered by FluxBB