読者です 読者をやめる 読者になる 読者になる

bate's blog

調べたこと実装したことなどを取りとめもなく書きます。

FXComposer超入門13

FXComposer超入門12をピクセルシェーダーで処理したやつ。
頂点で処理した方が味があるように見えてしまう。


/*

% Description of my shader.
% Second line of description for my shader.

keywords: material classic

date: YYMMDD

*/

float4x4 WIT : WorldInverseTranspose <string UIWidget = "none";>;
float4x4 WVP : WorldViewProjection <string UIWidget = "none";>;
float4x4 W : World <string UIWidget = "none";>;
float4x4 VI : ViewInverse <string UIWidget = "none";>;
float4x4 IW : WorldInverse <string UIWidget = "none";>;

// Camera
float4 CameraPos : Position
<
	string UIName = "Camera Pos";
	string Object = "PerspectiveCamera";
	string Space = "World";
>;


// struct
struct appdata
{
	float4 Pos		: POSITION;
	float3 Normal	: NORMAL;
};

struct V2Pdata
{
	float4 HPos		: POSITION;
	float3 WNormal	: TEXCOORD0;
	float3 LightDir	: TEXCOORD1;
};

V2Pdata mainVS(appdata IN)
{
	V2Pdata OUT = (V2Pdata)0;
	
	OUT.HPos = mul(WVP,IN.Pos);
	
	float3 normal = normalize(IN.Normal);
	float3 world_normal = mul((float3x3)WIT, normal).xyz;
	OUT.WNormal = normalize(world_normal).xyz;
	
	float3 world_position = mul((float3x3)W, IN.Pos.xyz).xyz;
	float3 world_camera_position = CameraPos.xyz;
	OUT.LightDir = normalize(world_camera_position-world_position).xyz;
	
	return OUT;
}

float4 mainPS(V2Pdata IN) :COLOR
{
	float rim = abs(dot(IN.LightDir, IN.WNormal));
	rim = rim<0.2?0.0:1.0;
	return float4(rim,rim,rim,1);
}

technique technique0 {
	pass p0 {
		CullFaceEnable = false;
		DepthTestEnable = true;
		VertexProgram = compile vp40 mainVS();
		FragmentProgram = compile fp40 mainPS();
	}
}
広告を非表示にする