Author Topic: jpct-ae noob question  (Read 8285 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae noob question
« Reply #15 on: August 10, 2012, 11:01:23 pm »
Can you please post the code of your IRenderHook implementation!?

Offline octav_ro

  • byte
  • *
  • Posts: 13
    • View Profile
Re: jpct-ae noob question
« Reply #16 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

}
}



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae noob question
« Reply #17 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?

Offline octav_ro

  • byte
  • *
  • Posts: 13
    • View Profile
Re: jpct-ae noob question
« Reply #18 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?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae noob question
« Reply #19 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae noob question
« Reply #20 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.

 
« Last Edit: August 13, 2012, 09:01:08 pm by EgonOlsen »

Offline octav_ro

  • byte
  • *
  • Posts: 13
    • View Profile
Re: jpct-ae noob question
« Reply #21 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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae noob question
« Reply #22 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.

Offline octav_ro

  • byte
  • *
  • Posts: 13
    • View Profile
Re: jpct-ae noob question
« Reply #23 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae noob question
« Reply #24 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.

Offline octav_ro

  • byte
  • *
  • Posts: 13
    • View Profile
Re: jpct-ae noob question
« Reply #25 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]