Jump to content
  • Advertisement
Sign in to follow this  
Cornstalks

OpenGL Use a Pixel Shader or Make More Textures?

This topic is 2592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently working on a 2D game, using OpenGL for my graphics library. I've never used shaders before, but I'm wondering if a pixel/fragment (or some other type) shader would be the optimal solution to one of my needs. It's a 2D sprite based game, where for the most part the sprites will be high quality. However, I want to have a special effect for various sprites, where a sprite "transforms" to and from its high quality version to a low-quality/pixelated version.

For example, you're walking a long, and then two enemies "apparate" in front of you. I want the enemies to appear in a very, very pixelated manner at first, but then to increase in quality (become less pixelated) over the course of a second or so, so that after the apparation animation sequence the enemies are now in full quality. Or I want to be able to do the reverse if the two enemies "disapparate".

One solution I've come up with is to generate "pixelated" sprite sheets. So for every frame in every animation sequence, I generate a series of pixelated versions (from low pixelation to high pixelation), so that during any animation sequence I can adjust the "pixelated" appearance of the object/character just by adjusting the texture coordinates of the sprite.

Is this the best option, or is it possible to use a shader to do this?



Sorry for using Harry Potter terms, I just watched the movie last night and can't think of a better word than "apparate."

Share this post


Link to post
Share on other sites
Advertisement
usually you create textures already with pixelated versions, called "mipmaps", those are usually selected automatically by the GPU, in a 2d game this probably makes no sense, as your pixel/texel ration is probably 1:1.

You could use http://www.opengl.org/registry/specs/EXT/texture_lod_bias.txt to select a different mipmap level, the GPU would blend between mipmap levels for you.




Share this post


Link to post
Share on other sites
Turn mip-mapping on first. Which builds your sprites down to a 1x1 pixel (the most pixelated in your case).

With glTexParameter() you can set the GL_TEXTURE_MAX_LOD, (or maybe it will be the min) and you can select to use the 1x1 version, or 2x2 version 4x4, all the way up to level 0 (which will be your original image).
http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml

Share this post


Link to post
Share on other sites
I like the idea of using mipmapping to do it, basically force the LoD bias to select a low resolution image. Also make sure to change your filtering mode to NEAREST_MIPMAP_NEAREST.

Share this post


Link to post
Share on other sites
Wow, you guys are awesome! I thought about mipmaps but wasn't sure if I could force select them or if I could set the filter mode to nearest. Thanks! That'll save quite a bit of memory and time.

Share this post


Link to post
Share on other sites
if by "transform" you mean a blending between both quality levels, I'd recommend GL_NEAREST_MIPMAP_LINEAR, you would have no filtering on the mipmap levels, but blending between levels.

Share this post


Link to post
Share on other sites
What exactly do you mean by blending between levels? I would prefer to have "hard" transitions, where each frame is only displaying one mipmap level (and not a blending between two mipmap levels). Would the NEAREST flag give this result?

Share this post


Link to post
Share on other sites
just remember that doing it by having the gpu automatically generate mipmap's takes away any control that a graphics artist might be able to "touch-up" the pix-elated animation, or do any special animation's.

Share this post


Link to post
Share on other sites

What exactly do you mean by blending between levels? I would prefer to have "hard" transitions, where each frame is only displaying one mipmap level (and not a blending between two mipmap levels). Would the NEAREST flag give this result?


yes. GL_NEAREST_MIPMAP_NEAREST will switch hard between two versions, I thought when you said 'where a sprite "transforms" to and from its high quality version to a low-quality/pixelated version;, you meant you want to blend between two levels.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!