Cirno2022/script/sample/SamplePS02_HLSL.txt

86 lines
1.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//================================================================
//大域設定値
//Texture
sampler sampler0_ : register(s0);
//--------------------------------
//マスク用テクスチャ
//画面幅(マスクテクスチャサイズ)
const float SCREEN_WIDTH = 640;
const float SCREEN_HEIGHT = 480;
texture textureMask_;
sampler samplerMask_ = sampler_state
{
Texture = <textureMask_>;
};
//================================================================
//--------------------------------
//ピクセルシェーダ入力値
struct PS_INPUT
{
float4 diffuse : COLOR0; //ディフューズ色
float2 texCoord : TEXCOORD0; //テクスチャ座標
float2 vPos : VPOS; //描画先座標
};
//--------------------------------
//ピクセルシェーダ出力値
struct PS_OUTPUT
{
float4 color : COLOR0; //出力色
};
//================================================================
// シェーダ
//--------------------------------
//ピクセルシェーダ
PS_OUTPUT PsMask( PS_INPUT In ) : COLOR0
{
PS_OUTPUT Out;
//テクスチャの色
float4 colorTexture = tex2D(sampler0_, In.texCoord);
//頂点ディフーズ色
float4 colorDiffuse = In.diffuse;
//合成
float4 color = colorTexture * colorDiffuse;
Out.color = color;
if(color.a > 0)
{
//--------------------------------
//マスク用のテクスチャから色成分を取得
//UVでの位置は画像ファイルの横幅と高さからの割合
//例えば、640x480の画像の位置(320,240)はUVでは0.5,0.5になる。
float2 maskUV;
//描画先からマスク用テクスチャの位置を計算
maskUV.x = In.vPos.x / SCREEN_WIDTH;
maskUV.y = In.vPos.y / SCREEN_HEIGHT;
float4 colorMask = tex2D(samplerMask_, maskUV);
//マスクのRGB値を出力結果のα値として合成する
Out.color.a = ( colorMask.r + colorMask.g + colorMask.b ) * 0.3333f * color.a;
}
return Out;
}
//================================================================
//--------------------------------
//technique
technique TecMask
{
pass P0
{
PixelShader = compile ps_3_0 PsMask();
}
}