www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on November 07, 2012, 02:09:13 pm

Title: Projector class
Post by: Thomas. 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
Title: Re: Projector class
Post by: EgonOlsen 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.
Title: Re: Projector class
Post by: Thomas. 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 :)
Title: Re: Projector class
Post by: EgonOlsen 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.
Title: Re: Projector class
Post by: Thomas. 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.
Title: Re: Projector class
Post by: EgonOlsen on November 09, 2012, 08:51:21 am
Take your time, i have plenty of other things to do... ;)
Title: Re: Projector class
Post by: Thomas. 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...
Title: Re: Projector class
Post by: EgonOlsen 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?
Title: Re: Projector class
Post by: Thomas. 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...
Title: Re: Projector class
Post by: EgonOlsen 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... ???
Title: Re: Projector class
Post by: Thomas. 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()? :)
Title: Re: Projector class
Post by: EgonOlsen 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... ;)
Title: Re: Projector class
Post by: Thomas. on November 11, 2012, 11:13:37 am
Thanks, I had to miss this methods :)
Title: Re: Projector class
Post by: Thomas. 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...
Title: Re: Projector class
Post by: EgonOlsen on November 11, 2012, 11:44:38 am
Have you set Config.maxTextureLayers to 2 or something like that?
Title: Re: Projector class
Post by: Thomas. on November 11, 2012, 11:46:13 am
No, maxTextureLayers is set to 4
Title: Re: Projector class
Post by: EgonOlsen on November 11, 2012, 11:57:17 am
Strange then...it's this line that crashes:

Code: [Select]
myObj.multiTex[i][polyID] == TextureManager.TEXTURE_NOTFOUND

polyID is 0 in your case, so it can't be the problem. The length of multiTex should be maxTextureLayers-1, so if it crashes on index 1, it seems to me that the array has been created for only 2 texture layers. However, it's actually not supposed to crash...i've updated the beta jar with a version that should not crash but give a log output instead if it can't add another layer. It would be interesting to see what this prints out in your case.
Title: Re: Projector class
Post by: Thomas. on November 11, 2012, 12:06:18 pm
Here is log. What is it mean?
Code: [Select]
11-11 12:05:12.101: I/jPCT-AE(15482): [ 1352631912106 ] - WARNING: No further texture stage available (2/1/4)!
11-11 12:05:12.101: I/jPCT-AE(15482): [ 1352631912106 ] - WARNING: No further texture stage available (2/3/4)!
Title: Re: Projector class
Post by: EgonOlsen on November 11, 2012, 12:24:45 pm
It means that, while the config would allow for 4 stages, the actual arrays are smaller. Maybe i should modify the method to deal with this, but i would like to know the root cause. Are these serialized objects?
Title: Re: Projector class
Post by: Thomas. on November 11, 2012, 12:32:12 pm
Particles and water-levels are created by code, everything else are serialized objects. 3DS and OBJ are no longer in use.
Title: Re: Projector class
Post by: EgonOlsen on November 11, 2012, 12:37:05 pm
As a workaround, try to serialize them in unreduced, i.e. reduced set to false. I'll fix the method later to handle this case.
Title: Re: Projector class
Post by: Thomas. on November 11, 2012, 12:47:38 pm
Oh, this is for testing purposes? Want to know if it will work? It is more than 50 objects. I'd rather wait for fix...
Title: Re: Projector class
Post by: EgonOlsen on November 11, 2012, 02:04:25 pm
I've updated the beta, but haven't really tested the fix... ;) Please give it a try to see if it helps.
Title: Re: Projector class
Post by: Thomas. on November 11, 2012, 02:28:08 pm
It works ;) but projected shadows are shifted, I have to look where is problem

edit: game can be started, but there is still this:
Code: [Select]
11-11 14:32:38.082: I/jPCT-AE(19080): [ 1352640758087 ] - WARNING: No further texture stage available (2/3/4)!
Title: Re: Projector class
Post by: EgonOlsen on November 11, 2012, 02:46:33 pm
How many layers are you using...looks like as if you've exceeded the maximum of 4 at least for some objects.