@:directlyUsed@:src({
function GGX(NdotV:Float, roughness:Float):Float {
var k = (roughness * roughness) * 0.5;
return NdotV / (NdotV * (1.0 - k) + k);
};
function G_Smith(roughness:Float, nDotV:Float, nDotL:Float):Float {
return GGX(nDotL, roughness) * GGX(nDotV, roughness);
};
function fragment() {
var roughness = input.uv.x;
var NoV = input.uv.y;
var v = vec3(sqrt(1.0 - NoV * NoV), 0., NoV);
var n = vec3(0, 0, 1.);
var numSamples = 1 << samplesBits;
var a = 0., b = 0.;
for (i in 0 ... numSamples) {
var xi = hammersley(i, numSamples);
var h = importanceSampleGGX(roughness, xi, n);
var l = reflect(-v, h);
var NoL = saturate(dot(n, l));
var NoH = saturate(dot(n, h));
var VoH = saturate(dot(v, h));
if (NoL > 0) {
var g = G_Smith(roughness, NoV, NoL);
var gvis = g * VoH / (NoH * NoV);
var fresnel = pow(1 - VoH, 5.);
a += (1 - fresnel) * gvis;
b += fresnel * gvis;
};
};
output.color = vec4(a / numSamples, b / numSamples, 0, 1);
};
})@:build(hxsl.Macros.buildShader())@:autoBuild(hxsl.Macros.buildShader())