OSL: Parallax Occlusion Mapping
This is a Parallax Occlusion Mapping Shader written in OSL. The Shader is based on the excellent Parallax Mapping Tutorial by Joey de Vries ( https://learnopengl.com , https://twitter.com/JoeyDeVriez ). Thanks again Joey for the permission to use it.
If you’re not familiar with Parallax Mapping: it’s a technique coming from real-time engines to fake depth without actually displacing any geometry. It does that by warping the UVW coordinates in relation to the viewer. Keep in mind that this is only a fake. Shadows will still be flat and objects do not intersect as if there was actual depth.
For everyone who is as excited as I am about the new OSL feature in max 2019, this is probably one of the most wanted shaders – it certainly is for me and has been on my wishlist for many years. I haven’t written any other osl shader before and I haven’t tested the shader a lot yet, so please let me know if you find something that doesn’t work or could be improved.
You can either use a filename node for the heightmap or load it directly in the shader itself. The min and max samples specify the amount of depth sampling the Shader does when looking straight-on or from a low angle. Be careful with this one, the default 8 and 32 should be enough for most cases.
Everything else should be pretty self-explanatory from the screenshot below. Make sure you do NOT modify the UVW coordinates after the parallax mapping shader. Those UVs are view-dependent and will not work if tiled or modified in any way. Use the UVW input of the shader to tile or rotate your textures.
Example setup in 3dsmax
Curved surfaces may yield small stepping in your texture when rendered. This is due to the fact that the tangent and binormals in OSL are not smoothed (in contrary to the baked tangents per object in real-time engines). Since this is a quite expensive calculation to do, offline renderers usually go with the unsmoothed tangents, which, for example, is often visible in facetted anisotropy. You can subdivide your model to make those artifacts less obvious.
Download and licensing:
Please read the license provided in the header of the .osl file before using it! (In short: the shader is free to use and you may use it in your daily work but you are not allowed to sell it.)
If you found this tool or script helpful in your daily work and want to support me, feel free to press the tiny shiny button below. Helps me cover the server costs and motivates further development :)