undefined

5๊ฐ• ์žฌ์งˆ part4 - ํ…์Šค์ณ2

 

[three.js] Material์— ํ…์Šค์ณ๋ฅผ ์ž…ํ˜€๋ณด์ž

5๊ฐ• ์žฌ์งˆ part3 - ํ…์Šค์ณ map ์†์„ฑ ํ…์Šค์ณ ๊ฐ์ฒด๋ฅผ ์ง€์ •ํ•˜๋ฉด ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ์˜ ํ‘œ๋ฉด์— ์ง€์ •๋œ ํ…์Šค์ณ์˜ ์ด๋ฏธ์ง€๊ฐ€ ์˜ท์ฒ˜๋Ÿผ ์ž…ํ˜€์ง ๋ฉ”์‰ฌ์˜ ๋ชจ๋“  material์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค ํ…์Šค์ณ ๊ฐ์ฒด ์ด๋ฏธ์ง€๋‚˜ ๋™์˜์ƒ ๋“ฑ์„

tech-hayo.tistory.com

์ €๋ฒˆ ์‹œ๊ฐ„์—๋Š” Material์˜ map ์†์„ฑ์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ํ…์Šค์ณ๋กœ ๋งŒ๋“ค์–ด ์ž…ํžˆ๊ณ , ์ด ํ…์Šค์ณ์˜ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์†์„ฑ์„ ๋‹ค๋ค„๋ณด์•˜๋‹ค.

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋‹ค์–‘ํ•œ map์„ ํ†ตํ•ด ๋” ์„ธ๋ฐ€ํ•˜๊ฒŒ ํ…์Šค์ณ๋ฅผ ๊ณ ๋„ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์›Œ๋ณธ๋‹ค.


 

์ค€๋น„ํ•˜๊ธฐ

์—ฐ์Šตํ•˜๊ธฐ ์ „, ์‚ฌ์šฉํ•  ํ…์Šค์ณ ์ด๋ฏธ์ง€๋ฅผ ์ค€๋น„ํ•ด์•ผ ํ•œ๋‹ค.

์—ฌ๊ธฐ์—์„œ ํ…์Šค์ณ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•œ๋‹ค.

[Glass Window 002

Glass Window 002 – Free seamless texture, 1024 x 1024, with the following maps: Diffuse Normal Displacement Roughness Ambient Occlusion Opacity

3dtextures.me](https://3dtextures.me/2020/07/15/glass-window-002/)

ํ•ด๋‹น ์ด๋ฏธ์ง€์˜ ํ•ด์ƒ๋„์™€ map ์†์„ฑ์— ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ด๋ฏธ์ง€๊ฐ€ ์–ด๋–ค ๊ฒƒ์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

TextureLoader๋กœ ์ด๋ฏธ์ง€ ํŒŒ์ผ์—์„œ ํ…์Šค์ณ ๊ฐ€์ ธ์˜ค๊ธฐ

TextureLoader๋ฅผ ์ด์šฉ

const textureLoader = new THREE.TextureLoader();

const map = textureLoader.load("/assets/images/glass/Glass_Window_002_basecolor.jpg");
const mapAO = textureLoader.load("/assets/images/glass/Glass_Window_002_ambientOcclusion.jpg");
const mapHeight = textureLoader.load("/assets/images/glass/Glass_Window_002_height.png");
const mapNormal = textureLoader.load("/assets/images/glass/Glass_Window_002_normal.jpg");
const mapRoughness = textureLoader.load("/assets/images/glass/Glass_Window_002_roughness.jpg");
const mapMetalic = textureLoader.load("/assets/images/glass/Glass_Window_002_metallic.jpg");
const mapAlpha = textureLoader.load("/assets/images/glass/Glass_Window_002_opacity.jpg");

 

map ์†์„ฑ๋งŒ ์ ์šฉํ–ˆ์„ ๋•Œ

const material = new THREE.MeshStandardMaterial({
  map: map,
});

  • ์ž…์ฒด๊ฐ์ด ๋šœ๋ ทํ•˜์ง€ ์•Š๋‹ค.

 

normalMap

  • ๋ฒ•์„  ๋ฒกํ„ฐ๋ฅผ ์ด๋ฏธ์ง€ํ™”ํ•œ ๊ฒƒ
  • ๋ฒ•์„  ๋ฒกํ„ฐ๋Š” ๋ฉ”์‰ฌ์˜ ํ‘œ๋ฉด์— ๋Œ€ํ•œ ์ˆ˜์ง ๋ฒกํ„ฐ๋กœ, ๊ด‘์›์˜ ์˜ํ–ฅ์„ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•œ๋‹ค.
const material = new THREE.MeshStandardMaterial({
      map: map,
      normalMap: mapNormal
    });

  • map๋งŒ ์ ์šฉํ–ˆ์„ ๋•Œ๋ณด๋‹ค ์ž…์ฒด๊ฐ์ด ๋ณด์ธ๋‹ค.

 

normalMap์ด ์ž…์ฒด๊ฐ์„ ๋ถ€์—ฌํ•˜๋Š” ๋ฐฉ์‹

normalMap๋งŒ ์ ์šฉํ•˜๊ณ  ๋ฒ•์„ ๋ฒกํ„ฐ๋ฅผ ์‹œ๊ฐํ™”ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณด์ธ๋‹ค.

๋ณธ๋ž˜ ์ง€์ •๋˜์ง€ ์•Š์€ ํŠน์ • ์ง€์ ์— ๋Œ€ํ•œ ๋ฒ•์„  ๋ฒกํ„ฐ๋Š” ๊ตฌ์„ฑ ์ขŒํ‘œ์˜ ๋ฒ•์„  ๋ฒกํ„ฐ๋“ค์„ ์ด์šฉํ•ด ๋ณด๊ฐ„ ๊ณ„์‚ฐ๋œ๋‹ค.

ํ•˜์ง€๋งŒ normalMap์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ•์Šค ํ‘œ๋ฉด์˜ ๋ฒ•์„  ๋ฒกํ„ฐ๋ฅผ normalMap ์ด๋ฏธ์ง€์˜ RGB ๊ฐ’์„ ์ด์šฉํ•ด ๊ณ„์‚ฐํ•˜๊ฒŒ ๋œ๋‹ค. ๋”ฐ๋ผ์„œ,

  • ๋ฉ”์‰ฌ ํ‘œ๋ฉด์˜ ๊ฐ ํ”ฝ์…€์— ๋Œ€ํ•ด ๋ฒ•์„  ๋ฒกํ„ฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค
  • ๊ฐ ํ”ฝ์…€ ๋‹จ์œ„๋กœ ๊ด‘์› ํšจ๊ณผ๊ฐ€ ๋‹ฌ๋ผ์ ธ ์ž…์ฒด๊ฐ์„ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

normalMap์€ ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ์ขŒํ‘œ๋ฅผ ๋ณ€ํ˜•ํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค. ์ผ์ข…์˜ ์ฐฉ์‹œ ํšจ๊ณผ๋ฅผ ์ด์šฉํ•ด ์ž…์ฒด๊ฐ์„ ๋ถ€์—ฌํ•œ๋‹ค.

๋”ฐ๋ผ์„œ ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ์˜ ๋งค์šฐ ์ ์€ ์ขŒํ‘œ ๊ตฌ์„ฑ๋งŒ์œผ๋กœ๋„ ์ž…์ฒด๊ฐ์„ ํšจ๊ณผ์ ์œผ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

displacementMap

  • normalMap๊ณผ ๋‹ฌ๋ฆฌ ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ์ขŒํ‘œ๋ฅผ ๋ณ€ํ˜•์‹œ์ผœ ์ž…์ฒด๊ฐ์„ ํ‘œํ˜„ํ•œ๋‹ค.
  • ๋งต ์ด๋ฏธ์ง€์˜ ํ”ฝ์…€๊ฐ’์ด ๋ฐ์„์ˆ˜๋ก ์ขŒํ‘œ์˜ ๋ณ€์œ„๊ฐ€ ์ปค์ง€๊ฒŒ ๋œ๋‹ค.
  • ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ์ขŒํ‘œ๋ฅผ ๋ณ€ํ˜•์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”์‰ฌ ํ‘œ๋ฉด์— ๋Œ€ํ•œ ๊ตฌ์„ฑ ์ขŒํ‘œ๋ฅผ ์ œ๊ณตํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

์•„๋ž˜ ๊ฒฐ๊ณผ๋ฌผ์€ box segment๊ฐ’์€ 256, sphere segment๊ฐ’์€ 512๋กœ ์„ค์ •ํ•˜์˜€๋‹ค.

const material = new THREE.MeshStandardMaterial({
  normalMap: mapNormal,

  displacementMap: mapHeight,
  displacementScale: 0.2,
  displacementBias: -0.15
});
  • displacementScale, displacementBias: ๋ณ€์œ„๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์†์„ฑ

 

displacementMap๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด

์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ํ‘œ๋ฉด์„ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์„ธ๊ทธ๋จผํŠธ๋กœ ๋ถ„ํ• ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋งŽ์€ ์„ธ๊ทธ๋จผํŠธ๋กœ ๋ถ„ํ• ๋ ์ˆ˜๋ก ๋งต ํšจ๊ณผ๊ฐ€ ์ž˜ ์ ์šฉ๋œ๋‹ค.

ํ•˜์ง€๋งŒ ์ขŒํ‘œ๋ฅผ ๋” ๋งŽ์ด ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์€ ๋ Œ๋”๋ง ์†๋„ ๋ฉด์—์„œ ๋น„ํšจ์œจ์ ์ด๋ฏ€๋กœ ์ ์ ˆํ•œ ๋…ธ๋ง ๋งต๊ณผ displacementMap ํšจ๊ณผ๋ฅผ ์œ„ํ•œ ์ ์ ˆํ•œ ์„ธ๊ทธ๋จผํŠธ ๋ถ„ํ• ์ด ํ•„์š”

 

aoMap

  • ํ…์Šค์ณ ์ด๋ฏธ์ง€์— ๋ฏธ๋ฆฌ ์Œ์˜ ํšจ๊ณผ๋ฅผ ๊ทธ๋ ค ๋„ฃ์€ ๊ฒƒ

์™ผ: normalMap, aoMap๋งŒ ์ ์šฉํ–ˆ์„ ๋•Œ ๊ฒฐ๊ณผ ์˜ค: map, normalMap, displacementMap, aoMap ์ ์šฉ

const material = new THREE.MeshStandardMaterial({
  map,
  normalMap: mapNormal,

  displacementMap: mapHeight,
  displacementScale: 0.2,
  displacementBias: -0.15,

  aoMap: mapAO,
  aoMapIntensity: 1  // ๊ทธ๋ฆผ์ž ๊ฐ•๋„ ์ง€์ •
});

 

aoMap์„ ์‚ฌ์šฉํ•  ์‹œ ์œ ์˜ํ•  ์ 

aoMap ํšจ๊ณผ๋ฅผ ๋‚ด๋ ค๋ฉด ๋‘ ๊ฐ€์ง€ ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค.

  1. scene์— AmbientLight ์ถ”๊ฐ€: ๋ชจ๋“  mesh์˜ ์ „์ฒด ๋ฉด์— ๋Œ€ํ•ด์„œ ๊ท ์ผํ•˜๊ฒŒ ๋น„์ถ”๋Š” ๊ด‘์›
  2. ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ์†์„ฑ์— uv2 ๋ฐ์ดํ„ฐ ์ง€์ •
  3. box.geometry.attributes.uv2 = box.geometry.attributes.uv sphere.geometry.attributes.uv2 = sphere.geometry.attributes.uv

aoMap์„ ์ด์šฉํ•˜๋ฉด ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด์ง„ ์„ธ๋ฐ€ํ•œ ๊ทธ๋ฆผ์ž ํšจ๊ณผ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

roughnessMap

  • ๊ฑฐ์น ๊ธฐ์— ๋Œ€ํ•œ ์žฌ์งˆ ์ ์šฉ
  • ๋งต ์ด๋ฏธ์ง€์˜ ํ”ฝ์…€ ๊ฐ’์ด ๋ฐ์„์ˆ˜๋ก ๊ฑฐ์น ๊ธฐ๊ฐ€ ๊ฐ•ํ•ด์ง
  • roughness ์†์„ฑ์œผ๋กœ ๊ฑฐ์น ๊ธฐ ์กฐ์ •
    • ๋‚ฎ์„์ˆ˜๋ก ๋ฐ˜์ง์ด๋Š” ํ”Œ๋ผ์Šคํ‹ฑ ๋Š๋‚Œ์ด ๋‚œ๋‹ค

roughness: 0.5

 

metalnessMap

  • ๊ธˆ์† ์žฌ์งˆ์— ๋Œ€ํ•œ ๋Š๋‚Œ์„ ๋ถ€์—ฌํ•˜๋Š” ๋งต
  • metalness ์†์„ฑ์œผ๋กœ ์กฐ์ • (๊ธฐ๋ณธ๊ฐ’: 0)

 

alphaMap

  • ํˆฌ๋ช…๋„์— ๋Œ€ํ•œ ๋งต ์†์„ฑ
  • ์ด๋ฏธ์ง€์˜ ํ”ฝ์…€๊ฐ’์ด ๋ฐ์„์ˆ˜๋ก ๋ถˆํˆฌ๋ช…ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ํ”ฝ์…€๊ฐ’์ด ์™„์ „ํ•œ ๊ฒ€์€์ƒ‰์ผ ๋•Œ ์™„์ „ํžˆ ํˆฌ๋ช…
  • transparent: true ์†์„ฑ์„ ์ค˜์„œ ํˆฌ๋ช…๋„๋ฅผ ํ™œ์„ฑํ™”ํ•ด์ฃผ์–ด์•ผ ํ•จ
    • ๋ฉ”์‰ฌ์˜ ๋’ท๋ฉด๋„ ๋ Œ๋”๋ง ํ•ด์•ผ ๋˜๊ธฐ ๋•Œ๋ฌธ์— side: THREE.DoubleSide ์ถ”๊ฐ€

 

lightMap

  • ์ง€์ •๋œ ์ด๋ฏธ์ง€์˜ ์ƒ‰์ƒ์œผ๋กœ ๋ฐœ๊ด‘ํ•˜๋Š” ๋Š๋‚Œ์„ ํ‘œํ˜„
  • lightMapIntensity ์†์„ฑ์œผ๋กœ ๊ฐ•๋„ ์กฐ์ ˆ

 


๋งˆ๋ฌด๋ฆฌ

์—ฌ๋Ÿฌ ๊ฐ€์ง€ ํ…์Šค์ณ ๋งตํ•‘ ์†์„ฑ์„ ๋‹ค๋ค„๋ณด๋ฉด์„œ ๋ฌผ์ฒด์— ์ž…์ฒด์ ์ธ ํšจ๊ณผ๋ฅผ ๋”ํ•ด์ฃผ๋Š” ๋ฐฉ์‹์„ ์ดํ•ดํ–ˆ๋‹ค.

 

[three.js] Material - ์˜ค๋ธŒ์ ํŠธ์˜ ์žฌ์งˆ์„ ๋‹ค์–‘ํ•˜๊ฒŒ ์„ค์ •ํ•ด๋ณด์ž

5๊ฐ• ์žฌ์งˆ (part1 ~ 2) Material์€ ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ์™€ ํ•จ๊ป˜ Object3D ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ํ•„์ˆ˜ ์š”์†Œ Object์˜ ์„ธ ๊ฐ€์ง€ ํŒŒ์ƒ ํด๋ž˜์Šค (Mesh, Line, Points) ๊ฐ๊ฐ์„ ์œ„ํ•œ ํด๋ž˜์Šค๋กœ ๋ถ„๋ฅ˜๋˜์–ด ์ œ๊ณต๋œ๋‹ค Material ๋ชจ๋“  material

tech-hayo.tistory.com

์ด์ „์— Material ๊ฐ์ฒด๋ฅผ ๋‹ค๋ค„๋ณด๋ฉด์„œ opacity, metalness, roughness ๋“ฑ์˜ ์†์„ฑ์œผ๋กœ ํ…์Šค์ณ๋ฅผ ๋‹ค๋ค˜์—ˆ๋‹ค.

์ด๋Ÿฐ ์†์„ฑ์€ ์˜ค๋ธŒ์ ํŠธ์˜ ์ „์ฒด ํ”ฝ์…€์— ๋™์ผํ•˜๊ฒŒ ์ ์šฉ๋œ๋‹ค.

 

ํ•˜์ง€๋งŒ ์ด๋ฒˆ ์‹œ๊ฐ„์— ๋‹ค๋ค˜๋˜ ๊ฒƒ์ฒ˜๋Ÿผ ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•ด ๋งตํ•‘์„ ํ•˜๋ฉด, ํ”ฝ์…€๋งˆ๋‹ค ํŠน์ •ํ•œ ์†์„ฑ๊ฐ’์„ ์ ์šฉ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

๋ณด๋‹ค ์‚ฌ์‹ค์ ์ธ 3D ๊ฐ์ฒด๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ…์Šค์ณ ๋งตํ•‘์œผ๋กœ ์ž…์ฒด๊ฐ์„ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์ด ํ•„์ˆ˜์ธ ๊ฒƒ ๊ฐ™๋‹ค.

 

BumpMap

bumpMap์€ normalMap์„ ์„ค์ •ํ•˜๋ฉด ๋ฌด์‹œ๋˜๋Š” ์†์„ฑ์ด๋‹ค.

normalMap์€ X, Y, Z ์ถ•์— ๋Œ€ํ•œ ๋ฒ•์„  ๋ฒกํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฐ˜๋ฉด, bumpMap์€ Y์ถ• ๋ฒกํ„ฐ๊ฐ’๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

์‹ค๋ฌด์—์„œ๋Š” bumpMap๋ณด๋‹จ normalMap์ด ์ฃผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.