Created
September 5, 2024 23:28
-
-
Save prankush-tech/789943bed47347e47e3a2aad8a77a0e9 to your computer and use it in GitHub Desktop.
Revisions
-
prankush-tech created this gist
Sep 5, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; }