webgl_marching_cubes.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - marching cubes</title>
  5. <meta charset="utf-8">
  6. <style>
  7. body {
  8. color: #fff;
  9. font-family: Monospace;
  10. font-size: 13px;
  11. text-align: center;
  12. background-color: #000;
  13. margin: 0px;
  14. overflow: hidden;
  15. }
  16. #info {
  17. color: #ffffff;
  18. position: absolute;
  19. top: 0px;
  20. width: 100%;
  21. padding: 5px;
  22. }
  23. a {
  24. color: gold;
  25. }
  26. #oldie {
  27. font-family: monospace;
  28. font-size: 13px;
  29. text-align: center;
  30. background: rgb(0, 0, 50);
  31. color: #fff;
  32. padding: 1em;
  33. width: 475px;
  34. margin: 5em auto 0;
  35. display: none;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <div id="container"></div>
  41. <div id="info">
  42. <a href="http://threejs.org" target="_blank">three.js</a> -
  43. marching cubes -
  44. [based on greggman's <a href="http://webglsamples.googlecode.com/hg/blob/blob.html">blob</a>, original code by Henrik Rydgård]
  45. </div>
  46. <script src="../build/three.min.js"></script>
  47. <script src="js/controls/TrackballControls.js"></script>
  48. <script src="js/shaders/CopyShader.js"></script>
  49. <script src="js/shaders/FXAAShader.js"></script>
  50. <script src="js/shaders/HorizontalTiltShiftShader.js"></script>
  51. <script src="js/shaders/VerticalTiltShiftShader.js"></script>
  52. <script src="js/postprocessing/EffectComposer.js"></script>
  53. <script src="js/postprocessing/RenderPass.js"></script>
  54. <script src="js/postprocessing/BloomPass.js"></script>
  55. <script src="js/postprocessing/ShaderPass.js"></script>
  56. <script src="js/postprocessing/MaskPass.js"></script>
  57. <script src="js/postprocessing/SavePass.js"></script>
  58. <script src="js/MarchingCubes.js"></script>
  59. <script src="js/ShaderToon.js"></script>
  60. <script src="js/Detector.js"></script>
  61. <script src="js/libs/stats.min.js"></script>
  62. <script src="js/libs/DAT.GUI.min.js"></script>
  63. <script>
  64. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  65. var MARGIN = 0;
  66. var SCREEN_WIDTH = window.innerWidth;
  67. var SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
  68. var container, stats;
  69. var camera, scene, renderer;
  70. var mesh, texture, geometry, materials, material, current_material;
  71. var light, pointLight, ambientLight;
  72. var effect, resolution, numBlobs;
  73. var composer, effectFXAA, hblur, vblur;
  74. var effectController;
  75. var time = 0;
  76. var clock = new THREE.Clock();
  77. init();
  78. animate();
  79. function init() {
  80. container = document.getElementById( 'container' );
  81. // CAMERA
  82. camera = new THREE.PerspectiveCamera( 45, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
  83. camera.position.set( -500, 500, 1500 );
  84. // CONTROLS
  85. controls = new THREE.TrackballControls( camera );
  86. // SCENE
  87. scene = new THREE.Scene();
  88. // LIGHTS
  89. light = new THREE.DirectionalLight( 0xffffff );
  90. light.position.set( 0.5, 0.5, 1 );
  91. scene.add( light );
  92. pointLight = new THREE.PointLight( 0xff3300 );
  93. pointLight.position.set( 0, 0, 100 );
  94. scene.add( pointLight );
  95. ambientLight = new THREE.AmbientLight( 0x080808 );
  96. scene.add( ambientLight );
  97. // MATERIALS
  98. materials = generateMaterials();
  99. current_material = "shiny";
  100. // MARCHING CUBES
  101. resolution = 28;
  102. numBlobs = 10;
  103. effect = new THREE.MarchingCubes( resolution, materials[ current_material ].m, true, true );
  104. effect.position.set( 0, 0, 0 );
  105. effect.scale.set( 700, 700, 700 );
  106. effect.enableUvs = false;
  107. effect.enableColors = false;
  108. scene.add( effect );
  109. // RENDERER
  110. renderer = new THREE.WebGLRenderer( { clearColor: 0x050505, clearAlpha: 1, alpha: false } );
  111. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  112. renderer.domElement.style.position = "absolute";
  113. renderer.domElement.style.top = MARGIN + "px";
  114. renderer.domElement.style.left = "0px";
  115. container.appendChild( renderer.domElement );
  116. //
  117. renderer.gammaInput = true;
  118. renderer.gammaOutput = true;
  119. renderer.physicallyBasedShading = true;
  120. // STATS
  121. stats = new Stats();
  122. stats.domElement.style.position = 'absolute';
  123. stats.domElement.style.top = '0px';
  124. container.appendChild( stats.domElement );
  125. stats.domElement.children[ 0 ].children[ 0 ].style.color = "#888";
  126. stats.domElement.children[ 0 ].style.background = "transparent";
  127. stats.domElement.children[ 0 ].children[ 1 ].style.display = "none";
  128. // COMPOSER
  129. renderer.autoClear = false;
  130. renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
  131. renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
  132. effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
  133. hblur = new THREE.ShaderPass( THREE.HorizontalTiltShiftShader );
  134. vblur = new THREE.ShaderPass( THREE.VerticalTiltShiftShader );
  135. var bluriness = 8;
  136. hblur.uniforms[ 'h' ].value = bluriness / SCREEN_WIDTH;
  137. vblur.uniforms[ 'v' ].value = bluriness / SCREEN_HEIGHT;
  138. hblur.uniforms[ 'r' ].value = vblur.uniforms[ 'r' ].value = 0.5;
  139. effectFXAA.uniforms[ 'resolution' ].value.set( 1 / SCREEN_WIDTH, 1 / SCREEN_HEIGHT );
  140. composer = new THREE.EffectComposer( renderer, renderTarget );
  141. var renderModel = new THREE.RenderPass( scene, camera );
  142. vblur.renderToScreen = true;
  143. //effectFXAA.renderToScreen = true;
  144. composer = new THREE.EffectComposer( renderer, renderTarget );
  145. composer.addPass( renderModel );
  146. composer.addPass( effectFXAA );
  147. composer.addPass( hblur );
  148. composer.addPass( vblur );
  149. // GUI
  150. setupGui();
  151. // EVENTS
  152. window.addEventListener( 'resize', onWindowResize, false );
  153. }
  154. //
  155. function onWindowResize( event ) {
  156. SCREEN_WIDTH = window.innerWidth;
  157. SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
  158. renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  159. camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  160. camera.updateProjectionMatrix();
  161. renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
  162. composer.reset( renderTarget );
  163. hblur.uniforms[ 'h' ].value = 4 / SCREEN_WIDTH;
  164. vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;
  165. effectFXAA.uniforms[ 'resolution' ].value.set( 1 / SCREEN_WIDTH, 1 / SCREEN_HEIGHT );
  166. }
  167. function generateMaterials() {
  168. // environment map
  169. var path = "textures/cube/SwedishRoyalCastle/";
  170. var format = '.jpg';
  171. var urls = [
  172. path + 'px' + format, path + 'nx' + format,
  173. path + 'py' + format, path + 'ny' + format,
  174. path + 'pz' + format, path + 'nz' + format
  175. ];
  176. var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
  177. reflectionCube.format = THREE.RGBFormat;
  178. var refractionCube = new THREE.Texture( reflectionCube.image, new THREE.CubeRefractionMapping() );
  179. reflectionCube.format = THREE.RGBFormat;
  180. // toons
  181. var toonMaterial1 = createShaderMaterial( "toon1", light, ambientLight ),
  182. toonMaterial2 = createShaderMaterial( "toon2", light, ambientLight ),
  183. hatchingMaterial = createShaderMaterial( "hatching", light, ambientLight ),
  184. hatchingMaterial2 = createShaderMaterial( "hatching", light, ambientLight ),
  185. dottedMaterial = createShaderMaterial( "dotted", light, ambientLight ),
  186. dottedMaterial2 = createShaderMaterial( "dotted", light, ambientLight );
  187. hatchingMaterial2.uniforms.uBaseColor.value.setRGB( 0, 0, 0 );
  188. hatchingMaterial2.uniforms.uLineColor1.value.setHSV( 0, 0.9, 0.9 );
  189. hatchingMaterial2.uniforms.uLineColor2.value.setHSV( 0, 0.9, 0.9 );
  190. hatchingMaterial2.uniforms.uLineColor3.value.setHSV( 0, 0.9, 0.9 );
  191. hatchingMaterial2.uniforms.uLineColor4.value.setHSV( 0.1, 0.9, 0.9 );
  192. dottedMaterial2.uniforms.uBaseColor.value.setRGB( 0, 0, 0 );
  193. dottedMaterial2.uniforms.uLineColor1.value.setHSV( 0.05, 1.0, 1.0 );
  194. var texture = THREE.ImageUtils.loadTexture( "textures/ash_uvgrid01.jpg" );
  195. texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
  196. var materials = {
  197. "chrome" :
  198. {
  199. m: new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: reflectionCube } ),
  200. h: 0, s: 0, v: 1
  201. },
  202. "liquid" :
  203. {
  204. m: new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: refractionCube, refractionRatio: 0.85 } ),
  205. h: 0, s: 0, v: 1
  206. },
  207. "shiny" :
  208. {
  209. m: new THREE.MeshPhongMaterial( { color: 0x550000, specular: 0x440000, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.3, perPixel: true, metal: true } ),
  210. h: 0, s: 0.9, v: 0.3
  211. },
  212. "matte" :
  213. {
  214. m: new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x111111, shininess: 1, perPixel: true } ),
  215. h: 0, s: 0, v: 1
  216. },
  217. "flat" :
  218. {
  219. m: new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x111111, shininess: 1, shading: THREE.FlatShading, perPixel: true } ),
  220. h: 0, s: 0, v: 1
  221. },
  222. "textured" :
  223. {
  224. m: new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess: 1, map: texture, perPixel: true } ),
  225. h: 0, s: 0, v: 1
  226. },
  227. "colors" :
  228. {
  229. m: new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 2, vertexColors: THREE.VertexColors, perPixel: true } ),
  230. h: 0, s: 0, v: 1
  231. },
  232. "plastic" :
  233. {
  234. m: new THREE.MeshPhongMaterial( { color: 0x000000, specular: 0x888888, ambient: 0x000000, shininess: 250, perPixel: true } ),
  235. h: 0.6, s: 0.9, v: 0.2
  236. },
  237. "toon1" :
  238. {
  239. m: toonMaterial1,
  240. h: 0.2, s: 0.5, v: 1
  241. },
  242. "toon2" :
  243. {
  244. m: toonMaterial2,
  245. h: 0.4, s: 0.5, v: 1
  246. },
  247. "hatching" :
  248. {
  249. m: hatchingMaterial,
  250. h: 0.2, s: 0.2, v: 1
  251. },
  252. "hatching2" :
  253. {
  254. m: hatchingMaterial2,
  255. h: 0.0, s: 0.9, v: 0.9
  256. },
  257. "dotted" :
  258. {
  259. m: dottedMaterial,
  260. h: 0.2, s: 0.2, v: 1
  261. },
  262. "dotted2" :
  263. {
  264. m: dottedMaterial2,
  265. h: 0.1, s: 1.0, v: 1
  266. }
  267. };
  268. return materials;
  269. }
  270. function createShaderMaterial( id, light, ambientLight ) {
  271. var shader = THREE.ShaderToon[ id ];
  272. var u = THREE.UniformsUtils.clone( shader.uniforms );
  273. var vs = shader.vertexShader;
  274. var fs = shader.fragmentShader;
  275. var material = new THREE.ShaderMaterial( { uniforms: u, vertexShader: vs, fragmentShader: fs } );
  276. material.uniforms.uDirLightPos.value = light.position;
  277. material.uniforms.uDirLightColor.value = light.color;
  278. material.uniforms.uAmbientLightColor.value = ambientLight.color;
  279. return material;
  280. }
  281. //
  282. function setupGui() {
  283. var createHandler = function( id ) {
  284. return function() {
  285. var mat_old = materials[ current_material ];
  286. mat_old.h = m_h.getValue();
  287. mat_old.s = m_s.getValue();
  288. mat_old.v = m_v.getValue();
  289. current_material = id;
  290. var mat = materials[ id ];
  291. effect.material = mat.m;
  292. m_h.setValue( mat.h );
  293. m_s.setValue( mat.s );
  294. m_v.setValue( mat.v );
  295. mm.setValue( current_material );
  296. if ( current_material === "textured" ) {
  297. effect.enableUvs = true;
  298. } else {
  299. effect.enableUvs = false;
  300. }
  301. if ( current_material === "colors" ) {
  302. effect.enableColors = true;
  303. } else {
  304. effect.enableColors = false;
  305. }
  306. };
  307. };
  308. function toggle( e ) {
  309. if ( e.style.display === "block" ) {
  310. e.style.display = "none";
  311. } else {
  312. e.style.display = "block";
  313. }
  314. }
  315. effectController = {
  316. material: "shiny",
  317. speed : 1.0,
  318. numBlobs: 10,
  319. resolution: 28,
  320. isolation: 80,
  321. floor: true,
  322. wallx: false,
  323. wallz: false,
  324. hue: 0.0,
  325. saturation: 0.9,
  326. value: 0.3,
  327. lhue: 0.04,
  328. lsaturation: 1.0,
  329. lvalue: 1.0,
  330. lx: 0.5,
  331. ly: 0.5,
  332. lz: 1.0,
  333. postprocessing: false,
  334. h_m: function() {
  335. for (var i = 0; i < g_m.length; i++) toggle(g_m[ i ].domElement);
  336. },
  337. h_c: function() {
  338. for (var i = 0; i < g_c.length; i++) toggle(g_c[ i ].domElement);
  339. },
  340. h_pc: function() {
  341. for (var i = 0; i < g_pc.length; i++) toggle(g_pc[ i ].domElement);
  342. },
  343. h_do: function() {
  344. for (var i = 0; i < g_do.length; i++) toggle(g_do[ i ].domElement);
  345. },
  346. h_s: function() {
  347. for (var i = 0; i < g_s.length; i++) toggle(g_s[ i ].domElement);
  348. },
  349. h_r: function() {
  350. for (var i = 0; i < g_r.length; i++) toggle(g_r[ i ].domElement);
  351. },
  352. dummy: function() {
  353. }
  354. };
  355. var e1, e2, e3, e4, e5, e6, h, m_h, m_s, m_v,
  356. g_m = [], g_c, g_pc, g_do, g_s, g_r, mm,
  357. gui = new DAT.GUI();
  358. // material (type)
  359. mm = gui.add( effectController, "material" );
  360. mm.domElement.style.display = "none";
  361. h = gui.add( effectController, "h_m" ).name( "Materials" );
  362. setGuiHeaderStyle(h, 0, 65, 50);
  363. for ( var m in materials ) {
  364. effectController[ m ] = createHandler( m );
  365. e1 = gui.add( effectController, m ).name( m );
  366. setGuiElementStyle( [ e1 ], 0, 65, 50, "block" );
  367. g_m.push( e1 );
  368. }
  369. // material (color)
  370. h = gui.add( effectController, "h_c" ).name( "Material color" );
  371. m_h = gui.add( effectController, "hue", 0.0, 1.0, 0.025 );
  372. m_s = gui.add( effectController, "saturation", 0.0, 1.0, 0.025 );
  373. m_v = gui.add( effectController, "value", 0.0, 1.0, 0.025 );
  374. g_c = [ m_h, m_s, m_v ];
  375. setGuiHeaderStyle( h, 20, 65, 50 );
  376. setGuiElementStyle( g_c, 20, 65, 50, "block" );
  377. // light (point)
  378. h = gui.add(effectController, "h_pc").name("Point light color");
  379. e1 = gui.add(effectController, "lhue", 0.0, 1.0, 0.025).name("hue");
  380. e2 = gui.add(effectController, "lsaturation", 0.0, 1.0, 0.025).name("saturation");
  381. e3 = gui.add(effectController, "lvalue", 0.0, 1.0, 0.025).name("value");
  382. g_pc = [ e1, e2, e3 ];
  383. setGuiHeaderStyle(h, 50, 65, 50);
  384. setGuiElementStyle(g_pc, 50, 65, 50);
  385. // light (directional)
  386. h = gui.add(effectController, "h_do").name("Directional light orientation");
  387. e1 = gui.add(effectController, "lx", -1.0, 1.0, 0.025).name("x");
  388. e2 = gui.add(effectController, "ly", -1.0, 1.0, 0.025).name("y");
  389. e3 = gui.add(effectController, "lz", -1.0, 1.0, 0.025).name("z");
  390. g_do = [ e1, e2, e3 ];
  391. setGuiHeaderStyle(h, 80, 65, 50);
  392. setGuiElementStyle(g_do, 80, 65, 50);
  393. // simulation
  394. h = gui.add(effectController, "h_s").name("Simulation");
  395. e1 = gui.add(effectController, "speed", 0.1, 8.0, 0.05);
  396. e2 = gui.add(effectController, "numBlobs", 1, 50, 1);
  397. e3 = gui.add(effectController, "resolution", 14, 40, 1);
  398. e4 = gui.add(effectController, "isolation", 10, 300, 1);
  399. e5 = gui.add(effectController, "floor");
  400. e6 = gui.add(effectController, "wallx");
  401. e7 = gui.add(effectController, "wallz");
  402. e5.updateDisplay();
  403. e6.updateDisplay();
  404. e7.updateDisplay();
  405. g_s = [ e1, e2, e3, e4, e5, e6, e7 ];
  406. setGuiHeaderStyle(h, 200, 65, 50);
  407. setGuiElementStyle(g_s, 200, 65, 50, "block");
  408. // rendering
  409. h = gui.add(effectController, "h_r").name("Rendering");
  410. e1 = gui.add(effectController, "postprocessing");
  411. g_r = [ e1 ];
  412. setGuiHeaderStyle(h, 225, 65, 50);
  413. setGuiElementStyle(g_r, 225, 65, 50, "block");
  414. // save
  415. //e1 = gui.add(GUI, "saveURL").name("Save to URL");
  416. //setGuiHeaderStyle(e1, 250, 65, 50, "block");
  417. gui.domElement.style.backgroundColor = "#222";
  418. // restore material from URL
  419. id = mm.getValue()
  420. current_material = id;
  421. var mat = materials[ id ];
  422. effect.material = mat.m;
  423. }
  424. function setGuiHeaderStyle( g, h, s, v ) {
  425. var color = "hsl(" + h + "," + s + "%, " + v + "%)";
  426. g.domElement.style.borderLeft = "solid 5px " + color;
  427. g.domElement.style.background = color;
  428. g.domElement.style.fontWeight = "bold";
  429. }
  430. function setGuiElementStyle( a, h, s, v, display ) {
  431. var s, color = "hsl(" + h + "," + s + "%, " + v + "%)";
  432. for ( i = 0; i < a.length; i ++ ) {
  433. s = a[ i ].domElement.style;
  434. s.borderLeft = "solid 5px " + color;
  435. s.display = display ? display : "none";
  436. }
  437. }
  438. // this controls content of marching cubes voxel field
  439. function updateCubes( object, time, numblobs, floor, wallx, wallz ) {
  440. object.reset();
  441. // fill the field with some metaballs
  442. var i, ballx, bally, ballz, subtract, strength;
  443. subtract = 12;
  444. strength = 1.2 / ( ( Math.sqrt( numblobs ) - 1 ) / 4 + 1 );
  445. for ( i = 0; i < numblobs; i ++ ) {
  446. ballx = Math.sin( i + 1.26 * time * ( 1.03 + 0.5 * Math.cos( 0.21 * i ) ) ) * 0.27 + 0.5;
  447. bally = Math.abs( Math.cos( i + 1.12 * time * Math.cos( 1.22 + 0.1424 * i ) ) ) * 0.77; // dip into the floor
  448. ballz = Math.cos( i + 1.32 * time * 0.1 * Math.sin( ( 0.92 + 0.53 * i ) ) ) * 0.27 + 0.5;
  449. object.addBall(ballx, bally, ballz, strength, subtract);
  450. }
  451. if ( floor ) object.addPlaneY( 2, 12 );
  452. if ( wallz ) object.addPlaneZ( 2, 12 );
  453. if ( wallx ) object.addPlaneX( 2, 12 );
  454. }
  455. //
  456. function animate() {
  457. requestAnimationFrame( animate );
  458. render();
  459. stats.update();
  460. }
  461. function render() {
  462. var delta = clock.getDelta();
  463. time += delta * effectController.speed * 0.5;
  464. controls.update( delta );
  465. // marching cubes
  466. if ( effectController.resolution !== resolution ) {
  467. resolution = effectController.resolution;
  468. effect.init( resolution );
  469. }
  470. if ( effectController.isolation !== effect.isolation ) {
  471. effect.isolation = effectController.isolation;
  472. }
  473. updateCubes( effect, time, effectController.numBlobs, effectController.floor, effectController.wallx, effectController.wallz );
  474. // materials
  475. if ( effect.material instanceof THREE.ShaderMaterial ) {
  476. if ( current_material === "dotted2" ) {
  477. effect.material.uniforms.uLineColor1.value.setHSV( effectController.hue, effectController.saturation, effectController.value );
  478. } else if ( current_material === "hatching2" ) {
  479. u = effect.material.uniforms;
  480. u.uLineColor1.value.setHSV( effectController.hue, effectController.saturation, effectController.value );
  481. u.uLineColor2.value.setHSV( effectController.hue, effectController.saturation, effectController.value );
  482. u.uLineColor3.value.setHSV( effectController.hue, effectController.saturation, effectController.value );
  483. u.uLineColor4.value.setHSV( ( effectController.hue + 0.2 % 1.0 ), effectController.saturation, effectController.value );
  484. } else {
  485. effect.material.uniforms.uBaseColor.value.setHSV( effectController.hue, effectController.saturation, effectController.value );
  486. }
  487. } else {
  488. effect.material.color.setHSV( effectController.hue, effectController.saturation, effectController.value );
  489. }
  490. // lights
  491. light.position.set( effectController.lx, effectController.ly, effectController.lz );
  492. light.position.normalize();
  493. pointLight.color.setHSV( effectController.lhue, effectController.lsaturation, effectController.lvalue );
  494. // render
  495. if ( effectController.postprocessing ) {
  496. composer.render( delta );
  497. } else {
  498. renderer.clear();
  499. renderer.render( scene, camera );
  500. }
  501. }
  502. </script>
  503. </body>
  504. </html>