NokiMo
pucklovesgames
pucklovesgames

patreon


Subsurface Scattering write-up Part 2: Foliage Shader

 If you haven't yet watched the video on this shader, you can view it here: Subsurface Scattering for Foliage (without raytracing) 

If we apply the Subsurface Scattering shader we made before to foliage geometry, we see that the parts of the shader that rely on surface normals are messing everything up, because foliage is usually created by a series of intersecting quads. To remedy this, it's a good idea to bend the normals on the mesh into an outward spherical shape. The best way to do this is to bake them in before you import your model, as it saves the shader from having to do the work and it means you can use one SSS shader for all your SSS materials. However there might be reason you want to retain the original normals, such as if you want the geometry to fade away at angles perpendicular to the view direction, which avoids that sharp 'edge on' look.

For tools and tips on pre-bending the normals, check out the Polycount Foliage Wiki.

To do it in shader, a simple solution is to take the Vertex Positions, and transform them into world space.

While we're doing this, we'll also take the magnitude of those vectors (in local space) to use as a gradient mask falling off from the pivot of the mesh. You can use the Distance node for magnitude, or ideally work out the square magnitude to avoid a square root calculation.

If you bent your normals in advance, then the best way to create this spherical falloff is painting them in via Vertex Colours in whatever modelling program you're familiar with.

We now just need to override our surface normals with our new outward pointing normals, and also mask the SSS contribution by our spherical falloff to avoid over-lighting the centre of the mesh.

I also like to use this spherical falloff to add in some extra ambient occlusion in the normal lighting pass, as well as multiply it by the wind strength if you've added movement to your vertices, to keep the leaves attached to the trunk of the tree


Related Creators