Jump to content


Photo

Drawing shadows using surfaces


  • Please log in to reply
2 replies to this topic

#1 Blackyjack6

Blackyjack6

    GMC Member

  • New Member
  • 4 posts

Posted 25 February 2012 - 07:24 PM

surface_set_target(global.light_surface); // Base surface 
draw_clear_alpha(global.color_zero,1);
draw_set_blend_mode(bm_add);
with(par_light){
// This draws calculated shadows && light sprites
draw_surface(light_surface,0-view_xview[0],0-view_yview[0]);
};
surface_reset_target();
draw_set_blend_mode_ext(bm_add,bm_subtract);
draw_surface(global.light_surface,0,0);
draw_set_blend_mode(bm_normal);

This code draws all the surfaces (it's borrowed code). It works fine, but not the way I want it too. Objects sprites are drawn on top, and these surfaces below that. So objects are constantly 'lit'. The shadows intersect with object sprites underneath so I can't just draw that surface it on top.

I split the sprites and shadows into two different surfaces. Code is nearly the same:
with(par_light){
draw_surface(light_surface_2,0-view_xview[0],0-view_yview[0]); // shadows
draw_surface(light_surface,0-view_xview[0],0-view_yview[0]); // light sprites
};
I set the order (top to bottom) base surface (black), light sprites, objects, shadows. Now the problem it the shadows are overlapped by the light sprites. So that doesn't work. I would need to have the shadows overlap the light, but still remain under the objects. It's crazy. I came here to see if anyone has any ideas/ can help.

I know how I could fix this, and that would involve messing with how the shadows are calculated so they won't overlap the object's sprite.
I barely can figure out what's going on in that code, so i'd rather not touch it unless I have too!
  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 25 February 2012 - 09:57 PM

If you want the order to be shadows, objects, then lights (which is what I'm hearing?), you can't do that with a single final global.light_surface surface. You'll need to create a surface for shadows and a surface for lights, and put them in two different objects. The shadow object should have a very high depth (like 999), and the light object should have a very low depth (like -999).

So, i.e., the shadow control would handle global.shadow_surface, which would draw the par_light instances' light_surface_2 surfaces. The light control would handle global.light_surface, which would draw the par_light instances' light_surface surfaces (seriously, abbreviate those variable names; it's getting tedious to keep saying "surface" :P ).

-IMP
  • 0

#3 xot

xot

    media multimixer

  • Global Moderators
  • 4650 posts
  • Version:GM:Studio

Posted 27 February 2012 - 06:51 PM

draw_set_blend_mode_ext(bm_add, bm_subtract);

Ack! Those constants shouldn't be used with that function. Constants bm_add, bm_subtract, bm_max, bm_normal should only be used with draw_set_blend_mode().

FYI, what you have is actually:

draw_set_blend_mode_ext(bm_zero, bm_src_color);

... which is a basic multiplicative blend, and in English means: "multiply the source by zero and the destination by the source and add them together".
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users