2013-07-02 54 views
0

我想創建一個擴展lambert着色器的自定義材質,但設置網格半透明不起作用。延伸lambert材料,不透明不工作

var shaders = { lambert : THREE.ShaderLib['lambert'] } 

materials.mylambert = function(parameters){ 

    var vertexShader = shaders.mylambert.vertexShader 
    , fragmentShader = shaders.mylambert.fragmentShader 
    , uniforms = shaders.mylambert.uniforms 
    , attributes = {} 

    var material = new THREE.ShaderMaterial( 
    { vertexShader: vertexShader 
    , fragmentShader: fragmentShader 
    , uniforms: uniforms 
    , lights : true 
    , fog : true 
    }) 

    material.setValues(parameters) 
    return material 
} 
var material = new materials.mylambert({ opacity : 0.4, transparent : true }) 
var mesh = new THREE.Mesh(geom, material) 
+0

什麼是你的最終目標是什麼?你想添加新的制服還是修改現有的制服?你爲什麼這樣做? – WestLangley

+0

是的,我想修改現有的,並添加新的,但起初我想要得到它的行爲像原始朗伯材料,然後從那裏工作。 – supernova

+0

我的目標之一是將0-255之間的int值傳遞給顏色的頂點着色器,而不是每個頂點4 float32。 – supernova

回答

2

您需要從材料制服中分離材料的屬性。你可以讓你的具體的例子,像這樣的工作:

var shaders = { mylambert : THREE.ShaderLib[ 'lambert' ] }; 

var materials = {}; 

materials.mylambert = function(parameters, myUniforms) { 

    var material = new THREE.ShaderMaterial({ 

     vertexShader: shaders.mylambert.vertexShader, 
     fragmentShader: shaders.mylambert.fragmentShader, 
     uniforms: THREE.UniformsUtils.merge([ shaders.mylambert.uniforms, myUniforms ]), 
     attributes: {} 

    }); 

    material.setValues(parameters) 

    return material; 

}; 

myProperties = { 
    lights: true, 
    fog: true, 
    transparent: true 
}; 

myUniforms = { 
    opacity: { type: "f", value: 0.4 }, 
}; 

var material = new materials.mylambert(myProperties, myUniforms); 

three.js所r.58