Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some questions in lesson 6 #87

Open
blxl909 opened this issue Nov 26, 2021 · 1 comment
Open

Some questions in lesson 6 #87

blxl909 opened this issue Nov 26, 2021 · 1 comment

Comments

@blxl909
Copy link

blxl909 commented Nov 26, 2021

In the normal mapping part of lesson 6,when we calculate nl, why uniform_M is ProjectionModelView and uniform_MIT is (Projection*ModelView).invert_transpose(), I think it should be ModelView and ModelView.invert_transpose() . since Projection matrix is non-linear, doing calculation in clip space confusing me a lot, maybe we should just calculate it in world or view space?

the code responds is follow:

`
struct Shader : public IShader {
mat<2,3,float> varying_uv;
mat<4,4,float> uniform_M; // ProjectionModelView, why? I think it should be ModelView
mat<4,4,float> uniform_MIT; // (Projection
ModelView).invert_transpose(), why? I think it should be ModelView.invert_transpose()

virtual Vec4f vertex(int iface, int nthvert) {
    varying_uv.set_col(nthvert, model->uv(iface, nthvert));
    Vec4f gl_Vertex = embed<4>(model->vert(iface, nthvert)); 
    return Viewport*Projection*ModelView*gl_Vertex; 

}

virtual bool fragment(Vec3f bar, TGAColor &color) {
    Vec2f uv = varying_uv*bar;  
    Vec3f n = proj<3>(uniform_MIT*embed<4>(model->normal(uv))).normalize();
    Vec3f l = proj<3>(uniform_M  *embed<4>(light_dir        )).normalize();
    float intensity = std::max(0.f, n*l);
    color = model->diffuse(uv)*intensity;  
    return false;        
}

`
My English is not so well, but I still want to thank you for your starting this project, I figure out many questions that have puzzled me a long time :)

@JIanhuaLi-CASC
Copy link

I think light vector nl can be calculated in both world or view space. But if we choose one space, then the normal vector must be calculated in the same space, the dot between the n and nl are the same for different spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants