Created
September 5, 2024 23:28
-
-
Save prankush-tech/789943bed47347e47e3a2aad8a77a0e9 to your computer and use it in GitHub Desktop.
In GLSL, **point light** emits light from a specific position in all directions with intensity decreasing over distance. **Directional light** has no position, shining uniformly from a direction. **Ambient light** provides constant, non-directional lighting to simulate global illumination.
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 characters
| 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; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment