SlideShare une entreprise Scribd logo
1  sur  14
THREE.JS
GFX2014 ADVANCED GRAPHICS WORKSHOP
MARCH 2014
BANGALORE
2014
WHAT IS THREE.JS ?
 A rendering library for rendering 3D, 2D objects – using Javascript
 Encapsulates all GL functionality discussed till now, in an easily usable API
 Employs a scenegraph concept
 Parent-child node relationships
GFX2014 Advanced Graphics Workshop, Bangalore
Canvas
WebGL
Three.js
OpenGL
ES2.0
Mesh
Material
ImageUtils
Camera
Scene
2014
DRAWING WITH THREE.JS
 Drawing with Three.js consists of creating
 A renderer
 A camera
 A scene that contains many objects (meshes, materials,
lights, textures) and groups of objects
2014
RENDERERS
 Two types of renderers
 GPU based OpenGL (WebGL) renderer
 THREE.WebGLRenderer( context3dStore );
 Canvas based 2D renderer fallback
 THREE.CanvasRenderer( { canvas: theCanvas } );
2014
THREE.JS - PROGRAMMING FLOW
 scene = new THREE.Scene();
 camera = new THREE.PerspectiveCamera( fieldOfViewAngle, aspect,
near, far );
 renderer = new THREE.WebGLRenderer( { canvas: theCanvas,
antialias: true } );
 scene.add(triangle);
 renderer.render( scene, camera );
2014
IMPORTANT APIS
 Lighting
 var light = new THREE.DirectionalLight( 0xffffff );
 Add the light to the scene just like any other object Scene.add(light);
 Objects
 Shape
 var heartShape = new THREE.Shape();
 heartShape.moveTo( x + 25, y + 25 );
 Geometry
 CubeGeometry
 PlaneGeometry
 SphereGeometry
 TorusGeometry
 IcosahedronGeometry
2014
IMPORTANT APIS (CONTD)
 Materials
 MeshBasicMaterial (plain color)
 MeshLambertMaterial (lighting associated)
 MeshPhongMaterial (lighting associated)
 Associated with a mesh, along with Geometry
 new THREE.Mesh( tubeGeom, redMat );
2014
BLENDING WITH THREE.JS
 Specify the blending property of material
 THREE.NormalBlending (default)
 THREE.NoBlending
 Example
 var material = new THREE.MeshBasicMaterial({ color: 0x0000ff, transparent: true,
opacity: .5, blending: THREE.NoBlending });
2014
SPECIFYING TEXTURES
 Load from source
 THREE.ImageUtils.loadTexture( sourceURL);
 Other properties of texture
 texture.wrapT (THREE.RepeatWrapping)
 texture.wrapS (THREE.ClampToEdgeWrapping)
 texture.repeat
 texture.offset
2014
OFFSCREEN RENDERING WITH THREE.JS
GFX2014 Advanced Graphics Workshop, Bangalore 10
DOING IT WITH GLES2 (CAVEMAN STYLE)
 //Bind offscreen texture
 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
 GL_CHECK(glBindTexture(GL_TEXTURE_2D, fboTextureId[i]));
 GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
inTextureWidth, inTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL));
 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_LINEAR));
 GL_CHECK(glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_LINEAR));
 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fboId[i]));
 GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTextureId[i], 0));
 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
GL_FRAMEBUFFER_COMPLETE)
 {
 printf("FB is not complete for rendering offscreenn");
 goto err;
 }
Taken from
https://gist.github.com/prabindh/8173489
Captain Caveman © Hanna-Barbera
2014
WITH THREE.JS (MODERN STYLE)
 Create
 rtTexture = new THREE.WebGLRenderTarget( window.innerWidth,
window.innerHeight, ..);
 Create screen, material, and mesh
 mtlScreen = new THREE.ShaderMaterial( { uniforms: { tDiffuse: { type:
"t", value: rtTexture } },
 mtl = new THREE.MeshBasicMaterial( { map: rtTexture } );
 mesh = new THREE.Mesh( plane, function(rtTexture) );
 scene.add( mesh );
 Use
 renderer.render( sceneRTT, cameraRTT, rtTexture, ..);
 renderer.render( scene, camera );
To offscreen
To display screen
2014
THREE.JS RENDERTARGET OBJECT
 WebGLRenderTarget
 Usage sample:
 rtTexture = new THREE.WebGLRenderTarget( width, height, { minFilter:
THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBFormat } );
2014
PASSING SHADERS FOR MATERIALS
 var myMaterial = new THREE.ShaderMaterial({
 uniforms: uniforms,
 vertexShader: document.getElementById( ‘myvertexsh' ).textContent,
 fragmentShader: document.getElementById( ‘myfragsh' ).textContent
 });
 Note that “projectionMatrix” and “modelViewMatrix” are provided automatically
by three.js in the vertex shader so no need to pass on the data
GFX2014 Advanced Graphics Workshop, Bangalore 14

Contenu connexe

Tendances

Tendances (20)

Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to Vulkan
 
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESGFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL
 
GFX Part 6 - Introduction to Vertex and Fragment Shaders in OpenGL ES
GFX Part 6 - Introduction to Vertex and Fragment Shaders in OpenGL ESGFX Part 6 - Introduction to Vertex and Fragment Shaders in OpenGL ES
GFX Part 6 - Introduction to Vertex and Fragment Shaders in OpenGL ES
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "
 
CG mini project
CG mini projectCG mini project
CG mini project
 
Sig13 ce future_gfx
Sig13 ce future_gfxSig13 ce future_gfx
Sig13 ce future_gfx
 
OpenGL 4 for 2010
OpenGL 4 for 2010OpenGL 4 for 2010
OpenGL 4 for 2010
 
Computer Graphics Project on Sinking Ship using OpenGL
Computer Graphics Project on Sinking Ship using OpenGLComputer Graphics Project on Sinking Ship using OpenGL
Computer Graphics Project on Sinking Ship using OpenGL
 
Avoiding 19 Common OpenGL Pitfalls
Avoiding 19 Common OpenGL PitfallsAvoiding 19 Common OpenGL Pitfalls
Avoiding 19 Common OpenGL Pitfalls
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
Computer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithmComputer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithm
 
CS 354 Introduction
CS 354 IntroductionCS 354 Introduction
CS 354 Introduction
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
bhargav_flowing-fountain
bhargav_flowing-fountainbhargav_flowing-fountain
bhargav_flowing-fountain
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUs
 
NVIDIA CUDA
NVIDIA CUDANVIDIA CUDA
NVIDIA CUDA
 

Similaire à GFX part 8 - Three.js introduction and usage

Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
Chihoon Byun
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
JavaScript Meetup HCMC
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
gerbille
 

Similaire à GFX part 8 - Three.js introduction and usage (20)

Intro to Three.js
Intro to Three.jsIntro to Three.js
Intro to Three.js
 
140716 : 同業前端聚會分享 - webgl 與 three.js
140716 : 同業前端聚會分享 - webgl 與 three.js140716 : 同業前端聚會分享 - webgl 與 three.js
140716 : 同業前端聚會分享 - webgl 與 three.js
 
Deep dive into deeplearn.js
Deep dive into deeplearn.jsDeep dive into deeplearn.js
Deep dive into deeplearn.js
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
 
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony ParisiWT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
 
WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics
 
Render to Texture with Three.js
Render to Texture with Three.jsRender to Texture with Three.js
Render to Texture with Three.js
 
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
 
WebGL and three.js
WebGL and three.jsWebGL and three.js
WebGL and three.js
 
WebGL - 3D programming
WebGL - 3D programmingWebGL - 3D programming
WebGL - 3D programming
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
 
WebGL - It's GO Time
WebGL - It's GO TimeWebGL - It's GO Time
WebGL - It's GO Time
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGL
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196
 
Migrating your Web app to Virtual Reality
Migrating your Web app to Virtual RealityMigrating your Web app to Virtual Reality
Migrating your Web app to Virtual Reality
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Opengl texturing
Opengl texturingOpengl texturing
Opengl texturing
 
Bs webgl소모임004
Bs webgl소모임004Bs webgl소모임004
Bs webgl소모임004
 

Plus de Prabindh Sundareson

Plus de Prabindh Sundareson (20)

Synthetic Data and Graphics Techniques in Robotics
Synthetic Data and Graphics Techniques in RoboticsSynthetic Data and Graphics Techniques in Robotics
Synthetic Data and Graphics Techniques in Robotics
 
Work and Life
Work and Life Work and Life
Work and Life
 
GPU Algorithms and trends 2018
GPU Algorithms and trends 2018GPU Algorithms and trends 2018
GPU Algorithms and trends 2018
 
Machine learning in the Indian Context - IEEE talk at SRM Institute
Machine learning in the Indian Context - IEEE talk at SRM InstituteMachine learning in the Indian Context - IEEE talk at SRM Institute
Machine learning in the Indian Context - IEEE talk at SRM Institute
 
Students Hackathon - 2017
Students Hackathon - 2017Students Hackathon - 2017
Students Hackathon - 2017
 
ICCE Asia 2017 - Program Outline
ICCE Asia 2017 - Program OutlineICCE Asia 2017 - Program Outline
ICCE Asia 2017 - Program Outline
 
Call for Papers - ICCE Asia 2017
Call for Papers - ICCE Asia 2017Call for Papers - ICCE Asia 2017
Call for Papers - ICCE Asia 2017
 
Technology, Innovation - A Perspective
Technology, Innovation - A PerspectiveTechnology, Innovation - A Perspective
Technology, Innovation - A Perspective
 
Open Shading Language (OSL)
Open Shading Language (OSL)Open Shading Language (OSL)
Open Shading Language (OSL)
 
IEEE - Consumer Electronics Trends Opportunities (2015)
IEEE - Consumer Electronics Trends Opportunities (2015)IEEE - Consumer Electronics Trends Opportunities (2015)
IEEE - Consumer Electronics Trends Opportunities (2015)
 
John Carmack talk at SMU, April 2014 - Virtual Reality
John Carmack talk at SMU, April 2014 - Virtual RealityJohn Carmack talk at SMU, April 2014 - Virtual Reality
John Carmack talk at SMU, April 2014 - Virtual Reality
 
GFX2014 OpenGL ES Quiz
GFX2014 OpenGL ES QuizGFX2014 OpenGL ES Quiz
GFX2014 OpenGL ES Quiz
 
Gfx2014 Graphics Workshop - Lab manual
Gfx2014 Graphics Workshop - Lab manualGfx2014 Graphics Workshop - Lab manual
Gfx2014 Graphics Workshop - Lab manual
 
ANGLE on Windows for OpenGLES2.0
ANGLE on Windows for OpenGLES2.0ANGLE on Windows for OpenGLES2.0
ANGLE on Windows for OpenGLES2.0
 
Yocto usage for Graphics SDK on AM335x
Yocto usage for Graphics SDK on AM335xYocto usage for Graphics SDK on AM335x
Yocto usage for Graphics SDK on AM335x
 
Gfx2013 lab manual
Gfx2013 lab manualGfx2013 lab manual
Gfx2013 lab manual
 
ARM Linux Embedded memory protection techniques
ARM Linux Embedded memory protection techniquesARM Linux Embedded memory protection techniques
ARM Linux Embedded memory protection techniques
 
Qt5 (minimal) on beaglebone, with Yocto
Qt5 (minimal) on beaglebone, with YoctoQt5 (minimal) on beaglebone, with Yocto
Qt5 (minimal) on beaglebone, with Yocto
 
Moksha - HTML5/CSS with Qt5+Snowshoe on AM335x
Moksha - HTML5/CSS with Qt5+Snowshoe on AM335xMoksha - HTML5/CSS with Qt5+Snowshoe on AM335x
Moksha - HTML5/CSS with Qt5+Snowshoe on AM335x
 
Qt5.0.0 eglfs abort issue
Qt5.0.0 eglfs abort issueQt5.0.0 eglfs abort issue
Qt5.0.0 eglfs abort issue
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

GFX part 8 - Three.js introduction and usage

  • 1. THREE.JS GFX2014 ADVANCED GRAPHICS WORKSHOP MARCH 2014 BANGALORE
  • 2. 2014 WHAT IS THREE.JS ?  A rendering library for rendering 3D, 2D objects – using Javascript  Encapsulates all GL functionality discussed till now, in an easily usable API  Employs a scenegraph concept  Parent-child node relationships GFX2014 Advanced Graphics Workshop, Bangalore Canvas WebGL Three.js OpenGL ES2.0 Mesh Material ImageUtils Camera Scene
  • 3. 2014 DRAWING WITH THREE.JS  Drawing with Three.js consists of creating  A renderer  A camera  A scene that contains many objects (meshes, materials, lights, textures) and groups of objects
  • 4. 2014 RENDERERS  Two types of renderers  GPU based OpenGL (WebGL) renderer  THREE.WebGLRenderer( context3dStore );  Canvas based 2D renderer fallback  THREE.CanvasRenderer( { canvas: theCanvas } );
  • 5. 2014 THREE.JS - PROGRAMMING FLOW  scene = new THREE.Scene();  camera = new THREE.PerspectiveCamera( fieldOfViewAngle, aspect, near, far );  renderer = new THREE.WebGLRenderer( { canvas: theCanvas, antialias: true } );  scene.add(triangle);  renderer.render( scene, camera );
  • 6. 2014 IMPORTANT APIS  Lighting  var light = new THREE.DirectionalLight( 0xffffff );  Add the light to the scene just like any other object Scene.add(light);  Objects  Shape  var heartShape = new THREE.Shape();  heartShape.moveTo( x + 25, y + 25 );  Geometry  CubeGeometry  PlaneGeometry  SphereGeometry  TorusGeometry  IcosahedronGeometry
  • 7. 2014 IMPORTANT APIS (CONTD)  Materials  MeshBasicMaterial (plain color)  MeshLambertMaterial (lighting associated)  MeshPhongMaterial (lighting associated)  Associated with a mesh, along with Geometry  new THREE.Mesh( tubeGeom, redMat );
  • 8. 2014 BLENDING WITH THREE.JS  Specify the blending property of material  THREE.NormalBlending (default)  THREE.NoBlending  Example  var material = new THREE.MeshBasicMaterial({ color: 0x0000ff, transparent: true, opacity: .5, blending: THREE.NoBlending });
  • 9. 2014 SPECIFYING TEXTURES  Load from source  THREE.ImageUtils.loadTexture( sourceURL);  Other properties of texture  texture.wrapT (THREE.RepeatWrapping)  texture.wrapS (THREE.ClampToEdgeWrapping)  texture.repeat  texture.offset
  • 10. 2014 OFFSCREEN RENDERING WITH THREE.JS GFX2014 Advanced Graphics Workshop, Bangalore 10
  • 11. DOING IT WITH GLES2 (CAVEMAN STYLE)  //Bind offscreen texture  GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));  GL_CHECK(glBindTexture(GL_TEXTURE_2D, fboTextureId[i]));  GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, inTextureWidth, inTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));  GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));  GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));  GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fboId[i]));  GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTextureId[i], 0));  if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)  {  printf("FB is not complete for rendering offscreenn");  goto err;  } Taken from https://gist.github.com/prabindh/8173489 Captain Caveman © Hanna-Barbera
  • 12. 2014 WITH THREE.JS (MODERN STYLE)  Create  rtTexture = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, ..);  Create screen, material, and mesh  mtlScreen = new THREE.ShaderMaterial( { uniforms: { tDiffuse: { type: "t", value: rtTexture } },  mtl = new THREE.MeshBasicMaterial( { map: rtTexture } );  mesh = new THREE.Mesh( plane, function(rtTexture) );  scene.add( mesh );  Use  renderer.render( sceneRTT, cameraRTT, rtTexture, ..);  renderer.render( scene, camera ); To offscreen To display screen
  • 13. 2014 THREE.JS RENDERTARGET OBJECT  WebGLRenderTarget  Usage sample:  rtTexture = new THREE.WebGLRenderTarget( width, height, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBFormat } );
  • 14. 2014 PASSING SHADERS FOR MATERIALS  var myMaterial = new THREE.ShaderMaterial({  uniforms: uniforms,  vertexShader: document.getElementById( ‘myvertexsh' ).textContent,  fragmentShader: document.getElementById( ‘myfragsh' ).textContent  });  Note that “projectionMatrix” and “modelViewMatrix” are provided automatically by three.js in the vertex shader so no need to pass on the data GFX2014 Advanced Graphics Workshop, Bangalore 14