Skip to content

Instantly share code, notes, and snippets.

View pixnblox's full-sized avatar

Mauricio Vives pixnblox

View GitHub Profile
@pixnblox
pixnblox / README.md
Last active December 4, 2025 02:10
Address the shadow terminator problem by computing a new shading position

Original Tweet - June 6, 2020

I really should have known this "shadow terminator" ray tracing issue was going to happen, but I stumbled into it anyway. It is a surprisingly tricky / annoying / common problem, but I got it fixed with some help from @pointinpolygon and others.

image

This arises from a difference between shading normals and geometric normals, particularly with low-poly geometry. This POV-Ray page has a nice diagram that explains it: http://wiki.povray.org/content/Knowledgebase:The_Shadow_Line_Artifact. This is not a floating-point precision issue.

This is also different from the "bump" terminator problem, which is about normal maps and not low-poly self-shadowing. See "Ray Tracing Gems" chapter 12 for details on that. The solution there is to modify the BSDF to add shadowin

@pixnblox
pixnblox / utf_conversion.h
Last active October 27, 2020 18:41
Convert Between UTF-8 and UTF 16
#include <codecvt>
#include <string>
using namespace std;
// UTF-16 to UTF-8 (variable-width encoding) string conversion.
// NOTE: This will throw a range_error exception if the input is invalid.
inline string narrow(const wstring& utf16Source)
{
wstring_convert<codecvt_utf8_utf16<wchar_t>> converter;
return converter.to_bytes(utf16Source);