Skip to content

Instantly share code, notes, and snippets.

View pixnblox's full-sized avatar

Mauricio Vives pixnblox

View GitHub Profile
@pixnblox
pixnblox / shading_position.hlsl
Last active August 14, 2023 13:15
Address the shadow terminator problem by computing a new shading position
// Projects the specified position (point) onto the plane with the specified origin and normal.
float3 projectOnPlane(float3 position, float3 origin, float3 normal)
{
return position - dot(position - origin, normal) * normal;
}
// Computes the shading position of the specified geometric position and vertex positions and
// normals. For a triangle with normals describing a convex surface, this point will be slightly
// above the surface. For a concave surface, the geometry position is used directly.
// NOTE: The difference between the shading position and geometry position is significant when
@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);