Cloning filters

Hi,

I have a scene that has a number of filters.

I am currently working on off screen rendering and I wish to off screen render the same scene with different cameras and viewports.

I understand that a filter is initialised with the viewport information when it is added to a FilterPostProcessor. The issue I have is, for example two viewports, the same filter would need to be added to two different FilterPostProcessors. This would cause the filter to get initialised twice with conflicting viewport data.

My solution is to create a clone of each filter to be added to each viewport’s FPP.

I couldnt find an override for the clone function in the filters. Before I write my own, is there a preferred method to run the same filter on two different viewports??

Thanks

Not all the filters have a clone method. As a work around you have to create new ones from scratch.
Each viewport should have its own FilterPostProcessor and each fpp should have its own filters.

Thank you. This is what I thought.

If you do the work, please feel free to send over a pull request as well :wink:

What is a pull request?

Oh, have a look at What is a pull request? for a detailed description. Then have a look at https://help.github.com/articles/using-pull-requests/

I am happy to post the override for clone() on the filters that I am using.

DannyJo,

I found that I didn’t need to subclass filter. Instead I have created a factory system. The code follows…

The interface show the relationship between the filter factory and the off screen renderer (subclass of viewport)…

package a.file.path;
import com.jme3.post.Filter;
public interface iFilterFactory
 {
 public Filter create();
 }

My scene will hold a list of FilterFactories instead of Filters. When the scene is applied to my subclass of viewport it will gather the list of FilterFactories from the scene and call create on each, in order, to get a new instance of whatever type of filter and append it.

I have created a filter factory for the bloom filter as follows…

package a.file.path;
import com.jme3.post.Filter;
import com.jme3.post.filters.BloomFilter;
public class BloomFilterFactory implements iFilterFactory
 {
//################################################################################
// iFilterFactory
//################################################################################
 public Filter create()
  {
  BloomFilter bf=new BloomFilter(glowMode);
  bf.setBloomIntensity(bloomIntensity);
  bf.setBlurScale(blurScale);
  bf.setExposureCutOff(exposureCutOff);
  bf.setExposurePower(exposurePower);
  bf.setDownSamplingFactor(downSamplingFactor);
  return bf;
  }
//################################################################################
// setting parameters
//################################################################################
 private BloomFilter.GlowMode glowMode=BloomFilter.GlowMode.Scene;
 private float blurScale=1.5f;
 private float exposurePower=5.0f;
 private float exposureCutOff=0.0f;
 private float bloomIntensity=2.0f;
 private float downSamplingFactor=1;
//################################################################################
// setting functions
//################################################################################
 public void setGlowMode(BloomFilter.GlowMode _glowMode)
  {
  glowMode=_glowMode;
  }
 public BloomFilter.GlowMode getGlowMode()
  {
  return glowMode;
  }
 public void setBloomIntensity(float _bloomIntensity)
  {
  bloomIntensity=_bloomIntensity;
  }
 public float getBloomIntensity()
  {
  return bloomIntensity;
  }
 public void setBlurScale(float _blurScale)
  {
  blurScale=_blurScale;
  }
 public float getBlurScale()
  {
  return blurScale;
  }
 public void setExposureCutOff(float _exposureCutOff)
  {
  exposureCutOff=_exposureCutOff;
  }
 public float getExposureCutOff()
  {
  return exposureCutOff;
  }
 public void setExposurePower(float _exposurePower)
  {
  exposurePower=_exposurePower;
  }
 public float getExposurePower()
  {
  return exposurePower;
  }
 public void setDownSamplingFactor(float _downSamplingFactor)
  {
  downSamplingFactor=_downSamplingFactor;
  }
 public float getDownSamplingFactor()
  {
  return downSamplingFactor;
  }
//################################################################################
// end
//################################################################################
 }

This should allow the same scene, with filters, to be rendered on as many viewports as required. Once the viewport no longer requires the filter object, it is released for garbage.

I hope you find this useful. Sorry about the format, I am a bit old school.

Regards
Penny