threejs-热力图(shader)

相比于通过改变imageData的方式,本次将透明度阶梯图和温度调色板图传入着色器,在着色器中进行纹理采样最终生成热力图。
着色器代码很简单,先对透明度阶梯图采样,再根据采样值对温度调色板图采样得到最终片元颜色。

<script type="x-shader/x-vertex" id="vertexshader">

  varying vec2 vUv;
  void main() {
    vUv = uv;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  }

</script>

<script type="x-shader/x-fragment" id="fragmentshader">

  #ifdef GL_ES
  precision highp float;
  #endif
  varying vec2 vUv;
  uniform sampler2D alphaScaleMap;
  uniform sampler2D paletteMap;
  void main() {
    vec4 alphaColor = texture2D(alphaScaleMap, vUv);
    vec4 color = texture2D(paletteMap, vec2(alphaColor.a, 0.0));
    gl_FragColor = vec4(color.r, color.g, color.b, alphaColor.a);
  }

</script>

案例源代码:https://github.com/NCQuan/heatMap_Shader/blob/main/heatMap_shader.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值