@:src({
@global var global:{ var pixelSize : Vec2; @perObject
var modelView : Mat4; @perObject
var modelViewInverse : Mat4};
@global var camera:{ var inverseViewProj : Mat4};
@const var USE_NORMAL_FADE:Bool;
@global var depthMap:Channel;
@param var fadePower:Float;
@param var fadeStart:Float;
@param var fadeEnd:Float;
@param var normalFadeStart:Float;
@param var normalFadeEnd:Float;
var calculatedUV:Vec2;
var transformedTangent:Vec4;
var transformedNormal:Vec3;
var pixelTransformedPosition:Vec3;
var projectedPosition:Vec4;
var pixelColor:Vec4;
var fadeFactor:Float;
function normalFade(worldNormal:Vec3) {
var z = normalize(vec3(0, 0, 1) * global.modelView.mat3());
var angle = 1 - abs(acos(z.dot(worldNormal)) / PI);
var f = saturate((angle - normalFadeStart) / (normalFadeEnd - normalFadeStart));
fadeFactor *= f;
};
function getWorlPos(pos:Vec2):Vec3 {
var depth = depthMap.get(screenToUv(pos)).r;
var ruv = vec4(pos, depth, 1);
var wpos = ruv * camera.inverseViewProj;
var result = (wpos.xyz / wpos.w);
return result;
};
function getWorldNormal():Vec3 {
var screenPos = projectedPosition.xy / projectedPosition.w;
var worldPos = getWorlPos(screenPos);
var ddx = worldPos - getWorlPos(screenPos + vec2(global.pixelSize.x, 0));
var ddy = worldPos - getWorlPos(screenPos + vec2(0, global.pixelSize.y));
return normalize(cross(ddy, ddx));
};
function outsideBounds(localPos:Vec3):Bool {
return (localPos.x > 0.5 || localPos.x < -0.5 || localPos.y > 0.5 || localPos.y < -0.5 || localPos.z > 0.5 || localPos.z < -0.5);
};
})@:build(hxsl.Macros.buildShader())@:autoBuild(hxsl.Macros.buildShader())