www.jpct.net

General => News => Topic started by: EgonOlsen on July 16, 2007, 10:15:10 pm

Title: Beta of 1.15 released!
Post by: EgonOlsen on July 16, 2007, 10:15:10 pm
Due to the significant changes that come with this version, i decided to add a beta-phase before actually releasing it. Grab it here: http://www.jpct.net/download/beta/jpctapi.zip (http://www.jpct.net/download/beta/jpctapi.zip).

Changes:

Added a possibility to the TextureManager to get the name for an ID. Fixed a bug when using environment mapping on multi-pass objects. Fixed a flaw in the discrete polygon and triangle strip rendering. Fixed a bug in Object3D.clone() that prevented a transparency setting from being cloned. Simplified the visibility list management.
Modified the behaviour of FrameBuffer.update() to make applications work that omit the call to one of the display()-methods. Fixed a bug in the getPosition()-methods for light sources. Fixed a bug in projective texturing that caused a wrong fov-value to be set. Added the possibility to Camera to explicitly set the y-fov.
Added shadow mapping using a fixed function pipeline approach with depth textures. A new class in util called ShadowHelper eases shadow mapping. Added some helper methods here and there to ease shadow mapping. Added a method to Texture to add another texture's content to one. Added a new constructor to texture to create a blank x*y texture.


And an example of how to use shadow mapping (showing a simple scene with a cube casting a shadow):
(http://www.jpct.net/pix/smap_example.jpg)

Code: [Select]
import java.awt.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class SimpleShadows {

private FrameBuffer fb = null;
private World world = null;
private Object3D plane = null;
private Object3D cube = null;
private Object3D sphere = null;
private Projector projector=null;
private ShadowHelper sh = null;
private Light sun=null;

public SimpleShadows() {
Config.glColorDepth = 24;
Config.glFullscreen = false;
Config.farPlane = 1000;
Config.glShadowZBias = 0.8f;
Config.glTrilinear=true;
}

private void initStuff() throws Exception {
fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
world = new World();
fb.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);

plane = Primitives.getPlane(20, 30);
plane.rotateX((float) Math.PI / 2f);

cube=Primitives.getCube(15);
cube.setAdditionalColor(Color.RED);
cube.translate(0, -30, -10);

sphere=Primitives.getSphere(12);
sphere.translate(0, 0, -50);
sphere.setAdditionalColor(new Color(0,0,50));

world.addObject(sphere);
world.addObject(plane);
world.addObject(cube);

TextureManager tm = TextureManager.getInstance();

projector = new Projector();
sh = new ShadowHelper(world, fb, projector, 512);
sh.addCaster(cube);
sh.addReceiver(plane);
sh.addReceiver(sphere);
sh.setAmbientLight(new Color(30,30,30));
sh.setFiltering(true);

world.setAmbientLight(90,90,90);
world.buildAllObjects();

sun=new Light(world);
sun.setIntensity(50, 50, 50);
}

private void doIt() throws Exception {
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.lookAt(plane.getTransformedCenter());

projector.setFOV(0.5f);
projector.setYFOV(0.5f);

SimpleVector pos=cube.getTransformedCenter();

projector.setPosition(pos);
projector.moveCamera(Camera.CAMERA_MOVEUP, 200);
projector.lookAt(pos);
SimpleVector offset=new SimpleVector(1,0,-1).normalize();
projector.moveCamera(offset, 215);

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

projector.lookAt(cube.getTransformedCenter());
offset.rotateY(0.007f);
projector.setPosition(pos);
projector.moveCamera(new SimpleVector(0,-1,0), 200);
projector.moveCamera(offset, 215);
sun.setPosition(projector.getPosition());

sh.updateShadowMap();

fb.clear();
sh.drawScene();

fb.update();
fb.displayGLOnly();

Thread.sleep(10);
}
fb.disableRenderer(IRenderer.RENDERER_OPENGL);
fb.dispose();
System.exit(0);
}

public static void main(String[] args) throws Exception {
SimpleShadows cd = new SimpleShadows();
cd.initStuff();
cd.doIt();
}
}

Edit: Here's a little PDF from NVidia dealing with the theory behind shadow mapping for you to get a feeling for possibilities and limitations. The implementation in jPCT may not be exactly like the one described in the PDF, but the theory applies: http://developer.nvidia.com/attach/8456 (http://developer.nvidia.com/attach/8456)
Title: Re: Beta of 1.15 released!
Post by: cyberkilla on July 17, 2007, 01:02:26 am
Wow! I really can't believe how much work you've done on this.
Title: Re: Beta of 1.15 released!
Post by: raft on July 17, 2007, 03:58:12 am
great work Egon, congratulations ;)
Title: Re: Beta of 1.15 released!
Post by: hytparadisee on July 19, 2007, 05:10:41 am
Thanks in advance, though I can't help much. (My damn shitty intel chip :'()
Title: Re: Beta of 1.15 released!
Post by: rolz on July 24, 2007, 12:39:12 am
Egon,
Great work. I'll give it a try.

2 Hytparadisee: man, works perfectly on my work laptop's shitty Intel 945GM
Title: Re: Beta of 1.15 released!
Post by: Melssj5 on July 24, 2007, 02:04:30 am
Long time Rolz! hOW IS TECHNOPOLIS?
Title: Re: Beta of 1.15 released!
Post by: manumoi on July 24, 2007, 06:55:22 am
Congratulation for the shadow texturing Egon... that s definetely a huge improvement (and huge work i suspect).

Also happy to see that Rolz is still in the field.
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 04:45:11 pm
2 Hytparadisee: man, works perfectly on my work laptop's shitty Intel 945GM
It does? Amazing! I've never expected it to work on Intel.
Title: Re: Beta of 1.15 released!
Post by: Melssj5 on July 24, 2007, 05:30:14 pm
2 Hytparadisee: man, works perfectly on my work laptop's shitty Intel 945GM
It does? Amazing! I've never expected it to work on Intel.

why not? I have had very good results on intel based chipsets!
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 05:38:52 pm
why not? I have had very good results on intel based chipsets!
Because my machine@work has on onboard intel chipset not almost nothing works on it. But this may be related to the drivers...they are very old and i'm not allowed to update them.... :-[
Title: Re: Beta of 1.15 released!
Post by: raft on July 24, 2007, 05:43:27 pm
it does work on my Intel 915GM too. but the shadows at borders arent that sharp as the image above . i've played with Config.glShadowZBias but didnt help much
Title: Re: Beta of 1.15 released!
Post by: hytparadisee on July 24, 2007, 05:56:52 pm
Awwww, no wonder mine can't work ----> Intel 852 :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 06:05:41 pm
it does work on my Intel 915GM too. but the shadows at borders arent that sharp as the image above . i've played with Config.glShadowZBias but didnt help much
Do you have a screenshot of this?
Title: Re: Beta of 1.15 released!
Post by: raft on July 24, 2007, 06:23:15 pm
default glShadowZBias
(http://img232.imageshack.us/img232/5415/defaulttu7.png)

glShadowZBias = 2
(http://img232.imageshack.us/img232/5654/60507429sl9.png)
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 06:35:34 pm
Looks like an issue with filtering. You can disable it by removing the call to <ShadowHelper>.setFiltering();...or set it to false explicitly just to be sure. Does that change anything?
Title: Re: Beta of 1.15 released!
Post by: raft on July 24, 2007, 06:46:43 pm
nope, didnt help with both default glShadowZBias and 2 :/
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 07:04:31 pm
But the edges have to look different then, don't they?
Title: Re: Beta of 1.15 released!
Post by: raft on July 24, 2007, 07:25:08 pm
nope, i see no difference :/ here a shot with filtering off and glShadowZBias = 2
(http://img120.imageshack.us/img120/7991/nofilter2xo9.png)
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 07:30:49 pm
Strange! The chip or the driver doesn't seem to care about the filtering setting and filters everything...not much i can do about this issue ATM.
Title: Re: Beta of 1.15 released!
Post by: raft on July 24, 2007, 07:43:26 pm
this is a fedora 4 btw. the default distribution didnt recognize my chipset so i downloaded and compiled a recent X. maybe relevant who knows ?
Title: Re: Beta of 1.15 released!
Post by: rolz on July 24, 2007, 10:27:20 pm
Egon,

Setting Config.glShadowZBias to 12 did not work on my card too. Looks like the problem with Intel 915GM.

BTW, i've played with this feature to create light projecting effect and noticed black border around the projected shape.
Is there a way to remove it ?

(http://img409.imageshack.us/img409/3559/sceneio6.jpg)


p.s. jpeg quality sucks. It looks better without compression.
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 10:41:27 pm
The black border is caused by the filtering...that can be disabled but can't on Intel 915G!? But for projecting a lightsource like in the "window blinds"-movie, simply using projective textures should be the better choice anyway.

BTW: 12 is very high value for the bias. It's very likely that no shadow at all will be visible with that.
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 10:42:24 pm
this is a fedora 4 btw. the default distribution didnt recognize my chipset so i downloaded and compiled a recent X. maybe relevant who knows ?
Can you please run this test case and post a screen shot of how it looks on your machine:

Code: [Select]
import com.threed.jpct.*;

public class FilterTest {

public static void main(String[] args) throws Exception {
Texture tex1=new Texture(16,16);
Texture tex2=new Texture(16,16);
TextureManager tm=TextureManager.getInstance();
FrameBuffer fb=new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
World world=new World();
fb.enableRenderer(IRenderer.RENDERER_OPENGL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
tm.addTexture("checkers1", tex1);
tm.addTexture("checkers2", tex2);
tex1.setEffect(new Maker());
tex1.applyEffect();
tex2.setEffect(new Maker());
tex2.applyEffect();
tex1.removeEffect();
tex2.removeEffect();
Object3D plane1=Primitives.getPlane(1, 12);
Object3D plane2=Primitives.getPlane(1, 12);
plane1.setTexture("checkers1");
plane2.setTexture("checkers2");
world.addObject(plane1);
world.addObject(plane2);
plane1.translate(-6, 0, 0);
plane2.translate(6, 0, 0);
world.buildAllObjects();
world.setAmbientLight(255, 255, 255);
Camera cam=world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 20);

tex1.setGLFiltering(false);
tex1.setGLMipmap(false);

while (!org.lwjgl.opengl.Display.isCloseRequested()) {
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.update();
fb.displayGLOnly();
Thread.sleep(100);
}
}

static class Maker implements ITextureEffect {
public void init(Texture tex) {}

public void apply(int[] dest, int[] source) {
for (int x=0; x<8; x++) {
for (int y=0; y<8; y++) {
dest[y*16+x]=0x00ffffff;
dest[(y+8)*16+(x+8)]=0x00ffffff;
}
}
}

public boolean containsAlpha() {
return false;
}
}
}

Title: Re: Beta of 1.15 released!
Post by: raft on July 24, 2007, 10:52:58 pm
here it is. one note, i set Config.glColorDepth to 24 to make it run. same applies to shadow sample
(http://img258.imageshack.us/img258/42/filtertestah9.png)
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 24, 2007, 10:57:55 pm
Looks like it should! So this means that the chip can do pick-nearest-filtering when using normal textures but it doesn't seem to support it on depth textures... ???
About the color depth: Windows always reports 32bpp, Linux always reports 24bpp. I could set it to 24 by default, but the fact that i didn't but documented the behaviour instead means, that i had reason not to. I just can't remember...
Title: Re: Beta of 1.15 released!
Post by: Melssj5 on July 25, 2007, 02:47:53 am
Well, Finally I tested the shadow thing on my old (still working) PC.

Java version is: 1.6.0_01
-> support for BufferedImage
Version helper for 1.2+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Can't find desired videomode (800 x 600 x 24) - searching for alternatives
Current mode:800 x 600 x 32 @75Hz
Driver is: nv4_disp/6.14.10.8198 on NVIDIA Corporation GeForce4 MX 440/AGP/SSE2
OpenGL renderer initialized (using 2 texture stages)
Software renderer disposed
[ Tue Jul 24 19:25:00 GMT-05:00 2007 ] - ERROR: Shadow mapping is not supported by the current hardware!
Exception in thread "main" java.lang.NullPointerException
   at com.threed.jpct.util.ShadowHelper.setFiltering(Unknown Source)
   at SimpleShadows.initStuff(SimpleShadows.java:53)
   at SimpleShadows.main(SimpleShadows.java:105)

I sold my 256MB ATI video card so I just have this GeForce4! and doesnt worked. the simpleShadows line 53 is:

sh.setFiltering(true);
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 25, 2007, 07:57:39 am
The actual problem is this: ERROR: Shadow mapping is not supported by the current hardware!
A real GeForce4 can do it (anything up from a GF3 supports it), but you are using a GeForce4MX, which is basically a GF2. There's nothing i can do about it. The MX doesn't have the hardware caps to do it. The null pointer shouldn't happen anyway in this case. I'll fix this.

Edit: If you want to use this feature, get something from a GF3 upwards, i.e. a GF that supports at least pixel shader 1.1. Don't get an ATI unless it's a real new one, because older ATIs have some problems with depth textures.
Title: Re: Beta of 1.15 released!
Post by: Melssj5 on July 31, 2007, 11:31:56 pm
2 Hytparadisee: man, works perfectly on my work laptop's shitty Intel 945GM
It does? Amazing! I've never expected it to work on Intel.

What about the new intel 3000 or the x3000 chipset! Its supossed to be much better and have good graphics quality!
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on July 31, 2007, 11:58:55 pm
Onboard graphic chips suck performance wise and so does the x3000. However, they constantly improve feature wise, so it may work with correct filtering on those newer Intels, but i don't have the chance to test it. The only Intel graphics chipset that i have access to is that of a 845G with very old drivers. Almost nothing works on this chip (well, Paradroidz worked @ 30fps/800*600...not amazing but playable).
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on August 02, 2007, 12:36:01 am
Updated the beta with a version that includes some additional fixes as well as an option to use FBOs (frame buffer objects) for render-to-texture/shadow mapping where available. It's enabled by default. Maybe it changes behaviour on Intel, albeit i don't think so.
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on August 06, 2007, 11:51:14 pm
And another little update that makes better use of the FBOs to allow shadow maps up to 8192*8192 in size (if hardware supports it...does any? I don't know, but at least 4096*4096 works fine).
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on August 10, 2007, 06:26:56 pm
And another update that fixes a performance problem with recent NVidia drivers.
Title: Re: Beta of 1.15 released!
Post by: Klaudiusz on October 16, 2007, 09:44:09 pm
is this possible to make one object as caster and reciever together? I mean something like self shadows.


Could be very usefull when child object could copy the shadows parameters from the parent.
Title: Re: Beta of 1.15 released!
Post by: EgonOlsen on October 17, 2007, 12:23:46 am
That is already possible, but the results may not satisfy you due to potential accuracy problems. This can be tweaked with http://www.jpct.net/doc/com/threed/jpct/Config.html#glShadowZBias (http://www.jpct.net/doc/com/threed/jpct/Config.html#glShadowZBias), which works fine for some objects but not always. Just play around with it.