Skip to content

v0.9 Tutorial 03 Materials

contriteobserver edited this page Jul 16, 2017 · 1 revision

SIMPLE MATERIAL

A basic material is just a color or a texture without any lighting enabled. This renders a green cube:

Material simple = new Material();
simple.setColor(Color.GREEN);
mCube.setMaterial(simple);

This renders a textured cube:

Texture texture = new Texture("unique_identifier", R.drawable.mytexture);
Material simple = new Material();
simple.addTexture(texture);
mCube.setMaterial(simple);

LAMBERT MATERIAL

Use this material to emulate diffusely reflecting surfaces. See this article on Wikipedia.

DirectionalLight mLight = new DirectionalLight(-3,-6,-3);
getCurrentScene().addLight(mLight);

Material lambert = new Material();
lambert.setColor(Color.YELLOW);
lambert.setDiffuseMethod(new DiffuseMethod.Lambert());
lambert.enableLighting(true)

mCube.setMaterial(lambert);

PHONG MATERIAL

Use this material to get nice specular highlights. See this article on Wikipedia.

DirectionalLight mLight = new DirectionalLight(-3,-6,-3);
getCurrentScene().addLight(mLight);

Material phong = new Material();
phong.setColor(Color.YELLOW);
phong.setSpecularMethod(new SpecularMethod.Phong());
phong.enableLighting(true)

mCube.setMaterial(lambert);

IMAGE MAPPING

Image maps can be applied to materials to simplify alpha, specular, and normal mapping.

Here is an example of how mapping is utilized:

Texture texture = new Texture("drawableTexture", R.drawable.texture);
NormalMapTexture normalMap = new NormalMapTexture("normalMap", R.drawable.normal);
SpecularMapTexture specularMap = new SpecularMapTexture("specularMap", R.drawable.specular);
AlphaMapTexture alphaMap = new AlphaMapTexture("alphaMap", R.drawable.alpha);

Material myMappedMaterial = new Material();
myMappedMaterial.addTexture(texture);
myMappedMaterial.addTexture(normalMap); //RGB normal map
myMappedMaterial.addTexture(specularMap); //Black and white alpha map where white is shiny
myMappedMaterial.addTexture(alphaMap); //Black and white alpha map where white is opaque

Object3D mObject = new Cube();
mObject.setMaterial(myMappedMaterial);
getCurrentScene().addChild(mObject);

ENVIRONMENT CUBE MAP MATERIAL

See https://github.com/Rajawali/Rajawali/wiki/Tutorial-05-Skybox

BUMP MAP/NORMAL MAP MATERIAL

See https://github.com/MasDennis/Rajawali/wiki/Tutorial-14-Bump-Normal-Mapping

PARTICLE MATERIAL

See https://github.com/MasDennis/Rajawali/wiki/Tutorial-11-Particles

CUSTOM MATERIAL/GLSL SHADER

See https://github.com/MasDennis/Rajawali/wiki/Tutorial-09-Creating-a-Custom-Material---GLSL-Shader

TOON/CEL MATERIAL

Use this material to emulate a cartoon-style effect. Read more about this in this Wikipedia article.

DirectionalLight mLight = new DirectionalLight(-3,-6,-3);
getCurrentScene().addLight(mLight);

Material toon = new Material();
toon.setDiffuseMethod(new DiffuseMethod.Toon());
toon.enableLighting(true);
toon.setColorInfluence(0);

mCube.setMaterial(toon);
Clone this wiki locally