1// This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 2// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a 3// letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 4 5/* Persistence Of Vision Raytracer sample file. 6 7 Demo for the Mesh Camera macros for use with the new mesh_camera: 8 9 Shows how to use the macros to create a custom mesh camera and apply some effects, like antialiasing 10 and vignetting, or to save it to a file for reuse. 11 12 -- 13 Jaime Vives Piqueres, Jan. 2011 <jaime@ignorancia.org> */ 14 15/******************************************************************************************* 16 * $File: //depot/povray/smp/distribution/scenes/camera/mesh_camera/meshcam_persp_demo.pov $ 17 * $Revision: #1 $ 18 * $Change: 5377 $ 19 * $DateTime: 2011/01/09 19:56:00 $ 20 * $Author: jholsenback $ 21 ******************************************************************************************/ 22#version 3.7; 23 24// control center 25#declare meshcam_file=1; // 0=off, 1=save mesh to file, 2=load mesh from file 26#declare aa_samples=5; // extra rays per pixel (one mesh copy per ray) (use 0 to turn aa off) 27#declare aa_aperture=.02; // max displacement along up and right vector 28#declare aa_rand=seed(78); // random seed for the fake aa 29#declare use_vignetting=1; // vignetting effect: 0=off, 1=on, fixed amount 30#declare use_distortion=.15; // lens distortion: 0=off, >0=barrel, <0=pincushion 31 32// common globals for all the demos 33#include "demo_globals.inc" 34 35// standard includes 36#include "colors.inc" 37#include "textures.inc" 38 39// common test subjects and scenario 40#include "demo_common.inc" 41 42// mesh camera macros being demonstrated 43#include "meshcam_macros.inc" 44 45// camera parameters 46#declare c_location=<4,2,-3>; // location 47#declare c_look_at=<0,1.1,1>; // look at 48#declare c_angle=54; // angle 49// calculate up and right vector transforms for fake antialiasing 50#declare f_up=vtransform(y,Reorient_Trans(z,c_look_at-c_location)); 51#declare f_right=vtransform(x,Reorient_Trans(z,c_look_at-c_location)); 52 53// create a mesh simulating a perspective camera, with or without distortion, with optional load/save mechanism 54#if (meshcam_file>0) 55 // get the file name 56 #if (use_distortion=0) 57 #declare Prefix="meshcam-pinhole_"; 58 #else 59 #declare Prefix="meshcam-lens_"; 60 #end 61 #declare mesh_file=concat(concat(concat(concat(concat(concat(Prefix,str(image_width,0,0)),"x"),str(image_height,0,0)),"-angle_"),str(c_angle,0,0)),".inc"); 62#else 63 // ..wich should be empty to turn the mesh file off 64 #declare mesh_file=""; 65#end 66#if (meshcam_file=2) 67 // loading a mesh from file 68 #declare camera_mesh= 69 #include mesh_file 70#else 71 // create a new mesh 72 #if (use_distortion=0) 73 #declare camera_mesh=meshcam_pinhole(image_width, image_height, c_angle, mesh_file) 74 #else 75 #declare camera_mesh=meshcam_lens(image_width, image_height, c_angle, use_distortion, mesh_file) 76 #end 77#end 78 79// create the camera with the generated or loaded mesh 80camera{ 81 mesh_camera{ aa_samples+1 0 // distribution 1 will do the job too in this case, as all the meshes are the same 82 mesh{camera_mesh 83 meshcam_placement(c_location,c_look_at) 84 } 85 // additional copies of the mesh for fake antialiasing, randomly translated along the viewing plane 86 #declare i_samples=0; 87 #while (i_samples<aa_samples) 88 #declare c_look_at_tmp=c_look_at+((-f_up*.5+f_up*rand(aa_rand))*aa_aperture*i_samples/aa_samples) 89 +((-f_right*.5+f_right*rand(aa_rand))*aa_aperture*i_samples/aa_samples); 90 mesh{camera_mesh 91 meshcam_placement(c_location,c_look_at_tmp) 92 } 93 #local i_samples=i_samples+1; 94 #end 95 } 96 location <0,0,-.01> // look at the face slighty off along the normal 97} 98 99// add vignetting if enabled, by instancing the mesh camera on the scene with a tricky texture 100#if (use_vignetting) 101mesh{camera_mesh 102 texture{ 103 pigment{ 104 cylindrical poly_wave 2 105 color_map{ 106 [0.2 rgb 0 transmit 0] 107 [0.5 rgb 0 transmit 1] 108 [1.0 rgb 0 transmit 1] 109 } 110 rotate 90*x 111 scale <image_width/image_height,1,1> 112 } 113 finish{emission 1} 114 } 115 hollow no_shadow 116 meshcam_placement(c_location,c_look_at) 117} 118#end 119 120 121 122