Matcap

Software: Away3D 4.x

Przemek, Newbie
Posted: 21 January 2014 11:42 AM   Total Posts: 5

Im searching for fastest method of rendering nicelooking materials. For me the best choice is technique used in sculpting software like Zbrush or part of Blender which uses “Matcaps”. Its really fast and toegether with fake shadows could be really fast solution for games.Is it possible to use this in Away3D v 4.1?

Now I can see only one method - to use environment map reflections, but its a bit strange solution for this problem. Should be something simplier.

Im not familiar with writing AGAL shaders, but maybe now this is only one possibility? What’s the best route?

   

Avatar
theMightyAtom, Sr. Member
Posted: 21 January 2014 12:39 PM   Total Posts: 669   [ # 1 ]

Very interesting technique, and as you say should provide a fast rendering method.
I admit I had to look up what Matcaps were, not coming from a Zbrush or Blender background.

Basically you are taking the normal map from the camera position, and replacing each pixel value from a pre-rendered sphere.

As far as writing your own shader for Away3D, I know no better source than the tutorials on this site…

http://away3d.com/tutorials/Writing_Custom_Materials_1:_Getting_Started
http://away3d.com/tutorials/Writing_Custom_Materials_2:_Adding_Textures
http://away3d.com/tutorials/Writing_Custom_Materials_3:_Simple_Lighting

And then you want to get hold of the normal map,
https://github.com/away3d/away3d-core-fp11/blob/master/src/away3d/materials/methods/BasicNormalMethod.as

That’s as far as I can go, unless I suddenly get some time off smile
I hope you crack it, or someone else takes up the challenge. Certainly seems like it would be a welcome addition to the material library.

Good Luck!

 

   

Van Hellsing, Newbie
Posted: 21 January 2014 12:42 PM   Total Posts: 30   [ # 2 ]

As far as I get it, You all you have in away 3d is a Diffuse map, Normal Map and Specular map and Environment mapping.

If you are making a game your workflow should basically look like this:

1. Make a nice looking detailed model with all the materials you wish in blender.
2. Make a lowpoly mesh for away3D with significantly less detail. In fact, make it as simple as humanly possible. Most of the detail will be replicated with above methods.
3. Make UV map for lowpoly mesh.
4. Bake normals, specular intensity and textures.
5. Export the mesh to some format, that is compatible with away3d (i stick with obj, but I’m not sure if it’s the best option) Don’t forget that away3d unit is 100 times smaller than blender unit, so you have to scale by 100 your model upon exporting (this can be set in blender exporter).
6. assemble your model in prefab or away builder, whichever works for you. This means, import your obj, create a new material, set diffuse, normal an specular textures, and assign it to your mesh.
7. Profit!

This is how my model looks like. Left to right: high poly model, low poly model, baked textures. Top to bottom: diffuse map, normal map, specular map.

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 21 January 2014 12:50 PM   Total Posts: 669   [ # 3 ]

That would be another solution, yes.
I think Przemek was hoping to leverage the existing libraries of Matcap materials…
http://pixologic.com/zbrush/downloadcenter/library/

Which would be ultra cool

 

   

Przemek, Newbie
Posted: 21 January 2014 08:25 PM   Total Posts: 5   [ # 4 ]

Yes, Matcaps could be great!, with this kind of material I can literally “draw” shader, there is one limitation with this - objects have the same shading direction from every point of view, but in fact this could be advantage in some games. Anyway it could give big visual kick for models.

Here is demo of Matcap in Unity (every of this shading effect is made by geometry + 1 bitmap, without any lights): http://www.youtube.com/watch?v=f4Kbndx6TCI

Till now, from the first demo on this page http://blog.tartiflop.com/tag/texture-mapping/ I can see that EnviroBitmapMaterial from Away3D 3.6 could work for this. Just it was for reflections, and disappeared from 4.1…

 

   

Van Hellsing, Newbie
Posted: 21 January 2014 09:01 PM   Total Posts: 30   [ # 5 ]

It looks a lot like an environment map. I mean, it looks like it works in a very similar way. Maybe you should try something in that direction?

 

   

Przemek, Newbie
Posted: 24 January 2014 11:06 PM   Total Posts: 5   [ # 6 ]

I did some working version of Matcap material, I mean Im not sure vector equations which Ive written in the shader, some parts are still bit mystery for me, but visual effect is what I wanted. I dont know if its really fast.

This shader is working only with perspective camera, for Orthogonal probably I should change transforming matrix, but still I don’t know how.

To use matcap material import this two classes from zipped file: MatCapMaterial and MatCapPass, embed some MatCap texture (size 128x128, 256x256, ... etc)
And set material for mesh in the scene this way for example:

yourMesh.material = new MatCapMaterial(yourTexture:Texture2DBase); 

Give some feedback please if you make tests, especially its interesting if shader works for big zooms (if I know its not working with orthogonal lenses).

Edit: In the post #12 I have attached corrected version of this shader.

 

 

File Attachments
matcap_Away3D.zip  (File Size: 2KB - Downloads: 349)
   

Avatar
theMightyAtom, Sr. Member
Posted: 26 January 2014 01:31 PM   Total Posts: 669   [ # 7 ]

That didn’t take you long, terrific!

I have downloaded, tested and it works like a charm.
http://videometry.net/away3d/matcap/

Very nice additional material option, I’m impressed.

Cheers!

 

   

John Brookes, Moderator
Posted: 26 January 2014 03:39 PM   Total Posts: 732   [ # 8 ]

@Przemek
Nice work smile

@mighty
That glass is nice wheres that from? Been collecting a few.

While im here. Nice utility to create your own.(windows)
http://www.zbrushcentral.com/showthread.php?92157-MaCrea-Material-Creation-Tool

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 26 January 2014 04:20 PM   Total Posts: 669   [ # 9 ]

@john
All my textures were made in Keyshot.
Simply import a sphere model, and there you go.

There’s a large library of raytrace materials included, and environments.
Naturally you can also use your own environments for the perfect match up.

@Przemek
Memory usage is indeed very low. A single 512x512 matcap texture is naturally far smaller than creating a whole cube map.

This is a good, cheap reflection/cartoon method, with the option to blend in some other material attributes. You could even generate the maps client side for even more efficiency, variation and flexibility.

What’s not to like smile

 

   

Przemek, Newbie
Posted: 26 January 2014 11:54 PM   Total Posts: 5   [ # 10 ]

@theMightyAtom
Yes, two nights of obsession with vectors and its ready gulp Was worth, Im not afraid of word AGAL as much as earlier.

I found today this demo http://jeanmoreno.com/matcap/
it illustrates exactly what you wrote about blending Matcap with other material attributes. If shadow method and normalmap method works with this material out of the box we can play the same tricks from now. If not hope I can add this functionality in shader or find another way with composing materials. I will investigate subject, looks like this method will be my favourite in game creation.

 

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 27 January 2014 07:52 AM   Total Posts: 669   [ # 11 ]

I can confirm that it works in combination with shadow casting lights, but there is unfortunately no way to add a normal map as long as it extends MaterialBase.

I tried extending MultiPassMaterialBase instead, but there’s unfortunately more to it than that. You of course would need the normal value of the pixel of the normal map added to your shader and preferably in a single pass. I wish you good luck, keep up the great work :O)

Cheers

 

   

Przemek, Newbie
Posted: 29 January 2014 06:38 PM   Total Posts: 5   [ # 12 ]

Corrected version of Matcap material.
Works with orthogonal lenses, and finally works well with any field of view of camera. First version of shader was doing significant distortions of texture, for lenses with FOV much smaller or bigger than 90.
Now works properly.

 

File Attachments
matcap_Away3D_v2.zip  (File Size: 3KB - Downloads: 293)
   

Avatar
theMightyAtom, Sr. Member
Posted: 06 March 2014 04:43 PM   Total Posts: 669   [ # 13 ]

I mananged to integrate normals today for a project I’m working on.
Help yourselves to the source if you need it smile

http://videometry.blogspot.dk/2014/03/matcap-with-normalmapping.html

Cheers!

 

   

Avatar
Fabrice Closier, Administrator
Posted: 06 March 2014 08:35 PM   Total Posts: 1265   [ # 14 ]

I’ve looked a bit at the way it works, it surprisingly looks a lot like the way we were “faking” lighting in the early days of the engine in Flash 9 smile
Similar to what Ralph was doing too. Probably very usefull on mobile…

 

   

Avatar
Darcey, Moderator
Posted: 07 March 2014 08:30 PM   Total Posts: 209   [ # 15 ]

Quite impressive, maybe a very good addition to Away3D? wink

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X