Last active
November 5, 2021 10:21
-
-
Save hexagit/93f7a067f911484a6646ed64a9929c14 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
//=========================================================================== | |
//! | |
//! @file SoftParticle.hlsli | |
//! @brief ソフトパーティクルの定数バッファなどの定義 | |
//! | |
//=========================================================================== | |
//----------------------------------------------------------- | |
//! @name 定義 | |
//----------------------------------------------------------- | |
//@{ | |
//=========================================================================== | |
//! @cbuffer cbObject | |
//! @brief オブジェクト用定数バッファ | |
//=========================================================================== | |
cbuffer cbObject : register(b0) | |
{ | |
row_major float4x4 gmW; // !< ワールド変換行列 | |
float4 gColor; // !< 乗算色 | |
float2 gThreshold; // !< しきい値 | |
} | |
//=========================================================================== | |
//! @cbuffer cbCamera | |
//! @brief カメラ情報用定数バッファ | |
//=========================================================================== | |
cbuffer cbCamera : register(b1) | |
{ | |
row_major float4x4 gmView; // !< ビュー変換行列 | |
row_major float4x4 gmProj; // !< 射影変換行列 | |
} | |
//=========================================================================== | |
//! @struct VSOutPut | |
//! @brief 頂点シェーダから出力する値 | |
//=========================================================================== | |
struct VSOutPut | |
{ | |
float4 Pos : SV_Position; //!< 射影行列 | |
float4 Color : TEXCOORD0; //!< 色 | |
float4 UV : TEXCOORD1; //!< UV | |
float4 wvpPos : TEXCOORD2; //!< 射影行列の複製 | |
} | |
//@} | |
//=========================================================================== | |
// END OF FILE | |
//=========================================================================== |
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
//=========================================================================== | |
//! | |
//! @file SoftParticlePS.hlsl | |
//! @brief ソフトパーティクルのピクセルシェーダ | |
//! | |
//=========================================================================== | |
//----------------------------------------------------------- | |
//! @name インクルード | |
//----------------------------------------------------------- | |
//@{ | |
#include "SoftParticle.hlsli" | |
//@} | |
//----------------------------------------------------------- | |
//! @name 変数 | |
//----------------------------------------------------------- | |
//@{ | |
Texture2D gTextuer : register(t0); //!< Colorテクスチャ | |
Texture2D gDepthTextuer : register(t1); //!< Depthテクスチャ | |
SamplerState gSampler : register(s0); //!< サンプラー | |
//@} | |
//----------------------------------------------------------- | |
//! @name 関数 | |
//----------------------------------------------------------- | |
//@{ | |
//----------------------------------------------------------- | |
//! @brief ピクセルシェーダーエントリーポイント | |
//! @param [in] In 入力データ | |
//! @return 色 | |
//----------------------------------------------------------- | |
float4 psMain(VSOutput In) : SV_TARGET | |
{ | |
float4 color = float4(1, 1, 1, 1); | |
float texColor gTexture.Sample(gSampler, In.UV); | |
float2 fetchUV = In.wvpPos.xy; | |
float alpha = 1.0f; | |
// Texture座標に合わせる | |
fetchUV.xy /= In.wvpPos.w; | |
fetchUV.x = 0.5 * (fetchUV.x + 1.0); | |
fetchUV.y = -0.5 * (fetchUV.y - 1.0); | |
// 今のピクセルの深度値 | |
float vz = In.wvpPos.z / In.wvpPos.w; | |
// 深度テクスチャから深度値を取得 | |
float depth = gDepthTexture.Sample(gSampler, fetchUV).r; | |
// 深度値の差分を取得 | |
float diff = abs(depth - vz); | |
//深度値の差分としきい値を比較しα値を決定 | |
if( diff < gThreshold ) { | |
alpha = diff / gThreshold; | |
} | |
else { | |
alpha = 1.0; | |
} | |
// 各色の合成 | |
color = texColor * In.Color * gColor; | |
color.a *= alpha; | |
return color; | |
} | |
//@} | |
//=========================================================================== | |
// END OF FILE | |
//=========================================================================== |
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
//=========================================================================== | |
//! | |
//! @file SoftParticleVS.hlsl | |
//! @brief ソフトパーティクルの頂点シェーダ | |
//! | |
//=========================================================================== | |
//----------------------------------------------------------- | |
//! @name インクルード | |
//----------------------------------------------------------- | |
//@{ | |
#include "SoftParticle.hlsli" | |
//@} | |
//----------------------------------------------------------- | |
//! @name 関数 | |
//----------------------------------------------------------- | |
//@{ | |
//----------------------------------------------------------- | |
//! @brief 頂点シェーダーエントリーポイント | |
//! @param [in] pos 頂点の位置 | |
//! @param [in] uv 頂点UV | |
//! @param [in] color 頂点色 | |
//! @return VSOutPut 出力データ | |
//----------------------------------------------------------- | |
VSOutPut vsMain(float4 pos : POSITION,float2 uv : TEXCOORD0, float4 color : COLOR) | |
{ | |
VSOutPut Out; | |
// 座標変換 | |
Out.Pos = mul(pos, gmW); | |
Out.Pos = mul(Out.Pos, gmView); | |
Out.Pos = mul(Out.Pos, gmProj); | |
Out.wvpPos = Out.Pos; | |
// 色 | |
Out.Color = color; | |
// UV | |
Out.UV = uv; | |
// 出力 | |
return Out; | |
} | |
//@} | |
//=========================================================================== | |
// END OF FILE | |
//=========================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment