57 lines
1.1 KiB
GLSL
57 lines
1.1 KiB
GLSL
uniform mat4 projectionMatrix;
|
|
uniform mat4 modelViewMatrix;
|
|
uniform mat3 normalMatrix;
|
|
|
|
out vec4 posInView;
|
|
#ifdef NORMAL_MAP
|
|
out vec3 varTangent;
|
|
out vec3 varBinormal;
|
|
#endif
|
|
|
|
#ifdef WIREFRAME
|
|
out vec3 varColor;
|
|
#else
|
|
out vec3 varNormal;
|
|
|
|
out vec2 varTexCoord;
|
|
#endif
|
|
|
|
layout(location = 0)in vec3 inPosition;
|
|
layout(location = 2)in vec2 inTexCoord;
|
|
layout(location = 1)in vec3 inNormal;
|
|
#ifdef NORMAL_MAP
|
|
layout(location = 3)in vec3 inTangent;
|
|
layout(location = 4)in vec3 inBinormal;
|
|
#endif
|
|
|
|
#ifdef INSTANCED
|
|
layout(location = 5)in vec3 inInstanceOffset;
|
|
#endif
|
|
|
|
void main(void) {
|
|
// computing normals
|
|
#ifdef NORMAL_MAP
|
|
varTangent = normalize(normalMatrix*inTangent);
|
|
varBinormal = normalize(normalMatrix*inBinormal);
|
|
#endif
|
|
|
|
#ifdef WIREFRAME
|
|
varColor = inNormal;
|
|
#else
|
|
varNormal = normalize(normalMatrix*inNormal);
|
|
|
|
//computing UVs
|
|
varTexCoord = inTexCoord.xy;
|
|
#endif
|
|
|
|
// computing positions
|
|
#ifdef INSTANCED
|
|
vec4 pos = vec4(inPosition + inInstanceOffset, 1.0);
|
|
#else
|
|
vec4 pos = vec4(inPosition, 1.0);
|
|
#endif
|
|
|
|
posInView = modelViewMatrix * pos;
|
|
gl_Position = projectionMatrix * posInView;
|
|
}
|