private void Scene19() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); var material = new BABYLON.StandardMaterial("kosh", scene); material.diffuseColor = BABYLON.Color3.Purple(); var light = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(-17.6, 18.8, -49.9), scene); camera.setPosition(new BABYLON.Vector3(-15, 10, -20)); camera.minZ = 1.0; camera.maxZ = 120.0; // Skybox var skybox = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene); var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene); skyboxMaterial.backFaceCulling = false; skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox", scene); skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE; skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0); skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0); skybox.material = skyboxMaterial; // depth material BABYLON.Effect.ShadersStore["depthVertexShader"] = "#ifdef GL_ES\n" + "precision highp float;\n" + "#endif\n" + "attribute vec3 position;\n" + "uniform mat4 worldViewProjection;\n" + "void main(void) {\n" + "gl_Position = worldViewProjection * vec4(position, 1.0);\n" + "}"; BABYLON.Effect.ShadersStore["depthPixelShader"] = "#ifdef GL_ES\n" + "precision highp float;\n" + "#endif\n" + "void main(void) {\n" + "float depth = 1.0 - (2.0 / (100.0 + 1.0 - gl_FragCoord.z * (100.0 - 1.0)));\n" + "gl_FragColor = vec4(depth, depth, depth, 1.0);\n" + "}\n" + ""; var depthMaterial = new BABYLON.ShaderMaterial( "depth", scene, "depth", new ShaderMaterialOptions() { attributes = new Array <string>("position"), uniforms = new Array <string>("worldViewProjection") }); depthMaterial.backFaceCulling = false; // Plane var plane = BABYLON.Mesh.CreatePlane("map", 10, scene); plane.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL; plane.scaling.y = 1.0 / engine.getAspectRatio(scene.activeCamera); // Render target var renderTarget = new BABYLON.RenderTargetTexture( "depth", new BABYLON.Size() { width = 1024, height = 1024 }, scene); renderTarget.renderList.Add(skybox); scene.customRenderTargets.Add(renderTarget); renderTarget.onBeforeRender = () => { for (var index = 0; index < renderTarget.renderList.Length; index++) { renderTarget.renderList[index]._savedMaterial = renderTarget.renderList[index].material; renderTarget.renderList[index].material = depthMaterial; } }; renderTarget.onAfterRender = () => { // Restoring previoux material for (var index = 0; index < renderTarget.renderList.Length; index++) { renderTarget.renderList[index].material = renderTarget.renderList[index]._savedMaterial; } }; // Spheres var spheresCount = 20; var alpha = 0.0; for (var index = 0; index < spheresCount; index++) { var sphere = BABYLON.Mesh.CreateSphere("Sphere" + index, 32, 3, scene); sphere.position.x = 10 * Math.Cos(alpha); sphere.position.z = 10 * Math.Sin(alpha); sphere.material = material; alpha += (2 * Math.PI) / spheresCount; renderTarget.renderList.Add(sphere); } // Plane material var mat = new BABYLON.StandardMaterial("plan mat", scene); mat.diffuseColor = BABYLON.Color3.Black(); mat.specularColor = BABYLON.Color3.Black(); mat.emissiveTexture = renderTarget; plane.material = mat; // Animations var isReady = false; scene.registerBeforeRender(() => { camera.alpha += 0.01 * scene.getAnimationRatio(); if (!isReady && scene.isReady()) { isReady = true; } }); this.scene.activeCamera.attachControl(this.canvas); }
private void Scene17() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); camera.setPosition(new BABYLON.Vector3(-5, 5, 0)); camera.lowerBetaLimit = 0.1; camera.upperBetaLimit = (Math.PI / 2) * 0.99; camera.lowerRadiusLimit = 5; // Mirror var mirror = BABYLON.Mesh.CreateBox("Mirror", 1.0, scene); mirror.scaling = new BABYLON.Vector3(100.0, 0.01, 100.0); var material = new BABYLON.StandardMaterial("mirror", scene); material.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4); material.specularColor = new BABYLON.Color3(0, 0, 0); //var reflectionTexture0 = new BABYLON.MirrorTexture("mirror", new BABYLON.Size { width = 512, height = 512 }, scene, true); //reflectionTexture0.mirrorPlane = new BABYLON.Plane(0, -1.0, 0, 0.0); //reflectionTexture0.level = 0.2; //material.reflectionTexture = reflectionTexture0; mirror.material = material; mirror.position = new BABYLON.Vector3(0, 0.0, 0); // Emitters var emitter0 = BABYLON.Mesh.CreateBox("emitter0", 0.1, scene); emitter0.isVisible = false; var emitter1 = BABYLON.Mesh.CreateBox("emitter1", 0.1, scene); emitter1.isVisible = false; //mirror.material.reflectionTexture.renderList.push(emitter0); //mirror.material.reflectionTexture.renderList.push(emitter1); // Particles var particleSystem = new BABYLON.ParticleSystem("particles", 4000, scene); particleSystem.particleTexture = new BABYLON.Texture("Flare.png", scene); particleSystem.minAngularSpeed = -0.5; particleSystem.maxAngularSpeed = 0.5; particleSystem.minSize = 0.1; particleSystem.maxSize = 0.5; particleSystem.minLifeTime = 0.5; particleSystem.maxLifeTime = 2.0; particleSystem.minEmitPower = 0.5; particleSystem.maxEmitPower = 4.0; particleSystem.emitter = emitter0; particleSystem.emitRate = 400; particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE; particleSystem.minEmitBox = new BABYLON.Vector3(-0.5, 0, -0.5); particleSystem.maxEmitBox = new BABYLON.Vector3(0.5, 0, 0.5); particleSystem.direction1 = new BABYLON.Vector3(-1, 1, -1); particleSystem.direction2 = new BABYLON.Vector3(1, 1, 1); particleSystem.color1 = new BABYLON.Color4(1, 0, 0, 1); particleSystem.color2 = new BABYLON.Color4(0, 1, 1, 1); particleSystem.gravity = new BABYLON.Vector3(0, -2.0, 0); particleSystem.start(); var particleSystem2 = new BABYLON.ParticleSystem("particles", 4000, scene); particleSystem2.particleTexture = new BABYLON.Texture("Flare.png", scene); particleSystem2.minSize = 0.1; particleSystem2.maxSize = 0.3; particleSystem2.minEmitPower = 1.0; particleSystem2.maxEmitPower = 2.0; particleSystem2.minLifeTime = 0.5; particleSystem2.maxLifeTime = 1.0; particleSystem2.emitter = emitter1; particleSystem2.emitRate = 500; particleSystem2.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE; particleSystem2.minEmitBox = new BABYLON.Vector3(0, 0, 0); particleSystem2.maxEmitBox = new BABYLON.Vector3(0, 0, 0); particleSystem2.gravity = new BABYLON.Vector3(0, -0.5, 0); particleSystem2.direction1 = new BABYLON.Vector3(0, 0, 0); particleSystem2.direction2 = new BABYLON.Vector3(0, 0, 0); particleSystem2.start(); var alpha = 0.0; scene.registerBeforeRender(() => { emitter1.position.x = 3.0 * Math.Cos(alpha); emitter1.position.y = 1.0; emitter1.position.z = 3.0 * Math.Sin(alpha); alpha += 0.05 * scene.getAnimationRatio(); }); this.scene.activeCamera.attachControl(this.canvas); }