Projector class

Started by Thomas., November 07, 2012, 02:09:13 PM

Previous topic - Next topic

Thomas.

Egon, could you provide me Projector class or implement it into jPCT-AE? It would be useful for shadows... Thanks

EgonOlsen

Sure, no problem. This is how it looks:


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.

Thomas.

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 :)

EgonOlsen

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.

Thomas.

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.

EgonOlsen

Take your time, i have plenty of other things to do... ;)

Thomas.

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

EgonOlsen

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?

Thomas.

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

EgonOlsen

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

Thomas.

#10
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:

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()? :)

EgonOlsen

#11
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... ;)

Thomas.

Thanks, I had to miss this methods :)

Thomas.

#13
What am I doing wrong? I get this error:

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

EgonOlsen

Have you set Config.maxTextureLayers to 2 or something like that?