summaryrefslogtreecommitdiff
path: root/data/shaders/phong-frag.glsl
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-08-16 17:12:23 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-08-16 17:12:23 -0400
commit7a4f04f1df6896a4978ba302ea3fc79b6e7dd1f7 (patch)
tree6b9de3a151435c3e125bcbe3068fe5b8967f10f2 /data/shaders/phong-frag.glsl
parent8c6326a46f82ae46cc63bd431b0678d4f6b10d00 (diff)
graphics: Add basic image based ambient lighting.
Diffstat (limited to 'data/shaders/phong-frag.glsl')
-rw-r--r--data/shaders/phong-frag.glsl11
1 files changed, 8 insertions, 3 deletions
diff --git a/data/shaders/phong-frag.glsl b/data/shaders/phong-frag.glsl
index 0beb75b..9c86c83 100644
--- a/data/shaders/phong-frag.glsl
+++ b/data/shaders/phong-frag.glsl
@@ -32,6 +32,7 @@ in vec2 fragTex;
out vec4 fragColor;
#endif
+uniform samplerCube skybox;
uniform sampler2D ambientMap;
uniform sampler2D diffuseMap;
uniform sampler2D specularMap;
@@ -39,7 +40,6 @@ uniform sampler2D normalMap;
uniform Material material;
uniform Light lights[MAX_LIGHTS];
uniform vec3 cameraPosition;
-uniform vec4 ambientLight;
const float GAMMA = 2.2;
@@ -135,6 +135,7 @@ void main() {
vec3 diffuseColor = materialDiffuse();
vec3 specularColor = materialSpecular();
vec3 normal = materialNormal();
+ vec3 reflection = reflect(-viewDir, normal);
vec3 color = vec3(0.0);
// Apply direct lighting.
@@ -155,8 +156,12 @@ void main() {
color += diffuseLight * diffuseColor + specularLight * specularColor;
}
- // Apply ambient lighting.
- vec3 ambientColor = diffuseColor * ambientLight.rgb * ambientOcclusion;
+ // Apply image based ambient lighting.
+ float fresnel = pow(1.0 - clamp(dot(viewDir, normal), 0.0, 1.0), 5);
+ float roughness = 1.0 - (material.shininess / 1000.0);
+ vec3 ambientDiffuse = textureCube(skybox, normal).rgb * diffuseColor;
+ vec3 ambientSpecular = textureLod(skybox, reflection, roughness * 7.0).rgb * fresnel;
+ vec3 ambientColor = (ambientDiffuse + ambientSpecular) * ambientOcclusion;
color += ambientColor;
// Apply gamma correction and HDR tone mapping to get the final