2010-05-06 18:22:53 +00:00
|
|
|
|
/*
|
|
|
|
|
oolite-dust.vertex
|
|
|
|
|
Vertex shader for interplanetary dust.
|
|
|
|
|
|
|
|
|
|
|
2012-12-31 09:00:28 +00:00
|
|
|
|
© 2010-2013 Jens Ayton
|
2012-04-01 13:27:36 +00:00
|
|
|
|
|
2010-05-06 18:22:53 +00:00
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
2012-04-01 13:27:36 +00:00
|
|
|
|
|
2010-05-06 18:22:53 +00:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2012-04-01 13:27:36 +00:00
|
|
|
|
|
2010-05-06 18:22:53 +00:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-05-09 19:23:06 +00:00
|
|
|
|
/* The following macros are provided by Oolite, to ensure that they stay in
|
|
|
|
|
sync with the values used in non-shader mode.
|
|
|
|
|
|
|
|
|
|
#define OODUST_SCALE_MAX (float(2))
|
|
|
|
|
#define OODUST_SCALE_FACTOR (float(0.002))
|
2010-05-09 19:37:09 +00:00
|
|
|
|
#define OODUST_SIZE (float(2000))
|
2010-05-09 19:23:06 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2010-05-06 18:22:53 +00:00
|
|
|
|
|
2010-05-09 18:22:53 +00:00
|
|
|
|
/* “Warpiness”: 0 for dots when not warping and the near end of lines when
|
|
|
|
|
warping, 1 for the far end of lines when warping. (Note that both “ends”
|
|
|
|
|
have the same input coordinates, and the shader applies the warp effect.)
|
|
|
|
|
*/
|
|
|
|
|
attribute float aWarpiness;
|
|
|
|
|
uniform vec4 uWarp;
|
2010-05-09 19:37:09 +00:00
|
|
|
|
|
2011-04-28 18:47:04 +00:00
|
|
|
|
// Player position, offset by -OODUST_SIZE/2 on each coordinate.
|
2010-05-09 19:37:09 +00:00
|
|
|
|
uniform vec4 uOffsetPlayerPosition;
|
2010-05-06 18:22:53 +00:00
|
|
|
|
|
2010-05-09 19:23:06 +00:00
|
|
|
|
varying vec4 vColor;
|
2010-05-06 18:22:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
|
{
|
2010-05-09 19:23:06 +00:00
|
|
|
|
/* Dust particles are arranged in a cube of 2000×2000×2000 metres
|
|
|
|
|
(OO_DUST_SIZE) around the universe origin. The following code offsets
|
|
|
|
|
each particle to be somewhere in a cube of the same size around the
|
|
|
|
|
player, creating an infinite repeating pattern.
|
|
|
|
|
*/
|
2012-01-18 15:23:11 +00:00
|
|
|
|
vec4 position = mod(gl_Vertex - uOffsetPlayerPosition, OODUST_SIZE) + uOffsetPlayerPosition;
|
2010-05-09 19:23:06 +00:00
|
|
|
|
position = position - uWarp * aWarpiness;
|
|
|
|
|
|
2010-05-09 19:37:09 +00:00
|
|
|
|
// Project the dust, and find its distance from the camera.
|
2010-05-09 18:22:53 +00:00
|
|
|
|
position.w = 1.0;
|
2010-05-09 19:23:06 +00:00
|
|
|
|
position = gl_ModelViewProjectionMatrix * position;
|
|
|
|
|
gl_Position = position;
|
|
|
|
|
|
|
|
|
|
float distance = length(position);
|
2010-05-06 18:22:53 +00:00
|
|
|
|
|
|
|
|
|
/* The original non-shader code fades to black using linear fog, with a
|
|
|
|
|
near plane of 500 and a far plane of 1000.
|
|
|
|
|
OODUST_SCALE_MAX is far plane/near plane, and OODUST_SCALE_FACTOR
|
|
|
|
|
is 1.0/(far plane - near plane).
|
|
|
|
|
This gives us a function such that f(x) ≥ 1 when x ≤ near plane,
|
|
|
|
|
f(x) ≤ 0 when x ≥ far plane, and a linear ramp in between, which we
|
|
|
|
|
then clamp to [0..1].
|
|
|
|
|
*/
|
|
|
|
|
float alpha = clamp(OODUST_SCALE_MAX - distance * OODUST_SCALE_FACTOR, 0.0, 1.0);
|
2010-05-08 22:51:33 +00:00
|
|
|
|
vColor = vec4(gl_Color.rgb, alpha * gl_Color.a);
|
2010-05-06 18:22:53 +00:00
|
|
|
|
}
|