Author Topic: Pre-computed light maps  (Read 6102 times)

Offline keaukraine

  • byte
  • *
  • Posts: 34
    • View Profile
Pre-computed light maps
« on: November 15, 2010, 08:19:41 am »
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.
« Last Edit: November 15, 2010, 08:24:49 am by keaukraine »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Pre-computed light maps
« Reply #1 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.

Offline keaukraine

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Pre-computed light maps
« Reply #2 on: November 15, 2010, 03:37:08 pm »
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.
« Last Edit: November 15, 2010, 08:54:26 pm by keaukraine »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Pre-computed light maps
« Reply #3 on: November 16, 2010, 12:13:44 am »
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.

Offline keaukraine

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Pre-computed light maps
« Reply #4 on: November 16, 2010, 11:35:07 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Pre-computed light maps
« Reply #5 on: November 16, 2010, 08:39:22 pm »
This is the extract that loads and serializes the level using the desktop version:

Code: [Select]

      // .....
      // 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);

Offline keaukraine

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Pre-computed light maps
« Reply #6 on: November 17, 2010, 08:11:21 am »
Thank you, I will give this code a try later today.