Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [IMPORTANT!] Using floats for projection matrix sucks.  (Read 5119 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
[IMPORTANT!] Using floats for projection matrix sucks.
« on: June 19, 2009, 06:00:58 pm »
Finally I figured it out!

This issue has been pointed out in this thread.
Using the example there can this hack be tested for the change in behaviour.

I found this blog post that talked exactly about this issue, but for OpenGL ES for the iPhone. Credits to that fellow.

I hacked the RenderTarget drawing function in SFML1-svn (when it loads the projection matrix) to prove my point.
This hack consists in using a double-precision projection matrix instead of float-precision one.

Please download the svn-patch here and try it out!

Aside note:
A debug-time assertion should be made when accessing Matrix3::operator() out of bounds, instead
of just returning the first element


Regards
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[IMPORTANT!] Using floats for projection matrix sucks.
« Reply #1 on: June 20, 2009, 06:55:59 pm »
Nice :)

Did you make some tests? What does it improve exactly?
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
[IMPORTANT!] Using floats for projection matrix sucks.
« Reply #2 on: June 20, 2009, 07:38:49 pm »
It improves the 1-to-1 image-to-screen pixel aspect. For any pixel index.

If you draw 1px vertical lines, you will notice that some will "stick" toghether... indiferent of the smoothing.

It's really noticeable when you resize the window (keeping a proper 1-to-1 view)... as apparently narrower dimensions yield more problems (i.e. "sticking") due to float rounding.

I'm making a GUI+SFML app and resizing is a common thing, so this problem left me with really ugly renders sometimes.

-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[IMPORTANT!] Using floats for projection matrix sucks.
« Reply #3 on: June 20, 2009, 07:58:02 pm »
Do you have a sample program that demonstrates this? I was starting to write one, but maybe you already did it for your own tests :)
Laurent Gomila - SFML developer

Julien_v42

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • http://tinyrpgsim.wordpress.com
[IMPORTANT!] Using floats for projection matrix sucks.
« Reply #4 on: June 22, 2009, 12:31:31 pm »
Just to push a bit this issue, I've got the same bugs using tilemaps. I hadn't given it much thought, but the rounding issue make sense.
So +1 on any fix, whether an opt-in feature or a default one.
Working on TinyRPGSim

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
[IMPORTANT!] Using floats for projection matrix sucks.
« Reply #5 on: June 25, 2009, 02:57:23 pm »
Sorry laurent, I don't. I made the tests on a bigger project with lot's of dependencies (like wxWidgets).

But you can load a sprite with an image with vertical 1px black and white lines, disable smoothing.
Then set up some code for the resize event (resize event that updates the RenderTarget size and the View rect).

Regards
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[IMPORTANT!] Using floats for projection matrix sucks.
« Reply #6 on: June 25, 2009, 02:59:39 pm »
Ok I'll do this, thanks.
Laurent Gomila - SFML developer

 

anything