![]() But for now we'll just use the default SpriteBatch shader, and only rely on sampling from the alpha channel. We could use a custom shader here to encode specific data into our occlusion pass (such as normals for diffuse lighting). end the batch before unbinding the FBO batch. opaque pixels will be shadow- casters, transparent pixels will not. set up our batch for the occluder pass batch. translate( mx - lightSize/ 2f, my - lightSize/ 2f) translate camera so that light is in the center cam. set the orthographic camera to the size of our FBO cam. To do this in LibGDX, we first need to set up a Frame Buffer Object like so: The larger the size, the greater the falloff, but also the more fill-limited our algorithm will become. Our algorithm will expect the light to be at the center of this "occlusion map." We use a square power-of-two size for simplicity's sake this will be the size of our light falloff, as well as the size of our various FBOs. This way, our shader can sample our scene and determine whether an object is a shadow-caster (opaque), or not a shadow-caster (transparent). ![]() The first step is to render an "occlusion map" to an FBO. Special thanks to "nego" on LibGDX forums, who suggested some great ideas to reduce the process into fewer passes. As you can see I'm using the same placeholder graphics for the occluders. ![]() My technique is inspired by Catalin Zima's dynamic lighting, although the process discussed in this article is rather different and requires far fewer passes. The idea is an extension of my previous attempts at shader-based shadows, which combines ideas from various sources. The following animation best demonstrates what's happening: The basic steps involved are (1) render occluders to a FBO, (2) build a 1D shadow map, (3) render shadows and sprites. My technique is implemented in LibGDX, although the concepts can be applied to any OpenGL/GLSL framework. Because of the high fill rate and multiple passes involved, this is generally less performant than geometry shadows (which are not per-pixel). Detailed here is an approach to 2D pixel-perfect lights/shadows using shaders and the GPU. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |