Advertisement
DEKTEN

SDF_013

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