Problem with textures appearing as black rects, or with weird artifacts. Only on iOS.

I’ve experienced this problem before, but in that scenario it was because I had changed the textureWrapX and Y to “repeat” and then not set it back to “clampToEdge” after creating that object. Afaik that isn’t the case this time.

The object appears as expected in the sim and on Android devices, it’s only on iOS that I experience this problem.

I am trying to use some of Corona’s filter effects, to create an object which is kind of like a stained glass window. I want the cells to remain in place, but the colours behind to change. In principle it is working, and I have condensed the code down to this:

local \_W = display.contentWidth local \_H = display.contentHeight local bannerHeight = 256 local BASE\_TILES = \_W/180--90 local mainBG = display.newRect(\_W \* 0.5, \_H \* 0.5, \_W, \_H) mainBG:setFillColor( 0, 1, 0 ) local paint = { type = "image", filename = "tile02.png" } display.setDefault( "textureWrapX", "repeat" ) display.setDefault( "textureWrapY", "mirroredRepeat" ) local snapshot = display.newSnapshot(1025, bannerHeight) snapshot.x, snapshot.y = \_W \* 0.5, \_H \* 0.5 local banner\_bg = display.newRect(snapshot.group, 0, 0, \_W - bannerHeight, bannerHeight) banner\_bg.fill = paint banner\_bg.fill.x = 0 banner\_bg.fill.y = 0 display.setDefault( "textureWrapX", "clampToEdge" ) display.setDefault( "textureWrapY", "clampToEdge" ) local scaleFactorX = banner\_bg.height / banner\_bg.width local scaleFactorY = banner\_bg.width / banner\_bg.height banner\_bg.fill.scaleX = 0.05 \* scaleFactorX banner\_bg.fill.scaleY = 0.05 banner\_bg.fill.rotation = 0 snapshot.fill.effect = "filter.crystallize" snapshot.fill.effect.numTiles = BASE\_TILES snapshot.fill.scaleX = scaleFactorX local count = 0 local function updateGame(e) banner\_bg.fill.x = banner\_bg.fill.x + 0.001 banner\_bg.fill.y = banner\_bg.fill.y + 0.001 snapshot.fill.rotation = snapshot.fill.rotation - 0.011 snapshot:invalidate() count = count + 0.001 if count \>= 360 then count = count - 360 end snapshot.fill.effect.numTiles = BASE\_TILES + 0.3 \* math.sin(count) end Runtime:addEventListener("enterFrame", updateGame)

The image being used is 128*128, so it is a power of two texture. This line here is the problem:

local snapshot = display.newSnapshot(1025, bannerHeight)

If I make the width 1024, then the texture appears on iOS but with lots of ‘distortion’ for lack of a better word.

I’m not sure where the problem lies. Here is a folder with the project - it’s just this simple main.lua and the image that’s being used:

https://www.dropbox.com/sh/5m4er2hy9u0npn9/AABzyX77x8Y6r_kT4ipziNUTa?dl=0

If anyone has any suggestions they would be appreciated.

Hi @Alan QuizTix,

Out of curiosity, may I ask why you’re using a snapshot for this?

Can you suggest an alternative, I’m certainly not attached to the snapshot if there is another way to achieve the same effect?  

The reason we’ve used it is because we want to be able to rotate the texture, without rotating the crystallise effect. This gives the effect of looking through a patterned glass, where the “cells” of the crystal stay in place but the colours behind may change based on other things moving.

Afaik we can’t apply the effect to a regular display group, which leaves us doing it to a snapshot.

It’s probably easier to see the current effect in the sim (where it does work) than have me try and explain it, If you wouldn’t mind running the project I’ve provided.

Hi Alan,

On inspecting your project, there might not be another way to achieve the same effect. If this is supposed to represent “glass” however, would you consider making the glass semi-transparent (alpha of 0.8 or something) and then showing whatever else behind it?

Brent

Do you happen to know why it is causing a black rect on iOS (or distortion if the size is less than 1024)?

Forgot to reply and say that the suggestion of putting a semi-transparent image over the top will not work for us. We’re not looking for the effect to represent “glass” as such, that was just the easiest way to describe what’s happening. The effect is actually a series of solid colour cells, which change colour as the texture behind rotates.

If we just put a semi-transparent image in front and then rotated an image, it would be really obvious that there was an image rotating, rather than the filter capturing a certain colour from the texture and using it. 

I thought I’d post images of what’s happening. 

iOS:

wfUCv0q.png

It might be hard to see in a static screenshot, but there are scratches appearing. While running on the device, these flicker all over the image.

Since we now have the ability to create our own shaders, is the source code for Corona’s own shaders now open source? I couldn’t find it anywhere. If there is a bug in the filter code I know you’d rather it was fixed for everyone, but if we were able to use the source code it may help us get past the issue for what is seemingly a non-standard use of the filter effect (and obviously if I found a fix I would let you know).

Hi @Alan QuizTix,

Out of curiosity, may I ask why you’re using a snapshot for this?

Can you suggest an alternative, I’m certainly not attached to the snapshot if there is another way to achieve the same effect?  

The reason we’ve used it is because we want to be able to rotate the texture, without rotating the crystallise effect. This gives the effect of looking through a patterned glass, where the “cells” of the crystal stay in place but the colours behind may change based on other things moving.

Afaik we can’t apply the effect to a regular display group, which leaves us doing it to a snapshot.

It’s probably easier to see the current effect in the sim (where it does work) than have me try and explain it, If you wouldn’t mind running the project I’ve provided.

Hi Alan,

On inspecting your project, there might not be another way to achieve the same effect. If this is supposed to represent “glass” however, would you consider making the glass semi-transparent (alpha of 0.8 or something) and then showing whatever else behind it?

Brent

Do you happen to know why it is causing a black rect on iOS (or distortion if the size is less than 1024)?

Forgot to reply and say that the suggestion of putting a semi-transparent image over the top will not work for us. We’re not looking for the effect to represent “glass” as such, that was just the easiest way to describe what’s happening. The effect is actually a series of solid colour cells, which change colour as the texture behind rotates.

If we just put a semi-transparent image in front and then rotated an image, it would be really obvious that there was an image rotating, rather than the filter capturing a certain colour from the texture and using it. 

I thought I’d post images of what’s happening. 

iOS:

wfUCv0q.png

It might be hard to see in a static screenshot, but there are scratches appearing. While running on the device, these flicker all over the image.

Since we now have the ability to create our own shaders, is the source code for Corona’s own shaders now open source? I couldn’t find it anywhere. If there is a bug in the filter code I know you’d rather it was fixed for everyone, but if we were able to use the source code it may help us get past the issue for what is seemingly a non-standard use of the filter effect (and obviously if I found a fix I would let you know).