fix alpha on glowLines

This commit is contained in:
SamGondelman 2017-09-22 13:22:08 -07:00
parent 20cb02dabb
commit bc477608ee
2 changed files with 10 additions and 9 deletions

View file

@ -9,7 +9,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
layout(location = 0) in vec4 inColor; in vec4 _color;
in float distanceFromCenter;
out vec4 _fragColor; out vec4 _fragColor;
@ -17,10 +18,10 @@ void main(void) {
// The incoming value actually ranges from -1 to 1, so modify it // The incoming value actually ranges from -1 to 1, so modify it
// so that it goes from 0 -> 1 -> 0 with the solid alpha being at // so that it goes from 0 -> 1 -> 0 with the solid alpha being at
// the center of the line // the center of the line
float alpha = 1.0 - abs(inColor.a); float alpha = 1.0 - abs(distanceFromCenter);
// Convert from a linear alpha curve to a sharp peaked one // Convert from a linear alpha curve to a sharp peaked one
alpha = pow(alpha, 10); alpha = _color.a * pow(alpha, 10);
// Drop everything where the curve falls off to nearly nothing // Drop everything where the curve falls off to nearly nothing
if (alpha <= 0.05) { if (alpha <= 0.05) {
@ -28,6 +29,5 @@ void main(void) {
} }
// Emit the color // Emit the color
_fragColor = vec4(inColor.rgb, alpha); _fragColor = vec4(_color.rgb, alpha);
return;
} }

View file

@ -18,7 +18,9 @@ layout(std140) uniform lineData {
vec4 color; vec4 color;
}; };
layout(location = 0) out vec4 _color; out vec4 _color;
// the distance from the center in 'quad space'
out float distanceFromCenter;
void main(void) { void main(void) {
_color = color; _color = color;
@ -45,11 +47,10 @@ void main(void) {
// Add or subtract the orthogonal vector based on a different vertex ID // Add or subtract the orthogonal vector based on a different vertex ID
// calculation // calculation
if (gl_VertexID < 2) { if (gl_VertexID < 2) {
// Use the alpha channel to store the distance from the center in 'quad space' distanceFromCenter = -1.0;
_color.a = -1.0;
eye.xyz -= orthogonal; eye.xyz -= orthogonal;
} else { } else {
_color.a = 1.0; distanceFromCenter = 1.0;
eye.xyz += orthogonal; eye.xyz += orthogonal;
} }