How to Add A Second Texture as Environment Map

Started by AGP, June 05, 2013, 07:42:13 PM

Previous topic - Next topic

AGP

How do you go about assigning a second texture like that? I'm using the fps demo's envmap.jpg as the environment map. The following doesn't work (I see the actual texture but no shine):


TextureManager tm = TextureManager.getInstance();
tm.addTexture("EnvironmentMap", new Texture("envmap.jpg"));
tm.addTexture("Red", new Texture("Red.png"));
TextureInfo tis=new TextureInfo(tm.getTextureID("EnvironmentMap"));
tis.add(tm.getTextureID("ironman_tex.png"), TextureInfo.MODE_ADD); // Or another mode...
model.get(0).setEnvmapped(Object3D.ENVMAP_ENABLED);
model.get(0).setEnvmapMode(Object3D.ENVMAP_WORLDSPACE);
model.get(0).setTexture(tis);

EgonOlsen

And without the second texture, it's looking fine? And with the second one, you are seeing only the second?

AGP

Do you mean, if I just setTexture("ironman_tex") instead of using TextureInfo? That still works.

EgonOlsen

I made myself a little test case...there's a problem when doing this on compiled objects, which causes the environment map to be switched to the second stage even if Config.glForceEnvMapToSecondStage is false. I've uploaded a fixed version here: http://jpct.de/download/beta/jpct.jar...but i'm not sure if this relates to your problem. Anyway, here's my test case. Maybe that helps too:


import com.threed.jpct.*;

/**
* A simple HelloWorld using the OpenGL-renderer.
*
* @author EgonOlsen
*
*/
public class HelloWorldOGL {

private World world;

private FrameBuffer buffer;

private Object3D box;

public static void main(String[] args) throws Exception {
new HelloWorldOGL().loop();
}

public HelloWorldOGL() throws Exception {

//Config.glForceEnvMapToSecondStage=true;

world = new World();
world.setAmbientLight(255, 255, 255);

TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));
TextureManager.getInstance().addTexture("something", new Texture("test.jpg"));

TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("box"));
ti.add(TextureManager.getInstance().getTextureID("something"), TextureInfo.MODE_MODULATE);

box = Primitives.getBox(13f, 2f);
box.calcTextureWrapSpherical();
box.setTexture(ti);
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
box.compile();
world.addObject(box);

world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
}

private void loop() throws Exception {

buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

// buffer.resize(360, 600);

while (!org.lwjgl.opengl.Display.isCloseRequested()) {

box.rotateY(0.01f);
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();

Thread.sleep(10);
}
System.exit(0);
}
}



However, what you can't do is to have both texture as an environment map, if that's what you have in mind...

AGP

The new jar doesn't help (and MODE_MODULATE makes my model fully black while MODE_ADD textures it right but with no shine whatsoever).

EgonOlsen

Have you tried the test case with some textures of yours? It works fine yor me. Either you are doing something different, your textures don't fit or our expectations of the actual outcome are different.

AGP

Regardless of my expectations, the end result is exactly the same as doing setTexture("ironman_tex"). I'm sure it's supposed to do something better than that. All the sources I've read so far are for objects without texture coordinates. If I do calcTextureWrapSpherical, my main texture won't fit my model.

AGP

It worked now. I was just being a complete idiot. Thanks.

EgonOlsen

No problem. At least it helped to discover the mentioned bug.