1/* 2 Copyright (c) 2013 yvt 3 4 This file is part of OpenSpades. 5 6 OpenSpades is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 OpenSpades is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with OpenSpades. If not, see <http://www.gnu.org/licenses/>. 18 19 */ 20 21 22 23uniform mat4 projectionViewModelMatrix; 24uniform mat4 modelMatrix; 25uniform mat4 modelNormalMatrix; 26uniform mat4 viewModelMatrix; 27uniform vec3 modelOrigin; 28uniform float fogDistance; 29uniform vec3 sunLightDirection; 30uniform vec3 customColor; 31uniform vec3 viewOriginVector; 32 33// [x, y, z, AO ID] 34attribute vec4 positionAttribute; 35 36// [R, G, B, diffuse] 37attribute vec4 colorAttribute; 38 39// [x, y, z] 40attribute vec3 normalAttribute; 41 42varying vec4 color; 43varying vec3 fogDensity; 44//varying vec2 detailCoord; 45 46void PrepareForDynamicLightNoBump(vec3 vertexCoord, vec3 normal); 47vec4 FogDensity(float poweredLength); 48 49void main() { 50 51 vec4 vertexPos = vec4(positionAttribute.xyz, 1.); 52 53 vertexPos.xyz += modelOrigin; 54 55 gl_Position = projectionViewModelMatrix * vertexPos; 56 57 color = colorAttribute; 58 59 if(dot(color.xyz, vec3(1.)) < 0.0001){ 60 color.xyz = customColor; 61 } 62 63 // linearize 64 color.xyz *= color.xyz; 65 66 // calculate normal 67 vec3 normal = normalAttribute; 68 normal = (modelNormalMatrix * vec4(normal, 1.)).xyz; 69 normal = normalize(normal); 70 71 vec2 horzRelativePos = (modelMatrix * vertexPos).xy - viewOriginVector.xy; 72 float horzDistance = dot(horzRelativePos, horzRelativePos); 73 fogDensity = FogDensity(horzDistance).xyz; 74 75 PrepareForDynamicLightNoBump((modelMatrix * vertexPos).xyz, normal); 76} 77 78