//== 3D Graphics begin here ====================================================
  dvxpipe 3;
  dcvxpipe 3;

  //Calc depth here
  mov #Background.MinDepth,  0.8; //Near distance
  mov #Background.MaxDepth,  6.0; //Far distance
  mov #Background.ShadeStart,1.0;
  mov #Background.DepthStep ,0.3; //Depth step. The lower, the higher quality is

  timer #Time; mul #Time,3;

  mov EAX,#Time; mod EAX,#Background.DepthStep;

  sub #Background.MinDepth,EAX;
  sub #Background.MaxDepth,EAX;

  //Initialize depth range
  mov  #Background.deltaDepth,#Background.MaxDepth;
  sub  #Background.deltaDepth,#Background.MinDepth;

  //Compute background stuff
  mov  #Background.ShadeStep,#Background.deltaDepth;
  div  #Background.ShadeStep,#Background.DepthStep;
  frnd #Background.ShadeStep;
  finv #Background.ShadeStep;
  mul  #Background.ShadeStep,#Background.ShadeStepMul;

  //Brightness too
  mov EAX,#Time; mod EAX,#Background.ShadeStep;
  sub #Background.ShadeStart,EAX;

  mov #_rect.color.r,200;
  mov #_rect.color.b,200;

// Uncomment this for trippy camera
//  timer EAX; div EAX,8; fsin EBX,EAX; mul EBX,2;
//  drotatescale EAX,EBX; mul EBX,2;

  dsetwidth 0.8;
  call Draw.Background;
dexit;

alloc Time;

//==============================================================================
Draw.Background:
  //Draw all the rectangles
  mov EAX,#Background.MinDepth; mov ECX,#Background.ShadeStart;
  BackgroundLoop:
    mov EDX,#Time; add EDX,EAX;
    mov EBP,#Time; div EBP,6.28; fcos EBP,EBP;

    fsin EDI,EDX; mul EDI,EBP; mul EDI,0.8; sub EDI,1;
    mov #_rect.offset.x,EDI;

    fcos ESI,EDX; mul ESI,EBP; mul ESI,0.4; sub ESI,1;
    mov #_rect.offset.y,ESI;

    mov EDX,ECX; fpwr EDX,2;
    mov #regZOffset,EAX;

    dcolor _rect.color;
// Uncomment this for trippy HSL color
//    mov ESI,#Time; add ESI,EAX;
//    fsin #HSL.R,ESI; mul #HSL.R,127; add #HSL.R,128; add ESI,1.57;// mul EAX,2;
//    fsin #HSL.G,ESI; mul #HSL.G,127; add #HSL.G,128; add ESI,1.57;// mul EAX,2;
//    fsin #HSL.B,ESI; mul #HSL.B,127; add #HSL.B,128;
//
//    dcolor HSL;
    dshade EDX;
    dorectwh _rect.offset,_rect.wh;

    sub ECX,#Background.ShadeStep;
    add EAX,#Background.DepthStep;

    cmp EAX,#Background.MaxDepth;
    jl BackgroundLoop;
ret

//==============================================================================
//Drawing parameters
scalar Background.MinDepth;
scalar Background.MaxDepth;
scalar Background.deltaDepth;
scalar Background.DepthStep;
scalar Background.ShadeStart;
scalar Background.ShadeStep;
scalar Background.ShadeStepMul,0.5;

color HSL;

//Generic rectangle
vector2f _rect.offset,-1,-1;
vector2f _rect.wh,2,2;

vector2f _pad1.offset;
vector2f _pad2.offset;
vector2f _pad.wh;

//Color scheme
color _rect.color, 200,200,200;
color _rect.color2,200,200,000;

color _pad1.color, 000,200,000;
color _pad2.color, 200,000,000;
