armory/Shaders/forward/mesh.vert.glsl

127 lines
2.2 KiB
Plaintext
Raw Normal View History

2016-01-28 00:58:00 +01:00
#version 450
2015-12-24 16:12:32 +01:00
#ifdef GL_ES
precision highp float;
#endif
2016-08-23 22:55:46 +02:00
#include "../compiled.glsl"
2016-10-17 17:39:40 +02:00
#ifdef _Skinning
#include "../std/skinning.glsl"
// getSkinningDualQuat()
#endif
#ifdef _VR
#include "../std/vr.glsl"
// undistort()
#endif
2016-08-23 22:55:46 +02:00
2016-01-28 00:58:00 +01:00
in vec3 pos;
in vec3 nor;
2016-10-09 16:06:18 +02:00
#ifdef _Tex
2016-07-19 19:42:46 +02:00
in vec2 tex;
2015-12-24 16:12:32 +01:00
#endif
#ifdef _VCols
2016-07-19 19:42:46 +02:00
in vec3 col;
2015-12-24 16:12:32 +01:00
#endif
2016-08-25 00:26:01 +02:00
#ifdef _NorTex
2016-07-19 19:42:46 +02:00
in vec3 tan;
2015-12-24 16:12:32 +01:00
#endif
#ifdef _Skinning
2016-07-19 19:42:46 +02:00
in vec4 bone;
in vec4 weight;
2015-12-24 16:12:32 +01:00
#endif
#ifdef _Instancing
2016-07-19 19:42:46 +02:00
in vec3 off;
2015-12-24 16:12:32 +01:00
#endif
2016-08-25 00:26:01 +02:00
uniform mat4 W;
uniform mat4 N;
2016-10-17 02:29:37 +02:00
#ifdef _Billboard
uniform mat4 WV;
uniform mat4 P;
#endif
2015-12-24 16:12:32 +01:00
uniform mat4 V;
uniform mat4 P;
2016-08-25 00:26:01 +02:00
uniform mat4 LWVP;
uniform vec4 baseCol;
2015-12-24 16:12:32 +01:00
uniform vec3 eye;
#ifdef _Skinning
2016-10-17 17:39:40 +02:00
//!uniform float skinBones[skinMaxBones * 8];
2015-12-24 16:12:32 +01:00
#endif
2016-08-10 17:46:16 +02:00
#ifdef _VR
2016-10-17 17:39:40 +02:00
// !uniform mat4 U;
// !uniform float maxRadSq;
2016-08-10 17:46:16 +02:00
#endif
2015-12-24 16:12:32 +01:00
2016-01-28 00:58:00 +01:00
out vec3 position;
2016-06-21 13:29:27 +02:00
#ifdef _Tex
2016-07-19 19:42:46 +02:00
out vec2 texCoord;
2015-12-24 16:12:32 +01:00
#endif
2016-10-15 12:17:33 +02:00
out vec4 lampPos;
2016-01-28 00:58:00 +01:00
out vec4 matColor;
out vec3 eyeDir;
2016-08-25 00:26:01 +02:00
#ifdef _NorTex
2016-07-19 19:42:46 +02:00
out mat3 TBN;
2016-02-14 15:33:23 +01:00
#else
2016-07-19 19:42:46 +02:00
out vec3 normal;
2015-12-24 16:12:32 +01:00
#endif
2016-01-24 22:32:51 +01:00
void main() {
2016-10-17 00:02:51 +02:00
vec4 sPos = vec4(pos, 1.0);
2016-08-29 09:56:34 +02:00
2015-12-24 16:12:32 +01:00
#ifdef _Skinning
2016-08-29 09:56:34 +02:00
vec4 skinA;
vec4 skinB;
2016-10-17 17:39:40 +02:00
getSkinningDualQuat(ivec4(bone), weight, skinA, skinB);
2016-08-29 09:56:34 +02:00
sPos.xyz += 2.0 * cross(skinA.xyz, cross(skinA.xyz, sPos.xyz) + skinA.w * sPos.xyz); // Rotate
sPos.xyz += 2.0 * (skinA.w * skinB.xyz - skinB.w * skinA.xyz + cross(skinA.xyz, skinB.xyz)); // Translate
vec3 _normal = normalize(mat3(N) * (nor + 2.0 * cross(skinA.xyz, cross(skinA.xyz, nor) + skinA.w * nor)));
#else
vec3 _normal = normalize(mat3(N) * nor);
2015-12-24 16:12:32 +01:00
#endif
2016-08-29 09:56:34 +02:00
2016-10-17 00:02:51 +02:00
#ifdef _Instancing
sPos.xyz += off;
#endif
2016-10-15 12:17:33 +02:00
lampPos = LWVP * sPos;
2015-12-24 16:12:32 +01:00
2016-08-25 00:26:01 +02:00
mat4 WV = V * W;
2016-01-25 20:43:11 +01:00
#ifdef _Billboard
// Spherical
2016-08-25 00:26:01 +02:00
WV[0][0] = 1.0; WV[0][1] = 0.0; WV[0][2] = 0.0;
WV[1][0] = 0.0; WV[1][1] = 1.0; WV[1][2] = 0.0;
WV[2][0] = 0.0; WV[2][1] = 0.0; WV[2][2] = 1.0;
2016-01-25 20:43:11 +01:00
// Cylindrical
2016-08-25 00:26:01 +02:00
//WV[0][0] = 1.0; WV[0][1] = 0.0; WV[0][2] = 0.0;
//WV[2][0] = 0.0; WV[2][1] = 0.0; WV[2][2] = 1.0;
2016-01-25 20:43:11 +01:00
#endif
2016-08-10 17:46:16 +02:00
#ifdef _VR
2016-08-25 00:26:01 +02:00
gl_Position = P * undistort(WV, sPos);
2016-08-10 17:46:16 +02:00
#else
2016-08-25 00:26:01 +02:00
gl_Position = P * WV * sPos;
2016-08-10 17:46:16 +02:00
#endif
2015-12-24 16:12:32 +01:00
2016-06-21 13:29:27 +02:00
#ifdef _Tex
2015-12-24 16:12:32 +01:00
texCoord = tex;
#endif
matColor = baseCol;
2015-12-24 16:12:32 +01:00
#ifdef _VCols
2016-07-19 19:42:46 +02:00
matColor.rgb *= col;
2015-12-24 16:12:32 +01:00
#endif
2016-10-09 16:06:18 +02:00
position = vec4(W * sPos).xyz;
eyeDir = eye - position;
2016-08-25 00:26:01 +02:00
#ifdef _NorTex
vec3 tangent = (mat3(N) * (tan));
2016-02-14 15:33:23 +01:00
vec3 bitangent = normalize(cross(_normal, tangent));
TBN = mat3(tangent, bitangent, _normal);
#else
normal = _normal;
2015-12-24 16:12:32 +01:00
#endif
}