overte/libraries/render-utils/src/deferred_light_point.slv
2018-10-29 16:42:46 -07:00

52 lines
1.4 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// deferred_light_limited.vert
// vertex shader
//
// Created by Sam Gateau on 6/16/16.
// 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
//
<@include gpu/Transform.slh@>
<@include gpu/Inputs.slh@>
<@include graphics/Light.slh@>
<@include render-utils/ShaderConstants.h@>
<$declareStandardTransform()$>
<$declareLightBuffer(256)$>
LAYOUT(binding=RENDER_UTILS_BUFFER_LIGHT_INDEX) uniform lightIndexBuffer {
int lightIndex[256];
};
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) out vec4 _texCoord0;
void main(void) {
int instanceID = lightIndex[gl_InstanceID];
Light light = getLight(instanceID);
vec4 sphereVertex = inPosition;
vec3 lightOrigin = getLightPosition(light);
vec4 sphereParam = vec4(1.0); // = getLightVolumeGeometry(light);
sphereVertex.xyz *= sphereParam.w;
sphereVertex.xyz += lightOrigin;
// standard transform
TransformCamera cam = getTransformCamera();
<$transformWorldToClipPos(cam, sphereVertex, gl_Position)$>;
vec4 projected = gl_Position / gl_Position.w;
projected.xy = (projected.xy + 1.0) * 0.5;
projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo()));
_texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w;
}