overte/libraries/render-utils/src/zone_drawKeyLight.slf
2018-09-06 08:59:07 -07:00

57 lines
1.7 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// Created by Sam Gateau on 5/16/17.
// Copyright 2017 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
//
<@include zone_draw.slh@>
<@include graphics/Light.slh@>
<@include LightingModel.slh@>
<$declareLightBuffer()$>
<@include LightDirectional.slh@>
<$declareLightingDirectional(_SCRIBE_NULL)$>
layout(location=0) in vec2 varTexCoord0;
layout(location=0) out vec4 _fragColor;
void main(void) {
<$evalGlobeWidget()$>
Light light = getKeyLight();
vec3 lightDirection = normalize(getLightDirection(light));
vec3 lightIrradiance = getLightIrradiance(light);
vec3 color = vec3(0.0);
const float INOUT_RATIO = 0.4;
const float SUN_THRESHOLD = 0.99;
vec3 outSpherePos = normalize(vec3(sphereUV, -sqrt(1.0 - sphereR2)));
vec3 outNormal = vec3(getViewInverse() * vec4(outSpherePos, 0.0));
float val = step(SUN_THRESHOLD, dot(-lightDirection, outNormal));
color = lightIrradiance * vec3(val);
if (sphereR2 < INOUT_RATIO * INOUT_RATIO * SCOPE_RADIUS2) {
vec2 inSphereUV = sphereUV / INOUT_RATIO;
vec3 inSpherePos = normalize(vec3(inSphereUV, sqrt(1.0 - dot(inSphereUV.xy, inSphereUV.xy))));
vec3 inNormal = vec3(getViewInverse() * vec4(inSpherePos, 0.0));
vec3 marbleColor = max(lightIrradiance * vec3(dot(-lightDirection, inNormal)), vec3(0.01));
color += marbleColor;
}
color = color * 1.0 - base.w + base.xyz * base.w;
const float INV_GAMMA_22 = 1.0 / 2.2;
_fragColor = vec4(pow(color, vec3(INV_GAMMA_22)), 1.0);
}