Author Topic: Projector class  (Read 6987 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Projector class
« on: November 07, 2012, 02:09:13 pm »
Egon, could you provide me Projector class or implement it into jPCT-AE? It would be useful for shadows... Thanks
« Last Edit: November 07, 2012, 02:35:43 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #1 on: November 07, 2012, 03:27:59 pm »
Sure, no problem. This is how it looks:

Code: [Select]
package com.threed.jpct;

/**
 * Projector is an extended Camera used for projecting textures into the scene.
 *
 * @see com.threed.jpct.Texture
 */
public class Projector extends Camera implements java.io.Serializable {
private static final long serialVersionUID = 1L;
}

...really, that's all there is. The actual projection magic lies in the renderer and that can't be ported to OpenGL ES, because it's missing all the required functionality. You have to do all the projection calculations in the shader. I would be grateful, if you could share some code/shaders if you have something that works, because i would like to add shadow support, but i don't have the time ATM to do this myself.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #2 on: November 08, 2012, 10:00:21 pm »
Thanks ;) Good news... Rendering of scene with per-pixel light, depth texture, motion vectors, depth of filed, distortion objects and shadow map (512) in one frame and my game running about 38fps. Without effects it is 60fps :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #3 on: November 08, 2012, 10:46:42 pm »
Could you somehow extract the depth/shadow map part of it? It would really help me to add this feature, if i have a working example to study.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #4 on: November 08, 2012, 11:07:58 pm »
It is not completed ATM. Anyway my ShadowHelper is bundled with my LightController that generates shaders based on lights parameters. But I can provide you shader as soon as be the completed.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #5 on: November 09, 2012, 08:51:21 am »
Take your time, i have plenty of other things to do... ;)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #6 on: November 09, 2012, 11:31:47 pm »
Is it possible to add the method GLGLShader.setUniform(String name, Texture texture)? If not, I have to somehow inject texture into shader, any idea how? Method getTexture() missing, but the creation of the TextureInfo is not a good idea IMHO...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #7 on: November 09, 2012, 11:45:21 pm »
I don't think so. I not aware of a way to use a texture in a shader by any other means than to assign it to a texture stage. If there were, texture stage count wouldn't be an issue and texture stages would be pointless anyway. Why would you want to?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #8 on: November 10, 2012, 12:08:35 am »
Somewhere I should use the shadow map, the good place could be a shader :) I want to maximal compatibility... I could set texture using the String name, after that in ShadowHelper create the TextureInfo with the texture of object (anyway it needs getTexture() method) and shadow map. But I'd like to keep the possibility to change the texture of object...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #9 on: November 10, 2012, 08:40:53 pm »
You can still change it on the fly, you just have to make sure to include the depth map too...i fail to see the problem... ???

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #10 on: November 10, 2012, 09:53:57 pm »
Yes, but I do not know which texture is applied on objects (missing getTexture() method), so I can not create TextureInfo. Is it possible, when I create TextureInfo in ShadowHelper and I would like to change texture at other place in the code by method setTexture(String name)?

edit:
I do not know how jPCT works inside. But would be nice this:

Code: [Select]
public void setTexture(String name){
   int id = TextureManager.getInstance().getTextureID(name);
   if(id != TextureInfo.TEXTURE_NOTFOUND){
      if(textureInfo == null)
          textureInfo = new TextureInfo(id);
      else
         textureInfo.set(id, 0, TextureInfo.MODE_ADD);
   }
}

public void setTexture(TextureInfo ti){
   textureInfo = ti;
}

public TextureInfo getTexture(){
    return textureInfo;
}

Maybe jPCT works this way, so could you implement method getTexture()? :)
« Last Edit: November 10, 2012, 10:22:36 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #11 on: November 11, 2012, 10:28:00 am »
You have several getPolygonTexture() and addTexture() methods. Maybe they are sufficient? Just keep in mind that you can't use them on stripped objects, i.e. you have to setup the objects before stripping them or don't strip them at all.

Edit: ...in the PolygonManager...but i guess you already figured it out... ;)
« Last Edit: November 11, 2012, 11:26:50 am by EgonOlsen »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #12 on: November 11, 2012, 11:13:37 am »
Thanks, I had to miss this methods :)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Projector class
« Reply #13 on: November 11, 2012, 11:36:29 am »
What am I doing wrong? I get this error:

Code: [Select]
pm.addTexture(0, textureID, TextureInfo.MODE_ADD);
...
11-11 11:29:41.861: E/AndroidRuntime(29407): FATAL EXCEPTION: GLThread 4883
11-11 11:29:41.861: E/AndroidRuntime(29407): java.lang.RuntimeException: [ 1352629781671 ] - ERROR: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
11-11 11:29:41.861: E/AndroidRuntime(29407): at com.threed.jpct.PolygonManager.addTexture(PolygonManager.java:113)

edit: I whole code is not used strip() method...
« Last Edit: November 11, 2012, 11:44:49 am by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Projector class
« Reply #14 on: November 11, 2012, 11:44:38 am »
Have you set Config.maxTextureLayers to 2 or something like that?