Update about stuff I guess.

Posted by Charlie Carlo on July 19, 2012, 5:23 p.m.

Okay, so after about two weeks of arduous trial-and-error, and the help of Poly and Spectre, I now have a sorta-good-maybe shadow engine for an untitled game that isn't Settle.

It looks like this.

If you tear off its skin, it looks like this.

{
    //Draw Background
    if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main)
                    draw_background_tiled(par_croom.setback,0-view_xview[0],0-view_yview[0])
                surface_reset_target()
                }
    //Draw Shadows
    if surface_exists(global.sur_5)
                {
                surface_set_target(global.sur_5);
                    draw_set_color(make_color_rgb(237,239,199));
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    draw_set_color(c_white);
                surface_reset_target()
                }               
    with par_light {
        var me;
        depth=19;
        me=id;
        if (instance_exists(par_hasshadow))
        {
            if surface_exists(global.sur_1)
                {
                surface_set_target(global.sur_1)
                    draw_set_color(c_white);
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    with (par_hasshadow)
                    {
                    draw_sprite_ext(sprite_index,image_index,
                        (x-(me.x-x)/4)-view_xview[0],
                        (y-(me.y-y)/4)-view_yview[0],
                        image_xscale*1.25,
                        image_yscale*1.25,
                        image_angle,
                        c_black,
                        1);
                    }
                }
            surface_reset_target();
            if surface_exists(global.sur_2)
                {
                surface_set_target(global.sur_2);
                    draw_set_color(c_white);
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    draw_sprite(spr_light,0,x-view_xview[0],y-view_yview[0])
                    draw_set_blend_mode(bm_add);
                    draw_surface(global.sur_1,0,0);
                    draw_set_blend_mode(bm_normal);
                }
            surface_reset_target();
            if surface_exists(global.sur_3)
                {
                surface_set_target(global.sur_3);
                    draw_set_color(c_white);
                    draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                    draw_set_blend_mode(bm_subtract);
                    draw_surface(global.sur_2,0,0);
                    draw_set_blend_mode(bm_normal);
                }
            surface_reset_target();
            if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);         
                    draw_set_blend_mode(bm_subtract);
                    draw_surface(global.sur_3,0,0);
                    draw_set_blend_mode(bm_normal);
                }  
            surface_reset_target();
            if surface_exists(global.sur_5)
                {
                surface_set_target(global.sur_5);
                    draw_set_blend_mode(bm_subtract);
                    draw_sprite(spr_shadow,0,x-view_xview[0],y-view_yview[0]);
                    draw_set_blend_mode(bm_normal);
                }
            }      
    //Draw Objects with Shadows
        with par_hasshadow {
            surface_reset_target();
            if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);         
                    if instance_exists(par_light)
                    if point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y) < 255
                    {
                        draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,
                        make_color_rgb(
                        255-point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y),
                        255-point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y),
                        255-point_distance(x,y,instance_nearest(x,y,par_light).x,instance_nearest(x,y,par_light).y)),
                        image_alpha)
                    }
                else
                    draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,c_black,image_alpha)
                    }               
                }
    //Draw Objects without Shadows
        with par_noshadow {
            surface_reset_target();
            if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);         
                    draw_sprite_ext(sprite_index,image_index,x-view_xview[0],y-view_yview[0],image_xscale,image_yscale,image_angle,c_white,image_alpha)               
                }
            }
    //Draw Foreground
    if surface_exists(global.sur_main)
                {
                surface_set_target(global.sur_main);
                    draw_background_tiled(par_croom.setfore,0-view_xview[0],0-view_yview[0]);
                surface_reset_target()
                }
    //Draw Shading
    if surface_exists(global.sur_4)
                {
                surface_set_target(global.sur_4);
                draw_set_color(c_black);
                draw_rectangle(0,0,view_wview[0],view_hview[0],0);
                draw_set_color(c_white);
                surface_reset_target();
                }
        with par_shading {
            surface_reset_target();
            if surface_exists(global.sur_4)
                {
                surface_set_target(global.sur_4);
                draw_sprite(sprite_index,image_index,x-view_xview[0],y-view_yview[0]);
                }
            }
    //Draw Lights
        with par_light{
            surface_reset_target();
                if surface_exists(global.sur_main)
                    {
                    surface_set_target(global.sur_main);
                    draw_set_blend_mode(bm_add);
                    draw_sprite_ext(spr_neglight,0,x-view_xview[0],y-view_yview[0],1,1,0,c_white,0.1);
                    draw_set_blend_mode(bm_normal);
                    }
                }
    //Draw EVERYTHING
        surface_reset_target();
        draw_surface_ext(global.sur_main,0,0,view_wport[0]/view_wview[0],view_hport[0]/view_hview[0],0,c_white,1);
        draw_set_blend_mode(bm_subtract);
        draw_surface_ext(global.sur_4,0,0,view_wport[0]/view_wview[0],view_hport[0]/view_hview[0],0,c_white,1);
        draw_surface_ext(global.sur_5,0,0,view_wport[0]/view_wview[0],view_hport[0]/view_hview[0],0,c_white,0.8);
        draw_set_blend_mode(bm_normal);

        }
}
Edit: I'll admit that I don't know the BB Code to put text into a collapsible singularity.

You guys have any thoughts/opinions/scrutiny/criticism/praise/hobbies to share, put them in boxes under this bigger one. I like feedback.

Edit: Dideo.

Comments

JuurianChi 12 years, 4 months ago

Quote:
I'll admit that I don't know the BB Code to put text into a collapsible singularity.
Use this maybe?

 [hide][img]<a rel="nofollow" href="http://www.webpagescreenshot.info/i/87021-720201211840am.png[/img">http://www.webpagescreenshot.info/i/87021-720201211840am.png[/img</a>] [/hide]

I like the way that sprite looks, I'm wondering if you took environmental light into account when shading it ahead of time?

Charlie Carlo 12 years, 4 months ago

Yeah, that's the specific tag that I don't know what it is.

Edit: I now know what it is.

Thanks, and no, I just always shade that way. If you mean the colors; I based all the artwork, so far, off of this new idea implanted into my brain that light casts warm colors and shadows are cold colors.

Cesque 12 years, 4 months ago

I still haven't got around to shading in GM. Heh.

But this looks awesome and very non-obtrusive for a pixelated game.

Rez 12 years, 4 months ago

agrh thats awesome. I wanna make a horror game so bad, but that code looks like a fucking bother to deal with for shadows alone :(

Charlie Carlo 12 years, 4 months ago

Quote:
agrh thats awesome. I wanna make a horror game so bad, but that code looks like a fucking bother to deal with for shadows alone :(

You should, I mean, Darling Springs was pretty good in the horror department; after going through that school and barely killing that cheerleader, I realized I had to go back, and I was all, "PLEASE GAME DON'T MAKE ME GO BACK THERE." It was the shit.

At any rate, I did post this script here, so feel free to use it/a derivative of it. It's not just shadows, it's light, shadows, drop shadows (badass shadows on the background relative to nearby lightsources' coordinates vs. the caster's coordinates) and it also draws everything else, since the use of surfaces in a draw event and trying to use views causes Game Maker to lose its shit.

This screenshot doesn't really do it justice. I'll make a video.

JuurianChi 12 years, 4 months ago

Quote:
light casts warm colors and shadows are cold colors.
Nice.

Also, it kind of bothered me how you instantly thought "horror", Rez.

I would love to see a system like this used creatively in another genre.

Or at least a hybrid that kept it from being cliche.

BP Scraps 12 years, 4 months ago

Looks pretty sweet, bro.

Rez 12 years, 4 months ago

stop saying bro

Anyhow, that lighting system looks like it could potentially add a lot to the atmosphere/scare factor. I'm definitely going to rip it off do something like it.

JuurianChi 12 years, 4 months ago

Yep, this is excellent. I've always used transparency/w sprites to get certain effects.

But this will help greatly with the system I built for my The Worlds End killer.

(Bro? Who says Bro? We're not bros here. If we where, I sure as hell didn't know.)

Charlie Carlo 12 years, 4 months ago

Hokay, I got a video up, brohams.