Add normal mapping support for gltf
This commit is contained in:
@@ -4,9 +4,7 @@ layout(location = 0) out vec4 f_color;
|
||||
|
||||
in vec3 v_normal;
|
||||
in vec2 v_texCoord;
|
||||
in vec3 v_fragmentPosition;
|
||||
in vec3 v_fragmentPositionTangent;
|
||||
in vec4 v_fragmentPositionDirectionalLightSpace;
|
||||
|
||||
in vec3 v_lightDirectionTangent;
|
||||
in vec3 v_lightPositionTangent0;
|
||||
@@ -62,6 +60,7 @@ void main()
|
||||
|
||||
vec3 normal = texture(u_material.texture_normal, v_texCoord).rgb;
|
||||
normal = normalize(normal * 2.0 - 1.0);
|
||||
|
||||
vec3 viewDir = normalize(v_viewPositionTangent - v_fragmentPositionTangent);
|
||||
|
||||
fragmentColor += directionalLightContribution(u_directionalLight, normal, viewDir);
|
||||
@@ -69,10 +68,7 @@ void main()
|
||||
for (int i = 0; i < NUM_POINT_LIGHTS; i++) {
|
||||
fragmentColor += pointLightContribution(u_pointLight[i], normal, v_fragmentPositionTangent, viewDir);
|
||||
}
|
||||
|
||||
// fragmentColor = (v_normal + 1.0f) * 0.5f;
|
||||
fragmentColor = vec3(texture(u_material.texture_diffuse, v_texCoord));
|
||||
|
||||
|
||||
f_color = vec4(fragmentColor, 1.0f);
|
||||
}
|
||||
|
||||
@@ -132,8 +128,7 @@ void computeShading(vec3 light_ambient, vec3 light_diffuse, vec3 light_specular,
|
||||
|
||||
ambient = light_ambient * vec3(diffuseTex);
|
||||
diffuse = light_diffuse * diffuseShading * vec3(diffuseTex);
|
||||
// specular = light_specular * specularShading * vec3(specularTex);
|
||||
specular = vec3(0.0f);
|
||||
specular = light_specular * specularShading * vec3(1.0f);//vec3(specularTex);
|
||||
}
|
||||
|
||||
float computeAttenuation(vec3 lightPos, vec3 fragPos, float K_q)
|
||||
|
||||
@@ -3,19 +3,18 @@
|
||||
layout(location = 0) in vec3 a_position;
|
||||
layout(location = 1) in vec2 a_texCoord;
|
||||
layout(location = 2) in vec3 a_normal;
|
||||
layout(location = 3) in vec3 a_tangent;
|
||||
layout(location = 4) in vec3 a_bitangent;
|
||||
layout(location = 3) in vec4 a_tangent;
|
||||
|
||||
out vec3 v_normal;
|
||||
out vec2 v_texCoord;
|
||||
|
||||
out vec3 v_fragmentPosition;
|
||||
out vec3 v_fragmentPositionTangent;
|
||||
out vec4 v_fragmentPositionDirectionalLightSpace;
|
||||
|
||||
out vec3 v_viewPositionTangent;
|
||||
|
||||
struct DirectionalLight {
|
||||
struct DirectionalLight
|
||||
{
|
||||
vec3 direction;
|
||||
bool isActive;
|
||||
vec3 color;
|
||||
@@ -23,7 +22,8 @@ struct DirectionalLight {
|
||||
uniform DirectionalLight u_directionalLight;
|
||||
out vec3 v_lightDirectionTangent;
|
||||
|
||||
struct PointLight {
|
||||
struct PointLight
|
||||
{
|
||||
vec3 position;
|
||||
bool isActive;
|
||||
vec3 color;
|
||||
@@ -31,37 +31,27 @@ struct PointLight {
|
||||
#define NUM_POINT_LIGHTS 1
|
||||
uniform PointLight u_pointLight[NUM_POINT_LIGHTS];
|
||||
out vec3 v_lightPositionTangent0;
|
||||
//out vec3 v_lightPositionTangent1;
|
||||
//out vec3 v_lightPositionTangent2;
|
||||
//out vec3 v_lightPositionTangent3;
|
||||
|
||||
uniform vec3 u_viewPosition;
|
||||
|
||||
uniform mat4 u_modelViewProjMatrix;
|
||||
uniform mat4 u_modelMatrix;
|
||||
|
||||
uniform mat4 u_directionalLightViewProjMatrix;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_modelViewProjMatrix * vec4(a_position, 1.0f);
|
||||
|
||||
vec3 T = normalize(vec3(u_modelMatrix * vec4(a_tangent, 0.0f)));
|
||||
vec3 B = normalize(vec3(u_modelMatrix * vec4(a_bitangent, 0.0f)));
|
||||
vec3 T = normalize(vec3(u_modelMatrix * vec4(a_tangent.xyz, 0.0f)));
|
||||
vec3 N = normalize(vec3(u_modelMatrix * vec4(a_normal, 0.0f)));
|
||||
T = normalize(T - dot(T, N) * N);
|
||||
vec3 B = cross(N, T) * a_tangent.w;
|
||||
mat3 TBN_transposed = transpose(mat3(T, B, N));
|
||||
|
||||
v_lightDirectionTangent = TBN_transposed * u_directionalLight.direction;
|
||||
v_lightPositionTangent0 = TBN_transposed * u_pointLight[0].position;
|
||||
//v_lightPositionTangent1 = vec3(0.0f);
|
||||
//v_lightPositionTangent2 = vec3(0.0f);
|
||||
//v_lightPositionTangent3 = vec3(0.0f);
|
||||
|
||||
v_fragmentPositionTangent = TBN_transposed * vec3(u_modelMatrix * vec4(a_position, 1.0f));
|
||||
|
||||
v_fragmentPosition = vec3(u_modelMatrix * vec4(a_position, 1.0f));
|
||||
v_fragmentPositionDirectionalLightSpace = u_directionalLightViewProjMatrix * vec4(v_fragmentPosition, 1.0f);
|
||||
|
||||
v_viewPositionTangent = TBN_transposed * u_viewPosition;
|
||||
v_viewPositionTangent = TBN_transposed * u_viewPosition; // seems like this is always 0 ?
|
||||
|
||||
v_normal = a_normal;
|
||||
v_texCoord = a_texCoord;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) out vec4 f_color;
|
||||
|
||||
uniform vec3 v_lightColor;
|
||||
|
||||
void main() {
|
||||
f_color = vec4(v_lightColor, 1.0f);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 a_position;
|
||||
|
||||
uniform mat4 u_modelViewProjMatrix;
|
||||
|
||||
void main() {
|
||||
gl_Position = u_modelViewProjMatrix * vec4(a_position, 1.0f);
|
||||
}
|
||||
Reference in New Issue
Block a user