summaryrefslogtreecommitdiff
path: root/data/shaders/pbr-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/pbr-frag.glsl
parent8c6326a46f82ae46cc63bd431b0678d4f6b10d00 (diff)
graphics: Add basic image based ambient lighting.
Diffstat (limited to 'data/shaders/pbr-frag.glsl')
-rw-r--r--data/shaders/pbr-frag.glsl14
1 files changed, 9 insertions, 5 deletions
diff --git a/data/shaders/pbr-frag.glsl b/data/shaders/pbr-frag.glsl
index c474981..fff725a 100644
--- a/data/shaders/pbr-frag.glsl
+++ b/data/shaders/pbr-frag.glsl
@@ -47,9 +47,9 @@ out vec4 fragColor;
uniform Material material;
uniform Light lights[MAX_LIGHTS];
-uniform vec4 ambientLight;
uniform bool vertexColored;
uniform vec3 cameraPosition;
+uniform samplerCube skybox;
uniform sampler2D baseColorTexture;
uniform sampler2D metallicRoughnessTexture;
uniform sampler2D normalTexture;
@@ -244,6 +244,7 @@ void main(void) {
float metallic = materialMetallic();
float roughness = materialRoughness();
vec3 normal = materialNormal();
+ vec3 reflection = reflect(-viewDirection, normal);
// The "raw" albedo has an alpha channel which we need to preserve
// so that we can apply the desired alpha blending method at the
// end, but it is completely ignored for lighting calculations.
@@ -356,11 +357,14 @@ void main(void) {
// The emissive texture says which fragments emit light. We simply
// add this light value to the color accumulator.
color += materialEmissive();
- // Apply simple ambient lighting. The affect of the ambient light
- // is dampened by the ambient occlusion factor.
+ // Apply image based ambient lighting. The affect of the ambient
+ // light is dampened by the ambient occlusion factor.
//
- // TODO: Use image based lighting.
- color += ambientLight.rgb * albedo * ambientOcclusion;
+ // TODO: Use fancy PBR equations instead of these basic ones.
+ float fresnel = pow(1.0 - clamp(dot(viewDirection, normal), 0.0, 1.0), 5);
+ vec3 ambientDiffuse = textureCube(skybox, normal).rgb;
+ vec3 ambientSpecular = textureLod(skybox, reflection, roughness * 7.0).rgb;
+ color += (ambientDiffuse * albedo + ambientSpecular * fresnel) * ambientOcclusion;
// Apply Reinhard tone mapping to convert our high dynamic range
// color value to low dynamic range. All of the lighting
// calculations stacked on top of each other is likely to create