Welcome, Guest. Please Login or Register.  • Help
SMF Underground
+ SHMUP-DEV » SHMUP DEV FORUMS » Game Design
|-+ Underwater level

Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read March 15, 2010, 11:08:28 am #0
Arpeggiodragon

Underwater level

Hi guys. I had named this: "Level design problems and using Lighting in 2D orthogonal mode vs Perspective projection using a very basic X/Y axis scrolling camera". ..Since this is for an underwater level idea you can see why I changed it. Tongue

Anyway so that's the basic idea: A dark mysterious ocean depth where the only light is emitted from the players ship and maybe some cool jellyfish enemies and bosses with lots of additive blending and such. -Unfortunately I had never messed with OpenGL lighting before so I just found out the 'hard' way what not to do and lost a lot of time in the process. -It does work with no Z coordinate and weirdly enough you don't need to generate Normals like I thought, however since it is vertex based every bullet, background, enemy would have to be tessellated (another option?) and unfortunately I can't afford that performance hit right now. (Next project maybe) For reference I am using texture atlas batches then sending the data to the gfx in large chunks for most of the  textures.

I've also hit the floor elsewhere today with another issue: I've been using two modes of ortho projection for the game mechanics-wise so far; windows int style and reversed perspective style, eg; glOrtho(0,w,h,0..) glOrtho(-1,1,1,-1..) (I've learned my lesson), and only using 3D stuff for a select background objects, ie; non-gameplay eye candy...and was wondering what is the 'norm' for this nowadays? Should I be using a perspective veiw for everything and add in a bunch of extra zero's to the vertex coordinates. Would this help make effects such as the aforementioned easier in any way. Any sneaky tricks here? hehe... Also is there any correlation between the two in terms of lighting effects? How do you guys do it?

..Okay I've dragged on long enough. I'll leave it there for now.

Shmup on.
Offline  
Read March 15, 2010, 11:58:01 am #1
Hornet600S

Re: Underwater level

It does work with no Z coordinate
If you don't explicitely send a Z coordinate OpenGL uses 0 for it.
That's of course a good thing if you're doing a "classic" shooter playing on a 2D playfield.

and weirdly enough you don't need to generate Normals like I thought,
Actually it may work for you if you're just using sprites / billboards and such, since again the default OpenGL state helps you: the default normal is 0,0,1 and that's used for fixed-function-lighting if you don't supply anything else.

every bullet, background, enemy would have to be tessellated (another option?) and unfortunately I can't afford that performance hit right now.
I doubt that on todays hardware, even lowest available, you will ever reach any geometry limits. And even if then fillrate-limits will kill you earlier Smiley

and only using 3D stuff for a select background objects, ie; non-gameplay eye candy...and was wondering what is the 'norm' for this nowadays?
I don't know what's "the norm" but I'd use orthographic projection only for HUD etc.

Should I be using a perspective veiw for everything and add in a bunch of extra zero's to the vertex coordinates. Would this help make effects such as the aforementioned easier in any way.
Yes, I find it much easier that way.


"To survive war – you gotta become war." - John Rambo
Offline  
Read March 15, 2010, 01:15:55 pm #2
Arpeggiodragon

Re: Underwater level

Thanks for the reply.

I was going through chapter 6 in the Red Book hoping for some 'magic code' to use but unfortunately none exist. Tongue What's happening with the lighting approach is it looks very awkward color-wise and the transition between lit and non-lit sprites is instantaneous, that is, they just 'snap' between light and dark. Looks ugly.  ..hmm.. Let me get a basic screenshot....

..ok it looks better in stillframe but you can see what I mean. Really random on what gets light and what doesn't.



I was also trying out the idea of additive blended cicles with very low alpha values, then simply drawing every other entity darker, which gives the impression of a light source. This seems to be a lot easier to implement.

So you're saying that adding many more vertexes to each sprite would be the best solution for this effect? ..I'll try and add an overload to my SpriteBatch and see if I can get it working then. ..Although it crashes on glDrawArrays on arrays larger than 25,800... (stupid intel).




Offline  
Read March 15, 2010, 01:32:36 pm #3
Hornet600S

Re: Underwater level

So you're saying that adding many more vertexes to each sprite would be the best solution for this effect?
Where did I say that?!
If your geometry only consists out of sprites then you should not tesselated them more. All those vertices would have the same normal anyway. Only on rather large flat surfaces you would gain something by higher tesselation, namely better specular highlights.
Though there are far better ways to archive effects like that using shaders.

When I look at your screenshot it looks like you are only using sprites / billboards. In that case I wouldn't use any OpenGL lighting at all, but only play with vertex-colors and blending.

And maybe it's worth to become familiar with shaders, since that allows you to do very weird / special / unique color and blending effects by yourself.


"To survive war – you gotta become war." - John Rambo
Offline  
Read March 15, 2010, 02:32:12 pm #4
Arpeggiodragon

Re: Underwater level

Oh sorry, I misread what you said here:
I doubt that on todays hardware, even lowest available, you will ever reach any geometry limits. And even if then fillrate-limits will kill you earlier Smiley


If your geometry only consists out of sprites then you should not tesselated them more. All those vertices would have the same normal anyway. Only on rather large flat surfaces you would gain something by higher tesselation, namely better specular highlights.
Though there are far better ways to archive effects like that using shaders.

That explains why there doesn't appear to be any difference then. Tongue  And yeah I don't have a video card right now that supports shaders, which is no biggie since I guess I'm still learning the 'basics' of openGL anyway it seems...

Now to mess with blending lots of stuff.  laugh  ...which I just realized I didn't take into account things like this when I coded the core system. D:

Thanks for your help. ..Ah, any good references for this type of blending? (non-visible until they enter a enter an [artificial] light source) I think if they are drawn as black then additive blending would have no effect on them. hmm..

Offline  
Read March 16, 2010, 10:32:03 am #5
moosa

Re: Underwater level

Let me just be upfront and say first that I don't know anything about openGL and my programming knowledge is very limited.
That being said, I get the impression you're making this more complicated than it needs to be. If I'm reading this right, and correct me if I'm wrong, you're basically trying to make it so that the objects closer to your light source appear brighter and the objects further from it appear darker, and you're working with only 2D objects at this point, correct?
Offline  
Read March 16, 2010, 02:37:04 pm #6
Arpeggiodragon

Re: Underwater level

Thanks again guys for your help.

Right you are moosa. It's easy to get caught up in the implementation that you sorta forget what it is you needed to do in the first place. After sleeping on it I've come up with a pretty good solution for a 2D 'spotlight'. Cheesy

What I've done is simply render everything normally then after all that is over with add in one of these blending modes, through some trial and error, have come upon:
Code:
gl.Enable( GL.TEXTURE_2D );
gl.BlendFunc( GL.ZERO, GL.SRC_COLOR );
//gl.BlendFunc( GL.DST_COLOR, GL.SRC_COLOR );
//draw texture


The texture is just a .jpg with a black background with a white circle inside that becomes darker as the radius increases. When applied with one of those blending functions basically draws the screen with alpha values that correspond to the white portions of the texture. Works like a charm! Really fast and pretty. Smiley

However I now have another problem: Since there needs to be multiple of these 'circles' illuminating over different objects I need to generate them dynamically, and can't use a pre-drawn texture.


[edit] Update: OpenGL is fantastic. I'm glad I went for the low-level aproach rather than using a library. Some code: Cheesy

Code:
GLuint texture;
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, c );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

      //then draw a black background and some circles and copy the screen:
glBindTexture( GL_TEXTURE_2D, target_texture );
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, xoffset, yoffset, x, y, width, height );


It seems I just took a major FPS loss from this though. Basically having to draw two black rectangles and some circles, then texture that onto the screen at the end of the frame...every frame.. I'm not sure I can afford that. Sad Can anyone optimize what I'm doing?
« Last Edit: March 16, 2010, 04:07:48 pm by Arpeggiodragon »
Offline  
Read March 16, 2010, 09:57:19 pm #7
moosa

Re: Underwater level

You basically did what I was thinking. Why not use a PNG instead of a JPG? I'm not sure but I think you would get a significantly smaller file size in this case, plus it's losslessly compressed and has the alpha values already built in.

As for your multiple spotlight issue, I can't read your code to help you out there, but can't you blend only the spotlights together additively before drawing them as one? To do this you would need to stick with the white-to-black radial gradient that you have instead of an alpha-to-black. I was thinking about a white-to-alpha gradient overlay, but I couldn't figure out how to blend that in my head...

Wait, can you create a solid black image to cover the whole screen, then take multiple alpha-to-black gradients, and just add the alpha values from all the gradients to the alpha of the black image, and then draw the result? I'm not sure about performance, but if you can do that it should work perfectly.
« Last Edit: March 16, 2010, 10:10:11 pm by moosa »
Offline  
Pages: [1]   Go Up
Jump to:  

Page created in 0.116 seconds with 20 queries.