ToneMapping.hx 959 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package h2d.filter;
  2. /**
  3. Applies a color correction that emulates tonemapping.
  4. **/
  5. class ToneMapping extends Filter {
  6. /**
  7. The value used to apply gamma correction.
  8. **/
  9. public var gamma(get, set) : Float;
  10. var pass : h3d.pass.ScreenFx<h3d.shader.pbr.ToneMapping>;
  11. var shader : h3d.shader.pbr.ToneMapping;
  12. /**
  13. Create a new ColorMatrix filter.
  14. @param gamma The value used to modify the resulting colors.
  15. **/
  16. public function new( ?g : Float ) {
  17. super();
  18. shader = new h3d.shader.pbr.ToneMapping();
  19. gamma = g;
  20. pass = new h3d.pass.ScreenFx(shader);
  21. }
  22. inline function get_gamma() return shader.gamma;
  23. inline function set_gamma(v) return shader.gamma = v;
  24. override function draw( ctx : RenderContext, t : h2d.Tile ) {
  25. var tout = ctx.textures.allocTileTarget("toneMappingOut", t);
  26. ctx.engine.pushTarget(tout);
  27. shader.hdrTexture = t.getTexture();
  28. pass.render();
  29. ctx.engine.popTarget();
  30. return h2d.Tile.fromTexture(tout);
  31. }
  32. }