#version 140 #define QF_GLSL_VERSION 430 #define VERTEX_SHADER #if !defined(myhalf) //#if !defined(__GLSL_CG_DATA_TYPES) #define myhalf float #define myhalf2 vec2 #define myhalf3 vec3 #define myhalf4 vec4 //#else //#define myhalf half //#define myhalf2 half2 //#define myhalf3 half3 //#define myhalf4 half4 //#endif #endif #if QF_GLSL_VERSION >= 130 precision highp float; # ifdef VERTEX_SHADER out myhalf4 qf_FrontColor; # define varying out # define attribute in # define gl_FrontColor qf_FrontColor # endif # ifdef FRAGMENT_SHADER in myhalf4 qf_FrontColor; out myhalf4 qf_FragColor; # define gl_Color qf_FrontColor # define gl_FragColor qf_FragColor # define varying in # define attribute in # define texture2D texture # define textureCube texture # define shadow2D texture # endif #endif #ifndef MAX_UNIFORM_BONES #define MAX_UNIFORM_BONES 100 #endif #ifdef VERTEX_SHADER attribute vec4 a_BonesIndices; attribute vec4 a_BonesWeights; uniform vec4 u_QF_DualQuats[MAX_UNIFORM_BONES*2]; void QF_VertexDualQuatsTransform(const int numWeights, inout vec4 Position, inout vec3 Normal, inout vec3 Tangent) { int index; vec4 Indices = a_BonesIndices; vec4 Weights = a_BonesWeights; vec4 Indices_2 = Indices * 2.0; vec4 DQReal, DQDual; index = int(Indices_2.x); DQReal = u_QF_DualQuats[index+0]; DQDual = u_QF_DualQuats[index+1]; if (numWeights > 1) { DQReal *= Weights.x; DQDual *= Weights.x; vec4 DQReal1, DQDual1; float scale; index = int(Indices_2.y); DQReal1 = u_QF_DualQuats[index+0]; DQDual1 = u_QF_DualQuats[index+1]; // antipodality handling scale = (dot(DQReal1, DQReal) < 0.0 ? -1.0 : 1.0) * Weights.y; DQReal += DQReal1 * scale; DQDual += DQDual1 * scale; if (numWeights > 2) { index = int(Indices_2.z); DQReal1 = u_QF_DualQuats[index+0]; DQDual1 = u_QF_DualQuats[index+1]; // antipodality handling scale = (dot(DQReal1, DQReal) < 0.0 ? -1.0 : 1.0) * Weights.z; DQReal += DQReal1 * scale; DQDual += DQDual1 * scale; if (numWeights > 3) { index = int(Indices_2.w); DQReal1 = u_QF_DualQuats[index+0]; DQDual1 = u_QF_DualQuats[index+1]; // antipodality handling scale = (dot(DQReal1, DQReal) < 0.0 ? -1.0 : 1.0) * Weights.w; DQReal += DQReal1 * scale; DQDual += DQDual1 * scale; } } } float len = length(DQReal); DQReal /= len; DQDual /= len; Position.xyz = (cross(DQReal.xyz, cross(DQReal.xyz, Position.xyz) + Position.xyz*DQReal.w + DQDual.xyz) + DQDual.xyz*DQReal.w - DQReal.xyz*DQDual.w)*2.0 + Position.xyz; Normal = cross(DQReal.xyz, cross(DQReal.xyz, Normal) + Normal*DQReal.w)*2.0 + Normal; Tangent = cross(DQReal.xyz, cross(DQReal.xyz, Tangent) + Tangent*DQReal.w)*2.0 + Tangent; } #define NUM_BONE_INFLUENCES 1 uniform mat4 u_ModelViewMatrix; uniform mat4 u_ModelViewProjectionMatrix; uniform float u_ShaderTime; uniform vec3 u_ViewOrigin; uniform mat3 u_ViewAxis; uniform vec3 u_EntityDist; uniform vec3 u_EntityOrigin; uniform myhalf4 u_EntityColor; uniform vec2 u_TextureMatrix[3]; #define TextureMatrix2x3Mul(m2x3,tc) vec2(dot((m2x3)[0],(tc)) + (m2x3)[2][0], dot((m2x3)[1],(tc)) + (m2x3)[2][1]) varying vec2 v_TexCoord; varying vec3 v_Position; varying mat3 v_StrMatrix; // directions of S/T/R texcoords (tangent, binormal, normal) attribute vec4 a_Position; attribute vec4 a_SVector; attribute vec3 a_Normal; attribute vec4 a_Color; attribute vec2 a_TexCoord; attribute vec2 a_LightmapCoord0, a_LightmapCoord1, a_LightmapCoord2, a_LightmapCoord3; void TransformVerts(inout vec4 Position, inout vec3 Normal, inout vec3 Tangent, inout vec2 TexCoord) { QF_VertexDualQuatsTransform(NUM_BONE_INFLUENCES, Position, Normal, Tangent); } void main() { vec4 Position = a_Position; vec3 Normal = a_Normal; myhalf4 inColor = myhalf4(a_Color); vec2 TexCoord = a_TexCoord; vec3 Tangent = a_SVector.xyz; float TangentDir = a_SVector.w; TransformVerts(Position, Normal, Tangent, TexCoord); myhalf4 outColor = myhalf4(1.0); gl_FrontColor = vec4(outColor); v_TexCoord = TextureMatrix2x3Mul(u_TextureMatrix, TexCoord); v_StrMatrix[0] = Tangent; v_StrMatrix[2] = Normal; v_StrMatrix[1] = TangentDir * cross(Normal, Tangent); v_Position = Position.xyz; gl_Position = u_ModelViewProjectionMatrix * Position; } #endif // VERTEX_SHADER