/src/away3d/filters/DepthOfFieldFilter3D.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 130 lines · 87 code · 19 blank · 24 comment · 1 complexity · 451d7e3521a7997f9d5b712f8179151a MD5 · raw file

  1. package away3d.filters
  2. {
  3. import away3d.cameras.Camera3D;
  4. import away3d.containers.ObjectContainer3D;
  5. import away3d.core.managers.Stage3DProxy;
  6. import away3d.filters.tasks.Filter3DHDepthOfFFieldTask;
  7. import away3d.filters.tasks.Filter3DVDepthOfFFieldTask;
  8. import flash.display3D.textures.Texture;
  9. import flash.geom.Vector3D;
  10. public class DepthOfFieldFilter3D extends Filter3DBase
  11. {
  12. private var _focusTarget:ObjectContainer3D;
  13. private var _hDofTask:Filter3DHDepthOfFFieldTask;
  14. private var _vDofTask:Filter3DVDepthOfFFieldTask;
  15. /**
  16. * Creates a new DepthOfFieldFilter3D object.
  17. * @param blurX The maximum amount of horizontal blur to apply
  18. * @param blurY The maximum amount of vertical blur to apply
  19. * @param stepSize The distance between samples. Set to -1 to auto-detect with acceptable quality.
  20. */
  21. public function DepthOfFieldFilter3D(maxBlurX:uint = 3, maxBlurY:uint = 3, stepSize:int = -1)
  22. {
  23. super();
  24. _hDofTask = new Filter3DHDepthOfFFieldTask(maxBlurX, stepSize);
  25. _vDofTask = new Filter3DVDepthOfFFieldTask(maxBlurY, stepSize);
  26. addTask(_hDofTask);
  27. addTask(_vDofTask);
  28. }
  29. /**
  30. * The amount of pixels between each sample.
  31. */
  32. public function get stepSize():int
  33. {
  34. return _hDofTask.stepSize;
  35. }
  36. public function set stepSize(value:int):void
  37. {
  38. _vDofTask.stepSize = _hDofTask.stepSize = value;
  39. }
  40. /**
  41. * An optional target ObjectContainer3D that will be used to auto-focus on.
  42. */
  43. public function get focusTarget():ObjectContainer3D
  44. {
  45. return _focusTarget;
  46. }
  47. public function set focusTarget(value:ObjectContainer3D):void
  48. {
  49. _focusTarget = value;
  50. }
  51. /**
  52. * The distance from the camera to the point that is in focus.
  53. */
  54. public function get focusDistance():Number
  55. {
  56. return _hDofTask.focusDistance;
  57. }
  58. public function set focusDistance(value:Number):void
  59. {
  60. _hDofTask.focusDistance = _vDofTask.focusDistance = value;
  61. }
  62. /**
  63. * The distance between the focus point and the maximum amount of blur.
  64. */
  65. public function get range():Number
  66. {
  67. return _hDofTask.range;
  68. }
  69. public function set range(value:Number):void
  70. {
  71. _vDofTask.range = _hDofTask.range = value;
  72. }
  73. /**
  74. * The maximum amount of horizontal blur.
  75. */
  76. public function get maxBlurX():uint
  77. {
  78. return _hDofTask.maxBlur;
  79. }
  80. public function set maxBlurX(value:uint):void
  81. {
  82. _hDofTask.maxBlur = value;
  83. }
  84. /**
  85. * The maximum amount of vertical blur.
  86. */
  87. public function get maxBlurY():uint
  88. {
  89. return _vDofTask.maxBlur;
  90. }
  91. public function set maxBlurY(value:uint):void
  92. {
  93. _vDofTask.maxBlur = value;
  94. }
  95. override public function update(stage:Stage3DProxy, camera:Camera3D):void
  96. {
  97. if (_focusTarget)
  98. updateFocus(camera);
  99. }
  100. private function updateFocus(camera:Camera3D):void
  101. {
  102. var target:Vector3D = camera.inverseSceneTransform.transformVector(_focusTarget.scenePosition);
  103. _hDofTask.focusDistance = _vDofTask.focusDistance = target.z;
  104. }
  105. override public function setRenderTargets(mainTarget:Texture, stage3DProxy:Stage3DProxy):void
  106. {
  107. super.setRenderTargets(mainTarget, stage3DProxy);
  108. _hDofTask.target = _vDofTask.getMainInputTexture(stage3DProxy);
  109. }
  110. }
  111. }