Ver código fonte

Fix sao using orthographic camera.

clementlandrin 1 mês atrás
pai
commit
2c21f3eb0a
2 arquivos alterados com 10 adições e 1 exclusões
  1. 3 0
      h3d/pass/ScalableAO.hx
  2. 7 1
      h3d/shader/SAO.hx

+ 3 - 0
h3d/pass/ScalableAO.hx

@@ -13,6 +13,9 @@ class ScalableAO extends h3d.pass.ScreenFx<h3d.shader.SAO> {
 		shader.cameraInverseViewProj = camera.getInverseViewProj();
 		shader.screenRatio.set(engine.height / engine.width, 1);
 		shader.fovTan = 1.0 / (2.0 * Math.tan(camera.fovY * (Math.PI / 180) * 0.5));
+		shader.ORTHO = camera.orthoBounds != null;
+		if ( shader.ORTHO )
+			shader.invOrthoHeight = 1.0 / camera.orthoBounds.ySize; 
 		render();
 	}
 

+ 7 - 1
h3d/shader/SAO.hx

@@ -18,6 +18,7 @@ class SAO extends ScreenShader {
 		@const var USE_START_FADE : Bool = false;
 		@const var USE_FADE : Bool = false;
 		@const var USE_SCALABLE_BIAS : Bool = false;
+		@const var ORTHO : Bool = false;
 
 		@ignore @param var depthTexture : Channel;
 		@ignore @param var normalTexture : Channel3;
@@ -32,6 +33,7 @@ class SAO extends ScreenShader {
 
 		@ignore @param var screenRatio : Vec2;
 		@ignore @param var fovTan : Float;
+		@ignore @param var invOrthoHeight : Float;
 
 		@param var startFadeStart : Float;
 		@param var startFadeEnd : Float;
@@ -90,7 +92,11 @@ class SAO extends ScreenShader {
 			var randomPatternRotationAngle = 2.0 * PI * sampleNoise;
 
 			// change from WS to DepthUV space
-			var radiusSS = (sampleRadius * fovTan) / (origin * cameraView).z;
+			var radiusSS = 0.0;
+			if ( ORTHO )
+				radiusSS = sampleRadius * invOrthoHeight;
+			else
+				radiusSS = (sampleRadius * fovTan) / (origin * cameraView).z;
 
 			for( i in 0...numSamples )
 				occlusion += sampleAO(vUV, origin, normal, radiusSS, i, randomPatternRotationAngle);