Beginner's shader tutorial (Panda3D but general)

Beginner's shader tutorial (Panda3D but general)

Postby Julius » 13 May 2019, 18:27

Might be interesting for some of the developers here: ... -beginners

3D Game Shaders For Beginners

Interested in adding textures, lighting, shadows, normal maps, glowing objects, ambient occlusion, and more to your 3D game? Great! Below is a collection of shading techniques that will take your game visuals to new heights. I've explained each technique in such a way that you can take what you learn here and apply/port it to whatever stack you use—be it Godot, Unity, or something else. For the glue in between the shaders, I've chosen the fabulous Panda3D game engine and the OpenGL Shading Language (GLSL). So if that is your stack, then you'll also get the benefit of learning how to use these shading techniques with Panda3D and OpenGL specifically.
User avatar
Community Moderator
Posts: 2395
Joined: 06 Dec 2009, 14:02

Re: Beginner's shader tutorial (Panda3D but general)

Postby fluffrabbit » 13 May 2019, 19:09

Neat! I'm not seeing anything about PBR/IBL or realistic rendering. My current quest is to find the best algorithms to bake an irradiance map for that (image related). My main sources are the OpenGL ES 3.0 Programming Guide and, and my stack is SDL or SFML with header-only Glad 2 and linalg.h.

Where this guide really shines is with the effects. SSAO and Phong lighting may not be perfectly realistic, but add all those layers together with the bloom, outlining, and other effects, and it looks amaaazing. However, if you want pixel outlines, a better way to do it is shown here.

Note to self: has the world's worst diffuse irradiance baker. Polar bias. Yuck. Ideally use pseudorandom sampling to use like 10% the number of texture lookups.

EDIT: According to the author, 20 or so texture lookups per fragment is fast enough to do in a defered renderer, but in a forward renderer like most people use (for the sake of multisampling, alpha transparency, and simplicity) it should really be used as a somewhat faster environment map baker, where the split sum approximation ruins grazing specular reflections and requires the developer to store multiple cubemaps. It's really frustrating that compromises have to made for the sake of efficiency.

EDIT 2: There is no way to sample realtime irradiance from a cubemap using current-gen hardware. The algorithms to get an irradiance map don't even function with fewer than 10 texture lookups per fragment due to the large area that must be sampled. Maybe importance sampling could get it down to 5 texture lookups, but then you have to do a different set of texture lookups to get the specular component, generally in the 12-20 range, so you're doing 17-30 or so texture lookups per fragment, and if you have layered objects some pixels could require 100 texture lookups. That's slideshow territory. I tested it. :(
Posts: 136
Joined: 11 Apr 2019, 11:17

Who is online

Users browsing this forum: No registered users and 1 guest