Theory of 2d per pixel lighting.

I first coded a pure java2d implementation based off of these: mattdesl-lwjgl-basics: Shader Lesson 6 and Java4k implementation

I’m tinkering with shaders on lwjgl (as per the first link) now (huge performance boost).

Didn’t know there was an alternative to fragment shaders, though, I’ll look into it.

Subtractive is when you’re blend something that absorbs light (like paints). Light reflecting off of things is (generally) additive and material dependent.

I have done 2d lights without a fbo 8)

I think the hardest part with 2d lighting is not the blending or setting up an fbo but actually calculation the shadows given a set of polygons.

Ummmm is there a way to “multiply” 2 texture by blending? When I do GL_ONE and GL_SRC_COLOR the effect is like dim and really looks crappy.

Ehhhhhhhhhhhhh yay!!! I feel like I won a lottery and my life is complete!!! At last I found a bug that caused my FBO lighting to look crap!

Thanks again theagent you made this possible.

I don’t really get it. There are all these “beginner” tutorials for opengl and such which don’t really teach anything… And there is literally no source code(I didn’t find any…) for stuff like this simple 2d lighting… Fek.

Ow… Just noticed… It doesn’t look as perfect as I would like. Is there a blending mode that isn’t additive (r + r) but rather if(new.r > curr.r) curr.r = new.r
Is there a way to implement something like dis?

You could use glBlendEquation() to change the operation from add to max().

Hmm seems to be what I’m looking for. But where do I find those modes? I can’t find them in either glcommon, gl11 or gl20.

My 2-cents is I’d suggest building up the lightmap in a shader rather than using old-school techniques. There’s no margin in them, they’re less flexible and less mileage as far as learning (time spent vs. benefit). Additionally I think the process has more fun-factor.

https://www.google.se/search?q=GL_MAX+lwjgl
https://www.google.se/search?q=glBlendEquation+lwjgl
Assuming LWJGL, of course.