c++ - Dynamic 2d shadows - Blending issue -
good day dear community.
i'm working on dynamic shadows game shall work on, happens bring problem, in hope (i'm actually) help.
this right now:
notice red square, want gradually fade away light source moves out of sight. check if point of polygon inside circle's radius, of course doesn't solve it; said want fade gradually until blacks out if light far away.
there's 1 idea on mind hope better one. not talk since it's last option , find 'brute force' technique.
this how render light:
glbegin(gl_triangle_fan); { graphics::instance()->setcolor(r_,g_,b_,intensity_); glvertex2f(posx_,posy_); glcolor4f(0.f, 0.f, 0.f, 0.0f); (angle_=0.0; angle_<=3.14159265*2; angle_+=((3.14159265*2)/64.0f) ) { glvertex2f(range_*(float)cos(angle_) + posx_, range_*(float)sin(angle_) + posy_); } glvertex2f(posx_+range_, posy_); }
and how blend it:
glblendfunc(gl_src_alpha, gl_one); l0->render(); glblendfunc(gl_src_alpha,gl_one_minus_src_alpha); l0->projectshadow(*mmm); l0->projectshadow(*bb);
that all. if didn't made myself clear or if missed post relevant code, please , don't downvote.
how calculating range center of red square light sources center? normalise value suitable range , adjust transparency or colour of red square? this:
double range(double x1, double y1, double x2, double y2) { double xdist = x1-x2; double ydist = y1-y2; return math::sqrt(xdist*xdist+ydist*ydist); } double calcintensity(double lightx, double lighty, double lightradius, double objectx, double objecty) { double range = range(lightx, lighty, objectx, objecty); double intensity; if( range > lightradius ) { intensity = 0.0; } else { intensity = range/lightradius; } return intensity; }
then call calcintensity
, feed in reletive positions of light , square , radius of light.
[edit] ...or more optomised version if you're not pre-checking it's within lights radius:
double calcintensity(double lightx, double lighty, double lightradius, double objectx, double objecty) { double intensity = 0.0; double xdist = lightx-objectx; if( xdist < lightradius ) { ydist = lighty-objecty; if( ydist < lightradius ) { double range = math::sqrt(xdist*xdist+ydist*ydist); intensity = range/lightradius; } } return intensity; }
Comments
Post a Comment