Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//光の球を4つ定義
var sphere1 =BABYLON.MeshBuilder.CreateSphere("sphere1",{diameter:50},scene);
sphere1.position = new BABYLON.Vector3(-100,-50,0);
var sphere2 =BABYLON.MeshBuilder.CreateSphere("sphere2",{diameter:50},scene);
sphere2.position = new BABYLON.Vector3(100,-50,80);
var sphere3 =BABYLON.MeshBuilder.CreateSphere("sphere3",{diameter:40},scene);
sphere3.position = new BABYLON.Vector3(40,-50,-100);
var sphere4 =BABYLON.MeshBuilder.CreateSphere("sphere4",{diameter:40},scene);
sphere4.position = new BABYLON.Vector3(-120,-50,-100);
//Glowレイヤーを使って、球を自発光させる
var gl = new BABYLON.GlowLayer("glow", scene,{
// mainTextureFixedSize: 1024,
// blurKernelSize: 64
});
gl.intensity = 100;
gl.customEmissiveColorSelector = function(mesh, subMesh, material, result) {
if (mesh.name === "sphere1") {
result.set(0.01, 0, 0.01, 0.2);//発光色を設定。4つめはアルファ値。以下3つも同様
} else if(mesh.name === "sphere2"){
result.set(0, 1, 0.1, 0.2);
} else if(mesh.name === "sphere3"){
result.set(0.01, 0.01, 0, 0.8);
} else if(mesh.name === "sphere4"){
result.set(0, 0.05, 1, 0.1);
} else{
result.set(0,0,0,0);
}
}
//Glowだけでは水面の中で光が弱いので、プールにライトを配置して光を強調
var pointlight1 = new BABYLON.PointLight("pointLight1", new BABYLON.Vector3(-140,-20,-40), scene);
pointlight1.specular = new BABYLON.Color3(0.01,0,0.01);
pointlight1.intensity = 800;
pointlight1.radius = 100;
var pointlight2 = new BABYLON.PointLight("pointLight2", new BABYLON.Vector3(100,-100,-40), scene);
pointlight2.specular = new BABYLON.Color3(0,1,0.1);
pointlight2.intensity = 100;
pointlight2.radius = 50;
var pointlight3 = new BABYLON.PointLight("pointLight3", new BABYLON.Vector3(40,-10,-40), scene);
pointlight3.specular = new BABYLON.Color3(0.01,0.01,0);
pointlight3.intensity = 100;
pointlight3.radius = 100;
var pointlight4 = new BABYLON.PointLight("pointLight3", new BABYLON.Vector3(40,-10,-40), scene);
pointlight4.specular = new BABYLON.Color3(0,0.05,1);
pointlight4.intensity = 100;
pointlight4.radius = 100;
//水面の中にある球を可視化する。(これがないと、水面の下にある球が見えなくなる)
gl.addExcludedMesh(waterMesh);
//post processエフェクトをつける。exposureで光を強調
var postProcess = new BABYLON.ImageProcessingPostProcess("processing", 1.0, camera);
postProcess.exposure = 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment