Skip to content
Dennis Ippel edited this page Aug 21, 2013 · 15 revisions

(Anchor Steam) Materials

(Just dumping information here at the moment, this will be more coherent)

Creating a color material without using lighting

Material material = new Material();
material.setColor(Color.RED);
// or
material.setColor(0xffff0000); 

Creating a color material with diffuse lighting

Material material = new Material();
material.setColor(Color.RED);
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());

Creating a color material with diffuse lighting and specular highlights

Material material = new Material();
material.setColor(Color.RED);
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.setSpecularMethod(new SpecularMethod.Phong());

Using a diffuse texture

Material material = new Material();
// -- The first parameter is compulsory and needs to be unique and
//    has the same restrictions as any Java variable.
material.addTexture(new Texture("earth", R.drawable.earth_diffuse));

Mixing diffuse texture with color

Material material = new Material();
material.addTexture(new Texture("earth", R.drawable.earth_diffuse));
material.setColor(Color.RED);
// -- Use 50% red
material.setColorInfluence(.5f);
Texture texture = new Texture("earth", R.drawable.earth_diffuse);
// -- Use 50% of the texture
texture.setInfluence(.5f);
material.addTexture(texture);

Using a diffuse texture with diffuse lighting and specular highlights

Material material = new Material();
material.addTexture(new Texture("earth", R.drawable.earth_diffuse));
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.setSpecularMethod(new SpecularMethod.Phong());

Mixing two diffuse textures

Material material = new Material();
Texture texture1 = new Texture("earth", R.drawable.earth_diffuse);
// -- Use 50% of this texure
texture1.setInfluence(.5f);
material.addTexture(texture1);
Texture texture2 = new Texture("clouds", R.drawable.earth_clouds);
// -- Use 50% of this texture
texture2.setInfluence(.5f);
material.addTexture(texture2);

Using a normal map

Material material = new Material();
material.addTexture(new Texture("earth", R.drawable.earth_diffuse));
material.addTexture(new NormalMapTexture("earthNormal", R.drawable.earth_normal));
// -- Note that you can also set the normal map's strength through the setInfluence(float) setter
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.setSpecularMethod(new SpecularMethod.Phong(0xeeeeee, 200));

Repeating textures

Material material = new Material();
Texture texture = new Texture("earth", R.drawable.earth_diffuse);
texture.setWrapType(WrapType.REPEAT);
// -- Repeat 10 times in the U/X direction and 5 times in the V/Y direction
texture.setRepeat(10, 5);
material.addTexture(texture);

Texture offset

Material material = new Material();
Texture texture = new Texture("earth", R.drawable.earth_diffuse);
// -- This has to be set explicitly because of shader optimization considerations
texture.enableOffset(true);
// -- Set the offsets in the U/X directions and V/Y directions. These are normalized coordinates so
//    they represent a 10% shift in the U/X direction and a 30% shift in the V/Y direction.
texture.setOffset(.1f, .3f);
// -- Note that the offset can be animated by changing the values on each frame in the onDrawFrame()
//    method in your renderer class.

Environment Cube Map

Material material = new Material();
int[] cubemaps = new int[6];
cubemaps[0] = R.drawable.posx;
cubemaps[1] = R.drawable.negx;
cubemaps[2] = R.drawable.posy;
cubemaps[3] = R.drawable.negy;
cubemaps[4] = R.drawable.posz;
cubemaps[5] = R.drawable.negz;
CubeMapTexture texture = new CubeMapTexture("cubemaps", cubemaps);
material.addTexture(texture);

Environment Sphere Map

Material material = new Material();
SphereMapTexture texture = new SphereMapTexture("sphereMap", R.drawable.sphere_map);
material.addTexture(texture);

Environment Sphere Map Combined With Color and a Diffuse Texture

Material material = new Material();
material.setUseColor(Color.ORANGE);
// -- use 30% plain orange color
material.setColorInfluence(.3f);

SphereMapTexture sphereMapTexture = new SphereMapTexture("sphereMap", R.drawable.sphere_map);
// -- use 30% of the environment sphere map
sphereMapTexture.setInfluence(.3f);
material.addTexture(sphereMapTexture);

Texture texture = new Texture("myTexture", R.drawable.my_texture);
// -- use 40% of the diffuse texture
texture.setInfluence(.4f);
material.addTexture(texture);

Diffuse Texture & Specular Map

Material material = new Material();
// -- add a diffuse texture
material.addTexture(new Texture("earth", R.drawable.earth_diffuse));
// -- add a specular map
material.addTexture(new SpecularMapTexture("earthSpec", R.drawable.earth_specular));

Diffuse Texture, Specular Map & Normal Map

Material material = new Material();
// -- add a diffuse texture
material.addTexture(new Texture("earthDiff", R.drawable.earth_diffuse));
// -- add a specular map
material.addTexture(new SpecularMapTexture("earthSpec", R.drawable.earth_specular));
// -- add a normal map
material.addTexture(new NormalMapTexture("earthNorm", R.drawable.earth_normal));

Diffuse Texture & Alpha Map

Material material = new Material();
Texture texture = new Texture("earth", R.drawable.earth_diffuse);
material.addTexture(texture);

AlphaMapTexture alphaMap = new AlphaMapTexture("alphaMap", R.drawable.camden_town_alpha);
material.addTexture(alphaMap);
Clone this wiki locally