not correct way of using normal maps but gives me some preliminary info.

This commit is contained in:
Warwick 2022-07-26 15:25:28 +01:00
parent 2eabd78ed5
commit 532382b1f9
3 changed files with 22 additions and 6 deletions

View file

@ -4,6 +4,7 @@ out vec4 FragColor;
in vec2 ourTexCoord;
in vec3 ourNormCoord;
in vec3 WorldPos;
in mat4 TBN;
// TODO: make temporary hard coded world/camera pos dynamic
//uniform vec3 WorldPos ;
@ -70,15 +71,31 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
return ggx1 * ggx2;
}
vec3 normal(){
// load and invert normal
vec3 normal = normalize(texture(texture_normal1, ourTexCoord).rgb * 2.0 - 1.0);
normal = (TBN * vec4(normal, 1.0)).xyz;
//TODO: Make the normal vector match the matrix of the rest of the model by
//actually calculating the TBN
return normal;
}
vec3 PBR(vec3 albedo, float roughness, float metallic, float ao)
{
// Establish a temporary hard coded light position
vec3 lightPosition = vec3( (sin(tick / 1000.0)*2), 1 + sin(tick / 600.0)*2, 2.0);
vec3 lightPosition = vec3( 1, 1, 2);
//vec3 lightPosition = vec3( (sin(tick / 1000.0)*2), 1 + sin(tick / 600.0)*2, 2.0);
//vec3 lightColor = vec3(1.0, 1.0, 1.0) - sin(tick / 90);
vec3 lightColor = vec3(13.47, 11.31, 10.79);
vec3 N = normalize(ourNormCoord);
vec3 V = normalize(CameraPos - WorldPos);
N = (N + normal()) / 2;
//N = normal(); For seeing if normal map tracks with light.
vec3 F0 = vec3(0.04);
F0 = mix(F0, albedo, metallic);
@ -126,9 +143,5 @@ void main()
float metallic = texture(texture_rma1, ourTexCoord).g;
float ao = texture(texture_rma1, ourTexCoord).b;
// Normals
// load and invert normal
vec3 normal = normalize(texture(texture_normal1, ourTexCoord).rgb * 2.0 - 1.0);
FragColor = vec4(PBR(albedo, roughness, metallic, ao), 1.0);
}

View file

@ -13,7 +13,7 @@ out vec3 ourNormCoord;
out vec3 WorldPos;
//Normals
out mat3 TBN;
out mat4 TBN;
void main()
{
@ -21,6 +21,8 @@ void main()
ourNormCoord = aNormal;
ourTexCoord = aTexCoord;
TBN = Model;
// Calculate position of fragment
WorldPos = vec3(Model * vec4(aPos, 1.0));
};

View file

@ -126,6 +126,7 @@ int main(int argc, char **argv) {
shader.setMat4("MVP", camera.getMVP());
shader.setVec3("CameraPos", camera.getCameraPosition());
shader.setInt("tick", SDL_GetTicks());
boxbarrel.rotate(0.001, glm::vec3(0, 1, 0));
// Draw Meshes
// cube.draw(shader);