Author Topic: Strange Lighting  (Read 1325 times)

Offline qcrist

  • byte
  • *
  • Posts: 29
    • View Profile
Strange Lighting
« 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



Code: [Select]
world.addLight(new SimpleVector(0,-50,0),Color.WHITE);
Config.fadeoutLight=false;
world.setAmbientLight(10,10,10);
« Last Edit: September 04, 2011, 04:08:30 am by qcrist »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12061
    • View Profile
    • http://www.jpct.net
Re: Strange Lighting
« Reply #1 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.

Offline qcrist

  • byte
  • *
  • Posts: 29
    • View Profile
Re: Strange Lighting
« Reply #2 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

skp:
http://www.mediafire.com/?3p3fgv491oaewuv

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12061
    • View Profile
    • http://www.jpct.net
Re: Strange Lighting
« Reply #3 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);
}
}