GLSL effects on 2D?
BlitzMax Forums/BlitzMax Programming/GLSL effects on 2D?
| ||
Is it possible to (using the GLMax2D driver) apply GLSL shader effects on a 2D game? To do things like simulating heat haze on the background behind the sprites on a 2D platformer, or doing a vortex effect when the player character enters a teleporting portal at the end of the level? |
| ||
Might be possible, depends on exactly what the shader needs access to (you'd probably end up modifying the GLMax2D driver). I'm currently writing an OpenGL 2D engine similar to Max3D. |
| ||
It's something I'm very interested too but unfortunately I dig many topics on this forum about that feature and always left the idea behind... If someone has a real simple and practical example I would love to learn that too ! Hey Plash, is your 2D OGL engine will surpass the graphic capabilities and performances of the GLMax2D Driver ? EDIT Oh, following your research Joe I found this example which is probably a good starting point for others searching on this : http://www.blitzbasic.com/Community/posts.php?topic=85263 Looking very doable after all but tricky and the example are abnormally slow :) |
| ||
Hi Joe, brl.GLMax2D uses brl.GLGraphics which in turn uses pub.OpenGL which only uses version 1.1. So since GLSL only starts at version 2.0 no, it isn't possible. For cross-platform GLSL in BMax there is Max3D or miniB3D Extended. |
| ||
Hey Plash, is your 2D OGL engine will surpass the graphic capabilities and performances of the GLMax2D Driver ? Most certainly. I intend to setup an single-surface animated textures, an entity system and materials for create-once, update and forget styled rendering. If someone has a real simple and practical example I would love to learn that too ! Here is a decent example using shaders, and my FBO test. |
| ||
Thanks Plash I will learn a bit from these examples : very interesting :) But I'm wondering seing all these "simple" shaders code floating around BlitzMax if game effects like water, fire, heat, glow, etc. is possible on 2D games with the example system ? Is this normal that activating more pass on this tiny example slow down a lot ? I tough it was using the GPU to overcome this problem ? |
| ||
But I'm wondering seing all these "simple" shaders code floating around BlitzMax if game effects like water, fire, heat, glow, etc. is possible on 2D games with the example system ? Yes, it is possible. You'd have to setup the context with glOrtho and such (I don't know the whole procedure, but that's what brl.glgraphics uses).In fact.. you can probably easily use GLGraphics to do some 2d stuff without much fuss. Is this normal that activating more pass on this tiny example slow down a lot ? I tough it was using the GPU to overcome this problem ? Well, shaders still take up time to execute operations (even though it should take less time when compared to an in-code version of the same effect), and adding more passes just doubles the required time for the operations to execute.What is the speed difference per pass? Also, what graphics card are you testing it on? |
| ||
Well, I am too green on OpenGL and BlitzMax to code this. I am thinking would be the way to go... It seems to me that one of the possible ways to accomplish it would be to: 1)Fork GLGraphics, GLMax2D 2)Add glew as a dependency and tweak them to use a programmable pipeline with deferred rendering, capable of plugging shader effects, which will probably involve FBOs to load and manipulate the game images. Wow, that sounds so simple! Bet it's easier said than done... |
| ||
Since shaders require the use of extensions and features that Max2D doesn't even use, I don't really see any reason off-hand why you couldn't use shaders right alongside Max2D without even having to preserve any GL state. |
| ||
Having looked around a bit about use of shaders in 2d games (which seems very uncommon), it seems that most effects you can do could also be done without shaders. When people talk about like heat shimmer, screen warping, lighting and shadows, etc, these can often all be done using regular 2d effects/commands without a shader. Sometimes it seems like people are using shaders `just because` you can do something in a shader. Like a rippling water which reflects the graphics above it - you can do most of that with regular 2d commands. Is it just that people don't have experience with trying to pull off these effects in clever ways using traditional techniques? |
| ||
Shablam. |
| ||
?! Erm, what? |
| ||
?! Erm, what? What?That is a link, you know.. |
| ||
What? Huh? |
| ||
Ok so blur is one that's a bit tricky to do with older methods, but still possible. What would you use blur for in a 2d game? |
| ||
I would use it to blur out all my bad graphics. |
| ||
What would you use blur for in a 2d game? Moving depth of field effects (with parallax layers or scaled sprites moving into or out of the screen), 'bad health' effects, end of scene blur/fade-outs... all sorts of possibilities. |
| ||
You'd want to apply *realtime* blur on a parallax layer which doesn't move in the Z direction? Sounds like a waste. The end of scene blur I could see doing, and maybe stuff that helps to provide new animation capabilities. |
| ||
No, IH, think of FF3 poison effect when you walk! Looks neat! Good work Plash. |
| ||
Keep in mind you can change the Z-range for the graphics buffer. I have not tested access to the z-position of a rendered pixel on the shader side, but I was thinking it may be possible to do pseudo-dof in 2D. |
| ||
You'd want to apply *realtime* blur on a parallax layer which doesn't move in the Z direction? Sounds like a waste. If you were to blur layers in and out according to their depth you'd get a very cool depth of field effect, adjusting the focus to suit the situation. The 'current focus' layer would be non-blurred, while layers both closer and further away would be blurred more depending on their distance from the focus layer. In this dodgy example, the focus is shifting from later 3 (middle) to layer 1 (closest): Key: --- No blur === Blur +++ More blur *** Even more blur OOO Total blur-fest Parallax layers from above: 5) Further still +++++++++++++++++++++++++++++++++++++++++++++++++++ 4) Further ========================================================= 3) FOCUS ----------------------------------------------------------- 2) Nearer ========================================================== 1) Nearer still ++++++++++++++++++++++++++++++++++++++++++++++++++++ ^ | Viewer Adjusting depth of field to nearest layer: 5) Further than even further OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 4) Even further **************************************************** 3) Further still +++++++++++++++++++++++++++++++++++++++++++++++++++ 2) Further ========================================================= 1) FOCUS ----------------------------------------------------------- ^ | Viewer (And with shaders it wouldn't be a waste at all.) |
| ||
Hmm yah ok. I will admit that new technology makes new things possible. :-) |
| ||
So why has hardly anyone used shaders in a 2D game so far? It's very hard to find examples of any games using it. Maybe just the technology is too advanced for most 2D developers? |
| ||
Have a look at Facewound, by the guy that did Garry's Mod for HL2. The link is a bit mangled, but this works. He even did a nice little tutorial where you can load up the shader files and play with them in the game: http://www.facewound.com/tutorials/shader1/ Maybe just the technology is too advanced for most 2D developers? Funnily enough, simple pixel shaders are very easy and loads of fun to play around with. Look at my Max3D hacks, based on almost no knowledge whatsoever... Crude depth of field, simply applying blur based on how far away each pixel is: Big image here for sake of thread. Speccy shader: ![]() |
| ||
Yes cool but that's 3D. ;-P |
| ||
The pixel shader effects are strictly 2D though, just modifying the pixel colour in each case -- no 3D geometry is being fiddled with. (OK, the castle DOF thing uses the depth buffer, but it's still a 2D buffer you're working with.) They're just examples of cool things you can do with very little shader knowledge indeed. |
| ||
Um... doing a full screen quad to draw pixel shader effects over a *3D* image does not make them a 2D effect ;-D by 2D I mean you use them in a typical 2D game - platformer, shootemup etc, where there is no 3D. |
| ||
@ImaginaryHuman: Whether it's a 2D or 3D game is irrelevant, shaders are incredibly fast ways of processing graphics as they are compiled an run directly on the graphics card as part of the render pipeline. |
| ||
Hummm, 2D is just a special case of 3D. I have to find some time to get back to coding my project. ;-) Risking hijacking my own thread, I have bought a WII and found Super Paper Mario a very original game mechanic for a 2D+3D game. |
| ||
Yah I know what shaders are and how they work. My point was just that so far hardly anyone has used them for 2D, hardly anyone knows how to or wants to, and even if they did it can be difficult to come up with ways to use a shader in a strictly 2D game. 2D games don't typically have or need things like normal mapping, shadows, ambient occlusion, etc--stuff that helps in 3D worlds of realism and polygon objects. |
| ||
There are dozens of applications for 2D shaders; * Depth of field (blur the background or foreground layers in real time) * Bloom * Full screen distortion effects * Localised distortion effects (think sound waves around explosions) * Various lighting and shadow effects Yes some of these can be done in pure 2D, but doing them with shaders would make them both look better and run faster. I am hoping someone can add a simple way to use shaders on Blitzmax, perhaps with a modified DirectX module (or openGL even) |