YouTube2Text

Fluffy stylized trees tutorial, using quadmesh-to-billboards shader in Unity — Transcript

by Pontus Karlsson · 5,792 words · 1,018 segments · language en · Watch on YouTube

Full transcript

  1. 0:03hello everyone
  2. 0:04today i would like to share a technique
  3. 0:07with you for making foliage
  4. 0:08that i figured out recently while making
  5. 0:10these trees for a game that i'm working
  6. 0:12on
  7. 0:13so the really cool thing about this
  8. 0:15technique is that
  9. 0:16i didn't actually place any of these
  10. 0:19cards by hand
  11. 0:20nor did i use any specialized
  12. 0:22third-party software
  13. 0:24in order to do any complex setup for
  14. 0:27this
  15. 0:28so the way that this technique work is
  16. 0:31that
  17. 0:32i've got this mesh that i made for the
  18. 0:35tree
  19. 0:36and the shader takes each of these quads
  20. 0:40and it effectively turns them into a
  21. 0:44billboard
  22. 0:51for this tutorial i will show you how we
  23. 0:54set up the content to work with this
  24. 0:55technique and also how we do
  25. 0:57this camera facing shader i won't have
  26. 1:00time to go through
  27. 1:01how we set up the wind and the lighting
  28. 1:04effect for these
  29. 1:05but hopefully this should give you a
  30. 1:08good start
  31. 1:10i will be using amplify shader inside of
  32. 1:13unity
  33. 1:13but if you're using unity shader graph
  34. 1:16for instance or maybe unreal
  35. 1:18i hope this should translate fairly well
  36. 1:22so let's start by jumping into
  37. 1:25our 3d software to see how we set up the
  38. 1:28model for this
  39. 1:33i've got my tree model here inside of my
  40. 1:363d software
  41. 1:37and as you can see this is not a very
  42. 1:40complex model
  43. 1:42there are however a few things we need
  44. 1:44to make sure of
  45. 1:45if we want this to work well with this
  46. 1:48billboard approach
  47. 1:49and the first one being that we
  48. 1:52want the model to consist out of
  49. 1:55equally distributed quads meaning
  50. 1:58polygons with four corners on it
  51. 2:00and in theory we could do this with
  52. 2:02triangles as well
  53. 2:04but the nice thing about a quad is that
  54. 2:06it maps nicely to the
  55. 2:08to use the entire texture space
  56. 2:12and secondly and more importantly we
  57. 2:15need to make sure that each of these
  58. 2:17quads use
  59. 2:19the entire uv space and i'll show you
  60. 2:21what i mean by that
  61. 2:23so if i open up the tree inside of my uv
  62. 2:25view and
  63. 2:26let's just isolate this
  64. 2:29so we only have the tree crown here as
  65. 2:32you can see
  66. 2:33each of these quads fill up the entire
  67. 2:36uv space here so from zero to one we
  68. 2:39fill out this entire thing so
  69. 2:41each of these uses up the entire thing
  70. 2:47and another thing that i've noticed
  71. 2:50gives a lot nicer result is to use hard
  72. 2:54edges
  73. 2:54on this model we could do this with
  74. 2:58without going for hard edges but i've
  75. 3:00noticed that each billboard gets
  76. 3:03a single light value if we make this a
  77. 3:06soft mesh
  78. 3:07each of the vertices will receive
  79. 3:09slightly different shading
  80. 3:11so having the hard edges kind of helps
  81. 3:14give each billboard a more
  82. 3:17representative
  83. 3:19light there is also no extra cost
  84. 3:22involved since
  85. 3:23we're already splitting each quad
  86. 3:26by the uv so this hard edge won't
  87. 3:28actually add
  88. 3:29any extra vertices for us
  89. 3:33so in order to create a mesh like this
  90. 3:36there are
  91. 3:37two approaches that i would recommend
  92. 3:38for doing this the
  93. 3:40first one if you're doing it inside of a
  94. 3:423d program
  95. 3:44i would use subdivision and let me just
  96. 3:47quickly show you
  97. 3:47why so i've created this new cube
  98. 3:50and i'm just gonna move it out of place
  99. 3:52here let's get up a bit
  100. 3:56so subdivision means that we take a mesh
  101. 3:59and we
  102. 4:00split each of the faces twice
  103. 4:03so we essentially end up with four times
  104. 4:05the geometry
  105. 4:06and one really nice property of
  106. 4:09subdivision
  107. 4:10is that no matter if we have quads like
  108. 4:13this
  109. 4:14or if we have triangles such as this
  110. 4:17or even if we have let's say a face
  111. 4:20with five vertices on it
  112. 4:25if we subdivide this mesh so let's say
  113. 4:29you build
  114. 4:30a volume out of some kind of geometry
  115. 4:33and
  116. 4:33if you then subdivide this mesh so it's
  117. 4:36subdivision here
  118. 4:39everything will be turned into quads so
  119. 4:41the triangles
  120. 4:42turn into quads and this big end gone
  121. 4:46over here
  122. 4:46this five-sided polygon also gets turned
  123. 4:50into equally distributed quads
  124. 4:55to manually unwrap a model like this
  125. 4:59what i would usually start out doing is
  126. 5:01doing
  127. 5:02a projection of some sort so either a
  128. 5:05planar projection or a
  129. 5:07view projection just so that all of the
  130. 5:10faces are represented inside of the uv
  131. 5:12space
  132. 5:13so once we have some sort of uvs we can
  133. 5:16then
  134. 5:16select all of the edges and
  135. 5:19cut the uvs by the edges in my case i'm
  136. 5:22using a hot key here
  137. 5:26once they're cut we can unfold them or
  138. 5:29relax them
  139. 5:32so that all of the faces are separated
  140. 5:34from each other
  141. 5:36so once it's separated we can align them
  142. 5:38and we can use a function called
  143. 5:40rectangle
  144. 5:41which will force the uvs to be
  145. 5:44rectangles
  146. 5:46but they're still a bit all over the
  147. 5:47place so next up i will
  148. 5:49align them so first aligning them
  149. 5:52vertically and then
  150. 5:53aligning them horizontally so they're
  151. 5:55all centered
  152. 5:56and they're all rectangles so once we
  153. 5:59have them like this
  154. 6:01all we need to do now is to select all
  155. 6:03of these
  156. 6:05stretch them out and just flatten these
  157. 6:08by scaling them
  158. 6:10and then snapping them to the to the
  159. 6:12borders of the uv
  160. 6:14so i'll do the same for this one and
  161. 6:16i'll
  162. 6:18scale it and then grabbing
  163. 6:21these scaling
  164. 6:24and moving it and same for this one
  165. 6:30so effectively now all of our uvs
  166. 6:34are unwrapped individually to use the
  167. 6:36full uv space
  168. 6:39so this is a really quick way if you
  169. 6:41want to do it inside of a 3d
  170. 6:42modeling software however
  171. 6:46i made this one inside of zbrush and
  172. 6:49i'll show you why that is a really nice
  173. 6:51approach
  174. 6:53so let me open up zbrush here and i've
  175. 6:56got the tree in here as well
  176. 6:59so as you can see i've sculpted these
  177. 7:01pieces and
  178. 7:02when you sculpt this geometry you can
  179. 7:04really go crazy with your style you can
  180. 7:06experiment a lot
  181. 7:07and once we have this mesh looking the
  182. 7:10way we want it to
  183. 7:12we can then use a feature in c brush
  184. 7:14called c remesher
  185. 7:16so inside of zbrush under geometry
  186. 7:20we have this thing called serial measure
  187. 7:24and serum measure takes whatever
  188. 7:26geometry we have
  189. 7:27and creates a quadrangulated mesh from
  190. 7:30it
  191. 7:32so in here we have a few options and one
  192. 7:35being the adaptive size and the adaptive
  193. 7:38size
  194. 7:39tells zbrush how much it should tolerate
  195. 7:43rectangles so whether or not we allow it
  196. 7:46to create
  197. 7:47long thin triangles and in my case i've
  198. 7:50just set this to zero
  199. 7:52feel free to experiment with this
  200. 7:56there's also a target polygon count
  201. 7:59meaning how how many triangles do you
  202. 8:02want to end up with
  203. 8:03and obviously the higher the polygon
  204. 8:06count the
  205. 8:07more expensive the mesh will be to
  206. 8:09render
  207. 8:10so feel free to experiment with this as
  208. 8:12well so i'm just going to hit serial
  209. 8:14measure
  210. 8:16and it takes my sculpt and it creates
  211. 8:18this
  212. 8:20nicely nicely distributed quad mesh
  213. 8:26so one more nice thing about zbrush is
  214. 8:29the way we can
  215. 8:30unwrap this in the way that the shader
  216. 8:32wants this
  217. 8:34so again in zbrush there is
  218. 8:37under uv map we have the option to
  219. 8:40create
  220. 8:40a new uv map for this so under review
  221. 8:44map and create
  222. 8:45there is a thing called the uv tile
  223. 8:49and clicking this creates a new uv
  224. 8:52that places these exactly how we want
  225. 8:54them and
  226. 8:55it's kind of hard to preview this in
  227. 8:57zbrush
  228. 8:58but if we click this morph uv button
  229. 9:02the faces will be morphed into their
  230. 9:05corresponding uv position
  231. 9:07giving us an indication that the uvs are
  232. 9:09laid out correctly
  233. 9:15i've got this new project set up with
  234. 9:19just these two models and a direction
  235. 9:22light in it
  236. 9:23that i will be using to try out our new
  237. 9:26shader while we build it
  238. 9:28and i'm going to start by creating the
  239. 9:31the actual shader by right clicking
  240. 9:33inside of the project
  241. 9:35i'm going to create and i'm going to
  242. 9:37make an
  243. 9:38amplify surface shader for this
  244. 9:41and let's name this foliage shader
  245. 9:47and we're also going to need a material
  246. 9:50that is using this shader
  247. 9:52so i'm going to right click once again
  248. 9:54and go to create
  249. 9:56and take material and let's name this
  250. 9:59voltage 01
  251. 10:03we also need to make sure that this new
  252. 10:05material is actually using the foliage
  253. 10:07shader so
  254. 10:08up here in the material we can change
  255. 10:10the shader to
  256. 10:12foliage shader
  257. 10:15there we go i also need to make sure
  258. 10:18that the models are using the new
  259. 10:20material
  260. 10:21so i'm going to drag drop these onto
  261. 10:23here
  262. 10:24like so and now we're good to go
  263. 10:27the data that we'll be using will be the
  264. 10:31actual uvs on the vertices and
  265. 10:34in order to access those we need to grab
  266. 10:36a note
  267. 10:37called vertex text chord
  268. 10:41so this one contains the
  269. 10:45u and v coordinates for each vertex
  270. 10:50and just to visualize what this data
  271. 10:52looks like
  272. 10:53i'm going to plug this into the emission
  273. 10:54channel
  274. 10:56and i'm going to hit compile
  275. 11:00so looking at the model now we can see
  276. 11:02that
  277. 11:03each of these quads is using the 0
  278. 11:07to 1 in uv space so the red one
  279. 11:10is the u axis and the green one is the v
  280. 11:14axis we can also think of these as x
  281. 11:17and y
  282. 11:20and i'm going to use this data to
  283. 11:24create a vertex offset
  284. 11:27if you've never done a vertex shader
  285. 11:30before
  286. 11:30or played around with vertex offsets you
  287. 11:33can think of it
  288. 11:34as a way for the shader to change the
  289. 11:38position of a vertex before it's being
  290. 11:40drawn onto the screen
  291. 11:42so the shader has access to
  292. 11:46all the information about the models
  293. 11:48that are being drawn onto the screen
  294. 11:50but before actually drawing out the
  295. 11:53triangles as pixels
  296. 11:56it has the ability to manipulate those
  297. 11:59values
  298. 12:00effectively just moving the vertices
  299. 12:03and the best way to visualize this is to
  300. 12:07just create a new vector so i'm going to
  301. 12:11create a
  302. 12:12vector 3. so
  303. 12:15three values and this is exactly the
  304. 12:18same
  305. 12:18as you would use position in your scene
  306. 12:22so you have the x y and z value and i'm
  307. 12:25just going to plug this
  308. 12:26directly into the local vertex offset
  309. 12:30and if we want to
  310. 12:33change these values in the
  311. 12:36material itself we also need to make
  312. 12:39sure that this
  313. 12:40vector is not a constant
  314. 12:43but it's actually a property so looking
  315. 12:46up in the left corner here we can see
  316. 12:47that this one is said to be a constant
  317. 12:50so changing this to be a property
  318. 12:54and we can name it something just so
  319. 12:56that we can see it
  320. 12:57more clearly so i'm going to call this
  321. 12:59offset
  322. 13:01and i'm going to hit compile so so far
  323. 13:04nothing has happened
  324. 13:05and that's because our offset is set to
  325. 13:06zero
  326. 13:08but if i select our material you can see
  327. 13:11in the inspector now we have this
  328. 13:14option here called offset and
  329. 13:18if i change one of these values so let's
  330. 13:20say i change this x value
  331. 13:23you can see that the vertices appears to
  332. 13:27move to the side here and we can always
  333. 13:29change the y value
  334. 13:30and the set value but the cool thing
  335. 13:33about
  336. 13:34a vertex shader is that the underlying
  337. 13:36model
  338. 13:37is actually intact and in unity we can
  339. 13:39see this quite clearly if we
  340. 13:41select the model so we can see here that
  341. 13:45the outline
  342. 13:46is outlining the original model
  343. 13:50whereas the geometry being drawn out is
  344. 13:53offset to the side here
  345. 13:58but i'm going to get rid of this because
  346. 14:00we're not going to do it this way
  347. 14:02however we are going to use
  348. 14:06these uv text cord this vertex text cord
  349. 14:10to drive the offset
  350. 14:13so what would happen if we just plug
  351. 14:16this
  352. 14:17directly into the local vertex officer
  353. 14:21let's give it a go
  354. 14:25so looking at the model now
  355. 14:28it sort of already looks like the thing
  356. 14:31we're going for
  357. 14:32we have each of these quads more or less
  358. 14:36facing towards us
  359. 14:38so what's actually happening here is
  360. 14:39that for each vertex
  361. 14:42it's looking up its uv value and
  362. 14:45if the uv is set to zero like it is here
  363. 14:48you can see that it stayed in place this
  364. 14:51is actually matching the outline here so
  365. 14:54this is the original location of the
  366. 14:56vertex whereas
  367. 14:59where the vertex is where the uv is
  368. 15:01green for instance
  369. 15:03it has moved one unit in the y-axis
  370. 15:07and where it is red it has moved one
  371. 15:09unit in the x-axis
  372. 15:12so this is sort of what we'll be doing
  373. 15:16however if we look if we zoom out a bit
  374. 15:19we can see that the
  375. 15:21everything is kind of going diagonally
  376. 15:23upwards
  377. 15:24and the reason for that is because we're
  378. 15:26adding one in x
  379. 15:28and one in y so we're effectively
  380. 15:31moving it up and right so the first
  381. 15:34thing we need to do is to
  382. 15:37make sure that the the lower left corner
  383. 15:41wouldn't stay in its place that it but
  384. 15:44rather going
  385. 15:47left and downwards instead
  386. 15:50so we need to remap this value so
  387. 15:52currently the uv goes from
  388. 15:54zero to one but what we want to do is
  389. 15:58that we want
  390. 16:00the right hand side to go
  391. 16:03as it is now but the left hand side
  392. 16:05should go in the opposite direction so
  393. 16:07negative one
  394. 16:09the easiest way to do that is by using a
  395. 16:13remap node so i'm going to type in remap
  396. 16:16and grab one of those
  397. 16:20so the remap node it
  398. 16:24takes a value and it scales it so we can
  399. 16:27say what the
  400. 16:28uh what the old minimum value is and
  401. 16:31then we can
  402. 16:32set a new minimum value effectively
  403. 16:36stretching the vertex
  404. 16:39so i'm going to plug this uv in here
  405. 16:43and by default the
  406. 16:46remap node when it's added a second
  407. 16:50channel here it actually didn't fill in
  408. 16:53the
  409. 16:54same value as the first one was so we
  410. 16:56can see here the
  411. 16:58maximum old is set to 1 for the x
  412. 17:01but 0 for this so we want the maximum
  413. 17:05old
  414. 17:06to be one so the old value should be
  415. 17:10the value that we currently have so we
  416. 17:12have a uv that goes from zero
  417. 17:14to one in both x and y
  418. 17:18but the new minimum value instead of
  419. 17:21being zero
  420. 17:22we want this to go towards negative one
  421. 17:25and same with the y to negative one
  422. 17:31and the max value should still be one so
  423. 17:34we need to
  424. 17:35make sure that this one is one as well
  425. 17:38like so
  426. 17:39and let's plug this in
  427. 17:46so now we can see that the
  428. 17:50uh the quads are um equally distributed
  429. 17:54to the top and to the side so
  430. 17:58it's no longer pointing towards the top
  431. 18:00right
  432. 18:01so again this looks
  433. 18:05sort of what we're going for however if
  434. 18:07i turn the camera
  435. 18:10you can see that it's not actually
  436. 18:13caring about the camera it's just
  437. 18:14pointing
  438. 18:17locally up and to the right it doesn't
  439. 18:21it doesn't know anything about the
  440. 18:22camera so
  441. 18:24the next thing we're going to do is to
  442. 18:27force these to
  443. 18:28look towards the camera
  444. 18:44to make the quads face the camera we're
  445. 18:47going to take our uv-based offset
  446. 18:49and we're going to transform it so that
  447. 18:53it is
  448. 18:53relative to the view of the camera which
  449. 18:56is
  450. 18:57also referred to as view space
  451. 19:01to do this i'm going to grab a node
  452. 19:04called view matrix
  453. 19:11the view matrix holds information about
  454. 19:14the camera that is currently rendering
  455. 19:15the scene
  456. 19:17or rather it holds the position and
  457. 19:20orientation of the
  458. 19:21inverse of the camera meaning what the
  459. 19:24camera is currently seeing
  460. 19:27if we multiply our uvs with the view
  461. 19:30matrix we're effectively
  462. 19:31transforming them to the view space
  463. 19:35so i'm going to add a multiply node
  464. 19:39this one and i'm going to multiply this
  465. 19:42scaled uv
  466. 19:43with the v matrix however
  467. 19:47this will not quite work
  468. 19:51so looking at it now we can see that
  469. 19:54it's
  470. 19:55doing something it sort of shifts a bit
  471. 19:57in place but
  472. 19:59the reason this is not working is
  473. 20:00because the vector we plugged in
  474. 20:03is a 2d vector we only have the u and
  475. 20:06the v
  476. 20:06value so we need to make sure that this
  477. 20:09is
  478. 20:09actually a 3d vector
  479. 20:13and to do that i'm going to use a append
  480. 20:16node
  481. 20:17so right click and type append
  482. 20:22so i want to create a
  483. 20:25vector3 so in the node itself we can set
  484. 20:28the
  485. 20:29vector type it's by default it's set to
  486. 20:31vector4
  487. 20:32but we're going for a vector3
  488. 20:35and i'm going to plug in the scaled uv
  489. 20:40and automatically it fills the x and y
  490. 20:42value
  491. 20:43however the set value is set to 0. and
  492. 20:48that's exactly what we want uh just be
  493. 20:50zero because we're not
  494. 20:51interested in the set value
  495. 20:56and we can see now that the lines going
  496. 20:59into this node
  497. 21:00has two lines meaning it's two values
  498. 21:03coming in
  499. 21:04but when we grab it from this side we
  500. 21:07can see three values going out so
  501. 21:09we've effectively turned our 2d vector
  502. 21:12into a
  503. 21:133d vector so once i plug this in here
  504. 21:17and hit compile
  505. 21:21these are now facing the camera
  506. 21:30so this is exactly the effect we're
  507. 21:32going for
  508. 21:33however there is
  509. 21:37one little problem with this or actually
  510. 21:38two little problems with this
  511. 21:42the reason this is actually working now
  512. 21:44is because i haven't changed the
  513. 21:46rotation of this so let's say i spin
  514. 21:49this
  515. 21:53now we're always facing
  516. 21:57the side of the quad
  517. 22:02the reason this is happening is because
  518. 22:04our offset is being applied
  519. 22:06relative to the orientation of the tree
  520. 22:08model itself
  521. 22:09which is known as object space or local
  522. 22:12space
  523. 22:14to fix this we need to take our offset
  524. 22:16and transform it
  525. 22:18so that it's using the object's
  526. 22:20orientation in the scene instead
  527. 22:22which is known as world space the
  528. 22:25easiest way to do this
  529. 22:26is to grab another matrix node and i'm
  530. 22:29going to use
  531. 22:30one called the object to
  532. 22:33world
  533. 22:37object to world matrix
  534. 22:41and same as before i'm going to multiply
  535. 22:44this
  536. 22:45uh our vector with this new matrix
  537. 22:48and i'm going to create another multiply
  538. 22:50node we can do this
  539. 22:51quickly by just holding down m and
  540. 22:53clicking
  541. 22:55so i'm going to grab this and i'm going
  542. 22:57to multiply with a vector
  543. 22:58with a matrix and i'm going to plug this
  544. 23:01into the local vertex offset
  545. 23:06so the effect is now supporting
  546. 23:09rotation so no matter how i rotate this
  547. 23:15uh all the quads are always facing the
  548. 23:18camera
  549. 23:20however once again we've missed one
  550. 23:23little thing
  551. 23:24so what would happen if i scale this
  552. 23:27model
  553. 23:32so you can see that the quads are not
  554. 23:34consistent
  555. 23:36when we scale this object and that is
  556. 23:38due to the
  557. 23:40the length of this vector
  558. 23:45so in order to make this vector a
  559. 23:49uniform length
  560. 23:50um so it doesn't go off like this when
  561. 23:53we scale it
  562. 23:54i'm going to use a normalized node so
  563. 23:57i'm going to right click
  564. 23:57i'm going to type normalize
  565. 24:02and i'm going to plug this in
  566. 24:08so now the tree supports
  567. 24:12rotation and it also supports
  568. 24:16scaling so this means that the camera
  569. 24:19effect
  570. 24:19is now actually working
  571. 24:23so let's get rid of this uv in a mission
  572. 24:27and let's instead use this
  573. 24:30pbr material that we already have set up
  574. 24:33here
  575. 24:34so i'm going to create an albedo value
  576. 24:36by creating a
  577. 24:38vector 5 which is used for colors
  578. 24:41so i'm going to hold down 5 i'm just
  579. 24:43going to click so this is a vector five
  580. 24:46and we can set it to a color so
  581. 24:49i'm gonna pick some sort of green shade
  582. 24:52for this
  583. 24:54um the alpha is actually irrelevant but
  584. 24:57i like seeing the color
  585. 24:58in this viewer
  586. 25:02so let's just go for some shade of green
  587. 25:06and plug this into the albedo
  588. 25:16so what we're seeing now is the
  589. 25:22quads are pic
  590. 25:25they keep the original lighting that the
  591. 25:28underlaying mesh had so
  592. 25:30to visualize this i'm going to
  593. 25:33create this blend effect that i had in
  594. 25:36my
  595. 25:37in my own example so that we can switch
  596. 25:39between the
  597. 25:40billboard version and the non-billboard
  598. 25:43version
  599. 25:44and all we need to do for that is to
  600. 25:47create
  601. 25:48a lerp so i'm gonna hit
  602. 25:52lerp so
  603. 25:55the lerp is just
  604. 25:58um two values uh that we
  605. 26:02blend linearly by plugging in a third
  606. 26:04value that controls
  607. 26:06which one of the two values we see or
  608. 26:08how much
  609. 26:09of each of these two we see by plugging
  610. 26:12in
  611. 26:13a value between zero and one so
  612. 26:17when this is set to one i want to see
  613. 26:19this effect
  614. 26:20and when it's set to zero i want
  615. 26:24the offset to be zero which we already
  616. 26:27have here
  617. 26:28and i'm just gonna create a value that
  618. 26:31controls this alpha
  619. 26:33i'm gonna hold down one and i'm gonna
  620. 26:35click so we'll get a float
  621. 26:38and just like before i don't want this
  622. 26:41to be constant i want to be able to
  623. 26:43access this
  624. 26:44inside of the material so i'm going to
  625. 26:45change this from a constant
  626. 26:48to be a property and i'm going to call
  627. 26:50this um effect blend
  628. 26:56like so and i'm going to plug this in as
  629. 26:59the alpha
  630. 27:01i also want to make sure that this value
  631. 27:03when we slide it
  632. 27:04it won't go below zero and it won't go
  633. 27:07above one and in amplify
  634. 27:10if we want to make sure that a property
  635. 27:14stays within range we can set a minimum
  636. 27:17and maximum value
  637. 27:19but if both of these are set to zero it
  638. 27:22means that we can slide it however we
  639. 27:24however we like so we need to set a
  640. 27:27maximum value here so i'm going to set
  641. 27:28this to one
  642. 27:30and you can see this instantly updates
  643. 27:31to a slider
  644. 27:34so let's just plug this back in and set
  645. 27:37the default to one
  646. 27:40and compile
  647. 27:43so selecting the material now we have
  648. 27:45this slider called effect blend
  649. 27:48and if i slide this towards zero
  650. 27:52we can now switch between the initial
  651. 27:56model without the offset and the
  652. 27:59billboard effect with a full offset
  653. 28:02so the really cool thing about this
  654. 28:04method is that
  655. 28:05uh if we look at this value that we have
  656. 28:09here
  657. 28:09like for instance let's look at this um
  658. 28:12dark quad down here once i slide this
  659. 28:17actually it went heading but hidden but
  660. 28:19the quad itself
  661. 28:21keeps the shading from the
  662. 28:24um from the original mesh
  663. 28:28so with vertex shader this is actually a
  664. 28:31positive side effect because whenever we
  665. 28:34change the position in a vertex shader
  666. 28:37we don't update the normals by default
  667. 28:41so if we would like the billboards to
  668. 28:45get their shading as if they were
  669. 28:48actually placed the way they were on
  670. 28:49screen we need to do that calculation
  671. 28:51ourselves
  672. 28:52but in this case we don't want that we
  673. 28:54want the
  674. 28:55original shading so this is just this is
  675. 28:58perfect as it is
  676. 29:00however we might want to
  677. 29:04make this look less blocky so i'm going
  678. 29:06to add a alpha to this
  679. 29:10so i've already prepared an alpha that
  680. 29:12i've used in my own trees
  681. 29:14and the reason this is red and not white
  682. 29:16black and white is because it's
  683. 29:17said to be a single channel meaning i
  684. 29:20get the red channel so
  685. 29:22think of this as a black and white image
  686. 29:24being our alpha so i'm just going to
  687. 29:26drag drop this in here
  688. 29:28and i'm going to plug this into the
  689. 29:31opacity mask
  690. 29:32however this shader does not yet support
  691. 29:36alpha so i'm going to select the shader
  692. 29:40and under render queue
  693. 29:44i'm going to change this to be alpha
  694. 29:46test
  695. 29:48so now we have the option to set an
  696. 29:50opacity mask we also have a few extra
  697. 29:53options that are only for transparent
  698. 29:55object and not
  699. 29:56the alpha test object so i'm also going
  700. 29:59to change the render type
  701. 30:00to be transparent cutout
  702. 30:04so now we only have the opacity mask
  703. 30:07available so
  704. 30:08i'm going to grab this red channel i'm
  705. 30:11going to plug it into the opacity mask
  706. 30:19and the reason it didn't update is
  707. 30:21because these texture samples
  708. 30:23are by default a property meaning that
  709. 30:26the
  710. 30:27material can override this
  711. 30:30the texture that we have set inside of
  712. 30:32the shader itself
  713. 30:33so we need to go to the material and we
  714. 30:36need to set this
  715. 30:37texture in the material as well
  716. 30:42there we go so as soon as we apply the
  717. 30:46alpha
  718. 30:48it instantly gets really fussy
  719. 30:53um it's also worth pointing out that
  720. 30:55something i've noticed
  721. 30:56with the alpha is that it really helps a
  722. 30:59lot to have
  723. 31:00quite a high frequency of detail so uh
  724. 31:04we have a lot of space in between as
  725. 31:06soon as it goes solid
  726. 31:08uh we get a lot of the strange overlaps
  727. 31:10that we had
  728. 31:11before we applied the alpha so when you
  729. 31:14make your alpha
  730. 31:15think make sure you keep some space
  731. 31:18between the
  732. 31:20leaves just to give it this fussiness
  733. 31:22because it helps
  734. 31:23hiding the fact that it's a billboard
  735. 31:27so just one quick note on the shading
  736. 31:32since it's picking up the shading of the
  737. 31:35object
  738. 31:36the really cool thing about this is that
  739. 31:39in order to change the overall style and
  740. 31:42look of this
  741. 31:43all we need to do is
  742. 31:48change the underlying material like
  743. 31:51ignoring the fact that it's doing this
  744. 31:54effect and just apply
  745. 31:56stuff like for instance smoothness
  746. 31:59let's add a bit of smoothness so i'm
  747. 32:02going to create
  748. 32:02a float holding down one clicking
  749. 32:07and i'm going to change this to be a
  750. 32:08property and let's just call this
  751. 32:09smoothness
  752. 32:12and plug it into smoothness
  753. 32:19and as soon as we crank up the
  754. 32:23smoothness
  755. 32:26you can see that we get this specular
  756. 32:29highlight
  757. 32:30on the model so already we're getting
  758. 32:34some sort of style going here
  759. 32:39we could also for instance add the
  760. 32:42fresnel effect
  761. 32:43so i'm going to add a fresnel node
  762. 32:49worth noting with the fresnel node is
  763. 32:50that it doesn't automatically output
  764. 32:53a black and white value so by default
  765. 32:56this will go really bright but i'm going
  766. 32:57to plug this into the emission
  767. 32:59just to show you what's going to happen
  768. 33:02and it goes super bright so
  769. 33:03the fresnel we need to make sure that it
  770. 33:05stays between 0
  771. 33:07and 1. and we can do that by adding a
  772. 33:09saturated node so
  773. 33:10if you haven't used saturate this is a
  774. 33:12clamp node so it cuts off
  775. 33:14uh it's a clamp node but it's set to be
  776. 33:17only between zero
  777. 33:18and one so any value below zero will be
  778. 33:21zero
  779. 33:22any value above one will be one so it
  780. 33:24just cuts off the
  781. 33:26uh the low end and the high end
  782. 33:30so i'm going to saturate this
  783. 33:35didn't actually do that much i'm also
  784. 33:39going to
  785. 33:40multiply this by a color so just another
  786. 33:43multiply node
  787. 33:44and another color note
  788. 33:47holding down 5.
  789. 33:52and i'm going to set this to some
  790. 33:55different shade of green
  791. 34:00and plug this back in
  792. 34:06so this way we can quickly uh
  793. 34:10add a lot of style to our
  794. 34:13trees
  795. 34:18so already it's starting to look like
  796. 34:21something from a
  797. 34:23studio ghibli film or something
  798. 34:32we can also look at this thing the cool
  799. 34:35thing about this shader is that
  800. 34:37as long as the object is unwrapped the
  801. 34:39way it is
  802. 34:41we can grab basically any model with
  803. 34:44this setup
  804. 34:44so for instance if we have a model like
  805. 34:46this
  806. 34:48we could add our foliage shader to it
  807. 34:50and it automatically just
  808. 34:53becomes foliage there are
  809. 34:56two more things i want to quickly show
  810. 34:58you before i
  811. 34:59end this video so
  812. 35:03this effect the camera facing effect
  813. 35:09let's say we want to change the
  814. 35:14size of these so each of these quads
  815. 35:17actually let's change this to shaded
  816. 35:19wireframe so we can look at the quads
  817. 35:22like this so we know that each of these
  818. 35:25are the size of the uv they're like
  819. 35:28negative one and one so these are
  820. 35:31two in size if we would like to change
  821. 35:34the size of these
  822. 35:35all we need to do is to take this vector
  823. 35:39and multiply it by a single value and
  824. 35:42that will change
  825. 35:43the scale a bit so i'm going to add
  826. 35:46a multiply node at the end of this
  827. 35:51chain here so multiply and i'm going to
  828. 35:54set this
  829. 35:55to use a single value and again i'm
  830. 35:58going to make this a property
  831. 36:01and let's call this um billboard
  832. 36:05size and by default it should be set to
  833. 36:10whoops
  834. 36:10not the max the default it should be set
  835. 36:12to one just so
  836. 36:14if we don't change this in the material
  837. 36:15it will be the it will be an appropriate
  838. 36:18value
  839. 36:25so now if we click the material we can
  840. 36:28set the
  841. 36:31scale or the billboard size by just
  842. 36:35changing this value
  843. 36:41another quite cool thing that we can do
  844. 36:43with this is that
  845. 36:46same way that we're changing the size of
  846. 36:48these we can also change
  847. 36:49how close to the original surface they
  848. 36:53are because currently
  849. 36:54these are placed at the position of the
  850. 36:57original vertices but since all of
  851. 37:01the chords have their own normals
  852. 37:04we can use the normals in order to
  853. 37:07inflate the model in order to push the
  854. 37:10vertices away
  855. 37:11in the direction they're facing so let
  856. 37:14me just
  857. 37:15make a bit of space here
  858. 37:20we access the normals of the vertices by
  859. 37:23right clicking
  860. 37:24and typing vert and norm
  861. 37:27normal so vertex normal
  862. 37:32so this is a vector describing
  863. 37:36the normal of the word basic in this
  864. 37:38case it's pointing
  865. 37:40outwards from the face so if we take
  866. 37:42this value
  867. 37:44and we can multiply it to say how far
  868. 37:47we want to push the billboard away from
  869. 37:51the surface
  870. 37:52by adding a single value so
  871. 37:56changing this to again a property and
  872. 37:59let's call this
  873. 38:02inflate
  874. 38:05and multiply this value i'm going to let
  875. 38:08the default be zero because
  876. 38:11perhaps we don't want to use this all
  877. 38:13the time but
  878. 38:15so here we have the scaled normal
  879. 38:20if we add this to the
  880. 38:23billboard we're essentially just moving
  881. 38:26the billboard
  882. 38:27in the direction of the normal so i'm
  883. 38:29going to add a add node
  884. 38:31holding down a click to add an add node
  885. 38:35so adding this value here
  886. 38:39and plugging it in here
  887. 38:43and hit compile
  888. 38:46we now have an option to inflate the
  889. 38:49model so
  890. 38:50let's set the size back to one
  891. 38:54so it doesn't go crazy and
  892. 38:57now we can push the face push the
  893. 39:00billboards away from the faces
  894. 39:02in order to inflate the model
  895. 39:11we could also also push them inwards but
  896. 39:13you'll notice that the
  897. 39:16shading looks a bit messed up because
  898. 39:18the
  899. 39:20faces that are on the other side of the
  900. 39:22mesh getting in different lighting
  901. 39:23will push through to the other side
  902. 39:27essentially just inverting the mesh
  903. 39:34one thing that i would like to add that
  904. 39:35i think is really cool with this method
  905. 39:38is that since we are just using
  906. 39:42the uvs in this case to manipulate the
  907. 39:45vertices
  908. 39:48anything that we can do to regular uv
  909. 39:51coordinates
  910. 39:52we can do to manipulate the billboard
  911. 39:56itself so just to visualize this i'm
  912. 39:59going to change this to shader wireframe
  913. 40:01again
  914. 40:02and just zooming in here looking at
  915. 40:05these
  916. 40:07so for instance one thing that is very
  917. 40:10common to use
  918. 40:10when doing vfx manipulating the vert
  919. 40:14the uv coordinates is for instance using
  920. 40:17a
  921. 40:18rotator so let me just add one of those
  922. 40:21so
  923. 40:21a rotator so
  924. 40:24the rotator takes the uvs and
  925. 40:28given an anchor and the time the time in
  926. 40:31this case
  927. 40:32being the amount of rotation
  928. 40:36will rotate the uv
  929. 40:39around this pivot point by this much
  930. 40:43so in our case
  931. 40:47the original center of the uv cord is
  932. 40:500.5 and 0.5 but since we've
  933. 40:53already remapped those we know that in
  934. 40:56this case
  935. 40:57where the maximum is 1 and the minimum
  936. 41:00is negative 1
  937. 41:01the pivot point will be at zero so i'm
  938. 41:04gonna plug this value
  939. 41:06as my uv leaving the anchor at zero and
  940. 41:10zero
  941. 41:11and just like this one suggests i'm
  942. 41:14going to add
  943. 41:15some time to this so right click and hit
  944. 41:17time
  945. 41:18and this is not how i would
  946. 41:22actually use it by just plugging time
  947. 41:24into it but i just want to show you what
  948. 41:25this will do
  949. 41:26so plugging time in and then plug it
  950. 41:29back into the chain here
  951. 41:32and hitting compile
  952. 41:35so rotating the uvs in this case
  953. 41:40doesn't mean rotating the
  954. 41:43texture inside of the quad it means
  955. 41:46actually
  956. 41:46rotating the billboard so
  957. 41:50in my example
  958. 41:53i'm using this effect to for my wind
  959. 41:56effect to get this
  960. 41:58jittering effect so that's essentially
  961. 42:01um
  962. 42:02using a rotator uh and instead of just
  963. 42:06plugging in time i'm plugging in
  964. 42:07the amount of rotation so i'm using a
  965. 42:10sine wave to
  966. 42:11basically wobble these quickly as the
  967. 42:14wind passes through
  968. 42:16um but i will not go through the wind
  969. 42:19setup in this one
  970. 42:21however if you would like to see it um i
  971. 42:23could perhaps do
  972. 42:24another tutorial if people would be
  973. 42:26interested to see
  974. 42:28how we could do a wind setup for this
  975. 42:34to conclude this video i would like to
  976. 42:37clarify that
  977. 42:38this technique is not a
  978. 42:40one-size-fits-all
  979. 42:41solution for making foliage it doesn't
  980. 42:44replace
  981. 42:45the traditional way of creating foliage
  982. 42:47where you
  983. 42:48make more branch-like cards and manually
  984. 42:51attach them to the tree trunk
  985. 42:53billboards are limited in the way that
  986. 42:56they're always facing the camera
  987. 42:58giving them an odd behavior when you're
  988. 43:00moving the camera around quickly
  989. 43:03they lend themselves better to more
  990. 43:05abstract art styles where the
  991. 43:07expression of the tree is more important
  992. 43:09than the accuracy
  993. 43:10and the overall level of detail
  994. 43:14i'm personally very excited for this
  995. 43:16technique though
  996. 43:18mainly because it requires so little
  997. 43:20manual setup once you have your shader
  998. 43:23the low complexity of this approach
  999. 43:24makes it very easy to
  1000. 43:27experiment with your style especially
  1001. 43:29when you can
  1002. 43:30almost instantly go from a sculpt to a
  1003. 43:33finished tree
  1004. 43:35it's also very quick to experiment with
  1005. 43:37the style of the leaves
  1006. 43:39since it's just using a single circular
  1007. 43:43alpha texture
  1008. 43:51thank you so much for watching i hope
  1009. 43:54you found this
  1010. 43:54video helpful in some way i'm looking
  1011. 43:57forward to see what others can do with
  1012. 43:59this technique
  1013. 44:00as i'm sure there are more use cases for
  1014. 44:02it
  1015. 44:03and let me know if anything is unclear
  1016. 44:06and i can hopefully
  1017. 44:07clarify it in the comments
  1018. 44:15bye

About this transcript

This page contains the full transcript of Fluffy stylized trees tutorial, using quadmesh-to-billboards shader in Unity by Pontus Karlsson, generated from the public captions YouTube serves with the video. The transcript has 5,792 words across 1,018 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.