overte-thingvellir/libraries/render-utils/src/glowLine.slv
2018-12-14 14:15:56 -08:00

61 lines
1.8 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// Created by Bradley Austin Davis on 2016/07/05
// Copyright 2013-2016 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 render-utils/ShaderConstants.h@>
<$declareStandardTransform()$>
struct LineData {
vec4 p1;
vec4 p2;
vec4 color;
float width;
};
LAYOUT_STD140(binding=0) uniform LineDataBuffer {
LineData _lineData;
};
layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color;
// the distance from the center in 'quad space'
layout(location=0) out float distanceFromCenter;
void main(void) {
_color = _lineData.color;
TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject();
vec4 p1eye, p2eye;
<$transformModelToEyePos(cam, obj, _lineData.p1, p1eye)$>
<$transformModelToEyePos(cam, obj, _lineData.p2, p2eye)$>
p1eye /= p1eye.w;
p2eye /= p2eye.w;
// Find the line direction
vec3 v1 = normalize(p1eye.xyz - p2eye.xyz);
// Find the vector from the eye to one of the points
vec3 v2 = normalize(p1eye.xyz);
// The orthogonal vector is the cross product of these two
vec3 orthogonal = cross(v1, v2) * _lineData.width;
// Deteremine which end to emit based on the vertex id (even / odd)
vec4 eye = mix(p2eye, p1eye, float(gl_VertexID % 2 == 0));
// Add or subtract the orthogonal vector based on a different vertex ID
// calculation
distanceFromCenter = 1.0 - 2.0 * float(gl_VertexID < 2);
eye.xyz += distanceFromCenter * orthogonal;
// Finally, put the eyespace vertex into clip space
<$transformEyeToClipPos(cam, eye, gl_Position)$>
}