GAMES 101 现代计算机图形学 作业3 双线性插值

其他的都没什么好说的,这里记录一下 双线性插值的应用过程

代码是学习这位大佬的 :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不知道为啥用不了

使用插值前
在这里插入图片描述

使用插值后
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值