mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-27 20:18:46 +02:00
37 lines
1.4 KiB
Text
Executable file
37 lines
1.4 KiB
Text
Executable file
<!
|
|
// DeferredLighting.slh
|
|
// libraries/render-utils/src
|
|
//
|
|
// Created by Sam Gateau on 1/15/15.
|
|
// Copyright 2013 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
!>
|
|
<@if not DEFERRED_LIGHTING_SLH@>
|
|
<@def DEFERRED_LIGHTING_SLH@>
|
|
|
|
// Frag Shading returns the diffuse amount as W and the specular rgb as xyz
|
|
vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
|
|
// Diffuse Lighting
|
|
float diffuseDot = dot(fragNormal, fragLightDir);
|
|
float facingLight = step(0.0, diffuseDot);
|
|
float diffuse = diffuseDot * facingLight;
|
|
|
|
// Specular Lighting depends on the half vector and the gloss
|
|
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
|
|
|
|
float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss * 128.0);
|
|
specularPower *= (gloss * 128.0 * 0.125 + 0.25);
|
|
|
|
float shlickPower = (1.0 - dot(fragLightDir,halfDir));
|
|
float shlickPower2 = shlickPower * shlickPower;
|
|
float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower;
|
|
// vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5);
|
|
vec3 schlick = vec3(0.21) * (1.0 - shlickPower5) + vec3(shlickPower5);
|
|
vec3 reflect = specularPower * schlick;
|
|
|
|
return vec4(reflect, diffuse);
|
|
}
|
|
|
|
<@endif@>
|