Tuesday, 4 March 2014

MatCap Materials, and Smooth Soft Shadows for Away3D


Today I'm going to introduce a couple of techniques for improving realism, while reducing the load in real-time 3D scenes using Away3D 4.0.

You might be surprised to learn there are no lights in this scene whatsoever. Neither are the materials "baked" in any way. In fact this nice shiny plastic material can be applied to any object with mapping coordinates, though curvy, organic shapes work best.

It is known as a "MatCap" material, and was developed for Away3D by Przemek. (props!)
http://away3d.com/forum/viewthread/5255/

This type of material has long been available in Z-brush, among other packages.
The material consists of a single bitmap of a sphere and a shader that reads values from the bitmap and apply them to the object dependent on a faces angle to the view.

Here's the map used, plus a couple more examples.


You'll find more on MatCap, or Material Capture shaders all over the web. Here's a nice intro vid.

Here's the source, including the version of MatCapMaterial available at time of posting.

Apart from the actual material, take a look at the soft subtle shadow under the teapot. To get such a soft shadow I would normally render the scene using a raytracing renderer such as Mental Ray and attach it to a plane below the object, as it's just about impossible, and extremely processor intensive to do in real-time.

Currently I'm working with objects that are created in real-time, so rendering the shadow in MAX is simply not an option. To get around this I made a class called SuperSoftShadow (also provided in the source download, together with a FlashDevelop project file)



In the examples above and below the shadow is drawn dynamically when the scene initializes, and from then on uses no processor at all, it is a simple plane with the shadow TextureMaterial attached, and a BlendMode.MULTIPLY to blend it in with the background.

A couple of Gotchas there. The background here is an actual plane in the scene. If you try to use BlendMode.MULTIPLY on a background using the view3D.background, the whole screen turns black(!). Another thing I've discovered is the alpha value appears to be ignored when using blend modes.

What the SuperSoftShadow class does, is given an ObjectContainer3D such as a Loader3D, takes a snapshot using an Ortographic camera placed above, and then uses AS3's built in BlurFilter to soften it as much as you like. The resulting bitmapData is then applied to a texture on a plane, also created dynamically to match the size of the container.

Here's how to use it:

shadow = new SuperSoftShadow(container, this.stage, blur, size, yoffset, shadowColor, distance);

A look at the constructor describes the parameters.

container - The container to apply the dropshadow to. This can be a loader3D.

stage - Reference to stage required for creating stage3D instance.

blur - The blur amount for the shadow. Note that using larger bitmap sizes requires using large blur values.

size - The size of the bitmap to use. This can be any power of 2 dimension (512 x 512, 1024 x 1024, 2048 x 2048...etc.) The bigger the bitmap the better the quality.

yoffset - This is the y position within the container, which the shadow will be attached to. The class attempts to place the shadow directly underneath the container (minY) though this may not be the desired position.

shadowColor - A hexadecimal code for the colour of the shadow. This can be useful for radiosity effects for glowing objects, glass objects, etc.

distance - An optional value to control the cross-section of the object container to use. This controls the near plane of the camera that takes the snapshot. 

Another example using dynamic text...


(if you don't have the patience to watch it turn slowly, try the arrow keys :)
You can enter your own text to see the dynamic shadow in action. You can also adjust the extrusion depth of the text with up and down arrows, but you need to press ENTER to update the shadow, or the text.

The material for the text uses yet another technique, image based lighting, a bit more tricky, but worth the effort :)

Enjoy!





Friday, 22 June 2012

New Mouse Events for Away3D 4.0

It's about time I posted something useful. Hopefully this will be of use to budding 3D application developers everywhere :)

I've extended the Away3D Mouse3DManager and MouseEvent3D classes to accept the right click and middle click events recently added to Flash Player (Novemeber 2011, I think)

Remember to update your compiler and target Flash Player 11.2 or later. I had to do a bit of mucking about in FlashDevelop to get it working myself, which may well explain why it's not yet in the official Away3d library. Here's a really crazy, wild demo to show it works...

(Click image to open demo. Click/Scroll on ball  to see events triggered)
 

And here are the files...
Mouse3DManager.as
MouseEvent3D.as

Usage Example:
ExtraMouseEvents.as

Enjoy!

Thursday, 9 February 2012

Flash is Dead, Long live AIR


Gravestone Generator



If you're on my blog, you probably belong to the group of us who appreciate Flash as a rapid development platform that just works, if you understand what you're doing.

If you're a Flash hater, you will no doubt have been delighted to read Adobe's latest press release, with yet more troll fodder.

http://blogs.adobe.com/flashplayer/2012/02/flash-chrome-for-android-beta.html

So, where does that leave Flash actually? It will no longer be attractive for advertisers, as they want maximum reach, which will leave it to game developers, and serious application developers. Perfect.
Drop the ads you don't like in Flash, download the apps and games you do like as AIR (though you'll never even know what language they're written in, right?)

What about advertising? We all love free content, but how will websites pay the bills?
Here's a message to all the Flash haters, which I admit is a large, or at least very vocal group:

Prepare to become HTML5 haters.


Advertising pays for content creation, advertisers compete for your attention. Everything you hated in Flash will now be created in HTML5, and here's the rub, you won't be able to turn it off any more. You won't be able to disable or remove the plugin (not many flash haters actually do remove the plugin, strangely. Make your own conclusions).

As for flash developers, should we drop flash and become "interactive developers" as some Flash evangelists would have you believe? Considering the new firepower Flash 11 has got, it's never been a better time for actually making flash apps and games. The distribution model is changing, and definitely if you are a banner ad designer you should be jumping ship. For those of us that develop applications, Objective C or Java would make sense, to keep with the times and go mobile. But wait, why not just use AIR?
At this moment AIR with hardware acceleration hasn't been released, and despite all my efforts I haven't found even as much as a target launch date. But it is in closed Beta, and Adobe are showing it off  so why not stick it out, the last 10 years might not have been a complete waist of time after all...

Monday, 24 October 2011

Cubic Bezier Curves - Flash 11

With all the (deserved) hype surrounding Stage3D, it's easy to miss some of the other great new features of Flash Player 11.

Over the weekend I tried and failed to find an example of Cubic Bezier Curves (cubicCurveTo), so there was no way out but to build one. In the past this would required a degree in maths and a minimum 4 litres of Red Bull, but with the new command any idiot can do it, and here's the proof...

DEMO

Click to add a point, click and drag to set the bezier curve. Right click to either "end" or "close" the polygon.
Once the polygon is drawn, use the control points to change the curves and vertex positions.
Press "Reset" to, err, reset.

And here's the source to get you started on your very own Illustrator clone.

Friday, 23 September 2011

15 Seconds of Fame


Away3D 4.0 Showreel 2011 using Flash Player 11 beta from Rob Bateman on Vimeo.


Well, actually not quite 15 seconds, but we managed to get 2 demos into the new Away3D showreel.

Tuesday, 13 September 2011

Introducing Atomizer


As seen in an earlier post, I've been messing with image based 3D. That is to say encoding 3D information into video. The technique is showing some promise, and I've started formalising it into an exporter for 3D Studio MAX and an AS3 library for Flash/Away3D. Here's another quick example. Please view in fullscreen.

To the right of the curtains you will see a small, wierd animation/film, that looks like this:

That is actually all the information needed to drive the curtain animation, that is happening realtime, as appose to a video. The vertex positions are simply captured and made into a video, that could be streamed over the net.
As you can see the video is very small. As described in a previous post it can also be applied to meshes of varying resolution.

Here's the same 3D animation with camera control
http://www.videometry.net/atomizer/cam/

.

Flash Player 11 - Release Candidate 1

We are approaching probably the most exciting Flash Player release in history!
Not since version 4 introduced scripting has there been a more major update.
We've been through quite a few beta versions, and visitors to the site will likely have experienced broken demos, as with each development cycle updates were necessary, and if you didin't have the right player, for the right demo, it was tough luck.

This morning, rather than play my customery game of online Scrabble, I went through all my old experiments and recompiled for Flash Player RC1. As the name suggests, this is not the final version, but it's worth testing some content with it, and reporting to Adobe any issues you might come across.

I'm sad to see that support for Intel graphics has been removed as it was running beautifully on my media center before this release. Apart from that, it seems very stable. Look forward to seeing it on mobile soon :O)