Author Topic: light and material effects for newie  (Read 2883 times)

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
light and material effects for newie
« on: August 26, 2012, 04:33:47 pm »
Hello,

First of all, thanks a lot for this great engine, i have working with it for some days.

On my little example i'm trying to show an Object3D (sphere in this case) and practice various effects, and unfortunately i can't do very much. Please, could somebody teach me how to make the following effects? or unless link to gl tutorial or something?

- partial transparency, ┐how it is possible to see the other side of the object? when i apply transparency i see the background but not the other side of my object3d.

- light or material effect. i'm trying to make an pullid and brightness effect to my sphere, like a billiard ball.

thank you in advance.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #1 on: August 27, 2012, 01:06:27 pm »
  • That's because of the backface culling that will be applied by default. You can change this behaviour by doing Object3D.setCulling(false);. However, because transparent objects have to be sorted to be rendered in the correct order, it highly depends on the object if the result will be visually pleasing of not.
  • This depends a little bit on the version of jPCT. Are you using the desktop version or jPCT-AE? I'm asking because a lot of questions related to the Android version pop up in this forum, so i just wanted to be sure before answering.

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
Re: light and material effects for newie
« Reply #2 on: August 27, 2012, 05:46:14 pm »
hello,

I'm usign jPCT-AE for Android project.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #3 on: August 27, 2012, 09:40:26 pm »
Have you already tried to add a light source to the scene?

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
Re: light and material effects for newie
« Reply #4 on: August 31, 2012, 07:12:08 pm »
yes i have added some light over the object but his appeareance is always like "matt finish" i want something like this http://www.pmpocketbilliards.com/pocketbilliardimages/9-Ball.jpg material effect. If it is possible of course.

Thank you again.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #5 on: August 31, 2012, 08:42:21 pm »
It is possible when using OpenGL ES 2.0 and a custom shader. If that's too mush hassle, you can try to use specular lighting to improve things a little (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setSpecularLighting(boolean), http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#specPow, http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#specTerm), but i'm not sure if that will cut it.

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
Re: light and material effects for newie
« Reply #6 on: September 09, 2012, 08:31:28 pm »
hello, i'm here again with new problems.

ok, i try with Object3D.setCulling(false); And the object looks like i want, the black transparent color of the png texture disappear and i can see the back side of the object.

But when y rotate the object on scene it looks bad, sometimes draw the back side over the front sides and his behaviour is not perfect. Please let me show some images for explain it:

http://www.tiikoni.com/tis/view/?id=f590cbf this is the good draw of a transparent object.

When i try to rotate this, then we can see something like that... http://www.tiikoni.com/tis/view/?id=6600893

And then we can see how the back side is drawing over the front side: http://www.tiikoni.com/tis/view/?id=0f1d8a5

I hope it could be solutions. Any ideas? thank you.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #7 on: September 09, 2012, 11:16:53 pm »
That's because the order in which the polygons will rendered depends on the order in which they are defined. For transparent objects, this matter and it might look wrong from certain angles. There's no way to fix this except by splitting the objects into smaller parts, if possible into transparent and opaque parts. Not sure if this helps in this case because i can't access the images ATM because my bandwidth here is very very low.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #8 on: September 11, 2012, 09:11:53 pm »
Another idea that is worth a try: Clone the object, make it a child of the actual object and invert it. Then add some sort offset, so that the inverted clone will always be painted before the actual object. Enable transparency on both and see if it helps. Don't disable calling on any of the objects in this case.

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
Re: light and material effects for newie
« Reply #9 on: September 17, 2012, 08:34:28 am »
hello,

I try this,

....

               clone = cube.cloneObject();

               cube.setTransparency(50);
               cube.setCulling(false);
               cube.setTexture("texture");
               //cube.strip();
               cube.build();
               
               cube.addChild(clone);
               clone.invert();
               clone.setTransparency(50);
               clone.setCulling(false);
               clone.setTexture("texture");
               clone.setSortOffset(-100000);
               //clone.strip();
               clone.build();
               
               world.addObject(clone);
               world.addObject(cube);

...

But it isn't works for me.

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
Re: light and material effects for newie
« Reply #10 on: September 17, 2012, 08:51:30 am »
i try too setSortOffset positive to draw first cloned object. And i could see it first but the result isn't good. Object3D.invert() make an strange effect over the texture (a .png picture) and it is drawed very bad (little triangles chunks of original texture on bad uv coords) and not solved my problem.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #11 on: September 17, 2012, 03:30:34 pm »
As said above: Don't disabled culling on these objects or the idea won't work. Remove your calls to setCulling.

Offline julycamara

  • byte
  • *
  • Posts: 10
    • View Profile
Re: light and material effects for newie
« Reply #12 on: September 17, 2012, 04:24:45 pm »
But if i don't disable culling i have not any problem with transparency.

The problem occurs when thre is an object with transparency and setCulling(false) to see the backside and the object is rotated. I will post a simple example code with image to illustrate it.

Thank you.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: light and material effects for newie
« Reply #13 on: September 17, 2012, 09:19:17 pm »
Yes, i know that this is the problem. And this idea might help to get rid of it, but if you still disable culling, it can't do any good. The actual idea is to combine the front faces of the first with the back faces of the second object. In your code, both objects will be painted one over the other.