• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Canglong

2D background sub-pixel movement

7 posts in this topic

Hello, I'm currently making a 2d platformer with direct3d 9 and I have a method to create large backgrounds where I load large images as a surface in system memory and then create smaller 256x256 textures from the image and then create a grid of quads and each is set to the corresponding texture. This works very well, but I want to be able to parallax scroll these backgrounds at different speeds relating to the players movement and sometimes that means moving very slow, less than a pixel per frame for example. The problem is, that leads to filtering and this will create ugly lines in the border between the textured quads. So I have to place the quadgrid pixel-perfect.
Does anyone know of a good way to display large images in their native size and use them with subpixel scolling? The images I'm using are too large too load as a single texture.
0

Share this post


Link to post
Share on other sites
How exactly do you mean that only slow movement leads to filtering?

The rasterizer always rounds to integer pixel coordinates and as long as quad vertices line up perfectly with neighboring quads, you shouldn't be able to see any artifacts between triangle borders.

Perhaps it's an issue with the filtering state of your texture samplers (repeat instead of clamping)?
0

Share this post


Link to post
Share on other sites
So in this case you'll want to emulate the filtering that would happen if your 256x256 tiles were all part of the same large texture. With linear filtering enabled, for any pixel you rasterize the resulting texture value will be a linear combination of the 4 neighboring texels. The weighting used depends on how far the pixel value is from the neighboring texels. So if you start off with one texel exactly overlapping a pixel, that one texel will get a weight of one and the 3 other texels will get a weight of zero. If you were to slide the texel to the left by one tenth of a pixel, then the texel will overlap nine tenths of the pixel. So the texel will get a weight of 0.9 and the texel to the right will get a value of 0.1. Thus you'll get a blend of those two pixels, with the blend depending on how much they overlap the pixel.

What you'll want to happen is you'll want is for your edge pixels to weighted by how much they overlap when you output them. Then you'll want to sum the results of all tiles that overlap that pixel, so that the result is the same as the bilinear filtering case. I think the easiest way to accomplish this would be use additive blending (D3DRS_SRCBLEND = D3DBLEND_ONE and D3DRS_DESTBLEND = D3DBLEND_ONE), and enable BORDER texture filtering with a border color of 0. The border filtering will cause edge pixels to get attenuated when they partially overlap, and then the additive blending will cause adjacent tiles to sum their results.I *think* this should work, although I've never tried it myself so there might be a problem that I haven't thought of.

Another possible solution would be to create a render target texture that's equal to the size of your screen + 256. You could then render all of the tiles required for the screen to that texture, except you would do it so that they're perfectly aligned to pixels. Then when you draw for real, you would render that large texture to the back buffer but offset a bit based on your scrolling. This would allow it to scroll smoothly, since you'd be filtering one large texture.
0

Share this post


Link to post
Share on other sites
Stupid question: is antialiasing enabled? Not sure how much this'd affect the output, but whatever.

And yeah, disable all filtering you can if you're going for pixel-perfect sprites. And you can always just round the vertex positions before actually drawing if you still have issues (I had to do this with the HTML5 2D canvas for this very reason).
0

Share this post


Link to post
Share on other sites
eppo:
You were right, I set the samplerstates to clamp and know it works, thank you very much!
I didn't express the problem clearly enough, it was not just a problem with slow movement, I just needed to be able to place the quads between pixels (not pixelperfect) and achieve exactly what MJP described but clamp did the trick.

hedgehog: What I wanted here was not pixelperfect quads since then the scrolling would be less smooth.
0

Share this post


Link to post
Share on other sites
MJP: I also tried your method with border filtering but I still got lines at the quadborders, thanks for the reply though
0

Share this post


Link to post
Share on other sites
MJP is still right though. Perhaps less noticeable, but if you stitch together multiple quads using different textures, you can't properly filter between two adjacent quad's border rows of pixels. The filterer doesn't have that continuity information available.
0

Share this post


Link to post
Share on other sites
Yeah that sounds right, but It's not noticeable at all, at least not to me. It looks exactly like one large quad with one texture.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0