hi,anybody can rewrite this demo in away3d?

4 views
Skip to first unread message

vkt

unread,
Aug 29, 2008, 6:06:15 AM8/29/08
to away3d.dev
http://blog.zupko.info/

I like they Reflections ,but now away3d have no Reflections class.

and I also try geepers's ViewReflection class,but it not support
camera rotaiton.

right now My project need some reflections effect..




vkt

unread,
Aug 29, 2008, 6:07:13 AM8/29/08
to away3d.dev

Li

unread,
Aug 29, 2008, 11:38:53 AM8/29/08
to away3...@googlegroups.com
Ah, wonderful!!

Ill give it a try...


Li

unread,
Aug 30, 2008, 10:31:45 AM8/30/08
to away3...@googlegroups.com
Hehe, I tried to port it and all I got was a terrible headache! You have to be very familiar with both engines for this, at design level I mean.

Ill try to understand the theory and make a new reflection class in away3d from scratch. If anyone has any links to articles or books that could help me with this, it'd be great!

Li

unread,
Aug 31, 2008, 10:37:11 AM8/31/08
to away3...@googlegroups.com
Ok, slow, but steady...

I realised that to make something like this, I had to start from the beginning. The beginning is shadows, and from there, reflections can be managed similarly but with more complexity... Im beginning to understand this shadows and reflections thing now. On the source you'll find a draft for a shadow projection class I made based on Zupko's theory, but not his code. The cool thing about it, is that the class does not use a secondary camera and view, it projects vertices from a point onto a plane.

This is the demo (move around with keyboard "wasd" and mouse):
http://www.piar.com.ar/li/away/shadows/

And this is the source:
http://www.piar.com.ar/li/away/shadows/VertexProjection.zip

As I dont know the engine's core, Im sure the code can be greatly optimized. I work on a more superficial layer of the engine...
Id be happy if anyone wants to work in this. Reflections are next, with bump mapping and transparency.

Rob Bateman

unread,
Aug 31, 2008, 11:06:08 AM8/31/08
to away3...@googlegroups.com
niiiiiiice :)


i'm wrapped up in some other away3d updates right now, but i think this is definitely something to add to the engine asap. And you should release this online as a demo! maybe you will attract more potential collaborators that way. great job so far!

Rob
--
Rob Bateman
Flash Development & Consultancy

rob.b...@gmail.com
www.infiniteturtles.co.uk
www.away3d.com

Fabrice

unread,
Aug 31, 2008, 11:11:59 AM8/31/08
to away3...@googlegroups.com
Very cool Li!
I'm sure many will enjoy/use this!

Fabrice

vkt

unread,
Aug 31, 2008, 11:38:32 AM8/31/08
to away3d.dev
WOW! so great demo :) Li
Looking forward to your next demo about reflections.

Li

unread,
Aug 31, 2008, 12:19:48 PM8/31/08
to away3...@googlegroups.com
Cool, it would be very nice on the engine. I would upgrade it by making it extend a pointlight object instead of an object container as it is in this demo.

I need a little help for reflections please...
Does anyone know how away draws triangles into materials? Im guessing this has something to do with UV mapping. For example in a bitmap texture, Away3d has to redraw the texture onto a face in some way, performing a perspective deformation. I have absolutely no idea on how this works, and I need it for reflections... Can anyone point me in the right direction about how this works?

Thanks!!

Fabrice

unread,
Aug 31, 2008, 1:33:01 PM8/31/08
to away3...@googlegroups.com
Li,
AbstractRenderSession and for instance BitmapMaterial should help you understand the way it works.

Fabrice

Fabrice

unread,
Aug 31, 2008, 1:40:05 PM8/31/08
to away3...@googlegroups.com
http://www.closier.nl/playground/beginbitmapfill.html

this demo should also help to understand visually.

Ignore the comments, 2 years ago I was rendering all 3D into a single bitmap and was looking at ways to draw the faces
full pixels the fastest way. But most shown in it is still actual.

Fabrice

On Aug 31, 2008, at 6:19 PM, Li wrote:

Li

unread,
Aug 31, 2008, 7:38:03 PM8/31/08
to away3...@googlegroups.com
Thanks Fabrice!
Ill be looking into it =)

katopz

unread,
Aug 31, 2008, 11:48:09 PM8/31/08
to away3...@googlegroups.com
thx, Li ;D

2008/9/1 Li <paleb...@gmail.com>

Li

unread,
Sep 1, 2008, 5:07:30 PM9/1/08
to away3...@googlegroups.com
Ok, still advancing...
I managed to resolve the vertex projection part for reflections.

DEMO: www.piar.com.ar/li/away/reflections/plainvertexprojection

Now, the hard part must be done; Currently, Im only copying the vertices and filling in the projected triangles with the object's WireColorMaterial color. This, without considerint sorting (thats why you can "see through" the reflection's material)...
I have to find a way to manage this sorting and copy the projected face's materials into the projection. Fabrice and Rob gave me a hand with this explaining how texture mapping is handled by the engine with beginBitmapFill() and matrix deformations. However, Im having a hard time finding a face's corresponding matrix to project the texture with a method involving beginBitmapFill... Any help would be great now!!

Li

unread,
Sep 2, 2008, 11:23:48 AM9/2/08
to away3d.dev
Bump mapping and transparency applyed. Still pending to resolve what I
posted earlier... Once that is done, Ill upload the source.

DEMO: http://www.piar.com.ar/li/away/reflections/plainwithbump/

On Sep 1, 6:07 pm, Li <paleblue...@gmail.com> wrote:
> Ok, still advancing...
> I managed to resolve the vertex projection part for reflections.
>
> DEMO:www.piar.com.ar/li/away/reflections/plainvertexprojection
>
> Now, the hard part must be done; Currently, Im only copying the vertices and
> filling in the projected triangles with the object's WireColorMaterial
> color. This, without considerint sorting (thats why you can "see through"
> the reflection's material)...
> I have to find a way to manage this sorting and copy the projected face's
> materials into the projection. Fabrice and Rob gave me a hand with this
> explaining how texture mapping is handled by the engine with
> beginBitmapFill() and matrix deformations. However, Im having a hard time
> finding a face's corresponding matrix to project the texture with a method
> involving beginBitmapFill... Any help would be great now!!
>
> On Mon, Sep 1, 2008 at 12:48 AM, katopz <kat...@gmail.com> wrote:
> > thx, Li ;D
>
> > 2008/9/1 Li <paleblue...@gmail.com>
>
> > Thanks Fabrice!
> >> Ill be looking into it =)
>
> >> On Sun, Aug 31, 2008 at 2:40 PM, Fabrice <fabric...@gmail.com> wrote:
>
> >>>http://www.closier.nl/playground/beginbitmapfill.html
> >>> this demo should also help to understand visually.
>
> >>> Ignore the comments, 2 years ago I was rendering all 3D into a single
> >>> bitmap and was looking at ways to draw the faces
> >>> full pixels the fastest way. But most shown in it is still actual.
>
> >>> Fabrice
>
> >>> On Aug 31, 2008, at 6:19 PM, Li wrote:
>
> >>> Cool, it would be very nice on the engine. I would upgrade it by making
> >>> it extend a pointlight object instead of an object container as it is in
> >>> this demo.
>
> >>> I need a little help for reflections please...
> >>> Does anyone know how away draws triangles into materials? Im guessing
> >>> this has something to do with UV mapping. For example in a bitmap texture,
> >>> Away3d has to redraw the texture onto a face in some way, performing a
> >>> perspective deformation. I have absolutely no idea on how this works, and I
> >>> need it for reflections... Can anyone point me in the right direction about
> >>> how this works?
>
> >>> Thanks!!
>

vkt

unread,
Sep 2, 2008, 11:33:58 AM9/2/08
to away3d.dev
I will be concerned about your progress,Li

Li

unread,
Sep 2, 2008, 12:03:05 PM9/2/08
to away3...@googlegroups.com
Forgot to mention!!
Use the keyboard "wasd" or arrows and mouse to move behind the plane... The plane is not only reflective, its transparent and hence refractive.
http://www.piar.com.ar/li/away/reflections/plainwithbump/

Li

unread,
Sep 2, 2008, 12:50:16 PM9/2/08
to away3d.dev
Me again...
The previous demo + shadows: http://www.piar.com.ar/li/away/reflections/plainwithbumwithshadow/

On Sep 2, 1:03 pm, Li <paleblue...@gmail.com> wrote:
> Forgot to mention!!
> Use the keyboard "wasd" or arrows and mouse to move behind the plane... The
> plane is not only reflective, its transparent and hence refractive.http://www.piar.com.ar/li/away/reflections/plainwithbump/

Peter Kapelyan

unread,
Sep 2, 2008, 12:52:39 PM9/2/08
to away3...@googlegroups.com
Holy Cow!
 
That is super amazing and looks great!

Superb job, Li! You are kicking some major butt with that stuff!

My eyes are really big and mouth is drooling :O
--
___________________

Actionscript 3.0 Flash 3D Graphics Engine

HTTP://AWAY3D.COM

Jensa

unread,
Sep 2, 2008, 1:56:28 PM9/2/08
to away3d.dev
Awesome job Li! Keep at it!

J

Rob Bateman

unread,
Sep 2, 2008, 2:07:35 PM9/2/08
to away3...@googlegroups.com
very cool! love it.

Rob


On Tue, Sep 2, 2008 at 6:56 PM, Jensa <jen...@gmail.com> wrote:

Awesome job Li! Keep at it!

J



Li

unread,
Sep 2, 2008, 2:30:04 PM9/2/08
to away3...@googlegroups.com
Thanks Peter, and everyone else for the positive replyes...

Here it is with an jpeg as bumpmap:
http://www.piar.com.ar/li/away/reflections/bumpwithimage/

Li

unread,
Sep 2, 2008, 5:08:20 PM9/2/08
to away3d.dev
Ok, Im completely stuck here. My head is about to explode!!

You can see the problem I have in this DEMO:
http://www.piar.com.ar/li/away/reflections/theproblem/
As I tryed to explain before, im having problems when redrawing the
reflected object's materials on the plane. With wirecolormaterials Im
only having trouble with sorting, but with moviematerials Im also
having trouble with the orientation of the vertices in the
beginbitmapfill method.

Ive made a big effort to make the source organized and have lots of
comments, so, here it is: http://www.piar.com.ar/li/away/reflections/theproblem/AdvancedReflections.zip

I believe that if someone familiar enough with the engine's core grabs
this, the problem would be resolved easily and quickly... A little
help and we're done!

On Sep 2, 3:30 pm, Li <paleblue...@gmail.com> wrote:
> Thanks Peter, and everyone else for the positive replyes...
>
> Here it is with an jpeg as bumpmap:http://www.piar.com.ar/li/away/reflections/bumpwithimage/
>
> On Tue, Sep 2, 2008 at 3:07 PM, Rob Bateman <rob.bate...@gmail.com> wrote:
> > very cool! love it.
>
> > Rob
>
> > On Tue, Sep 2, 2008 at 6:56 PM, Jensa <jens...@gmail.com> wrote:
>
> >> Awesome job Li! Keep at it!
>
> >> J
>
> > --
> > Rob Bateman
> > Flash Development & Consultancy
>
> > rob.bate...@gmail.com
> >www.infiniteturtles.co.uk
> >www.away3d.com

Fabrice

unread,
Sep 2, 2008, 6:09:46 PM9/2/08
to away3...@googlegroups.com
well, its because you reverse the face and scramble it,
to flip a face with vertexes [a b c] , make it [ b a c]

as about the uv's they also required to be ordered.

uva = new UV(0, 0);//downleft
uvb = new UV(0, 1 );//topleft
uvc = new UV(1, 1);//topright
uvd = new UV(1, 0);//downright

but shouldn't have to change them since you want reversed image, just
flip the face and you will be fine, otherwize if needed
flip order uvs on the exact same way as vertexes following the same
sequence.

Take a look at Lathe class, many examples of combinations in there.

//My head is about to explode!!
Take a break, you've done enough for today :))

Fab

Li

unread,
Sep 2, 2008, 11:38:58 PM9/2/08
to away3...@googlegroups.com
Fabrice: Ive been working with your suggestion with no success. Tryedas hard as I can.... The problem seems to be reduced to finding which faces to draw on the reflective plane. These are not the same faces as the ones drawn on the "real" object.

Question: Somewhere in the engine something is deciding which faces will be drawn. I suppose it makes this decision based on the objects position, if it is bothsided, etc. We need to apply this same logic to the "virtual" object this time, created in the reflection, and simply decide which faces will be drawn. Who makes this decision? And how does it create the appropiate DrawTriangle once it has been passed for rendering?

Fabrice

unread,
Sep 3, 2008, 4:16:16 AM9/3/08
to away3...@googlegroups.com
Hey Li,
The suggestion should work on the face issue... 
Set the cube to bothsides:true if you see the projection ok, and you have set the faces in right sequence order, then you are good for next step.

The point I think here is that you try render faces that are not in the loop, at some angles, you would need to see faces not in the renderlist of the object.
In other words, you want to see the mirrored dark side of the moon.
So you will need here to write a class that is a flipped clone of the original mesh and use that info. This should also increase speed since the faces would be ready to be used at any time. They also would have a front property instead of back property automatically.

For the shadow or fills case, may be another concept worth a try:
Take a look at the way the outline works. So instead of drawing whole geometry face by face, just collect the vertexes of the hedges, project them, and read on Render the list you've composed to draw once the whole shadow shape into your source destination. This would ensure almost same draw speed for simple or complex objects... and since your cast image also is a rectangle, you even could skip some vertexes if their are not included in that rect. Note that I haven't read your code, so you might do it already.

Just thinking loud here :)

Fabrice 

Rob Bateman

unread,
Sep 3, 2008, 6:07:00 AM9/3/08
to away3...@googlegroups.com
Hey Li


unfortunately i can't dive straight in here due to time constraints on other work, but i can point you in the direction of what you need

basically your talking about two things, rear face culling and z-sorting. both look out of whack in your reflection demo, so heres a couple of pointers as to how you could fix the problem.

a) face culling

the method away3d uses for this is to return the calculated area of a drawtriangle class (the 2d representation of a face in a view). However, this is not going to be easy to replicate in your demo as you are drawing directly from face to material! One way of seeing whether a face should be culled is calculating the dot product of the face normal to the camera axis. the face normal is easily obtained - there is a property called normal on the face class. tranforming it to world coordinates will require a similar set to the one you are doing in getVertexGlobalPosition, and finding the dot product between it and the camera vector (the world z axis of the camera object (or line of sight) is easily done with the number3d methods. if the product is positive, the face is facing the camera and should be drawn. otherwise it should be discarded.

b) z-sorting

currently this is not done at all in your render loop - basically you need to sort the drawing order of faces so that the ones furthest from the camera are drawn first, the next further drawn next and so on. you can get the global position of the vertices of each face by multiplying the scenetranform matrix of the object by the view matrix of the camera, then calulate a zdepth value by averaging their z-values. duplicate and sort the array based on this value, and then draw each face in the correct order.


sorry i can't be of more assistance right now - while the reflections you produce look great i am in no position to take this on myself atm, so i hope assistance in theory will be enough to point you in the right direction!

atb

Rob

Li

unread,
Sep 3, 2008, 12:16:39 PM9/3/08
to away3...@googlegroups.com
Thanks guys, your suggestions have been very useful.

Fabrice: Setting bothsides to true is necessary in order to obtain valid drawTriangles, and it is what im using. And Ive thought about your second suggestion and I will definitely implement it when I can, it could reduce cpu cost dramatically for shadows. It would involve an algorithm that would decide how to fill a vertex cloud...

Rob: Your two suggestions have been implemented succesfully. Ive used the virtual face's normal to determine if it should be rendered, and while doing this, I sorted the ones passed for rendering on their distance to the camera. Its been very effective.

See the new DEMO: http://www.piar.com.ar/li/away/reflections/sortingsolved/
The only problem that is left is determining in what order the 3 points are passed to the beginBitmapFill method. For this I believe I need to recognize which point is opposite to the hypotenuse of the triangle, and then somehow decide which is left to it and which is right to it... I have to pass p1, p2 and p3 in the right order in order to avoid scrambled faces. Do you know if there are any inherent conventions for this in the engine? Do you remember any part of the engine that handles anything similar to this?

Daevid

unread,
Sep 3, 2008, 12:53:00 PM9/3/08
to away3d.dev
Looks really cool so far! I hope you get the vertex/face sorting...
well... sorted out!

Is this effect created with a new shader class or does it need any
other changes to the engine?

/David

Li

unread,
Sep 3, 2008, 1:38:23 PM9/3/08
to away3...@googlegroups.com
Daevid,

Im trying to make it work with no changes to the engine, just a ReflectivePlane class that extends Plane, and a ShadowProjector class that extends PointLight3d. Anyway, if this gets assimilated in the engine, I suppose that the classes would be spread around a bit in order to optimize the processes involved in the effects.

Fabrice

unread,
Sep 4, 2008, 3:56:19 AM9/4/08
to away3...@googlegroups.com
My suggestion to set the bothsides to true is not to be used in the final version, it's just a way help you to build it up and solve each problems one at a time.
Right now you have more issues, one of them was a proper flip of the faces and set the uv's in right sequence. See it as a debug. When the bothsides info would be correctly displayed, then you can go for step two, use the back faces only.
Btw, using a grid like texture with colors, like a TV test image is also a faster way to see what's going wrong.

As about the hedges vertexes selection, the code is in there already.
Indeed an algo to fill a shape from points will be required.

Fabrice

Li

unread,
Sep 4, 2008, 10:12:45 AM9/4/08
to away3...@googlegroups.com
Hey Fabrice,

I noticed the proper flip issue and fixed it. About the rest of your commentaries I totally agree and will consider them seriously. Unfortunately Im gonna be a lot more busy these days so I wont be able to make progress on this for a while. Anyway, I take it as a good chance to slow down and start up a fresh copy of these classes, considering all the issues that came up during experimentation. So, I ask you and (anyone else interested) to drop any helpful commentaries here while I develop it. With a bit of patience, this should be a cool thing to have available in a few days...

Cheers!
Reply all
Reply to author
Forward
0 new messages