Skip to content

Instantly share code, notes, and snippets.

@prankush-tech
Created September 5, 2024 23:28
Show Gist options
  • Save prankush-tech/789943bed47347e47e3a2aad8a77a0e9 to your computer and use it in GitHub Desktop.
Save prankush-tech/789943bed47347e47e3a2aad8a77a0e9 to your computer and use it in GitHub Desktop.

Revisions

  1. prankush-tech created this gist Sep 5, 2024.
    50 changes: 50 additions & 0 deletions Lights.glsl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    vec3 pointLight(vec3 lightColor, float lightIntensity, vec3 normal, vec3 lightPosition, vec3 viewDirection, float specularPower, vec3 position, float lightDecay)
    {
    vec3 lightDelta = lightPosition - position;
    float lightDistance = length(lightDelta);
    vec3 lightDirection = normalize(lightDelta);
    vec3 lightReflection = reflect(- lightDirection, normal);

    // Shading
    float shading = dot(normal, lightDirection);
    shading = max(0.0, shading);

    // Specular
    float specular = - dot(lightReflection, viewDirection);
    specular = max(0.0, specular);
    specular = pow(specular, specularPower);

    // Decay
    float decay = 1.0 - lightDistance * lightDecay;
    decay = max(0.0, decay);

    return lightColor * lightIntensity * decay * (shading + specular);
    }




    vec3 directionalLight(vec3 lightColor, float lightIntensity, vec3 normal, vec3 lightPosition, vec3 viewDirection, float specularPower)
    {
    vec3 lightDirection = normalize(lightPosition);
    vec3 lightReflection = reflect(- lightDirection, normal);

    // Shading
    float shading = dot(normal, lightDirection);
    shading = max(0.0, shading);

    // Specular
    float specular = - dot(lightReflection, viewDirection);
    specular = max(0.0, specular);
    specular = pow(specular, specularPower);

    return lightColor * lightIntensity * (shading + specular);
    }


    vec3 ambientLight(vec3 lightColor, float lightIntensity)
    {
    return lightColor * lightIntensity;
    }