private void OpenGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args) { BABYLON.Effect.ShadersStore["legacydefaultVertexShader"] = Defaults.LegacyVertexShader; BABYLON.Effect.ShadersStore["legacydefaultPixelShader"] = Defaults.LegacyPixelShader; //BABYLON.Effect.ShadersStore["legacydefaultVertexShader"] = Defaults.BasicVertexShader; //BABYLON.Effect.ShadersStore["legacydefaultPixelShader"] = Defaults.BasicPixelShader; BABYLON.Effect.ShadersStore["defaultVertexShader"] = Defaults.DefaultVertexShader; BABYLON.Effect.ShadersStore["defaultPixelShader"] = Defaults.DefaultPixelShader; BABYLON.Effect.ShadersStore["shadowMapVertexShader"] = Defaults.ShadowMapVertexShader; BABYLON.Effect.ShadersStore["shadowMapPixelShader"] = Defaults.ShadowMapPixelShader; BABYLON.Effect.ShadersStore["particlesVertexShader"] = Defaults.ParticlesVertexShader; BABYLON.Effect.ShadersStore["particlesPixelShader"] = Defaults.ParticlesPixelShader; BABYLON.Effect.ShadersStore["lensFlareVertexShader"] = Defaults.LensFlareVertexShader; BABYLON.Effect.ShadersStore["lensFlarePixelShader"] = Defaults.LensFlarePixelShader; BABYLON.Effect.ShadersStore["postprocessVertexShader"] = Defaults.PostProcessVertexShader; BABYLON.Effect.ShadersStore["passPixelShader"] = Defaults.PassPixelShader; BABYLON.Effect.ShadersStore["blurPixelShader"] = Defaults.BlurPixelShader; this.canvas = new CanvasAdapter((int)this.Width, (int)this.Height, (int)this.MaxWidth, (int)this.MaxHeight, args.OpenGL); this.engine = new Engine(canvas, true); this.scene = new BABYLON.Scene(this.engine); this.Scene20(); }
private void Scene11() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); var sun = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(60, 100, 10), scene); camera.setPosition(new BABYLON.Vector3(-20, 20, 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; // Ground var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "heightMap.png", 100, 100, 100, 0, 10, scene, false); var groundMaterial = new BABYLON.StandardMaterial("ground", scene); var texture1 = new BABYLON.Texture("ground.jpg", scene); texture1.uScale = 6; texture1.vScale = 6; groundMaterial.diffuseTexture = texture1; groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0); ground.position.y = -2.05; ground.material = groundMaterial; System.Action beforeRenderFunction = () => { // Camera if (camera.beta < 0.1) { camera.beta = 0.1; } else if (camera.beta > (Math.PI / 2) * 0.9) { camera.beta = (Math.PI / 2) * 0.9; } if (camera.radius > 50) { camera.radius = 50; } if (camera.radius < 5) { camera.radius = 5; } }; scene.registerBeforeRender(beforeRenderFunction); this.scene.activeCamera.attachControl(this.canvas); }
private void Scene4() { SceneLoader.Load( "", "skull.babylon", engine, loadedScene => { this.scene = loadedScene; // Attach the camera to the scene this.scene.activeCamera.attachControl(canvas); }); }
private void Scene10() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -20), scene); var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene); var sphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 3, scene); var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 3, scene); var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 3, scene); var material0 = new BABYLON.StandardMaterial("mat0", scene); material0.diffuseColor = new BABYLON.Color3(1, 0, 0); sphere0.material = material0; sphere0.position = new BABYLON.Vector3(-10, 0, 0); var material1 = new BABYLON.StandardMaterial("mat1", scene); material1.diffuseColor = new BABYLON.Color3(1, 1, 0); sphere1.material = material1; var material2 = new BABYLON.StandardMaterial("mat2", scene); material2.diffuseColor = new BABYLON.Color3(1, 0, 1); sphere2.material = material2; sphere2.position = new BABYLON.Vector3(10, 0, 0); sphere1.convertToFlatShadedMesh(); camera.setTarget(new BABYLON.Vector3(0, 0, 0)); // Fog scene.fogMode = BABYLON.Scene.FOGMODE_EXP; scene.fogDensity = 0.1; // Animations var alpha = 0.0; scene.registerBeforeRender(() => { sphere0.position.z = 4 * Math.Cos(alpha); sphere1.position.z = 4 * Math.Sin(alpha); sphere2.position.z = 4 * Math.Cos(alpha); alpha += 0.1; }); this.scene.activeCamera.attachControl(this.canvas); }
private void Scene5() { SceneLoader.Load( "", "Spaceship.babylon", engine, loadedScene => { this.scene = loadedScene; var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, this.scene.meshes[0], scene); this.scene.meshes[0].scaling = new Vector3(0.04, 0.04, 0.04); this.scene.activeCamera.detachControl(this.canvas); this.scene.activeCamera = camera; this.scene.activeCamera.attachControl(this.canvas); }); }
private void Scene20() { SceneLoader.Load( "", "SSAOcat.babylon", engine, loadedScene => { this.scene = loadedScene; // Attach the camera to the scene var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, this.scene.meshes[0], scene); this.scene.activeCamera.detachControl(this.canvas); this.scene.activeCamera = camera; this.scene.activeCamera.attachControl(this.canvas); }); }
private void Scene8() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene); var material0 = new BABYLON.StandardMaterial("mat0", scene); material0.diffuseColor = new BABYLON.Color3(1, 0, 0); material0.bumpTexture = new BABYLON.Texture("normalMap.jpg", scene); var material1 = new BABYLON.StandardMaterial("mat1", scene); material1.diffuseColor = new BABYLON.Color3(0, 0, 1); var material2 = new BABYLON.StandardMaterial("mat2", scene); material2.emissiveColor = new BABYLON.Color3(0.4, 0, 0.4); var multimat = new BABYLON.MultiMaterial("multi", scene); multimat.subMaterials.Add(material0); multimat.subMaterials.Add(material1); multimat.subMaterials.Add(material2); var sphere = BABYLON.Mesh.CreateSphere("Sphere0", 16, 3, scene); sphere.material = multimat; sphere.subMeshes = new Array <SubMesh>(); ; var verticesCount = sphere.getTotalVertices(); sphere.subMeshes.Add(new BABYLON.SubMesh(0, 0, verticesCount, 0, 900, sphere)); sphere.subMeshes.Add(new BABYLON.SubMesh(1, 0, verticesCount, 900, 900, sphere)); sphere.subMeshes.Add(new BABYLON.SubMesh(2, 0, verticesCount, 1800, 2088, sphere)); camera.setPosition(new BABYLON.Vector3(-3, 3, 0)); // Animations scene.registerBeforeRender( () => { sphere.rotation.y += 0.01; }); this.scene.activeCamera.attachControl(this.canvas); }
private void Scene6() { SceneLoader.Load( "", "Viper.babylon", engine, loadedScene => { this.scene = loadedScene; var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, this.scene.meshes[0], scene); // Attach the camera to the scene this.scene.meshes[0].scaling = new Vector3(4.0, 4.0, 4.0); this.scene.activeCamera.detachControl(this.canvas); this.scene.activeCamera = camera; this.scene.activeCamera.attachControl(this.canvas); }); }
private void Scene7() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene); var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene); var material = new BABYLON.StandardMaterial("kosh", scene); material.bumpTexture = new BABYLON.Texture("normalMap.jpg", scene); material.diffuseColor = new BABYLON.Color3(1, 0, 0); sphere.material = material; camera.setPosition(new BABYLON.Vector3(-5, 5, 0)); // Animations scene.registerBeforeRender(() => { sphere.rotation.y += 0.02; }); this.scene.activeCamera.attachControl(this.canvas); }
private void Scene12() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -1, -0.2), scene); var light2 = new BABYLON.DirectionalLight("dir02", new BABYLON.Vector3(-1, -2, -1), scene); light.position = new BABYLON.Vector3(0, 30, 0); light2.position = new BABYLON.Vector3(10, 20, 10); light.intensity = 0.6; light2.intensity = 0.6; camera.setPosition(new BABYLON.Vector3(-20, 20, 0)); // Skybox var skybox = BABYLON.Mesh.CreateBox("skyBox", 1000.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; // Ground var ground = BABYLON.Mesh.CreateGround("ground", 1000, 1000, 1, scene, false); var groundMaterial = new BABYLON.StandardMaterial("ground", scene); BABYLON.Texture diffuseTexture = null; if (engine.getCaps().s3tc != null) { diffuseTexture = new BABYLON.Texture("grass.dds", scene); } else { diffuseTexture = new BABYLON.Texture("grass.jpg", scene); } diffuseTexture.uScale = 60; diffuseTexture.vScale = 60; groundMaterial.diffuseTexture = diffuseTexture; groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0); ground.position.y = -2.05; ground.material = groundMaterial; // Torus var torus = BABYLON.Mesh.CreateTorus("torus", 8, 2, 32, scene, false); torus.position.y = 6.0; var torus2 = BABYLON.Mesh.CreateTorus("torus2", 4, 1, 32, scene, false); torus2.position.y = 6.0; var torusMaterial = new BABYLON.StandardMaterial("torus", scene); torusMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5); torusMaterial.specularColor = new BABYLON.Color3(0.5, 0.5, 0.5); torus.material = torusMaterial; torus2.material = torusMaterial; // Shadows var shadowGenerator = new BABYLON.ShadowGenerator(new BABYLON.Size() { width = 512, height = 512 }, light); shadowGenerator.getShadowMap().renderList.Add(torus); shadowGenerator.getShadowMap().renderList.Add(torus2); shadowGenerator.usePoissonSampling = true; var shadowGenerator2 = new BABYLON.ShadowGenerator(new BABYLON.Size() { width = 512, height = 512 }, light2); shadowGenerator2.getShadowMap().renderList.Add(torus); shadowGenerator2.getShadowMap().renderList.Add(torus2); shadowGenerator2.useVarianceShadowMap = true; ground.receiveShadows = true; System.Action beforeRenderFunction = () => { // Camera if (camera.beta < 0.1) { camera.beta = 0.1; } else if (camera.beta > (Math.PI / 2) * 0.99) { camera.beta = (Math.PI / 2) * 0.99; } if (camera.radius > 150) { camera.radius = 150; } if (camera.radius < 5) { camera.radius = 5; } }; scene.registerBeforeRender(beforeRenderFunction); // Animations scene.registerBeforeRender(() => { torus.rotation.x += 0.01; torus.rotation.z += 0.02; torus2.rotation.x += 0.02; torus2.rotation.y += 0.01; }); this.scene.activeCamera.attachControl(this.canvas); }
private void Scene9() { this.scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 10, 0), scene); var light1 = new BABYLON.PointLight("Omni1", new BABYLON.Vector3(0, -10, 0), scene); var light2 = new BABYLON.PointLight("Omni2", new BABYLON.Vector3(10, 0, 0), scene); var light3 = new BABYLON.DirectionalLight("Dir0", new BABYLON.Vector3(1, -1, 0), scene); var material = new BABYLON.StandardMaterial("kosh", scene); var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene); camera.setPosition(new BABYLON.Vector3(-10, 10, 0)); light3.parent = camera; // Creating light sphere var lightSphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 0.5, scene); var lightSphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 0.5, scene); var lightSphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 0.5, scene); var material1 = new BABYLON.StandardMaterial("red", scene); material1.diffuseColor = new BABYLON.Color3(0, 0, 0); material1.specularColor = new BABYLON.Color3(0, 0, 0); material1.emissiveColor = new BABYLON.Color3(1, 0, 0); lightSphere0.material = material1; var material2 = new BABYLON.StandardMaterial("green", scene); material2.diffuseColor = new BABYLON.Color3(0, 0, 0); material2.specularColor = new BABYLON.Color3(0, 0, 0); material2.emissiveColor = new BABYLON.Color3(0, 1, 0); lightSphere1.material = material2; var material3 = new BABYLON.StandardMaterial("blue", scene); material3.diffuseColor = new BABYLON.Color3(0, 0, 0); material3.specularColor = new BABYLON.Color3(0, 0, 0); material3.emissiveColor = new BABYLON.Color3(0, 0, 1); lightSphere2.material = material3; // Sphere material material.diffuseColor = new BABYLON.Color3(1, 1, 1); sphere.material = material; // Lights colors light0.diffuse = new BABYLON.Color3(1, 0, 0); light0.specular = new BABYLON.Color3(1, 0, 0); light1.diffuse = new BABYLON.Color3(0, 1, 0); light1.specular = new BABYLON.Color3(0, 1, 0); light2.diffuse = new BABYLON.Color3(0, 0, 1); light2.specular = new BABYLON.Color3(0, 0, 1); light3.diffuse = new BABYLON.Color3(1, 1, 1); light3.specular = new BABYLON.Color3(1, 1, 1); // 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; skybox.infiniteDistance = true; // Animations var alpha = 0.0; scene.registerBeforeRender(() => { light0.position = new BABYLON.Vector3(10 * Math.Sin(alpha), 0, 10 * Math.Cos(alpha)); light1.position = new BABYLON.Vector3(10 * Math.Sin(alpha), 0, -10 * Math.Cos(alpha)); light2.position = new BABYLON.Vector3(10 * Math.Cos(alpha), 0, 10 * Math.Sin(alpha)); lightSphere0.position = light0.position; lightSphere1.position = light1.position; lightSphere2.position = light2.position; alpha += 0.01; }); this.scene.activeCamera.attachControl(this.canvas); }