MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Posted
2012-02-05 07:23:59 » |
|
Hello! I'm having trouble with a lighting problem. I understand the concept of creating a lightmap, and even have a set of pixel blending functions graciously provided by Dx4 in this post: http://www.java-gaming.org/topics/some-new-blendmodes-add-multiply-overlay-etc/24529/view.html. I'm currently running my prototype in FSEM with a BufferStrategy, Direct3d turned off by runtime options. Now, I'm wondering, given the Graphics I've been drawing all my lovely (read: horrifyingly primitive) sprites to, how exactly should I access the pixel data for the blending methods? Keeping a separate BufferedImage and calling out each pixel is EXTREMELY slow (especially in 1080p). Even having that BufferedImage and not applying a lightmap to it, then drawing it with g.drawImage(im, blah) is slow. Is there something I'm missing? Best, Munch [EDIT] the end goal is something akin to this: http://www.youtube.com/watch?v=Xmn6zhDJGLE&feature=fvwp&NR=1 though without the bump mapping.
|
|
|
|
|
theagentd
|
 |
«
Reply #1 - Posted
2012-02-05 07:46:02 » |
|
A good approach would be to draw your game normally and then blend a light map onto it. For the light map just draw each light with additive blending to the light map and finally blend the light map to the screen buffer with multiplicative blending. You're right about the slowness though. A 1080p framebuffer has almost 2 million pixels, and with a lightmap you'd be filling every one of those at least twice assuming terrain and sprites cover the whole screen + the lightmap blending + any overdraw. As you've disabled hardware acceleration all this is done by the CPU, and you're CPU isn't a graphics card. Graphics cards exist for a reason. xd
To improve performance you can try to reduce the resolution of the light-map to 1/2th to 1/4th the resolution of the screen. With bilinear interpolation (which is pretty much free if you re-enable hardware acceleration) the difference is completely indistinguishable while light rendering performance shoots through the roof.
The video you posted also has another thing: shadows. If you want shadows, then you'll have to drop Java2D and use OpenGL. OpenGL can handle hundreds of shadow-casting lights per frame, while unaccelerated Java2D can hardly draw an image covering the whole screen with blending... >_>
|
Myomyomyo.
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #2 - Posted
2012-02-05 07:50:49 » |
|
I am dissapoint. I'm really not looking forward to learning OpenGl, it's intimidating...!
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #3 - Posted
2012-02-05 08:20:50 » |
|
Oh also, for some reason FSEM in Java is extremely slow with D3D turned on. With 0 game logic it peaks around 80 fps at 1080p.
|
|
|
|
|
cylab
|
 |
«
Reply #4 - Posted
2012-02-05 10:59:41 » |
|
theagentd is right, you probably have to switch to an hardware accellerated api for 1080p with "effects". Take a look at slick2d or libgdx, which should offer enough of a high level api to make transition from java2d easier (especially slick2d, since it kind of mimicks the java2d concepts) and let you dig into the rendering pipeline, when you need to get advanced. libgdx will also offer android support.
|
Mathias - I Know What [you] Did Last Summer!
|
|
|
pitbuller
|
 |
«
Reply #5 - Posted
2012-02-05 11:38:57 » |
|
For Libgdx I have made light library that allow pretty much those effect that you see on that video out of the box. http://code.google.com/p/box2dlights/That work even on mobile devices and you dont have fiddle with opengl bits at all.
|
|
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #6 - Posted
2012-02-05 17:52:06 » |
|
For Libgdx I have made light library that allow pretty much those effect that you see on that video out of the box. http://code.google.com/p/box2dlights/That work even on mobile devices and you dont have fiddle with opengl bits at all.  neat.
|
|
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #7 - Posted
2012-02-05 18:19:43 » |
|
For Libgdx I have made light library that allow pretty much those effect that you see on that video out of the box. http://code.google.com/p/box2dlights/That work even on mobile devices and you dont have fiddle with opengl bits at all. Was trying to install it, but it seems to not mesh with the most recent libgdx download. What version of libgdx are you using with it?
|
|
|
|
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Cero
|
 |
«
Reply #10 - Posted
2012-02-06 18:59:44 » |
|
be advised that FBO are pretty advanced, and only available using OpenGL 3.0 and later if you want a lot of people to be able to play your game, don't use it. Alternatives include VBO and such
|
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #11 - Posted
2012-02-06 19:28:01 » |
|
be advised that FBO are pretty advanced, and only available using OpenGL 3.0 and later if you want a lot of people to be able to play your game, don't use it. Alternatives include VBO and such So... create a VBO, render the lightmap to that, then render the VBO on top of the scene?
|
|
|
|
|
pitbuller
|
 |
«
Reply #12 - Posted
2012-02-06 20:49:49 » |
|
I have two technique for lights. Fixed pipeline goes like this: 1. Render scene. 2. Clear alpha channel(use color mask for other channels, clear alpha to ambient) 3. Render Lights with blending, alpha channel as intesity. gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); 4. Render fullscreen black quad with blending. gl.glBlendFunc(GL10.GL_ONE, GL10.GL_DST_ALPHA); 5. Render UI. Shaders + FBO's goes like this. 1. Render scene. 2. Render Lights with blending to small size FBO, use alpha channel as intesity. gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); 3. Use gaussian blur to FBO. 4. Render FBO over to scene with custom shader that draw lights where intesity is high and shadow where intesity is low. 5. Render UI. Both techniques are as fast. Shaders give soft lights/shadows but fixed pipeline work everywhere.
|
|
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #13 - Posted
2012-02-06 22:30:50 » |
|
I have two technique for lights. Fixed pipeline goes like this: 1. Render scene. 2. Clear alpha channel(use color mask for other channels, clear alpha to ambient) 3. Render Lights with blending, alpha channel as intesity. gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); 4. Render fullscreen black quad with blending. gl.glBlendFunc(GL10.GL_ONE, GL10.GL_DST_ALPHA); 5. Render UI. Shaders + FBO's goes like this. 1. Render scene. 2. Render Lights with blending to small size FBO, use alpha channel as intesity. gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); 3. Use gaussian blur to FBO. 4. Render FBO over to scene with custom shader that draw lights where intesity is high and shadow where intesity is low. 5. Render UI. Both techniques are as fast. Shaders give soft lights/shadows but fixed pipeline work everywhere. Super n00b question: How do I clear the alpha channel?
|
|
|
|
|
pitbuller
|
 |
«
Reply #14 - Posted
2012-02-06 23:00:30 » |
|
1 2 3 4 5 6 7
| private void alphaChannelClear() { Gdx.gl10.glClearColor(0f, 0f, 0f, ambientLight); Gdx.gl10.glColorMask(false, false, false, true); Gdx.gl10.glClear(GL10.GL_COLOR_BUFFER_BIT); Gdx.gl10.glColorMask(true, true, true, true); Gdx.gl10.glClearColor(0f, 0f, 0f, 0f); } |
|
|
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #15 - Posted
2012-02-06 23:14:10 » |
|
Ok great. But what about this problem: With colored lights rendered over a white background (eg. snow) that blending function just takes it straight to white. Render the black quad first? 
|
|
|
|
|
|
|
pitbuller
|
 |
«
Reply #17 - Posted
2012-02-07 16:51:17 » |
|
Ok great. But what about this problem: With colored lights rendered over a white background (eg. snow) that blending function just takes it straight to white. Render the black quad first?  Yeah you find the problem. But there is easy fix for that. Just use 1
| glBlendFunc( GL_DST_COLOR,GL_SRC_COLOR); |
instead. You really don't want to render your scene per light. Instead just draw light to accum buffer and blend that over the scene. For that you dont even need any shaders.
|
|
|
|
|
MunchGamer
Senior Newbie  Medals: 1
|
 |
«
Reply #18 - Posted
2012-02-07 18:09:28 » |
|
Ok great. But what about this problem: With colored lights rendered over a white background (eg. snow) that blending function just takes it straight to white. Render the black quad first?  Yeah you find the problem. But there is easy fix for that. Just use 1
| glBlendFunc( GL_DST_COLOR,GL_SRC_COLOR); |
instead. You really don't want to render your scene per light. Instead just draw light to accum buffer and blend that over the scene. For that you dont even need any shaders. Using that blend function makes it look really bad, you can see the edges of the triangle fan of the lights instead of the smooth dropoff you get with a src_alpha blend.
|
|
|
|
|
pitbuller
|
 |
«
Reply #19 - Posted
2012-02-07 18:15:32 » |
|
That blend mode works for me but its not work with current shadow shader that I use but with withoutShadows shader(what is just texture color and nothing more) its work very nicely.
I will commit changes and screenshot later tonight.
Edit: in the trunk.
|
|
|
|
|
|