Advertisement
DEKTEN

SDF_011

Nov 27th, 2020 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** ************************************************ ***
  2. ***                                                  ***
  3. *** EASY___SOURCE:  tinyurl.com/SDF-011              ***
  4. *** DIRECT_SOURCE:  pastebin.com/kGZGqs1u            ***
  5. ***                                                  ***
  6. *** EASY_____DEMO:  tinyurl.com/SDF-011-DEMO         ***
  7. *** DIRECT___DEMO:  shadertoy.com/view/WsyBRh        ***
  8. ***                                                  ***
  9. *** About: Voxel Rendering For Patent Drawings.      ***
  10. ***        This version is a work in progress.       ***
  11. ***                                                  ***
  12. ***        Today we take the debugged 3/4 isometric  ***
  13. ***        slice plane and attempt to ray march      ***
  14. ***        into our voxel volume with it.            ***
  15. ***                                                  ***
  16. *** ************************************************ **/
  17. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  18. /** M: Macros Section **/
  19.  
  20.     #define V_4  vec4
  21.     #define V_3  vec3
  22.     #define V_2  vec2
  23.     #define F32 float
  24.     #define I32   int
  25.     #define U32  uint
  26.  
  27. /** M: Macros Section **/
  28. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  29. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  30. /** D: Data Section **/
  31.  
  32.     //:DEBUGGING:====================================://
  33.  
  34.         /** Nothing here yet **/
  35.  
  36.     //:====================================:DEBUGGING://
  37.     //:CONFIGURATION:================================://
  38.  
  39.         /** SLICE_RENDER_USING_CAMERA_PLANE **/
  40.         int CFG_SLICE_RENDER=( 0 );
  41.  
  42.     //:================================:CONFIGURATION://
  43.     //:RAYMARCHING_AND_VOXEL_CONSTANTS:==============://
  44.  
  45.         //:These defines are for ray marching when using
  46.         //:fragment coordinates as our coordinate space.
  47.         #define MAX_STE 1000   //:Max Step
  48.         #define MIN_DIS 0.02   //:Min Dist (SurfaceDist)
  49.         #define MAX_DIS 1000.0 //:Max Dist
  50.  
  51.         //:Number of tiles on each axis:
  52.         #define NTX  8  //:Num_Tiles (   in_voxel_map )
  53.         #define NTY  4  //:Num_Tiles (   in_voxel_map )
  54.         #define NTZ  3  //:Num_Tiles (   in_voxel_map )
  55.  
  56.         //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  57.         #define NPX  16 //:Num_Pixels_X( in_a_tile    )
  58.         #define NPY  16 //:Num_Pixels_Y( in_a_tile    )
  59.         #define NPZ  16 //:Num_Pixels_Z( in_a_tile    )
  60.  
  61.         //:Total__number_of__Pixels__in_entire_voxel_map
  62.         #define TPX  ( NTX * NPX ) //: Total_Pixels_X
  63.         #define TPY  ( NTY * NPY ) //: Total_Pixels_Y
  64.         #define TPZ  ( NTZ * NPZ ) //: Total_Pixels_Z
  65.  
  66.         #define _ 0                                          
  67.         #define X 1                                          
  68.         int VAT[ NTX * NTY * NTZ ]=int[ 8 * 4 * 3 ](  
  69.  
  70.         /** TODO: Eventually use an integer texture  **/
  71.         /**       for this tilemap data.             **/
  72.            
  73.         //:Highest Z Cross Section Is First Tile Map
  74.         //: 1 2 3 4 5 6 7 8        --- -----------------
  75.             X,X,X,X,X,X,X,X, //: 1  |             ^
  76.             X,_,_,_,_,_,_,X, //: 2  | Z == 0      |
  77.             X,_,_,_,_,_,_,X, //: 3  |             |
  78.             X,X,X,X,X,X,X,X, //: 4  |             |
  79.         //:                        ---            |
  80.         //: 1 2 3 4 5 6 7 8        ---   Cross Sections
  81.             X,_,_,_,_,_,_,X, //: 1  |    Can be thought
  82.             _,_,_,_,_,_,_,_, //: 2  |    of as differ-
  83.             _,_,_,_,_,_,_,_, //: 3  |    -ent 2D
  84.             X,_,_,_,_,_,_,X, //: 4  |    tilemaps.
  85.         //:                        ---            |
  86.         //: 1 2 3 4 5 6 7 8        ---            |
  87.             X,_,_,_,_,_,_,X, //: 1  |             |
  88.             X,_,_,_,_,_,_,X, //: 2  | Z == 2      |
  89.             X,_,_,_,_,_,_,X, //: 3  |             |
  90.             X,_,_,_,_,_,_,X  //: 4  |             V
  91.         //:                        --- -----------------
  92.         );                                                
  93.         #undef  _                                            
  94.         #undef  X  
  95.  
  96.     //:==============:RAYMARCHING_AND_VOXEL_CONSTANTS://
  97.     //:STRUCTS:======================================://
  98.  
  99.         //:RWC_AND_RWN:------------------------------://
  100.  
  101.             struct  RWC_AND_RWN{
  102.                 V_3 rwC        ;
  103.                 V_3         rwN;
  104.             };
  105.        
  106.         //:------------------------------:RWC_AND_RWN://
  107.         //:VOX_000:----------------------------------://
  108.  
  109.             /** VOC: VOxel_Current(information) **/
  110.             struct VOC{  
  111.                uint has;  //: voxel:exists?
  112.                 int val;  //: voxel:tile_value
  113.                 int dex;  //: voxel:1d_index
  114.                 int t_x;  //: voxel:tile_x
  115.                 int t_y;  //: voxel:tile_y
  116.                 int t_z;  //: voxel:tile_z
  117.             };
  118.  
  119.             /** VOD: VOxel_Distance(information) **/
  120.             struct VOD{  
  121.                 F32     dis_nex; //:Distance_To_Next
  122.                 F32     dis_sur; //:Distance_To_Surface
  123.                                  //:Within_Current_Voxel
  124.             };
  125.  
  126.             struct VOE{
  127.                 F32  msg_err;
  128.             };
  129.  
  130.             struct VOX_000{
  131.                        
  132.                 VOC     voc; //:Voxel_Current_Info
  133.                 VOD     vod; //:Voxel_Distance_Info
  134.                 VOE     voe; //:Voxel_Error____Info
  135.            
  136.             };
  137.  
  138.         //:----------------------------------:VOX_000://
  139.         //:VOX_MAR:----------------------------------://
  140.        
  141.             struct VOX_MAR{ //:SEE[ #VOX_MAR_ABOUT# ]
  142.  
  143.                 uint exit;
  144.  
  145.             };
  146.  
  147.         //:----------------------------------:VOX_MAR://
  148.  
  149.     //:======================================:STRUCTS://
  150.  
  151. /** D: Data Section **/
  152. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  153. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  154. /** I: Inifnite Degree Functions. Always At Top.     **/
  155.  
  156.     //:NO_HALT_USE_ERROR_PIXEL:======================://
  157.     //:PIX_ERR:======================================://
  158.  
  159.         #define ERR_001  1  /** msg_err # 1 **/
  160.         #define ERR_002  2  /** msg_err # 2 **/
  161.         #define ERR_003  3  /** msg_err # 3 **/
  162.  
  163.         V_4     PIX_ERR(
  164.             int msg_err /** EX: MSG_ERR_001 **/
  165.         ,   V_4 pix_err /** Previous Pixel Error **/
  166.         ,   int   o_k
  167.         )
  168.         {
  169.             /** Muddy Pastel Yellow For When You     **/
  170.             /** forget to set the pix_err_out value. **/
  171.             V_4 pix_err_out=V_4(0.5,0.5,0.2,1);
  172.  
  173.             float flux=( mod(iTime,1.0) );
  174.  
  175.             //:COLOR_PICKER_DEBUG_HEX:---------------://
  176.        
  177.             /** Make it easy to find source of error **/
  178.             /** in code by using color picker on     **/
  179.             /** shader output and then doing a       **/
  180.             /** CTRL+F with that hex code to find    **/
  181.             /** the offending source code.           **/
  182.  
  183.                 F32 _ =F32( 0.0    );
  184.                 F32 MAX =F32( 255.0  ); // MaxIntensity
  185.                 F32  A  =F32( 1.0    ); // Alpha_Max
  186.  
  187.                 //:ERROR_CODE_STROBE_COLORS:---------://
  188.  
  189.                 F32 _01_ =( F32(0x01) / MAX );
  190.                 F32 _10_ =( F32(0x10) / MAX );
  191.                 //
  192.                 F32 _02_ =( F32(0x02) / MAX );
  193.                 F32 _20_ =( F32(0x20) / MAX );
  194.                 //
  195.                 F32 _03_ =( F32(0x03) / MAX );
  196.                 F32 _30_ =( F32(0x30) / MAX );
  197.                 //
  198.                 F32 _04_ =( F32(0x04) / MAX );
  199.                 F32 _40_ =( F32(0x40) / MAX );
  200.                 //
  201.                 F32 _05_ =( F32(0x05) / MAX );
  202.                 F32 _50_ =( F32(0x50) / MAX );
  203.                 //
  204.                 F32 _06_ =( F32(0x06) / MAX );
  205.                 F32 _60_ =( F32(0x60) / MAX );
  206.                 //
  207.                 F32 _07_ =( F32(0x07) / MAX );
  208.                 F32 _70_ =( F32(0x70) / MAX );
  209.                 //
  210.                 F32 _08_ =( F32(0x08) / MAX );
  211.                 F32 _80_ =( F32(0x80) / MAX );
  212.                 //
  213.                 F32 _09_ =( F32(0x09) / MAX );
  214.                 F32 _90_ =( F32(0x90) / MAX );
  215.  
  216.                 V_4 _0x010101_ = V_4(_01_,_01_,_01_, A);
  217.                 V_4 _0x101010_ = V_4(_10_,_10_,_10_, A);
  218.  
  219.                 V_4 _0x020202_ = V_4(_02_,_02_,_02_, A);
  220.                 V_4 _0x202020_ = V_4(_20_,_20_,_20_, A);
  221.  
  222.                 V_4 _0x030303_ = V_4(_03_,_03_,_03_, A);
  223.                 V_4 _0x303030_ = V_4(_30_,_30_,_30_, A);
  224.  
  225.                 V_4 _0x040404_ = V_4(_04_,_04_,_04_, A);
  226.                 V_4 _0x404040_ = V_4(_40_,_40_,_40_, A);
  227.  
  228.                 V_4 _0x050505_ = V_4(_05_,_05_,_05_, A);
  229.                 V_4 _0x505050_ = V_4(_50_,_50_,_50_, A);
  230.  
  231.                 V_4 _0x060606_ = V_4(_06_,_06_,_06_, A);
  232.                 V_4 _0x606060_ = V_4(_60_,_60_,_60_, A);
  233.  
  234.                 V_4 _0x070707_ = V_4(_07_,_07_,_07_, A);
  235.                 V_4 _0x707070_ = V_4(_70_,_70_,_70_, A);
  236.  
  237.                 V_4 _0x080808_ = V_4(_08_,_08_,_08_, A);
  238.                 V_4 _0x808080_ = V_4(_80_,_80_,_80_, A);
  239.  
  240.                 V_4 _0x090909_ = V_4(_09_,_09_,_09_, A);
  241.                 V_4 _0x909090_ = V_4(_90_,_90_,_90_, A);
  242.  
  243.                 //:---------:ERROR_CODE_STROBE_COLORS://
  244.                 //:ERROR_ZERO_COLORS:----------------://
  245.                 #define F float
  246.                 #define V vec4
  247.                 /** If you forget to set error code, **/
  248.                 /** you will see flashing red and    **/
  249.                 /** blue. ( _0xFF0666_ & _0x6660FF_ )**/
  250.                  
  251.                 F   _FF_=( F32(0xFF) / MAX );
  252.                 //  _06_=( F32(0x06) / MAX );
  253.                 //  _60_=( F32(0x60) / MAX );
  254.                 F   _66_=( F32(0x66) / MAX );
  255.                 V   _0xFF0666_ =V_4(_FF_,_06_,_66_,A);
  256.                 V   _0x6660FF_ =V_4(_66_,_60_,_FF_,A);
  257.  
  258.                 #undef F
  259.                 #undef V
  260.                 //:----------------:ERROR_ZERO_COLORS://
  261.                 //:BAD_OK_ERROR_COLOR:---------------://
  262.                 #define F float
  263.                 #define V vec4
  264.                 /** You will see this if you init    **/
  265.                 /** o_k to a value other than 1 in   **/
  266.                 /** your source code.                **/
  267.                 /** Strobes between orange and lime. **/
  268.                 /** ( _0xFF7700_ & _0x77FF00_ )      **/
  269.                  
  270.                 //  _FF_=( F32(0xFF) / MAX );
  271.                 F   _77_=( F32(0x77) / MAX );
  272.                 F   _00_=( F32(0x00) / MAX );
  273.                 V   _0xFF7700_ =V_4(_FF_,_77_,_00_,A);
  274.                 V   _0x77FF00_ =V_4(_77_,_FF_,_00_,A);
  275.  
  276.                 #undef F
  277.                 #undef V
  278.                 //:---------------:BAD_OK_ERROR_COLOR://
  279.  
  280.             //:---------------:COLOR_PICKER_DEBUG_HEX://
  281.  
  282.             if( o_k <= 0 ){
  283.                 pix_err_out = pix_err;
  284.             }else
  285.             if( 1 == o_k ){
  286.  
  287.                 /** table of error "messages" #0 **/
  288.                 V_4 tab_err_000[10]=V_4[10](        
  289.                                                
  290.                     // 0: Invalid Error Code    
  291.                     _0xFF0666_  // RED_FLASH
  292.                          
  293.                     // Odd Frame Error Colors:
  294.                 ,   _0x010101_  //  ERR_001 : ODD_FRAME
  295.                 ,   _0x020202_  //  ERR_002 : ODD_FRAME
  296.                 ,   _0x030303_  //  ERR_003 : ODD_FRAME
  297.                 ,   _0x040404_  //  ERR_004 : ODD_FRAME
  298.                 ,   _0x050505_  //  ERR_005 : ODD_FRAME
  299.                 ,   _0x060606_  //  ERR_006 : ODD_FRAME
  300.                 ,   _0x070707_  //  ERR_007 : ODD_FRAME
  301.                 ,   _0x080808_  //  ERR_008 : ODD_FRAME
  302.                 ,   _0x090909_  //  ERR_009 : ODD_FRAME
  303.                 );;        
  304.                 /** table of error "messages" #1 **/
  305.                 V_4 tab_err_001[10]=V_4[10](        
  306.                                                
  307.                     // 0: Invalid Error Code    
  308.                     _0x6660FF_ // BLUE_FLASH    
  309.                          
  310.                     // Even Frame Error Colors:
  311.                 ,   _0x101010_  //  ERR_001 : EVE_FRAME
  312.                 ,   _0x202020_  //  ERR_002 : EVE_FRAME
  313.                 ,   _0x303030_  //  ERR_003 : EVE_FRAME
  314.                 ,   _0x404040_  //  ERR_004 : EVE_FRAME
  315.                 ,   _0x505050_  //  ERR_005 : EVE_FRAME
  316.                 ,   _0x606060_  //  ERR_006 : EVE_FRAME
  317.                 ,   _0x707070_  //  ERR_007 : EVE_FRAME
  318.                 ,   _0x808080_  //  ERR_008 : EVE_FRAME
  319.                 ,   _0x909090_  //  ERR_009 : EVE_FRAME
  320.                 );;                      
  321.  
  322.                 if( mod(iTime*16.0,2.0) < 1.0 ){
  323.                     pix_err_out =( tab_err_000
  324.                                  [ msg_err ] );;
  325.                 }else{
  326.                     pix_err_out =( tab_err_001
  327.                                  [ msg_err ] );;
  328.                 };;
  329.  
  330.             }else{
  331.                 /** Orange strobe for an o_k value   **/
  332.                 /** that is NOT expected. (o_k >= 2) **/
  333.  
  334.                 if( mod(iTime*2.0,2.0) < 1.0 ){
  335.                     pix_err_out = _0xFF7700_; // ORANGE
  336.                 }else{
  337.                     pix_err_out = _0x77FF00_; // LIME
  338.                 };;
  339.  
  340.             };;
  341.                
  342.             return( pix_err_out );
  343.         }
  344.  
  345.     //:======================================:PIX_ERR://
  346.     //:======================:NO_HALT_USE_ERROR_PIXEL://
  347.  
  348. /** I: Inifnite Degree Functions. Always At Top.     **/
  349. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  350. //:22222222222222222222222222222222222222222222222222://
  351.  
  352.     //:INTERPOLATION_3D:=============================://
  353.     //:sfd_i3d:======================================://
  354.  
  355.         V_3 sdf_i3d(
  356.         /**/V_3 _1_
  357.         ,   V_3 _2_
  358.         ,   F32 f_p
  359.         ){
  360.             return( _1_ + ( ( _2_ - _1_ )*f_p ) );
  361.         }
  362.  
  363.     //:=============================:INTERPOLATION_3D://
  364.     //:======================================:sfd_i3d://
  365.     //:FIRST_VOXEL_QUERY_NEEDED:=====================://
  366.  
  367.         #define T_X vox_000.voc.t_x
  368.         #define T_Y vox_000.voc.t_y
  369.         #define T_Z vox_000.voc.t_z
  370.  
  371.         /** rwN used to find distance to NEXT voxel. **/
  372.             VOX_000
  373.         GET_vox_000_USE_xyz_rwN(
  374.                         V_3 xyz
  375.                     ,   V_3     rwN
  376.         )
  377.         {
  378.             VOX_000 vox_000;
  379.  
  380.             //:CURRENT_VOXEL_CELL:-------------------://
  381.  
  382.             vox_000.voc.val = int( 0 - 1 );
  383.             T_X = ( int(floor( xyz.x / float( NPX ))));
  384.             T_Y = ( int(floor( xyz.y / float( NPY ))));
  385.             T_Z = ( int(floor( xyz.z / float( NPZ ))));
  386.  
  387.             //:-------------------:CURRENT_VOXEL_CELL://
  388.             //:GET_VOXEL_CELL_VALUE:-----------------://
  389.  
  390.             /** Voxel Volume Is Hard Coded To have   **/
  391.             /** voxel__tile[0,0,0] stuck at world    **/
  392.             /** world_coord[0,0,0]                   **/
  393.             if( T_X >= 0 && T_X < NTX
  394.             &&  T_Y >= 0 && T_Y < NTY
  395.             &&  T_Z >= 0 && T_Z < NTZ
  396.             ){
  397.  
  398.                 //: Index2D -and- Index3D
  399.                 int D2D = T_X + ( NTX    *    T_Y );
  400.                 int D3D = D2D + ( NTX * NTY * T_Z );
  401.  
  402.                 vox_000.voc.dex=(      D3D   );
  403.                 vox_000.voc.val=( VAT[ D3D ] );
  404.  
  405.                 /** NOTE: Voxel value 0 will NOT get **/
  406.                 /**       special treatment. It could**/
  407.                 /**       contain geometry if we     **/
  408.                 /**       really wanted it to.       **/
  409.                 vox_000.voc.has=uint(  1  );
  410.                
  411.             }else{
  412.                 /** Using a "has" flag so we         **/
  413.                 /** can keep more logic UNSIGNED.    **/
  414.                 /** (No need for negative value to ) **/
  415.                 /** (be used for invalid dex or val) **/
  416.                 vox_000.voc.dex= int(  0  );
  417.                 vox_000.voc.val= int(  0  );
  418.                 vox_000.voc.has=uint(  0  );
  419.             };;
  420.             //:-----------------:GET_VOXEL_CELL_VALUE://
  421.             //:DIST_TO_NEXT_VOXEL:-------------------://    
  422.             /** ************************************ ***
  423.                                 x_bound
  424.                                 |||
  425.                                 |||
  426.                                 |||
  427.             ====+-----+---[i]----+====== y_bound ====
  428.                 |     |   /      ||
  429.                 |     |  /       ||
  430.                 |     | /        ||
  431.                 |     |/         ||
  432.                 +- - -P----------+|
  433.                 |     .          ||
  434.                 |     .          ||
  435.                 +-----+----------+|
  436.                                 |||
  437.                                 |||
  438.                                 |||
  439.                                 |||
  440.             *** ************************************ **/
  441.             #define P xyz /** Point  **/
  442.             #define N rwN /** Normal **/
  443.  
  444.                 //:SIGNS_OF_RAY_VECTOR:--------------://
  445.                 /** We need to know if the ray is    **/
  446.                 /** moving forwards to HIGHER tile   **/
  447.                 /** values or BACKWARDS to LOWER     **/
  448.                 /** tile values.                     **/
  449.  
  450.                 /**  SEE[ #CONSISTENT_VOXEL_COORDS# **/
  451.                 F32  b_x  /** x_bound       **/     ;  
  452.                 F32  b_y  /** y_bound       **/     ;  
  453.                 F32  b_z  /** z_bound       **/     ;  
  454.                           /**               **/     ;
  455.                 F32  x_0  /** x_bound : MIN **/     ;  
  456.                 F32  y_0  /** y_bound : MIN **/     ;  
  457.                 F32  z_0  /** z_bound : MIN **/     ;  
  458.                           /**               **/     ;
  459.                 F32  x_1  /** x_bound : MAX **/     ;  
  460.                 F32  y_1  /** y_bound : MAX **/     ;  
  461.                 F32  z_1  /** z_bound : MAX **/     ;  
  462.                                                     ;
  463.                 x_1 =F32( ( T_X +  1 ) * NPX )      ;
  464.                 y_1 =F32( ( T_Y +  1 ) * NPY )      ;
  465.                 z_1 =F32( ( T_Z +  1 ) * NPZ )      ;
  466.                                                     ;
  467.                 x_0 =F32( ( T_X +  0 ) * NPX )- 1.0 ;
  468.                 y_0 =F32( ( T_Y +  0 ) * NPY )- 1.0 ;
  469.                 z_0 =F32( ( T_Z +  0 ) * NPZ )- 1.0 ;
  470.                                                     ;
  471.                 b_x = N.x >= 0.0 ? x_1 : x_0        ;
  472.                 b_y = N.y >= 0.0 ? y_1 : y_0        ;
  473.                 b_z = N.z >= 0.0 ? z_1 : z_0        ;
  474.  
  475.                 //:--------------:SIGNS_OF_RAY_VECTOR://
  476.                 /** ******************************** ***
  477.                 SEE[ #NEXT_VOXEL_BOUNDING_VOLUME# ]    
  478.                 The intersection point to next voxel    
  479.                 (By using plane intersections) should  
  480.                 not be further than ONE PIXEL away      
  481.                 from the current voxel we are inside.  
  482.            
  483.                 +----------------+----------------+
  484.                 | +- - -  - - -+ | +- - -  - - -+ |
  485.                 | |            | | |            | |
  486.                 |                |                |
  487.                 | |            | | |            | |
  488.                 |                |                |
  489.                 | |            | | |            | |
  490.                 | +- - -  - - -+ | +- - -  - - -+ |
  491.                 +----------------+----------------+
  492.                 | +- - -  - - -+ | +- - -  - - -+ |
  493.                 | |            | | |            | |
  494.                 |                |                |
  495.                 | |     CV     | | |            | |
  496.                 |   (CurVoxel)   |                |
  497.                 | |            | | |            | |
  498.                 | +- - -  - - -+ | +- - -  - - -+ |
  499.                 +----------------+----------------+
  500.  
  501.                 *** ******************************** **/
  502.                 /** ******************************** ***
  503.                 ___ == DONT CARE ABOUT
  504.                 P   + (N   * S   )==[ b_x, ___ , ___ ]
  505.                 P.x + (N.x * S.x )==  b_x
  506.                       (N.x * S.x )==  b_x - P.x
  507.                              S.x  == (b_x - P.x) / N.x
  508.                 *** ******************************** **/
  509.                 //:FIRST_PIXEL_OF_NEXT_VOXEL:--------://
  510.                 #define N_X ( 0.0 != N.x )
  511.                 #define N_Y ( 0.0 != N.y )
  512.                 #define N_Z ( 0.0 != N.z )
  513.  
  514.                 //:Scalar for point normal form.
  515.                 V_3 S = V_3( 0 );
  516.  
  517.                 if( N_X ){ S.x = ( b_x - P.x ) / N.x; };
  518.                 if( N_Y ){ S.y = ( b_y - P.y ) / N.y; };
  519.                 if( N_Z ){ S.z = ( b_z - P.z ) / N.z; };
  520.  
  521.                 F32 shortest_scalar_distance ;
  522.                 V_3 first_pixel_of_next_voxel;
  523.  
  524.                 if( N_X && S.x <= S.y && S.x <= S.z ){
  525.                     shortest_scalar_distance=(  S.x );
  526.                 }else
  527.                 if( N_Y && S.y <= S.x && S.y <= S.z ){
  528.                     shortest_scalar_distance=(  S.y );
  529.                 }else
  530.                 if( N_Z && S.z <= S.x && S.z <= S.y ){
  531.                     shortest_scalar_distance=(  S.z );
  532.                 };;
  533.  
  534.                 /** Not using this anywhere, BUT KEEP**/
  535.                 /** for now. Now is not the time     **/
  536.                 /** to optimize.                     **/
  537.                 first_pixel_of_next_voxel=(
  538.                 //: P + ( N * [ S.x | S.y | S.z ] )
  539.                     P + ( N * shortest_scalar_distance )
  540.                 );;
  541.  
  542.                 vox_000.vod.dis_nex=(
  543.                         shortest_scalar_distance );;
  544.  
  545.                 #undef  N_X  
  546.                 #undef  N_Y  
  547.                 #undef  N_Z  
  548.                 //:--------:FIRST_PIXEL_OF_NEXT_VOXEL://
  549.  
  550.            
  551.             #undef  P /** Point  **/
  552.             #undef  N /** Normal **/
  553.             //:-------------------:DIST_TO_NEXT_VOXEL://
  554.          
  555.             return( vox_000 );
  556.         }
  557.         #undef  T_X
  558.         #undef  T_Y
  559.         #undef  T_Z
  560.     //:=====================:FIRST_VOXEL_QUERY_NEEDED://
  561.     //:MARCH_INTO_VOXEL:=============================://
  562.     VOX_MAR sdf_MarchIntoVoxel(
  563.         VOX_000 vox_000
  564.     ,   V_3     xyz
  565.     ,   V_3     rwN
  566.     )
  567.     {
  568.  
  569.         VOX_MAR vox_mar;
  570.         vox_mar.exit=U32( 1 );
  571.  
  572.  
  573.         return( vox_mar );
  574.     }
  575.     //:=============================:MARCH_INTO_VOXEL://
  576.     //:INTEGER_MODULO:===============================://
  577.  
  578.     #ifndef I32
  579.     #define I32 int
  580.     #endif
  581.  
  582.     #ifndef F32
  583.     #define F32 float
  584.     #endif
  585.  
  586.         /** PRIVATE: Called only by I32_MOD **/
  587.         I32 i32_mod_neg( I32 neg_a , I32 pos_d ){
  588.  
  589.             /** ************************************ ***
  590.             Function Calculates:
  591.            
  592.             FIXED: (d-1)-[ mod(abs(a)+1 , d) ]
  593.  
  594.             GOAL: Negatives keep exact same tiling
  595.                   pattern as the positives.
  596.  
  597.             IN : -6 -5 -4 -3 -2 -1  0 +1 +2 +3 +4 +5 +6
  598.             OUT:  2  3  0  1  2  3  0  1  2  3  0  1  2
  599.  
  600.             0123 -> 0123 -> 0123 -> 0123 -> 0123 -> ect
  601.  
  602.            
  603.  
  604.             *** ************************************ **/
  605.  
  606.             I32 pos_a = ( 0 - neg_a ) + 1;
  607.            
  608.             F32 A = F32( pos_a );
  609.             F32 D = F32( pos_d );
  610.            
  611.             //: GLSL_MODULUS_WITH_INTEGERS_FORMULA
  612.             //: WARD:Wholepart,All,Remainder,Divisor
  613.             int W = int(  trunc( A / (          D  )) );
  614.             int R = int(         A - ( F32(W) * D  )  );
  615.            
  616.             return( (pos_d-1) - R );
  617.         }
  618.  
  619.         I32
  620.         I32_MOD(
  621.         /**/I32 a /** ALL     : CAN BE NEGATIVE **/
  622.         ,   I32 d /** DIVISOR : ALWAYS POSITIVE **/
  623.         ){
  624.  
  625.             /** ************************************ ***
  626.  
  627.             Allow for I32_MOD to be used for wrapping
  628.             even when the input to wrap[ a ] goes
  629.             negative. d should always be positive.
  630.  
  631.             EX: mod( x , 2 ) , where x == -1
  632.             | -1 | 0 [ 1 ] 2 |
  633.             |  1 | 0 [ 1 ] 0 | 1 | 0 |
  634.             d + 1 == 2 + (-1) == 1
  635.             *** ************************************ **/
  636.  
  637.             int R;
  638.  
  639.             if( a < 0 ){
  640.  
  641.                 //:This is CLOSE but then new problem
  642.                 //:of lots of green checkers is showing
  643.                 //:up. No clue...
  644.                 R = i32_mod_neg( a , d );
  645.  
  646.             }else{
  647.  
  648.                 F32 A = F32( a );
  649.                 F32 D = F32( d );
  650.                             //:<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<FIX_THE_OVERFLOW_BELOW
  651.                 //: GLSL_MODULUS_WITH_INTEGERS_FORMULA
  652.                 //: WARD:Wholepart,All,Remainder,Divisor
  653.                 int W = int(  trunc( A / (          D  )) );
  654.                     R = int(         A - ( F32(W) * D  )  );
  655.  
  656.             };;
  657.  
  658.             return( R );
  659.         }
  660.     //:===============================:INTEGER_MODULO://
  661. //:22222222222222222222222222222222222222222222222222://
  662. //:11111111111111111111111111111111111111111111111111://
  663.  
  664.     //:FRAGCOORD_TO_FRAGPERCENT:=====================://
  665.     //:f_c_CTO_f_p:==================================://
  666.  
  667.         V_2 f_c_CTO_f_p( V_2 f_c ){
  668.         V_2         f_p;
  669.             f_p = f_c / ( iResolution.xy - 1.0 );
  670.             return(  f_p );
  671.         }
  672.  
  673.     //:==================================:f_c_CTO_f_p://
  674.     //:=====================:FRAGCOORD_TO_FRAGPERCENT://
  675.     //:FRAGPER_TO_CAMERA_RAY:========================://
  676.     //:f_p_CTO_rwC_AND_rwN:==========================://
  677.     #define _0_  (0.0)
  678.     #define  _   (0.0)
  679.  
  680.                 RWC_AND_RWN
  681.         f_p_CTO_rwC_AND_rwN(
  682.             V_2 f_p /** 2 dimensional percentage **/
  683.         )
  684.         {
  685.             V_3 rwC; //:ray_word__COORDINATE
  686.             V_3 rwN; //:ray_world_NORMAL____
  687.  
  688.             //:#FIND_POINT_ON_SCREEN_PLANE#
  689.             /** ************************************ ***
  690.             Could possibly use these as slice planes.
  691.             But for now using these to navigate our
  692.             voxel map bounds.
  693.  
  694.             [ A ]Is_Directly_Above[ E ]On_Z_Axis
  695.             [ B ]Is_Directly_Above[ F ]On_Z_Axis
  696.             [ C ]Is_Directly_Above[ G ]On_Z_Axis
  697.             [ D ]Is_Directly_Above[ H ]On_Z_Axis
  698.            
  699.                         (In World/Frag Coords)
  700.                             [0,0,0]
  701.                                 \
  702.                 A_B              \
  703.             A----|------B  A -->  +=======+  <-- B
  704.             |    |      |        /.       .\
  705.             | rwC_001   |       / .       . \
  706.             |    |      |      /  .       .  \
  707.             C----|------D  C->+===============+<-D
  708.                 C_D           [   ._....._.   ]
  709.                               [  /         \  ]
  710.                               [ .           . ]
  711.                               [/             \]
  712.                               +===============+<-H
  713.  
  714.                               +===============+  
  715.                               [\             /]
  716.                               [ .           . ]
  717.                               [  \_......._/  ]
  718.                 E_F           [   .       .   ]
  719.             E----|------F  G->+===============+<-H
  720.             |    |      |      \  .       .  /
  721.             | rwC_002   |       \ .       . /
  722.             |    |      |        \.       ./
  723.             G----|------H  E -->  +=======+  <-- F
  724.                 G_H          
  725.                            
  726.             *** ************************************ **/
  727.  
  728.             //:Dimensions Of Voxel Volume:
  729.             //:As maximum indexes.
  730.             F32 M_X =( F32(TPX) - 1.0 );
  731.             F32 M_Y =( F32(TPY) - 1.0 );
  732.             F32 M_Z =( F32(TPZ) - 1.0 );
  733.  
  734.             //:TOP LAYER OF PIXELS OF VOXEL VOLUME:
  735.             //:(INCLUSIVE MATH. We are inside the)
  736.             //:(first layer of pixels of the first)
  737.             //:(layer of voxels)
  738.             V_3 _A_ = V_3( _-_ , _-_ , _-_ );
  739.             V_3 _B_ = V_3( M_X , _-_ , _-_ );      
  740.             V_3 _C_ = V_3( _-_ , M_Y , _-_ );
  741.             V_3 _D_ = V_3( M_X , M_Y , _-_ );
  742.  
  743.             //:BOTTOM LAYER OF PIXELS OF VOXEL VOLUME
  744.             //:(Incluseive Math. We are inside the )
  745.             //:(last layer of pixels of the last   )
  746.             //:(layer of voxels.                   )
  747.             V_3 _E_ = V_3( _-_ , _-_ , M_Z );
  748.             V_3 _F_ = V_3( M_X , _-_ , M_Z );      
  749.             V_3 _G_ = V_3( _-_ , M_Y , M_Z );
  750.             V_3 _H_ = V_3( M_X , M_Y , M_Z );
  751.  
  752.             /** ************************************ ***
  753.             Take our plane and pretend it is
  754.             the top of a cube that we want to
  755.             get plane in an isometric position to.
  756.             Where the new plane tangents corner _D_
  757.            
  758.            
  759.                    A------_B_            vec_D_B
  760.                   /|       \\                  \
  761.                  / |       |\\                  \
  762.                 /  |       | \\      vec_D_C <---D
  763.               _C_============_D_                 ^
  764.                |   |_ _ _ _|  ||                 |
  765.                |  /E       F\ ||            vec_H_D
  766.                | /           \||
  767.                |/             ||     Corner_Vector:
  768.                G-------------_H_  
  769.             *** *** * * * * * * **** * * * * * * *** **/
  770.  
  771.             /** Edge Vectors **/
  772.  
  773.             V_3 vec_C_D = normalize( _D_ - _C_ );
  774.             V_3 vec_D_C = normalize( _C_ - _D_ );
  775.             V_3 vec_D_B = normalize( _B_ - _D_ );
  776.             V_3 vec_H_D = normalize( _D_ - _H_ );
  777.             V_3 vec_D_H = normalize( _H_ - _D_ );
  778.  
  779.             /** *** * * * * * * **** * * * * * * *** ***
  780.             Use Corner_Vector to calculate a 3/4        
  781.             perspective plane that tangents _D_.
  782.             *** ************************************ **/
  783.             /** ************************************ ***
  784.    
  785.             X axis vector is pretty easy because the
  786.             camera X axis does not move in the Z
  787.             direction.
  788.                     ^         /
  789.                     |       /    ^
  790.             A-------B     /      |    a_x Is Average
  791.             |       |   /        |  
  792.             |       | /     vec_D_B
  793.             C-------D-->    vec_C_D ----->
  794.                   /
  795.                 /
  796.               /<-- goal is THIS line for X-axis.(a_x)
  797.             /
  798.             *** *** * * * * * * **** * * * * * * *** **/
  799.             #define _X_ vec_C_D
  800.             #define _Y_ vec_D_B
  801.             V_3 a_x =normalize(
  802.  
  803.                 /** 45 degree line on XY plane **/
  804.                 ( _X_ + _Y_ ) / 2.0  
  805.  
  806.             );;
  807.             #undef  _X_
  808.             #undef  _Y_
  809.             /** *** * * * * * * **** * * * * * * *** ***
  810.            
  811.             Y axis vector is a bit tricky because it
  812.             moves on all axis(es). XYZ.
  813.  
  814.             +--B  If we average vec_D_C & vec_D_B
  815.             |\ |  To get a 45 degree on the XY plane,
  816.             | \|  we can then tilt that vector up
  817.             C--D  by 45 degrees by averaging it
  818.                |  with vec_H_D
  819.                |
  820.                H
  821.  
  822.             *** ************************************ **/
  823.  
  824.             //: a_y: Axis_Y
  825.             #define _X_ vec_D_C
  826.             #define _Y_ vec_D_B
  827.             #define _Z_ vec_H_D
  828.             V_3 a_y =normalize(
  829.  
  830.                 (
  831.                     normalize( (_X_ + _Y_)/2.0 )
  832.                     +        (     _Z_         )
  833.                 ) /2.0
  834.             );;
  835.             #undef  _X_
  836.             #undef  _Y_
  837.             #undef  _Z_
  838.  
  839.            
  840.             /** Looking into the voxel volume from   **/
  841.             /** a 3/4 isometric direction.           **/
  842.             V_3 a_z = normalize(
  843.                 ( vec_D_C + vec_D_B + vec_D_H ) / 3.0
  844.             );;
  845.  
  846.             /** ************************************ ***
  847.  
  848.             We can now use point-normal form to
  849.             build our camera polygon. We will start
  850.             from point _D_ and walk HALFWAY the
  851.             WIDTH in both directions on our altered
  852.             x-axis vector( a_x ) and HALFWAY the
  853.             HEIGHT in both directions on our altered
  854.             y-axis vector( a_y ).
  855.  
  856.             HEIGHT: The height of our camera plane.
  857.              WIDTH: The width  of our camera plane.
  858.  
  859.                       P_X                   +---+
  860.                 +------+------+             |   |
  861.                 |      |      |         +---+---+
  862.             N_Y +---- _D_ ----+ P_Y     |_D_|
  863.                 |      |      |     +---+---+
  864.                 +------+------+     |   |#DIA_CAMCENTER#
  865.                       N_X           +---+
  866.  
  867.                 #CAMCENTER#:
  868.                 In order for the camera to be 100%
  869.                 centered, it may be necessary to
  870.                 squash or stretch the camera by 1
  871.                 pixel IF the camera is NOT an odd
  872.                 number of pixels on that axis.
  873.                 SEE_DIAGRAM[ #DIA_CAMCENTER# ]
  874.  
  875.                     +0 +1 +2 +2.5       +0 +1 +2 +3  
  876.                     [D]   [+]           ||     [+]    
  877.                 [ ][ ][ ][ ][ ]   [ ][ ][ ][ ][ ][ ]  
  878.                 |<---- 5 ---->|   |<------ 6 ----->|  
  879.  
  880.             *** ************************************ **/
  881.  
  882.             #define ZOOMED_IN_CAMERA_2020_11_26 ( 1 )
  883.             float H_W ;
  884.             float H_H ;
  885.             if( ZOOMED_IN_CAMERA_2020_11_26 >= 1 ){
  886.    
  887.                 /** Camera surface smaller than      **/
  888.                 /** client viewport means zoomed in  **/
  889.                 H_W = ( F32(TPX) / 2.0 );
  890.                 H_H = ( F32(TPY) / 2.0 );
  891.  
  892.             }else
  893.             if( ZOOMED_IN_CAMERA_2020_11_26 <= 0 ){
  894.  
  895.                 /** Camera surface exactly same size **/
  896.                 /** as client viewport means no zoom.**/
  897.                 H_W = ( iResolution.x / 2.0 );
  898.                 H_H = ( iResolution.y / 2.0 );
  899.  
  900.             };;
  901.             #undef  ZOOMED_IN_CAMERA_2020_11_26
  902.  
  903.             /** To be pixel-perfect, floor and ceil  **/
  904.             /** need to be used. This is an OCD      **/
  905.             /** optimization that can probably       **/
  906.             /** be removed without noticable         **/
  907.             /** difference in the result.            **/
  908.             //- P_X = floor( _D_ + ( a_x * H_W ) );  -//
  909.             //- N_X =  ceil( _D_ - ( a_x * H_W ) );  -//
  910.             //- P_Y = floor( _D_ + ( a_y * H_H ) );  -//
  911.             //- N_Y =  ceil( _D_ - ( a_y * H_H ) );  -//
  912.             //+ We can't do it this way, because the +//
  913.             //+ plane is not aligned with our native +//
  914.             //+ XYZ axis.                            +//
  915.             //+ What I mean is we can't get the top  +//
  916.             //+ left corner by saying:               +//
  917.             //+ vec3( N_Y.x , P_X.y , _D_.z )        +//
  918.             /** ************************************ ***
  919.             RASTER_GRAPHICS_STYLE_TOP_LEFT_ORIGIN
  920.                \
  921.                 +----------- +X ------------>
  922.                 |    
  923.                 |     _I_              _J_
  924.                 |       \      P_X      /  
  925.                 |        +------+------+        ^
  926.                 |        |      |      |        |
  927.                +Y    N_Y +---- _D_ ----+ P_Y [ -y ]
  928.                 |        |      |      |        |
  929.                 |        +------+------+        |
  930.                 |       /      N_X      \       |
  931.                 V     _K_               _L_     |
  932.                                                 |
  933.                     <---------[ -x ]------------+
  934.  
  935.             *** *** * * * * * * **** * * * * * * *** **/
  936.    
  937.             V_3 _I_ = _D_  - ( a_x * H_W )
  938.                            - ( a_y * H_H ) ;;
  939.  
  940.             V_3 _J_ = _D_  + ( a_x * H_W )
  941.                            - ( a_y * H_H ) ;;
  942.  
  943.             V_3 _K_ = _D_  - ( a_x * H_W )
  944.                            + ( a_y * H_H ) ;;
  945.  
  946.             V_3 _L_ = _D_  + ( a_x * H_W )
  947.                            + ( a_y * H_H ) ;;
  948.                    
  949.             /** ************************************ **/
  950.             #define USE_ANIMATED_DOLLY_FOR_DEBUG  ( 1 )
  951.             if(     USE_ANIMATED_DOLLY_FOR_DEBUG >= 1 ){
  952.  
  953.                 F32 max_dolly =max(
  954.                             F32(TPX)
  955.                 ,
  956.                         max(
  957.                             F32(TPY)
  958.                             ,
  959.                             F32(TPZ)
  960.                         )
  961.                 );;
  962.  
  963.                 F32 pos_cos=( (cos(iTime)/2.0)+0.5 );
  964.                 F32 neg_cos=( (cos(iTime)/2.0)-0.5 );
  965.  
  966.                 F32 dolly_amount =(
  967.                     pos_cos * max_dolly
  968.                 );;
  969.                
  970.                 _I_ += ( a_z * dolly_amount );
  971.                 _J_ += ( a_z * dolly_amount );
  972.                 _K_ += ( a_z * dolly_amount );
  973.                 _L_ += ( a_z * dolly_amount );
  974.  
  975.             };;
  976.             #undef  USE_ANIMATED_DOLLY_FOR_DEBUG
  977.            
  978.             V_3 I_J = sdf_i3d( _I_ , _J_ , f_p.x );
  979.             V_3 K_L = sdf_i3d( _K_ , _L_ , f_p.x );
  980.                 rwC = sdf_i3d( I_J , K_L , f_p.y );
  981.  
  982.                 //:#POSITIVE_Z_DIVES_INTO_SCREEN#://
  983.                 rwN = normalize( a_z );
  984.  
  985.                     RWC_AND_RWN
  986.                     rwC_AND_rwN;
  987.                     rwC_AND_rwN.rwC = rwC;
  988.                     rwC_AND_rwN.rwN = rwN;
  989.             return( rwC_AND_rwN );
  990.         }
  991.  
  992.     #undef  _0_
  993.     #undef   _
  994.     //:==========================:f_p_CTO_rwC_AND_rwN://
  995.     //:========================:FRAGPER_TO_CAMERA_RAY://
  996.     //:RENDER_SCENE:=================================://
  997.     //:sdf_RenderScene:==============================://
  998.     #define T_X vox_000.voc.t_x
  999.     #define T_Y vox_000.voc.t_y
  1000.     #define T_Z vox_000.voc.t_z
  1001.     #define HAS vox_000.voc.has
  1002.  
  1003.         V_4 sdf_RenderScene( RWC_AND_RWN rwC_AND_rwN )
  1004.         {
  1005.             I32 o_k = I32( 1 );
  1006.             V_4 c4d = V_4(1,0.5,0,1);
  1007.  
  1008.             V_3 rwN = rwC_AND_rwN.rwN;
  1009.             V_3 rwC = rwC_AND_rwN.rwC;
  1010.  
  1011.             V_3 xyz = rwC;
  1012.          
  1013.             VOX_000
  1014.             vox_000;
  1015.  
  1016.             VOX_MAR vox_mar;
  1017.  
  1018.             //:dis_nex: Distance To NEXT voxel.
  1019.             //:dis_sur: Distance To Surface Geometry inside
  1020.             //:     the current voxel. In world coords.
  1021.             vox_000.vod.dis_nex =( 0.0 );  
  1022.         //: vox_000.vod.dis_sur =( 0.0 );  
  1023.  
  1024.             //:Voxels will be thought of as 3D tiles:
  1025.             vox_000.voc.has = uint( 0 );
  1026.             vox_000.voc.dex =  int( 0 );
  1027.             vox_000.voc.t_x =  int( 0 );
  1028.             vox_000.voc.t_y =  int( 0 );
  1029.             vox_000.voc.t_z =  int( 0 );
  1030.  
  1031.             //:RAY_MARCH_LOOP:-----------------------://
  1032.             /** #ABOUT_RAY_MARCH_LOOP# **/
  1033.  
  1034.                 //:March to VOXEL:
  1035.                 for( int i = 0; i < MAX_STE ; i++ ){
  1036.  
  1037.                     //:March by distance to next voxel:
  1038.                    
  1039.                     //:Point_Normal_Form_To_Get:xyz
  1040.                     xyz =
  1041.                         rwC
  1042.                     + ( rwN * vox_000.vod.dis_nex )
  1043.                     ;;
  1044.                
  1045.                         vox_000 =
  1046.                     GET_vox_000_USE_xyz_rwN(
  1047.                                     xyz,rwN );;
  1048.  
  1049.                     //:If voxel is not empty, ray march
  1050.                     //:inside of the voxel.
  1051.                     if( vox_000.voc.val > 0 ){
  1052.                     for( int v = 0; v < MAX_STE ; v++ ){
  1053.    
  1054.                         vox_mar =(
  1055.                         sdf_MarchIntoVoxel(
  1056.                             vox_000,xyz,rwN
  1057.                         ));;
  1058.  
  1059.                         if( vox_mar.exit >= U32(1) ){
  1060.  
  1061.                             c4d=V_4(0,1,0,1); //:GREEN
  1062.  
  1063.                             break;
  1064.                         };;
  1065.  
  1066.                     };;};;
  1067.  
  1068.                     /** Don't move the ray anywhere  **/
  1069.                     /** We are going to slice into   **/
  1070.                     /** whatever voxels the camera   **/
  1071.                     /** plane passes through.        **/
  1072.                     if( CFG_SLICE_RENDER >= 1 ){
  1073.                         break;
  1074.                     };;
  1075.  
  1076.                 };;
  1077.  
  1078.             //:-----------------------:RAY_MARCH_LOOP://
  1079.  
  1080.  
  1081.             if( CFG_SLICE_RENDER >= 1 ){
  1082.  
  1083.                 //:Layer value, 1 or 0
  1084.                 int lay = I32_MOD( T_Z, 2 );
  1085.                
  1086.                 //:#MODULO_CHECKER_PATTERN#://
  1087.                 int chk =(  
  1088.                     I32_MOD( //:<<<<<<<<<<<<<<:SET_003
  1089.                         I32_MOD( T_Y, 2 )   //:SET_YYY
  1090.                     +   I32_MOD( T_X, 2 )   //:SET_XXX
  1091.                     ,                 2
  1092.                     )
  1093.                 );;
  1094.            
  1095.                 if(   0 != 0
  1096.                 || ( lay < 0 )
  1097.                 || ( lay > 1 )
  1098.                 || ( chk < 0 || chk > 1 )
  1099.                 || ( HAS > uint(1)      )
  1100.                 ){
  1101.                     //: _0x010101_ & _0x101010_
  1102.                     c4d=PIX_ERR(ERR_001,c4d,o_k--);
  1103.                 };;
  1104.  
  1105.                
  1106.                 F32 M =( 255.0); //:Max RGB value.
  1107.                 F32 X =( 1.0  ); //:FOR_DEBUGGING_COLORS
  1108.              //:F32 ...........;    Replace with "_"
  1109.              //:F32 ...........;    when done debugging.
  1110.                 F32 a =( 1.0  ); //:ALPHA
  1111.                 F32 _ =( 0.0  );
  1112.                 F32 g =( F32(0x33)/M ); //:DARK-GREY
  1113.                 F32 G =( F32(0x38)/M );
  1114.                 F32 w =( F32(0xE5)/M ); //:WHITE-GREY
  1115.                 F32 W =( F32(0xF2)/M );
  1116.  
  1117.                 V_4 _0x333333_ =V_4(g,g,g,a);
  1118.                 V_4 _0x383838_ =V_4(G,G,G,a);
  1119.                 V_4 _0xE5E5E5_ =V_4(w,w,w,a);
  1120.                 V_4 _0xF2F2F2_ =V_4(W,W,W,a);
  1121.                 V_4 _0x003300_ =V_4(_,g,_,a);
  1122.                 V_4 _0x003800_ =V_4(_,G,_,a);
  1123.                 V_4 _0x00E500_ =V_4(_,w,_,a);
  1124.                 V_4 _0x00F200_ =V_4(_,W,_,a);
  1125.  
  1126.                 V_4 tab_000[8]=V_4[8](
  1127.                     //:OUT OF BOUNDS:       //:HAS?
  1128.                     _0x333333_ , _0x383838_ //:LAY0
  1129.                    ,_0xE5E5E5_ , _0xF2F2F2_ //:LAY1
  1130.                 //: |   CHK0   |     CHK1   |::::::::://
  1131.                                    
  1132.                     //:IN BOUNDS:           //:HAS?
  1133.                    ,_0x003300_ , _0x003800_ //:LAY0
  1134.                    ,_0x00E500_ , _0x00F200_ //:LAY1
  1135.                 //: |   CHK0   |     CHK1   |::::::::://
  1136.                 );;
  1137.                
  1138.                 I32 pik = (
  1139.                    (4 * ( HAS >= uint(1) ? 1 : 0 ))
  1140.                 +  (2 * lay ) //: LAY0 -or- LAY1
  1141.                 +  (1 * chk ) //: CHK0 -or- CHK1
  1142.                 );;
  1143.  
  1144.                 if( pik < 0 || pik >= 8 ){
  1145.                     c4d=PIX_ERR(ERR_002,c4d,o_k--);
  1146.                 };;
  1147.                
  1148.                 //:TODO: Why is not rendering as
  1149.                 //:      checker?
  1150.                 if( 1 == o_k ){
  1151.                     c4d = tab_000[ pik ];
  1152.                 };;
  1153.  
  1154.             }else{
  1155.                 //:DEBUG ONLY.
  1156.                 //:c4d=V_4(1,1,1,1);
  1157.             };;
  1158.  
  1159.             return( c4d );
  1160.         }
  1161.  
  1162.     #undef  T_X
  1163.     #undef  T_Y
  1164.     #undef  T_Z
  1165.     #undef  HAS
  1166.     //:==============================:sdf_RenderScene://
  1167.     //:=================================:RENDER_SCENE://
  1168.  
  1169. //:11111111111111111111111111111111111111111111111111://
  1170. //:00000000000000000000000000000000000000000000000000://
  1171.  
  1172.     void mainImage(
  1173.         out vec4 fragColor
  1174.     ,   in  V_2 fragCoord
  1175.     )
  1176.     {
  1177.            
  1178.         #define R_Y iResolution.y
  1179.             V_2 f_c = V_2(
  1180.             //:( FLIP? )       ( Discrete XY       ) ://
  1181.                (  0.0  )   +   ( fragCoord.x - 0.5 )
  1182.             ,  (R_Y-1.0)   -   ( fragCoord.y - 0.5 )
  1183.             );;
  1184.         #undef R_Y  
  1185.         V_2 f_p = f_c_CTO_f_p( f_c );
  1186.  
  1187.  
  1188.         //:CAMERA_RAY_FOR_CURRENT_PIXEL:-------------://
  1189.  
  1190.             /** The coordinate and direction of the  **/
  1191.             /** camera ray [rwC,rwN] are closely     **/
  1192.             /** related, so return them using the    **/
  1193.             /** same function. This will save        **/
  1194.             /** processing power when we decide      **/
  1195.             /** to create a camera lense that        **/
  1196.             /** is a 360 degree cylinder around      **/
  1197.             /** an object. (for fun)                 **/
  1198.  
  1199.             RWC_AND_RWN
  1200.             rwC_AND_rwN;
  1201.  
  1202.             rwC_AND_rwN = f_p_CTO_rwC_AND_rwN( f_p );
  1203.  
  1204.         //:-------------:CAMERA_RAY_FOR_CURRENT_PIXEL://
  1205.  
  1206.         fragColor = sdf_RenderScene( rwC_AND_rwN );
  1207.  
  1208.     }
  1209. //:00000000000000000000000000000000000000000000000000://
  1210. //:DOCUMENTATION:====================================://
  1211. /** ************************************************ ***
  1212.     ABBREVIATIONS:
  1213.  
  1214.         f : fragment
  1215.         p : percent (Never Position, use C for coord)
  1216.         c : coordinate
  1217.         r : ray
  1218.         n : normal, for directions.
  1219.         d : distance. NEVER DIRECTION.( use: n:normal )
  1220.        
  1221.     IDENTIFIERS:
  1222.  
  1223.         CTO: Convert_TO
  1224.         rwC: RayWorldCoord
  1225.         rwN: RayWorldNormal
  1226.         f_p: FragPercent
  1227.         f_c: FragCoord (With Discrete Pixel Coords)
  1228.                     (instead of pixel centers  )
  1229.         dad: Distance_And_inDEX
  1230.             Index is 1D index of XYZ voxel tile
  1231.             coordinate.
  1232.         vat: Voxel_Array__of__Tiles
  1233.         c4d: Color_4_Dimensional(RGBA)
  1234.  
  1235.     FUNCTIONS:
  1236.  
  1237.         f_c_CTO_f_p : FragmentCoord -CTO- FragPercent
  1238.         f_c_CTO_per : USE[ f_c_CTO_f_p ]
  1239.         sdf_i3d     : Interpolate_Two_3D_Points
  1240.  
  1241.     EXTRACTED_BLOCK_COMMENTS:
  1242.  
  1243.         #ABOUT_RAY_MARCH_LOOP###########################
  1244.  
  1245.             Ray marching loop should be able to look    
  1246.             at the current voxel coordinate returned    
  1247.             and decide to STOP marching if it wants.    
  1248.             By stopping immediately without marching    
  1249.             at all we can make the camera phosphore    
  1250.             surface a slice plane that renders          
  1251.             cross sectional views of tilemap data.      
  1252.    
  1253.         ##########################ABOUT_RAY_MARCH_LOOP##
  1254.         #POSITIVE_Z_DIVES_INTO_SCREEN###################
  1255.  
  1256.             Positive Z is further back into screen.
  1257.             This way to help normalize voxel grid math.
  1258.        
  1259.         ###################POSITIVE_Z_DIVES_INTO_SCREEN#
  1260.         #FIND_POINT_ON_SCREEN_PLANE#####################
  1261.  
  1262.             ORIGINAL_COMMENT:
  1263.  
  1264.                 Polygon in 3d space to serve as the
  1265.                 phosphor surface the CRT monitor
  1266.                 electrons will be projected onto.
  1267.                 Could probably use a mat4 for this.
  1268.  
  1269.             MORE_INFORMATION_IN_RETROSPECT:
  1270.  
  1271.                 "Screen Plane" is also known as
  1272.                 "CRT Phospore" or "PHO" for short.
  1273.                 This is a plane put into 3D space that
  1274.                 represents the pixels of the client
  1275.                 viewport (physical monitor).
  1276.  
  1277.                 The "IMAGE" plane from this diagram:
  1278.                 https://tinyurl.com/IMAGE-PLANE
  1279.  
  1280.         #####################FIND_POINT_ON_SCREEN_PLANE#
  1281.         #MODULO_CHECKER_PATTERN#########################
  1282.  
  1283.             // Checker pattern value, 1 or 0.         //
  1284.             // Combine Sets so that they create       //
  1285.             // a checkerboard of odd/even values,     //
  1286.             // and then convert even to 0 and         //
  1287.             // odd to 1.                              //
  1288.             //                                        //
  1289.             // SET_YYY:[ 0 1 0 1 0 1 0 ]              //
  1290.             // SET_XXX:[ 0 1 0 1 0 1 0 ]              //
  1291.             //                                        //
  1292.             // SET_XXX:     [ 0 1 0 1 0 1 0 ]         //
  1293.             //                | | | | | | |           //
  1294.             // SET_YYY:[ 0 ]- 0 1 0 1 0 1 0           //
  1295.             //         [ 1 ]- 1 2 1 2 1 2 1           //
  1296.             //         [ 0 ]- 0 1 0 1 0 1 0           //
  1297.             //         [ 1 ]- 1 2 1 2 1 2 1           //
  1298.             //         [ 0 ]- 0 1 0 1 0 1 0           //
  1299.             //         [ 1 ]- 1 2 1 2 1 2 1           //
  1300.             //         [ 0 ]- 0 1 0 1 0 1 0           //
  1301.             int chk =(  
  1302.                 I32_MOD( // <<<<<<<<<<<<<< SET_003
  1303.                     I32_MOD( T_Y, 2 )   // SET_YYY
  1304.                 +   I32_MOD( T_X, 2 )   // SET_XXX
  1305.                 ,                 2
  1306.                 )
  1307.             );;
  1308.  
  1309.         #########################MODULO_CHECKER_PATTERN#
  1310.         #CONSISTENT_VOXEL_COORDS########################
  1311.  
  1312.             The tilemap math for calculating what
  1313.             [voxel/tile] we are inside of is
  1314.             geometrically consistent, even when
  1315.             given NEGATIVE numbers.
  1316.  
  1317.             Meaning: The FIRST PIXELS of any
  1318.                      [tile/voxel] are in the same
  1319.                      relative position.
  1320.  
  1321.             +-+-----+-+-----+-+-----+-+-----+
  1322.             | | -1  | |  0  | |  +1 | |  +2 |
  1323.             | |     | |     | |     | |     |
  1324.             | +-----| +-----| +-----| +-----+
  1325.             +-------+-------+-------+-------+
  1326.  
  1327.             +-+
  1328.             | |   <--- The first edge of pixels for
  1329.             | |        [voxel/tile] seen on the X/Y
  1330.             | +-----|  axis.
  1331.             +-------+
  1332.         ########################CONSISTENT_VOXEL_COORDS#
  1333.         #NEXT_VOXEL_BOUNDING_VOLUME#####################
  1334.  
  1335.             Assuming vectors are moving in a positive
  1336.             direction, the intersection point to
  1337.             next voxel MUST be within the bounds of
  1338.             the CURRENT VOXEL + One Pixel All Around.
  1339.  
  1340.             Because we know the DIRECTION of the
  1341.             ray vector, we don't need a bounding volume
  1342.             and can just check that the respective
  1343.             X,Y,Z bounding planes have
  1344.             not been exceeded.
  1345.  
  1346.             +--------------------+--------------------+
  1347.             |                    |                    |
  1348.             |   +- - -  - - -+   |   +- - -  - - -+   |
  1349.             |   |            |   |   |            |   |
  1350.             |                    |                    |
  1351.             |   |            |   |   |            |   |
  1352.             |                    |                    |
  1353.             |   |            |   |   |            |   |
  1354.             |   +- - -  - - -+   |   +- - -  - - -+   |
  1355.          111111111111111111111111111                  |
  1356.          1  +--------------------+-1------------------+
  1357.          1  |                    | 1                  |
  1358.          1  |   +- - -  - - -+   | 1 +- - -  - - -+   |
  1359.          1  |   |            |   | 1 |            |   |
  1360.          1  |                    | 1                  |
  1361.          1  |   |     CV     |   | 1 |            |   |
  1362.          1  |     (CurVoxel)     | 1                  |
  1363.          1  |   |            |   | 1 |            |   |
  1364.          1  |   +- - -  - - -+   | 1 +- - -  - - -+   |
  1365.          1  |                    | 1                  |
  1366.          1  +--------------------+-1------------------+
  1367.          111111111111111111111111111
  1368.  
  1369.         #####################NEXT_VOXEL_BOUNDING_VOLUME#
  1370.         #VOX_MAR_ABOUT##################################
  1371.  
  1372.             VOX_MAR: ( VOXel_MARch )
  1373.  
  1374.                     Holds information about ray
  1375.                     marching WITHIN a single voxel.
  1376.  
  1377.         ##################################VOX_MAR_ABOUT#
  1378.  
  1379.  
  1380. *** ************************************************ **/
  1381. //:====================================:DOCUMENTATION://
  1382. //:UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU://
  1383. /** U : Undefine Macros Section **/
  1384.  
  1385.     #undef  V_4  
  1386.     #undef  V_3  
  1387.     #undef  V_2  
  1388.     #undef  F32  
  1389.     #undef  I32  
  1390.     #undef  U32  
  1391.  
  1392. /** U : Undefine Macros Section **/
  1393. //:UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU://
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement