www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on June 05, 2013, 07:42:13 pm

Title: How to Add A Second Texture as Environment Map
Post by: AGP on June 05, 2013, 07:42:13 pm
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):

Code: [Select]
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);
Title: Re: How to Add A Second Texture as Environment Map
Post by: EgonOlsen on June 05, 2013, 10:33:42 pm
And without the second texture, it's looking fine? And with the second one, you are seeing only the second?
Title: Re: How to Add A Second Texture as Environment Map
Post by: AGP on June 05, 2013, 10:49:20 pm
Do you mean, if I just setTexture("ironman_tex") instead of using TextureInfo? That still works.
Title: Re: How to Add A Second Texture as Environment Map
Post by: EgonOlsen on June 05, 2013, 10:55:53 pm
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 (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:

Code: [Select]
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...
Title: Re: How to Add A Second Texture as Environment Map
Post by: AGP on June 05, 2013, 11:19:40 pm
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).
Title: Re: How to Add A Second Texture as Environment Map
Post by: EgonOlsen on June 05, 2013, 11:33:43 pm
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.
Title: Re: How to Add A Second Texture as Environment Map
Post by: AGP on June 05, 2013, 11:37:45 pm
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.
Title: Re: How to Add A Second Texture as Environment Map
Post by: AGP on June 06, 2013, 12:00:05 am
It worked now. I was just being a complete idiot. Thanks.
Title: Re: How to Add A Second Texture as Environment Map
Post by: EgonOlsen on June 06, 2013, 01:07:40 pm
No problem. At least it helped to discover the mentioned bug.