POV-Ray : Newsgroups : povray.general : What to do with the pixel in the middle : Re: What to do with the pixel in the middle Server Time
26 Apr 2024 21:30:11 EDT (-0400)
  Re: What to do with the pixel in the middle  
From: ingo
Date: 1 Feb 2019 18:33:31
Message: <XnsA9EA5AF9A331seed7@news.povray.org>
in news:XnsA9EA2A6B5B0Dseed7@news.povray.org ingo wrote:

> they seem to be "verbose"

A dense stereo cam file for example. Sanity check before serious use,

ingo

---%<------%<------%<---
#version 3.8;
global_settings{ assumed_gamma 1.0 }

#include "math.inc"
#include "transforms.inc"
//#include "udCameras.inc"

#macro udcLookAtTransform(
    D0_X_Fn, D0_Y_Fn, D0_Z_Fn,
    pLocation, pLookAt, Angle,
    optional Roll, optional vDirection,
    optional vRight, optional vUp
  )
  /*==
  Transforms the direction function of a user defined camera to look into 
the
  pLookAt direction from the camera location.
  
  Code base by: Tor Olav Kristensen, http://subcube.com
  This macro is intended to be used in user defined cameras. 
  For example use, see udcPerspective().
  
  D0_X_Fn, D0_Y_Fn, D0_Z_Fn (function): the original camera direction 
functions.
  pLocation  (vec) : the location of the camera
  pLookAt    (vec) : the point to look at
  Angle    (float) : horizontal field of view o view angle
  Roll     (float) : optional, defaults to 0. 
                     Roll, a.k.a. banking, rotates the camera around the 
view 
                     direction vector.
  vDirection (vec) : optional, defaults to +z.
  vRigth     (vec) : optional, defaults to 
<image_width/image_height,0,0>.
  vUp        (vec) : optional, defaults to +y.
  */
  #ifndef(local.Roll)
    #local Roll = 0;
  #end
  #ifndef(local.vDirection)
    #local vDirection = +1*z;
  #end
  #ifndef(local.vRight)
      #local vRight = +image_width/image_height*x;
  #end
  #ifndef(local.vUp)
    #local vUp = +1*y;
  #end
  #local vLookAt = pLookAt - pLocation;
  #local LookAtTransform = transform{
    Reorient_Trans(z, vLookAt)
    Axis_Rotate_Trans(vLookAt, Roll)
  }
  #local vDirection_1 = vtransform(vDirection, LookAtTransform);
  #local vRight_1 = vtransform(vRight, LookAtTransform);
  #local vUp_1 = vtransform(vUp, LookAtTransform);
  #local <X1_X, X1_Y, X1_Z> = vtransform(x, LookAtTransform);
  #local <Y1_X, Y1_Y, Y1_Z> = vtransform(y, LookAtTransform);
  #local <Z1_X, Z1_Y, Z1_Z> = vtransform(z, LookAtTransform);
  #local D1_X_Fn = function(u,v){
    0
    + X1_X*D0_X_Fn(u,v)
    + Y1_X*D0_Y_Fn(u,v)
    + Z1_X*D0_Z_Fn(u,v)
  };
  #local D1_Y_Fn = function(u,v){
    0
    + X1_Y*D0_X_Fn(u, v)
    + Y1_Y*D0_Y_Fn(u, v)
    + Z1_Y*D0_Z_Fn(u, v)
  };
  #local D1_Z_Fn = function(u,v){
    0
    + X1_Z*D0_X_Fn(u, v)
    + Y1_Z*D0_Y_Fn(u, v)
    + Z1_Z*D0_Z_Fn(u, v)
  };
  (D1_X_Fn, D1_Y_Fn, D1_Z_Fn)
#end

#macro udcStereo(pLocation,pLookAt,Angle,FocalDist)
  //http://paulbourke.net/stereographics/stereorender/
  #local EyeSep = FocalDist/30;
  #local Delta  = (image_width*EyeSep)/(2*FocalDist*tand(Angle/2));
  #local Angle1 = 2*atand((image_width+Delta)*tand(Angle/2)/image_width);
  #local AspectU = image_width+Delta+Delta;
  #local AspectV = image_height;
  #local vMovement  = EyeSep/2*vnormalize(vcross(pLookAt-pLocation,
<0,1,0>));
  #local pLocationL = pLocation+vMovement;
  #local pLocationR = pLocation-vMovement;
  #local <LocationXL, LocationYL, LocationZL> = pLocationL;
  #local <LocationXR, LocationYR, LocationZR> = pLocationR;
  #local LocationX = function(u){select((u<=0),-1, LocationXR, 
LocationXL)};
  #local LocationY = function(u){select((u<=0),-1, LocationYR, 
LocationYL)};
  #local LocationZ = function(u){select((u<=0),-1, LocationZR, 
LocationZL)};
  #local D0_X_Fn = function(u,v){u*AspectU};
  #local D0_Y_Fn = function(u,v){v*AspectV};
  #local D0_Z_Fn = function(u,v){AspectU/2/tand(Angle/2)};
  #local pLookAtL = pLookAt+vMovement;
  #local pLookAtR = pLookAt-vMovement;
  #local(D1L_X_Fn, D1L_Y_Fn, D1L_Z_Fn) = udcLookAtTransform(
    D0_X_Fn, D0_Y_Fn, D0_Z_Fn, pLocationL, pLookAtL, Angle1,,,,
  );
  #local(D1R_X_Fn, D1R_Y_Fn, D1R_Z_Fn) = udcLookAtTransform(
    D0_X_Fn, D0_Y_Fn, D0_Z_Fn, pLocationR, pLookAtR, Angle1,,,,
  );
  #local D2_X_Fn = function(u,v){select(
    (u<=0),
    -1, 
    D1R_X_Fn((u/AspectU*image_width)-0.25,v), 
    D1L_X_Fn((u/AspectU*image_width)+0.25,v)
  )};
  #local D2_Y_Fn = function(u,v){select((u<=0),-1, D1R_Y_Fn(u-0.25,v), 
D1L_Y_Fn(u+0.25,v))};
  #local D2_Z_Fn = function(u,v){select((u<=0),-1, D1R_Z_Fn(u-0.25,v), 
D1L_Z_Fn(u+0.25,v))};
  camera {
    user_defined
    location {
      function {LocationX(u)}
      function {LocationY(u)}
      function {LocationZ(u)}
    }
    direction {
      function {D2_X_Fn(u,v)}
      function {D2_Y_Fn(u,v)}
      function {D2_Z_Fn(u,v)}
    }
  }
#end

#declare ZeroParallax = 3;
udcStereo(<0,0,-ZeroParallax>,<0,0,0>,55,ZeroParallax)
light_source{< 1000,1000,-1000>, rgb 1}
light_source{<-1000,1000,-1000>, rgb .3}
difference{
  box{-0.5,0.5 pigment{rgb 1}}
  box{-0.5,0.5 scale <0.97,0.97,1.20>}
  box{-0.5,0.5 scale <0.97,1.20,0.97>}
  box{-0.5,0.5 scale <1.20,0.97,0.97>}
}
sphere{<0,-0.2,-1>,0.035 pigment{rgb z}}
sphere{<0,0.2,10>,0.03 pigment{rgb 1}}
plane{y,-1.5 pigment{checker}}
plane{z,20 pigment{function{abs(y)} scale 12 translate<0,-1.5,0>}}
sphere{<0, 0.0, 0>,0.03 pigment{rgb y}}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.