Skip to content
Snippets Groups Projects
Commit b8cccb7b authored by Adam Borgstrand's avatar Adam Borgstrand
Browse files

Fix bump mapping by multiplying normal with TBN

parent 6f842ec0
Branches
No related tags found
No related merge requests found
No preview for this file type
......@@ -182,8 +182,8 @@ void init(void)
//m = LoadModel("groundsphere.obj");
texID1 = LoadTexture("Substance_Normal92df.jpg", 1); // Flipped. Klipper?! FIXAD!
//texID1 = LoadTexture("normal.jpg", 1); // Flipped. Klipper?! FIXAD!
//texID1 = LoadTexture("Substance_Normal92df.jpg", 1); // Flipped. Klipper?! FIXAD!
texID1 = LoadTexture("normal.jpg", 1); // Flipped. Klipper?! FIXAD!
// Defaults to unit 0
glUniform1i(glGetUniformLocation(program,"texUnit"),0);
......
......@@ -62,7 +62,7 @@ vec3 CameraRay(float fieldOfViewY, float aspectRatio, vec2 point)
vec2 UV(vec3 intersection, int ID)
{
vec3 d = normalize(intersection - object_descriptor[ID]);
float U = 0.5 + atan(d.x, d.z)/(2.0*3.141592);
float U = 0.5 + atan(d.z, d.x)/(2.0*3.141592);
float V = 0.5 + asin(d.y)/3.141592;
return vec2(U,V);
}
......@@ -76,7 +76,7 @@ float thetaSphere(vec3 intersection, int ID)
vec3 theta_hat(float theta)
{
vec3 theta_hat = vec3(-cos(theta),-sin(theta), 0);
vec3 theta_hat = vec3(-cos(theta),sin(theta), 0);
return theta_hat;
}
......@@ -207,6 +207,11 @@ vec3 CalculateNormal(vec3 intersection_point, int id)
mat3 tbn = TBN(N,B,T);
vec2 uv = UV(intersection_point, id);
vec3 normal = normalize(texture(texUnit, uv).rgb*2.0 - 1.0);
normal = tbn * normal;
//if (dot(N, normal) < 0)
//{
// normal = -normal;
//}
return normal;
}
......@@ -320,7 +325,7 @@ void main(void)
if ((closest_id>=0) && (closest_distance<1500))
{
int nr_reflections = 3;
int nr_reflections = 5;
int reflections = 0;
int closest_id_temp = -1;
for (int i = 0; i<nr_reflections; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment