// // VROPostProcessEffectFactory.h // ViroKit // // Copyright © 2017 Viro Media. All rights reserved. // #ifndef VROPostProcessEffectFactory_h #define VROPostProcessEffectFactory_h #include #include #include #include #include "VROStringUtil.h" class VROShaderProgram; class VROImagePostProcess; class VROMaterial; class VROLight; class VROShaderModifier; class VRODriverOpenGL; class VRODriver; class VRORenderTarget; enum class VROPostProcessEffect{ GrayScale, Sepia, SinCity, BarallelDistortion, PincushionDistortion, Toonify, Inverted, ThermalVision, Pixelated, CrossHatch, None }; /* The PostProcessEffectFactory handles the enabling, disabling and caching of PostProcessEffectPrograms that are applied as part of VROChoreographer.renderBasePass(). */ class VROPostProcessEffectFactory { public: VROPostProcessEffectFactory(); virtual ~VROPostProcessEffectFactory(); /* Enables the given VROPostProcessEffect to be applied. Note effects are applied in the order upon which they are enabled. */ void enableEffect(VROPostProcessEffect effect, std::shared_ptr driver); /* Disables the given VROPostProcessEffect to be applied. */ void disableEffect(VROPostProcessEffect effect); /* Clears all effects that had been previously applied. */ void clearAllEffects(); /* This method should be invoked by the main render cycle, *after* the scene is rendered to an HDR target, but before tone-mapping and gamma. It is here that we should perform all post-processing effects. The *final* output of post processing should be rendered into the given target. Return true if anything was written to the destination. False if there was no post-processing done. */ bool handlePostProcessing(std::shared_ptr source, std::shared_ptr destination, std::shared_ptr driver); static VROPostProcessEffect getEffectForString(std::string strEffect){ VROStringUtil::toLowerCase(strEffect); if (strEffect.compare("grayscale") == 0){ return VROPostProcessEffect::GrayScale; } else if (strEffect.compare("sepia") == 0){ return VROPostProcessEffect::Sepia; } else if (strEffect.compare("sincity") == 0){ return VROPostProcessEffect::SinCity; } else if (strEffect.compare("baralleldistortion") == 0){ return VROPostProcessEffect::BarallelDistortion; } else if (strEffect.compare("pincushiondistortion") == 0){ return VROPostProcessEffect::PincushionDistortion; } else if (strEffect.compare("toonify") == 0){ return VROPostProcessEffect::Toonify; } else if (strEffect.compare("inverted") == 0){ return VROPostProcessEffect::Inverted; } else if (strEffect.compare("thermalvision") == 0){ return VROPostProcessEffect::ThermalVision; } else if (strEffect.compare("pixelated") == 0){ return VROPostProcessEffect::Pixelated; } else if (strEffect.compare("crosshatch") == 0){ return VROPostProcessEffect::CrossHatch; } return VROPostProcessEffect::None; } private: void renderEffects(std::shared_ptr input, std::shared_ptr output, std::shared_ptr driver); /* Shader programs cached by their VROPostProcessEffect types. */ std::vector>> _cachedPrograms; /* Below is a list of post-process specific functions that builds, caches and returns post process effects to run. TODO VIRO-1634: Optimize PostProcess Effects to negate cost of re-binding shaders when multiple effects are applied by having a single postProcess.vsh. */ std::shared_ptr createGreyScale(std::shared_ptr driver); std::shared_ptr createSepia(std::shared_ptr driver); std::shared_ptr createSinCity(std::shared_ptr driver); std::shared_ptr createBarallelDistortion(std::shared_ptr driver); std::shared_ptr createPinCusionDistortion(std::shared_ptr driver); std::shared_ptr createToonify(std::shared_ptr driver); std::shared_ptr createInverted(std::shared_ptr driver); std::shared_ptr createThermalVision(std::shared_ptr driver); std::shared_ptr createPixel(std::shared_ptr driver); std::shared_ptr createCrossHatch(std::shared_ptr driver); std::shared_ptr createEmptyEffect(std::shared_ptr driver); std::vector getHBCSModification(float hue, float brightness, float contrast, float saturation); }; #endif /* VROPostProcessEffectFactory_h */