Advertisement
DEKTEN

SDF_007

Nov 23rd, 2020 (edited)
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //: Voxel Renderer For Utility Patents
  2. //: SOURCE_URL: https://pastebin.com/RuZCTEhw
  3. //: ALIAS__URL: https://tinyurl.com/SDF-007
  4. //: On My Hard Disk As: SC_FILES\MATH\SDF\MY_SHADE\SDF_007._
  5.  
  6. //: Abbreviations:
  7. //: f : fragment
  8. //: p : percent (Never Position, use C for coord)
  9. //: c : coordinate
  10. //: r : ray
  11. //: n : normal, for directions.
  12. //: d : distance. NEVER DIRECTION.( use: n:normal )
  13.  
  14. //: Identifiers:
  15. //: CTO: Convert_TO
  16. //: rwC: RayWorldCoord
  17. //: rwN: RayWorldNormal
  18. //: f_p: FragPercent
  19. //: f_c: FragCoord (With Discrete Pixel Coords)
  20. //:                (instead of pixel centers  )
  21. //: dad: Distance_And_inDEX
  22. //:      Index is 1D index of XYZ voxel tile
  23. //:      coordinate.
  24. //: vat: Voxel_Array__of__Tiles
  25.  
  26. //:These defines are for ray marching when using
  27. //:fragment coordinates as our coordinate space.
  28. #define MAX_STE 1000   //:Max Steps
  29. #define MIN_DIS 0.02   //:Min Distance (SurfaceDist)
  30. #define MAX_DIS 1000.0 //:Max Distance
  31.  
  32. //:Number of tiles on each axis:
  33. #define NTX  8  //:Num_Tiles (   in_voxel_map )
  34. #define NTY  4  //:Num_Tiles (   in_voxel_map )
  35. #define NTZ  3  //:Num_Tiles (   in_voxel_map )
  36.  
  37. #define NPX  16 //:Num_Pixels_X( in_a_tile    )
  38. #define NPY  16 //:Num_Pixels_Y( in_a_tile    )
  39. #define NPZ  16 //:Num_Pixels_Z( in_a_tile    )
  40.  
  41. //:Total__number_of__Pixels__in_entire_voxel_map
  42. #define TPX  ( NTX * NPX ) //: Total_Pixels_X
  43. #define TPY  ( NTY * NPY ) //: Total_Pixels_Y
  44. #define TPZ  ( NTZ * NPZ ) //: Total_Pixels_Z
  45.  
  46. #define _ 0                                          
  47. #define X 1                                          
  48. int vat[ NTX * NTY * NTZ ]=int[ 8 * 4 * 3 ](                
  49.    
  50. //:Highest Z Cross Section Is First Tile Map
  51. //: 1 2 3 4 5 6 7 8        --- ---------------------
  52.     X,X,X,X,X,X,X,X, //: 1  |             ^
  53.     X,_,_,_,_,_,_,X, //: 2  | Z == 0      |
  54.     X,_,_,_,_,_,_,X, //: 3  |             |
  55.     X,X,X,X,X,X,X,X, //: 4  |             |
  56. //:                        ---            |
  57. //: 1 2 3 4 5 6 7 8        ---        Cross Sections
  58.     X,_,_,_,_,_,_,X, //: 1  |         Can be thought
  59.     _,_,_,_,_,_,_,_, //: 2  | Z == 1  of as differ-
  60.     _,_,_,_,_,_,_,_, //: 3  |         -ent 2D
  61.     X,_,_,_,_,_,_,X, //: 4  |         tilemaps.
  62. //:                        ---            |
  63. //: 1 2 3 4 5 6 7 8        ---            |
  64.     X,_,_,_,_,_,_,X, //: 1  |             |
  65.     X,_,_,_,_,_,_,X, //: 2  | Z == 2      |
  66.     X,_,_,_,_,_,_,X, //: 3  |             |
  67.     X,_,_,_,_,_,_,X  //: 4  |             V
  68. //:                        --- ---------------------
  69. );                                                
  70. #undef  _                                            
  71. #undef  X  
  72.  
  73.     struct SDF_DAD{
  74.  
  75.         vec4  d_S;
  76.         //:   d_S.x : Distance From x edges.
  77.         //:   d_S.y : Distance From y edges.
  78.         //:   d_S.z : Distance From z edges.
  79.         //:   d_S.w : Distance From Entire Volume
  80.  
  81.         float dex;
  82.  
  83.     };
  84.  
  85. //:INTERPOLATE:3D:===============================://
  86.  
  87.     vec3 I3D(
  88.         vec3  c_1 //:Starting Point (  0%)
  89.     ,   vec3  c_2 //:Ending   Point (100%)
  90.     ,   float per //:Percent as 0.0 to 1.0
  91.     )  
  92.     {
  93.         return(vec3(
  94.             c_1.x + ((c_2.x - c_1.x)*per)
  95.         ,   c_1.y + ((c_2.y - c_1.y)*per)
  96.         ,   c_1.z + ((c_2.z - c_1.z)*per)
  97.         ));;
  98.     }
  99.  
  100. //:===============================:INTERPOLATE:3D://
  101. //:RAY_WORLD:(Camera):===========================://
  102.  
  103.     vec3    f_p_CTO_rwC( vec2 f_p ){
  104.     vec3    /*OUT*/ rwC;
  105.  
  106.         /** Z-DOWN ----------------------------- **/
  107.         /** Usually I like Z-UP, but it makes    **/
  108.         /** more Sense for Z-DOWN so POSITIVE    **/
  109.         /** Z values map to POSITIVE Z tile      **/
  110.         /** values.                              **/
  111.         /** ------------------------------------ **/
  112.      
  113.         //:Minus 1.0 because first coord is [0,0]
  114.         float X = ( iResolution.x - 1.0  );
  115.         float Y = ( iResolution.y - 1.0  );
  116.  
  117.         //:Camera Height Above Voxel Map Volume:
  118.         float H =max( X,Y );
  119.  
  120.         //:Zero as underscore for cleanliness
  121.         float _ =( 0.0 );
  122.  
  123.         //: Simple polygon above XY plane for now.
  124.         vec3 _A_ = vec3(  _ , _ , _-H ); //:TOP:LEF
  125.         vec3 _B_ = vec3(  X , _ , _-H ); //:TOP:RIG
  126.         vec3 _C_ = vec3(  _ , Y , _-H ); //:BOT:LEF
  127.         vec3 _D_ = vec3(  X , Y , _-H ); //:BOT:RIG
  128.  
  129.         vec3 A_B = I3D( _A_ , _B_ , f_p.x );
  130.         vec3 C_D = I3D( _C_ , _D_ , f_p.x );
  131.              rwC = I3D( A_B , C_D , f_p.y );
  132.  
  133.  
  134.         //:TRAP_VALUE_Z_COORD:-------------------://
  135.  
  136.             /** DEBUG:                  **/
  137.             /** rwC should be NEGATIVE  **/
  138.             /** rwC should be (_-H)     **/
  139.  
  140.             if( rwC.z != _-H || rwC.z >= 0.0 ){
  141.                 rwC.z = 666.0 ;
  142.             };;
  143.             if( rwC.x < 0.0 || rwC.y < 0.0 ){
  144.                 rwC.z = 666.0 ;
  145.             };;
  146.  
  147.         //:-------------------:TRAP_VALUE_Z_COORD://
  148.  
  149.     return( rwC /** RAY_WORLD:Coord:XYZ **/ );  
  150.     }
  151.     //:- - - - - - - - - - -- - - - - - - - - - -://
  152.     vec3    f_p_CTO_rwN( vec2 f_p , vec3 lac ){
  153.     vec3    /*OUT*/ rwN;
  154.  
  155.         //:Not using look at coordinate XYZ
  156.         //:at this point in time.
  157.         if( length(lac) > 0.0 ){ /** NOOP **/ };
  158.  
  159.         //:For now, keep simple. Later the
  160.         //:vector can conform to the normals of
  161.         //:the screen surface we are mapping
  162.         //:onto in the f_p_CTO_rwC function.
  163.  
  164.         //:TEMP: Hardcode as pointing straight down.
  165.         rwN=normalize(vec3(
  166.             /* rwN.x */ 0.0
  167.         ,   /* rwN.y */ 0.0
  168.         ,   /* rwN.z */ 0.0 + 1.0 //:Z-DOWN
  169.         ));;
  170.  
  171.     return( rwN /** RAY_WORLD:Normal(dir) **/ );
  172.     }
  173. //:===========================:RAY_WORLD:(Camera)://
  174.  
  175. //: FragCoord(f_c) ConvertTo(CTO) FragPercent(f_p)
  176. vec2 f_c_CTO_f_p( vec2 f_c ){
  177.  
  178.     #define MAXINDEX_X ( iResolution.x - 1.0 )
  179.     #define MAXINDEX_Y ( iResolution.y - 1.0 )
  180.  
  181.         return(vec2( f_c.x / MAXINDEX_X
  182.                    , f_c.y / MAXINDEX_Y ));;
  183.  
  184.     #undef  MAXINDEX_X  
  185.     #undef  MAXINDEX_Y  
  186. }
  187.  
  188. //:min function taking 3 floats. If only called
  189. //:from ONE spot in code, keep formal parameter
  190. //:names IDENTICAL to actual parameter names.
  191. //:( AKA: param names === argument names )
  192. float min_f32_003(
  193.     float d_x
  194. ,   float d_y
  195. ,   float d_z
  196. ){
  197.     return( min( min(d_x,d_y) , d_z ) );
  198. }
  199.  
  200. float max_f32_003(
  201.     float d_x
  202. ,   float d_y
  203. ,   float d_z
  204. ){
  205.     return( max( max(d_x,d_y) , d_z ) );
  206. }
  207.  
  208. //:ctz: Return Closest To Zero.
  209. float sdf_ctz_f32_002(
  210.     float d_1 //:SIGNED INPUT
  211. ,   float d_2 //:SIGNED INPUT
  212. ){
  213.  
  214.     float out_var;
  215.     if( abs(d_1) < abs(d_2) ){
  216.         out_var = ( d_1 );
  217.     }else{
  218.         out_var = ( d_2 );
  219.     };;
  220.  
  221.     return( out_var );
  222. }
  223. float sdf_ctz_f32_003(
  224.     float d_1
  225. ,   float d_2
  226. ,   float d_3
  227. ){
  228.     return sdf_ctz_f32_002(
  229.  
  230.            sdf_ctz_f32_002( d_1 , d_2 )
  231.                                 , d_3
  232.  
  233.     );;
  234. }
  235.  
  236. float sdf_neg_min_002(
  237.     float d_1
  238. ,   float d_2
  239. ){
  240.     float out_var;
  241.  
  242.     if( d_1 < 0.0 && d_2 >= 0.0 ){
  243.         //:Negative Number Wins.
  244.         out_var = d_1;
  245.     }else
  246.     if( d_2 < 0.0 && d_1 >= 0.0 ){
  247.         //:Negative Number Wins.
  248.         out_var = d_2;
  249.     }else
  250.     if( d_1 >= 0.0 && d_2 >= 0.0 ){
  251.  
  252.         //:Closet To Zero Wins:
  253.         out_var=( min( d_1 , d_2 ) );
  254.  
  255.     }else
  256.     if( d_1 <= 0.0 && d_2 <= 0.0 ){
  257.  
  258.         out_var=( max( d_1 , d_2 ) );
  259.     }else{
  260.         //:UNEXPECTED:EDCL
  261.         out_var = ( d_1 + d_2 ) / 2.0 ;
  262.  
  263.     };;
  264.  
  265.     return( out_var );
  266. }
  267.  
  268. float sdf_neg_min_003(
  269.     float d_1
  270. ,   float d_2
  271. ,   float d_3
  272. ){
  273.     return sdf_neg_min_002(
  274.  
  275.            sdf_neg_min_002( d_1 , d_2 )
  276.                                 , d_3
  277.  
  278.     );;
  279. }
  280.  
  281. //: When ray marching need to know both the      ://
  282. //: DISTANCE to geometry, and what voxel cell    ://
  283. //: we are inside of. Knowing the voxel cell     ://
  284. //: will allow us to figure out local coordinates://
  285. //: within the cell as well as the material type ://
  286. //: assigned to that well.                       ://
  287. SDF_DAD    sdf_Get_dad( vec3 xyz ){
  288. SDF_DAD            dad             ;
  289.                    dad.d_S.w = 0.0 ;
  290.                    dad.dex   = 0.0 ;
  291.                    //:d_S: Distance To Geom Surf
  292.                    //:dex: Voxel Cell XY as index          
  293.  
  294.     //:Determine What Tile XYZ you are in.
  295.     //:To simplify problem, imagine an infinite
  296.     //:voxel grid, and your model DEFAUTLING
  297.     //:to having it's origin voxel at [0,0,0]
  298.     //:in this infinite grid. We can translate
  299.     //:it later, but right now keep a fixed
  300.     //:origin. Where voxel [0,0,0]'s top-left-back
  301.     //:is at xyz( 0, 0, 0 ) in our world space.
  302.  
  303.     //:What is the size of each voxel in world
  304.     //:space units? World space units are in
  305.     //:frag coords, so think of voxel as 3D tile
  306.     //:who's size is measured in [pixels/frags].
  307.     //:Lets say... 16-x-16-x-16 pixels because
  308.     //:it will be easy to hard code small pieces
  309.     //:of art for each material type later.
  310.     //:Material types being associated with the
  311.     //:tile type stored in[  vat   ].
  312.  
  313.     #define F32_TPX  float( TPX )
  314.     #define F32_TPY  float( TPY )
  315.     #define F32_TPZ  float( TPZ )
  316.  
  317.     //# THIS DISTANCE CALCULATION IS WRONG!!!!!  #//
  318.     //# Faulting Logic. Think it over....        #//
  319.     //# Try again tomorrow maybe?                #//
  320.     //:Distance_Calc:----------------------------://
  321.         float d_x,d_y,d_z;
  322.        
  323.         #define X xyz.x
  324.         #define Y xyz.y
  325.         #define Z xyz.z
  326.        
  327.         //: d_x = min( abs(X) , abs(X - F32_TPX ) );
  328.         //: d_y = min( abs(Y) , abs(Y - F32_TPY ) );
  329.         //: d_z = min( abs(Z) , abs(Z - F32_TPZ ) );
  330.  
  331.         #define C sdf_neg_min_002
  332.         d_x =   max(
  333.             0.0 - X , X - (F32_TPX - 1.0)
  334.         );;
  335.         d_y =   max(
  336.             0.0 - Y , Y - (F32_TPX - 1.0)
  337.         );;
  338.         d_z =   max(
  339.             0.0 - Z , Z - (F32_TPX - 1.0)
  340.         );;
  341.         #undef  C
  342.  
  343.         #undef  X  
  344.         #undef  Y  
  345.         #undef  Z  
  346.        
  347.         #define MAX_003 max_f32_003
  348.         #define MIN_003 min_f32_003
  349.  
  350.             dad.d_S.x = d_x ;
  351.             dad.d_S.y = d_y ;
  352.             dad.d_S.z = d_z ;
  353.             dad.d_S.w = MIN_003(
  354.                 abs( d_x )
  355.             ,   abs( d_y )
  356.             ,   abs( d_z )
  357.             );;
  358.  
  359.         #undef  MAX_003
  360.         #undef  MIN_003
  361.     //:----------------------------:Distance_Calc://
  362.  
  363.     //:[HACK]:Round to zero if close enough:
  364.     if( abs(xyz.x) <= 0.0008 ){ xyz.x = 0.0; };
  365.     if( abs(xyz.y) <= 0.0008 ){ xyz.y = 0.0; };
  366.     if( abs(xyz.z) <= 0.0008 ){ xyz.z = 0.0; };
  367.    
  368.     if( xyz.x < 0.0  
  369.     ||  xyz.y < 0.0
  370.     ||  xyz.z < 0.0 //:Z-AXIS:THIS_IS_A_PROBLEM_HERE
  371.     ){
  372.         //:Negative Out Of Bounds Debugging:
  373.         dad.dex = float( 0.0 - 222.0 );
  374.     }else
  375.     if( xyz.x >= F32_TPX  
  376.     ||  xyz.y >= F32_TPY  
  377.     ||  xyz.z >= F32_TPZ  
  378.     ){  //:Outside of voxel map bounds:
  379.  
  380.         /** Return distance to entire voxel map, **/
  381.         /** rather than distance to a specific   **/
  382.         /** tile in tilemap.                     **/
  383.  
  384.         dad.dex = float( 0 - 1 );
  385.         //: dex: Negative For Invalid Voxel
  386.         //: ---: Cell since outside bounds.
  387.  
  388.  
  389.     }else{ //:Inside voxel map bounds.
  390.  
  391.         //:TEMP_NOTE: #DIVIDE_AND_CONQUERE#
  392.         //:Before we worry about the individual
  393.         //:voxel tiles, lets make sure we can
  394.         //:render the entire voxel volume as a
  395.         //:cube.
  396.  
  397.         //:[TEMP]:[HACK]:
  398.         //: If we are inside bounding voxel tilemap,
  399.         //: always return tile #1. Change this once
  400.         //: we confirm the volume looks correct.
  401.         dad.dex =float( 1 );
  402.  
  403.     };;
  404.     #undef  F32_TPX   //:Float32:Total_Pixels_X
  405.     #undef  F32_TPY   //:Float32:Total_Pixels_Y  
  406.     #undef  F32_TPZ   //:Float32:Total_Pixels_Z  
  407.  
  408. return( dad );
  409. }
  410.  
  411. vec4 sdf_RenderScene( vec3 rwC , vec3 rwN ){
  412. vec4 /** OUTPUT_VAR **/ col=vec4(1,0,0, 1.0);
  413.  
  414.     //:xyz coordinate of point sliding along
  415.     //:ray using point normal form to move it.
  416.     vec3  xyz=vec3( rwC );
  417.  
  418.     float d_S            ; //:UNKNOWN_when_declared
  419.     float d_O = 0.0      ; //:Distance__from__Origin
  420.  
  421.     //:Distance_AND_tileinDEX
  422.     SDF_DAD  dad;
  423.  
  424.     //:Thought: Use DECIMAL portion to get the
  425.     //:         local percentage coordinates within
  426.     //:         voxel cell identified by integer
  427.     //:         portion of[ dex ].
  428.     float dex = 0.0 - 777.0; //:voxel_cell_1d_inDEX
  429.  
  430.     //:Ray marching loop: ( Raymarch into scene )
  431.     for( int i = 0; i < MAX_STE; i++ ){
  432.  
  433.         //:First Used Value:[ xyz === rwC ]
  434.         xyz = rwC + ( rwN * d_O );
  435.  
  436.         dad = sdf_Get_dad( xyz );
  437.         d_S = dad.d_S.w  ;
  438.         dex = dad.dex;
  439.  
  440.         //: At THIS POINT IN TIME:
  441.         //: d_S & d_O agree with each other.
  442.  
  443.         //:Lets not worry about off-by-1 errors
  444.         //:here. Tolerances are mostly a rough
  445.         //:art form than an exact value.
  446.         if( d_S <= MIN_DIS ){
  447.  
  448.             if( d_S >= 0.0 ){
  449.  
  450.                 xyz = xyz + ( rwN * (d_S*1.0) );
  451.                 dad = sdf_Get_dad( xyz );
  452.                 d_S = dad.d_S.w;
  453.                 dex = dad.dex;
  454.             };;
  455.  
  456.             break;
  457.         }else
  458.         if( d_O >= MAX_DIS ){
  459.             break; //:Way off in outer space.
  460.         };;
  461.  
  462.         //: Prep for next loop iteration.
  463.         //: d_S & d_O no longer agree.
  464.         d_O = d_O + d_S ;
  465.  
  466.     };;
  467.  
  468.         //:xyz + ( rwN
  469.  
  470.  
  471.     float min_voxel_side_length_2d=(
  472.         float( TPX )
  473.     ,   float( TPY )
  474.     //: float( TPZ ) REMOVED Z ://
  475.     );;
  476.  
  477.     //: ( d_S == dgs )                           ://
  478.     //: SDF_007._ : d_S                          ://
  479.     //: SDF_006._ : dgs (dist_from_geom_surface )://
  480.     //:                                          ://
  481.     //:We want a value we can multiply light     ://
  482.     //:vector with. So invert distance value     ://
  483.     //:& clamp distance value in [0,1] range.    ://
  484.     float hit =( 1.0 -
  485.  
  486.         max(0.0, min(1.0,
  487.  
  488.             //: Gradate The Hit Volume:
  489.             min( abs(dad.d_S.x)
  490.             ,    abs(dad.d_S.y) )
  491.  
  492.             /
  493.  
  494.             ( min_voxel_side_length_2d / 2.0 )
  495.  
  496.         ) )
  497.  
  498.     );;
  499.  
  500.     //:Light Intensity will consist of
  501.     //:RGB diffuse and a self-illumination value
  502.     //:to allow materials to emit light in the
  503.     //:future.
  504.     vec4  l_i ; //:= vec4(0,1,0,1);
  505.  
  506.     //: Change Material Type:
  507.     if( int( dex ) ==  int( 777.0 )  ){
  508.  
  509.         /** Trap Value To Indicate Error **/
  510.         /** DARK_RED: ERROR **/
  511.         l_i.x = 0.5; //: R
  512.         l_i.y = 0.0; //: G
  513.         l_i.z = 0.0; //: B
  514.         l_i.w = 1.0; //: L self illumination
  515.  
  516.     }else
  517.     if( int( dex ) == int( 0.0 - 222.0 ) ){
  518.    
  519.         if( d_S >= 0.0 ){
  520.  
  521.             //:Strobbing pixel means you are close
  522.             //:enough to the volume but on the
  523.             //:WRONG FUCKING SIDE OF IT.
  524.             //:Negative out of bounds:
  525.             l_i.x = mod( iTime * 16.0 , 1.0 );
  526.             l_i.y = mod( iTime * 16.0 , 1.0 );
  527.             l_i.z = mod( iTime * 16.0 , 1.0 );
  528.             l_i.w = 1.0; //: L self illumination
  529.  
  530.         }else{
  531.  
  532.             //:Negative out of bounds:
  533.             l_i.x = 0.0; //: R
  534.             l_i.y = 0.0; //: G
  535.             l_i.z = 0.0; //: B
  536.             l_i.w = 1.0; //: L self illumination
  537.  
  538.         };;
  539.  
  540.     }else
  541.     if( int( dex ) < 0 ){
  542.  
  543.         //:Out of bounds material is BLUE
  544.         l_i.x = 0.1; //: R
  545.         l_i.y = 0.1; //: G
  546.         l_i.z = 1.0; //: B
  547.         l_i.w = 1.0; //: L self illumination
  548.  
  549.     }else
  550.     if( int( dex ) == 1 ){
  551.  
  552.         //:Only known material is GREEN for now.
  553.         l_i.x = 0.0; //: R
  554.         l_i.y = 1.0; //: G
  555.         l_i.z = 0.0; //: B
  556.         l_i.w = 1.0; //: L self illumination
  557.  
  558.     }else{
  559.         //:Unknown Material Type : ORANGE
  560.         l_i.x = 1.0; //: R
  561.         l_i.y = 0.5; //: G
  562.         l_i.z = 0.0; //: B
  563.         l_i.w = 1.0; //: L self illumination
  564.     };;
  565.  
  566.     //:DEBUG: Strobe if distance from surface
  567.     //:       is POSITIVE. We want to be slightly
  568.     //:       inside, never slightly outside.
  569.     if( d_S > 0.0 ){
  570.         l_i = l_i * ( cos( iTime * 8.0 ) );
  571.     };;
  572.  
  573.     //:AKA: col = hit * l_i
  574.     col = vec4(
  575.         hit * l_i.x
  576.     ,   hit * l_i.y
  577.     ,   hit * l_i.z
  578.     ,   hit * l_i.w
  579.     );;
  580.  
  581.  
  582.     //:Lighting
  583.  
  584.     return( col /** OUTPUT_VAR **/ );
  585. }
  586.  
  587. void mainImage( out vec4 fragColor, in vec2 fragCoord )
  588. {
  589.     //:f_c:FragCoord_With_Graphics_Origin_Top_Left:
  590.     //:DISCRETE_X and DESCRETE_Y used to convert
  591.     //:from opengl pixel center model to raster
  592.     //:graphics discrete pixel model.
  593.     #define DISCRETE_X (   fragCoord.x - 0.5 )
  594.     #define DISCRETE_Y (   fragCoord.y - 0.5 )
  595.     #define MAXINDEX_Y ( iResolution.y - 1.0 )
  596.     vec2 f_c =vec2(
  597.         (     0.0      + DISCRETE_X  )
  598.     ,   (  MAXINDEX_Y  - DISCRETE_Y  )
  599.     );;
  600.  
  601.     #undef  DISCRETE_X
  602.     #undef  DISCRETE_Y
  603.     #undef  MAXINDEX_Y
  604.  
  605.     //:Figure out current camera ray. Abstract
  606.     //:the surface we are mapping ray coords
  607.     //:onto into functions so that we may easily
  608.     //:edit the functions to wrap the camera
  609.     //:around a cylinder if we want.
  610.     vec3  lac; //:Look_At_Coordinate
  611.     vec2  f_p; //:FragPer:(2d mapping onto 3d plane)
  612.     vec3  rwC; //:Ray: COORD XYZ
  613.     vec3  rwN; //:Ray: NORM(dir)
  614.  
  615.     lac = vec3( 0,0,0 );
  616.     f_p = f_c_CTO_f_p( f_c       );
  617.     rwC = f_p_CTO_rwC( f_p       );
  618.     rwN = f_p_CTO_rwN( f_p , lac );
  619.  
  620.     //: f_p : Looks_Correct , 100% confident
  621.     //: rwC : Looks_Correct , 100% confident
  622.     //: rwN : Looks_Correct , 100% confident
  623.  
  624.    //: fragColor=vec4(
  625.    //:     rwC.x / iResolution.x
  626.    //: ,   rwC.y / iResolution.y
  627.    //: ,   0.0 //:BLUE
  628.    //: ,   1.0 //:Alpha
  629.    //: );;
  630.  
  631.     if( rwC.z == 666.0 ){ //:Trap Value
  632.  
  633.         fragColor=vec4(1,0,1, 1.0 );
  634.  
  635.     }else{
  636.  
  637.         fragColor = sdf_RenderScene( rwC , rwN );
  638.  
  639.     };;
  640. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement