normal maping for object with two texture.

Started by kupiecu, November 20, 2013, 01:11:54 AM

Previous topic - Next topic

kupiecu

I have a class. This create the box with two textures. One of the textures is for "front" and other is for "back". Function reTexture repeat the texture. It's work great:

Now, i want add normal mapping to the texture, and i want "3d effect" of brick. I try make this very long time but the result is nothing.
my code :

public class Prostokat {

public Object3D createBox(final float width, final float depth,
final float height) {
final Object3D box = new Object3D(10);
final Object3D box1 = new Object3D(2);
Object3D box_suma;
final float x = width / 2;
final float y = depth / 2;
final float z = height / 2;

final int textureFactor = 512; //

final SimpleVector upperLeftFront = new SimpleVector(-x, -y, -z);
final SimpleVector upperRightFront = new SimpleVector(x, -y, -z);
final SimpleVector lowerLeftFront = new SimpleVector(-x, y, -z);
final SimpleVector lowerRightFront = new SimpleVector(x, y, -z);

final SimpleVector upperLeftBack = new SimpleVector(-x, -y, z);
final SimpleVector upperRightBack = new SimpleVector(x, -y, z);
final SimpleVector lowerLeftBack = new SimpleVector(-x, y, z);
final SimpleVector lowerRightBack = new SimpleVector(x, y, z);

int texIDw = TextureManager.getInstance().getTextureID("TexScianaW");
int texIDz = TextureManager.getInstance().getTextureID("TexScianaZ");
// front
box1.addTriangle(lowerLeftFront, x / textureFactor, 0, lowerRightFront,
0, 0, upperLeftFront, x / textureFactor, y / textureFactor); //zeby dobrze zorientowac normalne do mapowania tekstury musze o dobry kąt obrĂ³cić normalne , dlatego dziele przez texturefactor/ chyba ;/
box1.addTriangle(lowerRightFront, 0, 0, upperRightFront, 0, y
/ textureFactor, upperLeftFront, x / textureFactor, y
/ textureFactor);
box1.calcTextureWrapSpherical();
box1.build();
reTexture(box1, "TexScianaZ", 2f);

// back
box.addTriangle(upperLeftBack, x / textureFactor, 0, upperRightBack, 0,
0, lowerLeftBack, x / textureFactor, z / textureFactor,
texIDw);
box.addTriangle(upperRightBack, 0, 0, lowerRightBack, 0, z
/ textureFactor, lowerLeftBack, x / textureFactor, z
/ textureFactor, texIDw);

// upper
box.addTriangle(upperLeftFront, x / textureFactor, z / textureFactor,
upperRightBack, 0, 0, upperLeftBack, x / textureFactor, 0,
texIDz);
box.addTriangle(upperLeftFront, x / textureFactor, z / textureFactor,
upperRightFront, 0, z / textureFactor, upperRightBack, 0, 0,
texIDz);

// lower
box.addTriangle(lowerLeftBack, x / textureFactor, 0, lowerRightBack, 0,
0, lowerLeftFront, x / textureFactor, z / textureFactor,
texIDz);
box.addTriangle(lowerRightBack, 0, 0, lowerRightFront, 0, z
/ textureFactor, lowerLeftFront, x / textureFactor, z
/ textureFactor, texIDz);

// Left
box.addTriangle(lowerRightBack, y / textureFactor, 0, upperRightBack,
0, 0, lowerRightFront, y / textureFactor, z / textureFactor,
texIDz);
box.addTriangle(upperRightBack, 0, 0, upperRightFront, 0, z
/ textureFactor, lowerRightFront, y / textureFactor, z
/ textureFactor, texIDz);

// Right
box.addTriangle(upperLeftBack, y / textureFactor, 0, lowerLeftBack, 0,
0, upperLeftFront, y / textureFactor, z / textureFactor,
texIDz);
box.addTriangle(lowerLeftBack, 0, 0, lowerLeftFront, 0, z
/ textureFactor, upperLeftFront, y / textureFactor, z
/ textureFactor, texIDz);
box.calcTextureWrapSpherical();
box.build();
box_suma = Object3D.mergeObjects(box, box1);
box_suma.build();
return box_suma;
}
private void reTexture(Object3D obj, String t2, float tileFactor) {
Logger.log("ReTexturing...", Logger.MESSAGE);
PolygonManager pm=obj.getPolygonManager();
int t2Id=TextureManager.getInstance().getTextureID(t2);
int end=pm.getMaxPolygonID();
for (int i=0; i<end; i++) {
int t1=pm.getPolygonTexture(i);
SimpleVector uv0=pm.getTextureUV(i, 0);
SimpleVector uv1=pm.getTextureUV(i, 1);
SimpleVector uv2=pm.getTextureUV(i, 2);
TextureInfo ti=new TextureInfo(t1, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);

uv0.scalarMul(tileFactor);
uv1.scalarMul(tileFactor);
uv2.scalarMul(tileFactor);

ti.add(t2Id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y, TextureInfo.MODE_MODULATE);
pm.setPolygonTexture(i, ti);
}
Logger.log("ReTexturing...done!", Logger.MESSAGE);
}
}


I try connect this class with modyfied example "HelloShrader" but i can't.

Please help :)


EgonOlsen

I fail to see a relation between your code snippet and normal mapping. The HelloShader-example uses three textures. One base texture, a normal map and a height map. For proper normal (in this case parallax) mapping you either have to have this set of textures or you have to create the latter out of the former by using some tool that does this. I was using some command line tool for this, but i can't remember the name ATM. Armed with that, all you have to do is actually to replace the plane from the example with your own model.