webgl_materials_nodes.html 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - node material</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. color: #fff;
  10. font-family:Monospace;
  11. font-size:13px;
  12. margin: 0px;
  13. text-align:center;
  14. overflow: hidden;
  15. }
  16. #info {
  17. color: #fff;
  18. position: absolute;
  19. top: 10px;
  20. width: 100%;
  21. text-align: center;
  22. display:block;
  23. }
  24. a { color: white }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="container"></div>
  29. <div id="info">
  30. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - Node-Based Material
  31. </div>
  32. <script src="../build/three.js"></script>
  33. <script src='js/geometries/TeapotBufferGeometry.js'></script>
  34. <script src="js/controls/OrbitControls.js"></script>
  35. <script src="js/libs/dat.gui.min.js"></script>
  36. <!-- NodeLibrary -->
  37. <script src="js/nodes/GLNode.js"></script>
  38. <script src="js/nodes/RawNode.js"></script>
  39. <script src="js/nodes/TempNode.js"></script>
  40. <script src="js/nodes/InputNode.js"></script>
  41. <script src="js/nodes/ConstNode.js"></script>
  42. <script src="js/nodes/VarNode.js"></script>
  43. <script src="js/nodes/FunctionNode.js"></script>
  44. <script src="js/nodes/FunctionCallNode.js"></script>
  45. <script src="js/nodes/AttributeNode.js"></script>
  46. <script src="js/nodes/NodeBuilder.js"></script>
  47. <script src="js/nodes/NodeLib.js"></script>
  48. <script src="js/nodes/NodeMaterial.js"></script>
  49. <!-- Accessors -->
  50. <script src="js/nodes/accessors/PositionNode.js"></script>
  51. <script src="js/nodes/accessors/NormalNode.js"></script>
  52. <script src="js/nodes/accessors/UVNode.js"></script>
  53. <script src="js/nodes/accessors/ScreenUVNode.js"></script>
  54. <script src="js/nodes/accessors/ColorsNode.js"></script>
  55. <script src="js/nodes/accessors/CameraNode.js"></script>
  56. <script src="js/nodes/accessors/ReflectNode.js"></script>
  57. <script src="js/nodes/accessors/LightNode.js"></script>
  58. <!-- Inputs -->
  59. <script src="js/nodes/inputs/IntNode.js"></script>
  60. <script src="js/nodes/inputs/FloatNode.js"></script>
  61. <script src="js/nodes/inputs/ColorNode.js"></script>
  62. <script src="js/nodes/inputs/Vector2Node.js"></script>
  63. <script src="js/nodes/inputs/Vector3Node.js"></script>
  64. <script src="js/nodes/inputs/Vector4Node.js"></script>
  65. <script src="js/nodes/inputs/TextureNode.js"></script>
  66. <script src="js/nodes/inputs/Matrix4Node.js"></script>
  67. <script src="js/nodes/inputs/CubeTextureNode.js"></script>
  68. <!-- Math -->
  69. <script src="js/nodes/math/Math1Node.js"></script>
  70. <script src="js/nodes/math/Math2Node.js"></script>
  71. <script src="js/nodes/math/Math3Node.js"></script>
  72. <script src="js/nodes/math/OperatorNode.js"></script>
  73. <!-- Utils -->
  74. <script src="js/nodes/utils/SwitchNode.js"></script>
  75. <script src="js/nodes/utils/JoinNode.js"></script>
  76. <script src="js/nodes/utils/TimerNode.js"></script>
  77. <script src="js/nodes/utils/RoughnessToBlinnExponentNode.js"></script>
  78. <script src="js/nodes/utils/VelocityNode.js"></script>
  79. <script src="js/nodes/utils/LuminanceNode.js"></script>
  80. <script src="js/nodes/utils/ColorAdjustmentNode.js"></script>
  81. <script src="js/nodes/utils/NoiseNode.js"></script>
  82. <script src="js/nodes/utils/ResolutionNode.js"></script>
  83. <script src="js/nodes/utils/BumpNode.js"></script>
  84. <script src="js/nodes/utils/BlurNode.js"></script>
  85. <script src="js/nodes/utils/UVTransformNode.js"></script>
  86. <!-- Phong Material -->
  87. <script src="js/nodes/materials/PhongNode.js"></script>
  88. <script src="js/nodes/materials/PhongNodeMaterial.js"></script>
  89. <!-- Standard Material -->
  90. <script src="js/nodes/materials/StandardNode.js"></script>
  91. <script src="js/nodes/materials/StandardNodeMaterial.js"></script>
  92. <script>
  93. var container = document.getElementById( 'container' );
  94. var renderer, scene, camera, clock = new THREE.Clock(), fov = 50;
  95. var teapot, mesh;
  96. var controls;
  97. var move = false;
  98. var rtTexture, rtMaterial;
  99. var gui, guiElements = [];
  100. var textures = {
  101. brick: { url: 'textures/brick_diffuse.jpg' },
  102. grass: { url: 'textures/terrain/grasslight-big.jpg' },
  103. grassNormal: { url: 'textures/terrain/grasslight-big-nm.jpg' },
  104. decalDiffuse: { url: 'textures/decal/decal-diffuse.png' },
  105. cloud: { url: 'textures/lava/cloud.png' },
  106. spherical: { url: 'textures/envmap.png' }
  107. };
  108. var param = { example: 'standard' };
  109. function getTexture( name ) {
  110. var texture = textures[ name ].texture;
  111. if ( ! texture ) {
  112. texture = textures[ name ].texture = new THREE.TextureLoader().load( textures[ name ].url );
  113. texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
  114. }
  115. return texture;
  116. }
  117. var cubemap = function () {
  118. var path = "textures/cube/Park2/";
  119. var format = '.jpg';
  120. var urls = [
  121. path + 'posx' + format, path + 'negx' + format,
  122. path + 'posy' + format, path + 'negy' + format,
  123. path + 'posz' + format, path + 'negz' + format
  124. ];
  125. var textureCube = new THREE.CubeTextureLoader().load( urls );
  126. textureCube.format = THREE.RGBFormat;
  127. return textureCube;
  128. }();
  129. window.addEventListener( 'load', init );
  130. function init() {
  131. renderer = new THREE.WebGLRenderer( { antialias: true } );
  132. renderer.setPixelRatio( window.devicePixelRatio );
  133. renderer.setSize( window.innerWidth, window.innerHeight );
  134. container.appendChild( renderer.domElement );
  135. scene = new THREE.Scene();
  136. camera = new THREE.PerspectiveCamera( fov, window.innerWidth / window.innerHeight, 1, 1000 );
  137. camera.position.x = 50;
  138. camera.position.z = - 50;
  139. camera.position.y = 30;
  140. camera.target = new THREE.Vector3();
  141. controls = new THREE.OrbitControls( camera, renderer.domElement );
  142. controls.minDistance = 50;
  143. controls.maxDistance = 200;
  144. scene.add( new THREE.AmbientLight( 0x464646 ) );
  145. var light = new THREE.DirectionalLight( 0xffddcc, 1 );
  146. light.position.set( 1, 0.75, 0.5 );
  147. scene.add( light );
  148. var light = new THREE.DirectionalLight( 0xccccff, 1 );
  149. light.position.set( - 1, 0.75, - 0.5 );
  150. scene.add( light );
  151. teapot = new THREE.TeapotBufferGeometry( 15, 18 );
  152. mesh = new THREE.Mesh( teapot );
  153. scene.add( mesh );
  154. window.addEventListener( 'resize', onWindowResize, false );
  155. updateMaterial();
  156. onWindowResize();
  157. animate();
  158. }
  159. function clearGui() {
  160. if ( gui ) gui.destroy();
  161. gui = new dat.GUI();
  162. var example = gui.add( param, 'example', {
  163. 'basic / standard': 'standard',
  164. 'basic / physical': 'physical',
  165. 'basic / phong': 'phong',
  166. 'basic / layers': 'layers',
  167. 'basic / rim': 'rim',
  168. 'basic / color-adjustment': 'color-adjustment',
  169. 'basic / uv-transform': 'uv-transform',
  170. 'basic / bump': 'bump',
  171. 'basic / blur': 'blur',
  172. 'basic / spherical-reflection': 'spherical-reflection',
  173. 'adv / fresnel': 'fresnel',
  174. 'adv / saturation': 'saturation',
  175. 'adv / top-bottom': 'top-bottom',
  176. 'adv / skin': 'skin',
  177. 'adv / skin-phong': 'skin-phong',
  178. 'adv / caustic': 'caustic',
  179. 'adv / displace': 'displace',
  180. 'adv / plush': 'plush',
  181. 'adv / toon': 'toon',
  182. 'adv / camera-depth': 'camera-depth',
  183. 'adv / soft-body': 'soft-body',
  184. 'adv / wave': 'wave',
  185. 'adv / triangle-blur': 'triangle-blur',
  186. 'adv / expression': 'expression',
  187. 'adv / sss': 'sss',
  188. 'adv / translucent': 'translucent',
  189. 'misc / smoke': 'smoke',
  190. 'misc / firefly': 'firefly',
  191. 'misc / reserved-keywords': 'reserved-keywords',
  192. 'misc / varying': 'varying',
  193. 'misc / custom-attribute': 'custom-attribute'
  194. } ).onFinishChange( function () {
  195. updateMaterial();
  196. } );
  197. gui.open();
  198. }
  199. function addGui( name, value, callback, isColor, min, max ) {
  200. var node;
  201. param[ name ] = value;
  202. if ( isColor ) {
  203. node = gui.addColor( param, name ).onChange( function () {
  204. callback( param[ name ] );
  205. } );
  206. } else if ( typeof value == 'object' ) {
  207. node = gui.add( param, name, value ).onChange( function () {
  208. callback( param[ name ] );
  209. } );
  210. } else {
  211. node = gui.add( param, name, min, max ).onChange( function () {
  212. callback( param[ name ] );
  213. } );
  214. }
  215. return node;
  216. }
  217. function updateMaterial() {
  218. move = false;
  219. if ( mesh.material ) mesh.material.dispose();
  220. if ( rtTexture ) {
  221. rtTexture.dispose();
  222. rtTexture = null;
  223. }
  224. if ( rtMaterial ) {
  225. rtMaterial.dispose();
  226. rtMaterial = null;
  227. }
  228. var name = param.example;
  229. var mtl;
  230. clearGui();
  231. switch ( name ) {
  232. case 'phong':
  233. // MATERIAL
  234. mtl = new THREE.PhongNodeMaterial();
  235. //mtl.color = // albedo (vec3)
  236. //mtl.alpha = // opacity (float)
  237. //mtl.specular = // specular color (vec3)
  238. //mtl.shininess = // shininess (float)
  239. //mtl.normal = // normalmap (vec3)
  240. //mtl.normalScale = // normalmap scale (vec2)
  241. //mtl.emissive = // emissive color (vec3)
  242. //mtl.ambient = // ambient color (vec3)
  243. //mtl.shadow = // shadowmap (vec3)
  244. //mtl.light = // custom-light (vec3)
  245. //mtl.ao = // ambient occlusion (float)
  246. //mtl.light = // input/output light (vec3)
  247. //mtl.environment = // reflection/refraction (vec3)
  248. //mtl.environmentAlpha = // environment alpha (float)
  249. //mtl.transform = // vertex transformation (vec3)
  250. var mask = new THREE.SwitchNode( new THREE.TextureNode( getTexture( "decalDiffuse" ) ), 'w' );
  251. mtl.color = new THREE.TextureNode( getTexture( "grass" ) );
  252. mtl.specular = new THREE.FloatNode( .5 );
  253. mtl.shininess = new THREE.FloatNode( 15 );
  254. mtl.environment = new THREE.CubeTextureNode( cubemap );
  255. mtl.environmentAlpha = mask;
  256. mtl.normal = new THREE.TextureNode( getTexture( "grassNormal" ) );
  257. mtl.normalScale = new THREE.Math1Node( mask, THREE.Math1Node.INVERT );
  258. break;
  259. case 'standard':
  260. // MATERIAL
  261. mtl = new THREE.StandardNodeMaterial();
  262. //mtl.color = // albedo (vec3)
  263. //mtl.alpha = // opacity (float)
  264. //mtl.roughness = // roughness (float)
  265. //mtl.metalness = // metalness (float)
  266. //mtl.normal = // normalmap (vec3)
  267. //mtl.normalScale = // normalmap scale (vec2)
  268. //mtl.emissive = // emissive color (vec3)
  269. //mtl.ambient = // ambient color (vec3)
  270. //mtl.shadow = // shadowmap (vec3)
  271. //mtl.light = // custom-light (vec3)
  272. //mtl.ao = // ambient occlusion (float)
  273. //mtl.environment = // reflection/refraction (vec3)
  274. //mtl.transform = // vertex transformation (vec3)
  275. var mask = new THREE.SwitchNode( new THREE.TextureNode( getTexture( "decalDiffuse" ) ), 'w' );
  276. var normalScale = new THREE.FloatNode( .3 );
  277. var roughnessA = new THREE.FloatNode( .5 );
  278. var metalnessA = new THREE.FloatNode( .5 );
  279. var roughnessB = new THREE.FloatNode( 0 );
  280. var metalnessB = new THREE.FloatNode( 1 );
  281. var roughness = new THREE.Math3Node(
  282. roughnessA,
  283. roughnessB,
  284. mask,
  285. THREE.Math3Node.MIX
  286. );
  287. var metalness = new THREE.Math3Node(
  288. metalnessA,
  289. metalnessB,
  290. mask,
  291. THREE.Math3Node.MIX
  292. );
  293. var normalMask = new THREE.OperatorNode(
  294. new THREE.Math1Node( mask, THREE.Math1Node.INVERT ),
  295. normalScale,
  296. THREE.OperatorNode.MUL
  297. );
  298. mtl.color = new THREE.ColorNode( 0xEEEEEE );
  299. mtl.roughness = roughness;
  300. mtl.metalness = metalness;
  301. mtl.environment = new THREE.CubeTextureNode( cubemap );
  302. mtl.normal = new THREE.TextureNode( getTexture( "grassNormal" ) );
  303. mtl.normalScale = normalMask;
  304. // GUI
  305. addGui( 'color', mtl.color.value.getHex(), function ( val ) {
  306. mtl.color.value.setHex( val );
  307. }, true );
  308. addGui( 'roughnessA', roughnessA.number, function ( val ) {
  309. roughnessA.number = val;
  310. }, false, 0, 1 );
  311. addGui( 'metalnessA', metalnessA.number, function ( val ) {
  312. metalnessA.number = val;
  313. }, false, 0, 1 );
  314. addGui( 'roughnessB', roughnessB.number, function ( val ) {
  315. roughnessB.number = val;
  316. }, false, 0, 1 );
  317. addGui( 'metalnessB', metalnessB.number, function ( val ) {
  318. metalnessB.number = val;
  319. }, false, 0, 1 );
  320. addGui( 'normalScale', normalScale.number, function ( val ) {
  321. normalScale.number = val;
  322. }, false, 0, 1 );
  323. break;
  324. case 'physical':
  325. // MATERIAL
  326. mtl = new THREE.StandardNodeMaterial();
  327. //mtl.color = // albedo (vec3)
  328. //mtl.alpha = // opacity (float)
  329. //mtl.roughness = // roughness (float)
  330. //mtl.metalness = // metalness (float)
  331. //mtl.reflectivity = // reflectivity (float)
  332. //mtl.clearCoat = // clearCoat (float)
  333. //mtl.clearCoatRoughness = // clearCoatRoughness (float)
  334. //mtl.normal = // normalmap (vec3)
  335. //mtl.normalScale = // normalmap scale (vec2)
  336. //mtl.emissive = // emissive color (vec3)
  337. //mtl.ambient = // ambient color (vec3)
  338. //mtl.shadow = // shadowmap (vec3)
  339. //mtl.light = // custom-light (vec3)
  340. //mtl.ao = // ambient occlusion (float)
  341. //mtl.environment = // reflection/refraction (vec3)
  342. //mtl.transform = // vertex transformation (vec3)
  343. var mask = new THREE.SwitchNode( new THREE.TextureNode( getTexture( "decalDiffuse" ) ), 'w' );
  344. var normalScale = new THREE.FloatNode( .3 );
  345. var roughnessA = new THREE.FloatNode( .5 );
  346. var metalnessA = new THREE.FloatNode( .5 );
  347. var roughnessB = new THREE.FloatNode( 0 );
  348. var metalnessB = new THREE.FloatNode( 1 );
  349. var reflectivity = new THREE.FloatNode( 0 );
  350. var clearCoat = new THREE.FloatNode( 1 );
  351. var clearCoatRoughness = new THREE.FloatNode( 1 );
  352. var roughness = new THREE.Math3Node(
  353. roughnessA,
  354. roughnessB,
  355. mask,
  356. THREE.Math3Node.MIX
  357. );
  358. var metalness = new THREE.Math3Node(
  359. metalnessA,
  360. metalnessB,
  361. mask,
  362. THREE.Math3Node.MIX
  363. );
  364. var normalMask = new THREE.OperatorNode(
  365. new THREE.Math1Node( mask, THREE.Math1Node.INVERT ),
  366. normalScale,
  367. THREE.OperatorNode.MUL
  368. );
  369. mtl.color = new THREE.ColorNode( 0xEEEEEE );
  370. mtl.roughness = roughness;
  371. mtl.metalness = metalness;
  372. mtl.reflectivity = reflectivity;
  373. mtl.clearCoat = clearCoat;
  374. mtl.clearCoatRoughness = clearCoatRoughness;
  375. mtl.environment = new THREE.CubeTextureNode( cubemap );
  376. mtl.normal = new THREE.TextureNode( getTexture( "grassNormal" ) );
  377. mtl.normalScale = normalMask;
  378. // GUI
  379. addGui( 'color', mtl.color.value.getHex(), function ( val ) {
  380. mtl.color.value.setHex( val );
  381. }, true );
  382. addGui( 'reflectivity', reflectivity.number, function ( val ) {
  383. reflectivity.number = val;
  384. }, false, 0, 1 );
  385. addGui( 'clearCoat', clearCoat.number, function ( val ) {
  386. clearCoat.number = val;
  387. }, false, 0, 1 );
  388. addGui( 'clearCoatRoughness', clearCoatRoughness.number, function ( val ) {
  389. clearCoatRoughness.number = val;
  390. }, false, 0, 1 );
  391. addGui( 'roughnessA', roughnessA.number, function ( val ) {
  392. roughnessA.number = val;
  393. }, false, 0, 1 );
  394. addGui( 'metalnessA', metalnessA.number, function ( val ) {
  395. metalnessA.number = val;
  396. }, false, 0, 1 );
  397. addGui( 'roughnessB', roughnessB.number, function ( val ) {
  398. roughnessB.number = val;
  399. }, false, 0, 1 );
  400. addGui( 'metalnessB', metalnessB.number, function ( val ) {
  401. metalnessB.number = val;
  402. }, false, 0, 1 );
  403. addGui( 'normalScale', normalScale.number, function ( val ) {
  404. normalScale.number = val;
  405. }, false, 0, 1 );
  406. break;
  407. case 'wave':
  408. // MATERIAL
  409. mtl = new THREE.PhongNodeMaterial();
  410. var time = new THREE.TimerNode();
  411. var speed = new THREE.FloatNode( 5 );
  412. var scale = new THREE.FloatNode( 1 );
  413. var worldScale = new THREE.FloatNode( .4 );
  414. var colorA = new THREE.ColorNode( 0xFFFFFF );
  415. var colorB = new THREE.ColorNode( 0x0054df );
  416. var timeScale = new THREE.OperatorNode(
  417. time,
  418. speed,
  419. THREE.OperatorNode.MUL
  420. );
  421. var worldScl = new THREE.OperatorNode(
  422. new THREE.PositionNode(),
  423. worldScale,
  424. THREE.OperatorNode.MUL
  425. );
  426. var posContinuous = new THREE.OperatorNode(
  427. worldScl,
  428. timeScale,
  429. THREE.OperatorNode.ADD
  430. );
  431. var wave = new THREE.Math1Node( posContinuous, THREE.Math1Node.SIN );
  432. wave = new THREE.SwitchNode( wave, 'x' );
  433. var waveScale = new THREE.OperatorNode(
  434. wave,
  435. scale,
  436. THREE.OperatorNode.MUL
  437. );
  438. var displaceY = new THREE.JoinNode(
  439. new THREE.FloatNode(),
  440. waveScale,
  441. new THREE.FloatNode()
  442. );
  443. var displace = new THREE.OperatorNode(
  444. new THREE.NormalNode(),
  445. displaceY,
  446. THREE.OperatorNode.MUL
  447. );
  448. var blend = new THREE.OperatorNode(
  449. new THREE.PositionNode(),
  450. displaceY,
  451. THREE.OperatorNode.ADD
  452. );
  453. var color = new THREE.Math3Node(
  454. colorB,
  455. colorA,
  456. wave,
  457. THREE.Math3Node.MIX
  458. );
  459. mtl.color = color;
  460. mtl.transform = blend;
  461. // GUI
  462. addGui( 'speed', speed.number, function ( val ) {
  463. speed.number = val;
  464. }, false, 0, 10 );
  465. addGui( 'scale', scale.number, function ( val ) {
  466. scale.number = val;
  467. }, false, 0, 3 );
  468. addGui( 'worldScale', worldScale.number, function ( val ) {
  469. worldScale.number = val;
  470. }, false, 0, 1 );
  471. addGui( 'colorA', colorA.value.getHex(), function ( val ) {
  472. colorA.value.setHex( val );
  473. }, true );
  474. addGui( 'colorB', colorB.value.getHex(), function ( val ) {
  475. colorB.value.setHex( val );
  476. }, true );
  477. addGui( 'useNormals', false, function ( val ) {
  478. blend.b = val ? displace : displaceY;
  479. mtl.build();
  480. } );
  481. break;
  482. case 'rim':
  483. // MATERIAL
  484. mtl = new THREE.PhongNodeMaterial();
  485. var intensity = 1.3;
  486. var power = new THREE.FloatNode( 3 );
  487. var color = new THREE.ColorNode( 0xFFFFFF );
  488. var viewZ = new THREE.Math2Node(
  489. new THREE.NormalNode( THREE.NormalNode.VIEW ),
  490. new THREE.Vector3Node( 0, 0, - intensity ),
  491. THREE.Math2Node.DOT
  492. );
  493. var rim = new THREE.OperatorNode(
  494. viewZ,
  495. new THREE.FloatNode( intensity ),
  496. THREE.OperatorNode.ADD
  497. );
  498. var rimPower = new THREE.Math2Node(
  499. rim,
  500. power,
  501. THREE.Math2Node.POW
  502. );
  503. var rimColor = new THREE.OperatorNode(
  504. rimPower,
  505. color,
  506. THREE.OperatorNode.MUL
  507. );
  508. mtl.color = new THREE.ColorNode( 0x111111 );
  509. mtl.emissive = rimColor;
  510. // GUI
  511. addGui( 'color', color.value.getHex(), function ( val ) {
  512. color.value.setHex( val );
  513. }, true );
  514. addGui( 'intensity', intensity, function ( val ) {
  515. intensity = val;
  516. viewZ.b.z = - intensity;
  517. rim.b.number = intensity;
  518. }, false, 0, 3 );
  519. addGui( 'power', power.number, function ( val ) {
  520. power.number = val;
  521. }, false, 0, 6 );
  522. addGui( 'xray', false, function ( val ) {
  523. if ( val ) {
  524. mtl.emissive = color;
  525. mtl.alpha = rimPower;
  526. mtl.blending = THREE.AdditiveBlending;
  527. mtl.depthWrite = false;
  528. } else {
  529. mtl.emissive = rimColor;
  530. mtl.alpha = null;
  531. mtl.blending = THREE.NormalBlending;
  532. mtl.depthWrite = true;
  533. }
  534. mtl.build();
  535. } );
  536. break;
  537. case 'color-adjustment':
  538. // MATERIAL
  539. mtl = new THREE.PhongNodeMaterial();
  540. var texture = new THREE.TextureNode( getTexture( "brick" ) );
  541. var hue = new THREE.FloatNode();
  542. var sataturation = new THREE.FloatNode( 1 );
  543. var vibrance = new THREE.FloatNode();
  544. var brightness = new THREE.FloatNode( 0 );
  545. var contrast = new THREE.FloatNode( 1 );
  546. var hueNode = new THREE.ColorAdjustmentNode( texture, hue, THREE.ColorAdjustmentNode.HUE );
  547. var satNode = new THREE.ColorAdjustmentNode( hueNode, sataturation, THREE.ColorAdjustmentNode.SATURATION );
  548. var vibranceNode = new THREE.ColorAdjustmentNode( satNode, vibrance, THREE.ColorAdjustmentNode.VIBRANCE );
  549. var brightnessNode = new THREE.ColorAdjustmentNode( vibranceNode, brightness, THREE.ColorAdjustmentNode.BRIGHTNESS );
  550. var contrastNode = new THREE.ColorAdjustmentNode( brightnessNode, contrast, THREE.ColorAdjustmentNode.CONTRAST );
  551. mtl.color = contrastNode;
  552. // GUI
  553. addGui( 'hue', hue.number, function ( val ) {
  554. hue.number = val;
  555. }, false, 0, Math.PI * 2 );
  556. addGui( 'saturation', sataturation.number, function ( val ) {
  557. sataturation.number = val;
  558. }, false, 0, 2 );
  559. addGui( 'vibrance', vibrance.number, function ( val ) {
  560. vibrance.number = val;
  561. }, false, - 1, 1 );
  562. addGui( 'brightness', brightness.number, function ( val ) {
  563. brightness.number = val;
  564. }, false, 0, .5 );
  565. addGui( 'contrast', contrast.number, function ( val ) {
  566. contrast.number = val;
  567. }, false, 0, 2 );
  568. break;
  569. case 'uv-transform':
  570. // MATERIAL
  571. mtl = new THREE.PhongNodeMaterial();
  572. var translate = new THREE.Vector2();
  573. var rotate = 0;
  574. var scale = new THREE.Vector2( 1, 1 );
  575. var texture = new THREE.TextureNode( getTexture( "brick" ) );
  576. texture.coord = new THREE.UVTransformNode();
  577. //texture.coord.uv = new THREE.UVNode( 1 ); // uv2 for example
  578. mtl.color = texture;
  579. // GUI
  580. function updateUVTransform() {
  581. texture.coord.compose( translate, THREE.Math.degToRad( rotate ), scale );
  582. }
  583. addGui( 'translateX', translate.x, function ( val ) {
  584. translate.x = val;
  585. updateUVTransform();
  586. }, false, 0, 10 );
  587. addGui( 'translateY', translate.y, function ( val ) {
  588. translate.y = val;
  589. updateUVTransform();
  590. }, false, 0, 10 );
  591. addGui( 'scaleX', scale.x, function ( val ) {
  592. scale.x = val;
  593. updateUVTransform();
  594. }, false, .1, 5 );
  595. addGui( 'scaleY', scale.y, function ( val ) {
  596. scale.y = val;
  597. updateUVTransform();
  598. }, false, .1, 5 );
  599. addGui( 'rotate', rotate, function ( val ) {
  600. rotate = val;
  601. updateUVTransform();
  602. }, false, 0, 360 );
  603. break;
  604. case 'bump':
  605. // MATERIAL
  606. mtl = new THREE.PhongNodeMaterial();
  607. var diffuse = new THREE.TextureNode( getTexture( "brick" ) );
  608. var bump = new THREE.BumpNode( new THREE.TextureNode( getTexture( "brick" ) ) );
  609. bump.scale = new THREE.Vector2Node( - 1.5, - 1.5 );
  610. mtl.color = diffuse;
  611. mtl.normal = bump;
  612. // GUI
  613. addGui( 'scaleX', bump.scale.x, function ( val ) {
  614. bump.scale.x = val;
  615. }, false, - 2, 2 );
  616. addGui( 'scaleY', bump.scale.y, function ( val ) {
  617. bump.scale.y = val;
  618. }, false, - 2, 2 );
  619. addGui( 'color', true, function ( val ) {
  620. mtl.color = val ? diffuse : new THREE.ColorNode( 0xEEEEEE );
  621. mtl.build();
  622. } );
  623. break;
  624. case 'blur':
  625. // MATERIAL
  626. mtl = new THREE.PhongNodeMaterial();
  627. var diffuse = new THREE.TextureNode( getTexture( "brick" ) );
  628. var blur = new THREE.BlurNode( new THREE.TextureNode( getTexture( "brick" ) ) );
  629. mtl.color = blur;
  630. // GUI
  631. addGui( 'radiusX', blur.radius.x, function ( val ) {
  632. blur.radius.x = val;
  633. }, false, 0, 15 );
  634. addGui( 'radiusY', blur.radius.y, function ( val ) {
  635. blur.radius.y = val;
  636. }, false, 0, 15 );
  637. break;
  638. case 'spherical-reflection':
  639. // MATERIAL
  640. mtl = new THREE.PhongNodeMaterial();
  641. mtl.environment = new THREE.TextureNode( getTexture( "spherical" ), new THREE.ReflectNode( THREE.ReflectNode.SPHERE ) );
  642. break;
  643. case 'fresnel':
  644. // MATERIAL
  645. mtl = new THREE.PhongNodeMaterial();
  646. var reflectance = new THREE.FloatNode( 1.3 );
  647. var power = new THREE.FloatNode( 1 );
  648. var color = new THREE.CubeTextureNode( cubemap );
  649. var viewZ = new THREE.Math2Node(
  650. new THREE.NormalNode( THREE.NormalNode.VIEW ),
  651. new THREE.Vector3Node( 0, 0, - 1 ),
  652. THREE.Math2Node.DOT
  653. );
  654. var theta = new THREE.OperatorNode(
  655. viewZ,
  656. new THREE.FloatNode( 1 ),
  657. THREE.OperatorNode.ADD
  658. );
  659. var thetaPower = new THREE.Math2Node(
  660. theta,
  661. power,
  662. THREE.Math2Node.POW
  663. );
  664. var fresnel = new THREE.OperatorNode(
  665. reflectance,
  666. thetaPower,
  667. THREE.OperatorNode.MUL
  668. );
  669. mtl.color = new THREE.ColorNode( 0x3399FF );
  670. mtl.environment = color;
  671. mtl.environmentAlpha = new THREE.Math1Node( fresnel, THREE.Math1Node.SAT );
  672. // GUI
  673. addGui( 'reflectance', reflectance.number, function ( val ) {
  674. reflectance.number = val;
  675. }, false, 0, 3 );
  676. addGui( 'power', power.number, function ( val ) {
  677. power.number = val;
  678. }, false, 0, 5 );
  679. break;
  680. case 'layers':
  681. // MATERIAL
  682. mtl = new THREE.PhongNodeMaterial();
  683. var tex1 = new THREE.TextureNode( getTexture( "grass" ) );
  684. var tex2 = new THREE.TextureNode( getTexture( "brick" ) );
  685. var offset = new THREE.FloatNode( 0 );
  686. var scale = new THREE.FloatNode( 1 );
  687. var uv = new THREE.UVNode();
  688. var uvOffset = new THREE.OperatorNode(
  689. offset,
  690. uv,
  691. THREE.OperatorNode.ADD
  692. );
  693. var uvScale = new THREE.OperatorNode(
  694. uvOffset,
  695. scale,
  696. THREE.OperatorNode.MUL
  697. );
  698. var mask = new THREE.TextureNode( getTexture( "decalDiffuse" ), uvScale );
  699. var maskAlphaChannel = new THREE.SwitchNode( mask, 'w' );
  700. var blend = new THREE.Math3Node(
  701. tex1,
  702. tex2,
  703. maskAlphaChannel,
  704. THREE.Math3Node.MIX
  705. );
  706. mtl.color = blend;
  707. // GUI
  708. addGui( 'offset', offset.number, function ( val ) {
  709. offset.number = val;
  710. }, false, 0, 1 );
  711. addGui( 'scale', scale.number, function ( val ) {
  712. scale.number = val;
  713. }, false, 0, 10 );
  714. break;
  715. case 'saturation':
  716. // MATERIAL
  717. mtl = new THREE.StandardNodeMaterial();
  718. var tex = new THREE.TextureNode( getTexture( "brick" ) );
  719. var sat = new THREE.FloatNode( 0 );
  720. var satrgb = new THREE.FunctionNode( [
  721. "vec3 satrgb(vec3 rgb, float adjustment) {",
  722. //" const vec3 W = vec3(0.2125, 0.7154, 0.0721);", // LUMA
  723. " vec3 intensity = vec3(dot(rgb, LUMA));",
  724. " return mix(intensity, rgb, adjustment);",
  725. "}"
  726. ].join( "\n" ) );
  727. var saturation = new THREE.FunctionCallNode( satrgb );
  728. saturation.inputs.rgb = tex;
  729. saturation.inputs.adjustment = sat;
  730. // or try
  731. //saturation.inputs[0] = tex;
  732. //saturation.inputs[1] = sat;
  733. mtl.color = saturation;
  734. // GUI
  735. addGui( 'saturation', sat.number, function ( val ) {
  736. sat.number = val;
  737. }, false, 0, 2 );
  738. break;
  739. case 'top-bottom':
  740. // MATERIAL
  741. mtl = new THREE.PhongNodeMaterial();
  742. var top = new THREE.TextureNode( getTexture( "grass" ) );
  743. var bottom = new THREE.TextureNode( getTexture( "brick" ) );
  744. var normal = new THREE.NormalNode( THREE.NormalNode.WORLD );
  745. var normalY = new THREE.SwitchNode( normal, 'y' );
  746. var hard = new THREE.FloatNode( 9 );
  747. var offset = new THREE.FloatNode( - 2.5 );
  748. var hardClamp = new THREE.OperatorNode(
  749. normalY,
  750. hard,
  751. THREE.OperatorNode.MUL
  752. );
  753. var offsetClamp = new THREE.OperatorNode(
  754. hardClamp,
  755. offset,
  756. THREE.OperatorNode.ADD
  757. );
  758. var clamp0at1 = new THREE.Math1Node( offsetClamp, THREE.Math1Node.SAT );
  759. var blend = new THREE.Math3Node( top, bottom, clamp0at1, THREE.Math3Node.MIX );
  760. mtl.color = blend;
  761. // GUI
  762. addGui( 'hard', hard.number, function ( val ) {
  763. hard.number = val;
  764. }, false, 0, 20 );
  765. addGui( 'offset', offset.number, function ( val ) {
  766. offset.number = val;
  767. }, false, - 10, 10 );
  768. break;
  769. case 'displace':
  770. // MATERIAL
  771. mtl = new THREE.PhongNodeMaterial();
  772. var time = new THREE.TimerNode();
  773. var scale = new THREE.FloatNode( 2 );
  774. var speed = new THREE.FloatNode( .2 );
  775. var colorA = new THREE.ColorNode( 0xFFFFFF );
  776. var colorB = new THREE.ColorNode( 0x0054df );
  777. var uv = new THREE.UVNode();
  778. var timeScl = new THREE.OperatorNode(
  779. time,
  780. speed,
  781. THREE.OperatorNode.MUL
  782. );
  783. var displaceOffset = new THREE.OperatorNode(
  784. timeScl,
  785. uv,
  786. THREE.OperatorNode.ADD
  787. );
  788. var tex = new THREE.TextureNode( getTexture( "cloud" ), displaceOffset );
  789. var texArea = new THREE.SwitchNode( tex, 'w' );
  790. var displace = new THREE.OperatorNode(
  791. new THREE.NormalNode(),
  792. texArea,
  793. THREE.OperatorNode.MUL
  794. );
  795. var displaceScale = new THREE.OperatorNode(
  796. displace,
  797. scale,
  798. THREE.OperatorNode.MUL
  799. );
  800. var blend = new THREE.OperatorNode(
  801. new THREE.PositionNode(),
  802. displaceScale,
  803. THREE.OperatorNode.ADD
  804. );
  805. var color = new THREE.Math3Node(
  806. colorB,
  807. colorA,
  808. texArea,
  809. THREE.Math3Node.MIX
  810. );
  811. mtl.color = mtl.specular = new THREE.ColorNode( 0 );
  812. mtl.emissive = color;
  813. mtl.transform = blend;
  814. // GUI
  815. addGui( 'speed', speed.number, function ( val ) {
  816. speed.number = val;
  817. }, false, 0, 1 );
  818. addGui( 'scale', scale.number, function ( val ) {
  819. scale.number = val;
  820. }, false, 0, 10 );
  821. addGui( 'colorA', colorA.value.getHex(), function ( val ) {
  822. colorA.value.setHex( val );
  823. }, true );
  824. addGui( 'colorB', colorB.value.getHex(), function ( val ) {
  825. colorB.value.setHex( val );
  826. }, true );
  827. break;
  828. case 'smoke':
  829. // MATERIAL
  830. mtl = new THREE.PhongNodeMaterial();
  831. var time = new THREE.TimerNode();
  832. var uv = new THREE.UVNode();
  833. var timeSpeedA = new THREE.OperatorNode(
  834. time,
  835. new THREE.Vector2Node( 0.3, 0.1 ),
  836. THREE.OperatorNode.MUL
  837. );
  838. var timeSpeedB = new THREE.OperatorNode(
  839. time,
  840. new THREE.Vector2Node( 0.15, 0.4 ),
  841. THREE.OperatorNode.MUL
  842. );
  843. var uvOffsetA = new THREE.OperatorNode(
  844. timeSpeedA,
  845. uv,
  846. THREE.OperatorNode.ADD
  847. );
  848. var uvOffsetB = new THREE.OperatorNode(
  849. timeSpeedB,
  850. uv,
  851. THREE.OperatorNode.ADD
  852. );
  853. var cloudA = new THREE.TextureNode( getTexture( "cloud" ), uvOffsetA );
  854. var cloudB = new THREE.TextureNode( getTexture( "cloud" ), uvOffsetB );
  855. var clouds = new THREE.OperatorNode(
  856. cloudA,
  857. cloudB,
  858. THREE.OperatorNode.ADD
  859. );
  860. mtl.environment = new THREE.ColorNode( 0xFFFFFF );
  861. mtl.alpha = clouds;
  862. // GUI
  863. addGui( 'color', mtl.environment.value.getHex(), function ( val ) {
  864. mtl.environment.value.setHex( val );
  865. }, true );
  866. break;
  867. case 'camera-depth':
  868. // MATERIAL
  869. var colorA = new THREE.ColorNode( 0xFFFFFF );
  870. var colorB = new THREE.ColorNode( 0x0054df );
  871. var depth = new THREE.CameraNode( THREE.CameraNode.DEPTH );
  872. depth.near.number = 1;
  873. depth.far.number = 200;
  874. var colors = new THREE.Math3Node(
  875. colorB,
  876. colorA,
  877. depth,
  878. THREE.Math3Node.MIX
  879. );
  880. mtl = new THREE.PhongNodeMaterial();
  881. mtl.color = colors;
  882. // GUI
  883. addGui( 'near', depth.near.number, function ( val ) {
  884. depth.near.number = val;
  885. }, false, 1, 1200 );
  886. addGui( 'far', depth.far.number, function ( val ) {
  887. depth.far.number = val;
  888. }, false, 1, 1200 );
  889. addGui( 'nearColor', colorA.value.getHex(), function ( val ) {
  890. colorA.value.setHex( val );
  891. }, true );
  892. addGui( 'farColor', colorB.value.getHex(), function ( val ) {
  893. colorB.value.setHex( val );
  894. }, true );
  895. break;
  896. case 'caustic':
  897. // MATERIAL
  898. mtl = new THREE.StandardNodeMaterial();
  899. var hash2 = new THREE.FunctionNode( [
  900. "vec2 hash2(vec2 p) {",
  901. " return fract(sin(vec2(dot(p, vec2(123.4, 748.6)), dot(p, vec2(547.3, 659.3))))*5232.85324);",
  902. "}"
  903. ].join( "\n" ) );
  904. var voronoi = new THREE.FunctionNode( [
  905. // Based off of iq's described here: http://www.iquilezles.org/www/articles/voronoili
  906. "float voronoi(vec2 p, in float time) {",
  907. " vec2 n = floor(p);",
  908. " vec2 f = fract(p);",
  909. " float md = 5.0;",
  910. " vec2 m = vec2(0.0);",
  911. " for (int i = -1; i <= 1; i++) {",
  912. " for (int j = -1; j <= 1; j++) {",
  913. " vec2 g = vec2(i, j);",
  914. " vec2 o = hash2(n + g);",
  915. " o = 0.5 + 0.5 * sin(time + 5.038 * o);",
  916. " vec2 r = g + o - f;",
  917. " float d = dot(r, r);",
  918. " if (d < md) {",
  919. " md = d;",
  920. " m = n+g+o;",
  921. " }",
  922. " }",
  923. " }",
  924. " return md;",
  925. "}"
  926. ].join( "\n" ), [ hash2 ] ); // define hash2 as dependencies
  927. var voronoiLayers = new THREE.FunctionNode( [
  928. // based on https://www.shadertoy.com/view/4tXSDf
  929. "float voronoiLayers(vec2 p, in float time) {",
  930. " float v = 0.0;",
  931. " float a = 0.4;",
  932. " for (int i = 0; i < 3; i++) {",
  933. " v += voronoi(p, time) * a;",
  934. " p *= 2.0;",
  935. " a *= 0.5;",
  936. " }",
  937. " return v;",
  938. "}"
  939. ].join( "\n" ), [ voronoi ] ); // define voronoi as dependencies
  940. var time = new THREE.TimerNode();
  941. var timeScale = new THREE.FloatNode( 2 );
  942. var alpha = new THREE.FloatNode( 1 );
  943. var scale = new THREE.FloatNode( .1 );
  944. var intensity = new THREE.FloatNode( 1.5 );
  945. var color = new THREE.ColorNode( 0xFFFFFF );
  946. var colorA = new THREE.ColorNode( 0xFFFFFF );
  947. var colorB = new THREE.ColorNode( 0x0054df );
  948. var worldPos = new THREE.PositionNode( THREE.PositionNode.WORLD );
  949. var worldPosTop = new THREE.SwitchNode( worldPos, 'xz' );
  950. var worldNormal = new THREE.NormalNode( THREE.NormalNode.WORLD );
  951. var mask = new THREE.SwitchNode( worldNormal, 'y' );
  952. // clamp0at1
  953. mask = new THREE.Math1Node( mask, THREE.Math1Node.SAT );
  954. var timeOffset = new THREE.OperatorNode(
  955. time,
  956. timeScale,
  957. THREE.OperatorNode.MUL
  958. );
  959. var uvPos = new THREE.OperatorNode(
  960. worldPosTop,
  961. scale,
  962. THREE.OperatorNode.MUL
  963. );
  964. var voronoi = new THREE.FunctionCallNode( voronoiLayers );
  965. voronoi.inputs.p = uvPos;
  966. voronoi.inputs.time = timeOffset;
  967. var maskCaustic = new THREE.OperatorNode(
  968. alpha,
  969. mask,
  970. THREE.OperatorNode.MUL
  971. );
  972. var voronoiIntensity = new THREE.OperatorNode(
  973. voronoi,
  974. intensity,
  975. THREE.OperatorNode.MUL
  976. );
  977. var voronoiColors = new THREE.Math3Node(
  978. colorB,
  979. colorA,
  980. new THREE.Math1Node( voronoiIntensity, THREE.Math1Node.SAT ), // mix needs clamp
  981. THREE.Math3Node.MIX
  982. );
  983. var caustic = new THREE.Math3Node(
  984. color,
  985. voronoiColors,
  986. maskCaustic,
  987. THREE.Math3Node.MIX
  988. );
  989. var causticLights = new THREE.OperatorNode(
  990. voronoiIntensity,
  991. maskCaustic,
  992. THREE.OperatorNode.MUL
  993. );
  994. mtl.color = caustic;
  995. mtl.ambient = causticLights;
  996. // GUI
  997. addGui( 'timeScale', timeScale.number, function ( val ) {
  998. timeScale.number = val;
  999. }, false, 0, 5 );
  1000. addGui( 'intensity', intensity.number, function ( val ) {
  1001. intensity.number = val;
  1002. }, false, 0, 3 );
  1003. addGui( 'scale', scale.number, function ( val ) {
  1004. scale.number = val;
  1005. }, false, 0, 1 );
  1006. addGui( 'alpha', alpha.number, function ( val ) {
  1007. alpha.number = val;
  1008. }, false, 0, 1 );
  1009. addGui( 'color', color.value.getHex(), function ( val ) {
  1010. color.value.setHex( val );
  1011. }, true );
  1012. addGui( 'colorA', colorA.value.getHex(), function ( val ) {
  1013. colorA.value.setHex( val );
  1014. }, true );
  1015. addGui( 'colorB', colorB.value.getHex(), function ( val ) {
  1016. colorB.value.setHex( val );
  1017. }, true );
  1018. break;
  1019. case 'soft-body':
  1020. // MATERIAL
  1021. move = true;
  1022. mtl = new THREE.StandardNodeMaterial();
  1023. var scale = new THREE.FloatNode( 2 );
  1024. var colorA = new THREE.ColorNode( 0xFF6633 );
  1025. var colorB = new THREE.ColorNode( 0x3366FF );
  1026. var pos = new THREE.PositionNode();
  1027. var posNorm = new THREE.Math1Node( pos, THREE.Math1Node.NORMALIZE );
  1028. var mask = new THREE.SwitchNode( posNorm, 'y' );
  1029. var velocity = new THREE.VelocityNode( mesh, {
  1030. type: 'elastic',
  1031. spring: .95,
  1032. damping: .95
  1033. } );
  1034. var velocityArea = new THREE.OperatorNode(
  1035. mask,
  1036. scale,
  1037. THREE.OperatorNode.MUL
  1038. );
  1039. var softVelocity = new THREE.OperatorNode(
  1040. velocity,
  1041. velocityArea,
  1042. THREE.OperatorNode.MUL
  1043. );
  1044. var softPosition = new THREE.OperatorNode(
  1045. new THREE.PositionNode(),
  1046. softVelocity,
  1047. THREE.OperatorNode.ADD
  1048. );
  1049. var colors = new THREE.Math3Node(
  1050. colorB,
  1051. colorA,
  1052. mask,
  1053. THREE.Math3Node.MIX
  1054. );
  1055. mtl.color = colors;
  1056. mtl.transform = softPosition;
  1057. // GUI
  1058. addGui( 'spring', velocity.params.spring, function ( val ) {
  1059. velocity.params.spring = val;
  1060. }, false, 0, .95 );
  1061. addGui( 'damping', velocity.params.damping, function ( val ) {
  1062. velocity.params.damping = val;
  1063. }, false, 0, .95 );
  1064. addGui( 'scale', scale.number, function ( val ) {
  1065. scale.number = val;
  1066. }, false, 0, 3 );
  1067. addGui( 'softBody', colorA.value.getHex(), function ( val ) {
  1068. colorA.value.setHex( val );
  1069. }, true );
  1070. addGui( 'rigidBody', colorB.value.getHex(), function ( val ) {
  1071. colorB.value.setHex( val );
  1072. }, true );
  1073. break;
  1074. case 'plush':
  1075. // MATERIAL
  1076. mtl = new THREE.PhongNodeMaterial();
  1077. var color = new THREE.ColorNode( 0x8D8677 );
  1078. var mildness = new THREE.FloatNode( 1.6 );
  1079. var fur = new THREE.FloatNode( .5 );
  1080. var posDirection = new THREE.Math1Node( new THREE.PositionNode( THREE.PositionNode.VIEW ), THREE.Math1Node.NORMALIZE );
  1081. var norDirection = new THREE.Math1Node( new THREE.NormalNode( THREE.NormalNode.VIEW ), THREE.Math1Node.NORMALIZE );
  1082. var viewZ = new THREE.Math2Node(
  1083. posDirection,
  1084. norDirection,
  1085. THREE.Math2Node.DOT
  1086. );
  1087. // without luma correction for now
  1088. var mildnessColor = new THREE.OperatorNode(
  1089. color,
  1090. mildness,
  1091. THREE.OperatorNode.MUL
  1092. );
  1093. var furScale = new THREE.OperatorNode(
  1094. viewZ,
  1095. fur,
  1096. THREE.OperatorNode.MUL
  1097. );
  1098. mtl.color = color;
  1099. mtl.normal = new THREE.TextureNode( getTexture( "grassNormal" ) );
  1100. mtl.normalScale = furScale;
  1101. mtl.environment = mildnessColor;
  1102. mtl.environmentAlpha = new THREE.Math1Node( viewZ, THREE.Math1Node.INVERT );
  1103. mtl.shininess = new THREE.FloatNode( 0 );
  1104. // GUI
  1105. addGui( 'color', color.value.getHex(), function ( val ) {
  1106. color.value.setHex( val );
  1107. }, true );
  1108. addGui( 'mildness', mildness.number, function ( val ) {
  1109. mildness.number = val;
  1110. }, false, 1, 2 );
  1111. addGui( 'fur', fur.number, function ( val ) {
  1112. fur.number = val;
  1113. }, false, 0, 2 );
  1114. break;
  1115. case 'skin':
  1116. case 'skin-phong':
  1117. // MATERIAL
  1118. mtl = name == 'skin' ? new THREE.StandardNodeMaterial() : new THREE.PhongNodeMaterial();
  1119. var skinColor = new THREE.ColorNode( 0xFFC495 );
  1120. var bloodColor = new THREE.ColorNode( 0x6b0602 );
  1121. var wrapLight = new THREE.FloatNode( 1.5 );
  1122. var wrapShadow = new THREE.FloatNode( 0 );
  1123. var directLight = new THREE.LightNode();
  1124. var lightLuminance = new THREE.LuminanceNode( directLight );
  1125. var lightWrap = new THREE.Math3Node(
  1126. wrapShadow,
  1127. wrapLight,
  1128. lightLuminance,
  1129. THREE.Math3Node.SMOOTHSTEP
  1130. );
  1131. var lightTransition = new THREE.OperatorNode(
  1132. lightWrap,
  1133. new THREE.ConstNode( THREE.ConstNode.PI2 ),
  1134. THREE.OperatorNode.MUL
  1135. );
  1136. var wrappedLight = new THREE.Math1Node( lightTransition, THREE.Math1Node.SIN );
  1137. var wrappedLightColor = new THREE.OperatorNode(
  1138. wrappedLight,
  1139. bloodColor,
  1140. THREE.OperatorNode.MUL
  1141. );
  1142. var bloodArea = new THREE.Math1Node( wrappedLightColor, THREE.Math1Node.SAT );
  1143. var totalLight = new THREE.OperatorNode(
  1144. directLight,
  1145. bloodArea,
  1146. THREE.OperatorNode.ADD
  1147. );
  1148. mtl.color = skinColor;
  1149. mtl.light = totalLight;
  1150. if ( name == 'skin' ) {
  1151. // StandardNodeMaterial
  1152. mtl.metalness = new THREE.FloatNode( 0 );
  1153. mtl.roughness = new THREE.FloatNode( 1 );
  1154. mtl.reflectivity = new THREE.FloatNode( 0 );
  1155. mtl.clearCoat = new THREE.FloatNode( .2 );
  1156. mtl.clearCoatRoughness = new THREE.FloatNode( .3 );
  1157. mtl.environment = new THREE.CubeTextureNode( cubemap );
  1158. } else {
  1159. // PhongNodeMaterial
  1160. mtl.specular = new THREE.ColorNode( 0x2f2e2d );
  1161. mtl.shininess = new THREE.FloatNode( 15 );
  1162. }
  1163. // GUI
  1164. addGui( 'skinColor', skinColor.value.getHex(), function ( val ) {
  1165. skinColor.value.setHex( val );
  1166. }, true );
  1167. addGui( 'bloodColor', bloodColor.value.getHex(), function ( val ) {
  1168. bloodColor.value.setHex( val );
  1169. }, true );
  1170. addGui( 'wrapLight', wrapLight.number, function ( val ) {
  1171. wrapLight.number = val;
  1172. }, false, 0, 3 );
  1173. addGui( 'wrapShadow', wrapShadow.number, function ( val ) {
  1174. wrapShadow.number = val;
  1175. }, false, - 1, 0 );
  1176. break;
  1177. case 'toon':
  1178. // MATERIAL
  1179. mtl = new THREE.PhongNodeMaterial();
  1180. var count = new THREE.FloatNode( 3.43 );
  1181. var sceneDirectLight = new THREE.LightNode();
  1182. var color = new THREE.ColorNode( 0xAABBFF );
  1183. var lineColor = new THREE.ColorNode( 0xFF0000 );
  1184. var lineSize = new THREE.FloatNode( 0.23 );
  1185. var lineInner = new THREE.FloatNode( 0 );
  1186. // CEL
  1187. var lightLuminance = new THREE.LuminanceNode( sceneDirectLight );
  1188. var preCelLight = new THREE.OperatorNode(
  1189. lightLuminance,
  1190. count,
  1191. THREE.OperatorNode.MUL
  1192. );
  1193. var celLight = new THREE.Math1Node(
  1194. preCelLight,
  1195. THREE.Math1Node.CEIL
  1196. );
  1197. var posCelLight = new THREE.OperatorNode(
  1198. celLight,
  1199. count,
  1200. THREE.OperatorNode.DIV
  1201. );
  1202. // LINE
  1203. var posDirection = new THREE.Math1Node( new THREE.PositionNode( THREE.PositionNode.VIEW ), THREE.Math1Node.NORMALIZE );
  1204. var norDirection = new THREE.Math1Node( new THREE.NormalNode( THREE.NormalNode.VIEW ), THREE.Math1Node.NORMALIZE );
  1205. var viewZ = new THREE.Math2Node(
  1206. posDirection,
  1207. norDirection,
  1208. THREE.Math2Node.DOT
  1209. );
  1210. var lineOutside = new THREE.Math1Node(
  1211. viewZ,
  1212. THREE.Math1Node.ABS
  1213. );
  1214. var line = new THREE.OperatorNode(
  1215. lineOutside,
  1216. new THREE.FloatNode( 1 ),
  1217. THREE.OperatorNode.DIV
  1218. );
  1219. var lineScaled = new THREE.Math3Node(
  1220. line,
  1221. lineSize,
  1222. lineInner,
  1223. THREE.Math3Node.SMOOTHSTEP
  1224. );
  1225. var innerContour = new THREE.Math1Node( new THREE.Math1Node( lineScaled, THREE.Math1Node.SAT ), THREE.Math1Node.INVERT );
  1226. // APPLY
  1227. mtl.color = color;
  1228. mtl.light = posCelLight;
  1229. mtl.shininess = new THREE.FloatNode( 0 );
  1230. mtl.environment = lineColor;
  1231. mtl.environmentAlpha = innerContour;
  1232. // GUI
  1233. addGui( 'color', color.value.getHex(), function ( val ) {
  1234. color.value.setHex( val );
  1235. }, true );
  1236. addGui( 'lineColor', lineColor.value.getHex(), function ( val ) {
  1237. lineColor.value.setHex( val );
  1238. }, true );
  1239. addGui( 'count', count.number, function ( val ) {
  1240. count.number = val;
  1241. }, false, 1, 8 );
  1242. addGui( 'lineSize', lineSize.number, function ( val ) {
  1243. lineSize.number = val;
  1244. }, false, 0, 1 );
  1245. addGui( 'lineInner', lineInner.number, function ( val ) {
  1246. lineInner.number = val;
  1247. }, false, 0, 1 );
  1248. addGui( 'ignoreIndirectLight', false, function ( val ) {
  1249. mtl.ao = val ? new THREE.FloatNode() : undefined;
  1250. mtl.build();
  1251. } );
  1252. break;
  1253. case 'custom-attribute':
  1254. // GEOMETRY
  1255. // add "position" buffer to "custom" attribute
  1256. teapot.attributes[ 'custom' ] = teapot.attributes[ 'position' ];
  1257. // MATERIAL
  1258. mtl = new THREE.PhongNodeMaterial();
  1259. mtl.color = new THREE.AttributeNode( "custom", 3 );
  1260. // or
  1261. //mtl.color = new THREE.AttributeNode( "custom", "vec3" );
  1262. break;
  1263. case 'expression':
  1264. // MATERIAL
  1265. mtl = new THREE.PhongNodeMaterial();
  1266. var speed = new THREE.FloatNode( .5 );
  1267. mtl.color = new THREE.FunctionNode( "myCustomUv + (sin(time*speed)*.5) + (position * .05)", "vec3" );
  1268. mtl.color.keywords[ "speed" ] = speed;
  1269. mtl.transform = new THREE.FunctionNode( "mod(time*speed,1.0) < 0.5 ? position + (worldNormal*(1.0+sin(time*speed*1.0))*3.0) : position + sin( position.x * sin(time*speed*2.0))", "vec3" );
  1270. mtl.transform.keywords[ "speed" ] = speed;
  1271. // add global keyword ( variable or const )
  1272. THREE.NodeLib.addKeyword( 'myCustomUv', function ( builder ) {
  1273. return new THREE.ReflectNode();
  1274. } );
  1275. // GUI
  1276. addGui( 'speed', speed.number, function ( val ) {
  1277. speed.number = val;
  1278. }, false, 0, 1 );
  1279. break;
  1280. case 'reserved-keywords':
  1281. // MATERIAL
  1282. mtl = new THREE.PhongNodeMaterial();
  1283. var keywordsexample = new THREE.FunctionNode( [
  1284. // use "uv" reserved keyword
  1285. "vec4 keywordsexample( sampler2D texture ) {",
  1286. " return texture2D( texture, myUV ) + vec4( position * myAlpha, 0.0 );",
  1287. "}"
  1288. ].join( "\n" ) );
  1289. // add local keyword ( const only )
  1290. keywordsexample.keywords[ "myAlpha" ] = new THREE.ConstNode( "float myAlpha .05" );
  1291. // add global keyword ( const only )
  1292. THREE.NodeLib.addKeyword( 'myUV', function ( builder ) {
  1293. return new THREE.UVNode();
  1294. } );
  1295. // add global const or function
  1296. //THREE.NodeLib.add( new THREE.ConstNode("float MY_CONST .05") )
  1297. // reserved keywords
  1298. console.log( THREE.NodeLib.keywords );
  1299. // keywords conflit? use this to disable:
  1300. //blurtexture.useKeywords = false; // ( true is default )
  1301. mtl.color = new THREE.FunctionCallNode( keywordsexample, [ new THREE.TextureNode( getTexture( "brick" ) ) ] );
  1302. break;
  1303. case 'varying':
  1304. // MATERIAL
  1305. mtl = new THREE.PhongNodeMaterial();
  1306. var varying = new THREE.VarNode( "vec3" );
  1307. var setMyVar = new THREE.FunctionNode( [
  1308. "float setMyVar( vec3 pos ) {",
  1309. // set "myVar" in vertex shader in this example,
  1310. // can be used in fragment shader too or in rest of the current shader
  1311. " myVar = pos;",
  1312. // it is not accept "void" functions for now!
  1313. " return 0.;",
  1314. "}"
  1315. ].join( "\n" ) );
  1316. // add keyword
  1317. setMyVar.keywords[ "myVar" ] = varying;
  1318. var transform = new THREE.FunctionNode( "setMyVar( position * .1 ) + position", "vec3", [ setMyVar ] );
  1319. transform.keywords[ "tex" ] = new THREE.TextureNode( getTexture( "brick" ) );
  1320. mtl.transform = transform;
  1321. mtl.color = varying;
  1322. break;
  1323. case 'triangle-blur':
  1324. // MATERIAL
  1325. mtl = new THREE.PhongNodeMaterial();
  1326. var delta = new THREE.Vector2Node( .5, .25 );
  1327. var alpha = new THREE.FloatNode( 1 );
  1328. var blurtexture = new THREE.FunctionNode( [
  1329. // Reference: TriangleBlurShader.js
  1330. "vec4 blurtexture(sampler2D texture, vec2 uv, vec2 delta) {",
  1331. " vec4 color = vec4( 0.0 );",
  1332. " float total = 0.0;",
  1333. // randomize the lookup values to hide the fixed number of samples
  1334. " float offset = rand( uv );",
  1335. " for ( float t = -BLUR_ITERATIONS; t <= BLUR_ITERATIONS; t ++ ) {",
  1336. " float percent = ( t + offset - 0.5 ) / BLUR_ITERATIONS;",
  1337. " float weight = 1.0 - abs( percent );",
  1338. " color += texture2D( texture, uv + delta * percent ) * weight;",
  1339. " total += weight;",
  1340. " }",
  1341. " return color / total;",
  1342. "}"
  1343. ].join( "\n" ), [ new THREE.ConstNode( "float BLUR_ITERATIONS 10.0" ) ] );
  1344. var blurredTexture = new THREE.FunctionCallNode( blurtexture, {
  1345. texture: new THREE.TextureNode( getTexture( "brick" ) ),
  1346. delta: delta,
  1347. uv: new THREE.UVNode()
  1348. } );
  1349. var color = new THREE.Math3Node(
  1350. new THREE.TextureNode( getTexture( "brick" ) ),
  1351. blurredTexture,
  1352. alpha,
  1353. THREE.Math3Node.MIX
  1354. );
  1355. mtl.color = color;
  1356. // GUI
  1357. addGui( 'alpha', alpha.number, function ( val ) {
  1358. alpha.number = val;
  1359. }, false, 0, 1 );
  1360. addGui( 'deltaX', delta.x, function ( val ) {
  1361. delta.x = val;
  1362. }, false, 0, 1 );
  1363. addGui( 'deltaY', delta.x, function ( val ) {
  1364. delta.y = val;
  1365. }, false, 0, 1 );
  1366. break;
  1367. case 'firefly':
  1368. // MATERIAL
  1369. mtl = new THREE.PhongNodeMaterial();
  1370. var time = new THREE.TimerNode();
  1371. var speed = new THREE.FloatNode( .5 );
  1372. var color = new THREE.ColorNode( 0x98ff00 );
  1373. var timeSpeed = new THREE.OperatorNode(
  1374. time,
  1375. speed,
  1376. THREE.OperatorNode.MUL
  1377. );
  1378. var sinCycleInSecs = new THREE.OperatorNode(
  1379. timeSpeed,
  1380. new THREE.ConstNode( THREE.ConstNode.PI2 ),
  1381. THREE.OperatorNode.MUL
  1382. );
  1383. var cycle = new THREE.Math1Node( sinCycleInSecs, THREE.Math1Node.SIN );
  1384. var cycleColor = new THREE.OperatorNode(
  1385. cycle,
  1386. color,
  1387. THREE.OperatorNode.MUL
  1388. );
  1389. var cos = new THREE.Math1Node( cycleColor, THREE.Math1Node.SIN );
  1390. mtl.color = new THREE.ColorNode( 0 );
  1391. mtl.emissive = cos;
  1392. // GUI
  1393. addGui( 'speed', speed.number, function ( val ) {
  1394. speed.number = val;
  1395. }, false, 0, 3 );
  1396. break;
  1397. case 'sss':
  1398. case 'translucent':
  1399. // DISTANCE FORMULA
  1400. var modelPos = new THREE.Vector3Node();
  1401. var viewPos = new THREE.PositionNode( THREE.PositionNode.VIEW );
  1402. var cameraPosition = new THREE.CameraNode( THREE.CameraNode.POSITION );
  1403. var cameraDistance = new THREE.Math2Node(
  1404. modelPos,
  1405. cameraPosition,
  1406. THREE.Math2Node.DISTANCE
  1407. );
  1408. var viewPosZ = new THREE.SwitchNode( viewPos, 'z' );
  1409. var distance = new THREE.OperatorNode(
  1410. cameraDistance,
  1411. viewPosZ,
  1412. THREE.OperatorNode.SUB
  1413. );
  1414. var distanceRadius = new THREE.OperatorNode(
  1415. distance,
  1416. new THREE.FloatNode( 70 ),
  1417. THREE.OperatorNode.ADD
  1418. );
  1419. var objectDepth = new THREE.Math3Node(
  1420. distanceRadius,
  1421. new THREE.FloatNode( 0 ),
  1422. new THREE.FloatNode( 50 ),
  1423. THREE.Math3Node.SMOOTHSTEP
  1424. );
  1425. // RTT ( get back distance )
  1426. rtTexture = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBFormat } );
  1427. var distanceMtl = new THREE.PhongNodeMaterial();
  1428. distanceMtl.environment = objectDepth;
  1429. distanceMtl.side = THREE.BackSide;
  1430. distanceMtl.build();
  1431. rtMaterial = distanceMtl;
  1432. // MATERIAL
  1433. mtl = new THREE.StandardNodeMaterial();
  1434. var backSideDepth = new THREE.TextureNode( rtTexture, new THREE.ScreenUVNode( new THREE.ResolutionNode( renderer ) ) );
  1435. var difference = new THREE.OperatorNode(
  1436. objectDepth,
  1437. backSideDepth,
  1438. THREE.OperatorNode.SUB
  1439. );
  1440. var sss = new THREE.Math3Node(
  1441. new THREE.FloatNode( - .1 ),
  1442. new THREE.FloatNode( .5 ),
  1443. difference,
  1444. THREE.Math3Node.SMOOTHSTEP
  1445. );
  1446. var sssAlpha = new THREE.Math1Node( sss, THREE.Math1Node.SAT );
  1447. var frontColor, backColor;
  1448. if ( name == 'sss' ) {
  1449. var sssOut = new THREE.Math2Node(
  1450. objectDepth,
  1451. sssAlpha,
  1452. THREE.Math2Node.MIN
  1453. );
  1454. frontColor = new THREE.ColorNode( 0xd4cfbb );
  1455. backColor = new THREE.ColorNode( 0xd04327 );
  1456. var color = new THREE.Math3Node(
  1457. backColor,
  1458. frontColor,
  1459. sssOut,
  1460. THREE.Math3Node.MIX
  1461. );
  1462. var light = new THREE.OperatorNode(
  1463. new THREE.LightNode(),
  1464. color,
  1465. THREE.OperatorNode.ADD
  1466. );
  1467. mtl.color = frontColor;
  1468. mtl.roughness = new THREE.FloatNode( .1 );
  1469. mtl.metalness = new THREE.FloatNode( .5 );
  1470. mtl.light = light;
  1471. mtl.environment = color;
  1472. } else {
  1473. frontColor = new THREE.ColorNode( 0xd04327 );
  1474. backColor = new THREE.ColorNode( 0x1a0e14 );
  1475. var color = new THREE.Math3Node(
  1476. frontColor,
  1477. backColor,
  1478. sssAlpha,
  1479. THREE.Math3Node.MIX
  1480. );
  1481. var light = new THREE.OperatorNode(
  1482. new THREE.LightNode(),
  1483. color,
  1484. THREE.OperatorNode.ADD
  1485. );
  1486. mtl.color = new THREE.ColorNode( 0xffffff );
  1487. mtl.roughness = new THREE.FloatNode( .1 );
  1488. mtl.metalness = new THREE.FloatNode( .5 );
  1489. mtl.light = light;
  1490. mtl.environment = color;
  1491. }
  1492. // GUI
  1493. addGui( 'frontColor', frontColor.value.getHex(), function ( val ) {
  1494. frontColor.value.setHex( val );
  1495. }, true );
  1496. addGui( 'backColor', backColor.value.getHex(), function ( val ) {
  1497. backColor.value.setHex( val );
  1498. }, true );
  1499. addGui( 'area', sss.b.number, function ( val ) {
  1500. sss.b.number = val;
  1501. }, false, 0, 1 );
  1502. break;
  1503. }
  1504. // build shader
  1505. mtl.build();
  1506. // set material
  1507. mesh.material = mtl;
  1508. }
  1509. function onWindowResize() {
  1510. var width = window.innerWidth, height = window.innerHeight;
  1511. camera.aspect = width / height;
  1512. camera.updateProjectionMatrix();
  1513. renderer.setSize( width, height );
  1514. if ( rtTexture ) rtTexture.setSize( width, height );
  1515. }
  1516. function animate() {
  1517. var delta = clock.getDelta();
  1518. if ( move ) {
  1519. var time = Date.now() * 0.005;
  1520. mesh.position.z = Math.cos( time ) * 10;
  1521. mesh.position.y = Math.sin( time ) * 10;
  1522. } else {
  1523. mesh.position.z = mesh.position.y = 0;
  1524. }
  1525. //mesh.rotation.z += .01;
  1526. // update material animation and/or gpu calcs (pre-renderer)
  1527. mesh.material.updateFrame( delta );
  1528. // render to texture for sss/translucent material only
  1529. if ( rtTexture ) {
  1530. scene.overrideMaterial = rtMaterial;
  1531. renderer.render( scene, camera, rtTexture, true );
  1532. scene.overrideMaterial = null;
  1533. }
  1534. renderer.render( scene, camera );
  1535. requestAnimationFrame( animate );
  1536. }
  1537. </script>
  1538. </body>
  1539. </html>