GAMES101 作业3(附三角形重心坐标,Blinn 您所在的位置:网站首页 三角形重心向量坐标推导 GAMES101 作业3(附三角形重心坐标,Blinn

GAMES101 作业3(附三角形重心坐标,Blinn

2024-07-06 14:32| 来源: 网络整理| 查看: 265

目录

写在前面

第一题 三角形重心坐标

第二题 Blinn-Phong光照模型

第三题 纹理贴图

第四题 凹凸贴图实现及法线贴图推导

第五题 位移贴图

写在前面

        main 函数中  std::function active_shader = displacement_fragment_shader 这一句是指定当前的着色方式,  将等号后的displacement_fragment_shader 改为 phong_fragment_shader 等方法函数名即可, 或者在属性中修改命令行参数也可以。

第一题 三角形重心坐标

题目: 对三角形顶点处的各属性进行插值, 并进行着色。

void rst::rasterizer::rasterize_triangle(const Triangle& t, const std::array& view_pos) { // TODO: From your HW3, get the triangle rasterization code. // TODO: Inside your rasterization loop: // * v[i].w() is the vertex view space depth value z. // * Z is interpolated view space depth for the current pixel // * zp is depth between zNear and zFar, used for z-buffer // float Z = 1.0 / (alpha / v[0].w() + beta / v[1].w() + gamma / v[2].w()); // float zp = alpha * v[0].z() / v[0].w() + beta * v[1].z() / v[1].w() + gamma * v[2].z() / v[2].w(); // zp *= Z; // TODO: Interpolate the attributes: // auto interpolated_color // auto interpolated_normal // auto interpolated_texcoords // auto interpolated_shadingcoords // Use: fragment_shader_payload payload( interpolated_color, interpolated_normal.normalized(), interpolated_texcoords, texture ? &*texture : nullptr); // Use: payload.view_pos = interpolated_shadingcoords; // Use: Instead of passing the triangle's color directly to the frame buffer, pass the color to the shaders first to get the final color; // Use: auto pixel_color = fragment_shader(payload); }

解析: 

1. 三角形重心坐标的推导:

        首先推导直线重心坐标, 然后由直线推广到三角形。

1.1 直线重心坐标: 

        设有向量 AB, A点坐标(a1, a2), B点坐标(b1, b2),  直线上有任意一点 C(c1, c2)。如何用 A, B 两点来表示 C?可以用点起始点坐标加上 k 倍的向量得到 C = A + k\vec{AB} = A + kB - kA = (1-k)A + kB 

因为 kAB 这个向量的起点是原点,所以 A + kAB 也就是把 kAB 这个向量的起点从原点挪到了 A 点。又因为 C 点在 AB 上, 所以要满足 0



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有