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

Blurry Sprite3D #63

Open
novacoder opened this issue Feb 26, 2013 · 2 comments
Open

Blurry Sprite3D #63

novacoder opened this issue Feb 26, 2013 · 2 comments

Comments

@novacoder
Copy link

When we use Sprite3D we don't want to scale up the bitmapdata if it is not power of two. So, we need to have something like Image in starling.

I made changes (hardcode) to reach such behavior.
Here are some changes in BitmapTextureResource.as:

            if (resizeForGPU) {
                var wLog2Num:Number = Math.log(data.width)/Math.LN2;
                var hLog2Num:Number = Math.log(data.height)/Math.LN2;
                var wLog2:int = Math.ceil(wLog2Num);
                var hLog2:int = Math.ceil(hLog2Num);
                if (wLog2 != wLog2Num || hLog2 != hLog2Num || wLog2 > 11 || hLog2 > 11) {
                    // Resize bitmap
                    wLog2 = (wLog2 > 11) ? 11 : wLog2;
                    hLog2 = (hLog2 > 11) ? 11 : hLog2;
                    source = new BitmapData(1 << wLog2, 1 << hLog2, data.transparent, 0x0);
                    source.copyPixels(data, data.rect, new Point(0, 0));
                    scaleUV = new Rectangle(0, 0, data.width / source.width, data.height / source.height);
                }
            }

So, we copy data without resizing. source.copyPixels(data, data.rect, new Point(0, 0)); Then save scaleUV to set them in Sprite3D.as:

            geometry.setAttributeValues(VertexAttributes.POSITION, Vector.<Number>([0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0]));
            geometry.setAttributeValues(VertexAttributes.NORMAL, Vector.<Number>([0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[1], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[2], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[3], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[4], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[5], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[6], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));
            geometry.setAttributeValues(VertexAttributes.TEXCOORDS[7], Vector.<Number>([0, 0, 0, scaleV, scaleU, scaleV, scaleU, 0]));

I don't know how to integrate it correct into the main code. So it would be great to see similar changes in the next releases.

Thanks.

@makc
Copy link
Contributor

makc commented Feb 26, 2013

Here are some changes in BitmapTextureResource.as

This should be in MyNewAndShinyTextureResource in order to be backwards compatible. But even then they will not add it because new stuff is too much to test (see #45).

@novacoder
Copy link
Author

I understand it. But I can resize my bitmap prior to pass it to BitmapTextureResource. But I can't change uv coords in Sprite3D, so I need to write MyNewAndShinySprite3D.

Moreover it is strange to see parameter resizeForGPU
if (resizeForGPU) { ...

Of course you need to resize it by default if dimensions are not power of two.

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