├── LICENSE ├── README.md ├── examples ├── ColoredLights.html ├── CornellBox.html ├── CornellBox_Textured.html ├── Mailbox.html ├── Sponza.html └── img │ ├── crate.jpg │ ├── multicol.jpg │ └── red.jpg ├── js ├── DDSLoader.js ├── LightBaking.js ├── LightBakingDemo.js ├── LightBakingWorker.js ├── Lucy100k_slim.js ├── MTLLoader.js ├── OBJLoader.js ├── OBJMTLLoader.js ├── Octree.js ├── Sidebar.LightBaking.js ├── TrackballControls.js ├── dat.gui.min.js ├── jszip-utils.js ├── jszip.min.js ├── packer.growing.js ├── r71 │ ├── three.js │ └── three.min.js ├── r93 │ ├── three.js │ └── three.min.js ├── three.js └── three.min.js └── obj └── sponza_01 ├── 00_skap.JPG ├── 01_STUB-bump.jpg ├── 01_STUB.JPG ├── 01_S_ba.JPG ├── 01_S_kap-bump.jpg ├── 01_S_kap.JPG ├── 01_St_kp-bump.jpg ├── 01_St_kp.JPG ├── KAMEN-bump.jpg ├── KAMEN-stup.JPG ├── KAMEN.JPG ├── copyright.txt ├── prozor1.JPG ├── reljef-bump.jpg ├── reljef.JPG ├── sp_luk-bump.JPG ├── sp_luk.JPG ├── sponza.mtl ├── sponza.obj ├── vrata_ko.JPG ├── vrata_kr.JPG ├── x01_st-bump.jpg └── x01_st.JPG /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2015 Dominik Link, Jan Pascal Tschudy, FHNW. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LightBaking.js 2 | ======== 3 | 4 | #### Light Baking for three.js #### 5 | 6 | The aim of this project is to provide light baking functionality for [THREE.js WebGL library](http://mrdoob.github.com/three.js/). 7 | This project handles everything from UV mapping to baking the light for the whole scene with Path Tracing and filter the maps to get a smooth result even with lower resolution maps. 8 | 9 | edit: This is a fork by manthrax, attempting to get this running with current three.js 10 | 11 | ```html 12 | This build might not be stable for THREE.js 13 | ``` 14 | 15 | ## Features 16 | 17 | * Distortion free UV mapping 18 | * Optimizing UV layout with bin packing from [Code inComplete](http://codeincomplete.com/posts/2011/5/7/bin_packing/) 19 | * Light Baking 20 | * Path Tracing 21 | * Gauss/Box Filter 22 | * Import and Export 23 | * Integration in three.js 24 | * Integration in the [three.js editor](http://threejs.org/editor/) 25 | * Web Worker functionality 26 | 27 | ## Examples 28 | 29 | Live Examples: 30 | * [Cornell Box](https://cdn.rawgit.com/manthrax/lightbaking/master/examples/CornellBox.html) 31 | * [Cornell Box_Textured](https://cdn.rawgit.com/manthrax/lightbaking/master/examples/CornellBox_Textured.html) 32 | * [Colored Lights](https://cdn.rawgit.com/manthrax/lightbaking/master/examples/ColoredLights.html) 33 | * [Mailbox](https://cdn.rawgit.com/manthrax/lightbaking/master/examples/Mailbox.html) 34 | 35 | Pictures: 36 | * [Cornell Box](http://web.fhnw.ch/technik/projekte/i/bachelor15/tschudy-link/img/cornell_algorithm.png) 37 | * [Cornell Box Ball Lightmap](http://web.fhnw.ch/technik/projekte/i/bachelor15/tschudy-link/img/uvpacking.png) 38 | * [Cornell Box Textures](http://web.fhnw.ch/technik/projekte/i/bachelor15/tschudy-link/img/cornellbox_walltexture.png) 39 | * [Mailbox](http://web.fhnw.ch/technik/projekte/i/bachelor15/tschudy-link/img/mailbox.png) 40 | * [Editor integration](http://web.fhnw.ch/technik/projekte/i/bachelor15/tschudy-link/img/editor.png) 41 | * [Concave Object](http://web.fhnw.ch/technik/projekte/i/bachelor15/tschudy-link/img/concaveObj.png) 42 | 43 | 44 | ## Recommendations 45 | * Webserver eg node.js, phpstorm etc. 46 | * Chrome 44 (Mozilla and IE seems to have some issues while using our workers) 47 | 48 | ## Usage 49 | Download the following scripts: 50 | * Mandatory [script](https://github.com/manthrax/lightbaking/tree/master/js/LightBaking.js) 51 | * Optional only for using workers [script](https://github.com/manthrax/lightbaking/tree/master/js/LightBakingWorker.js) 52 | * Optional for import/export [script](https://github.com/Stuk/jszip/blob/master/dist/jszip.min.js) 53 | * Optional for import/export [script](https://github.com/Stuk/jszip-utils/tree/master/dist/jszip-utils.min.js) 54 | 55 | Include them in your html after the [THREE.js WebGL library](http://mrdoob.github.com/three.js/). 56 | 57 | ```html 58 | 59 | 60 | ``` 61 | 62 | #### Minimal Config (Singlethreaded) 63 | ```html 64 | lightBaking = THREE.LightBaking({ 65 | "scene"": scene, 66 | "appMode": THREE.LightBaking.ApplicationExecutionEnum.SINGLETHREADED 67 | )}; 68 | ``` 69 | 70 | #### Minimal Config (Multithreaded) 71 | ```html 72 | lightBaking = THREE.LightBaking({ 73 | "scene"": scene, 74 | "workerSource": "LightBakingWorker.js", //optional, only used if multithreading is enabled. Set the source of the LightBakingWorker.js file. 75 | )}; 76 | ``` 77 | 78 | #### Parameter description 79 | All Parameters are listed with their default values. 80 | 81 | ```html 82 | lightBaking = THREE.LightBaking( { 83 | 84 | // Scene Information 85 | // pass the scene object to the LightBaking plugin 86 | "scene"": scene 87 | 88 | // Application Execution Model 89 | // Runs the application in the desired mode. 90 | // - SINGLETHREADED: Everything is done in the main(ui)thread 91 | // - ASYNC: Executed asynchronously(not really different to SINGLETHREADED) 92 | // - MULTITHREADED: Using dedicated WebWorkers 93 | "appMode": THREE.LightBaking.ApplicationExecutionEnum.MULTITHREADED, 94 | 95 | // (dedicated) Web Worker 96 | // - workerSource: only used if multithreading is enabled. Set the source of the LightBakingWorker.js file. 97 | // - workerLimit: Maximal amount of worker 98 | "workerSource": "js/LightBakingWorker.js", 99 | "workerLimit": navigator.hardwareConcurrency, 100 | 101 | // Debugging 102 | // only used for developing purposes 103 | // - debugText: get some insight which method was called 104 | // - debugLightmap: same functionality as debugLightmaps() on THREE.LightBaking 105 | "debugText": false, 106 | "debugLightmap": false, 107 | "debugVisual": false, 108 | "debugVisualMeshNbr": 0, 109 | "debugVisualProbabilityFilter": 0.005, 110 | "debugVisualIsSelectedMesh": false 111 | "debugVisualRT": false, 112 | 113 | // Lightmap size 114 | // Usually 2^x 115 | "textureWidth": 512, 116 | "textureHeight": 512, 117 | 118 | // Shading Techniques 119 | // - PHONG 120 | // - FLAT 121 | // - FLATFAST (color determined by face vertices, and the whole face gets this color) 122 | "shading": THREE.LightBaking.ShadingEnum.PHONG, 123 | 124 | // Illumination Models 125 | // Only Lambertian. Phong doesn't make sense in terms of lightbaking. 126 | // - LAMBERT 127 | "illuminationModel": THREE.LightBaking.IlluminationModelEnum.LAMBERT, 128 | 129 | // UV related 130 | // - uvMethod: optional, 0 - first try, 1 - simple centered, 2 - bin packing approach 131 | // - packingOffset: optional, offset in pixels for the UV map 132 | // - uvSmoothing: optional, offset in percent for the inTriangle test used in baking 133 | "uvMethod": THREE.LightBaking.UVMethodEnum.PACKED, 134 | "packingOffset": 2, 135 | "uvSmoothing": 0.2, 136 | 137 | // Light Baking algorithms 138 | // used for baking TWOPASS/PATHTRACING 139 | "bakingMethod": THREE.LightBaking.BakingMethodEnum.PATHTRACING, 140 | 141 | // TwoPass Method 142 | // - twoPassCount: 1 - only direct light, 2 with indirect light 143 | // (more passes not possible) 144 | "twoPassPassCount": 2, 145 | 146 | // PathTracing Method (minimum settings(only direct light)) 147 | // - sampels: samples per lumel 148 | // - pathTracingRecLevel: max recursion depth 149 | "samples": 1, 150 | "pathTracingRecLevel": 0, 151 | 152 | // Ray direction 153 | // how to integrate over the hemisphere 154 | // direction for the rays [0-1], 155 | // 0: only in normal direction 156 | // 1: 180� direction(ideal diffuse) 157 | "importanceValue":1, 158 | 159 | // specificMeshBaking 160 | // Enable/disable specific baking 161 | // - ENABLED = default(bake all) 162 | // - DISABLED = bake all which have userDate.baking.bakeMe === true(bake only these) 163 | // - INVERTED = bakeMe===True ignores these to bake) 164 | "specificMeshBaking": THREE.LightBaking.SpecificMeshBakingEnum.DISABLED, 165 | 166 | // specificRayCasting 167 | //optional used for enable/disable ignoring objects, 168 | // - ENABLED = default(raycast all) 169 | // - DISABLED = bake all which have userDate.baking.intersectMe === true(use only these fot intersection tests) 170 | // - INVERTED = intersectMe===True ignores these to intersect) 171 | "specificRayCasting": THREE.LightBaking.SpecificRayCastingEnum.DISABLED, 172 | 173 | // Raycasting 174 | // - raycasterImplementation: choose between threejs raycaster implementation and octree(threejs preferred atm!) 175 | // - raycasterPrecision: set the raycaster precision. the lower the more precise 176 | "raycasterImplementation": THREE.LightBaking.RayCasterEnum.THREEJS, 177 | "raycasterPrecision": 0.0001, 178 | 179 | // softshadows 180 | // - softShadows: enable/disable soft shadows 181 | // - softShadowSamples: number of shadow samples fot the TWOPASS method. 182 | // - softShadowIntensity: used in direct light calculation, higher intensity results in brighter values 183 | "softShadows": true, 184 | "softShadowSamples": 1, 185 | "softShadowIntensity": 1, 186 | 187 | // giIntensity 188 | // increase it to boost the brightness of the indirect rays 189 | "giIntensity": 2, 190 | 191 | // lightAttenuation 192 | // - turn the light Attenuation for point lights on/off. Attenuation is derives from the standard point light attributes 193 | "lightAttenuation": false, 194 | 195 | // Lightmaps post processing: 196 | // applies an image processing filter onto the lightmap 197 | // postProcessingFilter: NONE/BOX/GAUSS, used to soften the lightmaps 198 | "postProcessingFilter": THREE.LightBaking.FilterEnum.NONE, 199 | 200 | } ); 201 | ``` 202 | 203 | #### Most common parameters: 204 | * to get a smooth/flat shading use: shading & ShadingEnum.Flat or ShadingEnum.PHONG 205 | * to get rid of seams use: packingOffset and/or uvSmoothing and set a higher texture width/height 206 | * to get indirect lighting use: samples > 0 rec level > 1 207 | * to get softshadows use: softshadows: true 208 | * to achieve a brighter lightmap: set giIntensity >= 2 209 | * to improve the pathtracing quality: the more samples the better the quality 210 | 211 | #### Import Scene 212 | ```html 213 | var lightBaking = THREE.LightBaking( { scene: scene } ); 214 | lightBaking.importLightMaps( "baked/Mailbox.zip" ); 215 | ``` 216 | #### Export Scene 217 | From developer Console: 218 | ```html 219 | lightBaking.exportLightMaps() 220 | ``` 221 | 222 | #### Editor 223 | To add our baking solution to the three.js editor you need to add the [Sidebar.LightBaking.js](https://github.com/manthrax/lightbaking/tree/master/js/Sidebar.LightBaking.js) into the editor/js folder. 224 | In addition, include the following files in the editors index.html: 225 | ```html 226 | 227 | 228 | ... 229 | 230 | ... 231 | ``` 232 | 233 | 234 | --- 235 | 236 | *Copyright (C) 2015 [Dominik Link](https://github.com/paradoxxl/), [Jan Pascal Tschudy](https://github.com/mem1b), [FHNW](http://www.fhnw.ch/)* 237 | *For full license and information, see [LICENSE](https://manthrax.github.com/lightbaking/LICENSE).* -------------------------------------------------------------------------------- /examples/ColoredLights.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |GUI
's constructor: localStorage
on exit. localStorage
will override those passed to dat.GUI
's constructor. This makes it easier to work incrementally, but localStorage
is fragile, and your friends may not see the same values you do.