Author Topic: Transparency - How does it work?!  (Read 2295 times)

Offline nerdinand

  • byte
  • *
  • Posts: 3
    • View Profile
Transparency - How does it work?!
« on: July 04, 2014, 10:58:14 am »
Hello

I'm using JPCT-AE for something serious. ;)
It is a medical application where a user can select a pain point on a 3D model of the body. Right now I implemented this pain point using a Sphere primitive without texture and set the additional color to color it. Now I'd like to make it pulsate by making it more and less transparent over time. How would I implement this? I know there is a setTransparency() method, but this only accepts integers (IMO the JavaDoc could be improved here to explain some more what range of values it accepts and what they mean). When I set the transparency to -1, the object is fully opaque and setting it to 1 seems to make it fully transparent. How can I vary the transparency in order to achieve the desired effect?

Thanks for this easy to use lib and your help!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency - How does it work?!
« Reply #1 on: July 04, 2014, 12:36:18 pm »
I agree that the documentation isn't sufficient here. I actually thought that it mentions the formula, but obviously it doesn't. But you find it here: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#glTransparencyOffset. The calculated value ranges from [0..1].
The reason that the method doesn't take these values directly but uses the formula to calculate them based on some integer is historical. jPCT for desktop was a software renderer only in the beginning that handled (and still does...) transparency in a different way. Using ints was perfectly valid for this. With additional hardware support, this changed but i wanted them to behave similar, so i invented this formula. jPCT-AE is based on the desktop version and should be as compatible as possible, so it inherits this behaviour too.

Offline nerdinand

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Transparency - How does it work?!
« Reply #2 on: July 04, 2014, 01:50:16 pm »
I see, so the way to go here is to modify Config.glTransparencyMul then? Could I for example modify it through a sine wave with each frame rendered?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Transparency - How does it work?!
« Reply #3 on: July 04, 2014, 03:41:41 pm »
No, that's not how it's meant to be used. I suggest to set the offset to 0 and the mul to maybe 0.0039. Then use values between 0 and 255 for setTransparency(<int>) to go from fully transparent to fully opaque.

Offline nerdinand

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Transparency - How does it work?!
« Reply #4 on: July 04, 2014, 04:26:34 pm »
Ah I see. Thanks. Although, I already Implemented it the other way now, and it works. But maybe I'll refactor it at some point.