Pre-computed light maps

Started by keaukraine, November 15, 2010, 08:19:41 AM

Previous topic - Next topic

keaukraine

Can I use pre-computed light maps with jPCT-AE? Does it support multi-texturing so I can apply pre-computed shadows on objects?
If it doesn't support this, vertex coloring also can be handy in this situation. Does engine support coloring of certain vertices? This way I also can make some parts of objects darker and lighter.

If jPCT-AE doesn't have this feature (vertex colors) please add it, I suppose it isn't very hard to implement.

EgonOlsen

Current smartphone hardware supports two texture stages and so does jPCT-AE. The bigger problem is, that neither 3DS nor OBJ allows for multiple texture layers. I usually split the models into two, one for each layer, then use desktop jPCT to combine them into one object and serialize that for loading it into AE.

keaukraine

#2
Quote from: EgonOlsen on November 15, 2010, 09:28:13 AM
Current smartphone hardware supports two texture stages and so does jPCT-AE. The bigger problem is, that neither 3DS nor OBJ allows for multiple texture layers. I usually split the models into two, one for each layer, then use desktop jPCT to combine them into one object and serialize that for loading it into AE.
OK, can you please give hints how to do this? Do you have some examples or description of such procedure?
I suppose combined object will have double polycount (polygons w/ diffuse and the same polygons w/ lightmaps), or it doesn't?

And what about adding colors to vertices? Is this possible? This seems to be the easiest (and more efficient) way to create shadows.

EgonOlsen

Vertex colors are not supported ATM. Vertex alpha is, but no colors. There was a reason for this, i just can't remember it right now...

About the multi-texturing approach: No, the polycount doesn't change. The idea is to export the model two times, one time with normal texture coordinates and one time with the uv-mapping for the lightmaps. After loading, you merge them into one model with two texture layers by using the PolygonManager. I have some sample code that does this with a quake3-level lying around. I'll try to post it tomorrow or the day after. On current hardware, multitexturing is virtually free, so this is a pretty good approach for doing shadows.
You can see the result in the last test of An3DBench (available at the market), where i'm using it. Or watch the video at http://www.youtube.com/watch?v=9gWVMzowM7c (Level benchmark starts at 1:10)...keep in mind that this was taken from a quite slow phone, which is why is looks pretty jerky.

keaukraine

Oh, that would be great if you will provide code samples on how to combine UV maps.

I've checked out An3DBench, lightmaps looks nice in it's Quake level test.

Now I don't have need in vertex coloring, I will use lightmaps.

EgonOlsen

This is the extract that loads and serializes the level using the desktop version:



      // .....
      // Ensure that all textures are loaded...it's not part of this code....
      // .....

      // Load the level with the base texture mapping
      Object3D[] levelParts=Loader.load3DS("demo/q3/ql1.3ds", 5f);
      Object3D level=Object3D.mergeAll(levelParts);
     
      // Load the same mesh but with lightmapping
      levelParts=Loader.load3DS("demo/q3/ql2.3ds", 5f);
      Object3D lightmap=Object3D.mergeAll(levelParts);

      // Merge the two into one...
      PolygonManager pm1=level.getPolygonManager();
      PolygonManager pm2=lightmap.getPolygonManager();

      int max=pm1.getMaxPolygonID();

      Object3D result=new Object3D(max);

      for (int i=0; i<max; i++) {
         int tid1=pm1.getPolygonTexture(i);
         int tid2=pm2.getPolygonTexture(i);
         SimpleVector ver1=pm1.getTransformedVertex(i, 0);
         SimpleVector ver2=pm1.getTransformedVertex(i, 1);
         SimpleVector ver3=pm1.getTransformedVertex(i, 2);
         SimpleVector lt1=pm1.getTextureUV(i, 0);
         SimpleVector lt2=pm1.getTextureUV(i, 1);
         SimpleVector lt3=pm1.getTextureUV(i, 2);

         SimpleVector mt1=pm2.getTextureUV(i, 0);
         SimpleVector mt2=pm2.getTextureUV(i, 1);
         SimpleVector mt3=pm2.getTextureUV(i, 2);

         TextureInfo ti=new TextureInfo(tid1, lt1.x, lt1.y, lt2.x, lt2.y, lt3.x, lt3.y);
         ti.add(tid2, mt1.x, mt1.y, mt2.x, mt2.y, mt3.x, mt3.y, TextureInfo.MODE_MODULATE);
         result.addTriangle(ver1, ver2, ver3, ti);
      }

      level=result;

      level.getMesh().compress();
      level.build();
      new DeSerializer().serialize(level, new FileOutputStream("mylevel.ser"), true);

keaukraine

Thank you, I will give this code a try later today.