Advertisement
DEKTEN

SDF_012

Nov 28th, 2020 (edited)
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** ************************************************ ***
  2. ***                                                  ***
  3. ***     Live Stream Of Me Working On This Code:      ***
  4. ***                                                  ***
  5. *** ************************************************ ***
  6.  
  7.                 twitch.com/kanjicoder    
  8.  
  9. *** ************************************************ ***
  10. ***                                                  ***
  11. *** EASY___SOURCE:  tinyurl.com/SDF-012              ***
  12. *** DIRECT_SOURCE:  pastebin.com/jUUQ0CxR            ***
  13. ***                                                  ***
  14. *** EASY_____DEMO:  tinyurl.com/SDF-012-DEMO         ***
  15. *** DIRECT___DEMO:  shadertoy.com/view/3dKBzh        ***
  16. ***                                                  ***
  17. *** About: Voxel Rendering For Patent Drawings.      ***
  18. ***        This version is a work in progress.       ***
  19. ***                                                  ***
  20. ***        Today we refine our ray marching          ***
  21. ***        function so that it takes more than       ***
  22. ***        ONE step into to world space.             ***
  23. ***                                                  ***
  24. *** ************************************************ **/
  25. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  26. /** M: Macros Section **/
  27.  
  28.     #define V_4  vec4
  29.     #define V_3  vec3
  30.     #define V_2  vec2
  31.     #define F32 float
  32.     #define I32   int
  33.     #define U32  uint
  34.  
  35. /** M: Macros Section **/
  36. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  37. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  38. /** D: Data Section **/
  39.  
  40.     //:DEBUGGING:====================================://
  41.  
  42.         V_4 THE_COLOR_OF_EMPTY_SPACE=V_4(
  43.             0.0 , 0.0 , 0.0 , 1.0
  44.         /** RED   GRE   BLU   ALP **/
  45.         );
  46.  
  47.     //:====================================:DEBUGGING://
  48.     //:CONFIGURATION:================================://
  49.  
  50.         //:CAMERA_SETTINGS:==========================://
  51.         /** **************************************** ***
  52.         PREFIX:
  53.  
  54.             OGP: OrthoGraphicProjection
  55.             P3D: Perspective_3D
  56.             T3O: TUBE360_OUT (TubeCam Looking OUTWARD)
  57.             T3I: TUBE360_INN (TubeCam Looking INWARD )
  58.  
  59.         POSTFIX: (SUFFIX ):
  60.             TOP: Top View
  61.             34D: 3/4 Tilted DOWN view.
  62.             AAZ: Around_Axis_Z (NOT:WAZ)
  63.  
  64.         NOTES:
  65.  
  66.             T3O    : commonly known as PANORAMIC 360  
  67.             TubeCam: Revolve Around Axis As Camera.
  68.                      Literally "Tube Camera"
  69.  
  70.         *** **************************************** **/
  71.  
  72.             #define OGP_TOP ( 1 ) /** Good For Debug **/
  73.             #define OGP_34D ( 2 ) /** PATENT_DRAWING **/
  74.             #define T3O_AAZ ( 3 ) /** Outward: Z-Axis**/
  75.             #define T3I_AAZ ( 4 ) /** Inward : Z-Axis**/
  76.  
  77.             /** Selected Camera Type **/
  78.             #define CAMTYPE ( OGP_34D )
  79.         //  #define CAMTYPE ( OGP_TOP )
  80.  
  81.         //:==========================:CAMERA_SETTINGS://
  82.  
  83.         /** SLICE_RENDER_USING_CAMERA_PLANE **/
  84.         int CFG_SLICE_RENDER=( 0 );
  85.  
  86.     //:================================:CONFIGURATION://
  87.     //:RAYMARCHING_AND_VOXEL_CONSTANTS:==============://
  88.  
  89.         //:These defines are for ray marching when using
  90.         //:fragment coordinates as our coordinate space.
  91.         #define MAX_STE 1000   //:Max Step
  92.         #define MIN_DIS 0.02   //:Min Dist (SurfaceDist)
  93.         #define MAX_DIS (64.0*16.0 * 1.0) //:Max Dist
  94.  
  95.         //:Number of tiles on each axis:
  96.         #define NTX  8  //:Num_Tiles (   in_voxel_map )
  97.         #define NTY  4  //:Num_Tiles (   in_voxel_map )
  98.         #define NTZ  7  //:Num_Tiles (   in_voxel_map )
  99.  
  100.         //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  101.         #define NPX  16 //:Num_Pixels_X( in_a_tile    )
  102.         #define NPY  16 //:Num_Pixels_Y( in_a_tile    )
  103.         #define NPZ  16 //:Num_Pixels_Z( in_a_tile    )
  104.  
  105.         //:Total__number_of__Pixels__in_entire_voxel_map
  106.         #define TPX  ( NTX * NPX ) //: Total_Pixels_X
  107.         #define TPY  ( NTY * NPY ) //: Total_Pixels_Y
  108.         #define TPZ  ( NTZ * NPZ ) //: Total_Pixels_Z
  109.  
  110.         #define _  U32( 0 )                                        
  111.         #define X  U32( 1 )    
  112.         #define C  U32( 0x00FFFFff )
  113.         #define c  U32( 0x008888ff )
  114.         #define Y  U32( 0xFFFF00ff )
  115.         #define y  U32( 0x888800ff )
  116.         #define M  U32( 0xFF00FFff )
  117.         #define m  U32( 0x880088ff )
  118.         #define L  U32( 0x88FF00ff )
  119.         #define l  U32( 0x448800ff )
  120.         #define O  U32( 0xFF8800ff )
  121.         #define o  U32( 0x884400ff )
  122.         U32  VAT[ NTX * NTY * NTZ ]= U32[ 8 * 4 * 7 ](  
  123.  
  124.         /** TODO: Eventually use an integer texture  **/
  125.         /**       for this tilemap data.             **/
  126.            
  127.         //:Highest Z Cross Section Is First Tile Map
  128.         //: 1 2 3 4 5 6 7 8        --- -----------------
  129.             c,C,c,C,c,C,c,C, //: 1  |             ^
  130.             C,_,_,O,o,_,_,c, //: 2  | Z == 0      |
  131.             c,_,_,o,O,_,_,C, //: 3  |             |
  132.             C,c,C,c,C,c,C,c, //: 4  |             |
  133.         //:                        ---            |
  134.         //: 1 2 3 4 5 6 7 8        ---   Cross Sections
  135.             Y,_,_,_,_,_,_,y, //: 1  |    Can be thought
  136.             _,_,_,_,_,_,_,_, //: 2  |    of as differ-
  137.             _,_,_,_,_,_,_,_, //: 3  |    -ent 2D
  138.             y,_,_,_,_,_,_,Y, //: 4  |    tilemaps.
  139.         //:                        ---            |
  140.         //: 1 2 3 4 5 6 7 8        ---            |
  141.             M,_,_,_,_,_,_,M, //: 1  |             |
  142.             m,_,_,L,l,_,_,m, //: 2  | Z == 2      |
  143.             M,_,_,l,L,_,_,M, //: 3  |             |
  144.             m,_,_,_,_,_,_,m, //: 4  |             V
  145.         //:                        --- -----------------
  146.  
  147.         //: 1 2 3 4 5 6 7 8
  148.             M,_,C,O,M,Y,_,M,
  149.             m,_,_,_,_,_,_,m,
  150.             M,_,_,_,_,_,_,M,
  151.             m,_,_,_,_,_,_,m,
  152.         //: 1 2 3 4 5 6 7 8
  153.             M,_,_,_,_,_,_,M,
  154.             m,_,C,O,M,Y,_,m,
  155.             M,_,_,_,_,_,_,M,
  156.             m,_,_,_,_,_,_,m,
  157.         //: 1 2 3 4 5 6 7 8
  158.             M,_,_,_,_,_,_,M,
  159.             m,_,_,_,_,_,_,m,
  160.             M,_,C,O,M,Y,_,M,
  161.             m,_,_,_,_,_,_,m,
  162.         //: 1 2 3 4 5 6 7 8
  163.             M,_,_,_,_,_,_,M,
  164.             m,_,_,_,_,_,_,m,
  165.             M,_,_,_,_,_,_,M,
  166.             m,_,C,O,M,Y,_,m //:<<< NO COMMA LAST ELEMENT
  167.  
  168.         );                                                
  169.         #undef  _                                            
  170.         #undef  X  
  171.         #undef  C  
  172.         #undef  c  
  173.         #undef  Y  
  174.         #undef  y  
  175.         #undef  M  
  176.         #undef  m  
  177.         #undef  L  
  178.         #undef  l  
  179.         #undef  O  
  180.         #undef  o  
  181.  
  182.     //:==============:RAYMARCHING_AND_VOXEL_CONSTANTS://
  183.     //:STRUCTS:======================================://
  184.  
  185.         //:RWC_AND_RWN:------------------------------://
  186.  
  187.             struct  RWC_AND_RWN{
  188.                 V_3 rwC        ;
  189.                 V_3         rwN;
  190.             };
  191.        
  192.         //:------------------------------:RWC_AND_RWN://
  193.         //:VOX_000:----------------------------------://
  194.  
  195.             /** VOC: VOxel_Current(information) **/
  196.             struct VOC{  
  197.                 U32 has;  //  voxel:exists?     : 1 : //
  198.                 U32 val;  //  voxel:tile_value  : 2 : //
  199.                           //                    :---: //
  200.                 I32 dex;  //  voxel:1d_index    : 3 : //
  201.                 I32 t_x;  //  voxel:tile_x      : 4 : //
  202.                 I32 t_y;  //  voxel:tile_y      : 5 : //
  203.                 I32 t_z;  //  voxel:tile_z      : 6 : //
  204.             };                                
  205.  
  206.             /** VOD: VOxel_Distance(information) **/
  207.             struct VOD{  
  208.                 F32     dis_nex; //:Distance_To_Next
  209.                 F32     dis_sur; //:Distance_To_Surface
  210.                                  //:Within_Current_Voxel
  211.             };
  212.  
  213.             struct VOE{
  214.                 F32  msg_err;
  215.             };
  216.  
  217.             struct VOX_000{ /** var: vox_000 **/
  218.                        
  219.                 VOC     voc; //:Voxel_Current_Info
  220.                 VOD     vod; //:Voxel_Distance_Info
  221.                 VOE     voe; //:Voxel_Error____Info
  222.            
  223.             };
  224.  
  225.         //:----------------------------------:VOX_000://
  226.         //:VOX_MAR:----------------------------------://
  227.        
  228.             struct VOX_MAR{ //:SEE[ #VOX_MAR_ABOUT# ]
  229.  
  230.                 uint exit;
  231.  
  232.             };
  233.  
  234.         //:----------------------------------:VOX_MAR://
  235.  
  236.     //:======================================:STRUCTS://
  237.  
  238. /** D: Data Section **/
  239. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  240. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  241. /** I: Inifnite Degree Functions. Always At Top.     **/
  242.  
  243.     //:NO_HALT_USE_ERROR_PIXEL:======================://
  244.     //:PIX_ERR:======================================://
  245.  
  246.         #define ERR_001  1  /** msg_err #1 (0x101010)**/
  247.                             /** msg_err #1 (0x010101)**/
  248.  
  249.         #define ERR_002  2  /** msg_err #2 (0x202020)**/
  250.                             /** msg_err #2 (0x020202)**/
  251.  
  252.         #define ERR_003  3  /** msg_err #3 (0x303030)**/
  253.                             /** msg_err #3 (0x030303)**/
  254.  
  255.         V_4     PIX_ERR(
  256.             int msg_err /** EX: MSG_ERR_001 **/
  257.         ,   V_4 pix_err /** Previous Pixel Error **/
  258.         ,   int   o_k
  259.         )
  260.         {
  261.             /** Muddy Pastel Yellow For When You     **/
  262.             /** forget to set the pix_err_out value. **/
  263.             V_4 pix_err_out=V_4(0.5,0.5,0.2,1);
  264.  
  265.             float flux=( mod(iTime,1.0) );
  266.  
  267.             //:COLOR_PICKER_DEBUG_HEX:---------------://
  268.        
  269.             /** Make it easy to find source of error **/
  270.             /** in code by using color picker on     **/
  271.             /** shader output and then doing a       **/
  272.             /** CTRL+F with that hex code to find    **/
  273.             /** the offending source code.           **/
  274.  
  275.                 F32 _ =F32( 0.0    );
  276.                 F32 MAX =F32( 255.0  ); // MaxIntensity
  277.                 F32  A  =F32( 1.0    ); // Alpha_Max
  278.  
  279.                 //:ERROR_CODE_STROBE_COLORS:---------://
  280.  
  281.                 F32 _01_ =( F32(0x01) / MAX );
  282.                 F32 _10_ =( F32(0x10) / MAX );
  283.                 //
  284.                 F32 _02_ =( F32(0x02) / MAX );
  285.                 F32 _20_ =( F32(0x20) / MAX );
  286.                 //
  287.                 F32 _03_ =( F32(0x03) / MAX );
  288.                 F32 _30_ =( F32(0x30) / MAX );
  289.                 //
  290.                 F32 _04_ =( F32(0x04) / MAX );
  291.                 F32 _40_ =( F32(0x40) / MAX );
  292.                 //
  293.                 F32 _05_ =( F32(0x05) / MAX );
  294.                 F32 _50_ =( F32(0x50) / MAX );
  295.                 //
  296.                 F32 _06_ =( F32(0x06) / MAX );
  297.                 F32 _60_ =( F32(0x60) / MAX );
  298.                 //
  299.                 F32 _07_ =( F32(0x07) / MAX );
  300.                 F32 _70_ =( F32(0x70) / MAX );
  301.                 //
  302.                 F32 _08_ =( F32(0x08) / MAX );
  303.                 F32 _80_ =( F32(0x80) / MAX );
  304.                 //
  305.                 F32 _09_ =( F32(0x09) / MAX );
  306.                 F32 _90_ =( F32(0x90) / MAX );
  307.  
  308.                 V_4 _0x010101_ = V_4(_01_,_01_,_01_, A);
  309.                 V_4 _0x101010_ = V_4(_10_,_10_,_10_, A);
  310.  
  311.                 V_4 _0x020202_ = V_4(_02_,_02_,_02_, A);
  312.                 V_4 _0x202020_ = V_4(_20_,_20_,_20_, A);
  313.  
  314.                 V_4 _0x030303_ = V_4(_03_,_03_,_03_, A);
  315.                 V_4 _0x303030_ = V_4(_30_,_30_,_30_, A);
  316.  
  317.                 V_4 _0x040404_ = V_4(_04_,_04_,_04_, A);
  318.                 V_4 _0x404040_ = V_4(_40_,_40_,_40_, A);
  319.  
  320.                 V_4 _0x050505_ = V_4(_05_,_05_,_05_, A);
  321.                 V_4 _0x505050_ = V_4(_50_,_50_,_50_, A);
  322.  
  323.                 V_4 _0x060606_ = V_4(_06_,_06_,_06_, A);
  324.                 V_4 _0x606060_ = V_4(_60_,_60_,_60_, A);
  325.  
  326.                 V_4 _0x070707_ = V_4(_07_,_07_,_07_, A);
  327.                 V_4 _0x707070_ = V_4(_70_,_70_,_70_, A);
  328.  
  329.                 V_4 _0x080808_ = V_4(_08_,_08_,_08_, A);
  330.                 V_4 _0x808080_ = V_4(_80_,_80_,_80_, A);
  331.  
  332.                 V_4 _0x090909_ = V_4(_09_,_09_,_09_, A);
  333.                 V_4 _0x909090_ = V_4(_90_,_90_,_90_, A);
  334.  
  335.                 //:---------:ERROR_CODE_STROBE_COLORS://
  336.                 //:ERROR_ZERO_COLORS:----------------://
  337.                 #define F float
  338.                 #define V vec4
  339.                 /** If you forget to set error code, **/
  340.                 /** you will see flashing red and    **/
  341.                 /** blue. ( _0xFF0666_ & _0x6660FF_ )**/
  342.                  
  343.                 F   _FF_=( F32(0xFF) / MAX );
  344.                 //  _06_=( F32(0x06) / MAX );
  345.                 //  _60_=( F32(0x60) / MAX );
  346.                 F   _66_=( F32(0x66) / MAX );
  347.                 V   _0xFF0666_ =V_4(_FF_,_06_,_66_,A);
  348.                 V   _0x6660FF_ =V_4(_66_,_60_,_FF_,A);
  349.  
  350.                 #undef F
  351.                 #undef V
  352.                 //:----------------:ERROR_ZERO_COLORS://
  353.                 //:BAD_OK_ERROR_COLOR:---------------://
  354.                 #define F float
  355.                 #define V vec4
  356.                 /** You will see this if you init    **/
  357.                 /** o_k to a value other than 1 in   **/
  358.                 /** your source code.                **/
  359.                 /** Strobes between orange and lime. **/
  360.                 /** ( _0xFF7700_ & _0x77FF00_ )      **/
  361.                  
  362.                 //  _FF_=( F32(0xFF) / MAX );
  363.                 F   _77_=( F32(0x77) / MAX );
  364.                 F   _00_=( F32(0x00) / MAX );
  365.                 V   _0xFF7700_ =V_4(_FF_,_77_,_00_,A);
  366.                 V   _0x77FF00_ =V_4(_77_,_FF_,_00_,A);
  367.  
  368.                 #undef F
  369.                 #undef V
  370.                 //:---------------:BAD_OK_ERROR_COLOR://
  371.  
  372.             //:---------------:COLOR_PICKER_DEBUG_HEX://
  373.  
  374.             if( o_k <= 0 ){
  375.                 pix_err_out = pix_err;
  376.             }else
  377.             if( 1 == o_k ){
  378.  
  379.                 /** table of error "messages" #0 **/
  380.                 V_4 tab_err_000[10]=V_4[10](        
  381.                                                
  382.                     // 0: Invalid Error Code    
  383.                     _0xFF0666_  // RED_FLASH
  384.                          
  385.                     // Odd Frame Error Colors:
  386.                 ,   _0x010101_  //  ERR_001 : ODD_FRAME
  387.                 ,   _0x020202_  //  ERR_002 : ODD_FRAME
  388.                 ,   _0x030303_  //  ERR_003 : ODD_FRAME
  389.                 ,   _0x040404_  //  ERR_004 : ODD_FRAME
  390.                 ,   _0x050505_  //  ERR_005 : ODD_FRAME
  391.                 ,   _0x060606_  //  ERR_006 : ODD_FRAME
  392.                 ,   _0x070707_  //  ERR_007 : ODD_FRAME
  393.                 ,   _0x080808_  //  ERR_008 : ODD_FRAME
  394.                 ,   _0x090909_  //  ERR_009 : ODD_FRAME
  395.                 );;        
  396.                 /** table of error "messages" #1 **/
  397.                 V_4 tab_err_001[10]=V_4[10](        
  398.                                                
  399.                     // 0: Invalid Error Code    
  400.                     _0x6660FF_ // BLUE_FLASH    
  401.                          
  402.                     // Even Frame Error Colors:
  403.                 ,   _0x101010_  //  ERR_001 : EVE_FRAME
  404.                 ,   _0x202020_  //  ERR_002 : EVE_FRAME
  405.                 ,   _0x303030_  //  ERR_003 : EVE_FRAME
  406.                 ,   _0x404040_  //  ERR_004 : EVE_FRAME
  407.                 ,   _0x505050_  //  ERR_005 : EVE_FRAME
  408.                 ,   _0x606060_  //  ERR_006 : EVE_FRAME
  409.                 ,   _0x707070_  //  ERR_007 : EVE_FRAME
  410.                 ,   _0x808080_  //  ERR_008 : EVE_FRAME
  411.                 ,   _0x909090_  //  ERR_009 : EVE_FRAME
  412.                 );;                      
  413.  
  414.                 if( mod(iTime*16.0,2.0) < 1.0 ){
  415.                     pix_err_out =( tab_err_000
  416.                                  [ msg_err ] );;
  417.                 }else{
  418.                     pix_err_out =( tab_err_001
  419.                                  [ msg_err ] );;
  420.                 };;
  421.  
  422.             }else{
  423.                 /** Orange strobe for an o_k value   **/
  424.                 /** that is NOT expected. (o_k >= 2) **/
  425.  
  426.                 if( mod(iTime*2.0,2.0) < 1.0 ){
  427.                     pix_err_out = _0xFF7700_; // ORANGE
  428.                 }else{
  429.                     pix_err_out = _0x77FF00_; // LIME
  430.                 };;
  431.  
  432.             };;
  433.                
  434.             return( pix_err_out );
  435.         }
  436.  
  437.     //:======================================:PIX_ERR://
  438.     //:======================:NO_HALT_USE_ERROR_PIXEL://
  439.  
  440. /** I: Inifnite Degree Functions. Always At Top.     **/
  441. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  442. //:22222222222222222222222222222222222222222222222222://
  443.  
  444.     //:INTERPOLATION_3D:=============================://
  445.     //:sfd_i3d:======================================://
  446.  
  447.         V_3 sdf_i3d(
  448.         /**/V_3 _1_
  449.         ,   V_3 _2_
  450.         ,   F32 f_p
  451.         ){
  452.             return( _1_ + ( ( _2_ - _1_ )*f_p ) );
  453.         }
  454.  
  455.     //:=============================:INTERPOLATION_3D://
  456.     //:======================================:sfd_i3d://
  457.     //:FIRST_VOXEL_QUERY_NEEDED:=====================://
  458.  
  459.         #define T_X vox_000.voc.t_x
  460.         #define T_Y vox_000.voc.t_y
  461.         #define T_Z vox_000.voc.t_z
  462.  
  463.         /** rwN used to find distance to NEXT voxel. **/
  464.             VOX_000
  465.         GET_vox_000_USE_xyz_rwN(
  466.                         V_3 xyz
  467.                     ,   V_3     rwN
  468.         )
  469.         {
  470.             VOX_000 vox_000;
  471.  
  472.             //:CURRENT_VOXEL_CELL:-------------------://
  473.  
  474.             vox_000.voc.val = U32( 0 );
  475.             T_X = ( int(floor( xyz.x / float( NPX ))));
  476.             T_Y = ( int(floor( xyz.y / float( NPY ))));
  477.             T_Z = ( int(floor( xyz.z / float( NPZ ))));
  478.  
  479.             //:-------------------:CURRENT_VOXEL_CELL://
  480.             //:GET_VOXEL_CELL_VALUE:-----------------://
  481.  
  482.             /** Voxel Volume Is Hard Coded To have   **/
  483.             /** voxel__tile[0,0,0] stuck at world    **/
  484.             /** world_coord[0,0,0]                   **/
  485.             if( T_X >= 0 && T_X < NTX
  486.             &&  T_Y >= 0 && T_Y < NTY
  487.             &&  T_Z >= 0 && T_Z < NTZ
  488.             ){
  489.  
  490.                 //: Index2D -and- Index3D
  491.                 int D2D = T_X + ( NTX    *    T_Y );
  492.                 int D3D = D2D + ( NTX * NTY * T_Z );
  493.  
  494.                 vox_000.voc.dex=(      D3D   );
  495.                 vox_000.voc.val=( VAT[ D3D ] );
  496.  
  497.                 /** NOTE: Voxel value 0 will NOT get **/
  498.                 /**       special treatment. It could**/
  499.                 /**       contain geometry if we     **/
  500.                 /**       really wanted it to.       **/
  501.                 vox_000.voc.has= U32(  1  );
  502.                
  503.             }else{
  504.                 /** Using a "has" flag so we         **/
  505.                 /** can keep more logic UNSIGNED.    **/
  506.                 /** (No need for negative value to ) **/
  507.                 /** (be used for invalid dex or val) **/
  508.                 vox_000.voc.dex= int(  0  );
  509.                 vox_000.voc.val= U32(  0  );
  510.                 vox_000.voc.has= U32(  0  );
  511.             };;
  512.             //:-----------------:GET_VOXEL_CELL_VALUE://
  513.             //:DIST_TO_NEXT_VOXEL:-------------------://    
  514.             /** ************************************ ***
  515.                                 x_bound
  516.                                 |||
  517.                                 |||
  518.                                 |||
  519.             ====+-----+---[i]----+====== y_bound ====
  520.                 |     |   /      ||
  521.                 |     |  /       ||
  522.                 |     | /        ||
  523.                 |     |/         ||
  524.                 +- - -P----------+|
  525.                 |     .          ||
  526.                 |     .          ||
  527.                 +-----+----------+|
  528.                                 |||
  529.                                 |||
  530.                                 |||
  531.                                 |||
  532.             *** ************************************ **/
  533.             #define P xyz /** Point  **/
  534.             #define N rwN /** Normal **/
  535.  
  536.                 //:SIGNS_OF_RAY_VECTOR:--------------://
  537.                 /** We need to know if the ray is    **/
  538.                 /** moving forwards to HIGHER tile   **/
  539.                 /** values or BACKWARDS to LOWER     **/
  540.                 /** tile values.                     **/
  541.  
  542.                 /**  SEE[ #CONSISTENT_VOXEL_COORDS# **/
  543.                 F32  b_x  /** x_bound       **/     ;  
  544.                 F32  b_y  /** y_bound       **/     ;  
  545.                 F32  b_z  /** z_bound       **/     ;  
  546.                           /**               **/     ;
  547.                 F32  x_0  /** x_bound : MIN **/     ;  
  548.                 F32  y_0  /** y_bound : MIN **/     ;  
  549.                 F32  z_0  /** z_bound : MIN **/     ;  
  550.                           /**               **/     ;
  551.                 F32  x_1  /** x_bound : MAX **/     ;  
  552.                 F32  y_1  /** y_bound : MAX **/     ;  
  553.                 F32  z_1  /** z_bound : MAX **/     ;  
  554.                                                     ;
  555.                 x_1 =F32( ( T_X +  1 ) * NPX )      ;
  556.                 y_1 =F32( ( T_Y +  1 ) * NPY )      ;
  557.                 z_1 =F32( ( T_Z +  1 ) * NPZ )      ;
  558.                                                     ;
  559.                 x_0 =F32( ( T_X +  0 ) * NPX )- 1.0 ;
  560.                 y_0 =F32( ( T_Y +  0 ) * NPY )- 1.0 ;
  561.                 z_0 =F32( ( T_Z +  0 ) * NPZ )- 1.0 ;
  562.                                                     ;
  563.                 b_x = N.x >= 0.0 ? x_1 : x_0        ;
  564.                 b_y = N.y >= 0.0 ? y_1 : y_0        ;
  565.                 b_z = N.z >= 0.0 ? z_1 : z_0        ;
  566.  
  567.                 //:--------------:SIGNS_OF_RAY_VECTOR://
  568.                 /** ******************************** ***
  569.                 SEE[ #NEXT_VOXEL_BOUNDING_VOLUME# ]    
  570.                 The intersection point to next voxel    
  571.                 (By using plane intersections) should  
  572.                 not be further than ONE PIXEL away      
  573.                 from the current voxel we are inside.  
  574.            
  575.                 +----------------+----------------+
  576.                 | +- - -  - - -+ | +- - -  - - -+ |
  577.                 | |            | | |            | |
  578.                 |                |                |
  579.                 | |            | | |            | |
  580.                 |                |                |
  581.                 | |            | | |            | |
  582.                 | +- - -  - - -+ | +- - -  - - -+ |
  583.                 +----------------+----------------+
  584.                 | +- - -  - - -+ | +- - -  - - -+ |
  585.                 | |            | | |            | |
  586.                 |                |                |
  587.                 | |     CV     | | |            | |
  588.                 |   (CurVoxel)   |                |
  589.                 | |            | | |            | |
  590.                 | +- - -  - - -+ | +- - -  - - -+ |
  591.                 +----------------+----------------+
  592.  
  593.                 *** ******************************** **/
  594.                 /** ******************************** ***
  595.                 ___ == DONT CARE ABOUT
  596.                 P   + (N   * S   )==[ b_x, ___ , ___ ]
  597.                 P.x + (N.x * S.x )==  b_x
  598.                       (N.x * S.x )==  b_x - P.x
  599.                              S.x  == (b_x - P.x) / N.x
  600.                 *** ******************************** **/
  601.                 //:FIRST_PIXEL_OF_NEXT_VOXEL:--------://
  602.                 #define N_X ( 0.0 != N.x )
  603.                 #define N_Y ( 0.0 != N.y )
  604.                 #define N_Z ( 0.0 != N.z )
  605.  
  606.                 //:Scalar for point normal form.
  607.              //:F32 MAX_F32=intBitsToFloat(0x7f7fFFFF);
  608.              //:F32 MAX_F32=F32( 2147483647 );
  609.                 F32 MAX_F32=F32( 1000 * 1000 );
  610.                 V_3 S = V_3(MAX_F32,MAX_F32,MAX_F32);
  611.                 //:V_3 S = V_3( 0,0,0 );
  612.  
  613.                 if( N_X ){ S.x = ( b_x - P.x ) / N.x; };
  614.                 if( N_Y ){ S.y = ( b_y - P.y ) / N.y; };
  615.                 if( N_Z ){ S.z = ( b_z - P.z ) / N.z; };
  616.    
  617.                 /** #TRAP_VALUE_MUST_BE_NEG_666# **/
  618.                 #define _666_ ( 0.0 - 666.0  )
  619.                 F32 shortest_scalar_distance=( _666_ );
  620.                 V_3 first_pixel_of_next_voxel;
  621.                 #undef  _666_
  622.  
  623.                 if( N_X && S.x <= S.y && S.x <= S.z ){
  624.                     shortest_scalar_distance=(  S.x );
  625.                 }else
  626.                 if( N_Y && S.y <= S.x && S.y <= S.z ){
  627.                     shortest_scalar_distance=(  S.y );
  628.                 }else
  629.                 if( N_Z && S.z <= S.x && S.z <= S.y ){
  630.                     shortest_scalar_distance=(  S.z );
  631.                 };;
  632.  
  633.                 /** Not using this anywhere, BUT KEEP**/
  634.                 /** for now. Now is not the time     **/
  635.                 /** to optimize.                     **/
  636.                 first_pixel_of_next_voxel=(
  637.                 //: P + ( N * [ S.x | S.y | S.z ] )
  638.                     P + ( N * shortest_scalar_distance )
  639.                 );;
  640.  
  641.                 vox_000.vod.dis_nex=(
  642.                         shortest_scalar_distance );;
  643.  
  644.                 //:vox_000.vod.dis_nex=( 8.0 );
  645.  
  646.                 #undef  N_X  
  647.                 #undef  N_Y  
  648.                 #undef  N_Z  
  649.                 //:--------:FIRST_PIXEL_OF_NEXT_VOXEL://
  650.  
  651.            
  652.             #undef  P /** Point  **/
  653.             #undef  N /** Normal **/
  654.             //:-------------------:DIST_TO_NEXT_VOXEL://
  655.          
  656.             return( vox_000 );
  657.         }
  658.         #undef  T_X
  659.         #undef  T_Y
  660.         #undef  T_Z
  661.     //:=====================:FIRST_VOXEL_QUERY_NEEDED://
  662.     //:MARCH_INTO_VOXEL:=============================://
  663.     VOX_MAR sdf_MarchIntoVoxel(
  664.         VOX_000 vox_000
  665.     ,   V_3     xyz
  666.     ,   V_3     rwN
  667.     )
  668.     {
  669.  
  670.         VOX_MAR vox_mar;
  671.         vox_mar.exit=U32( 1 );
  672.  
  673.  
  674.         return( vox_mar );
  675.     }
  676.     //:=============================:MARCH_INTO_VOXEL://
  677.     #define  F    float
  678.     #define  U    uint
  679.     #define _FF_  uint( 0xFF )
  680.  
  681.         V_4 u32_CTO_c4d(
  682.             U32 u32
  683.         ){
  684.             V_4
  685.             c4d = V_4( /** c4d:Color_4_Dimensional **/
  686.                 F( ( u32 >> U(24) ) & _FF_ ) / 255.0
  687.             ,   F( ( u32 >> U(16) ) & _FF_ ) / 255.0
  688.             ,   F( ( u32 >> U( 8) ) & _FF_ ) / 255.0
  689.             ,   F( ( u32 >> U( 0) ) & _FF_ ) / 255.0
  690.             );;
  691.             return( c4d );
  692.         }
  693.  
  694.     #undef  F  
  695.     #undef  U  
  696.     #undef _FF_
  697.     //:INTEGER_MODULO:===============================://
  698.  
  699.     #ifndef I32
  700.     #define I32 int
  701.     #endif
  702.  
  703.     #ifndef F32
  704.     #define F32 float
  705.     #endif
  706.  
  707.         /** PRIVATE: Called only by I32_MOD **/
  708.         I32 i32_mod_neg( I32 neg_a , I32 pos_d ){
  709.  
  710.             /** ************************************ ***
  711.             Function Calculates:
  712.            
  713.             FIXED: (d-1)-[ mod(abs(a)+1 , d) ]
  714.  
  715.             GOAL: Negatives keep exact same tiling
  716.                   pattern as the positives.
  717.  
  718.             IN : -6 -5 -4 -3 -2 -1  0 +1 +2 +3 +4 +5 +6
  719.             OUT:  2  3  0  1  2  3  0  1  2  3  0  1  2
  720.  
  721.             0123 -> 0123 -> 0123 -> 0123 -> 0123 -> ect
  722.  
  723.            
  724.  
  725.             *** ************************************ **/
  726.  
  727.             I32 pos_a = ( 0 - neg_a ) + 1;
  728.            
  729.             F32 A = F32( pos_a );
  730.             F32 D = F32( pos_d );
  731.            
  732.             //: GLSL_MODULUS_WITH_INTEGERS_FORMULA
  733.             //: WARD:Wholepart,All,Remainder,Divisor
  734.             int W = int(  trunc( A / (          D  )) );
  735.             int R = int(         A - ( F32(W) * D  )  );
  736.            
  737.             return( (pos_d-1) - R );
  738.         }
  739.  
  740.         I32
  741.         I32_MOD(
  742.         /**/I32 a /** ALL     : CAN BE NEGATIVE **/
  743.         ,   I32 d /** DIVISOR : ALWAYS POSITIVE **/
  744.         ){
  745.  
  746.             /** ************************************ ***
  747.  
  748.             Allow for I32_MOD to be used for wrapping
  749.             even when the input to wrap[ a ] goes
  750.             negative. d should always be positive.
  751.  
  752.             EX: mod( x , 2 ) , where x == -1
  753.             | -1 | 0 [ 1 ] 2 |
  754.             |  1 | 0 [ 1 ] 0 | 1 | 0 |
  755.             d + 1 == 2 + (-1) == 1
  756.             *** ************************************ **/
  757.  
  758.             int R;
  759.  
  760.             if( a < 0 ){
  761.  
  762.                 //:This is CLOSE but then new problem
  763.                 //:of lots of green checkers is showing
  764.                 //:up. No clue...
  765.                 R = i32_mod_neg( a , d );
  766.  
  767.             }else{
  768.  
  769.                 F32 A = F32( a );
  770.                 F32 D = F32( d );
  771.                             //:<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<FIX_THE_OVERFLOW_BELOW
  772.                 //: GLSL_MODULUS_WITH_INTEGERS_FORMULA
  773.                 //: WARD:Wholepart,All,Remainder,Divisor
  774.                 int W = int(  trunc( A / (          D  )) );
  775.                     R = int(         A - ( F32(W) * D  )  );
  776.  
  777.             };;
  778.  
  779.             return( R );
  780.         }
  781.     //:===============================:INTEGER_MODULO://
  782. //:22222222222222222222222222222222222222222222222222://
  783. //:11111111111111111111111111111111111111111111111111://
  784.  
  785.     //:FRAGCOORD_TO_FRAGPERCENT:=====================://
  786.     //:f_c_CTO_f_p:==================================://
  787.  
  788.         V_2 f_c_CTO_f_p( V_2 f_c ){
  789.         V_2         f_p;
  790.             f_p = f_c / ( iResolution.xy - 1.0 );
  791.             return(  f_p );
  792.         }
  793.  
  794.     //:==================================:f_c_CTO_f_p://
  795.     //:=====================:FRAGCOORD_TO_FRAGPERCENT://
  796.     //:FRAGPER_TO_CAMERA_RAY:========================://
  797.     //:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP:==========://
  798.  
  799.                 RWC_AND_RWN
  800.         f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP(
  801.             V_2 f_p /** 2 dimensional percentage **/
  802.         )
  803.         {
  804.             F32 bug = ( F32(NPZ) * 4.0 ); //:DEBUG_ONLY
  805.             F32 spd     =( 0.5 /**SPEED FACTOR **/ );
  806.             F32 pos_cos =( cos(iTime*spd)+1.0 ) / 2.0;
  807.             F32 neg_cos =( cos(iTime*spd)-1.0 ) / 2.0;
  808.             bug=bug*pos_cos;
  809.             //:bug = ( (-16.1) * bug );
  810.             //:bug = ( -1036.8 );
  811.             //:bug=( -32.2   );
  812.  
  813.             /** ************************************ ***
  814.             TODO: Fix bug...
  815.                 bug=( -   0.2 ); <<<<< OK
  816.                 bug=( -  16.2 ); <<<<< OK
  817.                 bug=( -  32.2 ); <<<<< ERR
  818.                 bug=( -  48.2 ); <<<<< OK
  819.                 bug=( -  64.2 ); <<<<< ERR
  820.                 bug=( -  80.2 ); <<<<< OK
  821.                 bug=( -  96.2 ); <<<<< ERR
  822.                 bug=( - 112.2 ); <<<<< OK
  823.                 bug=( - 128.2 ); <<<<< ERR
  824.                 bug=( -1036.8 );
  825.  
  826.             *** ************************************ **/
  827.          
  828.             V_3 rwC; //:ray_word__COORDINATE
  829.             V_3 rwN; //:ray_world_NORMAL____
  830.  
  831.             //:#FIND_POINT_ON_SCREEN_PLANE#
  832.             F32 H = F32( 0 - 9 );; //:Cam Height Pos
  833.             F32 X = iResolution.x - 1.0;
  834.             F32 Y = iResolution.y - 1.0;
  835.             /** ************************************ ***
  836.                             A_B
  837.                         A----|------B
  838.                         |    |      |
  839.                         |   rwC     |
  840.                         |    |      |
  841.                         C----|------D
  842.                             C_D
  843.                                
  844.             *** ************************************ **/
  845.  
  846.             F32  _ =F32( 0.0 /**ALWAYS_ZERO **/ );
  847.             F32 XOS=F32( 0 );
  848.             F32 YOS=F32( 0 );
  849.             F32 ZOS=F32( 0 );
  850.  
  851.             V_3 _A_ = V_3( _+XOS,_+YOS,  bug+H+ZOS );  
  852.             V_3 _B_ = V_3( X+XOS,_+YOS,  bug+H+ZOS );  
  853.                                      
  854.             V_3 _C_ = V_3( _+XOS,Y+YOS,  bug+H+ZOS );  
  855.             V_3 _D_ = V_3( X+XOS,Y+YOS,  bug+H+ZOS );  
  856.                                      
  857.  
  858.             V_3 A_B = sdf_i3d( _A_ , _B_ , f_p.x );
  859.             V_3 C_D = sdf_i3d( _C_ , _D_ , f_p.x );
  860.                 rwC = sdf_i3d( A_B , C_D , f_p.y );
  861.  
  862.                 //:#POSITIVE_Z_DIVES_INTO_SCREEN#://
  863.                 rwN = normalize( V_3( 0 , 0 , 1 ) );
  864.  
  865.                     RWC_AND_RWN
  866.                     rwC_AND_rwN;
  867.                     rwC_AND_rwN.rwC = rwC;
  868.                     rwC_AND_rwN.rwN = rwN;
  869.             return( rwC_AND_rwN );
  870.         }
  871.  
  872.     //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP://
  873.     //:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D:==========://
  874.     #define _0_  (0.0)
  875.     #define  _   (0.0)
  876.  
  877.                 RWC_AND_RWN
  878.         f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D(
  879.             V_2 f_p /** 2 dimensional percentage **/
  880.         )
  881.         {
  882.             RWC_AND_RWN  /** OUTPUT_OBJECT **/
  883.             rwC_AND_rwN; /** OUTPUT_OBJECT **/
  884.  
  885.             V_3 rwC; //:ray_word__COORDINATE
  886.             V_3 rwN; //:ray_world_NORMAL____
  887.  
  888.             //:#FIND_POINT_ON_SCREEN_PLANE#
  889.             /** ************************************ ***
  890.             Could possibly use these as slice planes.
  891.             But for now using these to navigate our
  892.             voxel map bounds.
  893.  
  894.             [ A ]Is_Directly_Above[ E ]On_Z_Axis
  895.             [ B ]Is_Directly_Above[ F ]On_Z_Axis
  896.             [ C ]Is_Directly_Above[ G ]On_Z_Axis
  897.             [ D ]Is_Directly_Above[ H ]On_Z_Axis
  898.            
  899.                         (In World/Frag Coords)
  900.                             [0,0,0]
  901.                                 \
  902.                 A_B              \
  903.             A----|------B  A -->  +=======+  <-- B
  904.             |    |      |        /.       .\
  905.             | rwC_001   |       / .       . \
  906.             |    |      |      /  .       .  \
  907.             C----|------D  C->+===============+<-D
  908.                 C_D           [   ._....._.   ]
  909.                               [  /         \  ]
  910.                               [ .           . ]
  911.                               [/             \]
  912.                               +===============+<-H
  913.  
  914.                               +===============+  
  915.                               [\             /]
  916.                               [ .           . ]
  917.                               [  \_......._/  ]
  918.                 E_F           [   .       .   ]
  919.             E----|------F  G->+===============+<-H
  920.             |    |      |      \  .       .  /
  921.             | rwC_002   |       \ .       . /
  922.             |    |      |        \.       ./
  923.             G----|------H  E -->  +=======+  <-- F
  924.                 G_H          
  925.                            
  926.             *** ************************************ **/
  927.  
  928.             //:Dimensions Of Voxel Volume:
  929.             //:As maximum indexes.
  930.             F32 M_X =( F32(TPX) - 1.0 );
  931.             F32 M_Y =( F32(TPY) - 1.0 );
  932.             F32 M_Z =( F32(TPZ) - 1.0 );
  933.  
  934.             //:TOP LAYER OF PIXELS OF VOXEL VOLUME:
  935.             //:(INCLUSIVE MATH. We are inside the)
  936.             //:(first layer of pixels of the first)
  937.             //:(layer of voxels)
  938.             V_3 _A_ = V_3( _-_ , _-_ , _-_ );
  939.             V_3 _B_ = V_3( M_X , _-_ , _-_ );      
  940.             V_3 _C_ = V_3( _-_ , M_Y , _-_ );
  941.             V_3 _D_ = V_3( M_X , M_Y , _-_ );
  942.  
  943.             //:BOTTOM LAYER OF PIXELS OF VOXEL VOLUME
  944.             //:(Incluseive Math. We are inside the )
  945.             //:(last layer of pixels of the last   )
  946.             //:(layer of voxels.                   )
  947.             V_3 _E_ = V_3( _-_ , _-_ , M_Z );
  948.             V_3 _F_ = V_3( M_X , _-_ , M_Z );      
  949.             V_3 _G_ = V_3( _-_ , M_Y , M_Z );
  950.             V_3 _H_ = V_3( M_X , M_Y , M_Z );
  951.  
  952.             /** ************************************ ***
  953.             Take our plane and pretend it is
  954.             the top of a cube that we want to
  955.             get plane in an isometric position to.
  956.             Where the new plane tangents corner _D_
  957.            
  958.            
  959.                    A------_B_            vec_D_B
  960.                   /|       \\                  \
  961.                  / |       |\\                  \
  962.                 /  |       | \\      vec_D_C <---D
  963.               _C_============_D_                 ^
  964.                |   |_ _ _ _|  ||                 |
  965.                |  /E       F\ ||            vec_H_D
  966.                | /           \||
  967.                |/             ||     Corner_Vector:
  968.                G-------------_H_  
  969.             *** *** * * * * * * **** * * * * * * *** **/
  970.  
  971.             /** Edge Vectors **/
  972.  
  973.             V_3 vec_C_D = normalize( _D_ - _C_ );
  974.             V_3 vec_D_C = normalize( _C_ - _D_ );
  975.             V_3 vec_D_B = normalize( _B_ - _D_ );
  976.             V_3 vec_H_D = normalize( _D_ - _H_ );
  977.             V_3 vec_D_H = normalize( _H_ - _D_ );
  978.  
  979.             /** *** * * * * * * **** * * * * * * *** ***
  980.             Use Corner_Vector to calculate a 3/4        
  981.             perspective plane that tangents _D_.
  982.             *** ************************************ **/
  983.             /** ************************************ ***
  984.    
  985.             X axis vector is pretty easy because the
  986.             camera X axis does not move in the Z
  987.             direction.
  988.                     ^         /
  989.                     |       /    ^
  990.             A-------B     /      |    a_x Is Average
  991.             |       |   /        |  
  992.             |       | /     vec_D_B
  993.             C-------D-->    vec_C_D ----->
  994.                   /
  995.                 /
  996.               /<-- goal is THIS line for X-axis.(a_x)
  997.             /
  998.             *** *** * * * * * * **** * * * * * * *** **/
  999.             #define _X_ vec_C_D
  1000.             #define _Y_ vec_D_B
  1001.             V_3 a_x =normalize(
  1002.  
  1003.                 /** 45 degree line on XY plane **/
  1004.                 ( _X_ + _Y_ ) / 2.0  
  1005.  
  1006.             );;
  1007.             #undef  _X_
  1008.             #undef  _Y_
  1009.             /** *** * * * * * * **** * * * * * * *** ***
  1010.            
  1011.             Y axis vector is a bit tricky because it
  1012.             moves on all axis(es). XYZ.
  1013.  
  1014.             +--B  If we average vec_D_C & vec_D_B
  1015.             |\ |  To get a 45 degree on the XY plane,
  1016.             | \|  we can then tilt that vector up
  1017.             C--D  by 45 degrees by averaging it
  1018.                |  with vec_H_D
  1019.                |
  1020.                H
  1021.  
  1022.             *** ************************************ **/
  1023.  
  1024.             //: a_y: Axis_Y
  1025.             #define _X_ vec_D_C
  1026.             #define _Y_ vec_D_B
  1027.             #define _Z_ vec_H_D
  1028.             V_3 a_y =normalize(
  1029.  
  1030.                 (
  1031.                     normalize( (_X_ + _Y_)/2.0 )
  1032.                     +        (     _Z_         )
  1033.                 ) /2.0
  1034.             );;
  1035.             #undef  _X_
  1036.             #undef  _Y_
  1037.             #undef  _Z_
  1038.  
  1039.            
  1040.             /** Looking into the voxel volume from   **/
  1041.             /** a 3/4 isometric direction.           **/
  1042.             V_3 a_z = normalize(
  1043.                 ( vec_D_C + vec_D_B + vec_D_H ) / 3.0
  1044.             );;
  1045.  
  1046.             /** ************************************ ***
  1047.  
  1048.             We can now use point-normal form to
  1049.             build our camera polygon. We will start
  1050.             from point _D_ and walk HALFWAY the
  1051.             WIDTH in both directions on our altered
  1052.             x-axis vector( a_x ) and HALFWAY the
  1053.             HEIGHT in both directions on our altered
  1054.             y-axis vector( a_y ).
  1055.  
  1056.             HEIGHT: The height of our camera plane.
  1057.              WIDTH: The width  of our camera plane.
  1058.  
  1059.                       P_X                   +---+
  1060.                 +------+------+             |   |
  1061.                 |      |      |         +---+---+
  1062.             N_Y +---- _D_ ----+ P_Y     |_D_|
  1063.                 |      |      |     +---+---+
  1064.                 +------+------+     |   |#DIA_CAMCENTER#
  1065.                       N_X           +---+
  1066.  
  1067.                 #CAMCENTER#:
  1068.                 In order for the camera to be 100%
  1069.                 centered, it may be necessary to
  1070.                 squash or stretch the camera by 1
  1071.                 pixel IF the camera is NOT an odd
  1072.                 number of pixels on that axis.
  1073.                 SEE_DIAGRAM[ #DIA_CAMCENTER# ]
  1074.  
  1075.                     +0 +1 +2 +2.5       +0 +1 +2 +3  
  1076.                     [D]   [+]           ||     [+]    
  1077.                 [ ][ ][ ][ ][ ]   [ ][ ][ ][ ][ ][ ]  
  1078.                 |<---- 5 ---->|   |<------ 6 ----->|  
  1079.  
  1080.             *** ************************************ **/
  1081.  
  1082.             #define ZOOMED_IN_CAMERA_2020_11_26 ( 1 )
  1083.             float H_W ;
  1084.             float H_H ;
  1085.             if( ZOOMED_IN_CAMERA_2020_11_26 >= 1 ){
  1086.    
  1087.                 /** Camera surface smaller than      **/
  1088.                 /** client viewport means zoomed in  **/
  1089.                 H_W = ( F32(TPX) / 2.0 );
  1090.                 H_H = ( F32(TPY) / 2.0 );
  1091.  
  1092.             }else
  1093.             if( ZOOMED_IN_CAMERA_2020_11_26 <= 0 ){
  1094.  
  1095.                 /** Camera surface exactly same size **/
  1096.                 /** as client viewport means no zoom.**/
  1097.                 H_W = ( iResolution.x / 2.0 );
  1098.                 H_H = ( iResolution.y / 2.0 );
  1099.  
  1100.             };;
  1101.             #undef  ZOOMED_IN_CAMERA_2020_11_26
  1102.  
  1103.             /** To be pixel-perfect, floor and ceil  **/
  1104.             /** need to be used. This is an OCD      **/
  1105.             /** optimization that can probably       **/
  1106.             /** be removed without noticable         **/
  1107.             /** difference in the result.            **/
  1108.             //- P_X = floor( _D_ + ( a_x * H_W ) );  -//
  1109.             //- N_X =  ceil( _D_ - ( a_x * H_W ) );  -//
  1110.             //- P_Y = floor( _D_ + ( a_y * H_H ) );  -//
  1111.             //- N_Y =  ceil( _D_ - ( a_y * H_H ) );  -//
  1112.             //+ We can't do it this way, because the +//
  1113.             //+ plane is not aligned with our native +//
  1114.             //+ XYZ axis.                            +//
  1115.             //+ What I mean is we can't get the top  +//
  1116.             //+ left corner by saying:               +//
  1117.             //+ vec3( N_Y.x , P_X.y , _D_.z )        +//
  1118.             /** ************************************ ***
  1119.             RASTER_GRAPHICS_STYLE_TOP_LEFT_ORIGIN
  1120.                \
  1121.                 +----------- +X ------------>
  1122.                 |    
  1123.                 |     _I_              _J_
  1124.                 |       \      P_X      /  
  1125.                 |        +------+------+        ^
  1126.                 |        |      |      |        |
  1127.                +Y    N_Y +---- _D_ ----+ P_Y [ -y ]
  1128.                 |        |      |      |        |
  1129.                 |        +------+------+        |
  1130.                 |       /      N_X      \       |
  1131.                 V     _K_               _L_     |
  1132.                                                 |
  1133.                     <---------[ -x ]------------+
  1134.  
  1135.             *** *** * * * * * * **** * * * * * * *** **/
  1136.    
  1137.             V_3 _I_ = _D_  - ( a_x * H_W )
  1138.                            - ( a_y * H_H ) ;;
  1139.  
  1140.             V_3 _J_ = _D_  + ( a_x * H_W )
  1141.                            - ( a_y * H_H ) ;;
  1142.  
  1143.             V_3 _K_ = _D_  - ( a_x * H_W )
  1144.                            + ( a_y * H_H ) ;;
  1145.  
  1146.             V_3 _L_ = _D_  + ( a_x * H_W )
  1147.                            + ( a_y * H_H ) ;;
  1148.                    
  1149.             /** ************************************ **/
  1150.             #define USE_ANIMATED_DOLLY_FOR_DEBUG  ( 1 )
  1151.             if(     USE_ANIMATED_DOLLY_FOR_DEBUG >= 1 ){
  1152.  
  1153.                 F32 max_dolly =max(
  1154.                             F32(TPX)
  1155.                 ,
  1156.                         max(
  1157.                             F32(TPY)
  1158.                             ,
  1159.                             F32(TPZ)
  1160.                         )
  1161.                 );;
  1162.  
  1163.                 F32 pos_cos=( (cos(iTime)/2.0)+0.5 );
  1164.                 F32 neg_cos=( (cos(iTime)/2.0)-0.5 );
  1165.  
  1166.                 F32 dolly_amount =(
  1167.                     pos_cos * max_dolly
  1168.                 );;
  1169.                
  1170.                 _I_ += ( a_z * dolly_amount );
  1171.                 _J_ += ( a_z * dolly_amount );
  1172.                 _K_ += ( a_z * dolly_amount );
  1173.                 _L_ += ( a_z * dolly_amount );
  1174.  
  1175.             };;
  1176.             #undef  USE_ANIMATED_DOLLY_FOR_DEBUG
  1177.            
  1178.             V_3 I_J = sdf_i3d( _I_ , _J_ , f_p.x );
  1179.             V_3 K_L = sdf_i3d( _K_ , _L_ , f_p.x );
  1180.                 rwC = sdf_i3d( I_J , K_L , f_p.y );
  1181.  
  1182.                 //:#POSITIVE_Z_DIVES_INTO_SCREEN#://
  1183.                 rwN = normalize( a_z );
  1184.  
  1185.                     rwC_AND_rwN.rwC = rwC;
  1186.                     rwC_AND_rwN.rwN = rwN;
  1187.             return( rwC_AND_rwN );
  1188.         }
  1189.     #undef  _0_
  1190.     #undef   _
  1191.     //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D://
  1192.     //:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ:==========://
  1193.  
  1194.                 RWC_AND_RWN
  1195.         f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ(
  1196.             V_2 f_p /** 2 dimensional percentage **/
  1197.         )
  1198.         {
  1199.             RWC_AND_RWN
  1200.             rwC_and_rwN;
  1201.  
  1202.             //:TODO: Logic.
  1203.  
  1204.             return( rwC_and_rwN );
  1205.  
  1206.         }
  1207.  
  1208.     //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ://
  1209.     //:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ:==========://
  1210.  
  1211.                 RWC_AND_RWN
  1212.         f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ(
  1213.             V_2 f_p /** 2 dimensional percentage **/
  1214.         )
  1215.         {
  1216.             RWC_AND_RWN
  1217.             rwC_and_rwN;
  1218.  
  1219.             //:TODO: Logic.
  1220.  
  1221.             return( rwC_and_rwN );
  1222.  
  1223.         }
  1224.  
  1225.     //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ://
  1226.     //:f_p_CTO_rwC_AND_rwN:==========================://
  1227.     #define ogp_top f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP
  1228.     #define ogp_34d f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D
  1229.     #define t3o_aaz f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ
  1230.     #define t3i_aaz f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ
  1231.  
  1232.                 RWC_AND_RWN
  1233.         f_p_CTO_rwC_AND_rwN(
  1234.             V_2 f_p /** 2 dimensional percentage **/
  1235.         )
  1236.         {
  1237.             RWC_AND_RWN
  1238.             rwC_and_rwN;
  1239.  
  1240.             switch( CAMTYPE ){
  1241.  
  1242.                 case          OGP_TOP :
  1243.                 rwC_and_rwN = ogp_top( f_p ); break;
  1244.  
  1245.                 case          OGP_34D :
  1246.                 rwC_and_rwN = ogp_34d( f_p ); break;
  1247.  
  1248.                 case          T3O_AAZ :
  1249.                 rwC_and_rwN = t3o_aaz( f_p ); break;
  1250.  
  1251.                 case          T3I_AAZ :
  1252.                 rwC_and_rwN = t3i_aaz( f_p ); break;
  1253.            
  1254.                 default : /** OGP_TOP **/
  1255.                 rwC_and_rwN = ogp_top( f_p ); break;
  1256.  
  1257.             };;  
  1258.  
  1259.             return( rwC_and_rwN );
  1260.         }
  1261.  
  1262.     #undef  ogp_top  
  1263.     #undef  ogp_34d  
  1264.     #undef  t3o_aaz  
  1265.     #undef  t3i_aaz  
  1266.     //:==========================:f_p_CTO_rwC_AND_rwN://
  1267.     //:========================:FRAGPER_TO_CAMERA_RAY://
  1268.     //:RENDER_SCENE:=================================://
  1269.     //:sdf_RenderScene:==============================://
  1270.     #define T_X vox_000.voc.t_x
  1271.     #define T_Y vox_000.voc.t_y
  1272.     #define T_Z vox_000.voc.t_z
  1273.     #define HAS vox_000.voc.has
  1274.     #define VAL vox_000.voc.val
  1275.     #define D_N vox_000.vod.dis_nex
  1276.  
  1277.         V_4 sdf_RenderScene( RWC_AND_RWN rwC_AND_rwN )
  1278.         {
  1279.             I32 o_k = I32( 1 );
  1280.             V_4 c4d = THE_COLOR_OF_EMPTY_SPACE ;
  1281.  
  1282.             V_3 rwN = rwC_AND_rwN.rwN;
  1283.             V_3 rwC = rwC_AND_rwN.rwC;
  1284.  
  1285.             V_3 xyz = rwC;
  1286.             F32 xyz_TDF_rwC=(0.0);
  1287.             /** xyz_total_distance_from_rwC **/
  1288.          
  1289.             VOX_000
  1290.             vox_000;
  1291.  
  1292.             VOX_MAR vox_mar;
  1293.  
  1294.             //:dis_nex: Distance To NEXT voxel.
  1295.             //:dis_sur: Distance To Surface Geometry inside
  1296.             //:     the current voxel. In world coords.
  1297.             vox_000.vod.dis_nex =( 0.0 );  
  1298.         //: vox_000.vod.dis_sur =( 0.0 );  
  1299.  
  1300.             //:Voxels will be thought of as 3D tiles:
  1301.             vox_000.voc.has = uint( 0 ); // :1: //
  1302.             vox_000.voc.val = uint( 0 ); // :2: //
  1303.             vox_000.voc.dex =  int( 0 ); // :3: //
  1304.             vox_000.voc.t_x =  int( 0 ); // :4: //
  1305.             vox_000.voc.t_y =  int( 0 ); // :5: //
  1306.             vox_000.voc.t_z =  int( 0 ); // :6: //
  1307.  
  1308.             //:RAY_MARCH_LOOP:-----------------------://
  1309.             /** #ABOUT_RAY_MARCH_LOOP# **/
  1310.  
  1311.                 //:(RayMarch)March to VOXEL:
  1312.                 for( int i = 0; i < MAX_STE ; i++ ){
  1313.  
  1314.                     //:March by distance to next voxel:
  1315.                    
  1316.                     //:Point_Normal_Form_To_Get:xyz
  1317.                     //:#DISTANCE_IS_NOT_CUMULATIVE#
  1318.                     rwN=normalize(rwN); //:TEMP_DEBUG
  1319.                     xyz =  xyz + ( rwN * (D_N+0.0) );;
  1320.                 //: xyz =  xyz + ( rwN * -8.0 );
  1321.  
  1322.                     /** B4 : GET_vox_000_USE_xyz_rwN **/
  1323.                     xyz_TDF_rwC += D_N;
  1324.                     if( xyz_TDF_rwC > MAX_DIS ){break;};
  1325.                
  1326.                         vox_000 =
  1327.                     GET_vox_000_USE_xyz_rwN(
  1328.                                     xyz,rwN );;
  1329.  
  1330.                     //:if( D_N <= 0.0 we have trouble )
  1331.                     F32 MF3=intBitsToFloat(0x7f7fFFFF);
  1332.                     if( 0.0 - 666.0 == D_N ){
  1333.  
  1334.                         /** Exit On Error            **/
  1335.                         /** #DIST_NEXT_NEVER_ZERO#   **/
  1336.                         c4d=PIX_ERR(ERR_003,c4d,o_k--);
  1337.                         break;
  1338.  
  1339.                     }else
  1340.                     if( vox_000.vod.dis_nex <= 0.0 ){
  1341.                         //:PULSING:ORANGE:VIA:POS_COS:
  1342.                         F32 p_c=((cos(iTime)+1.0)/2.0);
  1343.                         c4d=V_4(V_3(1,0.5,0)*p_c,1.0);
  1344.                         break;
  1345.                     }else
  1346.                     if( D_N == MF3 /** MaxFloat32 **/ ){
  1347.                         F32 p_c=((cos(iTime)+1.0)/2.0);
  1348.                         c4d=V_4(V_3(1,0.5,1)*p_c,1.0);
  1349.                         break;
  1350.                     }else
  1351.                     if( isinf( D_N ) ){
  1352.                         c4d=u32_CTO_c4d(U32(
  1353.                                     0xE0E0E0FF ));
  1354.                     };;
  1355.  
  1356.                     //:If voxel is not empty, ray march
  1357.                     //:inside of the voxel.
  1358.                     #define _0_ U32( 0 ) //:#########://
  1359.  
  1360.                     if( HAS > _0_ && _0_ == VAL ){
  1361.  
  1362.                         //:EMPTY_TILE_INSIDE_MAP_BOUNDS:
  1363.                         c4d=u32_CTO_c4d(U32(
  1364.                                     0x003300FF ));
  1365.  
  1366.                     }else
  1367.                     if( _0_ == HAS ){
  1368.  
  1369.                         //:OUT_OF_MAP_BOUNDS:
  1370.                     //  c4d=u32_CTO_c4d(U32(
  1371.                     //              0x330011FF ));
  1372.    
  1373.                         xyz_TDF_rwC=(length(xyz - rwC));
  1374.                         F32 per=(xyz_TDF_rwC / MAX_DIS);
  1375.                         F32 inv=( 1.0 - per );
  1376.  
  1377.                         c4d=V_4( V_3(1)*(inv) , 1.0 );
  1378.  
  1379.                     }else
  1380.                     if( HAS > _0_ && VAL > _0_  ){
  1381.    
  1382.                         vox_mar =(
  1383.                         sdf_MarchIntoVoxel(
  1384.                             vox_000,xyz,rwN
  1385.                         ));;
  1386.                        
  1387.                         /*[FIX]: ALWAYS RETURNS EXIT */
  1388.                         if( vox_mar.exit >= U32(1) ){
  1389.                        
  1390.                             c4d=( u32_CTO_c4d(
  1391.                             vox_000.voc.val ) );;
  1392.                        
  1393.                             break;
  1394.                         };;
  1395.  
  1396.                     }else{
  1397.  
  1398.                         //:SHOULD_NEVER_EXECUTE:
  1399.                         c4d=V_4(1,0,0,1);
  1400.  
  1401.                     };;
  1402.  
  1403.                     #undef  _0_  //:#################://
  1404.  
  1405.                     /** Don't move the ray anywhere  **/
  1406.                     /** We are going to slice into   **/
  1407.                     /** whatever voxels the camera   **/
  1408.                     /** plane passes through.        **/
  1409.                     if( CFG_SLICE_RENDER >= 1 ){
  1410.                         break;
  1411.                     };;
  1412.  
  1413.                 };;
  1414.  
  1415.             //:-----------------------:RAY_MARCH_LOOP://
  1416.  
  1417.  
  1418.             if( CFG_SLICE_RENDER >= 1 ){
  1419.  
  1420.                 //:Layer value, 1 or 0
  1421.                 int lay = I32_MOD( T_Z, 2 );
  1422.                
  1423.                 //:#MODULO_CHECKER_PATTERN#://
  1424.                 int chk =(  
  1425.                     I32_MOD( //:<<<<<<<<<<<<<<:SET_003
  1426.                         I32_MOD( T_Y, 2 )   //:SET_YYY
  1427.                     +   I32_MOD( T_X, 2 )   //:SET_XXX
  1428.                     ,                 2
  1429.                     )
  1430.                 );;
  1431.            
  1432.                 if(   0 != 0
  1433.                 || ( lay < 0 )
  1434.                 || ( lay > 1 )
  1435.                 || ( chk < 0 || chk > 1 )
  1436.                 || ( HAS > uint(1)      )
  1437.                 ){
  1438.                     //: _0x010101_ & _0x101010_
  1439.                     c4d=PIX_ERR(ERR_001,c4d,o_k--);
  1440.                 };;
  1441.  
  1442.                
  1443.                 F32 M =( 255.0); //:Max RGB value.
  1444.                 F32 X =( 1.0  ); //:FOR_DEBUGGING_COLORS
  1445.              //:F32 ...........;    Replace with "_"
  1446.              //:F32 ...........;    when done debugging.
  1447.                 F32 a =( 1.0  ); //:ALPHA
  1448.                 F32 _ =( 0.0  );
  1449.                 F32 g =( F32(0x33)/M ); //:DARK-GREY
  1450.                 F32 G =( F32(0x38)/M );
  1451.                 F32 w =( F32(0xE5)/M ); //:WHITE-GREY
  1452.                 F32 W =( F32(0xF2)/M );
  1453.  
  1454.                 V_4 _0x333333_ =V_4(g,g,g,a);
  1455.                 V_4 _0x383838_ =V_4(G,G,G,a);
  1456.                 V_4 _0xE5E5E5_ =V_4(w,w,w,a);
  1457.                 V_4 _0xF2F2F2_ =V_4(W,W,W,a);
  1458.                 V_4 _0x003300_ =V_4(_,g,_,a);
  1459.                 V_4 _0x003800_ =V_4(_,G,_,a);
  1460.                 V_4 _0x00E500_ =V_4(_,w,_,a);
  1461.                 V_4 _0x00F200_ =V_4(_,W,_,a);
  1462.  
  1463.                 V_4 tab_000[8]=V_4[8](
  1464.                     //:OUT OF BOUNDS:       //:HAS?
  1465.                     _0x333333_ , _0x383838_ //:LAY0
  1466.                    ,_0xE5E5E5_ , _0xF2F2F2_ //:LAY1
  1467.                 //: |   CHK0   |     CHK1   |::::::::://
  1468.                                    
  1469.                     //:IN BOUNDS:           //:HAS?
  1470.                    ,_0x003300_ , _0x003800_ //:LAY0
  1471.                    ,_0x00E500_ , _0x00F200_ //:LAY1
  1472.                 //: |   CHK0   |     CHK1   |::::::::://
  1473.                 );;
  1474.                
  1475.                 I32 pik = (
  1476.                    (4 * ( HAS >= uint(1) ? 1 : 0 ))
  1477.                 +  (2 * lay ) //: LAY0 -or- LAY1
  1478.                 +  (1 * chk ) //: CHK0 -or- CHK1
  1479.                 );;
  1480.  
  1481.                 if( pik < 0 || pik >= 8 ){
  1482.                     c4d=PIX_ERR(ERR_002,c4d,o_k--);
  1483.                 };;
  1484.                
  1485.                 //:TODO: Why is not rendering as
  1486.                 //:      checker?
  1487.                 if( 1 == o_k ){
  1488.                     c4d = tab_000[ pik ];
  1489.                 };;
  1490.  
  1491.             }else{
  1492.                 //:DEBUG ONLY.
  1493.                 //:c4d=V_4(1,1,1,1);
  1494.             };;
  1495.  
  1496.             return( c4d );
  1497.         }
  1498.  
  1499.     #undef  T_X
  1500.     #undef  T_Y
  1501.     #undef  T_Z
  1502.     #undef  HAS
  1503.     #undef  VAL
  1504.     #undef  D_N
  1505.     //:==============================:sdf_RenderScene://
  1506.     //:=================================:RENDER_SCENE://
  1507.  
  1508. //:11111111111111111111111111111111111111111111111111://
  1509. //:00000000000000000000000000000000000000000000000000://
  1510.  
  1511.     void mainImage(
  1512.         out vec4 fragColor
  1513.     ,   in  V_2 fragCoord
  1514.     )
  1515.     {
  1516.            
  1517.         #define R_Y iResolution.y
  1518.             V_2 f_c = V_2(
  1519.             //:( FLIP? )       ( Discrete XY       ) ://
  1520.                (  0.0  )   +   ( fragCoord.x - 0.5 )
  1521.             ,  (R_Y-1.0)   -   ( fragCoord.y - 0.5 )
  1522.             );;
  1523.         #undef R_Y  
  1524.         V_2 f_p = f_c_CTO_f_p( f_c );
  1525.  
  1526.  
  1527.         //:CAMERA_RAY_FOR_CURRENT_PIXEL:-------------://
  1528.  
  1529.             /** The coordinate and direction of the  **/
  1530.             /** camera ray [rwC,rwN] are closely     **/
  1531.             /** related, so return them using the    **/
  1532.             /** same function. This will save        **/
  1533.             /** processing power when we decide      **/
  1534.             /** to create a camera lense that        **/
  1535.             /** is a 360 degree cylinder around      **/
  1536.             /** an object. (for fun)                 **/
  1537.  
  1538.             RWC_AND_RWN
  1539.             rwC_AND_rwN;
  1540.  
  1541.             rwC_AND_rwN = f_p_CTO_rwC_AND_rwN( f_p );
  1542.  
  1543.         //:-------------:CAMERA_RAY_FOR_CURRENT_PIXEL://
  1544.  
  1545.         fragColor = sdf_RenderScene( rwC_AND_rwN );
  1546.  
  1547.     }
  1548. //:00000000000000000000000000000000000000000000000000://
  1549. //:DOCUMENTATION:====================================://
  1550. /** ************************************************ ***
  1551.     ABBREVIATIONS:
  1552.  
  1553.         f : fragment
  1554.         p : percent (Never Position, use C for coord)
  1555.         c : coordinate
  1556.         r : ray
  1557.         n : normal, for directions.
  1558.         d : distance. NEVER DIRECTION.( use: n:normal )
  1559.        
  1560.     IDENTIFIERS:
  1561.  
  1562.         CTO: Convert_TO
  1563.         rwC: RayWorldCoord
  1564.         rwN: RayWorldNormal
  1565.         f_p: FragPercent
  1566.         f_c: FragCoord (With Discrete Pixel Coords)
  1567.                     (instead of pixel centers  )
  1568.         dad: Distance_And_inDEX
  1569.             Index is 1D index of XYZ voxel tile
  1570.             coordinate.
  1571.         vat: Voxel_Array__of__Tiles
  1572.         c4d: Color_4_Dimensional(RGBA)
  1573.  
  1574.     FUNCTIONS:
  1575.  
  1576.         f_c_CTO_f_p : FragmentCoord -CTO- FragPercent
  1577.         f_c_CTO_per : USE[ f_c_CTO_f_p ]
  1578.         sdf_i3d     : Interpolate_Two_3D_Points
  1579.  
  1580.     EXTRACTED_BLOCK_COMMENTS:
  1581.  
  1582.         #ABOUT_RAY_MARCH_LOOP###########################
  1583.  
  1584.             Ray marching loop should be able to look    
  1585.             at the current voxel coordinate returned    
  1586.             and decide to STOP marching if it wants.    
  1587.             By stopping immediately without marching    
  1588.             at all we can make the camera phosphore    
  1589.             surface a slice plane that renders          
  1590.             cross sectional views of tilemap data.      
  1591.    
  1592.         ##########################ABOUT_RAY_MARCH_LOOP##
  1593.         #POSITIVE_Z_DIVES_INTO_SCREEN###################
  1594.  
  1595.             Positive Z is further back into screen.
  1596.             This way to help normalize voxel grid math.
  1597.        
  1598.         ###################POSITIVE_Z_DIVES_INTO_SCREEN#
  1599.         #FIND_POINT_ON_SCREEN_PLANE#####################
  1600.  
  1601.             ORIGINAL_COMMENT:
  1602.  
  1603.                 Polygon in 3d space to serve as the
  1604.                 phosphor surface the CRT monitor
  1605.                 electrons will be projected onto.
  1606.                 Could probably use a mat4 for this.
  1607.  
  1608.             MORE_INFORMATION_IN_RETROSPECT:
  1609.  
  1610.                 "Screen Plane" is also known as
  1611.                 "CRT Phospore" or "PHO" for short.
  1612.                 This is a plane put into 3D space that
  1613.                 represents the pixels of the client
  1614.                 viewport (physical monitor).
  1615.  
  1616.                 The "IMAGE" plane from this diagram:
  1617.                 https://tinyurl.com/IMAGE-PLANE
  1618.  
  1619.         #####################FIND_POINT_ON_SCREEN_PLANE#
  1620.         #MODULO_CHECKER_PATTERN#########################
  1621.  
  1622.             // Checker pattern value, 1 or 0.         //
  1623.             // Combine Sets so that they create       //
  1624.             // a checkerboard of odd/even values,     //
  1625.             // and then convert even to 0 and         //
  1626.             // odd to 1.                              //
  1627.             //                                        //
  1628.             // SET_YYY:[ 0 1 0 1 0 1 0 ]              //
  1629.             // SET_XXX:[ 0 1 0 1 0 1 0 ]              //
  1630.             //                                        //
  1631.             // SET_XXX:     [ 0 1 0 1 0 1 0 ]         //
  1632.             //                | | | | | | |           //
  1633.             // SET_YYY:[ 0 ]- 0 1 0 1 0 1 0           //
  1634.             //         [ 1 ]- 1 2 1 2 1 2 1           //
  1635.             //         [ 0 ]- 0 1 0 1 0 1 0           //
  1636.             //         [ 1 ]- 1 2 1 2 1 2 1           //
  1637.             //         [ 0 ]- 0 1 0 1 0 1 0           //
  1638.             //         [ 1 ]- 1 2 1 2 1 2 1           //
  1639.             //         [ 0 ]- 0 1 0 1 0 1 0           //
  1640.             int chk =(  
  1641.                 I32_MOD( // <<<<<<<<<<<<<< SET_003
  1642.                     I32_MOD( T_Y, 2 )   // SET_YYY
  1643.                 +   I32_MOD( T_X, 2 )   // SET_XXX
  1644.                 ,                 2
  1645.                 )
  1646.             );;
  1647.  
  1648.         #########################MODULO_CHECKER_PATTERN#
  1649.         #CONSISTENT_VOXEL_COORDS########################
  1650.  
  1651.             The tilemap math for calculating what
  1652.             [voxel/tile] we are inside of is
  1653.             geometrically consistent, even when
  1654.             given NEGATIVE numbers.
  1655.  
  1656.             Meaning: The FIRST PIXELS of any
  1657.                      [tile/voxel] are in the same
  1658.                      relative position.
  1659.  
  1660.             +-+-----+-+-----+-+-----+-+-----+
  1661.             | | -1  | |  0  | |  +1 | |  +2 |
  1662.             | |     | |     | |     | |     |
  1663.             | +-----| +-----| +-----| +-----+
  1664.             +-------+-------+-------+-------+
  1665.  
  1666.             +-+
  1667.             | |   <--- The first edge of pixels for
  1668.             | |        [voxel/tile] seen on the X/Y
  1669.             | +-----|  axis.
  1670.             +-------+
  1671.         ########################CONSISTENT_VOXEL_COORDS#
  1672.         #NEXT_VOXEL_BOUNDING_VOLUME#####################
  1673.  
  1674.             Assuming vectors are moving in a positive
  1675.             direction, the intersection point to
  1676.             next voxel MUST be within the bounds of
  1677.             the CURRENT VOXEL + One Pixel All Around.
  1678.  
  1679.             Because we know the DIRECTION of the
  1680.             ray vector, we don't need a bounding volume
  1681.             and can just check that the respective
  1682.             X,Y,Z bounding planes have
  1683.             not been exceeded.
  1684.  
  1685.             +--------------------+--------------------+
  1686.             |                    |                    |
  1687.             |   +- - -  - - -+   |   +- - -  - - -+   |
  1688.             |   |            |   |   |            |   |
  1689.             |                    |                    |
  1690.             |   |            |   |   |            |   |
  1691.             |                    |                    |
  1692.             |   |            |   |   |            |   |
  1693.             |   +- - -  - - -+   |   +- - -  - - -+   |
  1694.          111111111111111111111111111                  |
  1695.          1  +--------------------+-1------------------+
  1696.          1  |                    | 1                  |
  1697.          1  |   +- - -  - - -+   | 1 +- - -  - - -+   |
  1698.          1  |   |            |   | 1 |            |   |
  1699.          1  |                    | 1                  |
  1700.          1  |   |     CV     |   | 1 |            |   |
  1701.          1  |     (CurVoxel)     | 1                  |
  1702.          1  |   |            |   | 1 |            |   |
  1703.          1  |   +- - -  - - -+   | 1 +- - -  - - -+   |
  1704.          1  |                    | 1                  |
  1705.          1  +--------------------+-1------------------+
  1706.          111111111111111111111111111
  1707.  
  1708.         #####################NEXT_VOXEL_BOUNDING_VOLUME#
  1709.         #VOX_MAR_ABOUT##################################
  1710.  
  1711.             VOX_MAR: ( VOXel_MARch )
  1712.  
  1713.                     Holds information about ray
  1714.                     marching WITHIN a single voxel.
  1715.  
  1716.         ##################################VOX_MAR_ABOUT#
  1717.         #DISTANCE_IS_NOT_CUMULATIVE#####################
  1718.  
  1719.             WRONG: xyz =  rwC + ( rwN * D_N );
  1720.             RIGHT: xyz =  xyz + ( rwN * D_N );
  1721.  
  1722.             The distance is NOT cumulative. Our ray
  1723.             marching is not anchored to the original
  1724.             ray world coordinate ( rwC ).
  1725.  
  1726.             Reason:
  1727.                 Collision with the first pixel of
  1728.                 the next voxel is PIXEL PERFECT and
  1729.                 if[  D_N  ]were a cumulative distance
  1730.                 over multiple iterations we would
  1731.                 probably see weird artifacts as slight
  1732.                 rounding errors compound.
  1733.  
  1734.                 Thus do NOT anchor to[  rwC  ]but
  1735.                 rather make a new origin location at
  1736.                 [  xyz  ]each loop iteration.
  1737.    
  1738.                 Think: Folds in orgami.
  1739.    
  1740.         #####################DISTANCE_IS_NOT_CUMULATIVE#
  1741.         #DIST_NEXT_NEVER_ZERO###########################
  1742.  
  1743.             Even if you are 1 pixel away from the next
  1744.             voxel, the distance to the next voxel should
  1745.             NEVER be zero. It should always be a
  1746.             POSITIVE NON-ZERO value.
  1747.    
  1748.             If this is NOT the case, your point-normal
  1749.             form ray marching will fail.
  1750.  
  1751.         ###########################DIST_NEXT_NEVER_ZERO#
  1752.         #TRAP_VALUE_MUST_BE_NEG_666#####################
  1753.  
  1754.             Using ( 0.0 - 666.0 ) as a trap value
  1755.             in our code that determines the distance
  1756.             to the next voxel. If you detect (-666.0)
  1757.             in your ray march loop, it means that
  1758.             the distance to the next voxel was never
  1759.             set. Distance to next voxel should ALWAYS
  1760.             be NON-ZERO and POSITIVE.
  1761.  
  1762.         #####################TRAP_VALUE_MUST_BE_NEG_666#
  1763.         #PIXEL_PROBABILITY_CLOUD########################
  1764.  
  1765.             [TODO](MAYBE)
  1766.  
  1767.             We should probably have 1 pixel equal to
  1768.             3 native frag coords. That way if you
  1769.             are in the CENTER of the pixel, you know
  1770.             you don't need to alias. But if you are
  1771.             on one of the boarder edges, you know
  1772.             you need to use some aliasing.
  1773.  
  1774.                [ONE FRAG COORD]
  1775.                      _|_
  1776.                     /   \
  1777.                     +   +     X: CENTER, no aliasing
  1778.                     |   |        required.
  1779.                     V   V
  1780.             +---+---+---+ <--+
  1781.             |   |   |   |     \
  1782.             +---+---+---+      \
  1783.             |   | X |   |       +--[ ONE PIXEL ]
  1784.             +---+---+---+      /
  1785.             |   |   |   |     /
  1786.             +---+---+---+ <--+
  1787.  
  1788.         ########################PIXEL_PROBABILITY_CLOUD#
  1789.  
  1790.  
  1791. *** ************************************************ **/
  1792. //:====================================:DOCUMENTATION://
  1793. //:UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU://
  1794. /** U : Undefine Macros Section **/
  1795.  
  1796.     #undef  V_4  
  1797.     #undef  V_3  
  1798.     #undef  V_2  
  1799.     #undef  F32  
  1800.     #undef  I32  
  1801.     #undef  U32  
  1802.  
  1803. /** U : Undefine Macros Section **/
  1804. //:UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU://
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement