[Papervision3D] Flash 10 Optimization idea: replace "precise" with Flash 10 3
Tom Richardson
kwarismian at gmail.com
Wed May 20 16:41:22 PDT 2009
Z-index perspective correction is certainly not rocket surgery,
however without hardware support it will always be slow. In worst
cases it is as much as 15 times slower than standard affine texturing.
That us why pv3d, an engine dedicated to speed over sex appeal
chooses a passable middle ground of subdividing a surface with
classic affine texturing to minimize the visible distortion. Applying
depth based perspective correction will be equally slow in flash 9 as
it would be in flash 10. Matrix "robustness" has nothing to do with
the issue.
~T
On Wednesday, May 20, 2009, Alan Pinstein <apinstein at mac.com> wrote:
> [updated patch]
>
> I fixed a few bugs.
>
> Unfortunately this is Flash 10 only; but if we can figure out how to emulate the perspective correction via a matrix transform in Flash 9 we can greatly improve performance and texturemapping quality.
>
> Alan
>
> Index: src/org/papervision3d/materials/BitmapMaterial.as
> ===================================================================
> --- src/org/papervision3d/materials/BitmapMaterial.as (revision 910)
> +++ src/org/papervision3d/materials/BitmapMaterial.as (working copy)
> @@ -18,6 +18,7 @@
> import flash.utils.Dictionary;
> +import flash.display.TriangleCulling
> /**
> * The BitmapMaterial class creates a texture from a BitmapData object.
> @@ -113,8 +114,41 @@
> override public function drawTriangle(tri:RenderTriangle, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData = null, altUV:Matrix = null):void
> {
> // trace("at drawing triangle???");
> - _triMap = altUV ? altUV : (uvMatrices[tri] || transformUVRT(tri));
> - if(!_precise || !_triMap){
> + //trace('precise: ' + _precise + ', trimap: ' + _triMap);RT(tri));
> + if(!_precise || !_triMap) {
> + if (graphics['drawTriangles'])
> + {
> + // flash 10
> + var vertices:Vector.<Number>, // xy coords of triangle on 2d output bitmap to be "filled"
> + indices:Vector.<int> = null, // mapping of input sets of vertices to triangle vertices
> + uvtData:Vector.<Number> = null; // UV data points matching input vertices, along with a T value (scale due to z-depth)
> + x0 = tri.v0.x;
> + y0 = tri.v0.y;
> + x1 = tri.v1.x;
> + y1 = tri.v1.y;
> + x2 = tri.v2.x;
> + y2 = tri.v2.y;
> + vertices = Vector.<Number>([ // not right; this is the triangle on the texture, we want the triangle on the output?
> + x0, y0,
> + x1, y1,
> + x2, y2
> + ]);
> + indices = Vector.<int>([
> + 0,1,2
> + ]);
> + var fl:Number = renderSessionData.camera.focus;
> + uvtData = Vector.<Number>([
> + tri.triangle.uv0.u * maxU, 1-tri.triangle.uv0.v * maxV, (fl/(fl+tri.v0.z)),
> + tri.triangle.uv1.u * maxU, 1-tri.triangle.uv1.v * maxV, (fl/(fl+tri.v1.z)),
> + tri.triangle.uv2.u * maxU, 1-tri.triangle.uv2.v * maxV, (fl/(fl+tri.v2.z))
> + ]);
> + graphics.beginBitmapFill(bitmap, null, tiled, smooth);
> + graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE);
> + graphics.endFill();
> + renderSessionData.renderStatistics.triangles++;
> + return;
> + }
> if( lineAlpha )
> graphics.lineStyle( lineThickness, lineColor, lineAlpha );
> if( bitmap )
>
>
> On May 20, 2009, at 4:35 PM, Alan Pinstein wrote:
>
>
> Good news! I was able to achieve my stated goal for the day, to improve perspective correction by using Flash 10 drawTriangles(). The patch is below.
>
> The "magic" that really solved things was getting proper perspective correction (the "t" in UVT) mapped through to drawTriangles(), see the uvtData vector creation in the patch.
>
> As for speed, drawTriangles() is flat-out slower than the bitmapFill() current technique by 20-25%.
>
> However, if you need "precise", it is both faster (~10-15%) and *much* higher quality than PV3D's emulated precise (precise=true, precision=8).
>
> QUESTION:
> As great as this is for Flash 10, I am now wondering if there is a way to easily do this in Flash 9? Or is Flash 9's matrix capability not robust enough to allow for this type of transform?
>
> Alan
>
> --- materials/BitmapMaterial.as (revision 910)
> +++ materials/BitmapMaterial.as (working copy)
> @@ -18,6 +18,7 @@
> import flash.utils.Dictionary;
> +import flash.display.TriangleCulling
> /**
> * The BitmapMaterial class creates a texture from a BitmapData object.
> @@ -113,8 +114,41 @@
> override public function drawTriangle(tri:RenderTriangle, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData = null, altUV:Matrix = null):void
> {
> // trace("at drawing triangle???");
> - _triMap = altUV ? altUV : (uvMatrices[tri] || transformUVRT(tri));
> - if(!_precise || !_triMap){
> + //trace('precise: ' + _precise + ', trimap: ' + _triMap);RT(tri));
> + if(!_precise || !_triMap) {
> + if (1 && graphics.drawTriangles)
> + {
> + // flash 10
> + var vertices:Vector.<Number>, // xy coords of triangle on 2d output bitmap to be "filled"
> + indices:Vector.<int> = null, // mapping of input sets of vertices to triangle vertices
> + uvtData:Vector.<Number> = null; // UV data points matching input vertices, along with a T value (scale due to z-depth)
> + x0 = tri.v0.x;
> + y0 = -tri.v0.y;
> + x1 = tri.v1.x;
> + y1 = -tri.v1.y;
> + x2 = tri.v2.x;
> + y2 = -tri.v2.y;
> + vertices = Vector.<Number>([ // not right; this is the triangle on the texture, we want the triangle on the output?
> + x0, y0,
> + x1, y1,
> + x2, y2
> + ]);
> + indices = Vector.<int>([
> + 0,1,2
> + var fl:Number = renderSessionData.camera.focus;
> + uvtData = Vector.<Number>([
> + tri.triangle.uv0.u, tri.triangle.uv0.v, (fl/(fl+tri.v0.z)),
> + tri.triangle.uv1.u, tri.triangle.uv1.v, (fl/(fl+tri.v1.z)),
> + tri.triangle.uv2.u, tri.triangle.uv2.v, (fl/(fl+tri.v2.z))
> + ]);
> + graphics.beginBitmapFill(bitmap, null, tiled, smooth);
> + graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE);
> + graphics.endFill();
> + renderSessionData.renderStatistics.triangles++;
> + return;
> + }
> if( lineAlpha )
> graphics.lineStyle( lineThickness, lineColor, lineAlpha );
> if( bitmap )
>
>
>
> On May 20, 2009, at 9:38 AM, Alan Pinstein wrote:
>
>
> Clox-
>
> We are going to work on this today, too. We're on eastern time. I'll hop on IRC an let's see if we can find each other and make some progress.
>
> Alan
>
> On May 20, 2009, at 1:51 AM, Clox wrote:
>
>
>
>
> Jake Lewis wrote:
>
>
> The problem with drawTriangles is that there is no z sorting of the
> triangles. For a simple scene made up of one simple (ie non-concave)
> object
> this is fine ( ie it will work for your virtual tour Alan) but a generic
> AP
More information about the Papervision3D
mailing list