CubeTwister 2.0alpha141 2011-10-13

idx3d
Class idx3d_PerspectiveRasterizer

java.lang.Object
  extended by idx3d.idx3d_Rasterizer
      extended by idx3d.idx3d_PerspectiveRasterizer

public final class idx3d_PerspectiveRasterizer
extends idx3d_Rasterizer

Perspective-correct rasterizer stage of the render pipeline.

This rasterizer performs non-linear perspective-correct interpolation of textures. The algorithm is slower than idx3d_PerspectiveRasterizer but produces less distortions.

Perspective-correct texturing:

         Screen
         ---+------------------→ z-Axis
            |
            |
            |             z1.Textured Surface
            |           . '/
            |       . '   /
            |   . '      /            xf := 0;
          x1. '         /             dxf := 1.0/(x2 - x1);
  Eye   . ' |          /              for x := x1 to x2
    *------x+--------→+tr                xf := xf + dxf;
        ' . |        /
          x2' .     /
            |   ' ./
            |    z2 '
            ↓
            X-Axis
 
Non-optimized pseudo code which calculates for each screen pixel x between x1 and x2 the relative texture coordinate tr.
 int x1, x2, z1, z2;
 real xr, tr;
 for x := x1 to x2 do
   xr  := (x - x1) / (x1 - x2);
   tr  := xr * z1 / (xr * z1 + (1 - xr) * z2);
   ...use tr...
 end
 
Optimized pseudo code which calculates for each screen pixel x between x1 and x2 the relative texture coordinate tr.
 int x1, x2, z1, z2;
 real tr, tn, td, dtn, dtd;
 int dx;
 dtd := z1 / (x2 - x1) - (z2 / (x2 - x1);
 dtn := z1 / x2 - x1;
 td := z2;
 tn := 0;
 for x := x1 to x2 do
   tr  := tn / td;
   ...use tr...
   td  := td + dtd;
   tn := tn + dtn;
 end
 

Version:
3.2.1 2004-08-31 Werner Randelshofer: Minor bug fixes and speed improvements.
3.2 2003-12-18 Werner Randelshofer: Supports now lightmaps of different resolutions. Dependency note: This change also requires changes in class idx3d_Lightmap. Changed the idBuffer array from int[] to short[] to save memory. The idBuffer only stores triangle id's now (instead of object id's in its upper 16 bit and the triangle id in the lower 16 bits). We do not need to store the object id in the idBuffer, because all triangles know their parent object. Changed the size of the idBuffer to the size of the display area (instead of to the size of the antialias screen, which is twice as big. Dependency note: These changes also require changes in class idx3d_Math, idx3d_RenderPipeline and idx3d_Scene. Method clearReferences added to allow for better memory management by the garbage collector. Dependency note: This change also requires changes in class idx3d_RenderPipeline. Moved responsibility for texture location from class idx3d_Vertex to this class. Dependency note: This change also requires changes in idx3d_Vertex, idx3d_Triangle, idx3d_TextureProjector, idx3d_Object. Removed all OR operations with the alpha channel. As we do not produce an RGB channel, we do not have to care about the bits contained in this channel. Dependency note: This requires that the idx3d_Screen produces an image without an RGB channel.

Field Summary
 boolean ready
           
 
Constructor Summary
idx3d_PerspectiveRasterizer(idx3d_RenderPipeline pipeline)
           
 
Method Summary
 boolean isAntialiased()
           
 void loadLightmap(idx3d_Lightmap lm)
          Lightmap loader.
 void loadMaterial(idx3d_InternalMaterial material)
          Material loader.
static void main(java.lang.String[] args)
           
 void render(idx3d_Triangle tri)
          Renderer.
 void setPipeline(idx3d_RenderPipeline pipeline)
          Render pipeline.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ready

public boolean ready
Constructor Detail

idx3d_PerspectiveRasterizer

public idx3d_PerspectiveRasterizer(idx3d_RenderPipeline pipeline)
Method Detail

setPipeline

public void setPipeline(idx3d_RenderPipeline pipeline)
Description copied from class: idx3d_Rasterizer
Render pipeline. By convention this method is only called by idx3d_RenderPipeline.

Specified by:
setPipeline in class idx3d_Rasterizer

isAntialiased

public boolean isAntialiased()

loadLightmap

public void loadLightmap(idx3d_Lightmap lm)
Description copied from class: idx3d_Rasterizer
Lightmap loader.

Specified by:
loadLightmap in class idx3d_Rasterizer

loadMaterial

public void loadMaterial(idx3d_InternalMaterial material)
Description copied from class: idx3d_Rasterizer
Material loader.

Specified by:
loadMaterial in class idx3d_Rasterizer

render

public void render(idx3d_Triangle tri)
Description copied from class: idx3d_Rasterizer
Renderer.

Specified by:
render in class idx3d_Rasterizer

main

public static void main(java.lang.String[] args)

(c) Werner Randelshofer.
All rights reserved.