Kaynağa Gözat

Adding SAO fade distances. SAO sample count is now in 0-127 range. Removing empty line in renderer.

clementlandrin 1 yıl önce
ebeveyn
işleme
e3a4d0f138
2 değiştirilmiş dosya ile 13 ekleme ve 2 silme
  1. 0 1
      h3d/scene/Renderer.hx
  2. 13 1
      h3d/shader/SAO.hx

+ 0 - 1
h3d/scene/Renderer.hx

@@ -107,7 +107,6 @@ class Renderer extends hxd.impl.AnyProps {
 		}
 		if( frontToBack )
 			passes.sort(function(p1, p2) return p1.pass.layer == p2.pass.layer ? (p1.depth > p2.depth ? 1 : -1) : p1.pass.layer - p2.pass.layer);
-
 		else
 			passes.sort(function(p1, p2) return p1.pass.layer == p2.pass.layer ? (p1.depth > p2.depth ? -1 : 1) : p1.pass.layer - p2.pass.layer);
 	}

+ 13 - 1
h3d/shader/SAO.hx

@@ -8,9 +8,14 @@ class SAO extends ScreenShader {
 
 	static var SRC = {
 
-		@range(4,30) @const var numSamples : Int;
+		@global var camera : {
+			var position : Vec3;
+		};
+
+		@range(4,30) @const(127) var numSamples : Int;
 		@range(1,10) @const(16) var numSpiralTurns : Int;
 		@const var useWorldUV : Bool;
+		@const var USE_FADE : Bool = false;
 
 		@ignore @param var depthTexture : Channel;
 		@ignore @param var normalTexture : Channel3;
@@ -29,6 +34,9 @@ class SAO extends ScreenShader {
 		@ignore @param var microOcclusion : Channel;
 		@param var microOcclusionIntensity : Float;
 
+		@param var fadeStart : Float;
+		@param var fadeEnd : Float;
+
 		function sampleAO(uv : Vec2, position : Vec3, normal : Vec3, radiusSS : Float, tapIndex : Int, rotationAngle : Float) : Float {
 			// returns a unit vector and a screen-space radius for the tap on a unit disk
 			// (the caller should scale by the actual disk radius)
@@ -83,6 +91,10 @@ class SAO extends ScreenShader {
 			occlusion = 1.0 - occlusion / float(numSamples);
 			occlusion = pow(occlusion, 1.0 + intensity).saturate();
 
+			if ( USE_FADE ) {
+				var dist = distance(origin, camera.position);
+				occlusion = mix(occlusion, 1.0, saturate((dist - fadeStart) / (fadeEnd - fadeStart)));
+			}
 			occlusion *= mix(1, microOcclusion.get(vUV).r, microOcclusionIntensity);
 
 			output.color = vec4(occlusion.xxx, 1.);