regl 纹理重复,镜面和边缘填充

原文链接: regl 纹理重复,镜面和边缘填充

上一篇: regl depth 深度缓冲

下一篇: regl 使用json数据绘制雪花

http://www.jiazhengblog.com/blog/2015/12/10/2772/

up-277d8ab97259f60e96f7678a21147f612cc.png

up-65a5a5ec19b7414a0383fe12c4ed45b805d.png

up-ea046775d8e0b98e4629a24f10fbcb9a734.png

平铺和镜面的话必须是一个宽高 都是2的次幂的图片

import REGL from "regl";
import { getImg, imageResize } from "../../utils/index";
export default async (canvas: HTMLCanvasElement) => {
  const { url } = await imageResize("/img/test2.jpg", {
    width: 1024,
    height: 512,
  });
  const img = await getImg(url);
  console.log(img);
  const regl = REGL(canvas);
  const texture = regl.texture({
    data: img,
    //  wrap: "repeat",
    // wrap: "mirror",
    wrap: "clamp",
    mipmap: false,
  });
  console.log("texture", texture);
  interface Uniforms {
    texture: REGL.Texture2D;
  }

  interface Attributes {
    position: [number, number][];
    aVsUv: [number, number][];
    aVsColor: [number, number, number][];
  }

  regl<Uniforms, Attributes>({
    frag: `
  precision mediump float;
  uniform sampler2D texture;
  varying vec2 uv;
  varying vec3 outColor;
  void main () {
    // gl_FragColor = vec4(outColor,1);
    gl_FragColor = texture2D(texture, uv);
    // gl_FragColor = vec4(0,1,0,1);

    // 交换颜色通道
    // gl_FragColor = texture2D(texture, uv).bgra;
  }`,

    vert: `
  precision mediump float;
  attribute vec2 position;
  attribute vec3 aVsColor;
  attribute vec2 aVsUv;
  varying vec2 uv;
  varying vec3 outColor;
  void main () {
    uv = aVsUv;
    outColor=aVsColor;
    // gl_Position = vec4(1.0 - 2.0 * position, 0, 1);
    gl_Position =  vec4(position,0,1);
  }`,

    attributes: {
      position: [
        [-0.5, 0.5],
        [0.5, 0.5],
        [0.5, -0.5],
        [-0.5, 0.5],
        [0.5, -0.5],
        [-0.5, -0.5],
      ],
      aVsColor: [
        [1, 0, 0],
        [1, 0, 0],
        [1, 0, 0],
        [0, 1, 0],
        [0, 1, 0],
        [0, 1, 0],
      ],
      aVsUv: [
        [0.0, 0.0],
        [2.0, 0.0],
        [2.0, 2.0],
        [0.0, 0.0],
        [2.0, 2.0],
        [0.0, 2.0],
      ],
    },
    uniforms: {
      texture,
    },
    count: 6,
  })();
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值