123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Shaders Library</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
- <script src="../Tools/DevLoader/BabylonLoader.js"></script>
- <style>
- html, body {
- width: 100%;
- height: 100%;
- padding: 0;
- margin: 0;
- overflow: hidden;
- }
- #renderCanvas {
- width: 100%;
- height: 100%;
- }
- #fps {
- position: absolute;
- background-color: black;
- border: 2px solid red;
- text-align: center;
- font-size: 16px;
- color: white;
- top: 15px;
- left: 10px;
- width: 60px;
- height: 20px;
- }
- </style>
- </head>
- <body>
- <div id="fps">0</div>
- <canvas id="renderCanvas"></canvas>
- <script src="test/index.js"></script>
- <script src="test/addlava.js"></script>
- <script src="test/addnormal.js"></script>
- <script src="test/addwater.js"></script>
- <script src="test/addfur.js"></script>
- <script src="test/addterrain.js"></script>
- <script src="test/addfire.js"></script>
- <script src="test/addtriplanar.js"></script>
- <script src="test/addgradient.js"></script>
- <script src="test/addsky.js"></script>
- <script src="test/addgrid.js"></script>
- <script src="test/addpbr.js"></script>
- <script src="test/addpbrmetallicroughness.js"></script>
- <script src="test/addpbrspecularglossiness.js"></script>
- <script src="test/addCell.js"></script>
- <script src="test/addbackground.js"></script>
- <script src="test/addMix.js"></script>
-
- <script>
- var backgroundSkybox = null;
- BABYLONDEVTOOLS.Loader.load(function() {
- if (BABYLON.Engine.isSupported()) {
- var canvas = document.getElementById("renderCanvas");
- var engine = new BABYLON.Engine(canvas, true);
- BABYLONDEVTOOLS.Loader.debugShortcut(engine);
- var divFps = document.getElementById("fps");
- scene = new BABYLON.Scene(engine);
- var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 6, 50, BABYLON.Vector3.Zero(), scene);
- camera.attachControl(canvas, true);
- camera.minZ = 0.1;
- // Lights
- var hemisphericLight = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);
- var pointLight = new BABYLON.PointLight("point", new BABYLON.Vector3(20, 20, 10), scene);
- pointLight.setEnabled(false);
- var directionalLight = new BABYLON.DirectionalLight("directional", new BABYLON.Vector3(0,-1, 0), scene);
- directionalLight.setEnabled(false);
- directionalLight.position = new BABYLON.Vector3(0, 50, 0);
- var spotLight = new BABYLON.SpotLight("spot", new BABYLON.Vector3(0, -30, 0), new BABYLON.Vector3(0, 1, 0), 1.1, 1, scene);
- spotLight.setEnabled(false);
- // Create meshes
- var sphere = BABYLON.Mesh.CreateSphere("sphere", 48, 30.0, scene);
-
- var plane = BABYLON.MeshBuilder.CreateBox("plane", { width: 30, height: 1, depth:30 }, scene);
- plane.setEnabled(false);
-
- var ground = BABYLON.Mesh.CreateGround("ground", 512, 512, 32, scene, false);
- ground.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1);
- ground.setEnabled(false);
-
- var knot = BABYLON.Mesh.CreateTorusKnot("knot", 10, 3, 128, 64, 2, 3, scene);
- knot.setEnabled(false);
-
- var heightMap = BABYLON.Mesh.CreateGroundFromHeightMap("heightMap", "/Playground/textures/heightMap.png", 100, 100, 100, 0, 10, scene, false);
- heightMap.setEnabled(false);
-
- // 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("/Playground/textures/TropicalSunnyDay", scene);
- skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
- skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
- skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
- skyboxMaterial.disableLighting = true;
- skybox.material = skyboxMaterial;
- skybox.setEnabled(false);
- var currentMesh = sphere;
- // Rabbit
- var rabbit;
- BABYLON.SceneLoader.ImportMesh("Rabbit", "/Playground/scenes/", "Rabbit.babylon", scene, function (newMeshes, particleSystems, skeletons) {
- rabbit = newMeshes[1];
- rabbit.setEnabled(false);
- rabbit.scaling = new BABYLON.Vector3(0.3, 0.3, 0.3);
- scene.beginAnimation(skeletons[0], 0, 100, true, 0.8);
- // Shadow caster
- var shadowCaster = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
- shadowCaster.setEnabled(false);
- shadowCaster.position = new BABYLON.Vector3(0, 30, 0);
-
- var shadowCaster2 = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
- shadowCaster2.setEnabled(false);
- shadowCaster2.position = new BABYLON.Vector3(0, -30, 0);
-
- var shadowCaster3 = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
- shadowCaster3.setEnabled(false);
- shadowCaster3.position = new BABYLON.Vector3(20, 20, 10);
- var shadowGenerator = new BABYLON.ShadowGenerator(1024, directionalLight);
- shadowGenerator.getShadowMap().renderList.push(shadowCaster);
- shadowGenerator.usePoissonSampling = true;
- shadowGenerator.bias = 0;
-
- var shadowGenerator2 = new BABYLON.ShadowGenerator(1024, spotLight);
- shadowGenerator2.getShadowMap().renderList.push(shadowCaster2);
- shadowGenerator2.usePoissonSampling = true;
-
- var shadowGenerator3 = new BABYLON.ShadowGenerator(1024, pointLight);
- shadowGenerator3.getShadowMap().renderList.push(shadowCaster3);
- shadowGenerator3.usePoissonSampling = false;
- shadowGenerator3.bias = 0;
- // Register a render loop to repeatedly render the scene
- engine.runRenderLoop(function () {
- scene.render();
- divFps.innerHTML = engine.getFps().toFixed() + " fps";
- shadowCaster.rotation.x += 0.01;
- shadowCaster.rotation.y += 0.01;
- shadowCaster2.rotation.x += 0.01;
- shadowCaster2.rotation.y += 0.01;
- shadowCaster3.rotation.x += 0.01;
- shadowCaster3.rotation.y += 0.01;
- });
- // Resize
- window.addEventListener("resize", function () {
- engine.resize();
- });
- // Fog
- scene.fogMode = BABYLON.Scene.FOGMODE_NONE;
- scene.fogDensity = 0.01;
-
- // Create shaders
- var std = new BABYLON.StandardMaterial("std", scene);
- std.diffuseTexture = new BABYLON.Texture("/Playground/textures/amiga.jpg", scene);
- std.diffuseTexture.uScale = 5;
- std.diffuseTexture.vScale = 5;
- var lava = prepareLava();
- var simple = new BABYLON.SimpleMaterial("simple", scene);
- simple.diffuseTexture = new BABYLON.Texture("/Playground/textures/amiga.jpg", scene);
- simple.diffuseTexture.uScale = 5;
- simple.diffuseTexture.vScale = 5;
- var normal = prepareNormal();
- var gradient = prepareGradient();
-
- var fur = prepareFur();
-
- var water = prepareWater();
- water.addToRenderList(skybox);
- water.addToRenderList(shadowCaster);
- water.addToRenderList(shadowCaster2);
- water.addToRenderList(shadowCaster3);
-
- var fire = prepareFire();
-
- var terrain = prepareTerrain();
- var pbr = preparePBR();
- var back = prepareBackgroundMaterial();
- var pbrmetallicroughness = preparePBRMetallicRoughness();
- var pbrspecularglossiness = preparePBRSpecularGlossiness();
-
- var triPlanar = prepareTriPlanar();
-
- var sky = prepareSky();
- var grid = prepareGrid();
- var shadowOnly = new BABYLON.ShadowOnlyMaterial();
- var cell = prepareCell();
- var mix = prepareMix();
-
- // Default to std
- var currentMaterial = std;
- sphere.material = std;
- sphere.receiveShadows = true;
- gui.add(options, 'material', ['standard', 'simple', 'water', 'fire', 'lava', 'normal', 'terrain', 'pbr', 'pbrmetallicroughness', 'pbrspecularglossiness', 'fur', 'triPlanar', 'gradient', 'sky', 'grid', 'shadowOnly', 'cell', 'background', 'mix']).onFinishChange(function () {
- water.enableRenderTargets(false);
- skybox.material = skyboxMaterial;
- currentMesh.isVisible = true;
- fur.resetFur();
- if (backgroundSkybox) {
- backgroundSkybox.setEnabled(false);
- }
-
- switch (options.material) {
- case "shadowOnly":
- currentMaterial = shadowOnly;
- break;
- case "simple":
- currentMaterial = simple;
- break;
- case "water":
- currentMaterial = water;
- water.enableRenderTargets(true);
- skybox.setEnabled(true);
- break;
- case "fire":
- currentMaterial = fire;
- break;
- case "lava":
- currentMaterial = lava;
- break;
- case "normal":
- currentMaterial = normal;
- break;
- case "terrain":
- currentMaterial = terrain;
- break;
- case "pbr":
- currentMaterial = pbr;
- break;
- case "pbrmetallicroughness":
- currentMaterial = pbrmetallicroughness;
- break;
- case "pbrspecularglossiness":
- currentMaterial = pbrspecularglossiness;
- break;
- case "fur":
- currentMaterial = fur.material;
- fur.configureFur(currentMesh);
- break;
- case "triPlanar":
- currentMaterial = triPlanar;
- break;
- case "gradient":
- currentMaterial = gradient;
- break;
- case "sky":
- skybox.setEnabled(true);
- skybox.material = sky;
- break;
- case "grid":
- currentMaterial = grid;
- break;
- case "cell":
- currentMaterial = cell;
- break;
- case "background":
- currentMaterial = back;
- backgroundSkybox.setEnabled(true);
- break;
- case "mix":
- currentMaterial = mix;
- break;
- default:
- currentMaterial = std;
- break;
- }
- currentMesh.material = currentMaterial;
-
- window.enableMaterial(options.material);
- });
- gui.add(options, 'mesh', ['sphere', 'knot', 'plane', 'ground', 'heightMap', 'rabbit']).onFinishChange(function () {
- currentMesh.setEnabled(false);
- switch (options.mesh) {
- case "sphere":
- currentMesh = sphere;
- break;
- case "knot":
- currentMesh = knot;
- break;
- case "plane":
- currentMesh = plane;
- break;
- case "ground":
- currentMesh = ground;
- break;
- case "heightMap":
- currentMesh = heightMap;
- break;
- case "rabbit":
- currentMesh = rabbit;
- break;
- }
- currentMesh.setEnabled(true);
- currentMesh.receiveShadows = true;
- currentMesh.material = currentMaterial;
-
- water.mesh = currentMesh;
-
- if (currentMaterial === fur.material) {
- // Furify the mesh
- fur.resetFur();
- fur.configureFur(currentMesh);
- }
- });
- var f1 = gui.addFolder('lights');
- f1.add(options, 'lightIntensity').onChange(function() {
- hemisphericLight.intensity = options.lightIntensity;
- directionalLight.intensity = options.lightIntensity;
- pointLight.intensity = options.lightIntensity;
- spotLight.intensity = options.lightIntensity;
- });
- f1.add(options, 'lightIntensityMode', ['automatic', 'luminousPower', 'luminousIntensity', 'illuminance', 'luminance']).onFinishChange(function() {
- switch (options.lightIntensityMode) {
- case "automatic":
- hemisphericLight.intensityMode = BABYLON.Light.INTENSITYMODE_AUTOMATIC;
- directionalLight.intensityMode = BABYLON.Light.INTENSITYMODE_AUTOMATIC;
- pointLight.intensityMode = BABYLON.Light.INTENSITYMODE_AUTOMATIC;
- spotLight.intensityMode = BABYLON.Light.INTENSITYMODE_AUTOMATIC;
- break;
- case "luminousPower":
- hemisphericLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSPOWER;
- directionalLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSPOWER;
- pointLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSPOWER;
- spotLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSPOWER;
- break;
- case "luminousIntensity":
- hemisphericLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSINTENSITY;
- directionalLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSINTENSITY;
- pointLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSINTENSITY;
- spotLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINOUSINTENSITY;
- break;
- case "illuminance":
- hemisphericLight.intensityMode = BABYLON.Light.INTENSITYMODE_ILLUMINANCE;
- directionalLight.intensityMode = BABYLON.Light.INTENSITYMODE_ILLUMINANCE;
- pointLight.intensityMode = BABYLON.Light.INTENSITYMODE_ILLUMINANCE;
- spotLight.intensityMode = BABYLON.Light.INTENSITYMODE_ILLUMINANCE;
- break;
- case "luminance":
- hemisphericLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINANCE;
- directionalLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINANCE;
- pointLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINANCE;
- spotLight.intensityMode = BABYLON.Light.INTENSITYMODE_LUMINANCE;
- break;
- }
- });
-
- f1.add(options, 'lightRange').onChange(function() {
- hemisphericLight.range = options.lightRange;
- directionalLight.range = options.lightRange;
- pointLight.range = options.lightRange;
- spotLight.range = options.lightRange;
- });
-
- f1.add(options, 'lightRadius').onChange(function() {
- hemisphericLight.radius = options.lightRadius;
- directionalLight.radius = options.lightRadius;
- pointLight.radius = options.lightRadius;
- spotLight.radius = options.lightRadius;
- });
-
- f1.add(options, 'hemisphericLight').onChange(function () {
- hemisphericLight.setEnabled(options.hemisphericLight);
- });
- f1.add(options, 'pointLight').onChange(function () {
- pointLight.setEnabled(options.pointLight);
- shadowCaster3.setEnabled(options.pointLight && options.castShadows);
- });
-
- f1.add(options, 'spotLight').onChange(function () {
- spotLight.setEnabled(options.spotLight);
- shadowCaster2.setEnabled(options.spotLight && options.castShadows);
- });
- f1.add(options, 'directionalLight').onChange(function () {
- directionalLight.setEnabled(options.directionalLight);
- shadowCaster.setEnabled(options.directionalLight && options.castShadows);
- });
- f1.add(options, 'castShadows').onChange(function () {
- shadowCaster.setEnabled(options.directionalLight && options.castShadows);
- shadowCaster2.setEnabled(options.spotLight && options.castShadows);
- shadowCaster3.setEnabled(options.pointLight && options.castShadows);
- });
- gui.add(options, 'fog').onChange(function () {
- scene.fogMode = options.fog ? BABYLON.Scene.FOGMODE_EXP : BABYLON.Scene.FOGMODE_NONE;
- });
-
- gui.add(options, 'skybox').onChange(function() {
- skybox.setEnabled(options.skybox);
- });
- });
- }
- });
- </script>
- </body>
- </html>
|