Created
December 1, 2019 15:33
-
-
Save LoadDragon0000000000/f6af5ff45e3afc0f6b09a8041c0a6589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------- | |
// 拡散光 | |
// シェーダはモデルに対して適用する | |
// ---------------------------------------------------------------- | |
// ---------------------------------------------------------------- | |
// アプリケーション側で設定する変数 | |
// ---------------------------------------------------------------- | |
float4x4 mWVP; // ローカル-ワールド-ビュー-射影まで | |
float3 vLightDir; // ライトの方向 | |
float4 BaseColor = { 0.10f, 0.10f, 0.10f, 0.10f }; // 白(デフォルト値) | |
float4 BaseLight = { 0.0f, 0.0f, 0.0f, 0.0f }; | |
// ---------------------------------------------------------------- | |
// 頂点シェーダ:渡された頂点(ローカル座標系)にどのような処理を施すか | |
// 今回はライトベクトルと法線ベクトルから色を算出して頂点の色を変える | |
// そして、ピクセルシェーダに渡すことで画面へ出力する | |
// ---------------------------------------------------------------- | |
struct VS_OUTPUT { | |
float4 Pos : POSITION; | |
float4 Color : COLOR0; | |
}; | |
VS_OUTPUT VS( | |
float4 Pos : POSITION, // 頂点のローカル座標での頂点位置を受け取る | |
float4 Normal : NORMAL // 頂点のローカル座標での法線ベクトルを受け取る | |
) { | |
VS_OUTPUT Out; // 出力データ | |
Out.Pos = mul(Pos, mWVP); // ローカル座標系のPosを射影まで変換する(これで表示できるようになる) | |
float3 L = vLightDir; // ライトベクトル | |
float3 N = Normal; // 法線ベクトル | |
// BaseColor自体が単色になっている | |
Out.Color = BaseColor + min(0.40f , BaseLight + max(0.0f, dot(N, L))); | |
//Out.Color = BaseColor; | |
return Out; | |
} | |
// ------------------------------------------------------------- | |
float4 PS(VS_OUTPUT In) : COLOR | |
{ | |
return In.Color; | |
} | |
// ------------------------------------------------------------- | |
// テクニック | |
// ------------------------------------------------------------- | |
technique TShader | |
{ | |
pass P0 | |
{ | |
VertexShader = compile vs_2_0 VS(); | |
PixelShader = compile ps_2_0 PS(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment