Browse Source

remove old hardware pick

Nicolas Cannasse 1 năm trước cách đây
mục cha
commit
3b8b187f29
2 tập tin đã thay đổi với 0 bổ sung160 xóa
  1. 0 95
      h3d/pass/HardwarePick.hx
  2. 0 65
      h3d/scene/Scene.hx

+ 0 - 95
h3d/pass/HardwarePick.hx

@@ -1,95 +0,0 @@
-package h3d.pass;
-
-private class FixedColor extends hxsl.Shader {
-
-	static var SRC = {
-		@param var colorID : Vec4;
-		@param var viewport : Vec4;
-		var output : {
-			position : Vec4,
-			colorID : Vec4
-		};
-		function vertex() {
-			output.position = (output.position + vec4(viewport.xy, 0., 0.) * output.position.w) * vec4(viewport.zw, 1., 1.);
-		}
-		function fragment() {
-			output.colorID = colorID;
-		}
-	}
-
-}
-
-class HardwarePick extends Default {
-
-	public var pickX : Float;
-	public var pickY : Float;
-
-	var fixedColor = new FixedColor();
-	var colorID : Int;
-	var texOut : h3d.mat.Texture;
-	var material : h3d.mat.Pass;
-	public var pickedIndex = -1;
-
-	public function new() {
-		super("hwpick");
-		material = new h3d.mat.Pass("");
-		material.blend(One, Zero);
-		texOut = new h3d.mat.Texture(3, 3, [Target]);
-		texOut.depthBuffer = new h3d.mat.Texture(3, 3, Depth24Stencil8);
-	}
-
-	override function dispose() {
-		super.dispose();
-		texOut.dispose();
-		texOut.depthBuffer.dispose();
-	}
-
-	override function getOutputs() : Array<hxsl.Output> {
-		return [Value("output.colorID")];
-	}
-
-	override function drawObject(p) {
-		super.drawObject(p);
-		nextID();
-	}
-
-	inline function nextID() {
-		fixedColor.colorID.setColor(0xFF000000 | (++colorID));
-	}
-
-	override function draw(passes:h3d.pass.PassList,?sort) {
-
-		for( cur in passes ) @:privateAccess {
-			// force all materials to use opaque blend
-			var mask = h3d.mat.Pass.blendSrc_mask | h3d.mat.Pass.blendDst_mask | h3d.mat.Pass.blendAlphaDst_mask | h3d.mat.Pass.blendAlphaSrc_mask | h3d.mat.Pass.blendOp_mask | h3d.mat.Pass.blendAlphaOp_mask;
-			cur.pass.bits &= ~mask;
-			cur.pass.bits |= material.bits & mask;
-		}
-		colorID = 0;
-
-		nextID();
-		fixedColor.viewport.set( -(pickX * 2 / ctx.engine.width - 1), (pickY * 2 / ctx.engine.height - 1), ctx.engine.width / texOut.width, ctx.engine.height / texOut.height);
-		ctx.engine.pushTarget(texOut);
-		ctx.engine.clear(0xFF000000, 1);
-		ctx.extraShaders = ctx.allocShaderList(fixedColor);
-		super.draw(passes,sort);
-		ctx.extraShaders = null;
-		ctx.engine.popTarget();
-
-		for( cur in passes ) {
-			// will reset bits
-			cur.pass.blendSrc = cur.pass.blendSrc;
-			cur.pass.blendDst = cur.pass.blendDst;
-			cur.pass.blendOp = cur.pass.blendOp;
-			cur.pass.blendAlphaSrc = cur.pass.blendAlphaSrc;
-			cur.pass.blendAlphaDst = cur.pass.blendAlphaDst;
-			cur.pass.blendAlphaOp = cur.pass.blendAlphaOp;
-			cur.pass.colorMask = cur.pass.colorMask;
-		}
-
-		ctx.engine.clear(null, null, 0);
-		var pix = texOut.capturePixels();
-		pickedIndex = (pix.getPixel(pix.width>>1, pix.height>>1) & 0xFFFFFF) - 1;
-	}
-
-}

+ 0 - 65
h3d/scene/Scene.hx

@@ -244,10 +244,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 	public function dispose() {
 		if ( allocated )
 			onRemove();
-		if( hardwarePass != null ) {
-			hardwarePass.dispose();
-			hardwarePass = null;
-		}
 		ctx.dispose();
 		if(renderer != null) {
 			renderer.dispose();
@@ -277,67 +273,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx.elapsedTime = elapsedTime;
 	}
 
-	var hardwarePass : h3d.pass.HardwarePick;
-
-	/**
-		Use GPU rendering to pick a model at the given pixel position.
-		hardwarePick() will check all scene visible meshes bounds against a ray cast with current camera, then draw them into a 1x1 pixel texture with a specific shader.
-		The texture will then be read and the color will identify the object that was rendered at this pixel.
-		This is a very precise way of doing scene picking since it performs exactly the same transformations (skinning, custom shaders, etc.) but might be more costly than using CPU colliders.
-		Please note that when done during/after rendering, this might clear the screen on some platforms so it should always be done before rendering.
-	**/
-	public function hardwarePick( pixelX : Float, pixelY : Float) {
-		var engine = h3d.Engine.getCurrent();
-		camera.screenRatio = engine.width / engine.height;
-		camera.update();
-		ctx.camera = camera;
-		ctx.engine = engine;
-		ctx.scene = this;
-		ctx.start();
-
-		var ray = camera.rayFromScreen(pixelX, pixelY);
-		var savedRay = ray.clone();
-
-		iterVisibleMeshes(function(m) {
-			if( m.primitive == null ) return;
-			ray.transform(m.getInvPos());
-			if( m.primitive.getBounds().rayIntersection(ray,false) >= 0 )
-				ctx.emitPass(m.material.mainPass, m);
-			ray.load(savedRay);
-		});
-
-		ctx.lightSystem = null;
-
-		var found = null;
-		for ( passes in @:privateAccess ctx.passes ) {
-			if ( found != null )
-				break;
-			var passList = new h3d.pass.PassList(passes);
-			if( !passList.isEmpty() ) {
-				var p = hardwarePass;
-				if( p == null )
-					hardwarePass = p = new h3d.pass.HardwarePick();
-				ctx.setGlobal("depthMap", { texture : h3d.mat.Texture.fromColor(0xFF00000, 0) });
-				p.pickX = pixelX;
-				p.pickY = pixelY;
-				p.setContext(ctx);
-				p.draw(passList);
-				if( p.pickedIndex >= 0 )
-					for( po in passList )
-						if( p.pickedIndex-- == 0 ) {
-							found = po.obj;
-							break;
-						}
-			}
-		}
-
-		ctx.done();
-		ctx.camera = null;
-		ctx.engine = null;
-		ctx.scene = null;
-		return found;
-	}
-
 	/**
 		Synchronize the scene without rendering, updating all objects and animations by the given amount of time, in seconds.
 	**/