light and material effects for newie

Started by julycamara, August 26, 2012, 04:33:47 PM

Previous topic - Next topic

julycamara

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.

EgonOlsen


  • 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.

julycamara

hello,

I'm usign jPCT-AE for Android project.

EgonOlsen

Have you already tried to add a light source to the scene?

julycamara

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.

EgonOlsen

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.

julycamara

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.


EgonOlsen

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.

EgonOlsen

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.

julycamara

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.

julycamara

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.

EgonOlsen

As said above: Don't disabled culling on these objects or the idea won't work. Remove your calls to setCulling.

julycamara

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.

EgonOlsen

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.