Skip to content

Instantly share code, notes, and snippets.

@hug0hq
Forked from patriciogonzalezvivo/GLSL-Math.md
Created November 17, 2022 16:55
Show Gist options
  • Save hug0hq/e09ef0808ce62f9027c381912d2c9e96 to your computer and use it in GitHub Desktop.
Save hug0hq/e09ef0808ce62f9027c381912d2c9e96 to your computer and use it in GitHub Desktop.

Revisions

  1. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Nov 4, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions GLSL-Math.md
    Original file line number Diff line number Diff line change
    @@ -54,8 +54,8 @@ mat4 RotateY(float theta){
    mat4 RotateZ(float psi){
    return mat4(
    vec4(cos(psi),sin(psi),0.,0),
    vec4(-sin(psi),cos(psi),0.,0.),
    vec4(cos(psi),-sin(psi),0.,0),
    vec4(sin(psi),cos(psi),0.,0.),
    vec4(0.,0.,1.,0.),
    vec4(0.,0.,0.,1.));
    }
  2. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Oct 31, 2014. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions GLSL-Math.md
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,24 @@ float cosd(float a){return cos(a * PI180);}
    From <http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-3:-3D-transformation-and-projection.html>

    ```
    mat4 scale(float x, float y, float z){
    return mat4(
    vec4(x, 0.0, 0.0, 0.0),
    vec4(0.0, y, 0.0, 0.0),
    vec4(0.0, 0.0, z, 0.0),
    vec4(0.0, 0.0, 0.0, 1.0)
    );
    }
    mat4 translate(float x, float y, float z){
    return mat4(
    vec4(1.0, 0.0, 0.0, 0.0),
    vec4(0.0, 1.0, 0.0, 0.0),
    vec4(0.0, 0.0, 1.0, 0.0),
    vec4(x, y, z, 1.0)
    );
    }
    mat4 RotateX(float phi){
    return mat4(
    vec4(1.,0.,0.,0),
  3. @patriciogonzalezvivo patriciogonzalezvivo renamed this gist Oct 18, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 29, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,8 @@ float cosd(float a){return cos(a * PI180);}
    ```

    From <http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-3:-3D-transformation-and-projection.html>

    ```
    mat4 RotateX(float phi){
    return mat4(
  5. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 29, 2014. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,32 @@ float cosd(float a){return cos(a * PI180);}
    ```

    ```
    mat4 RotateX(float phi){
    return mat4(
    vec4(1.,0.,0.,0),
    vec4(0.,cos(phi),-sin(phi),0.),
    vec4(0.,sin(phi),cos(phi),0.),
    vec4(0.,0.,0.,1.));
    }
    mat4 RotateY(float theta){
    return mat4(
    vec4(cos(theta),0.,-sin(theta),0),
    vec4(0.,1.,0.,0.),
    vec4(sin(theta),0.,cos(theta),0.),
    vec4(0.,0.,0.,1.));
    }
    mat4 RotateZ(float psi){
    return mat4(
    vec4(cos(psi),sin(psi),0.,0),
    vec4(-sin(psi),cos(psi),0.,0.),
    vec4(0.,0.,1.,0.),
    vec4(0.,0.,0.,1.));
    }
    ```

    ### [IQ Functions](http://iquilezles.org/www/articles/functions/functions.htm) by Iñigo Quilez

    ```
  6. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 9, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;
    float PHI = (1.0+sqrtf(5.0))/2.0;
    ```

    ```
  7. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 2, 2014. No changes.
  8. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 2, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@

    # Angles
    ### Trigonometry

    ```
    const float PI = 3.1415926535897932384626433832795;
    @@ -15,7 +14,7 @@ float cosd(float a){return cos(a * PI180);}
    ```

    # [IQ Functions](http://iquilezles.org/www/articles/functions/functions.htm) by Iñigo Quilez
    ### [IQ Functions](http://iquilezles.org/www/articles/functions/functions.htm) by Iñigo Quilez

    ```
    float almostIdentity( float x, float m, float n ){
  9. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 1, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@

    ```
    # Angles

    ```
    const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;
    ```

    ```
    float PI180 = float(PI / 180.0);
    float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}
  10. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jul 1, 2014. 1 changed file with 49 additions and 0 deletions.
    49 changes: 49 additions & 0 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -14,3 +14,52 @@ float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}
    ```

    # [IQ Functions](http://iquilezles.org/www/articles/functions/functions.htm) by Iñigo Quilez

    ```
    float almostIdentity( float x, float m, float n ){
    if( x>m ) return x;
    const float a = 2.0f*n - m
    const float b = 2.0f*m - 3.0f*n;
    const float t = x/m;
    return (a*t + b)*t*t + n;
    }
    ```

    ```
    float impulse( float k, float x ){
    const float h = k*x;
    return h*expf(1.0f-h);
    }
    ```

    ```
    float cubicPulse( float c, float w, float x ){
    x = fabsf(x - c);
    if( x>w ) return 0.0f;
    x /= w;
    return 1.0f - x*x*(3.0f-2.0f*x);
    }
    ```

    ```
    float expStep( float x, float k, float n ){
    return expf( -k*powf(x,n) );
    }
    ```

    ```
    float parabola( float x, float k ){
    return powf( 4.0f*x*(1.0f-x), k );
    }
    ```

    ```
    float pcurve( float x, float k ){
    float k = powf(a+b,a+b) / (pow(a,a)*pow(b,b));
    return k * powf( x, a ) * powf( 1.0-x, b );
    }
    ```
  11. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jun 29, 2014. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion Math.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,16 @@

    ```
    const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;
    ```

    ```
    float PI180 = float(PI / 180.0);
    float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}
    ```
    ```
  12. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jun 29, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ˜˜˜
    ```
    const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;
    @@ -7,4 +7,4 @@ float PI180 = float(PI / 180.0);
    float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}
    ˜˜˜
    ```
  13. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jun 29, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    '''

    ˜˜˜
    const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;
    @@ -8,4 +7,4 @@ float PI180 = float(PI / 180.0);
    float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}

    '''
    ˜˜˜
  14. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jun 29, 2014. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion Math.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,11 @@
    '''

    const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;

    float PI180 = float(PI / 180.0);
    float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}
    float cosd(float a){return cos(a * PI180);}

    '''
  15. @patriciogonzalezvivo patriciogonzalezvivo revised this gist Jun 29, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #define PI 3.1415926535897932384626433832795
    #define PI180 0.0174532925199
    const float PI = 3.1415926535897932384626433832795;
    const float PI_2 = 1.57079632679489661923;
    const float PI_4 = 0.785398163397448309616;

    #define sind(a) sin(float(a) * PI180)
    #define cosd(a) cos(float(a) * PI180)
    float PI180 = float(PI / 180.0);
    float sind(float a){return sin(a * PI180);}
    float cosd(float a){return cos(a * PI180);}
  16. @patriciogonzalezvivo patriciogonzalezvivo created this gist Jun 29, 2014.
    5 changes: 5 additions & 0 deletions Math.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #define PI 3.1415926535897932384626433832795
    #define PI180 0.0174532925199

    #define sind(a) sin(float(a) * PI180)
    #define cosd(a) cos(float(a) * PI180)