mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-18 05:53:40 +02:00
89 lines
2.4 KiB
Text
89 lines
2.4 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
//
|
|
// spot_light.frag
|
|
// fragment shader
|
|
//
|
|
// Created by Sam Gateau on 9/18/15.
|
|
// Copyright 2014 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
|
|
//
|
|
|
|
// Everything about deferred buffer
|
|
<@include DeferredBufferRead.slh@>
|
|
|
|
<$declareDeferredCurvature()$>
|
|
|
|
// Everything about light
|
|
<@include model/Light.slh@>
|
|
|
|
<@include LightingModel.slh@>
|
|
|
|
<@include LightSpot.slh@>
|
|
<$declareLightingSpot(supportScattering)$>
|
|
|
|
uniform vec4 texcoordFrameTransform;
|
|
|
|
in vec4 _texCoord0;
|
|
out vec4 _fragColor;
|
|
|
|
void main(void) {
|
|
|
|
DeferredFrameTransform deferredTransform = getDeferredFrameTransform();
|
|
|
|
// Grab the fragment data from the uv
|
|
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
|
texCoord *= texcoordFrameTransform.zw;
|
|
texCoord += texcoordFrameTransform.xy;
|
|
|
|
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
|
|
|
if (frag.mode == FRAG_MODE_UNLIT) {
|
|
discard;
|
|
}
|
|
|
|
// Kill if in front of the light volume
|
|
float depth = frag.depthVal;
|
|
if (depth < gl_FragCoord.z) {
|
|
discard;
|
|
}
|
|
|
|
// Need the light now
|
|
Light light = getLight();
|
|
|
|
// Frag pos in world
|
|
mat4 invViewMat = getViewInverse();
|
|
vec4 fragPos = invViewMat * frag.position;
|
|
|
|
// Clip againgst the light volume and Make the Light vector going from fragment to light center in world space
|
|
vec4 fragLightVecLen2;
|
|
vec4 fragLightDirLen;
|
|
float cosSpotAngle;
|
|
if (!clipFragToLightVolumeSpot(light, fragPos.xyz, fragLightVecLen2, fragLightDirLen, cosSpotAngle)) {
|
|
discard;
|
|
}
|
|
|
|
// Frag to eye vec
|
|
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
|
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
|
|
|
|
|
vec3 diffuse;
|
|
vec3 specular;
|
|
vec4 midNormalCurvature;
|
|
vec4 lowNormalCurvature;
|
|
if (frag.mode == FRAG_MODE_SCATTERING) {
|
|
unpackMidLowNormalCurvature(texCoord, midNormalCurvature, lowNormalCurvature);
|
|
}
|
|
evalLightingSpot(diffuse, specular, light,
|
|
fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness,
|
|
frag.metallic, frag.fresnel, frag.albedo, 1.0,
|
|
frag.scattering, midNormalCurvature, lowNormalCurvature);
|
|
|
|
_fragColor.rgb += diffuse;
|
|
_fragColor.rgb += specular;
|
|
}
|
|
|