浏览代码

fixed pixelSize global with renderTarget

Nicolas Cannasse 4 年之前
父节点
当前提交
e4b0caba79
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      h3d/pass/Default.hx

+ 6 - 1
h3d/pass/Default.hx

@@ -20,7 +20,7 @@ class Default extends Base {
 	@global("camera.viewProj") var cameraViewProj : h3d.Matrix = ctx.camera.m;
 	@global("camera.inverseViewProj") var cameraInverseViewProj : h3d.Matrix = ctx.camera.getInverseViewProj();
 	@global("global.time") var globalTime : Float = ctx.time;
-	@global("global.pixelSize") var pixelSize : h3d.Vector = new h3d.Vector(2 / ctx.engine.width, 2 / ctx.engine.height);
+	@global("global.pixelSize") var pixelSize : h3d.Vector = getCurrentPixelSize();
 	@global("global.modelView") var globalModelView : h3d.Matrix;
 	@global("global.modelViewInverse") var globalModelViewInverse : h3d.Matrix;
 
@@ -30,6 +30,11 @@ class Default extends Base {
 		initGlobals();
 	}
 
+	function getCurrentPixelSize() {
+		var t = ctx.engine.getCurrentTarget();
+		return new h3d.Vector(2 / (t == null ? ctx.engine.width : t.width), 2 / (t == null ? ctx.engine.height : t.height));
+	}
+
 	function getOutputs() : Array<hxsl.Output> {
 		return [Value("output.color")];
 	}