StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
282 stars 89 forks source link

Visual bug of tiled display #112

Closed ziibibi closed 10 years ago

ziibibi commented 10 years ago

Hello! I have problem with displaying an extra large bitmap with graphics extention - it's like 6000px in width and obviously cannot be displayed as single texture due to max size limit. Hence I'm using graphics extension, split bitmap data into smaller chunks and draw each of them with separate call. So far so good, it works. With one major issue - borders of bitmap tiles might not stick together so good: image

Can anyone tell me whats a problem and how can it be fixed?

Regards, J

jonathanrpace commented 10 years ago

It's possible it's a result of the bitmap repeating at the edges. If you overscale the matrix a bit, do these lines get reduced a bit?

You can also try changing the following line in this file https://github.com/StarlingGraphics/Starling-Extension-Graphics/blob/master/extension/src/starling/display/shaders/fragment/TextureFragmentShader.as

Change "tex ft1, v1, fs0 <2d, repeat, linear> \n" +

To "tex ft1, v1, fs0 <2d, clamp, linear> \n" +

Let me know if either of these changes or fixes it for you - it'll help narrow down the cause.

ziibibi commented 10 years ago

Thanks for a quick response! I looked up that file and it was: "tex ft1, v1, fs0 <2d, repeat, linear> \n" + somehow ... But still this change helped!

Now should I just compile from source to avoid bug in a future or that is a bug and will be fixed in some near release?

jonathanrpace commented 10 years ago

Well this means that your error is occurring due to texture repeating - however, this is something we usually want on by default! (Think about most bitmap fills in Flash, you get the imaged tiled over and over again).

I suggest introducing a scaling parameter to the matrix you pass to your beginTextureFill() call.

You want to scale it up by a tiny amount (enough to push a single pixel off the edge). The amount you want will be relative to the resolution of your bitmap.

If your texture was 512x512, you want to scale it up by 1/512 in both axis to get the desired effect. Ie

scaleX = (1 + 1/texture.width) scaleY = (1 + 1/texture.height) matrix.scale( scaleX, scaleY ) beginTextureFill( texture, matrix )

ziibibi commented 10 years ago

Thanks, will try that.

ziibibi commented 10 years ago

Just tried to reset TextureFragmentShader and apply scaling to matrix and somehow it doesn't work - it removes most of artifacts, but not all of them.