         if(fCurrSampledHeight > fCurrRayHeight)
         {
             float delta1 = fCurrSampledHeight - fCurrRayHeight;
-            float delta2 = (fCurrRayHeight + fStepSize) + fLastSampledHeight;
+            float delta2 = (fCurrRayHeight + fStepSize) - fLastSampledHeight;
 
             float ratio = delta1 / (delta1 + delta2);
-            vCurrOffset = (ratio) * vLastOffset + (1 - ratio) * vCurrOffset;
+            vCurrOffset = (ratio) * vLastOffset + (1.0 - ratio) * vCurrOffset;
             nCurrSample = nNumSamples + 1;
         }
         else


void main(void)
{
    /*vec3 vL = normalize(v_vTLight);
    vec3 vE = normalize(v_vTEye);
    vec3 vN = normalize(v_vTNormal);

    // parallax occlusion
    float fParallaxLimit = -length(v_vTEye.xy) / v_vTEye.z;
    fParallaxLimit *= 0.1; // scale

    vec2 vOffset = normalize(v_vTEye.xy);
    vec2 vMaxOffset = vOffset * fParallaxLimit;

    int nNumSamples = int(mix(20, 4, dot(vE, vN)));
    float fStepSize = 1.0 / float(nNumSamples);

    float fCurrRayHeight = 1.0;
    vec2 vCurrOffset = vec2(0.0);
    vec2 vLastOffset = vec2(0.0);
    float fLastSampledHeight = 1.0;
    float fCurrSampledHeight = 1.0;
    int nCurrSample = 0;

    // for each sample
