什么是THREE.NormalBlending的混合方程?

时间:2017-06-05 04:50:10

标签: javascript three.js

我在文档中找不到它。谁能告诉我这个等式是什么?

我认为它等于以下THREE.CustomBlending

    blending: THREE.CustomBlending,
    blendEquation: THREE.AddEquation,
    blendSrc: THREE.SrcAlphaFactor,
    blendDst: THREE.OneMinusSrcAlphaFactor

但是当我将材料从NormalBlending更改为上面的CustomBlending时,我得到了不同的结果。

以下是关于默认CustomBlending的{​​{3}}。

1 个答案:

答案 0 :(得分:2)

Looking at the source code各种Three.js混合模式根据材料是否标记为使用预乘alpha而不同

因此,如果材料被认为是预乘的,那么它应该与

相同
blending: THREE.CustomBlending,
blendEquation: THREE.AddEquation,
blendSrc: THREE.OneFactor,
blendDst: THREE.OneMinusSrcAlphaFactor

否则就是

blending: THREE.CustomBlending,
blendEquation: THREE.AddEquation,
blendSrc: THREE.SrcAlphaFactor,
blendSrcAlpha: THREE.OneFactor,
blendDst: THREE.OneMinusSrcAlphaFactor



"use strict";

const nonPremultipledBlend = {
  blending: THREE.CustomBlending,
  blendEquation: THREE.AddEquation,
  blendSrc: THREE.SrcAlphaFactor,
  blendSrcAlpha: THREE.OneFactor,
  blendDst: THREE.OneMinusSrcAlphaFactor,
};

const premultipledBlend = {
  blending: THREE.CustomBlending,
  blendEquation: THREE.AddEquation,
  blendSrc: THREE.OneFactor,
  blendDst: THREE.OneMinusSrcAlphaFactor,
};


const renderer = new THREE.WebGLRenderer();
document.body.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-1.5, 1.5, 1, -1, -1, 1);
camera.position.z = 1;
const scene = new THREE.Scene();
const geometry = new THREE.PlaneGeometry(.5, .5);
[
  { color: 0xFF8080, x: -.6,  y:    0, z: 0.2, },
  { color: 0x008040, x: -.30, y: -.25, z: 0.1, },
  { color: 0x008040, x: -.90, y: -.25, z: 0.1, blend: nonPremultipledBlend, },
  { color: 0xFF8080, x:  .6,  y:    0, z: 0.2, },
  { color: 0x008040, x:  .30, y: -.25, z: 0.1, pre: true, },
  { color: 0x008040, x:  .90, y: -.25, z: 0.1, pre: true, blend: premultipledBlend, },
].forEach(info => {
  const material = new THREE.MeshBasicMaterial({
    color: info.color,
    transparent: true,
    opacity: .5,
  });
  if (info.pre) {
    material.premultipliedAlpha = info.pre;
  }
  if (info.blend) {
    Object.assign(material, info.blend);
  }
  const mesh = new THREE.Mesh(geometry, material);
  scene.add(mesh);
  mesh.position.x = info.x;
  mesh.position.y = info.y;
  mesh.position.z = info.z;
});
renderer.render(scene, camera);

body { margin: 0; }
canvas { width: 100vw; height: 100vh; display block; }

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/85/three.min.js"></script>
&#13;
&#13;
&#13;