Преглед на файлове

MeshBatch : Added distance clipping

TothBenoit преди 1 година
родител
ревизия
e6a3f9ac42
променени са 1 файла, в които са добавени 10 реда и са изтрити 0 реда
  1. 10 0
      h3d/scene/MeshBatch.hx

+ 10 - 0
h3d/scene/MeshBatch.hx

@@ -66,6 +66,8 @@ class ComputeIndirect extends hxsl.Shader {
 		@const var ENABLE_LOD : Bool;
 		@const var ENABLE_LOD : Bool;
 		@param var lodCount : Float = 1;
 		@param var lodCount : Float = 1;
 
 
+		@const var ENABLE_DISTANCE_CLIPPING : Bool;
+		@param var maxDistance : Float = -1;
 
 
 		var modelView : Mat4;
 		var modelView : Mat4;
 		function __init__() {
 		function __init__() {
@@ -93,6 +95,10 @@ class ComputeIndirect extends hxsl.Shader {
 				}
 				}
 			}
 			}
 
 
+			if ( ENABLE_DISTANCE_CLIPPING ) {
+				culled = distToCam > maxDistance;
+			}
+
 			if ( ENABLE_LOD ) {
 			if ( ENABLE_LOD ) {
 				var screenRatio = scaledRadius / distToCam;
 				var screenRatio = scaledRadius / distToCam;
 				for ( i in 0...int(lodCount) ) {
 				for ( i in 0...int(lodCount) ) {
@@ -140,6 +146,8 @@ class MeshBatch extends MultiMaterial {
 	public var meshBatchFlags(default, null) : haxe.EnumFlags<MeshBatchFlag>;
 	public var meshBatchFlags(default, null) : haxe.EnumFlags<MeshBatchFlag>;
 	var enableLOD(get, never) : Bool;
 	var enableLOD(get, never) : Bool;
 	function get_enableLOD() return meshBatchFlags.has( EnableLod );
 	function get_enableLOD() return meshBatchFlags.has( EnableLod );
+
+	public var maxDistance : Float = -1;
 	var enableGPUCulling(get, never) : Bool;
 	var enableGPUCulling(get, never) : Bool;
 	function get_enableGPUCulling() return meshBatchFlags.has( EnableGpuCulling );
 	function get_enableGPUCulling() return meshBatchFlags.has( EnableGpuCulling );
 
 
@@ -605,6 +613,8 @@ class MeshBatch extends MultiMaterial {
 					computePass.addShader(computeShader);
 					computePass.addShader(computeShader);
 					computeShader.ENABLE_LOD = enableLOD;
 					computeShader.ENABLE_LOD = enableLOD;
 					computeShader.ENABLE_CULLING = enableGPUCulling;
 					computeShader.ENABLE_CULLING = enableGPUCulling;
+					computeShader.ENABLE_DISTANCE_CLIPPING = maxDistance >= 0;
+					computeShader.maxDistance = maxDistance;
 					addComputeShaders(computePass);
 					addComputeShaders(computePass);
 					p.computePass = computePass;
 					p.computePass = computePass;