2013-08-29 11:45:22 +09:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 yvt
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-29 11:45:22 +09:00
|
|
|
This file is part of OpenSpades.
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-29 11:45:22 +09:00
|
|
|
OpenSpades 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-29 11:45:22 +09:00
|
|
|
OpenSpades 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.
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-29 11:45:22 +09:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-29 11:45:22 +09:00
|
|
|
*/
|
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
|
|
|
|
uniform mat4 projectionViewMatrix;
|
|
|
|
uniform mat4 viewMatrix;
|
|
|
|
uniform vec3 rightVector;
|
|
|
|
uniform vec3 upVector;
|
2016-11-06 22:15:37 +09:00
|
|
|
uniform vec3 viewOriginVector;
|
2013-08-18 16:18:06 +09:00
|
|
|
|
|
|
|
uniform float fogDistance;
|
|
|
|
|
|
|
|
attribute vec4 positionAttribute;
|
|
|
|
attribute vec3 spritePosAttribute;
|
|
|
|
attribute vec4 colorAttribute;
|
|
|
|
|
|
|
|
varying vec4 color;
|
|
|
|
varying vec2 texCoord;
|
|
|
|
varying vec4 fogDensity;
|
|
|
|
|
2014-02-03 23:52:53 +09:00
|
|
|
vec4 FogDensity(float poweredLength);
|
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
void main() {
|
|
|
|
vec3 pos = positionAttribute.xyz;
|
|
|
|
float radius = positionAttribute.w;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
vec3 right = rightVector * radius;
|
|
|
|
vec3 up = upVector * radius;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
float angle = spritePosAttribute.z;
|
|
|
|
float c = cos(angle), s = sin(angle);
|
|
|
|
vec2 sprP;
|
|
|
|
sprP.x = dot(spritePosAttribute.xy, vec2(c, -s));
|
|
|
|
sprP.y = dot(spritePosAttribute.xy, vec2(s, c));
|
|
|
|
sprP *= radius;
|
|
|
|
pos += right * sprP.x;
|
|
|
|
pos += up * sprP.y;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
gl_Position = projectionViewMatrix * vec4(pos,1.);
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
color = colorAttribute;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
texCoord = spritePosAttribute.xy * .5 + .5;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
// fog.
|
|
|
|
// cannot gamma correct because sprite may be
|
|
|
|
// alpha-blended.
|
|
|
|
vec4 viewPos = viewMatrix * vec4(pos,1.);
|
2016-11-06 22:15:37 +09:00
|
|
|
vec2 horzRelativePos = pos.xy - viewOriginVector.xy;
|
|
|
|
float horzDistance = dot(horzRelativePos, horzRelativePos);
|
|
|
|
fogDensity = FogDensity(horzDistance);
|
2013-08-18 16:18:06 +09:00
|
|
|
}
|
|
|
|
|