www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: qcrist on September 04, 2011, 04:06:07 am

Title: Strange Lighting
Post by: qcrist on September 04, 2011, 04:06:07 am
[I'm good with titles :D]

:l?

The reason it is wierd, is because the light is in the center of the room. :o

(http://img220.imageshack.us/img220/9383/85277298.png)

Code: [Select]
world.addLight(new SimpleVector(0,-50,0),Color.WHITE);
Config.fadeoutLight=false;
world.setAmbientLight(10,10,10);
Title: Re: Strange Lighting
Post by: EgonOlsen on September 04, 2011, 07:46:52 pm
Try to set discard distance and attenuation in World (or by using the Light-class in util, which i suggest...) both to -1 and let me know, if this changes something.
Title: Re: Strange Lighting
Post by: qcrist on September 05, 2011, 03:59:05 am
changing the discard distance and attenuation didn't seem to change much.

I did notice small changes of the model changed it tho.

The model is made with Google Sketchup pro.

3ds:
http://www.mediafire.com/?llyqu6g34pwfksa (http://www.mediafire.com/?llyqu6g34pwfksa)

skp:
http://www.mediafire.com/?3p3fgv491oaewuv (http://www.mediafire.com/?3p3fgv491oaewuv)
Title: Re: Strange Lighting
Post by: EgonOlsen on September 05, 2011, 08:22:50 pm
Maybe you are lighting the backfaces, i.e. the light source is below the ground? I've written a little test case. It shows how lighting affects your model for different light source positions. Maybe it helps:

Code: [Select]
import java.awt.Color;

import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.Light;

public class HelloRoom {

private World world;

private FrameBuffer buffer;

private Object3D box;
private Object3D bulb;

private Light light;

public static void main(String[] args) throws Exception {
Config.glUseVBO = true;

new HelloRoom().loop();
}

public HelloRoom() throws Exception {
world = new World();
world.setAmbientLight(10, 10, 10);
light = new Light(world);
light.setPosition(new SimpleVector(0f, -50f, 0f));
light.setIntensity(255, 255, 255);

bulb=Primitives.getEllipsoid(2, 1);
world.addObject(bulb);
bulb.setAdditionalColor(Color.WHITE);
bulb.compile();

TextureManager.getInstance().addTexture("Material.jpg", new Texture("textures/stones.jpg"));

box = Object3D.mergeAll(Loader.load3DS("mesh/map.3ds", 0.05f));
box.rotateX((float) -Math.PI / 2f);
box.compile();
box.build();
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);

SimpleVector lPos = new SimpleVector(0, -50, 0);
float add = -0.25f;

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

lPos.y += add;

light.setPosition(lPos);
bulb.clearTranslation();
bulb.translate(lPos);

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

if (add < 0) {
if (lPos.y <= -50f) {
add = 0.25f;
}
} else {
if (lPos.y >= 50f) {
add = -0.25f;
}
}
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
System.exit(0);
}
}