[3JS] WebGL & Three.js

Chenยท2024๋…„ 5์›” 23์ผ

Three.js

๋ชฉ๋ก ๋ณด๊ธฐ
1/4
post-thumbnail

๊ณต๋ถ€์ˆœ์„œ

  1. Basic
    • Scene ๋งŒ๋“ค๊ธฐ
    • Object ์ถ”๊ฐ€ํ•˜๊ธฐ
    • Materials ๊ณ ๋ฅด๊ธฐ
    • Texture ์ถ”๊ฐ€ํ•˜๊ธฐ
    • Animation ์ถ”๊ฐ€ํ•˜๊ธฐ
  2. Classic
    • Geometry ๋งŒ๋“ค๊ธฐ
    • ๋น›๊ณผ ๊ทธ๋ฆผ์ž
    • 3D์™€์˜ ์ธํ„ฐ๋ž™์…˜
    • Particle ์ถ”๊ฐ€
  3. Advanced
    • Physics, Realistic render ์—ฐ์ถœ
    • Custom shader
    • Post-processing ์ถ”๊ฐ€
    • ๋‚˜๋งŒ์˜ Blender model ๋งŒ๋“ค๊ณ  ์‚ฌ์šฉ

What is Three.js?

Itโ€™s a 3D JS library that enables devs to create 3D experiences for the web. It works with WebGL(u can make it work with SVG & CSS, but not gonna get the same result)


What is WebGL?

Has the access to properties, methods, and etcโ€ฆ to create creative stuffs

  • JavaScript API that renders triangles in a canvas at a remarkable speed
  • compatible with most modern browsers
  • fast cuz it uses the GPU of the visitor
  • can also use WebGL to create 2D exp. (like Pixi.js)


+++ CPU vs GPU

uses CPU when doing calc. in JS

GPU working when drawing triangles

CPU can do calc. really fast but one by one. BTW GPU can do thousands of parallel calculations in one go

To draw a 3D model, the idea is to draw many tri. at the right position & colorize so that they look the way we want. The GPU will position all those points at once according to many factor.

Once the points are placed, the GPU will draw each visible pixel of those tri. Again, those thousands of pixels will be calculated and drawn in parallel extremely fast.

The instructions to place the points and draw the pixels are written in Shaders (also need to provide data to these shaders)

(ex) points positions, model transformation, the camera coordinatesโ€ฆ

Native WebGL benefits from existing at a low level which enables optimizations and more control, cuz u r close to ur GPU to position things and colorize the pixels. BUT SUPER HARD;;


THREE.JS TO THE RESCUE!!

  • JS library
  • under MIT license
  • Right above WebGL, close enough to native WebGL
  • GOAL = drastically simplify the process of all of above
  • you won't have to provide shaders and matrices like native WebGL
  • still able to interact with WebGL & create ur own shader & provide ur own info.

Documentation

https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene


Just Out of Curiosityโ€ฆ

  • CPU 13-14, 59, 488, 501
  • GPU 80, 454

โœ… ํ€ด์ฆˆ ์ธ์ฆ

profile
ํ˜„์‹ค์ ์ธ ๋ชฝ์ƒ๊ฐ€

0๊ฐœ์˜ ๋Œ“๊ธ€