Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------
Toshihiro Shimizu 890ddd
 Iwa_PNPerspectiveFx
shun-iwasawa 267c1f
 render perspective noise pattern.
Toshihiro Shimizu 890ddd
------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
#ifndef IWA_PN_PERSPECTIVE_H
Toshihiro Shimizu 890ddd
#define IWA_PN_PERSPECTIVE_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
shun-iwasawa 267c1f
struct double3 {
shun-iwasawa 267c1f
  double x, y, z;
Toshihiro Shimizu 890ddd
};
shun-iwasawa 267c1f
struct double4 {
shun-iwasawa 267c1f
  double x, y, z, w;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
shun-iwasawa 267c1f
// parameters
Toshihiro Shimizu 890ddd
struct PN_Params {
shun-iwasawa 267c1f
  enum RenderMode {
shun-iwasawa 267c1f
    Noise = 0,
shun-iwasawa 267c1f
    Noise_NoResample,
shun-iwasawa 267c1f
    WarpHV,
shun-iwasawa 267c1f
    Fresnel,
shun-iwasawa 267c1f
    WarpHV2
shun-iwasawa 267c1f
  } renderMode;
shun-iwasawa 267c1f
  enum NoiseType { Perlin = 0, Simplex } noiseType;
shun-iwasawa 267c1f
  double size;         // noise size of the first generation
shun-iwasawa 267c1f
  int octaves;         // generation count
shun-iwasawa 267c1f
  TPointD offset;      // offset of the first generation
shun-iwasawa 267c1f
  double p_intensity;  // intensity ratio between gen
shun-iwasawa 267c1f
  double p_size;       // size ratio between gen
shun-iwasawa 267c1f
  double p_offset;     // offset ratio between gen
shun-iwasawa 267c1f
  TPointD eyeLevel;
shun-iwasawa 267c1f
  int drawLevel;  // vertical distance from the bottom to the top of the drawing
shun-iwasawa 267c1f
                  // region
Shinya Kitaoka 120a6e
  bool alp_rend_sw;
shun-iwasawa 267c1f
  double waveHeight;  // used in the WarpHV and Fresnel modes
shun-iwasawa 267c1f
  double fy_2;
shun-iwasawa 267c1f
  double A;
shun-iwasawa 267c1f
  double3 cam_pos;
shun-iwasawa 267c1f
  double base_fresnel_ref;  // used in the Fresnel mode
shun-iwasawa 267c1f
  double top_fresnel_ref;   // used in the Fresnel mode
shun-iwasawa 267c1f
  double int_sum;
shun-iwasawa 267c1f
  TAffine aff;
shun-iwasawa 267c1f
  double time;
shun-iwasawa 267c1f
  double p_evolution;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class Iwa_PNPerspectiveFx final : public TStandardZeraryFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(Iwa_PNPerspectiveFx)
Shinya Kitaoka 120a6e
shun-iwasawa 267c1f
  TIntEnumParamP m_renderMode;
shun-iwasawa 267c1f
  TIntEnumParamP m_noiseType;
shun-iwasawa 267c1f
  TDoubleParamP m_size;
shun-iwasawa 267c1f
  TDoubleParamP m_evolution;
shun-iwasawa 267c1f
  TIntEnumParamP m_octaves;
shun-iwasawa 267c1f
  TPointParamP m_offset;
shun-iwasawa 267c1f
shun-iwasawa 267c1f
  TDoubleParamP m_persistance_intensity;
shun-iwasawa 267c1f
  TDoubleParamP m_persistance_size;
shun-iwasawa 267c1f
  TDoubleParamP m_persistance_evolution;
shun-iwasawa 267c1f
  TDoubleParamP m_persistance_offset;
shun-iwasawa 267c1f
shun-iwasawa 267c1f
  TDoubleParamP m_fov;      // vertical angle of camera fov in degrees
shun-iwasawa 267c1f
  TPointParamP m_eyeLevel;  // vanishing point
shun-iwasawa 267c1f
shun-iwasawa 267c1f
  TBoolParamP m_alpha_rendering;  // specify if render noise pattern to the
shun-iwasawa 267c1f
                                  // alpha channel as well
shun-iwasawa 267c1f
shun-iwasawa 267c1f
  TDoubleParamP m_waveHeight;
shun-iwasawa 267c1f
shun-iwasawa 267c1f
  TBoolParamP m_normalize_fresnel;  // normalize fresnel reflectivity
shun-iwasawa 267c1f
  TDoubleParamP m_normalize_margin;
shun-iwasawa 267c1f
Shinya Kitaoka 120a6e
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa 267c1f
  void setOutputRaster(double4 *srcMem, const RASTER dstRas, TDimensionI dim,
Shinya Kitaoka 120a6e
                       int drawLevel, const bool alp_rend_sw);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void getPNParameters(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                       const TRenderSettings &settings, PN_Params ¶ms,
Shinya Kitaoka 120a6e
                       TDimensionI &dimOut);
Shinya Kitaoka 120a6e
shun-iwasawa 267c1f
  // render for 2 Noise modes
shun-iwasawa 267c1f
  void calcPerinNoise_CPU(double4 *out_host, TDimensionI &dimOut, PN_Params &p,
Shinya Kitaoka 120a6e
                          bool doResample);
Shinya Kitaoka 120a6e
shun-iwasawa 267c1f
  // render for WarpHV / Fresnel modes
shun-iwasawa 267c1f
  void calcPNNormal_CPU(double4 *out_host, TDimensionI &dimOut, PN_Params &p,
Shinya Kitaoka 120a6e
                        bool isSubWave = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Iwa_PNPerspectiveFx();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  bool canHandle(const TRenderSettings &info, double frame) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void doCompute(TTile &tile, double frame,
Shinya Kitaoka 38fd86
                 const TRenderSettings &rend_sets) override;
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
  void doCompute_CPU(double frame, const TRenderSettings &settings,
shun-iwasawa 267c1f
                     double4 *out_host, TDimensionI &dimOut,
Shinya Kitaoka 120a6e
                     PN_Params &pnParams);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void getParamUIs(TParamUIConcept *&concepts, int &length) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif