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 chunkPosition;
|
|
|
|
uniform float fogDistance;
|
2016-11-06 22:15:37 +09:00
|
|
|
uniform vec3 viewOriginVector;
|
2013-08-18 16:18:06 +09:00
|
|
|
|
|
|
|
// --- Vertex attribute ---
|
|
|
|
// [x, y, z]
|
|
|
|
attribute vec3 positionAttribute;
|
|
|
|
|
|
|
|
// [ax, ay]
|
|
|
|
attribute vec2 ambientOcclusionCoordAttribute;
|
|
|
|
|
|
|
|
// [R, G, B, diffuse]
|
|
|
|
attribute vec4 colorAttribute;
|
|
|
|
|
|
|
|
// [nx, ny, nz]
|
|
|
|
attribute vec3 normalAttribute;
|
|
|
|
|
2014-04-10 18:02:12 +09:00
|
|
|
// [sx, sy, sz]
|
|
|
|
attribute vec3 fixedPositionAttribute;
|
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
varying vec2 ambientOcclusionCoord;
|
|
|
|
varying vec4 color;
|
|
|
|
varying vec3 fogDensity;
|
|
|
|
varying vec2 detailCoord;
|
|
|
|
|
2014-04-10 18:02:12 +09:00
|
|
|
void PrepareForShadowForMap(vec3 vertexCoord, vec3 fixedVertexCoord, vec3 normal);
|
2014-02-03 23:52:53 +09:00
|
|
|
vec4 FogDensity(float poweredLength);
|
2013-08-18 16:18:06 +09:00
|
|
|
|
|
|
|
void main() {
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
vec4 vertexPos = vec4(chunkPosition, 1.);
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
vertexPos.xyz += positionAttribute.xyz;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
gl_Position = projectionViewMatrix * vertexPos;
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
color = colorAttribute;
|
|
|
|
color.xyz *= color.xyz; // linearize
|
2016-11-06 22:15:37 +09:00
|
|
|
|
2013-08-18 16:18:06 +09:00
|
|
|
// ambient occlusion
|
2014-02-04 00:04:27 +09:00
|
|
|
ambientOcclusionCoord = (ambientOcclusionCoordAttribute + .5) * (1. / 256.);
|
2013-08-18 16:18:06 +09:00
|
|
|
|
|
|
|
vec4 viewPos = viewMatrix * vertexPos;
|
2016-11-06 22:15:37 +09:00
|
|
|
vec2 horzRelativePos = vertexPos.xy - viewOriginVector.xy;
|
|
|
|
float horzDistance = dot(horzRelativePos, horzRelativePos);
|
|
|
|
fogDensity = FogDensity(horzDistance).xyz;
|
|
|
|
|
2014-04-10 18:02:12 +09:00
|
|
|
vec3 fixedPosition = chunkPosition;
|
|
|
|
fixedPosition += fixedPositionAttribute * 0.5;
|
|
|
|
fixedPosition += normalAttribute * 0.1;
|
2013-08-18 16:18:06 +09:00
|
|
|
|
2014-02-04 00:04:27 +09:00
|
|
|
vec3 normal = normalAttribute;
|
2013-08-18 16:18:06 +09:00
|
|
|
vec3 shadowVertexPos = vertexPos.xyz;
|
2014-04-10 18:02:12 +09:00
|
|
|
PrepareForShadowForMap(shadowVertexPos, fixedPosition, normal);
|
2013-08-18 16:18:06 +09:00
|
|
|
}
|
|
|
|
|