Closed XiaofanLinUS closed 2 years ago
Good finding, should be zero at the fourth homogeneous coordinate.
Thanks. That solves my concerns.
Another thing though. Is it necessary to perform the matrix transformation? Since both normal and light_dir are technically in world space now where the model matrix is identity. I don't see the need to do such a matrix transformation. (But in my implementation, the intensity is a bit dim after matrix transformation. Maybe I have some other bugs somewhere.) I have referred to other resources too. Some only perform the normal transformation under the circumstance that the model matrix is not an identity matrix without combining the matrix with perspective projection.
And one more question. Does proj<3> function just drop the w coordinate to convert from vec4 to vec3? Just to confirm the implementation. That's pretty much it. Thanks!
Yes, in my implementation proj<3> simply drops the 4th coordinate. You do not always have to transform normals/lights to the normalized device coordinates (e.g. for static scenes), but sometimes you don't have choice. Choose whatever space is simpler in your case.
Ok, my last attempt to perform a transformation on normal according to your codes failed. Do you have any idea on how to solve it? I can continue but it still bugs me.
Wow, that is a nice bug. From visual inspection alone I have no idea...
It turns out I use light_dir as a global variable without noticing it. The bug is fixed now.
I am implementing normal mapping from texture. I am encountering some issues regarding transforming the normal into another space.
This is the provided code for calculating intensity per pixel level on normal texture.
I inspect the source code for function "embed<4>". I realize the default fill value is 1 but shouldn't the vector instead of point be filled with 0 instead, both for normal and the light_dir 3-dim-vector? I didn't use provided lib for matrix operations since I am doing the tutorial on javascript so I am confusing how to implement the embed function. Thanks.