TDT4230_final_project/res/shaders/simple.vert

63 lines
2.0 KiB
GLSL
Raw Normal View History

2019-02-04 18:32:08 +01:00
#version 430 core
in layout(location = 0) vec3 position;
in layout(location = 1) vec3 normal;
2019-03-14 12:43:41 +01:00
in layout(location = 2) vec2 UV;
2019-03-18 11:48:11 +01:00
in layout(location = 3) vec4 color;
in layout(location = 4) vec3 tangent;
in layout(location = 5) vec3 bitangent;
2019-02-04 18:32:08 +01:00
layout(binding = 0) uniform sampler2D diffuseTexture;
layout(binding = 1) uniform sampler2D normalTexture;
2019-03-16 20:12:35 +01:00
layout(binding = 2) uniform sampler2D displacementTexture;
2019-03-19 20:15:13 +01:00
layout(binding = 3) uniform sampler2D reflectionTexture;
2019-03-16 20:12:35 +01:00
uniform float displacementCoefficient;
2019-03-15 16:26:31 +01:00
uniform mat4 MVP;
uniform mat4 MV;
uniform mat4 MVnormal;
// material
uniform vec2 uvOffset;
uniform float opacity;
uniform float shininess;
uniform vec3 diffuse_color;
uniform vec3 specular_color;
uniform vec3 emissive_color;
2019-03-14 12:43:41 +01:00
uniform bool isIlluminated;
uniform bool isTextured;
uniform bool isVertexColored;
2019-03-14 12:43:41 +01:00
uniform bool isNormalMapped;
uniform bool isDisplacementMapped;
uniform bool isReflectionMapped;
uniform bool isInverted;
2019-02-04 18:32:08 +01:00
2019-03-16 20:12:35 +01:00
out layout(location = 0) vec3 vertex_out;
out layout(location = 1) vec3 normal_out;
2019-03-14 12:43:41 +01:00
out layout(location = 2) vec2 uv_out;
2019-03-18 11:48:11 +01:00
out layout(location = 3) vec4 color_out;
out layout(location = 4) vec3 tangent_out;
out layout(location = 5) vec3 bitangent_out;
2019-02-04 18:32:08 +01:00
2019-03-14 12:43:41 +01:00
void main() {
vec3 displacement = vec3(0.0);
if (isDisplacementMapped) {
float o = texture(displacementTexture, UV + uvOffset).r * 2.0 - 1.0;
float u = (texture(displacementTexture, UV + uvOffset + vec2(0.001, 0.0)).r*2.0-1.0 - o) / 0.004;
float v = (texture(displacementTexture, UV + uvOffset + vec2(0.0, 0.001)).r*2.0-1.0 - o) / 0.004;
displacement = normal * displacementCoefficient * o;
}
normal_out = normalize(vec3(MVnormal * vec4(normal, 1.0f)));
vertex_out = vec3(MV * vec4(position+displacement, 1.0f));
uv_out = UV + uvOffset;
gl_Position = MVP * vec4(position+displacement, 1.0f);
2019-03-14 12:43:41 +01:00
2019-03-18 11:48:11 +01:00
color_out = color;
tangent_out = normalize(vec3(MVnormal * vec4(tangent, 1.0f)));
bitangent_out = normalize(vec3(MVnormal * vec4(bitangent, 1.0f)));
2019-02-04 18:32:08 +01:00
}