step up voxel raymarching

mail@pastecode.io avatar
unknown
glsl
a year ago
3.7 kB
16
Indexable
Never
if (OctreeLevel == 0)
         {
            if (Temporary_Step_UP_Counter > Temporary_Step_UP_Threshold)//  && !StepDown_Threshold)
            {
               Init_Step_Down = true;
               if (OctreeLevel == 0)
                  OctreeLevel = 1;
               if (OctreeLevel == 1)
                  OctreeLevel = 2;
               if (OctreeLevel == 2)
                  OctreeLevel = 4;            
            
               if (OctreeLevel == 1)
               {
                  Temporary_Step_UP_Counter = 0;
                  Temporary_Step_UP_Threshold = 32;
               }
               else if (OctreeLevel == 2)
               {
                  Temporary_Step_UP_Counter = 0;
                  Temporary_Step_UP_Threshold = 32;
               }
               else if (OctreeLevel == 4)
               {
                  Temporary_Step_UP_Threshold = 32;
                  Temporary_Step_UP_Counter = -1;
               //ends step up routine
               }
            
               Step_Up_On_Collision = true;
            }
            if (Graphics_Settings[8].status == 1 && Init_Step_Down)
            {

               Step_Back_Up_Counter++;
            
            
               float3 Octree_Pos_floored = float3(floor(Octree_Pos.x), floor(Octree_Pos.y), floor(Octree_Pos.z));

               float4 Raycast_StepUp = RayBoxIntersect(origin, direction, Octree_Pos_floored, Octree_Pos_floored + float3(Octree_Scale, Octree_Scale, Octree_Scale));
               float3 Step_Up_Origin = origin + direction * Raycast_StepUp[3];            
            
               if (OctreeLevel == 0)
               {
                  Octree_Scale = 1.0;
               }
               else if (OctreeLevel == 1)
               {
                  Octree_Scale = 2;
               }
               else if (OctreeLevel == 2)
               {
                  Octree_Scale = 4;
               }
               else if (OctreeLevel == 3)
               {
                  Octree_Scale = 8;
               }
               else if (OctreeLevel == 4)
               {
                  Octree_Scale = 16;
               }
               else if (OctreeLevel == 5)
               {
                  Octree_Scale = 32;
               }
            
               float3 Step_Up_Origin_floored = float3(floor(Step_Up_Origin.x), floor(Step_Up_Origin.y), floor(Step_Up_Origin.z));
            
               ix = Step_Up_Origin_floored[0];
               iy = Step_Up_Origin_floored[1];
               iz = Step_Up_Origin_floored[2];

               xDir = (direction.x > 0) ? Octree_Scale : (direction.x < 0) ? -Octree_Scale : 0;
               yDir = (direction.y > 0) ? Octree_Scale : (direction.y < 0) ? -Octree_Scale : 0;
               zDir = (direction.z > 0) ? Octree_Scale : (direction.z < 0) ? -Octree_Scale : 0;

               xBound = ((xDir > 0) ? ix + Octree_Scale : ix);
               yBound = ((yDir > 0) ? iy + Octree_Scale : iy);
               zBound = ((zDir > 0) ? iz + Octree_Scale : iz);

               xDelta = xDir / direction.x;
               yDelta = yDir / direction.y;
               zDelta = zDir / direction.z;

               xt = Octree_Scale * (xBound - Step_Up_Origin.x) / (direction.x * Octree_Scale);
               yt = Octree_Scale * (yBound - Step_Up_Origin.y) / (direction.y * Octree_Scale);
               zt = Octree_Scale * (zBound - Step_Up_Origin.z) / (direction.z * Octree_Scale);
                    
               Input_Voxel_Hit.World_Pos = Octree_Pos;
            }
         }