Author Topic: transparency - wrong color  (Read 2594 times)

Offline tjm

  • byte
  • *
  • Posts: 17
    • View Profile
transparency - wrong color
« on: March 25, 2010, 07:38:50 pm »
Unfortunately for me, my hardware doesn't support shadows, so I'm trying to implement pseudo-shadows. It's going OK, but the transparency has got my a bit stumped. My texture is an all black JPG (made in Photoshop) with the opacity set to 50%

When the pseudo shadow is rendered, it's white, not black. This is probably something to do with Lights, but I can't figure it out. Any help appreciated!!

A screen grab and code are below. BTW, the program itself is basically a hacked up version of HelloWorld from the Wiki, with the World ambient light is 255,255,255, the code below is almost 100% taken from a forum post (sorry, can't remember who posted it).

--Tim.




Code: [Select]
private Object3D makePseudoShadow(float transZ) {
Object3D obj = new Object3D( 2 );
        float offset = 50;  // width / height of the billboard (assumes it is square)
        obj.addTriangle( new SimpleVector( -offset, -offset, 0 ),
                           0, 0,
                           new SimpleVector( -offset, offset, 0 ), 0, 1,
                           new SimpleVector( offset, offset, 0 ), 1, 1,
                           TextureManager.getInstance().getTextureID(
                                                             "shadow" ) );
        obj.addTriangle( new SimpleVector( offset, offset, 0 ),
                           1, 1,
                           new SimpleVector( offset, -offset, 0 ), 1, 0,
                           new SimpleVector( -offset, -offset, 0 ), 0, 0,
                           TextureManager.getInstance().getTextureID(
                                                             "shadow" ) );

obj.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
obj.setTransparency(100);
obj.setLighting(Object3D.LIGHTING_NO_LIGHTS);
obj.setAdditionalColor(java.awt.Color.BLACK);

        obj.build();

obj.rotateX(-80);
obj.translate(0,0,transZ);

return(obj);
}

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: transparency - wrong color
« Reply #1 on: March 25, 2010, 08:47:02 pm »
I would guess that drawing a simi-transparent object using TRANSPERENCY_MODE_ADD is part of the problem.  What that transparency mode does is it adds the RGB values of both images together, which is always going to be brighter that either image by itself (which is great for lighted effects but not so great for shadows).

Another issue is that you should use an image format other than JPG.  As far as I know, JPG does not support transparency.  I would use PNG format instead.  Then you can play around with the transparency in both your image editing tool and also with the settings in JPCT to get it to look the way you want it to.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: transparency - wrong color
« Reply #2 on: March 25, 2010, 09:45:15 pm »
Using png for this is the better choice indeed, because you have to load the texture with alpha or otherwise, jPCT will make all your black parts transparent...which isn't what you want. Using ADD on a black texture won't work either...something+0 is still something.

About the color itself...looks to me as if this is the dummy texture, which is all white. Maybe loading your texture has failed!?

Offline tjm

  • byte
  • *
  • Posts: 17
    • View Profile
Re: transparency - wrong color
« Reply #3 on: March 25, 2010, 10:35:02 pm »
Thanks Paul and Egon .... fixed it ;D

Using a PNG and removing the TRANSPARENCY_MODE_ADD did the trick. The result is a bit ugly, but I'm prototyping core interactions and it will do nicely.

BTW, the code (above) is from one of Paul's posts. Thanks ... it would have taken me ages to figure out how to put a simple square into a world.

Here's the obligatory screen shot. Not so great, but shows it worked:



--Tim.