其他的都没什么好说的,这里记录一下 双线性插值的应用过程
代码是学习这位大佬的 :https://blog.youkuaiyun.com/qq_36242312/article/details/105888669
在Texture.hpp中 添加一个函数
Eigen::Vector3f getColorBilinear(float u,float v)
{
if(u<0) u=0;
if(u>1) u=1;
if(v<0) v=0;
if(v>1) v=1;
auto u_img = u * width;
auto v_img = (1 - v) * height;
float u_min=std::floor(u_img);
float u_max=std::min((float)width,std::ceil(u_img));
float v_min=std::floor(v_img);
float v_max=std::min((float)height,std::ceil(v_img));
auto Q11=image_data.at<cv::Vec3b> (v_max,u_min);
auto Q12=image_data.at<cv::Vec3b> (v_max,u_max);
auto Q21=image_data.at<cv::Vec3b> (v_min,u_min);
auto Q22=image_data.at<cv::Vec3b> (v_min,u_max);
float rs=(u_img-u_min)/(u_max- u_min);
float rt=(v_img-v_max)/(v_min-v_max);
auto cBot = (1-rs)*Q11+ rs* Q12;
auto cTop = (1-rs)*Q21+ rs* Q22;
auto p=(1-rt)*cBot+rt*cTop;
return Eigen::Vector3f(P[0],P[1],P[2]);
}
(1-rs)Q11+ rs Q12;就等价于 rs*(Q12-Q11) +Q11…不过我发现他们都喜欢这样写
然后在main.cpp的 texture_fragment_shader 里面使用它
if (payload.texture)
{
// TODO: Get the texture value at the texture coordinates of the current fragment
// return_color=payload.texture->getColor(payload.tex_coords.x(),payload.tex_coords.y());
return_color=payload.texture->getColorBilinear(payload.tex_coords.x(),payload.tex_coords.y());
}
在main函数里面修改
这个texture.png是我自己缩小的400X400的纹理,作业框架里面的SVG不知道为啥用不了
使用插值前
使用插值后