This project is read-only.

Shadows vs. Line of Sight...

Feb 15, 2011 at 7:26 PM

Shadows and Line of Sight, on the surface, appear to be pretty close cousins, so I wonder if LOS functionality is currently possible, or easy to add?

Imagine this... I have a top-down point of view game with sprites running around a map (think "Gauntlet").  I draw my floor, then I draw my walls, and I draw all my characters and enemies.

Currently, I'm placing lights on each of my characters, and hulls on the walls.  This creates a great shadow effect.  Lovely.  But I can still "see" in the shadows.

What differentiates "shadows" from "line of sight" is what happens in the occluded areas.

For "shadows", the region is still drawn and rendered completely, but in the ambient color.

For "line of sight", I'd like to see ONLY the floor (or some "background texture") drawn, and nothing else.

What do you think?  I realize Line of Sight is outside the scope of the project, so don't think I'm not grateful that it's not already included!  :)


Feb 15, 2011 at 7:34 PM

I guess what would need to happen is to do this:

1) Draw the background

2) Render the full scene to a RenderTarget

3) Use the lightmap generated by Krypton to adjust alpha values of the full scene render target, and copy that on top of the background.

Feb 15, 2011 at 8:16 PM

I'm not sure I'm 100% following, but if you dropped krypton.AmbientLight to (0, 0, 0) would that not have the desired effect?

You then set your player's light to have a FOV and rotate to his current angle - it'd only light up the areas he can see.

Feb 15, 2011 at 8:33 PM
Edited Feb 15, 2011 at 8:34 PM

Yes, I guess I wasn't very clear.  Let me try again.  :)

In your post, you suggest setting ambient light to 0,0,0.  This means that all shadows would get drawn full black.  The effect I'm looking for is to draw SOMETHING ELSE (for varying values of SOMETHING ELSE) in the shadow area.


See this screenshot (from an upcoming game Monaco, written by a friend of mine)

In this game, he has a background texture which is a blueprint layout of the level.

Then he creates his "line of sight" map, based on the characters position.  He uses this map to determine what part of the foreground is visible or not.

Then, using this map, he renders the foreground on top of the blueprint image.  ONLY the portions that are "lit up" by the map are drawn.  The "shadow" parts have full transparency.

As I said, I suspect this is outside the bounds of the Krypton project.

Feb 15, 2011 at 8:50 PM

That's a really great looking game! It looks like he's taking a two pass approach. I plan on creating a way for Krypton to draw "layers" of shadows, for different depths, and this could surely be used to do what you're looking for. For now, however, you say you want a direct relationship between visible stuff, and the lgihtmap generated by krypton, and an inverse relationship between other stuff and krypton's light map.

I mean to add access to the lightmap directly from krypton.LightMap, but for now, you may have to add that property yourself. I would add the LightMap property to Krypton and return "this.mMap". From there, you could use that light map to render, and just get rid of Krypton's default rendering method.

However, if you'd like to wait, I can add support for what you're asking, as it's pretty modular.

Please open a work item on the issue tracker, and I'll get to it as soon as I finish zombie cow's request. :)

Feb 15, 2011 at 9:38 PM

Monaco:  Yeah, he's a pro game developer who went indie a few years back, and Monaco is his latest gig.  I guess it won some big indie awards and stuff.  Pretty cool.

I'll add an Issuer Tracker thingy, and also probably get a handle on mMap for my own evil purposes.... :)

Feb 16, 2011 at 12:11 PM

In my game I do exactly what you are explaining, using Krypton (probably I'll add screenshots later today).

I'll try to explain how I do it with my awful english:

What I do is to draw all the background normally, then I run Krypton (with ambientcolor black) but without drawing the lighmap. Then I take Krypton's rendertarget (named "mMap", which I made public, as it is private) and I use it as a mask for drawing all the world objects (enemies, objects, tables, etc), changing the objects' alphamask depending on the higher value of the map's RGB values: For example if the light is green (0, 255, 0), then the alpha will be 255 and thus the object will be fully drawn. Finally I draw the krypton's rendertarget with a lower alpha for the shadows.

Feb 16, 2011 at 5:45 PM

Thanks Pnikosis!  I'd love to see screenshots.

And your English is not awful!  :)

Feb 17, 2011 at 1:01 PM
Edited Feb 17, 2011 at 1:02 PM

Hi adman, I'm working on improving some stuff in the engine, so I need a little more time for making a screenshot that shows clearly the effect. So instead, here's video from an old build, where I didn't use color lights. But the effect is quite similar.


Feb 17, 2011 at 5:41 PM

Awesome.  Totally awesome.  This is just the effect I was looking for.

I'm pretty sure I can hack my own.  My original question was whether this is worth including in the Krypton project or not...

Thanks for sharing!

Feb 17, 2011 at 10:48 PM

That game looks awesome, btw :)

Also, I'll probably have time to implement this on the weekend and push a new release.

Feb 18, 2011 at 7:11 AM

Thanks guys for the compliments :$ 

It's an old build anyway, the current build looks a lot better, soon I'll upload a new video.

Feb 18, 2011 at 6:59 PM

Here's how I think it should work (for what it's worth, which is very little :)

There should be three major types of objects:  Lights, Hulls, and ViewPoints.

Lights and Hulls work together to create a LightMap.  The LightMap is combined with the scene to create areas of light and shadow.  This is already done.

ViewPoints would be like Lights.  They work with Hulls to create a ViewMap (very much like a LightMap).  The ViewMap is applied to the scene AFTER the LightMap is applied, and adjust the transparency of the scene.



Feb 18, 2011 at 11:33 PM

Before I read the rest of the post, I have to stop you on your first line...

I get all of my inspiration for Krypton from Krypton's users, and thus any information given by said users is invaluable to me. I wouldn't be able to improve on Krypton without it. :)

Feb 18, 2011 at 11:53 PM

Precisely what I was going to do, but I for some reason I couldn't figure out what to call "ViewPoint". So that's it's name now.

I'm thinking ViewPoint will support Solid and Gradient fills.

As for how Krypton displays these maps, I will leave that up to the user (default functionality will be left available, but the texture will also be returned to the user for custom use).

I'm thinking...

var lightMap = this.krypton.LightMapPrepare(lights, hulls);
var sightMap = this.krypton.SightMapPrepare(lights, hulls);

This will allow users to pass in their own IQueriable's of lights and hulls, which will enable them to do custom culling.

I'll also probably provide a better render helper, and add some nicities...

this.krypton.Renderer.DrawTextureToTarget(lightmap, PostBlend.Multiply);
this.krypton.Renderer.DrawTextureToTarget(sightmap, PostBlend.Multiply);
Any other thoughts?
Apr 27, 2011 at 9:00 PM

Did this ever go anywhere...?  Just curious.

Apr 28, 2011 at 2:19 PM


Not yet. School and work have been taking much of my time. School, however, should be over soon, and I may have time to get some work done on Krypton.