目录
一、渲染小奶牛
1. normal shader
get_projection_matrix (来自作业1,填充在main.cpp中)
rasterize_triangle(来自作业2,填充在rasterizer.cpp中)
2. phong shader
phong_fragment_shader(填充在main.cpp中)
3. texture shader
texture_fragment_shader(填充在main.cpp中)
4. bump shader
bump_fragment_shader(填充在main.cpp中)
4. displacement shader
displacement_fragment_shader(填充在main.cpp中)
二、使用.obj模型
三、双线性插值
四、踩坑总结
根据官方教程,我们需要使用 作业1、作业2 里面实现的代码来填充以下两个函数,并得到样例normal shader的渲染结果:
// TODO: Use the same projection matrix from the previous assignments
Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar)
{Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();Eigen::Matrix4f M_p = Eigen::Matrix4f::Identity();M_p << zNear,0,0,0,0,zNear,0,0,0,0,zNear+zFar,(-1.0*zNear*zFar),0,0,1,0;//[l,r] [b,t] [f,n]float angle = eye_fov*MY_PI/180;float t = tan(angle/2)*-zNear;float b = -1.0*t;float r = t*aspect_ratio;float l = -1.0*r;Eigen::Matrix4f M_s = Eigen::Matrix4f::Identity();M_s << 2/(r-l),0,0,0,0,2/(t-b),0,0,0,0,2/(zNear-zFar),0,0,0,0,1;Eigen::Matrix4f M_t = Eigen::Matrix4f::Identity();M_t << 1,0,0,(-1.0)*(r+l)/2,0,1,0,(-1.0)*(t+b)/2,0,0,1,(-1.0)*(zNear+zFar)/2,0,0,0,1;projection = M_s*M_t*M_p*projection;return projection;
}
// my func
float min2(float a, float b) {if (a < b) return a;else return b;
}// my func
float min3(float a, float b, flo
本文发布于:2024-01-31 15:12:57,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170668517829427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |