R for the Rest of Us Podcast Episode 23: Terence Teo
In this episode, I chat with Terence Teo, Professor at Seton Hall University and expert in creating stunning 3D maps using the {rayshader} package in R. Terence discusses his journey into data visualization, specifically his use of R and the RayShader package to create mesmerizing 3D maps. Terence shares insights from his academic background in political science, his creative process for making maps, and how he balances artistic flair with technical rigor. The discussion dives into geospatial data, the intricacies of the {rayshader} and {rayrender} packages, and the value of experimentation in visual storytelling.
Listen to the Audio Version
Watch the Video Version
You can also watch the conversation on YouTube.
Important resources mentioned:
River Basins of the Iberian Peninsula: https://bsky.app/profile/tterence.bsky.social/post/3kdbsv4bbc32k
GitHub repo of code used
Connect with Terence on:
Bluesky: @tterence.bsky.social
Learn More
If you want to receive emails to help you on your R Journey, sign up for the R for the Rest of Us newsletter.
If you're ready to learn R, check out our courses.
Transcript
[00:00:00] David Keyes: Well, I'm delighted to be joined today by Terence Teo. Uh, Terence is a professor at Seton Hall University in the Department of Political Science. But if you are around the R community, you are more likely to know Terence for the incredible maps that he makes using the various RayShader packages, which we are going to discuss today.
[00:00:50] So Terence, welcome, and thanks for joining me.
[00:00:52] Terence Teo: Thank you for having me, David.
[00:00:54] David Keyes: Yeah, so tell me first, if you don't mind, just a bit about your academic background, um, and then we'll kind of build on that because I'm curious to hear to what degree that relates to your interest in making maps.
[00:01:07] Terence Teo: Right. So yeah, so I was trained, I'm trained as a political scientist and I do work primarily on democracies and dictatorships. So I study, in particular, authoritarian regimes, why some of them are stable. And more recently, uh, why democracies may backslide, um, into dictatorships. So that's sort of
[00:01:27] David Keyes: That's a, that's a very relevant topic for those of us in the US.
[00:01:31] Terence Teo: correct. So I'm going to be very busy, uh, uh, you know, in the next few years. Uh, so that's, that's sort of my, my day job. So I, that's my research. When I work, uh, I do work along those lines. And when I teach, I teach work along those lines as well on democracy and dictatorship, but also mainly research methods.
[00:01:50] So I teach methods and statistics to social science undergrads, as well as some game theory at times to students. Yeah,
[00:02:00] David Keyes: Cool. Um, so like I said before, the reason I know you, and I think the reason many people in the R community know you, is for the incredible maps that you make. Um, and in a little bit we'll actually have you put up your screen and demonstrate how you make these maps. But I'm curious, uh, if you could talk, first of all, how you got into making maps in the first place.
[00:02:21] Did it come from your academic work, or was it just a general interest in maps?
[00:02:26] Terence Teo: so this was, I mean, I had never considered making maps as an academic. Back when I was in grad school and when I finished grad school, I was more focused on running statistics, doing statistical models, and then figuring out how to present them, um, the estimates, the quantities of interest in an accessible and accurate way, right?
[00:02:44] So most of my time was spent, how do I visualize descriptive data, and then how do I then, um, visualize the statistics, the estimates that I get. Uh, so I stumbled upon maps, uh, so when I first became a dad, I think I was sleep deprived. Uh, and, uh, and we, we, my wife and I, we were taking turns with working in shifts.
[00:03:05] And so sometimes late at night, like 2 am or 3 a.M um, after a while I was into, I found out the data viz society had just started up. So this was, I think, five years ago. And I joined the Slack, I heard people talking about it, and so I joined the conversation there, and met a lot of people doing incredible work. And then people also on Twitter.
[00:03:26] Now, I had a Twitter account back in 2012 that I started, and there was a way to procrastinate from writing a dissertation, but I never used it. But through the Slack, I saw people sharing stuff on Twitter, I thought, why not go see what's happening there. And when I joined, uh, when I started using the account, I stumbled upon the work of Tyler Morganwall, right, the developer of, of RayShader and, the and rayverse And I thought the first thing I saw, I remember was, uh, he had crafted a, a, a sword made of cubes in 3D in R, and it was spinning. And I thought that was incredibly cool. And I never imagined that you could do that with R, right? Because all I knew about R was, It's a fantastic language for programming, for statistical analysis, for doing reproducible work, but not 3D rendering, right?
[00:04:18] Much less, much less maps. Um, and then the rest, as people say, right? It's history. So I started following his work, um, and then trying it out, watching development of the packages he was writing. Um, and then when Rayshader came out, uh, with maps, I thought this was just amazing. And so I tried it out. I, I loved it.
[00:04:35] I just sort of, fell in love with it. You say I just got really obsessed with, with creating it. And that's how, it's how I started and how I got into maps. So really, uh, the connection was data viz, I suppose. Um, and then just sort of just getting really excited by the things we could do with R, right?
[00:04:52] Something that I never thought possible. Um, but, but Tyler, he, you know, he, through his wizardry or sorcery, uh, managed, managed to get that, get that packages, those packages out.
[00:05:02] David Keyes: Yeah, and so at this point, the maps you make, are, do you use them at all in your academic research, or is it really just two separate interests?
[00:05:12] Terence Teo: Yeah, right now, honestly, they are separate. So it is a, it is a hobby of mine to create maps. Um, and so, although I have recently started to see that there are connections that could be made. Um, so for instance, I think lots of the work that I do with dictatorships, um, and some dictators, what they do is they, they only direct resources to people who support them.
[00:05:37] Um, And so there's a spatial component to that, right? So if you look at, you pick a country, you can see perhaps some areas of the country where the support of the dictator would get lots of, they might get pipes, they might get roads built, um, where those that don't, don't get it, right? So I, I'm starting to see that there are connections that, that we could make, um, and in political science, I think geospatial data is starting to come up, um, hasn't quite become popular, if you will, right?
[00:06:04] So there's a niche of researchers doing great work that brings in the geospatial component. But most of the time, I think the field is looking at economic data, political data, survey data, experiments. And so I think at some point, um, I have been toyed with the idea of really bringing in a geospatial component since I've been working on maps for a while now.
[00:06:26] David Keyes: Okay. Interesting. So let's talk a bit about, um, the Rayverse. So the Rayverse, you know, the verse part of it is kind of similar to the idea of like the tidyverse. It's a collection of packages. So can you talk about the packages that you typically use and kind of what they do? Because the maps you make are very unique.
[00:06:48] And again, we'll have you show that in a minute. Um, so yeah, talk through the, some of the packages that you use within the Rayverse. Yeah,
[00:07:01] Terence Teo: I use are Ray Shader, right? Which is a a 3D heel shading package that Tyler developed. Um, and then for the final product, it's also, um, a package called Ray Render. So this one is where the magic happens, um, where you take.
[00:07:16] The mesh object from ray shader, and then put it through a path tracing uh, set of algorithms that give it, that gives it that, that final, uh, blender y look, if you like, right? Where you simulate realistically how light would travel in the scene and how it would reflect and bounce off surfaces. And so that gives us that final, uh, product.
[00:07:35] Uh, in addition to, to the Rayverse, I think, because it's geospatial data mostly, um, The simple features package, right? The SF package that allows us to, our users to work with all sorts of geospatial data from lines, polygons, um, points and the like, that's something that's almost always right in, in my, in my workflow.
[00:07:54] And then there's also Elevator, right? Um, the Elevator package by Jeff Hollister. Uh, I think he works at the EPA. A fantastic package that allows us to just get rest of the data, um, From any point on the globe, right? That, and just one line of code, you give it, um, sort of, uh, the shapefile or the boundary of the country or the region, and then it pulls in elevation data from any resolution that you want.
[00:08:18] So that's also one that I, I always have in my, in my, uh, workflow. Yeah.
[00:08:24] David Keyes: because the maps that you make, so I do a lot of mapping, but it's almost always just using vector data, or, you know, yeah, it's using simple features data, not any kind of raster data, definitely not the 3D component that I think really makes your maps unique. And I think that. That, that really is the thing that, that is unique about using the kind of Rayverse is, you know, the being able to plot in what looks like 3D, having the, that light, um, I mean, I honestly, I never would have thought about that as a, as a way to make maps, but when you look at it, it gives it a really distinctive visual, um, look and feel.
[00:09:11] Um, yeah, and it's just, it's, it's really amazing. So I've talked a bit about why I like the, the Rayverse, but you've described yourself as the Rayverse's number one fan. What is it about the Rayverse that you really like so much?
[00:09:24] Terence Teo: I, I, I think what I really liked was, uh, The ease of creating sort of high quality 3D visualizations, right? So that, that was what first got me into the Rayverse, uh, what, what struck me about the final product that, that one can, one can create. Um, and then just the documentation, at least, uh, in my opinion for that, what Tyler has put out with respect to all the packages with rayshader, rayrender, and his other packages as well.
[00:09:52] Um, It's just very comprehensive and accessible. So much of what I know is from just reading the docs. And, and I think for us, we know good documentation when we see it, when we see them, right. Um, and so I had this huge appreciation for everything being very nicely laid out, all the arguments are there and then with examples.
[00:10:11] Um, and so that, that, that was another reason why, why that, and then as well, I think being in our, um, It allows us to, it gives us a canvas to explore and to experiment. So that's another reason why I really liked it. That, that it was, um, I could play with it and, and play with it in real time. So it's not like you have to wait for it to render.
[00:10:36] You can move it around. It opens up a window. You can spin it around with your mouse. You can try different things. Um, and on top and above all, it works. I think, I'm not sure if this is, it's probably something that Tyler intended. Um, it works on the principles of, of the grammar of graphics. It's like ggplot, but with a 3D capability, right?
[00:10:56] So you can add layers. And so sort of what I've, um, learned in ggplot or practiced in ggplot, I could bring it right to RayShader. And then when, when I think about these visualizations, I think in terms of adding layers on top of sort of the blank raster canvas layer, if you will. Um, And so, yeah, so I, I've been, so that's sort of why I'm so enamored with the package and, and there's just so much data out there, right.
[00:11:24] That we can, I think we can overlay on maps, um, and just play around. So that, that's sort of why, why I like it so
[00:11:32] David Keyes: Yeah. Well, it's interesting because I think You know, some people, when they think of kind of 3D data visualization, I mean, the classic is right, like the like silly Microsoft Excel, like 3D pie charts or whatever. And there's kind of a, I think because 3D has been done so poorly in the past, there's been a stigma against 3D as just, you know, it's just a terrible gimmicky way to show data.
[00:11:58] But I'm curious for you, because you've, you know, you make these maps in 3D, do you think? There's value in 3D that people might overlook.
[00:12:09] Terence Teo: Yeah, definitely. And I totally hear you about, you know, what some might call gratuitous 3D and, and, and, you know, Microsoft and things in the 90s, they were not, did not help, did not help things. But I think these days with increasing computational power, the computing power that we have, and I think judicious use of 3D, I think in general, we see the world in 3D, right?
[00:12:32] And, and it has this sort of. connection with what we actually observe. And sometimes it can give us, uh, it makes things more impactful. Now, of course, not everything needs to be 3D. In fact, maybe the majority of visualizations need not be in 3D, right? Uh, but, but if we want sort of that, that, that added, um, engagement from people, and so that's why I've seen from some of the work that, that I've put out, um, it makes people look closer, right?
[00:12:59] And so that, that I think grabbing the attention. hopefully in a positive way, allows people to explore further, and it gives people more to look at. And that's despite the issues that are, you know, to be fair, are inherent in 3D, which is the issue of perspective,
[00:13:16] David Keyes: sure.
[00:13:18] Terence Teo: things that look further away might look somewhat different.
[00:13:21] So there's some distortion if you're unable to, um, sort of manipulate the image on screen. But nonetheless, I think there is value. I don't believe really in dismissing a type of data viz outright, I think. Um, and really just being careful about when you go 3D. Um, and for my part, it's really a lot of experimentation, right?
[00:13:43] So does it look good in 3D? No, not, okay, then let's not do that. Um, yeah.
[00:13:48] David Keyes: It's interesting because the, the thing you said about 3d. Getting people's attention, I think, is something that people who just focus on, you know, kind of like, what's the right type of visualization, ignore.
[00:14:02] I mean, honestly, I wouldn't be talking to you today if your maps weren't so visually stunning and didn't, like, grab my attention. And in a world where, you know, people are scrolling, people's attention spans are limited, being able to produce something that makes people stop for a second and pay attention, I think, is, is hugely valuable, even for kind of, you know, dry academic research.
[00:14:28] I know that's not necessarily what you're using it for, but, you know, getting people to, to pay attention is, is a, can be a huge value that comes from 3D. Mm
[00:14:39] Terence Teo: and you know, sometimes you say, well, Here's a map, you want to put some stuff on it, but you don't really need shaded relief, right? You don't need to know, you know, the elevation of the country. But it just, I think, again, depending on the specific case, it does add something. It makes it look, makes people look at it again, and maybe sort of makes them pay attention, right?
[00:15:02] Beyond just, here's another flat 2D image, I see the country boundary, here's some stuff on it that I should pay attention to. But if you have some relief in the background, maybe, you know, maybe elevation actually might, might have something to say about why the points or lines are
[00:15:17] David Keyes: Right.
[00:15:18] Terence Teo: certain ways.
[00:15:19] For example, the work that I did with population density maps, I think that the sort of took off in a way that I did not expect.
[00:15:25] David Keyes: Uh huh.
[00:15:27] Terence Teo: It was less about, you know, one could say, well, just have a, you know, orthographic top down view and then, you know, use color or hue to sort of show where, where
[00:15:37] David Keyes: Yeah, yeah.
[00:15:38] Terence Teo: And that's fine, but if you add elevation, then you will see that people don't live where there are mountains, right? Um, and, and so you have where people live and where people don't live because of their physical geography. And I think that that's interesting. Um, I, I thought that was cool when, when I, when it, you know, when I first did it.
[00:15:56] Um, yeah. Yeah.
[00:16:00] David Keyes: in Oregon and I don't know how much you know about the topography of Oregon, but there are mountains that run right down the middle of the state, and I make a lot of maps in Oregon, but I've never done anything to show, you know, the mountains, which, as you were talking, I was thinking like, yeah, when I do things like show, you know, I don't know, median income or whatever outcome, you know, it doesn't make sense to, in some ways to show it without that information there because, or I mean, population density is probably a better example, right?
[00:16:34] Because obviously you're going to have lower, it's not just that those are like unpopulated areas because people choose not to live there. They choose not to live there because they're in the middle of the mountains. It's hard to, you know, it snows a lot in the winter, whatever. So, um, I think that's a really good point. Cool. So, um, I was hoping that you could walk through an example of making a map. Now, we emailed before because I know that making these 3D maps can take a while, right? Just out of curiosity, when you make a map, it's not even the coding part that takes a while, right?
[00:17:12] Like, it's the leaving it to render part. How long does that kind of thing typically take?
[00:17:19] Terence Teo: Yeah, but you're right. So you're right that the coding part actually is, is reasonably quick, right? So again, large part is the cleaning, right? The munging the data, the wrangling, getting in shape that we want. And once you get the code, uh, once you get that cleaned out, then it's pretty straightforward, um, given sort of all the tools that Tyler has built into.
[00:17:38] The rendering part is where, yes, that's where most of the, the time is spent, right? Uh, although I would say that with this, the reason why I, I'm going to, why I'm going to show, um, I can do it in, in real time is because that there's been a recent update and Tyler has been very good with updates to, to the Rayverse packages.
[00:17:57] Um, he has sped up, but usually depending on the size, so if I'm rendering the entire world, um, that can take up to a couple of hours, right?
[00:18:06] David Keyes: Oh, wow.
[00:18:06] Terence Teo: Right. So I leave it to run. It runs solely on the CPU. So it's, it's not accelerated by, by the video, by, by the video card. Uh, but if it's just a small area, right. You can take anything from a few minutes to maybe 10 minutes.
[00:18:21] Uh, yeah.
[00:18:23] David Keyes: Okay. Interesting. Um, great. Well, you want to put your screen up and kind of talk us through what you're going to show and then work through it?
[00:18:32] Sure. Sure.
[00:18:32] Terence Teo: So I think we talked about this. Uh, I'm going to show how I would render, for instance, river basins along with their rivers.
[00:18:39] And so the region we've decided on is Iberia, right? So in the Iberian peninsula, um, we're going to do that. Um, also a place where I spent a year, right. Um, uh, there, so there's something close to. to, to me. Right, so should I just get started?
[00:18:54] David Keyes: Yeah, so, um, and I'll post, this is actually a map, um, you posted it on BlueSky not too long ago, and I'll put in the show description a link to the final product, um, and then we can also post a link to the code, um, so if you're following along, don't feel like you have to copy the code as Terence goes through it.
[00:19:16] Terence Teo: Right, here's the script. You see here all I need are four packages. So tidyverse, I think we're all familiar with that. And then there's Rayer, uh, there's simple features of the SF package, and then there's geo data. And there are money in packages like geodata, like I think more recently our geo boundaries, uh, our natural earth as well. Um, you see that I, I'll use that to, to, um, get the country's shaped files right, and then just to, to make sure that, um, I set the, not, not to use the new as to, um. System over here.
[00:19:48] So I can run, I can run this. What,
[00:19:49] David Keyes: what is the S two system? I, 'cause I've seen that before and I mean, I make some maps, but like, I'm not a geospatial person. So can you explain that?
[00:19:57] Terence Teo: Yeah. Honestly, I, I, I'm also not quite sure, um, what, what it is. Um, I only know that, that there's some instances or many instances where if I were to use that and you try to.
[00:20:07] Uh, manipulate a shapefile. I think things can go wonky, uh, that way. Okay. Yeah. Yeah. Okay.
[00:20:14] David Keyes: I mean, that's been my experience too, but I, I've never understood why. So I'm glad, I'm glad I'm not the only one.
[00:20:18] Terence Teo: Yeah. So, uh, yeah, I'm not, so which is why I have to make sure I'm not a geospatial, uh, expert by any means.
[00:20:24] Uh, everything I know is self taught, uh, from experimentation, uh, and sort of just, just playing around.
[00:20:31] David Keyes: But I think that's a great, uh, point that like you don't have to be a geospatial expert in order to make really cool maps in R.
[00:20:40] Terence Teo: That's right. R for me is like a big playground.
[00:20:42] Um, and the fact that it can interface with so many other languages and you don't have to learn what they are, right? It's just incredibly cool. It gives us, gives the R user, um, Like, you know, you can write websites without knowing HTML or CSS. Yeah, right. All. So I, I'm gonna can just load these packages.
[00:21:00] Um, so four packages over here, um, and then links call over here, lines eight and nine. I have, I'm gonna tell geodata to go to, um, GADM, which is I think the general administrative. A website that contains all the country boundaries at different levels, right? So you could get it at level, you see I have it for Portugal.
[00:21:21] Um, I chose level one, so it shows the sub, the subdivisions of the country administratively. Zero would be just the country outline, right? So one would
[00:21:32] David Keyes: be kind of like whatever the Portuguese equivalent of states is? That's right,
[00:21:35] Terence Teo: that's right. Okay.
[00:21:36] David Keyes: Yep.
[00:21:37] Terence Teo: And so I'm going to run that one, and then I do the same thing for Spain.
[00:21:40] I see you're a fan of the right hand assignment. Yes, yes. I, um, I, that's how I think, I guess, to do this and then put it in, you know, and so when I teach, I make it seem like, you know, you do something and then put that in the box, right? That's the object. You
[00:21:56] David Keyes: know, it's funny. I mean, to me, that actually, it also makes more intuitive sense, but because so many of the tutorials and code that you see that people have online is the opposite.
[00:22:08] I've always. I've not done it because I don't want to confuse people. I mean, I show them that you can do this, but, um, yeah, it's interesting that that's your approach, but anyway, that's not actually what we're here to discuss.
[00:22:21] Terence Teo: Right. So, yeah, so I got Spain and Portugal and then we can look at them.
[00:22:25] And if you see that, you will see it for the Portugal. Um, so because I chose level one, I get all the states, if you will, um, in Portugal. So. I'm gonna focus on Iberia, so I'm gonna take out all the islands, uh, with, with apologies to both Portugal and, and Spain. . I know , sometimes when I do this, people say where, you know, where, where the Canary Islands or where the right.
[00:22:45] Uh, but I'm gonna take that out, uh, for this one. Yeah. So I'm gonna just, um, filter that out. Um, for Portugal, do the same thing for Spain. And then the next thing I would do is I, I want just Iberia, so Portugal and Spain. Um, again, sometimes I've done just Spain or just Portugal. Namely because when I do, when I do just Spain, people say, well, where is the part to the, to the West?
[00:23:08] So we can combine the two of them and I'm going to make sure I use this SD cast is the, from the SF package to make sure that they are merged together in a single polygon. So I'm going to do that. Um, it'll take some time and that, that's it for getting the shape file, right? So that's, um, and actually from here on, if we wanted to say render an elevation or shaded relief map.
[00:23:32] of Iberia. We can, right? With the shapefile, I can pipe, I can take it to elevator package, which we'll see later on, um, and then get a nice shaded relief of, of Iberia. Um, but for now, what I'm going to do is take, um, river and basin data from Hydrosheds, right? So this is a website, uh, that you can put it, you know, uh, there's a link to it.
[00:23:52] I can put a link to it, um, that contains all the river basins and, and rivers for the entire world. Right. So I'm going to go over here and just take out those for, for Europe, right? So they have it by continent, I believe. And so you can take the whole world as well, but that's huge. And so I just do it for, for Europe.
[00:24:12] And then you see here, so that's the Hydro basins, right? That's high bass, EU for Europe, level 0. 1 to 12. So there are different levels, right, of increasing detail. Right. So one would be very general. If you go to 12, it gets very, um, detailed. Right. So every single tiny one is there. I chose five. Right. And why, why I chose five, uh, again, I'm not a guy who studies rivers.
[00:24:40] Um, it's sort of the, the trade off between too many and too little. So, and so there are times when I share these things and I love it when, when I share it because people give me feedback, right. They tell me, look, Uh, these are not the right river basins, right? Um, and, and, and now I'll go back and try to figure out, um, you know, I should do some background research on, on how, which ones are the key ones are the important ones.
[00:25:03] Um, so it's really, as I say, it's a hobby. And so many things are just, let me just see how it looks. Let me try it out. Um, and inevitably, And it's useful sometimes when you get feedback from people who are actually experts who say that You have no clue what you're doing And I would think you're right, you know, you're right.
[00:25:23] I have no clue. I have no clue what i'm doing I'm, just trying this out and but I appreciate those that actually tell me or point me to resources that say look Maybe take a look at this. Um, and you know, this one is you know, how we would do it in our field Um, and then you know, I go look at it and and hopefully do justice to Yeah To what i'm producing.
[00:25:42] David Keyes: Yeah So is this vector data or, um, is this raster? What, what? So this is vector. So right now, this is all vector
[00:25:49] Terence Teo: data. Okay. So I'm going to, I'm going to load this. Then I'm going to, to, so this contains it for the whole of Europe. I'm going to use st intersection to only get Iberia.
[00:25:59] And
[00:26:00] Terence Teo: I'm going to pick out just the ID. So each basin has an ID, right? Uh, it's coded in this and lots of other details in that, but we don't need that. Yeah, yeah. Um, And then with maps, this is something I also learned, um, belatedly, right? Um, projections, right? So you have to, again, I had no clue about projections when I first started, like, four years ago.
[00:26:20] And I always wondered why, why does California or the US look strange when I do it from, from professional maps? And, uh, it is the coordinate reference system, right? The projections. So I'm going to transform those, uh, transform the Bayesian data, and then call it IB. So how did you
[00:26:37] David Keyes: choose the projection there that you're using?
[00:26:40] Terence Teo: Right, so this one, typically what I would do is I would Google for the official projection, and then that would take us to the EPSG website, I think EPSG. io, and there's a whole bunch of projections there. Cool. Yeah, so that's usually
[00:26:55] David Keyes: how I do these. Okay. I've started using sometimes, do you know the crs suggest package?
[00:27:01] Yeah. Oh, I'm not familiar with that. Yeah, so I I haven't tested a ton. So I mean if it doesn't work for you Um, so kyle walker who makes the tidy census package and tigris Um has made a package called crs suggest which you give it geospatial data Some kind of sf data and then it will tell you it'll recommend a Projection based on the data that you have.
[00:27:25] Terence Teo: Oh, that's terrific. I should try it out. Um, Yeah, the CRS suggests. Yeah, I'll take a look at that. That would be a lot. Yeah.
[00:27:33] David Keyes: Yeah, because yes I run into the same issue trying to figure out what the best projection is Can be a lot of work. So yes. Yes. All right. Okay,
[00:27:40] Terence Teo: cool. All right, so that's that's Bayesian data So I'm gonna do the same thing for rivers.
[00:27:44] Let me just go up a little bit so rivers here that the I have already sort of cropped out the rivers for for Iberia in part because Mm
[00:27:55] hmm
[00:27:56] Terence Teo: River data is a lot more dense. Um, it's, it's a pretty solid data set and it takes a while to run. In fact, it takes longer to extract the rivers than it does to render in high quality, as we will see later on.
[00:28:08] Interesting. So, so I've done that pre prior to I see. Okay. Yeah.
[00:28:13] David Keyes: And just for clarification, hydro basin versus river, hydro basin is what, what, what is a hydro basin exactly?
[00:28:22] Terence Teo: So, so it gives you the basin for the river. So all the other rivers that will form, um, the, the, the watershed of the specific river. I see.
[00:28:31] Okay. And for rivers, it's all the rivers. Okay. Every single, from the major ones all the way to the tiniest ones are in the rivers data set. And
[00:28:38] David Keyes: that's why the rivers data is, is huge. Cause there are a lot of rivers. Yes. Yes. Got it. Okay.
[00:28:44] Terence Teo: Yeah. Cool. So yeah, so I, I've done that sort of before our, our conversation here.
[00:28:48] And then. So I'm going to read that in and then transform it, right? Again, to make sure they're all in the same projection. Right. I'm going to do that one. And you see, even with this, it takes quite a bit longer than, than sort of reading in the EU or the Europe basin data. Um, so I've done that one. So you see now, that's done and now, so we have all the vector data we need.
[00:29:10] So, so we have the country boundary. or the Iberia's boundary. We have the basin data and we have the river data. Right. So the next step here, so that's usually my, my workflow. So I would think about, well, what do I want to overlay on a map? Right. So, my base canvas typically would be, well, it's, it's a raster, right?
[00:29:31] The raster is my canvas and what can I put on top of it? Right. I can, um, so the elevator package is over here. Right. And so you see, Um, I use the git lf raster function. I give it the boundary. Um, C tells us the resolution of the final, of the raster that we want, right? So where larger numbers indicate more detail.
[00:29:54] So if I'm working with a smaller area, you can zoom in as much as, I think it goes up to 13 before you might get a warning message about data that don't exist at the resolution. And then I wanted to clip onto the location of the boundaries of that shaped file.
[00:30:10] Okay. There are multiple ways you can do this. Um, so location does that. You can do it B box, the bounding box. So it takes outside as well. I see. I'm gonna do it that way. I'm gonna read it. So I take that and then use the terra package and the rest function to make sure it's a, the terra object.
[00:30:28] Right? I see Uhhuh . Um, and why? Because I'm gonna use Terra to repro project that Resta data. Mm-hmm . Mm-hmm . Um, okay. In the past I've used the Resta package, so if you're using the Resta package, you could use just Resta and Project Resta. Um, but I'm using Terra, so I'm gonna do this. So you will get the Elevation data from, Amazon Web Services.
[00:30:49] This will take a bit of time.
[00:30:53] David Keyes: I mean, I'm inspired like. I want to go now, make a map of Oregon. I mean, my map is going to be very simple compared to what you do, but just make something that shows the hill shading of the, you know, with the mountains in Oregon. Yes, yes, I think
[00:31:08] Terence Teo: you totally should, right? Just get Oregon shapefile, get the raster, and then you can go right into generating shaded relief.
[00:31:16] Yeah, yeah. Yeah, without having to overlay anything. I think it would look and which is how I started. It was It was, um, looking at, um, so I saw Sean Conway, he does this, he takes old maps, right. And he uses Blender to put, make it 3d with shaded relief. I think that was from Scott Reinhardt at the New York Times back about six, seven years ago now.
[00:31:36] Um, and that's how I got into it, right. That you could overlay before I started saying, you know, let's try if I could do something else. Yeah. So let me just run this, let me just reproject this and that's it. So I rect vector data, I rest the data. Now, from here on, everything is RayShader, right, so what RayShader does is it can take digital, so a digital elevation model, um, and transform it into a matrix, right, so raster to matrix, that is from RayShader, um, it gives us, it will take the elevation model and transform it into a matrix, right, so you have the coordinates and then, and then the height, so you get, get a sense of how The size of the matrix, right?
[00:32:16] It's about, it's not, that's reasonably small, right? And that's because I chose six in part because we don't really need to, uh, too much detail. And then it also increases rendering time, right? If you pick a more detailed, um, elevation model, then it takes a lot more time to render that. And so, so that's it.
[00:32:34] So at this point, let me just show you what, what you could do already with just, The Iberia shape for the country shape file and the rest are from elevation, uh, from elevator. I could just do a very quick
[00:32:52] and I would get a huge shape. Oh wow. Right. Just, just wow. Right. Just like that. Right. Um, which is one line of code. Right. So it is kind of amazing what, what Tyler has done. Yeah. So just take the matrix and then this is a, a shading algorithm and you get a map. Right. A shaded relief map. Uh, if you wanted something that is just, um.
[00:33:11] Look at the heights, so these are just defaults, and then you will get something like that, right? So a flat, right, where the mountain ranges show up. Um, yeah, yeah. So what we're gonna do is we're gonna take this as the canvas, and then we're gonna put basin data on top, and river data on top. Okay. Now, there are multiple ways to do this.
[00:33:34] So one, uh, is the same function. So rivers are made of lines. So there's a function in Ray Trader called generate line overlay. And so here's one way to do this, right? To quickly do this. Uh, but what I'm going to do is I prefer to have finer control over, um, sort of what, what I do. And so I'm going to do it manually.
[00:33:59] It's probably not the most efficient. Uh, I'm sure there are better ways people who write better code, uh, can do this in a more efficient way. But what I do is, what I did for this map was, let me just back up a second. Let's look at the basin data first, right? So the basin is a, are polygons. So there's also a function called generate polygon overlay, which I can then give it, I feed it the, the basin shapefile.
[00:34:25] So you can have your IB basin. Um, I would specify the extent of that shapefile. I wanted to just cover the extent of the, uh, Elevation model, so you have your tera, ext, right, dem. The height map, that's the matrix, so it knows the heights. I could fill, um, and then fill the polygons. In this case, I want it to be the Bayesian ID.
[00:34:51] Right, so I want, I'm telling RayShader to take this data, and for each Bayesian ID, Hybris ID, fill it with some color.
[00:35:00] David Keyes: It's basically like the aesthetic properties from ggplot idea, right? Exactly, yes. And then I
[00:35:04] Terence Teo: can specify a palette. Uh huh. And so here I'm using MoMA colors. Yeah. Right, and I just randomly picked one.
[00:35:13] So this will just sort of programmatically create, right, a polygon overlay. Now, the thing here is that if I do this, then it will sort of just assign the colors in here, and I don't like that. I've tried different ways. And, and I decided instead, I'm going to just extract out all the basins and specify each polygon manually, right?
[00:35:35] So this is where someone who, you know, I know that this is not, you know, the most efficient way, uh, but, but at least for this one, that is how I do it. And other, other ones where, uh, it's less, fewer basins, uh, then I might just go straight to just using a simple function and getting that done. So these are all just all the, uh,
[00:35:55] David Keyes: Okay.
[00:35:56] Yeah. All the
[00:35:57] Terence Teo: ID, I'm going to do that all right at one go and it's, oops. Um, did I not do this right? Let me just go back here.
[00:36:15] Oh, so I had not, I had not run that code. I think I just went through it. That's okay. Yeah. Right. So that that's done. And then I just, so now just extracted every single basin. Yep. And then this is where, so this is the default of how, So if you have just a simple one polygon, right, you could just do this, right?
[00:36:36] That's a generic polygon overlay. Give it the height map, which is the matrix. Give it the extent, which is the extent of the digital elevation model. I don't want a line. So I have line with a zero and then I specify, uh, color. So this is where I, for the most part, and I think it's the same for when you date, when you do data viz with ggplot2, it's It's figuring out the aesthetics that take the longest time, right?
[00:37:01] The right colors, making sure that it's accessible, um, enough contrast, um, playing around with the widths and all that, right? Um, and so what I've done here, just pick 19 colors, uh, 18 rather, and then they all look the same. So I'm going to just generate every single,
[00:37:23] this is running every single Bayesian in that specify. And then I'll do the same thing for rivers. Right. So for the river data, there's an, there's a variable called ORT flow, where smaller numbers indicate bigger rivers, wider, bigger rivers. And so the code I had earlier allows us, let me just scroll up for a sec.
[00:37:44] This one would just do everything all at once.
[00:37:46] David Keyes: Sure. Same idea as that one below it, right?
[00:37:49] Terence Teo: Yeah, correct. But I don't want all of them, at least for this one. So I just going to just pick out those that go from five to eight. It's a pretty quick. And the same kind of grammar, if you will, for generate line overlay, right?
[00:38:02] So again, testament to Tyler's, um, how he wrote this package was that all the overlays, uh, have the same grammar, similar arguments. So again, you see here, put in the shapefile, all the vector data, and then specify the height with the height map and the matrix, the extent, and the rest will be just, you Figuring out, you know, how you want the width of lines, the color, and so on and so forth.
[00:38:26] Yeah, yeah. And you have the same thing, there's a generate point overlay. It's the same thing, you give it the vector data, which is points now, height map, extent, and then specify how the size of the point and the color, and so on and so forth. So then I'm going to just run these. And so you see, it's taking longer each time, right?
[00:38:49] So four is very quick, right? It should go to six. Seven and eight, it takes longer. Uh, because there are more rivers. So More rivers. Yes. Smaller and smaller rivers. I see. And I'm, I'm doing this where, you know, I want the big ones to have a wider, to be wider. So that's four. I see. Yeah. 3, 2, 1. Just, um, and that's, and that's it.
[00:39:08] So we have the overlays, we have for the rivers, we have the overlays for the basins. Um, and we cannot put them all together. Right. Cool. So the ray shader, so this is the code. Um, so what I'm doing here is take the matrix and then you saw earlier when I demoed, you could use sphere shade, a shading algorithm or height shade, like, like what you have here on the page, um, since we are overlaying basin and river data, we, I chose not to do anything to it.
[00:39:36] Right. I just want a flat, um, canvas, and that will only show up once and any sort of. Shadows and light will only show up once we pass this off to render high quality. And so I'll show you what that means So constant shade, uh, that's sort of a relatively new and by that, I mean a couple of years ago Where you could create very nice looking Monochrome maps where it's just light and shadow, right?
[00:40:04] So you just so what happens
[00:40:05] David Keyes: for example, if you just run lines 110 and 111 Does that make a map?
[00:40:11] Terence Teo: Yes, so let me just, I'm going to just, um, do this real quick. So I'm going to just do this and do So it just looks like that. Oh,
[00:40:21] David Keyes: okay,
[00:40:21] Terence Teo: I see. Right? So it's, I just chose one color. And so you just see, because the magic happens with render high quality.
[00:40:29] Then you will see that there's actually elevation, uh, encoded in there, right? Now I could do, for instance, if we, let's move this to 3D for now. Um, and I'm going to talk about, about this in a sec. So if I do it in 3D, then, okay, this is, you can actually, you can actually see there's elevation, um, in it.
[00:40:53] David Keyes: Hmm.
[00:40:53] Okay.
[00:40:54] Terence Teo: Yeah. So that's, that's constant shade. I see. Okay.
[00:40:57] David Keyes: Yeah.
[00:40:59] Terence Teo: Let me, I hope
[00:41:00] David Keyes: this is so it's not like making, you know, the parts of the, Map that are higher in elevation a different color. Correct. It's just making everything that's that same light golden rod or whatever it is.
[00:41:11] Terence Teo: Yes, yes, that's a lot of the color.
[00:41:12] Okay. Yeah, in R. So I'm gonna use constant shade instead of all the other shading algorithms, and they're gonna add the overlays. So I, so add overlay, that's the first Bayesian. The alpha layer allows us to specify how the alpha parameter, right, how transparent we want it to be. So zero being completely transparent, one being completely opaque.
[00:41:32] Uh, so this is an, an aesthetic choice, right? Um, mm-hmm . I'm gonna add all of that, and then I'm gonna add the lines as well. The rivers.
[00:41:41] Mm-hmm .
[00:41:41] Terence Teo: So the ad overlay allows us to do this, and you can add all the overlays that we've created. Um, again, lines, points, uh, polygons, right? And, and buildings and, and, and, you know, all the other functions in, in Ray.
[00:41:58] So I'm gonna do that. And the final thing to bring it into 3D. is the plot 3d, right? So I could, let me just take this out for now and just do a map where all the overlays are added. I'm just changing. So I'm going to, right. So just plot map at the end that gives us.
[00:42:17] David Keyes: All right. All right. Oh, okay. So you got your map here.
[00:42:20] Terence Teo: Yes. So this is a a 2D map, right? Uhhuh . So with, with plot map is a 2D map, right? Um, and you see that I have the basins shaded by the colors I specify.
[00:42:30] Um, and then I have the river. So these are, you know, river line four, the bigger, the wider ones. And then, you know, as you go smaller, smaller rivers, um, they become, um, narrow and narrower, right? So that's cool. That's the idea. Right now. The, the magic happens. So this is just a 2D and it's useful for just making sure that everything works.
[00:42:48] Yeah. Yeah. Um, and but to, to actually get the sort of the, the Ray shader look, uh, we have to use the 3D plot, 3D function. So I'm gonna take that out and then go in into plot 3D. And so what, what it takes is first, uh, the matrix, the height map at the elevation matrix, right? The height map over here, Z Scale specifies how much vertical exaggeration we want.
[00:43:12] David Keyes: Uhhuh , right? So
[00:43:14] Terence Teo: depending on the, the resolution of the rest. Um, so you could actually, if you want to exaggerate to make the mountains look higher than they are for, um, you know, a more cinematic look or just to, uh, more artistic, uh, appearance, you can mess around with the Z scale.
[00:43:29] David Keyes: Yeah.
[00:43:30] Terence Teo: Right. So for instance, if I'm working with LiDAR data, uh, at one meter resolution, then this would be one and correspond exactly to the resolution of the LiDAR data set.
[00:43:39] Um, this one, I chose 60. Um, again, this is. From trial and error, right, and aesthetic preference, I wanted to exaggerate just enough, but not too much, because such a thing as too much exaggeration. And so 60 is the number I chose, so it goes from, you know, anything between zero, and it can go up to a few hundred, if you like, to really make it.
[00:44:05] Uh, window size will describe, will specify the size of the window that shows up, right? So this, uh, what ratio that works with is the RGL package, um, that allows us to do 3d in R, right? So this, this tells me how large of a window, um, again, if you wanted to occupy the whole screen, you could make it really big, uh, but if not, then I chose 800.
[00:44:29] So 800 means it's a square 800 by 800 pixels. That's the width, that's the size of the window. And then, these other parameters here, these other arguments, are, um, Another cool thing about Rayshader is that it makes you into a, sort of, a cinematographer, if you will. So you can play with a camera, so you can imagine, here is the scene, and where do you want the camera to be?
[00:44:53] So this says, well in this case, I want, so theta is zero, that's the rotation of the scene. Phi here is the position of the camera. So where 90 degrees is where you are right above the scene. So what they call an orthographic view. You can do 45, that's at an angle of 45 degrees. If you're at zero, then you're just looking at, you know, at it from the side.
[00:45:17] Zoom tells us how much we want to zoom in, right? So whether we're going to zoom in very close on, on, on the scene or to zoom out. And I actually just add here, there's a field of view as well that you can use. So that's like, uh, you know, whether you want it to be To see more so there'll be some distortion if you do that, but that that's helpful for certain countries like like Chile for instance Right, yeah And there are a whole bunch of other options.
[00:45:48] I just not include them here because yeah, it doesn't yeah Because this is not the final product So it is, it is possible to just say, if you specify, you can specify the shadow, the, if you want shadows, the depth of the shadow, the color of the shadows, you can specify the color of the solid base, um, you know, whether you want it to look like it's soil.
[00:46:09] Um, so it's a whole bunch of options and Tidal does an amazing job in the documentation of showing you what each option does along with examples. So I thought that was, I know that's incredible. And then I went into anti alias lines, which is really not really, I think, let's just take that out, we don't really need that.
[00:46:28] Okay. Yeah, yep, and then I'm gonna run this, and I'm gonna hope it shows up.
[00:46:38] David Keyes: So is this the part that typically takes a long time, or is it the next render high quality step that takes a while? Render high quality. Okay. Right,
[00:46:45] Terence Teo: so at this point Because this is just
[00:46:46] David Keyes: a little preview?
[00:46:47] Terence Teo: Yes. And sometimes this is sufficient, right? So if you want The, the over here, what I have not done, I have not added any shadows, which you can as well.
[00:46:58] Mm-hmm . The different functions in. So if I would to add shadows, it'll be up here. Um, there's ratio, there's ambient shape where you can add shadows to this, uh, 3D plot over here. I see.
[00:47:11] David Keyes: Okay.
[00:47:11] Terence Teo: Right. Um, but I haven't, I haven't done that, uh, in part because I'm, I'm going to use Ray Render. I'm gonna take this scene.
[00:47:19] Push it over to Ray Render and ask Ray render to use path tracing, uh, to render this. Um, so just show so I can actually move this. I see. Right. So this is, uh, I could zoom in. So that's what the zoom does. I could zoom out. Mm-hmm . Um, I could change the field of view. That's I just holding my right mouse button and just pulling it back and forth.
[00:47:40] Yeah. Right. And so I could, and see, I chose solid equal fall. So there's no, there's no solid uhhuh and just, yeah. Why, because. I view from the top, not from the side. Yeah. So it doesn't really matter for us. So I do the set to make sure that the camera is, um, is properly sent it. I'm gonna do theta equal zero.
[00:48:03] I don't, I don't want it to rotate. Um, I gonna set fee to 89.9, uh, to zoom to 0.8 and field of view to zero. Right. I'm gonna set that to make sure that it is. It looks nice and scented, uh, before we render high quality. Uh huh. And what one trick, um, is that the, for the orthographic, orthographic look where the camera is right above 89.
[00:48:29] 9 is the limit, right? So if you set it to 90, that wouldn't work. Right. Uh, it would just not, it would, it would, um, ratio would throw an error. Right. So if you want, it gets as close as possible to 90. Yeah. Yeah. That's a little trick. Uh, yeah. And then we're going to render high quality. So what this does is it, it will write this 3D scene, right?
[00:48:50] This mesh scene, um, and then send it to ray render, which is that, that path tracing package. Um, here we have a few options here. Uh, I set number of samples to 400. Again, um, the more samples, the less noise in the final render. Um, So 400 is a good thing for, for final render. You could, if you are sort of trying it out, you could set it to something very low and you'll see a lot of noise in the final image, uh, but 400, the sample method, um, there are different sample methods, uh, there is, uh, one that is faster, um, this one is a little bit longer, but I'm going to choose this one, uh, parallel equal true lets us use all the cores we have, uh, on our computer.
[00:49:35] Right. So. It will be, it's multi threaded, so you'll use all the available cores. And then we've specified the lighting, right? So we're gonna talk about light here. And this is also where it can take a very long time to play around with light, right? So then that's the cinematography aspect where it really comes up to how you light the scene.
[00:49:56] Where you want to place the light, where do you think the shadows will fall, um, whether you want a very strong focus spotlight type look with very strong shadows, or you want a more diffuse type look. Um, so what I like to do is to use, um, HDR images. So this, I got this image from Polyhaven, um, to give us a more realistic look.
[00:50:19] So this is a high resolution image captured at dawn. So you get that nice, um, diffuse light. Um, so that's where I set environment underscore light. So it takes in HDR images. It can also take in JPEGs, um, even though it's lower resolution. So you might have a couple of arguments that you can use to, to, uh, increase that.
[00:50:41] Um, so that's just the lighting, how I'm lighting the scene.
[00:50:45] David Keyes: Yeah.
[00:50:45] Terence Teo: Right. And then you can also rotate the scene. The light, I mean. So the light's an image, you can rotate that because, um, so in this case, I'm trying to get the light to come from the northwest, which is sort of the, the, the norm in, in doing these types of maps, which also I've learned from putting it online and people telling me, yeah, your light is wrong because the mountains look wrong.
[00:51:11] Um, and so this is just, you know, you can rotate the light, right? So where, where the main light source is, so that is the correct way. And since we're using, um, an HDR image, like the scene, I don't have to use RayRender's default lighting. So I have, I set light to false, and then here's the width of the final, um, image preview.
[00:51:32] I was, we will see it rendering, um, interactive so that if I click on the window, it doesn't change the scene. So RayRender allows us, if interactive is true, I can actually have it render and then go through the scene. I can move around the scene. Um, so the fly throughs that you see Tyler does sometimes, you're flying through a scene.
[00:51:53] Um, it's very hard to sort of picture it in your head in 3D, right, where the camera should be. Um, so what he did was make the window interactive. So you fly through the scene with your, you know, keyboard, and then you'll record all the camera coordinates. So you know where to put the camera. I'm going to do this, and then we will see the final result.
[00:52:18] So you see it rendering, so you start seeing that the shadows start popping out. Uh huh. Right, you see the lightning from, from the, the northwest. Uh huh. And so this is what's happening with, that's what Ray render does. And that's why we get render high quality.
[00:52:31] David Keyes: Huh. Yeah. So, okay, my, my very naive understanding, it's, um, Like the samples 400, is it making multiple versions of this and like stitching it together?
[00:52:44] What, what's, what's happening here that's making it look different, say, than the one that you made before? I mean, I can tell it's 3D, but besides that?
[00:52:54] Terence Teo: Yeah, so the one I made before is, is a flat 2D image, right? Yeah. Um, and with real, no real, no realistic light or shadow. I see. So what, what this is doing and the samples are doing is it's actually calculating, right?
[00:53:08] It's simulating light as it travels, and then when it hits the, the scene, uh, uhhuh and how many times it hits the scene and until it converges to, to a, to an image, to a pixel, if you will.
[00:53:20] David Keyes: I see. Yeah. So and so, for example, like. I can see with the shadow, at least, like in the mountains, kind of in the center there, it's sort of darker on the bottom.
[00:53:31] Yeah, exactly. Yes. Because you said the light's coming from the northwest, so it's making those, that area look darker. Is that, is that right?
[00:53:40] Terence Teo: That's right. So it's, so you're drawing a light, it's hitting this mountain range, and so it knows that this will be brighter, and then here will be darker, because light is not hitting here, it's been, it has been stopped by.
[00:53:51] by that, um, by this object over here. Um, and that's what ray, that's what path tracing does, right? It gives you, in games, it gives you realistic lighting. Um, and in this case for, with ray render in R, we get the ability to actually model how light travels through a scene realistically. Um, as you might see in, in real life.
[00:54:12] So that's what,
[00:54:12] David Keyes: I've always heard that term path tracing, but never quite known what it means. It just means like kind of displaying the, the path of light in a kind of accurate way. Is that the idea?
[00:54:23] Terence Teo: Yes, yes, and how it interacts with objects in the scene. Right, right. So if it hits, you know, if it hits a metallic object, there is a difference between hitting a metallic object or going through a glass object, right?
[00:54:37] So in this case, I haven't specified what type of Material we want the scene to be. So actually we could specify, I wanted this to be made of metal, right? We could do that in render high quality and we get a slightly different look because now we It's as if we have carved this out of metal And then shine a light on it And take a picture to see what to see what it looks like.
[00:54:56] So this is uh, yeah Yep So you can see there's a lot there's a lot of room to play with and you can make it out of glass like, you know um And then you can do, you know, caustics where, where, you know, you have light travel through a glass and you see some reflection sometimes, and sometimes, you know, um, so it's a lot of, so RayRender gives us that ability to, to play with that.
[00:55:16] And I'm also a big fan. I used to, uh, I played a lot with, with RayRender.
[00:55:20] David Keyes: Yeah, I can tell. I mean, there's so many things. I mean, as you're talking, it all makes sense that, yeah, of course, you know, if you render it with glass, it's going to look different than metal, but I've never actually thought about, you know, this when I make maps.
[00:55:33] Terence Teo: Right, so here, so this is the final. Okay. Yeah, I haven't specified a file name because I wanted it to print to the plot window, but this is now a 2000 by 2000 pixel image rendered in high quality. Okay. From RayShader, right? So we went from RayShader, all the river basins, the rivers, and the shadows you see here, I didn't, I didn't add them.
[00:55:55] They're not drop shadows, right? They're actual shadows simulated from the travel of light, right? So you get this very nice, soft shadows with this, what you might see, right? In, in, in, with your, you know, in, in reality, if, um, and, um, so parts where the light is, you see it's brighter. Yeah. Parts and then if you hit mountain ranges, it becomes darker.
[00:56:16] You see the shadow So I don't have to specify the shadow or where they are, right? Um, yeah, because it's realistic simulating of light we get There will be places where it's bright and places where it's dark. Yeah, because that's how right. Um, The physics of light is is like so that's um That's that's interesting.
[00:56:36] Yeah how this works. Um And and I also want to talk about a different package which so You Up to this point with Plot3D, that's all RayShader. Which allows us to take a matrix and extrude the height. And like I said, we could add shadows on that, but it won't be as nice as one that is path traced, which is what the RayRender package gets us.
[00:57:02] And what we get with render high quality.
[00:57:06] David Keyes: And so render high quality is from ray render, not ray shader? Ray render, yes. Yep, correct.
[00:57:12] Terence Teo: And so render high quality will call ray render from within ray shader. And render high quality is sort of the R equivalent of blender. Okay. Right, so you can actually create scenes, um, there are lots of objects you can create, um, and then have it, right, render through the simulation of light.
[00:57:32] with different materials and the like. So you can actually play with, with, if you want the map to make, be made out of a different object, different material, you can play with that. Um,
[00:57:41] David Keyes: yeah.
[00:57:42] Terence Teo: So that's, that's render high quality. And then there's one more thing I thought I would show, which is there's also a separate package, um, that, that Tyler has written called ray vertex.
[00:57:54] So this is a, a, a rasterizer, a different way of, of getting, um, 3D sort of, it will look like you also have how light would travel through a scene, but it's not as computationally intensive as render high quality. Right. Um, so I could do this, this is a snapshot. So what, what this does is a snapshot of the plot 3D scene, right, of this scene here.
[00:58:20] If I just have render snapshot, it would just take an image of that one. And render snapshot by default can only accommodate the resolution of your screen. Uh huh. So, um, if you're on 4k, 4k is the max, right? But let's say you don't want to use render high quality because it takes too long, even though with the recent update, it has sped up incredibly.
[00:58:42] I don't know what Tyler did, but it's much faster now. Uh, so render snapshot with ray vertex is another way to get, uh, sort of save an image beyond the resolution of your screen, but still retain some of the, uh, sort of the, uh. that the light and shadow effect of ray render, uh, but at a much lower computational cost.
[00:59:05] Yeah. So that means, all that means is renders faster.
[00:59:08] David Keyes: Yeah, yeah.
[00:59:08] Terence Teo: Uh, but it looks slightly different. So over here, I was going to run this code. I say, use the lighting in ray, in ray vertex. Um, I specify what the light is. Uh, I want, I want the shadows and using software render, I'm going to hit this, um, and you'll see it will show up, looks slightly different.
[00:59:28] Like that.
[00:59:29] David Keyes: Okay.
[00:59:30] Terence Teo: Yeah, so that, that's the, the ray vertex. Um, what that, what I like from this one is that it allows us to do, um, to make images look like cartoons, you know? Okay. Like 3D cartoons, like toon shading or cell shading. Um, it gives us that effect sometimes. Interesting. And, and, so one last thing was, you know, I could render a movie from this one, if I like.
[00:59:54] Okay. Um, this is from RayShader, which is just render movie, I want it to orbit around a number of frames. Yeah. Um, specify the filename, and then I
[01:00:02] David Keyes: could just keep Oh yeah, I've seen Tyler post these where the, like, the glove spins, that kind of thing, right? Yes, so you can
[01:00:05] Terence Teo: just spin around. Okay. Yeah, and it renders to a movie.
[01:00:09] David Keyes: In the code at the bottom, is that anything?
[01:00:14] Terence Teo: Oh, over here? Oh, this is if we wanted to zoom around. Okay. So this, this are camera angles. Okay. So, I, I, this is just extra stuff that, that we don't have to go through. Yeah.
[01:00:25] David Keyes: Yeah, that's fine. We'll just leave that.
[01:00:28] Um, cool. Um, well, that's great. Thank you for showing that. That's a, um, really interesting way that I have never used R. Um, yeah, and it's fun to see what's possible.
[01:00:42] Terence Teo: Yeah.
[01:00:43] David Keyes: Is there anything else you want to add about Rayshading, Rayverse stuff before I do the wrap up?
[01:00:51] Terence Teo: Um, I mean, I would say that, that really for, for people interested in this, that there are lots of people now who are doing terrific work and sharing tutorials. I mean, most of the stuff that, that I, what I've done or how I've learned this was to, Well, Tyler puts out tutorials on his website, um, that does really cool things.
[01:01:08] So that's where I, so I've got my start and then just looking at the documentation, which I think is really great. Uh, and then just trying things out. But, but that said, there are also other people who've been sort of sharing tutorials. I know Milosh, right, has been doing a great series of work on that.
[01:01:26] And, and there are many people I think now who are, um, sort of playing around with this. And it's really, I think it's just fun to play. Uh, I see this as play. Uh, and then, you know, whatever comes out, it's a bonus, right? That, that, oh, something nice has come up. Um, and, and you don't have to be an expert, I think, to do these things, right?
[01:01:48] It just, and I think this is true for most of R, right? Where you
[01:01:52] David Keyes: Yeah.
[01:01:53] Terence Teo: You have a project, you want to do something, let's see if you can do it in R, and then see where it goes with that. You
[01:01:57] David Keyes: Yeah, well, like you said before, you know, this isn't, this didn't come out of your, your academic interests. This came out of your own personal interests and wanting to make some, some interesting maps. So, um, well, this has been great, Terence. Thank you again. If people want to, uh, learn more about your work, see more examples of your work, what's, what's the best place to go?
[01:02:16] Terence Teo: Well, so I'm on Blue Sky at, at T. Terence. Um, and then I'm on Twitter as well, and the Research Remora. And so that's usually where the two main places where I, um, where I share the work that I do. Um, yeah.
[01:02:31] David Keyes: Great. Well, we will post links to both of those, uh, in the description. Um, so Terence, thanks again for joining me. I really appreciate it.
[01:02:40] Terence Teo: Yeah. Thank you so much, David. This was, this was great.
[01:02:42]
Sign up for the newsletter
Get blog posts like this delivered straight to your inbox.
You need to be signed-in to comment on this post. Login.