Author Topic: Texture plus env map  (Read 7839 times)

3d-er

  • Guest
Texture plus env map
« on: January 24, 2006, 10:01:42 am »
Egon,
Fantastic work on the engine!!!  I could not determine from the API if mapping a texture and env map to the same object is possible.  From my trials, it is not.  If it is not possible, would adding that feature be possible?  

Would a monetary donation incent getting it done sooner that later?
If speed is a concern, could a different mode be added to allow it?  The idx3d engine and Jazz3d are good examples.

Thank you in advance.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Texture plus env map
« Reply #1 on: January 24, 2006, 05:54:22 pm »
By looking at the examples you've given, i guess you are talking about software rendering here, don't you? If so, it is possible to a degree...
You can "abuse" bump mapping for it like so:

Code: [Select]

      TextureManager texMan=TextureManager.getInstance();
      Texture grey=new Texture("grey.jpg");
      Texture brick=new Texture("brick.jpg");
      Texture env=new Texture("envmap.jpg");
      texMan.addTexture("grey", grey);
      texMan.addTexture("brick", brick);
      texMan.addTexture("env", env);
      level.setAllTextures("brick","env","grey");
      level.setBlending(Object3D.BLENDING_ENABLED);
      level.setEnvmapMode(Object3D.ENVMAP_CAMERASPACE);


This blends the bump mapped environment map with the base map. If the bump map is a unicolored texture of RGB 127/127/127, you should get a plain blending without any bumps. Of course, you can add bumps in addition if you want to. The blending is additive. If you were talking about OpenGL accelerated rendering, this option doesn't exist ATM.

3d-er

  • Guest
Example not working
« Reply #2 on: January 25, 2006, 07:18:45 am »
Egon,
Correct, I was talking software rendering.  The example provided only shows 100% env map reflection not additive when run.  The brick surface does not show at all and I have used your code exactly with a 127,127,127 gray bump map.  Would it be possible to add the two textures mapping into the rendering pipeline?  I am willing to pay for this feature.
Thanks,
3d-er

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Texture plus env map
« Reply #3 on: January 25, 2006, 08:11:11 am »
But i've tried it..it works...example (with a badly placed brick texture, but anyway):



Must be something else... :?:

3d-er

  • Guest
It works!
« Reply #4 on: January 25, 2006, 08:29:36 am »
After I set blending to true and made my maps the same size it worked, but is extremely slow compared to idx3d.  I'm only getting about 4 fps for 4,000 triangles compared with idx3d doing 18,490 triangles.  I use SAMPLINGMODE_OGSS_FAST because SAMPLINGMODE_NORMAL's quality is too low for my application.

Any ideas if the speed could be improved by eliminating the bump map requirement so only envp map plus texture could render?

Thanks,
3d-er

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: It works!
« Reply #5 on: January 25, 2006, 04:50:47 pm »
Quote from: "3d-er"
Any ideas if the speed could be improved by eliminating the bump map requirement so only envp map plus texture could render?
Maybe, but i wouldn't expect too much from it. How fast is the rendering without the blending enabled, i.e. with env mapping only? Comparing the performance of IDX3D and jPCT is difficult as jPCT does a lot more and is more accurate in what it's doing. For example, IDX3D has no perspective correction for example and produces lots of gaps between polygons. What exactly is your application? An object viewer? There are some settings tailored for more complex scenes that you may try to adjust and see if that helps.

3d-er

  • Guest
rendering quality/speed
« Reply #6 on: January 25, 2006, 11:20:43 pm »
Yes, we need texture w/env map w/o bump map that is relatively quick.  The current jPCT rocks for what it does, but I hope to get slightly better image quality that is still useable (anywhere close to idx3d speed would be awesome).  It is an object viewer.

Would making a new method w/o bump mapping speed up the processing?  I am willing to pay for any customizations necessary.

Thanks,
3d-er

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Texture plus env map
« Reply #7 on: January 25, 2006, 11:31:14 pm »
I can write you a hacked renderer that does the job. That's not the problem (maybe next monday). But i'm not sure if it's really that much faster. That's why i asked about the performance without the blending (just env mapped).
If it's an object viewer only, you can disable some stuff like:

Config.doSorting=false;
Config.alwaysSort=false;
Config.spanBasedHsr=false;

and maybe (if the object is completely visible anyway)

Config.useFrustumCulling=false;

Are you using dynamic lighting? If not, Config.gouraud=false may also help.

Not sure how much you can gain from these settings, but it's worth a try.

3d-er

  • Guest
Thank you
« Reply #8 on: January 26, 2006, 06:03:39 am »
Egon,
Thank you, I will try your suggestions.
I would be very interested in a hacked renderer!  All it should do is combine transparency, texture and env maps with gouraud shading.  No bump mapping needed.  

Specifically if there are some speed optimizations that can be made, such as bit shifting where possible, avoiding if/then statements in the pipeline and avoiding new object creation at any cost (member vars for all objects rather than creating new int[], etc. in loops) and also avoiding any up or down casting such as collections work.  Is there a way to render in 32 bits?  That way any transparency ops will be handled by hardware using argb.  I believe that is one of the secrets of idx3d.

Obviously there are places where this is necessary.  Any collections work in any loop could be replaced with arrays or a hand-made collection (I can provide this to you) that returns the proper type of object w/o casting such as 3d_vector or poly (I'm sure you know arrays approach c++ speed  especially when pre-allocated).
The application I hope to create will help many people.
Thanks,
3d-er

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Texture plus env map
« Reply #9 on: January 26, 2006, 09:06:09 am »
The secret of IDX3D is not hardware acceleration of alpha, because a 1.1VM doesn't support it and there is no hardware support even in 1.4+ for images where you are explicitly setting single pixels in their int[]-array of pixels. The "secret" is, that it's doing the rendering much simpler. It's not doing the texel filtering, it's not subpixel/subtexel/subcolor correct. It has no perspective correction for neither textures, colors or zbuffer (requires 3 muls every 16 pixels). Your hints about performance are all true, but are  all in jPCT. There is not a single generic Collection used in the engine, it's full of bit shifting, no object creation in loops, reuse of objects etc.
To make you believe, here's an inner loop of the renderer. If you can suggest something that'll make it faster, i would appreciate it:

Edit: Opps, i had accidently posted the no-z-buffer version. Here's the correct one:

Code: [Select]

 for (int tx=x+yPos; tx<=end; tx++) {

  if (zbuffer[tx]>iz) {
      col=texels[((((t1&texClampU)>>18)+(((t2&texClampV)>>18)<<shift)))];

      r=(((col>>16))*(srI>>10))>>16;
      g=(((col>>8)&255)*(sgI>>10))>>16;
      b=((col&255)*(sbI>>10))>>16;

      pixels[tx]=b|(g<<8)|(r<<16);
      zbuffer[tx]=iz;
   }

   t1+=dus;
   t2+=dvs;

   srI+=delr;
   sgI+=delg;
   sbI+=delb;

   iz+=delz;
 }

3d-er

  • Guest
speed up
« Reply #10 on: January 27, 2006, 07:57:16 am »
Egon,
Hm... remove perspective correction and there is no need for texeling and the maps look distorted especially close to camera such as seen with idx3d.

So with your tight code and the dependency of persp. correction on texeling, per your previous suggestions, it doesn't appear there is a way to speed it up.  

SAMPLINGMODE_OGSS_FAST seems to be a tradeoff of speed/quality that I may be able to make work.  Thank you so much for your timely and well thought through responses, your time for looking into it and most of all, the great engine.

Best regards,
3d-er

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Texture plus env map
« Reply #11 on: January 30, 2006, 06:38:40 pm »
Here's the hacked file: http://www.jpct.net/download/hacks
To use it, you have to use the SoftGLRenderer in exactly the same way as you would with "normal" blending enabled, i.e. you also have to assign the bump map in the proper format, but with a don't-care-content (use a dummy texture of any kind for this, not one of the actual textures because bump maps will be pre-processed). The difference to the normal renderer is, that the bump map isn't used anymore for blending and that transparency works in combination with blending.
Hope this helps.