Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel perfection, texel snapping #176

Open
micktu opened this issue Aug 6, 2013 · 4 comments
Open

Pixel perfection, texel snapping #176

micktu opened this issue Aug 6, 2013 · 4 comments

Comments

@micktu
Copy link

micktu commented Aug 6, 2013

        if(Futile.isOpenGL)
        {
            Futile.screenPixelOffset = 0;
        }
        else //directX needs to be offset by half a pixel
        {
            Futile.screenPixelOffset = 0.5f * Futile.displayScaleInverse;
        }

While this is correct, it is not a solution. Subpixel movement will still get artifacts most of the time, on both OpenGL and DirectX. This could be resolved two ways: the less elegant is to snap every object's position to points (e.g., round() for OGL, round() + 0.5 for DX; the more elegant one is to snap inside the shader, and in fact, a shader like this is already a part of the official Unity kit. Grab Unity 4.2 shader source and take a look at Sprites/Pixel Snap/Alpha Blended.

@MattRix
Copy link
Owner

MattRix commented Aug 6, 2013

Yeah I'm not a big fan of snapping the objects themselves (that will create other issues), but doing it in a shader is an interesting approach. I don't think I'd make it the default, but having pixel-snapping shaders as an option in Futile would be handy.

@micktu
Copy link
Author

micktu commented Aug 6, 2013

On the other hand, I thought that eliminating subpixel positioning by snapping vertices to points may not be a bad idea after all. It will also allow people to use their own shaders without integrating them with pixel snap algorithm. I will try that as well, it's an easy patch after all.

@MattRix
Copy link
Owner

MattRix commented Aug 6, 2013

Yup, you could go into the FRenderLayers and manually round the position of each vertex. I think that'd work but it'd introduce a sizeable processing overhead if you were doing it every frame.

@micktu
Copy link
Author

micktu commented Aug 6, 2013

I don't think a call to a single native method will cause any significant overhead, I even think that it will be a tiny nice optimization (don't update vertices if they round up to the old values). I haven't digged into the renderer code yet, but I'm pretty sure it's not reuploading vertices unless they are changed, so it'd be just a bonus condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants