Toshihiro Shimizu 890ddd
/*------------------------------------------------------------
Toshihiro Shimizu 890ddd
 Iwa_PNPerspectiveFx
Toshihiro Shimizu 890ddd
 PerlinNoise/SimplexNoiseパターンを生成、透視投影する
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
Toshihiro Shimizu 890ddd
struct float2 {
Toshihiro Shimizu 890ddd
	float x, y;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
struct float3 {
Toshihiro Shimizu 890ddd
	float x, y, z;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
struct float4 {
Toshihiro Shimizu 890ddd
	float x, y, z, w;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*計算に用いるパラメータ群*/
Toshihiro Shimizu 890ddd
struct PN_Params {
Toshihiro Shimizu 890ddd
	int renderMode;
Toshihiro Shimizu 890ddd
	int noiseType;	 /* 0:Perlin, 1: Simplex */
Toshihiro Shimizu 890ddd
	float size;		   /* 第1世代のノイズサイズ */
Toshihiro Shimizu 890ddd
	int octaves;	   /* 世代数 */
Toshihiro Shimizu 890ddd
	float2 offset;	 /* 第1世代のオフセット */
Toshihiro Shimizu 890ddd
	float p_intensity; /* 世代間の強度比 */
Toshihiro Shimizu 890ddd
	float p_size;	  /* 世代間のサイズ比 */
Toshihiro Shimizu 890ddd
	float p_offset;	/* 世代間のオフセット比 */
Toshihiro Shimizu 890ddd
	float2 eyeLevel;   /* 視点位置 */
Toshihiro Shimizu 890ddd
	int drawLevel;	 /* 描画範囲の下からの距離 描画を開始するスキャンライン位置 */
Toshihiro Shimizu 890ddd
	bool alp_rend_sw;
Toshihiro Shimizu 890ddd
	float waveHeight; /* warpHV / フレネル反射のときのみ使う */
Toshihiro Shimizu 890ddd
	float fy_2;
Toshihiro Shimizu 890ddd
	float A;
Toshihiro Shimizu 890ddd
	float3 cam_pos;
Toshihiro Shimizu 890ddd
	float base_fresnel_ref; /* フレネル反射のときのみ使う */
Toshihiro Shimizu 890ddd
	float int_sum;
Toshihiro Shimizu 890ddd
	float a11, a12, a13;
Toshihiro Shimizu 890ddd
	float a21, a22, a23;
Toshihiro Shimizu 890ddd
	float time;
Toshihiro Shimizu 890ddd
	float p_evolution;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Iwa_PNPerspectiveFx : public TStandardZeraryFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(Iwa_PNPerspectiveFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TIntEnumParamP m_renderMode; /* 描画モード
Toshihiro Shimizu 890ddd
											    - 強度
Toshihiro Shimizu 890ddd
											    - 強度(リサンプルなし)
Toshihiro Shimizu 890ddd
											    - WarpHV用オフセット
Toshihiro Shimizu 890ddd
											    - フレネル反射 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TIntEnumParamP m_noiseType; /* ノイズのタイプ
Toshihiro Shimizu 890ddd
											    - Perlin Noise
Toshihiro Shimizu 890ddd
											    - Simplex Noise */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoubleParamP m_size;	  /* ベースとなる大きさ */
Toshihiro Shimizu 890ddd
	TDoubleParamP m_evolution; /* 展開 */
Toshihiro Shimizu 890ddd
	TIntEnumParamP m_octaves;  /* 世代数 */
Toshihiro Shimizu 890ddd
	TPointParamP m_offset;	 /* ノイズのオフセット */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoubleParamP m_persistance_intensity; /* 次の世代での振幅の倍率 */
Toshihiro Shimizu 890ddd
	TDoubleParamP m_persistance_size;	  /* 次の世代での波長の倍率 */
Toshihiro Shimizu 890ddd
	TDoubleParamP m_persistance_evolution; /* 次の世代での展開周期の倍率 */
Toshihiro Shimizu 890ddd
	TDoubleParamP m_persistance_offset;	/* 次の世代でのオフセット距離の倍率 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoubleParamP m_fov;	 /* カメラ画角 */
Toshihiro Shimizu 890ddd
	TPointParamP m_eyeLevel; /* 消失点の位置 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TBoolParamP m_alpha_rendering; /* アルファチャンネルもノイズを与えるかどうか */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoubleParamP m_waveHeight; /* 波の高さ */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* 出力結果をChannel値に変換して格納 */
Toshihiro Shimizu 890ddd
	template <typename pixel="" raster,="" typename=""></typename>
Toshihiro Shimizu 890ddd
	void setOutputRaster(float4 *srcMem,
Toshihiro Shimizu 890ddd
						 const RASTER dstRas,
Toshihiro Shimizu 890ddd
						 TDimensionI dim,
Toshihiro Shimizu 890ddd
						 int drawLevel,
Toshihiro Shimizu 890ddd
						 const bool alp_rend_sw);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* PerlinNoiseのパラメータを取得 */
Toshihiro Shimizu 890ddd
	void getPNParameters(TTile &tile,
Toshihiro Shimizu 890ddd
						 double frame,
Toshihiro Shimizu 890ddd
						 const TRenderSettings &settings,
Toshihiro Shimizu 890ddd
						 PN_Params ¶ms,
Toshihiro Shimizu 890ddd
						 TDimensionI &dimOut);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* 通常のノイズのCPU計算 */
Toshihiro Shimizu 890ddd
	void calcPerinNoise_CPU(float4 *out_host,
Toshihiro Shimizu 890ddd
							TDimensionI &dimOut,
Toshihiro Shimizu 890ddd
							PN_Params &p,
Toshihiro Shimizu 890ddd
							bool doResample);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* WarpHVモード、Fresnel反射モード */
Toshihiro Shimizu 890ddd
	void calcPNNormal_CPU(float4 *out_host,
Toshihiro Shimizu 890ddd
						  TDimensionI &dimOut,
Toshihiro Shimizu 890ddd
						  PN_Params &p,
Toshihiro Shimizu 890ddd
						  bool isSubWave = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Iwa_PNPerspectiveFx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doGetBBox(
Toshihiro Shimizu 890ddd
		double frame, TRectD &bBox, const TRenderSettings &info);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(
Toshihiro Shimizu 890ddd
		const TRenderSettings &info, double frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute(
Toshihiro Shimizu 890ddd
		TTile &tile, double frame, const TRenderSettings &rend_sets);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute_CPU(TTile &tile,
Toshihiro Shimizu 890ddd
					   double frame,
Toshihiro Shimizu 890ddd
					   const TRenderSettings &settings,
Toshihiro Shimizu 890ddd
					   float4 *out_host,
Toshihiro Shimizu 890ddd
					   TDimensionI &dimOut,
Toshihiro Shimizu 890ddd
					   PN_Params &pnParams);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getParamUIs(TParamUIConcept *&concepts, int &length);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif