1 package com.jme3.post.filters; 2 3 import com.jme3.asset.AssetManager; 4 import com.jme3.material.Material; 5 import com.jme3.post.Filter; 6 import com.jme3.renderer.RenderManager; 7 import com.jme3.renderer.ViewPort; 8 9 /** 10 * 11 * @author Phate666 12 * @version 1.0 initial version 13 * @version 1.1 added luma 14 */ 15 public class GammaCorrectionFilter extends Filter 16 { 17 private float gamma = 2.0f; 18 private boolean computeLuma = false; 19 20 public GammaCorrectionFilter() 21 { 22 super("GammaCorrectionFilter"); 23 } 24 25 public GammaCorrectionFilter(float gamma) 26 { 27 this(); 28 this.setGamma(gamma); 29 } 30 31 @Override 32 protected Material getMaterial() 33 { 34 return material; 35 } 36 37 @Override 38 protected void initFilter(AssetManager manager, 39 RenderManager renderManager, ViewPort vp, int w, int h) 40 { 41 material = new Material(manager, 42 "Common/MatDefs/Post/GammaCorrection.j3md"); 43 material.setFloat("gamma", gamma); 44 material.setBoolean("computeLuma", computeLuma); 45 } 46 47 public float getGamma() 48 { 49 return gamma; 50 } 51 52 /** 53 * set to 0.0 to disable gamma correction 54 * @param gamma 55 */ 56 public void setGamma(float gamma) 57 { 58 if (material != null) 59 { 60 material.setFloat("gamma", gamma); 61 } 62 this.gamma = gamma; 63 } 64 65 public boolean isComputeLuma() 66 { 67 return computeLuma; 68 } 69 70 public void setComputeLuma(boolean computeLuma) 71 { 72 if (material != null) 73 { 74 material.setBoolean("computeLuma", computeLuma); 75 } 76 this.computeLuma = computeLuma; 77 } 78 } 79