Browse Source

Merge pull request #5016 from Sir-Irk/fix_pbr_example_tangents

[example] Fix pbr example shaders to use vec4 for vertexTangent
pull/5018/head
Ray 2 weeks ago
committed by GitHub
parent
commit
8cf932c822
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions
  1. +3
    -3
      examples/shaders/resources/shaders/glsl100/pbr.vs
  2. +4
    -4
      examples/shaders/resources/shaders/glsl120/pbr.vs
  3. +4
    -4
      examples/shaders/resources/shaders/glsl330/pbr.vs

+ 3
- 3
examples/shaders/resources/shaders/glsl100/pbr.vs View File

@ -4,7 +4,7 @@
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec3 vertexTangent;
attribute vec4 vertexTangent;
attribute vec4 vertexColor;
// Input uniform values
@ -52,7 +52,7 @@ mat3 transpose(mat3 m)
void main()
{
// Compute binormal from vertex normal and tangent
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz) * vertexTangent.w;
// Compute fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
@ -62,7 +62,7 @@ void main()
fragTexCoord = vertexTexCoord*2.0;
fragNormal = normalize(normalMatrix*vertexNormal);
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);

+ 4
- 4
examples/shaders/resources/shaders/glsl120/pbr.vs View File

@ -4,7 +4,7 @@
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec3 vertexTangent;
attribute vec4 vertexTangent;
attribute vec4 vertexColor;
// Input uniform values
@ -52,7 +52,7 @@ mat3 transpose(mat3 m)
void main()
{
// Compute binormal from vertex normal and tangent
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz) * vertexTangent.w;
// Compute fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
@ -62,7 +62,7 @@ void main()
fragTexCoord = vertexTexCoord*2.0;
fragNormal = normalize(normalMatrix*vertexNormal);
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
@ -71,4 +71,4 @@ void main()
// Calculate final vertex position
gl_Position = mvp*vec4(vertexPosition, 1.0);
}
}

+ 4
- 4
examples/shaders/resources/shaders/glsl330/pbr.vs View File

@ -4,7 +4,7 @@
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
in vec3 vertexTangent;
in vec4 vertexTangent;
in vec4 vertexColor;
// Input uniform values
@ -26,7 +26,7 @@ const float normalOffset = 0.1;
void main()
{
// Compute binormal from vertex normal and tangent
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz) * vertexTangent.w;
// Compute fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
@ -36,7 +36,7 @@ void main()
fragTexCoord = vertexTexCoord*2.0;
fragNormal = normalize(normalMatrix*vertexNormal);
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
vec3 fragTangent = normalize(normalMatrix*vertexTangent.xyz);
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
@ -45,4 +45,4 @@ void main()
// Calculate final vertex position
gl_Position = mvp*vec4(vertexPosition, 1.0);
}
}

Loading…
Cancel
Save