0 Replies Latest reply on Apr 30, 2009 8:37 AM by Sachbearbeiter

    Ati-GLSL Shader floating point arithmetic question

    Sachbearbeiter
      3 different ways to write an equation and only one works, why?

      In a glsl shader code for explicit time integration for the euler equations the equation

      Fx=(cxl*ulf-cxr*urf)/dx;

      occurs. There cxl and crx are both vec4 and ulf, urf and dx are floats. The test example is a rising heat bubble. Now there are at least four ways to write the equation above:

      1. Fx=(cxl*ulf-cxr*urf)/dx;

      2. Fx=cxl*(ulf/dx)-cxr*(urf/dx);

      3. Fx=(cxl/dx)*ulf-(cxr/dx)*urf;

      4. Fx=cxl*ulf/dx-cxr*urf/dx;

      only the last one (4.) gives the correct result and the bubble stays symmetric, all the others make unsymetric errors.

      anyone has an idea why that?

      thanks

      Stefan