2016-05-27 50 views
0

我希望看到每個頂點指定顏色的圖表並獲得一點陰影。 但是,如果我使用MeshBasicMaterial,我只會得到VertexColor而沒有動態陰影。 另一方面,如果我使用MeshPhongMaterial我只是得到陰影,但沒有從我的頂點顏色發射。我如何在ThreeJS中每個頂點和每個頂點照明發光?

+0

看看下面這個例子http://threejs.org/examples/#webgl_geometry_colors –

+0

感謝您的評論,我reviewd和嘗試,但我使用BufferGeometry而且好像createMultiMaterialObject是隻使用幾何。我試圖跳過寫一個着色器,但似乎我不能逃避。 –

回答

0

由於THREE.JS PhongMaterial支持vertexColors,給你一個動態照明和頂點顏色的完美結合,我不太清楚我理解你的問題。也許這是你應該調查更多的東西?

但是,作爲編寫自定義着色器的替代方法,您可以嘗試以多遍渲染模型。

這不會給你太多的控制頂點顏色和phong照明如陰影一樣的方式,但通常一個簡單的加/乘混合可以給出相當不錯的結果。

算法:

- create two meshes for the BufferGeometry, one with the BasicMaterial and one with the PhongMaterial 
- for the PhongMaterial, set 
    depthFunc = THREE.EqualDepth 
    transparent = true; 
    blending = THREE.AdditiveBlending(or MultiplyBlending) 
- render the first mesh 
- render the second mesh at the exact same spot