Latest / CyberSecurity Summary / Unity Shaders and Effects Cookbook
Transcript
- 0:00Speaker 1: Okay, let's unpack this. Today we're taking a deep dive
- 0:03Speaker 1: into the fascinating world of game visuals. We're going to
- 0:07Speaker 1: pull back the curtain on how developers craft those stunning,
- 0:10Speaker 1: immersive graphics you see in modern Unity three D games.
- 0:13Speaker 2: Right.
- 0:14Speaker 1: Our mission isn't to bury you in technical jargon, but
- 0:17Speaker 1: to cut through the complexity and extract the most important
- 0:21Speaker 1: nuggets of knowledge and insight. Yeah, make it accessible, and
- 0:24Speaker 1: we're drawing heavily from a truly fantastic resource, the Unity
- 0:27Speaker 1: Shaders and Affects Cookbook by Kenny Lammers. A book that's well,
- 0:31Speaker 1: it's a masterclass in practical recipe based learning, and it's
- 0:35Speaker 1: full of surprising facts.
- 0:37Speaker 2: That's right. This deep dive is your shortcut to being
- 0:39Speaker 2: well informed about the magic behind how games look. Think
- 0:43Speaker 2: of it as unveiling the clever illusions and powerful tools
- 0:47Speaker 2: that turn polygons into vibrant living worlds.
- 0:50Speaker 1: Yeah.
- 0:50Speaker 2: We'll explore everything from the kind of foundational building blocks
- 0:54Speaker 2: of visual effects to advance techniques that make a game
- 0:57Speaker 2: truly shine. Our goal is to help you understand not
- 1:01Speaker 2: just what shaders and effects are, but why they matter
- 1:04Speaker 2: to the final esthetic and performance of a game. And
- 1:07Speaker 2: how they contribute to that wow factor.
- 1:09Speaker 1: So we're talking about making things look good in Unity.
- 1:13Speaker 1: When you're building a game, where do you even begin
- 1:16Speaker 1: to well paint that visual masterpiece?
- 1:19Speaker 2: We begin with shaders. Imagine them as tiny, highly specialized
- 1:24Speaker 2: painters that live inside your graphics card. Well painters, Yeah, exactly.
- 1:29Speaker 2: Every surface in your game, a tree, a wall, a
- 1:31Speaker 2: character skin gets painted by a shader. Historically it was
- 1:35Speaker 2: like using a preset brush, maybe a bit rigid, But today,
- 1:38Speaker 2: with modern rendering languages like Craig and Unity's user friendly
- 1:42Speaker 2: surface shaders, developers have vastly more.
- 1:44Speaker 1: Control, more flexibility, way more.
- 1:46Speaker 2: Unity surface shadors are particularly efficient because they handle a
- 1:49Speaker 2: lot of the heavy lifting for the graphics processing unit,
- 1:51Speaker 2: the GPU, making it much smoother to customize how things look.
- 1:55Speaker 1: That sounds incredibly powerful. So we're building these custom painters,
- 1:59Speaker 1: these shaders, But how do artists who might not write
- 2:02Speaker 1: code actually use them? Is there a simple way to
- 2:04Speaker 1: tweak things?
- 2:05Speaker 2: Absolutely? That's where properties come in. Think of them as
- 2:08Speaker 2: the adjustable knobs and sliders on your shader's control panel
- 2:11Speaker 2: right in the Unity editor.
- 2:12Speaker 1: Ah okay, so the artist sees those directly.
- 2:15Speaker 2: Yep, they let artists or designers fine tune colors, textures,
- 2:18Speaker 2: or how shiny something is directly within Unity's inspector tab.
- 2:23Speaker 2: No coding required for them at that point.
- 2:24Speaker 1: That makes so much sense. So these properties literally let
- 2:28Speaker 1: you declare different kinds of inputs. You could have a
- 2:31Speaker 1: color property for a color picker.
- 2:32Speaker 2: Maybe exactly, or a range for a slider. You can
- 2:35Speaker 2: have a two D property for a texture image, a
- 2:38Speaker 2: cube for something called a cube map. We'll definitely get
- 2:40Speaker 2: to those later, okay. Or simple float values for numbers.
- 2:44Speaker 2: Eat property like a missive color or my slider value
- 2:49Speaker 2: links directly to the shader's inner workings. And the real
- 2:52Speaker 2: beauty here is you can set up a slider in
- 2:55Speaker 2: the Unity editor that, when dragged, might dynamically change how
- 2:59Speaker 2: sack traded a color is in your game, all in
- 3:01Speaker 2: real time. Wow.
- 3:03Speaker 1: Yeah, that must be a huge time saver. Empowers the
- 3:05Speaker 1: artists directly. What's fascinating here is how textures then become
- 3:10Speaker 1: more than just image files you said, They become powerful
- 3:12Speaker 1: data containers.
- 3:14Speaker 2: Indeed, think of a texture not just as a pretty picture,
- 3:18Speaker 2: but as a candice where each pixel can hold different
- 3:21Speaker 2: kinds of information.
- 3:22Speaker 1: It's quite clever like scrolling textures for effects like waterfalls, rivers,
- 3:27Speaker 1: or maybe lava flows.
- 3:28Speaker 2: Exactly, it's an illusion of movement, but incredibly effective. You're
- 3:33Speaker 2: simply shifting the textures, coordinates, the uvs over time in
- 3:37Speaker 2: the shader, often using unities built in time variable.
- 3:40Speaker 1: Just sliding the picture along basically pretty much.
- 3:43Speaker 2: And similarly animating sprite sheets. People often call them sprite atlases.
- 3:47Speaker 2: That's like creating a digital flip book.
- 3:48Speaker 1: Ah.
- 3:49Speaker 2: You're taking a large texture with many smaller images frames
- 3:52Speaker 2: of an animation, and the shader cleverly cycles through them,
- 3:55Speaker 2: using precise mathematical calculations like wad and seal to create
- 4:00Speaker 2: that smooth illusion to movement.
- 4:01Speaker 1: And here's an AHA moment, I think, especially for performance
- 4:05Speaker 1: packing textures. You mentioned storing multiple grayscale images inside a
- 4:09Speaker 1: single texture.
- 4:10Speaker 2: Yes, like a secret compartment. You use the red, green, blue,
- 4:13Speaker 2: and alpha channels, the RGBA channels to store four different
- 4:17Speaker 2: grayscale maps.
- 4:17Speaker 1: Why is that so important?
- 4:19Speaker 2: Memory textures eat up memory, especially on mobile. Packing them
- 4:23Speaker 2: like this drastically shrinks your app size. It's a huge optimization.
- 4:27Speaker 1: Okay, so you pack them save memory, then.
- 4:30Speaker 2: What then the shader can intelligently blend these hidden images
- 4:34Speaker 2: together on a surface. You use the LURP function linear
- 4:38Speaker 2: interpolation to smoothly transition between say, grass, dirt, and rock
- 4:44Speaker 2: on a terrain model, all from one tiny file.
- 4:46Speaker 1: That sounds incredibly useful for detailed environments it is.
- 4:49Speaker 2: And then there's normal mapping. This was well a truly
- 4:52Speaker 2: genius technique that let games leak forward visually without tanking performance.
- 4:57Speaker 1: Right, making things look bumpy without adding actual polygons.
- 5:00Speaker 2: Instead of requiring complex high polling models. A normal map
- 5:04Speaker 2: uses a special texture where pixel colors represent surface direction.
- 5:08Speaker 2: It tells the light how to bounce off, faking intricate
- 5:10Speaker 2: detail on a.
- 5:11Speaker 1: Low poly mesh like optical illusion geometry kind of.
- 5:15Speaker 2: Unity even has helpers like unpack normal to make it easier,
- 5:19Speaker 2: and you can control the intensity with a shader property
- 5:22Speaker 2: like a normal map intensity slider.
- 5:24Speaker 1: It doesn't stop there, though. What if you need patterns
- 5:27Speaker 1: that aren't in a file, or need to adjust textures
- 5:29Speaker 1: on the fly.
- 5:30Speaker 2: Well, you can create procedural textures dynamically within the Unity
- 5:34Speaker 2: editor using c sharp.
- 5:36Speaker 1: Scripts, generating them with code.
- 5:38Speaker 2: Yeah, you can generate patterns, shapes, maybe gradulate distances to
- 5:41Speaker 2: create rings or gradients. You can even replicate Photoshop levels
- 5:45Speaker 2: effects directly in your.
- 5:46Speaker 1: Shader, like adjusting brightness and contrast in real.
- 5:49Speaker 2: Time exactly adjust brightness contrast gamma using functions like max
- 5:55Speaker 2: to clamp values. Precise artistic control, but generated dynamically.
- 6:00Speaker 1: Okay, so we've painted surfaces use textures as smart data.
- 6:04Speaker 1: But what about making things really shine and reflect the
- 6:07Speaker 1: world around them that metallic glint or waterychine.
- 6:10Speaker 2: Right, That's where specularity comes in. It describes how shiny
- 6:13Speaker 2: an object is, and crucially, it's a view dependent.
- 6:16Speaker 1: Defect, meaning it changes based on where I'm standing.
- 6:19Speaker 2: Precisely the highlight moves as you move around the object.
- 6:23Speaker 2: A core concept here is the half vector, which is
- 6:26Speaker 2: sort of an efficient way to calculate where that highlight
- 6:29Speaker 2: should be between the light source and your viewpoint. Unity
- 6:32Speaker 2: provides a built in blind fong lighting model that's very
- 6:36Speaker 2: common and pretty efficient for this.
- 6:37Speaker 1: But you're not limited to just the built in options, right?
- 6:40Speaker 1: Can artists get more granular control?
- 6:43Speaker 2: Oh? Absolutely not limited. You can write your own custom
- 6:45Speaker 2: shine models and masking specula with textures gives artists incredible
- 6:49Speaker 2: pixel level control.
- 6:51Speaker 1: So using a texture as a stencil for shininess.
- 6:54Speaker 2: Exactly a grayscale texture, where black means matt and white
- 6:57Speaker 2: means full shine. This leads to tech niques for simulating
- 7:01Speaker 2: different material properties, think metallic versus soft speculat.
- 7:05Speaker 1: Like brushed metal versus say, plastic.
- 7:07Speaker 2: Precisely, you can mimic different roughness levels or even at
- 7:11Speaker 2: a fresnel term. That's the effect where reflections get stronger
- 7:13Speaker 2: at glancing angles, like on water or car paint. And
- 7:16Speaker 2: for really specialized surfaces like brush metal or even hair,
- 7:20Speaker 2: there's anisotropic speculator that uses a normal map not just
- 7:24Speaker 2: for bumps, but to define the direction of the highlight,
- 7:27Speaker 2: making it stretch along the grain usually needs a slightly
- 7:31Speaker 2: more powerful shader model like three.
- 7:33Speaker 1: Point zero reflections. Then, equally important for realism, how do
- 7:37Speaker 1: we get objects to actually mirror their surroundings.
- 7:40Speaker 2: The key there is cube maps. Remember the cube property type.
- 7:43Speaker 1: Yeah, you mentioned we'd get back to those right.
- 7:45Speaker 2: So imagine taking six photos up, down, left, right, forward, backward,
- 7:49Speaker 2: all from one point, stitch them together into a cube.
- 7:52Speaker 2: That's your cube map. It captures the entire environment around an.
- 7:56Speaker 1: Object, like wrapping the object in a photo box.
- 7:59Speaker 2: Pretty much, you can create cube maps directly in Unity,
- 8:02Speaker 2: using a function called rendered a cube map, often with
- 8:05Speaker 2: a little menator helper tool for static scenes, or use
- 8:08Speaker 2: external tools like Ati cube map gen for more control.
- 8:11Speaker 1: Okay, so you've got your environment, box, your cube map.
- 8:14Speaker 1: How does the shader use it?
- 8:15Speaker 2: Unity makes simple cube map reflection surprisingly easy. The shader's
- 8:20Speaker 2: input data usually have a built in vector, often called
- 8:23Speaker 2: world refle that automatically calculates the correct reflection direction based
- 8:28Speaker 2: on the surface normal and view angle.
- 8:30Speaker 1: So it knows where to look into the cube exactly.
- 8:32Speaker 2: Then you just use the text key function to sample
- 8:35Speaker 2: that cube map at that direction and boom you get
- 8:37Speaker 2: the reflection color.
- 8:38Speaker 1: And just like with speculator, I assume you can control
- 8:41Speaker 1: where it reflects.
- 8:42Speaker 2: Yep, you can mask reflections using another grayscale texture black
- 8:46Speaker 2: for no reflection, white for full reflection, same principle.
- 8:49Speaker 1: And combining normal maps with reflections for bumpy reflective surfaces.
- 8:54Speaker 2: Absolutely, That's where it gets really convincing. You need to
- 8:57Speaker 2: access the surface normal after it's been modified by the
- 9:00Speaker 2: normal map. Unity provides ways to do this, often using
- 9:04Speaker 2: something called internal data. Then you use a function like
- 9:07Speaker 2: world reflection vector to calculate the reflection direction based on
- 9:10Speaker 2: that bumpy normal the reflection gets realistically perturbed.
- 9:14Speaker 1: Makes sense, So the bumps distort the reflection, right, And.
- 9:18Speaker 2: You mentioned fresnel reflections earlier with specularity, same applies here,
- 9:22Speaker 2: very common for making reflections pomp at glancing angles looks
- 9:25Speaker 2: great on water glass car paint.
- 9:27Speaker 1: And can these reflections be dynamic update in real time?
- 9:31Speaker 2: They can, but it's computationally expensive. You can build dynamic
- 9:34Speaker 2: cube map systems that maybe swap between precaptured cube maps
- 9:38Speaker 2: based on where the object is, or even re render
- 9:41Speaker 2: the cube map periodically in real time.
- 9:43Speaker 1: So needs careful scripting. Maybe checking distances.
- 9:46Speaker 2: Exactly use c sharp scripts, maybe with execute an edit
- 9:49Speaker 2: mode for editor previews, check distances using vector three, do
- 9:53Speaker 2: distance and trigger cube map updates or swamps. It's powerful,
- 9:57Speaker 2: but needs optimization. So if we connect this to the
- 10:00Speaker 2: bigger picture, beyond the fundamental shine and color from diffuse
- 10:03Speaker 2: in speculator lighting, custom lighting models let you achieve incredible
- 10:07Speaker 2: visual fidelity, especially for really complex or unique surfaces, things
- 10:12Speaker 2: that standard lighting just doesn't capture.
- 10:13Speaker 1: Well, what's one of the more maybe unconventional approaches to lighting.
- 10:17Speaker 1: You see something that doesn't rely on standard lights in
- 10:19Speaker 1: the scene.
- 10:20Speaker 2: One really interesting one is the lits sphere lighting model.
- 10:23Speaker 2: You might hear it called Matt caps, especially if you've.
- 10:26Speaker 1: Used z brush Matt caps. Okay, how does that work.
- 10:29Speaker 2: It's a form of image based lighting. Basically, the entire
- 10:32Speaker 2: lighting and shading of an object, highlights, shadows, everything is
- 10:36Speaker 2: baked into a single two D texture, which looks like
- 10:39Speaker 2: a picture of a sphere lit in a certain way.
- 10:42Speaker 1: So you map that sphere image onto your object sort of.
- 10:45Speaker 2: Yeah. The shader uses the object surface normal relative to
- 10:49Speaker 2: the camera to look up the color on this sphere map.
- 10:52Speaker 2: The big catches. This lighting is completely fake in a way.
- 10:56Speaker 2: It doesn't react to scene lights at all.
- 10:58Speaker 1: Ah, so it's always lit the same way relative to.
- 11:00Speaker 2: The camera, exactly locked to the camera's view. But you
- 11:03Speaker 2: can swap out the Matt cab texture to instantly change
- 11:06Speaker 2: the perceived lighting and material. It's very fast, great for
- 11:09Speaker 2: stylized looks or sculpting previews.
- 11:11Speaker 1: Interesting shortcut. What else in image based lighting?
- 11:14Speaker 2: Another technique is the diffuse convolution lighting model. This uses
- 11:17Speaker 2: a preprocess sort of blurred cube map to simulate soft
- 11:22Speaker 2: diffuse ambient lighting from the environment.
- 11:24Speaker 1: So capturing the general color of the surroundings precisely.
- 11:27Speaker 2: It gives you that nice effect where an object picks
- 11:29Speaker 2: up ambient color from say a blue sky above and
- 11:33Speaker 2: green grass below. I think ambient cube shading a convolution
- 11:36Speaker 2: or blurring process is too slow for real time, but
- 11:38Speaker 2: you pre calculate it great for static scenes or cinematics.
- 11:42Speaker 2: For that realistic environmental downslid. It often uses the world
- 11:45Speaker 2: normal vector function to sample this blurred cube map.
- 11:48Speaker 1: Okay, so you have these specialized models, but then you
- 11:51Speaker 1: start combining things. Right, what's a good example of a
- 11:54Speaker 1: material that pulls multiple techniques together.
- 11:56Speaker 2: The vehicle paint lighting model is a perfect example. It's
- 11:59Speaker 2: not just one simple effect. It's often a sophisticated blend.
- 12:03Speaker 2: You might use special BRDF textures B or bidirectional reflectance
- 12:08Speaker 2: distribution function basically textures that define how light reflects differently
- 12:13Speaker 2: based on viewing and light angles. So you use those
- 12:15Speaker 2: for the diffuse color, maybe get that subtle color shift
- 12:18Speaker 2: you see on cars, and you combine it with cue
- 12:20Speaker 2: AAPS for the sharp clearcoat reflections. It really brings many techniques.
- 12:24Speaker 1: Together, right, that complex layered Look what about something really
- 12:28Speaker 1: organic like skin that seems incredibly hard to get right.
- 12:32Speaker 2: Oh. Skin shading is notoriously tricky because light doesn't just
- 12:36Speaker 2: bounce off skin, It penetrates and scatters underneath, called subsurface scattering.
- 12:41Speaker 1: How do shaders even fake that?
- 12:43Speaker 2: Well? The diffuse part often uses a BRDF lookup texture
- 12:47Speaker 2: specifically designed to simulate that light scattering, and the speculator
- 12:51Speaker 2: or shine is complex too. It usually incorporates fresmal effects
- 12:55Speaker 2: and maybe some rim lighting techniques to give that soft,
- 12:58Speaker 2: waxy highlight you see on skin. It often relies on
- 13:01Speaker 2: calculating things like blurred normals and surface curvature.
- 13:04Speaker 1: Curvature like how quickly the surface is bending.
- 13:07Speaker 2: Yeah, Using functions like fwidth to find sharp changes in
- 13:10Speaker 2: length to measure how sharp they are helps find details
- 13:13Speaker 2: like pores or wrinkles to subtly affect the lighting.
- 13:15Speaker 1: Wow. And for cloth shading, getting that fabric look a.
- 13:18Speaker 2: Common technique there involves detail normal maps and detailed textures.
- 13:22Speaker 1: Using two normal maps.
- 13:23Speaker 2: Yeah, you overlay a fine tiling normal map representing the
- 13:28Speaker 2: weave pattern on top of the main normal map for
- 13:30Speaker 2: the folds. This achieves a higher level of micro detail,
- 13:34Speaker 2: helping to break up and realistically disperse the speculator highlights
- 13:37Speaker 2: across the tiny fibers makes it look much more like
- 13:40Speaker 2: actual fabric.
- 13:41Speaker 1: We've covered a lot on making things look solid, shiny, reflective,
- 13:46Speaker 1: but what about the opposite, making things see through? Transparency
- 13:50Speaker 1: seems simple, maybe just an alpha channel, but you mention
- 13:53Speaker 1: it causes issues.
- 13:54Speaker 2: It does, especially with draw order. Creating transparency with alpha
- 13:58Speaker 2: is the fundamental part. Yes, you add an alpha parameters
- 14:01Speaker 2: your shadeer's set up the hashtag pragma statement telling unity
- 14:04Speaker 2: it can be transparent. Then you feed a value, usually
- 14:06Speaker 2: from a texture's alpha channel to the O alpha parameter
- 14:09Speaker 2: in your output. Zero is fully transparent, one is opaque.
- 14:12Speaker 1: Okay, standard stuff. But then there's the transparent cutoff shader.
- 14:15Speaker 1: How's that different?
- 14:16Speaker 2: Right? Cutoff uses an alpha test variable name parameter. Instead
- 14:19Speaker 2: of blending smoothly, it acts like a switch. If the
- 14:22Speaker 2: alpha value is below a certain threshold the variable name
- 14:26Speaker 2: the pixel is completely discarded, fully transparent. If it's above,
- 14:30Speaker 2: it's fully opaque, no in between grays.
- 14:33Speaker 1: Why use that performance often?
- 14:35Speaker 2: Yes, especially historically, it avoids some blending complexities. But counterintuitively,
- 14:41Speaker 2: the source points out that on some mobile GPUs, doing
- 14:44Speaker 2: that per pixel test for the cutoff can actually be
- 14:47Speaker 2: more expensive than regular alpha blending depends on the hardware architecture.
- 14:50Speaker 1: Huh. Interesting, So this draw order problem, how does Unity
- 14:54Speaker 1: handle stacks of transparent things.
- 14:56Speaker 2: That's where depth sorting with rendered cues comes in. Normally,
- 14:59Speaker 2: a Unity draw solid objects from front to back using
- 15:02Speaker 2: the depth buffer or Z buffer to make sure closer
- 15:05Speaker 2: things cover farther things. Transparent objects are usually drawn after
- 15:08Speaker 2: solid ones sorted back to front, back to front. Why
- 15:11Speaker 2: so that you can see farther transparent objects through closer
- 15:14Speaker 2: ones correctly. But you can override this default sorting using
- 15:18Speaker 2: tags in your shader. You can set tags q transparent ten,
- 15:22Speaker 2: for example, to force an object into a specific drawing
- 15:25Speaker 2: order within the transparent group.
- 15:26Speaker 1: So you can layer them manually if needed.
- 15:28Speaker 2: Exactly. Unity has built in queues like background geometry, alpha test,
- 15:33Speaker 2: or cutoff shaders transparent and overlay, and a crucial tag
- 15:37Speaker 2: for transparent objects is z write off. This tells Unity
- 15:40Speaker 2: not to write the object's depth information into the depth buffer,
- 15:44Speaker 2: which is essential for letting things behind it render correctly.
- 15:47Speaker 1: Okay, that makes sense. So a practical example maybe GUI
- 15:51Speaker 1: and transparency like three D interfaces floating in the world.
- 15:54Speaker 2: Perfect example, you might create a cool three dui using
- 15:57Speaker 2: texture sheets with alpha channels for buttons or readouts. When
- 16:01Speaker 2: those UI elements get very close together, maybe overlapping slightly,
- 16:04Speaker 2: Unity's automatic sorting might flicker or get confused.
- 16:07Speaker 1: Right, you see that Z fighting sometimes exactly.
- 16:10Speaker 2: So this is where a small C sharp script, maybe
- 16:13Speaker 2: using execute and edit mode so it runs in the editor,
- 16:16Speaker 2: becomes invaluable. It can let you dynamically adjust the Q
- 16:19Speaker 2: values for individual UI materials right there in the inspector.
- 16:22Speaker 2: It gives you that fine grained Photoshop like layer control
- 16:26Speaker 2: over your three DUI.
- 16:27Speaker 1: Elements, super useful for complex interfaces. Now, moving beyond just
- 16:32Speaker 1: surface appearance. Vertex magic, you mean, shaders can actually change
- 16:36Speaker 1: the shape of the model precisely.
- 16:38Speaker 2: There's a special function within a shader, the vertex function,
- 16:41Speaker 2: that runs once for every single point or vertex that
- 16:43Speaker 2: makes up the three D model. Inside this function, you
- 16:47Speaker 2: can manipulate that vertex's position, it's color, even it's textra
- 16:50Speaker 2: coordinates uves before it even gets rendered.
- 16:53Speaker 1: WHOA, so you can access a vertex color in a
- 16:55Speaker 1: surface shader. Models can store colored data per point.
- 16:58Speaker 2: They can often export of and three D modeling software.
- 17:01Speaker 2: You can retrieve this using a specific infesststructure like ap
- 17:04Speaker 2: data full and passed along. This float for color variable
- 17:07Speaker 2: can hold RGB and even an alpha value for extra
- 17:09Speaker 2: data right there on the vertex.
- 17:11Speaker 1: What can you do with that vertex data?
- 17:13Speaker 2: All sorts of cool stuff. You can animate vertices in
- 17:15Speaker 2: a surface shader. Imagine making a flag ripple realistically. Instead
- 17:19Speaker 2: of complex bones and skinning, you just apply a sine
- 17:22Speaker 2: wave using the sin function to the vertex positions based
- 17:26Speaker 2: on time.
- 17:27Speaker 1: So the shader itself makes the flagwave.
- 17:29Speaker 2: Yeah, or create ocean waves pulsating effects, all without traditional
- 17:32Speaker 2: animation systems. You could also use Vertex color for terrains
- 17:36Speaker 2: to blend textures. For instance, paint Vertex colors onto your
- 17:40Speaker 2: terrain mash, maybe red for rock, green for grass, and
- 17:43Speaker 2: use those colors in the shader to control the blend.
- 17:45Speaker 2: Combined with a height map, this lets you get really
- 17:48Speaker 2: detailed blending in crevasses and on hillsides. Games like Uncharted
- 17:52Speaker 2: in Gears of War made this popular for their stunning environments.
- 17:55Speaker 2: This all sounds incredibly powerful, but it does raise important question.
- 17:59Speaker 2: With all these techniques layering effects, maybe animating vertices, how
- 18:04Speaker 2: do we keep things running smoothly? Especially on say, mobile devices,
- 18:08Speaker 2: How do we manage performance?
- 18:10Speaker 1: That's the critical question, isn't it? What makes a shader
- 18:13Speaker 1: cheap or efficient? It's not always obvious.
- 18:15Speaker 2: It's not, but generally it means optimizing a few things,
- 18:20Speaker 2: minimizing memory usage for variables, keeping the number of texture
- 18:23Speaker 2: lookups low, and writing efficient code logic within the shader itself,
- 18:28Speaker 2: fewer calculations per pixel.
- 18:30Speaker 1: Basically, how do you even measure that? How do you
- 18:32Speaker 1: know if a shader is slow?
- 18:34Speaker 2: Unity's built in profiler is your absolute best friend here.
- 18:37Speaker 2: It's like an EKG for your game.
- 18:39Speaker 1: Okay.
- 18:39Speaker 2: Lets you track GPU usage, CPU usage and specifically rendering performance.
- 18:44Speaker 2: Frame by frame. You can see details like draw calls,
- 18:47Speaker 2: how many separate things are being drawn, and the actual milliseconds.
- 18:50Speaker 1: Spent rendering, so you can pinpoint bottlenecks exactly.
- 18:53Speaker 2: Profiling might clearly show that adding just one more texture
- 18:56Speaker 2: lookup and ALERP function for blending significantly increases the render
- 19:00Speaker 2: time for certain objects, guiding you directly to where optimization
- 19:03Speaker 2: is needed.
- 19:04Speaker 1: And what about specifically modifying shaders for mobile? Are there
- 19:07Speaker 1: common tricks?
- 19:08Speaker 2: Yeah? There are definitely mobile specific considerations. You might use
- 19:12Speaker 2: simplified lighting functions like a proxview or half as view,
- 19:15Speaker 2: which are faster but slightly less accurate. You might declare
- 19:19Speaker 2: variables using fixed or half precision instead of full float
- 19:22Speaker 2: to save memory.
- 19:23Speaker 1: And bandwidth smaller numbers basically right.
- 19:26Speaker 2: You might also use directives like no forward ad to
- 19:28Speaker 2: limit complex per pixel lighting to only one directional light,
- 19:32Speaker 2: significantly cutting down calculations, or explicitly state no light mapping
- 19:37Speaker 2: support if you're not using baked lighting to prevent the
- 19:40Speaker 2: shader from doing unnecessary checks. Yeah, it's always a trade off.
- 19:44Speaker 2: Balancing visual fidelity with the performance constraints of your target
- 19:48Speaker 2: hardware makes sense.
- 19:49Speaker 1: It sounds like you could end up with lots of
- 19:51Speaker 1: slightly different versions of shaders, though, how do you manage
- 19:54Speaker 1: that complexity.
- 19:55Speaker 2: That's where modularity comes in. Making your shader world modular
- 19:59Speaker 2: with c includes is crucial. Think of them like shared
- 20:02Speaker 2: code libraries or header files and C plus plus hand.
- 20:05Speaker 2: Unity already provides several built in siege include files. Unity
- 20:10Speaker 2: CG dot c jink is a big one, full of
- 20:12Speaker 2: helper functions for common tasks like calculating luminance for desaturation
- 20:16Speaker 2: effects lighting. Dot cjinc defines the standard built in lighting
- 20:20Speaker 2: models like blindphone.
- 20:22Speaker 1: But the real power is making your own.
- 20:23Speaker 2: Absolutely you can create your own cg include files, dot
- 20:26Speaker 2: caging files. You wrap your custom lighting models, helper functions,
- 20:30Speaker 2: maybe common variable declarations inside preprocessor directives like hashtag, if
- 20:35Speaker 2: def hashtag define and hashtag NF.
- 20:38Speaker 1: So you define a block of code once and.
- 20:41Speaker 2: Then you just hashtag include my customs stuff, dot cgenejink
- 20:44Speaker 2: at the top of any shader that needs it. It
- 20:46Speaker 2: keeps your shaders clean, avoids repetition, and makes updates much easier,
- 20:49Speaker 2: super efficient workflow.
- 20:51Speaker 1: That sounds way better than copying and pasting code everywhere.
- 20:53Speaker 2: Oh it is. And you can even use hashtag defined
- 20:56Speaker 2: directives within your main shaders to build shaders with multiple
- 20:59Speaker 2: states or feet feat How does that work? You could
- 21:01Speaker 2: write your lighting code inside and hashtag if stiff my
- 21:04Speaker 2: cool feature hashtag end off block. Then maybe in your
- 21:07Speaker 2: material inspector or via script, you can enable or disable
- 21:10Speaker 2: that hashtag define. Unity shader compiler will then create different
- 21:14Speaker 2: compiled versions, one with the feature, one without, all from
- 21:17Speaker 2: the same source file. Immense flexibility without managing dozens of
- 21:21Speaker 2: near identical shader files.
- 21:22Speaker 1: Okay, that's really clever for managing variations So we've built
- 21:26Speaker 1: our objects, lit them, maybe made them transparent or wavy,
- 21:29Speaker 1: But what about that final polish, that cinematic look. How
- 21:33Speaker 1: do artists tweak the entire screen image?
- 21:36Speaker 2: Ah? Now you're talking about screen effects, often called post
- 21:39Speaker 2: effects or post processing. This is where the real magic
- 21:43Speaker 2: often happens for mood and.
- 21:44Speaker 1: Style, So effects applied after everything else is drawn.
- 21:47Speaker 2: Exactly, you grab the entire rendered image of your game
- 21:49Speaker 2: just before it's shown, process all its pixels on the
- 21:52Speaker 2: GPU using another shader, a post effect shader, and then
- 21:55Speaker 2: slap that altered image back onto the screen. It's like
- 21:58Speaker 2: having photoshop layers and filters running over your live game view.
- 22:01Speaker 1: How do you set that up? In Unity?
- 22:02Speaker 2: It typically involves the script system. You attach a c
- 22:05Speaker 2: sharp script to your camera. That script uses unities on
- 22:09Speaker 2: render image function, which gets called after the scene is rendered.
- 22:13Speaker 2: Inside that function, you use graphics dot blit. This takes
- 22:16Speaker 2: the source render texture the current screen image, passes it
- 22:19Speaker 2: to your post effects shader. The shader does its magic
- 22:21Speaker 2: in its frag function fragment function, and blit puts the
- 22:25Speaker 2: result back onto the screen. Usually requires Unity pro or
- 22:28Speaker 2: now it's often part of the Universal render pipeline or
- 22:31Speaker 2: high definition render pipeline features.
- 22:33Speaker 1: Okay, so you have this pipeline, what kind of things
- 22:35Speaker 1: can you easily do? Basic color correction?
- 22:37Speaker 2: Absolutely, you can easily control global brightness, saturation, and contrast
- 22:42Speaker 2: a function in your shad maybe contrast saturation brightness can
- 22:46Speaker 2: adjust these values. Brightness calculation often uses standard luminance COEFT
- 22:50Speaker 2: values based on how humanized perceive color, and you use
- 22:53Speaker 2: LERP functions to blend between the original and adjusted color smoothly.
- 22:57Speaker 1: What about those basic Photoshop like blend mode like multiply.
- 23:01Speaker 2: Or screen yep, totally doable. Multiply is simple. Just multiply
- 23:04Speaker 2: the pixel color from the render texture with the color
- 23:07Speaker 2: from another blend texture. Channel by channel darkens the image
- 23:10Speaker 2: add sums them, brightening it. Screen blend is a bit
- 23:13Speaker 2: more math. Invert both textures, multiply them, then invert the
- 23:17Speaker 2: result again. Gives a nice brightening effect that preserves whites.
- 23:20Speaker 2: Each one is just a precise mathematical formula applied per pixel.
- 23:24Speaker 1: And what about a more complex one like overlay blend mode?
- 23:27Speaker 2: That was cool? It uses conditional checks for each pixel
- 23:30Speaker 2: and color channel. It checks if the blend texture's value
- 23:32Speaker 2: is less than point five. If it is, it applies
- 23:36Speaker 2: a formula similar to multiply. If it's greater than or
- 23:39Speaker 2: equal to point five, it applies a formula similar to screen.
- 23:43Speaker 2: It creates a nice contrasty blend that preserves mid tones.
- 23:46Speaker 2: Again just math, but give sophisticated artistic.
- 23:49Speaker 1: Control beyond just global adjustments. How are these screen effects
- 23:52Speaker 1: used for gameplay and screen effects to really enhance immersion? Oh?
- 23:55Speaker 2: All the time. These effects can be triggered by in
- 23:58Speaker 2: game events to dramatically change the mood, signal, danger, simulate conditions.
- 24:03Speaker 2: It's huge for immersion.
- 24:05Speaker 1: Like what give me an example.
- 24:06Speaker 2: Okay, take the old movie screen effect. That's not just
- 24:09Speaker 2: turning a grayscale. That's a combination of effects.
- 24:11Speaker 1: Right, needs more than just desaturation.
- 24:13Speaker 2: Yeah, you'd add a cpio tone for that brownish vintage look.
- 24:17Speaker 2: You'd add a vignette effect, darkening the corners and edges
- 24:19Speaker 2: like lightfall off from an old projector bulb. And crucially,
- 24:23Speaker 2: you'd overlay animated dust and scratches textures animated. Ah, you
- 24:28Speaker 2: scroll the uvs for the dust scratch texture over time,
- 24:32Speaker 2: maybe using unity sind time or just time, and maybe
- 24:35Speaker 2: add a random value multiplied in to make it flicker
- 24:38Speaker 2: or jump slightly, simulating film imperfections. The cpiotone often uses
- 24:42Speaker 2: specific YIQ color space values for accurate luminance calculation before tinting.
- 24:48Speaker 1: That sounds really convincing. What about another classic like night vision?
- 24:51Speaker 2: Ah, yeah, the staple of many first person shooters. That's
- 24:54Speaker 2: another combo of effect. You need that distinct tinted green
- 24:57Speaker 2: overlay obviously, but then you add scan lines, faint horizontal lines.
- 25:01Speaker 2: You add some noise or grain to simulate the sensor noise.
- 25:04Speaker 2: You definitely add vignette, often quite strong, simulating looking through
- 25:08Speaker 2: a circular scope. And for extra polish, maybe some lens distortion.
- 25:12Speaker 1: Lens distortion like Fishie.
- 25:15Speaker 2: A little bit. Yeah, using functions like barrel distortion to
- 25:18Speaker 2: slightly curve the edges of the screen outwards. It all
- 25:21Speaker 2: comes together to sell the effect of looking through a device,
- 25:26Speaker 2: not just seeing a green screen changes your whole perception.
- 25:28Speaker 1: Wow. Okay, So from the absolute basics of surface shaders
- 25:32Speaker 1: and the power of making things adjustable with properties.
- 25:36Speaker 2: Yeah, all the way to transforming textures into data, faking detail,
- 25:39Speaker 2: making things shine.
- 25:40Speaker 1: Creating dynamic reflections that really mirror the world, even bending
- 25:44Speaker 1: and animating the models themselves with Vertex Magic.
- 25:47Speaker 2: Right through optimizing for different platforms, making your code reusable
- 25:50Speaker 2: with includes.
- 25:51Speaker 1: And finally layering on those screen effects for that cinematic
- 25:54Speaker 1: polish or gameplay feedback. We've really journeyed through the whole
- 25:58Speaker 1: pipeline of Unity's visual effects.
- 26:00Speaker 2: Indeed, this deep dive should hopefully arm you with a
- 26:04Speaker 2: much better understanding of how to make your Unity projects
- 26:06Speaker 2: not just look good, but look stunning, run efficiently, and
- 26:10Speaker 2: feel deeply immersive. You've got a solid foundation now to analyze,
- 26:15Speaker 2: maybe debug, and certainly create more sophisticated visual experiences. You
- 26:19Speaker 2: know the tricks behind the curtain.
- 26:20Speaker 1: Now, So what does this all mean for you the listener?
- 26:23Speaker 1: Given this incredible power of shaders not just to paint pixels,
- 26:26Speaker 1: but to store data, change shapes, simulate physics, alter perception,
- 26:31Speaker 1: what unthought of visual experience could you create by combining
- 26:35Speaker 1: just two of these techniques that maybe aren't normally paired together.
- 26:38Speaker 2: Yeah, Like, what if procedural textures didn't just create patterns,
- 26:42Speaker 2: but actively drove the parameters of a complex cloth shader
- 26:46Speaker 2: in real time?
- 26:47Speaker 1: Or what if Vertex animation wasn't just cosmetic but somehow
- 26:50Speaker 1: reacted dynamically to screen space, blend modes being applied. What unexpected,
- 26:54Speaker 1: artistic or gameplay frontiers could you explore by smashing these
- 26:57Speaker 1: powerful tools together in new ways