2D Lighting System

[x] <- This is awesome, riven… Have you seen the “Egit-tutorial-post” I wrote? The list codes are aweful…

[quote=“CodeBunny,post:1,topic:39113”]
It looks great! Are you likely to make it freely available?

Probably - however, I’m probably going to finish my current game before I do anything like that.

I’ve been putting together a proto-version of jRabbit 2.0 as I go - there’s a lot of very massive changes I need to do, so everything is being built again from the ground up. What I will probably end up doing is creating a series of “plugin” libraries that easily integrate with the base distribution. The lighting engine will be one of those, so you would be able to very simply add lighting to any game, but don’t need to have unnecessary jars bloating your end product.

Welp, I put together a video that explains my general methods for 2D lighting. http://youtu.be/0FZIKX1Y_8I

Too bad that you don’t actually explain anything regarding the actual lighting, except rendering a texture with multiplication. :frowning:

This seems to be the general consensus. :’( I’m putting together an addendum video that shows how I do shadows. My bad.

Don’t bother with videos… just post code and explain it. :smiley:

Eh, I think videos are more accessible to more people. It also allows people to directly see what I’m talking about - they don’t have to put out any effort and mess with it themselves.

I think your audience (programmers) want to copy and paste your code and see it work.

Good point. However, while I’m willing to explain my techniques, I’m keeping my code proprietary at the moment. I’ll release it (along with tutorials and examples) later.

Basically, I want to finish my current game (since it’s going to be commercial, I’m not going to be releasing code). Then, once I get jRabbit v2.0 released, I’ll have my lighting system be an open-source plugin for that.

This is obviously entirely your choice and the code is yours to do with how you want. It’s a shame though, it would be nice to have the option to use a simple shading system.

I understand, and as I previously stated, I’m going to make it an open-source plugin for jRabbit v2.0. It’ll just take a while.

The second part of the tutorial is up. This video explains how to create cast shadows.

4BtjcH-iLR0

What do you guys think?

Nice breakdown, and I’m sure it will help some people who have no idea what a lighting system consists of, but it doesn’t go into any detail on the polygon clipping algorithm (which is the heart of your system). Clearly you are trying to help people… Why not provide source code or a detailed explanation of the algorithm? Otherwise I don’t really see the point of your videos.

I like your system, though. Mind you: there’s no need to bind/sample a texture. The radial fade out and colouring can be done in a shader, probably more efficiently.

For soft shadows, you could apply a full-screen blur shader to all of your shadow maps at once. Depending on your scenario, it may be much faster than blurring each shadow map individually. For added effect, you could increase the blur size based on the distance from the light center. The result will look very good, probably identical to my own lighting tests, the only difference is that yours requires much less overdraw. :slight_smile:

I’m glad you liked the overview.

I’ve already talked about the source code issue - I even explain why in the video. I really do understand why you want it, but I’ve decided to not release it. That said, polygon clipping isn’t that hard, and people should be able to get something together if they can get everything else working.

I think binding a texture is faster than computing the lighting fade-off in a shader (texture lookup vs. distance calculation), but if there’s any difference, it’s so negligible as to not be an issue. Additionally, I don’t think you’re realizing the advantages of using a texture - I can have masked lights! I could make lights out of any of these:

So yes, potentially it’s useful. It allows me to customize my lights individually without needing to utilize any uniforms.

The blur shader was to be applied after the final lighting mask was calculated (not each light as it was rendered), so yes, you’re correct. Render all of the lights normally, and then do a blur pass.

Eh, I’m not a per-pixel lighting kind of guy. I figure that super-fast and good is preferable to slow but perfect.

Regarding closed source, it’s your call. I just don’t really see how helpful it is to write a tutorial and leave out the most important part – i.e. the actual implementation. It’s like writing a cooking book where you don’t include any recipes, but instead just show how good all the food looks when it’s done. :slight_smile:

[quote]I think binding a texture is faster than computing the lighting fade-off in a shader (texture lookup vs. distance calculation)
[/quote]
In my experience, texture fetching is pretty expensive. Simple arithmetic like this would lead to better performance, and has the same result as using a radial gradient texture. Another minor bonus is that it doesn’t require an extra glBindTexture per frame.

	float dist = length(gl_TexCoord[0].st - 0.5) * 2.0;
	gl_FragColor = vec4(color.r, color.g, color.b, 1.0 - dist);

Of course, it’s all relevant – you probably won’t even notice a difference unless you are rendering many lights. :slight_smile:

He’s made good on releasing source before, so if he wants to make it part of his engine before releasing anything, I might not agree with it 100% but that is his call.