www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: octav_ro on August 10, 2012, 10:26:10 am

Title: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 10:26:10 am
hi, i am very new to 3d and jpct, can you tell me how do i change the default render order for my scene objects ?
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 11:28:10 am
You can't. It's up to the engine to decide about the render order. That's one major point in using it. Why would you want to?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 11:49:44 am
i have some baked shadows that do not  appear correct when the objects are stacked one over another, this could be solved by rendering the objects above first.
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 12:12:34 pm
Do you have a screen shot of this?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 12:20:30 pm
see attached

[attachment deleted by admin]
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 01:32:27 pm
And that shadow is...what? A plane with an alpha blended shadow texture on it?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 01:34:34 pm
yes is a plane, with transparent texture, i have used

gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

probably im doing smth wrong but because of my limited knowledge i donno where to look.
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 02:04:45 pm
I'm confused now...you are using jPCT-AE for this? Then why are you fiddling around with gl commands directly? You are not supposed to do that and if you want or have to do that, why are you using a 3d engine in the first place?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 02:07:47 pm
i would do it without gl commands if i knew how, anyway the only gl commands i have are these:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      gl.glEnable(GL10.GL_DITHER);
      gl.glEnable(GL10.GL_BLEND);
      gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
      Config.glIgnoreNearPlane = false;
      gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
      gl.glClearColor(m_backColor.getRed(), m_backColor.getGreen(), m_backColor.getBlue(), m_backColor.getAlpha());
      gl.glColorMask(true, true, true, true);
      gl.glDisable(GL10.GL_CULL_FACE);
      gl.glDisable(GL10.GL_DEPTH_TEST);
      gl.glDepthMask(true);
   }

i use jpct to load, place and move objects around, set up the world, lights and camera + all the rendering, the only gl direct stuff is over there.
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 02:14:58 pm
None of these makes any sense in the context of the engine. Scratch off all this gl related code.

Is the drop shadow a single plane with a texture with alpha applied to it? If not, make it one, i.e. separate it from the lamp.
If it is, enable transparency by using <shadowPlane>.setTranspareny(0...) and maybe adjusting transparency mode. You might have to offset it from the ground a little to prevent depth buffer issues.
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 03:12:21 pm
tx for your responses, but removing blending makes things even worse, so if i remove:

//gl.glEnable(GL10.GL_BLEND);
//gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);

i get the stuff attached, the objects create holes inside other object.

the shadow plane is part of the mesh and cant be separated there are hundreds of models like it, so modifying transparency will cause a the whole object to loose transparency so i cant use setTransparency on the whole object.

[attachment deleted by admin]
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 04:11:29 pm
That's because the alpha channel of the texture gets written into the frame buffer, which is normal behaviour...but obviously unwanted in this particular case. Which OpenGL ES version are you using 1.x or 2.0?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 04:18:35 pm
im using 1.x
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 05:14:23 pm
Stupid me...i should gave guessed it from the gl calls...anyway, you have to disable writing into the alpha channel to fix this. This is one of the very seldom occasions where i suggest to call gl directly, but it has to be done in a way that doesn't interfere with the engine's pipeline.

To do this, implement IRenderHook and do

Code: [Select]
gl.glColorMask(true,true,true,false);

in the beforeRendering()-method and

Code: [Select]
gl.glColorMask(true,true,true,true);

in the afterRendering()-method. Then add this hook to the objects that have this problem.
Title: Re: jpct-ae noob question
Post by: octav_ro on August 10, 2012, 06:35:53 pm
adding the hook causes another problem without fixing the previous, if i cant help with more details or more code let me know, im not sure what is wrong here and for sure i can't figure out for myself.

ty very much for your time.

[attachment deleted by admin]
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 10, 2012, 11:01:23 pm
Can you please post the code of your IRenderHook implementation!?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 11, 2012, 07:27:17 am
this is the code, i stripped what was not related

Code: [Select]

public class MyRenderer implements GLSurfaceView.Renderer, IRenderHook
{
              //this method as an object3d to the world
public void addModel()
{

InputStream is = null;
try {
Texture t = new Texture(prod.getTexture(getContext()), true);
man.addTexture(String.valueOf(prod.getId()), t);
is = getModel(getContext(), prod);
Object3D model = Loader.loadSerializedObject(is);
model.setTexture(String.valueOf(prod.getId()));
model.build();
model.setRenderHook(this);
model.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
model.strip();
m_world.addObject(model);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
is.close();
}
}
}



private GL10 m_gl;

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
m_gl = gl;
}



@Override
public void afterRendering(int arg0) {
m_gl.glColorMask(true, true, true, true);

}

@Override
public void beforeRendering(int arg0) {
m_gl.glColorMask(true, true, true, false);

}

@Override
public void onDispose() {
// TODO Auto-generated method stub

}

@Override
public boolean repeatRendering() {
// TODO Auto-generated method stub
return false;
}

@Override
public void setCurrentObject3D(Object3D arg0) {
// TODO Auto-generated method stub

}

@Override
public void setTransparency(float arg0) {
// TODO Auto-generated method stub

}
}


Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 11, 2012, 09:15:15 pm
Looks fine at first glance. I think that my idea doesn't work in the way i expected it too. Not writing the alpha value at all isn't very smart either. Im not sure how to solve this in 1.x...in 2.0, it would be much easier. Is using OpenGL ES 2.0 an option for you?
Title: Re: jpct-ae noob question
Post by: octav_ro on August 12, 2012, 06:29:56 am
i guess i can use open gl 2.0 but what changes i need to do, are you aware of a list with devices that support 2.0?

Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 12, 2012, 08:32:45 pm
2.0 is supported by almost every device except for some really odd or old ones. Everything that runs on Android 2.1 and higher should support it. To enable it, you have to enable it in the Activity (the shader example shows how) and change the constructor of FrameBuffer to the one that doesn't use the gl context. Then, and that's the more complicated part, you have to modify one of the default shaders to write a fixed alpha value. If you send me a test case, i can do these adjustments in it to show you how it works.
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 13, 2012, 08:59:33 pm
...unfortunately, it's not as easy as i thought it would be. If you enable transparency at least on the vase (which your example doesn't do, but your gl-hack does...so your hack is nothing else but a non-allowed version of obj.setTransparency(100);), you have two problems: The alpha value gets written into the framebuffer, which results in the background being blended with it and the sorting of vase and shadow isn't correct, so that the shadow will be rendered in front of the vase in your example.

My idea was to create a shader that writes every pixel as opaque (i.e. alpha = 1.0). That's a neat idea, but it doesn't work because gl's blending process can't be controlled by the shader and happens after the shader's execution. Which means that an alpha of 1.0 results in a black square below the vase. So that's obviously not an option...

Enabling transparency and use the IRenderHook implementation makes the shadow look better as the alpha of the table (=1.0) will be written into the frame buffer and the shadow doesn't change this. But then, the vase also doesn't write it's alpha, which is fine as long the table is behind it. But at the top of the vase, it's before the background and with no alpha written at that point, the background blends over the vase...no option either.

The best solution to all this would be what i mentioned quite early in this thread: Separate the shadow from the vase. That way, the vase and table can be fully opaque and the only transparent object would be the shadow. That combined with the IRenderHook would prevent the shadow from battling with the background, the vase wouldn't blend with the background either and the sorting between vase and shadow would be fine too. Another solution would be to bake the shadow into the table's texture instead of the vase if that's feasible.

As long as you have a none-opaque frame buffer, i don't see any other solution than the two above.

 
Title: Re: jpct-ae noob question
Post by: octav_ro on August 14, 2012, 09:49:04 am
is there any chance the soft shadows can be implemented at runtime, is there any example or code around that can generate soft shadows ?
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 14, 2012, 03:07:07 pm
No. If you feel adventurous, you could implement basic shadow mapping yourself by writing a bunch of advanced shaders, but i wouldn't recommend that. And that wouldn't give you soft shadows, which are an even more complex story. I don't think that this is the way to go here. Isn't seperating the object and the shadow an option? You just have to export them as two different objects in one file. The loader will create individual objects from that when importing them.
Title: Re: jpct-ae noob question
Post by: octav_ro on August 14, 2012, 03:09:32 pm
the problem is that there are hundreds of already made models, anyway will try splitting them and see how it goes.
Title: Re: jpct-ae noob question
Post by: EgonOlsen on August 14, 2012, 03:49:58 pm
If you upload one of them in its normal format (i.e. 3ds or obj), i can have a look to see if i've some idea on how to do this efficiently.
Title: Re: jpct-ae noob question
Post by: octav_ro on August 16, 2012, 12:59:17 pm
removing the shadow plane from the model somehow worked, but as you can see in the attached screenshot, the shadow plane appears only when a model is stacked over another, and correctly projects the "shadow", however it doesn't appear otherwise. Can you help with this issue?

[attachment deleted by admin]