Skip to content

Instantly share code, notes, and snippets.

@selfshadow
selfshadow / Input
Created June 18, 2014 19:27
HLSL bug with const parameters and loops (tested with fxc from 7.0, 8.0, 8.1 Windows SDK)
struct PS_INPUT
{
float4 Pos : VS_OUT_POSITION;
};
// removing "const" fixes the problem
float4 Function(const float4 value)
{
return value;
}
@selfshadow
selfshadow / gist:8048308
Last active March 19, 2023 06:44
Reoriented Normal Mapping (http://blog.selfshadow.com/publications/blending-in-detail/) for unpacked, normalised vectors
// Blending when n1 and n2 are already 'unpacked' and normalised
float3 blend_rnm_unpacked(float3 n1, float3 n2)
{
float3 t = n1.xyz + float3( 0, 0, 1);
float3 u = n2.xyz * float3(-1, -1, 1);
float3 r = (t/t.z)*dot(t, u) - u;
return r;
}
@selfshadow
selfshadow / gist:5794173
Last active December 18, 2015 13:59
Quick Beckmann HLSL test
float Beckmann1(float3 n, float3 h, float m)
{
float ndoth = saturate(dot(n, h));
float cos2 = ndoth*ndoth;
return exp((cos2 - 1)/(cos2*m*m));
}
// mul r0.x, cb0[2].x, cb0[2].x
// dp3_sat r0.y, cb0[0].xyzx, cb0[1].xyzx
// mul r0.z, r0.y, r0.y