Mix - Bilinear Interpolation

Task

To fill the screen using bilinear interpolation, follow these steps:

  1. Assign the color blue to the left-top corner of the screen.

  2. Assign the color red to the left-bottom corner of the screen.

  3. Assign the color green to the right-top corner of the screen.

  4. Assign the color black to the right-bottom corner of the screen.

  5. Use bilinear interpolation to blend the colors in between the corners and fill the screen with a smooth gradient.
    使用双线性的方式铺满屏幕,如下步骤实现:

  6. 屏幕左上角设置为蓝色

  7. 屏幕左下角设置为红色

  8. 屏幕右上角设置为绿色

  9. 屏幕右下角设置为黑色

  10. 使用双线性渲染的方式,两个角直接通过线性插值实现

Theory

Bilinear interpolation 是一种决定每个像素颜色的一种特定的方法。分别是XY轴方向进行线性插值

具体实现步骤

  1. Horizontal Interpolation. 先做一次横向的线性插值.
  2. Vertical Interpolation. 在做一次纵向的线性插值。

注意:因为是一个面有4个点,所以横向插值时需要做上下两边。

Answer

glsl 复制代码
uniform vec2 iResolution;

void main() {
  // Normalized pixel coordinates (from 0 to 1)
  vec2 uv = gl_FragCoord.xy / iResolution.xy;
  
  vec3 red = vec3(1.0, 0.0, 0.0);
  vec3 black = vec3(0.0, 0.0, 0.0);
  vec3 blue = vec3(0.0, 0.0, 1.0);
  vec3 green = vec3(0.0, 1.0, 0.0);
  vec3 t1 = mix(red, black, uv.x);
  vec3 t2 = mix(blue, green, uv.x);
  vec3 color = mix(t1, t2, uv.y);
  
  gl_FragColor = vec4(color, 1.0);
}

效果

练习

Mix - Bilinear Interpolation

最后

如果你觉得这篇文章有用,记得点赞、关注、收藏,学Shader更轻松!!

相关推荐
We་ct6 小时前
LeetCode 5. 最长回文子串:DP + 中心扩展
前端·javascript·算法·leetcode·typescript
陈随易10 小时前
有生之年系列,Nodejs进程管理pm2 v7.0发布
前端·后端·程序员
冰暮流星10 小时前
javascript之事件代理/事件委托
前端
陈随易11 小时前
AI时代,你还在坚持手搓文章吗
前端·后端·程序员
里欧跑得慢13 小时前
17. Flutter Hero动画实现:让界面过渡更加优雅
前端·css·flutter·web
IT_陈寒14 小时前
Vue的这个响应式陷阱,我debug了一整天才爬出来
前端·人工智能·后端
kyriewen14 小时前
前端测试:别为了100%覆盖率而写测试,那是自欺欺人
前端·javascript·单元测试
去伪存真14 小时前
我自己写的第一个skills--project-core-standards
前端·agent
Data_Journal14 小时前
如何使用cURL更改User Agent
大数据·服务器·前端·javascript·数据库
竹林81815 小时前
wagmi v2 多链钱包切换:一个 Uniswap 仿盘项目让我踩了三天坑
前端·javascript