//================================================================== // 定数 //================================================================== // テクスチャ int g_use_model_env_map; ///< 環境マップタイプ(シェーダー切り替えるタイプにした方が吉) Texture2D g_texture_diffuse; Texture2D g_texture_specular; Texture2D g_texture_normal; Texture2D g_texture_reflect; Texture2D g_texture_emissive; Texture2D g_texture_environment; Texture3D g_texture_diffuse3D; Texture3D g_texture_specular3D; Texture3D g_texture_normal3D; Texture3D g_texture_reflect3D; Texture3D g_texture_emissive3D; // 投影シャドウ用 Texture2D g_texture_proj_shadow; // コンスタント int g_GP_ConstantFlag; float g_GP_no_effect_shadow = 1.0f;///< 影の影響を受けないフラグ int g_GP_MipmapBias = 0; ///< ミップマップのバイアスをかける int g_GP_Mask = 0; ///< 2D ロックオンマーカー用マスク float g_GP_RimVal = 0.0f;///< リムライトの種類(1.0f:通常 0.5f闇) //================================================================== // 定数(2) ※シェーダー内のみ //================================================================== // サンプルステート SamplerState samLinear { Filter = MIN_MAG_MIP_LINEAR; AddressU = Wrap; AddressV = Wrap; AddressW = CLAMP; }; SamplerState samAnisotropic { //Filter = MIN_MAG_MIP_POINT; Filter = ANISOTROPIC; AddressU = Wrap; AddressV = Wrap; AddressW = CLAMP; MipLODBias = -1; }; SamplerState samAnisotropicBias { //Filter = MIN_MAG_MIP_POINT; Filter = ANISOTROPIC; AddressU = Wrap; AddressV = Wrap; AddressW = CLAMP; MipLODBias = -3; }; // ボリュームテクスチャはMipMapすると、W方向の解像度がすぐなくなってしまうので // 少し遠くでMipMapするようにバイアス掛ける SamplerState samAnisotropic3D { Filter = ANISOTROPIC; AddressU = Wrap; AddressV = Wrap; AddressW = CLAMP; MipLODBias = -3; }; SamplerState samPoint { Filter = MIN_MAG_MIP_POINT; AddressU = Wrap; AddressV = Wrap; AddressW = CLAMP; }; // Deferred Shadingのジオメトリパスはアルファブレンドしない BlendState NoBlend { BlendEnable[0] = FALSE; BlendEnable[1] = FALSE; BlendEnable[2] = FALSE; BlendEnable[3] = FALSE; BlendEnable[4] = FALSE; BlendEnable[5] = FALSE; BlendEnable[6] = FALSE; BlendEnable[7] = FALSE; }; //================================================================== // グローバル変数(設定) //================================================================== int g_GP_VSmode; int g_GP_PSmode; int g_GP_PSmode_NoLight; float4 g_cam_pos; // カメラ位置 // モデルごとの設定 cbuffer cbSetUpModelData { matrix g_matrix_w; // モデル→ワールド matrix g_matrix_wv; // モデル→ビュー matrix g_matrix_wvp; // モデル→プロジェクション matrix g_matrix_shadow_wvp; // 投影シャドウ用モデル→プロジェクション float g_emissive_rate; // 発光レート float g_CubeMapRate; // 環境マップレート float g_3DTexDepth; // モデルで使われている3Dテクスチャの深度(ゆくゆくはマテリアルに?) float g_DR_light_group; // モデルのライトグループ } // ビュー座標系法線を出力するか、グローバル座標系法線を出力するか、切り替える // 法線を変換する行列 #define G_NORMAL_COV_MTX (g_matrix_w) // 位置を変換する行列 #define G_POSITION_COV_MTX (g_matrix_w) // ノードごとの設定 cbuffer cbSetUpNodeData { matrix g_matrix_model; // モデリング座標 int stencil_write_value = 0; } // マテリアル毎の設定 cbuffer cbSetUpMaterialData { // マテリアル float4 material_emission; // エミッションカラー float4 material_diffuse; // ディフューズカラー float4 material_ambient; // アンビエントカラー // UVスクロール float4 texture_transform; // テクスチャ変換行列 float material_specular; // スペキュラカラー float material_shininess; // 輝度 float g_reflection_emissive_rate; // 反射マップを発光マップとして扱うレート } // カラー変更のパラメーター(nsModel::stChangeColorParam) cbuffer cbChangeColor { float4 change_color_scale; // スケール float4 change_color_offset; // オフセット } cbuffer cbSetUpSkinMesh { matrix g_matrix_bone_mtx0; matrix g_matrix_bone_mtx1; matrix g_matrix_bone_mtx2; matrix g_matrix_bone_mtx3; matrix g_matrix_bone_mtx4; matrix g_matrix_bone_mtx5; } // スキニングするボーン数 cbuffer cbWeightNum { int g_weight_num; } SamplerState LinearSampler { Filter = MIN_MAG_MIP_LINEAR; AddressU = Clamp; AddressV = Clamp; }; // パラボラ環境マップアクセス // 反射ベクトルを入力 float4 texDP( float3 vec) { vec = normalize(vec); bool front = (vec.z >= 0); if ( !front ) vec.xz = -vec.xz; float2 uv; uv = vec.xy / (1+vec.z); uv.y = -uv.y; uv = uv * 0.5 + 0.5; //uv.x /= 2; // テクスチャは横2倍 //if ( !front ) { // 後方テクスチャは2枚目(右半分) // uv.x += 0.5; //} //return texParabEnvMap.Sample( LinearSampler, uv ); return g_texture_environment.Sample( LinearSampler, uv ); //return g_texture_specular.Sample( LinearSampler, uv ); } //================================================================== // シェーダーの入力 //================================================================== // 頂点シェーダーの入力 struct VS_INPUT { float4 m_position : POSITION; // 座標 float3 m_normal: NORMAL; // 法線 float3 m_tangent: TANGENT; // 接線 float3 m_binormal: BINORMAL; // 従法線 float4 m_color: COLOR; // 色 float2 m_uv: TEXCOORD; // UV float weight0: WEIGHTA; float weight1: WEIGHTB; float weight2: WEIGHTC; float weight3: WEIGHTD; float weight4: WEIGHTE; float weight5: WEIGHTF; }; // ピクセルシェーダーの入力 struct PS_INPUT { float4 m_position : SV_POSITION; // 頂点座標 float4 m_color : COLOR; // 頂点カラー float2 m_uv : TEXCOORD0; // UV float3 m_position2 : TEXCOORD1; // ワールド座標 float3 vNormal : TEXCOORD2; float3 vTangent : TEXCOORD3; float3 vBinormal : TEXCOORD4; //float4 m_uv_shadow : POSITION; // 投影シャドウ用UV }; // ピクセルシェーダーの出力 struct PS_OUTPUT { float4 m_diffuse : SV_TARGET0; // ディフューズカラー+スペキュラ強度 float4 m_ambient : SV_TARGET1; // アンビエント+スペキュラ係数 float4 m_normal : SV_TARGET2; // グローバル空間法線 float4 m_position : SV_TARGET3; // グローバル空間位置 float4 m_reflection : SV_TARGET4; // 反射強度(現状Rのみ) float4 m_specular : SV_TARGET5; // スペキュラ float4 m_emissive : SV_TARGET6; }; //============================================================================================================================== // ■ バーテックスシェーダー //============================================================================================================================== //-------------------------------------------- //--------- 頂点シェーダー リジッド 法線マップ無し--------- PS_INPUT VS_NoWeight( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 // 姿勢×カメラ変換 float4 model_pos = mul( vtx, g_matrix_model ); output.m_position = mul( model_pos, g_matrix_wvp ); nml = mul( nml, (float3x3)g_matrix_model ); output.vNormal = normalize(mul( nml, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー // 色変更、大した計算ではないので常に output.m_color = input.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 output.m_position2 = (float3)mul( model_pos, G_POSITION_COV_MTX ); // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー リジッド 法線マップあり--------- PS_INPUT VS_NoWeightNormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 // 姿勢×カメラ変換 float4 model_pos = mul( vtx, g_matrix_model ); output.m_position = mul( model_pos, g_matrix_wvp ); nml = mul( nml, (float3x3)g_matrix_model ); output.vNormal = normalize(mul( nml, (float3x3)G_NORMAL_COV_MTX)); { tan = mul( tan, (float3x3)g_matrix_model ); output.vTangent = normalize(mul( tan, (float3x3)G_NORMAL_COV_MTX)); bin = mul( bin, (float3x3)g_matrix_model ); output.vBinormal = normalize(mul( bin, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー // 色変更、大した計算ではないので常に output.m_color = input.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 // グローバル座標系での頂点座標 output.m_position2 = (float3)mul( model_pos, G_POSITION_COV_MTX ); // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 1ウェイト 法線マップ無し--------- PS_INPUT VS_Weight1( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 1ウェイト 法線マップあり--------- PS_INPUT VS_Weight1NormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); {output.vTangent += input.weight0 * mul(tan, (float3x3)g_matrix_bone_mtx0); output.vBinormal+= input.weight0 * mul(bin, (float3x3)g_matrix_bone_mtx0); } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); { output.vTangent = normalize(mul( output.vTangent, (float3x3)G_NORMAL_COV_MTX)); output.vBinormal = normalize(mul( output.vBinormal, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 2ウェイト 法線マップ無し--------- PS_INPUT VS_Weight2( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 2ウェイト 法線マップあり--------- PS_INPUT VS_Weight2NormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); {output.vTangent += input.weight0 * mul(tan, (float3x3)g_matrix_bone_mtx0); output.vBinormal+= input.weight0 * mul(bin, (float3x3)g_matrix_bone_mtx0); } { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); {output.vTangent += input.weight1 * mul(tan, (float3x3)g_matrix_bone_mtx1); output.vBinormal+= input.weight1 * mul(bin, (float3x3)g_matrix_bone_mtx1); } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); { output.vTangent = normalize(mul( output.vTangent, (float3x3)G_NORMAL_COV_MTX)); output.vBinormal = normalize(mul( output.vBinormal, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 3ウェイト 法線マップ無し--------- PS_INPUT VS_Weight3( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 3ウェイト 法線マップあり--------- PS_INPUT VS_Weight3NormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); {output.vTangent += input.weight0 * mul(tan, (float3x3)g_matrix_bone_mtx0); output.vBinormal+= input.weight0 * mul(bin, (float3x3)g_matrix_bone_mtx0); } { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); {output.vTangent += input.weight1 * mul(tan, (float3x3)g_matrix_bone_mtx1); output.vBinormal+= input.weight1 * mul(bin, (float3x3)g_matrix_bone_mtx1); } { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); {output.vTangent += input.weight2 * mul(tan, (float3x3)g_matrix_bone_mtx2); output.vBinormal+= input.weight2 * mul(bin, (float3x3)g_matrix_bone_mtx2); } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); { output.vTangent = normalize(mul( output.vTangent, (float3x3)G_NORMAL_COV_MTX)); output.vBinormal = normalize(mul( output.vBinormal, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 4ウェイト 法線マップ無し--------- PS_INPUT VS_Weight4( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); { model_pos += input.weight3 * mul(vtx, g_matrix_bone_mtx3); output.vNormal += input.weight3 * mul(nml, (float3x3)g_matrix_bone_mtx3); } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 4ウェイト 法線マップあり--------- PS_INPUT VS_Weight4NormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); {output.vTangent += input.weight0 * mul(tan, (float3x3)g_matrix_bone_mtx0); output.vBinormal+= input.weight0 * mul(bin, (float3x3)g_matrix_bone_mtx0); } { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); {output.vTangent += input.weight1 * mul(tan, (float3x3)g_matrix_bone_mtx1); output.vBinormal+= input.weight1 * mul(bin, (float3x3)g_matrix_bone_mtx1); } { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); {output.vTangent += input.weight2 * mul(tan, (float3x3)g_matrix_bone_mtx2); output.vBinormal+= input.weight2 * mul(bin, (float3x3)g_matrix_bone_mtx2); } { model_pos += input.weight3 * mul(vtx, g_matrix_bone_mtx3); output.vNormal += input.weight3 * mul(nml, (float3x3)g_matrix_bone_mtx3); {output.vTangent += input.weight3 * mul(tan, (float3x3)g_matrix_bone_mtx3); output.vBinormal+= input.weight3 * mul(bin, (float3x3)g_matrix_bone_mtx3); } } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); { output.vTangent = normalize(mul( output.vTangent, (float3x3)G_NORMAL_COV_MTX)); output.vBinormal = normalize(mul( output.vBinormal, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 5ウェイト 法線マップ無し--------- PS_INPUT VS_Weight5( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); { model_pos += input.weight3 * mul(vtx, g_matrix_bone_mtx3); output.vNormal += input.weight3 * mul(nml, (float3x3)g_matrix_bone_mtx3); { model_pos += input.weight4 * mul(vtx, g_matrix_bone_mtx4); output.vNormal += input.weight4 * mul(nml, (float3x3)g_matrix_bone_mtx4); } } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 5ウェイト 法線マップあり--------- PS_INPUT VS_Weight5NormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); {output.vTangent += input.weight0 * mul(tan, (float3x3)g_matrix_bone_mtx0); output.vBinormal+= input.weight0 * mul(bin, (float3x3)g_matrix_bone_mtx0); } { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); {output.vTangent += input.weight1 * mul(tan, (float3x3)g_matrix_bone_mtx1); output.vBinormal+= input.weight1 * mul(bin, (float3x3)g_matrix_bone_mtx1); } { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); {output.vTangent += input.weight2 * mul(tan, (float3x3)g_matrix_bone_mtx2); output.vBinormal+= input.weight2 * mul(bin, (float3x3)g_matrix_bone_mtx2); } { model_pos += input.weight3 * mul(vtx, g_matrix_bone_mtx3); output.vNormal += input.weight3 * mul(nml, (float3x3)g_matrix_bone_mtx3); {output.vTangent += input.weight3 * mul(tan, (float3x3)g_matrix_bone_mtx3); output.vBinormal+= input.weight3 * mul(bin, (float3x3)g_matrix_bone_mtx3); } { model_pos += input.weight4 * mul(vtx, g_matrix_bone_mtx4); output.vNormal += input.weight4 * mul(nml, (float3x3)g_matrix_bone_mtx4); {output.vTangent += input.weight4 * mul(tan, (float3x3)g_matrix_bone_mtx4); output.vBinormal+= input.weight4 * mul(bin, (float3x3)g_matrix_bone_mtx4); } } } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); { output.vTangent = normalize(mul( output.vTangent, (float3x3)G_NORMAL_COV_MTX)); output.vBinormal = normalize(mul( output.vBinormal, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 6ウェイト 法線マップ無し--------- PS_INPUT VS_Weight6( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 //float3 tan = input.m_tangent; // 正規化済み前提 //float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); { model_pos += input.weight3 * mul(vtx, g_matrix_bone_mtx3); output.vNormal += input.weight3 * mul(nml, (float3x3)g_matrix_bone_mtx3); { model_pos += input.weight4 * mul(vtx, g_matrix_bone_mtx4); output.vNormal += input.weight4 * mul(nml, (float3x3)g_matrix_bone_mtx4); { model_pos += input.weight5 * mul(vtx, g_matrix_bone_mtx5); output.vNormal += input.weight5 * mul(nml, (float3x3)g_matrix_bone_mtx5); } } } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } //-------------------------------------------- //--------- 頂点シェーダー 6ウェイト 法線マップあり--------- PS_INPUT VS_Weight6NormalMap( VS_INPUT input ) { // 出力クリア PS_INPUT output = (PS_INPUT)0; //--- // 頂点座標(入力) float4 vtx = input.m_position; vtx.w = 1.0f; // 念のため // 法線(入力) float3 nml = input.m_normal; // 正規化済み前提 float3 tan = input.m_tangent; // 正規化済み前提 float3 bin = input.m_binormal; // 正規化済み前提 // モデリング座標 float4 model_pos = float4(0,0,0,0); model_pos += input.weight0 * mul(vtx, g_matrix_bone_mtx0); output.vNormal += input.weight0 * mul(nml, (float3x3)g_matrix_bone_mtx0); {output.vTangent += input.weight0 * mul(tan, (float3x3)g_matrix_bone_mtx0); output.vBinormal+= input.weight0 * mul(bin, (float3x3)g_matrix_bone_mtx0); } { model_pos += input.weight1 * mul(vtx, g_matrix_bone_mtx1); output.vNormal += input.weight1 * mul(nml, (float3x3)g_matrix_bone_mtx1); {output.vTangent += input.weight1 * mul(tan, (float3x3)g_matrix_bone_mtx1); output.vBinormal+= input.weight1 * mul(bin, (float3x3)g_matrix_bone_mtx1); } { model_pos += input.weight2 * mul(vtx, g_matrix_bone_mtx2); output.vNormal += input.weight2 * mul(nml, (float3x3)g_matrix_bone_mtx2); {output.vTangent += input.weight2 * mul(tan, (float3x3)g_matrix_bone_mtx2); output.vBinormal+= input.weight2 * mul(bin, (float3x3)g_matrix_bone_mtx2); } { model_pos += input.weight3 * mul(vtx, g_matrix_bone_mtx3); output.vNormal += input.weight3 * mul(nml, (float3x3)g_matrix_bone_mtx3); {output.vTangent += input.weight3 * mul(tan, (float3x3)g_matrix_bone_mtx3); output.vBinormal+= input.weight3 * mul(bin, (float3x3)g_matrix_bone_mtx3); } { model_pos += input.weight4 * mul(vtx, g_matrix_bone_mtx4); output.vNormal += input.weight4 * mul(nml, (float3x3)g_matrix_bone_mtx4); {output.vTangent += input.weight4 * mul(tan, (float3x3)g_matrix_bone_mtx4); output.vBinormal+= input.weight4 * mul(bin, (float3x3)g_matrix_bone_mtx4); } { model_pos += input.weight5 * mul(vtx, g_matrix_bone_mtx5); output.vNormal += input.weight5 * mul(nml, (float3x3)g_matrix_bone_mtx5); {output.vTangent += input.weight5 * mul(tan, (float3x3)g_matrix_bone_mtx5); output.vBinormal+= input.weight5 * mul(bin, (float3x3)g_matrix_bone_mtx5); } } } } } } output.m_position = mul(model_pos, g_matrix_wvp); output.vNormal = normalize(mul(output.vNormal, (float3x3)G_NORMAL_COV_MTX)); { output.vTangent = normalize(mul( output.vTangent, (float3x3)G_NORMAL_COV_MTX)); output.vBinormal = normalize(mul( output.vBinormal, (float3x3)G_NORMAL_COV_MTX)); } //--- // 頂点カラー output.m_color = ( input.m_color ); // 色変更、大した計算ではないので常に output.m_color = output.m_color * change_color_scale + change_color_offset; //--- // UV // スクロール output.m_uv = input.m_uv + texture_transform.xy; //--- // ビュー座標orグローバル座標 float4 _vtx = mul( model_pos, G_POSITION_COV_MTX ); // グローバル座標系での頂点座標 output.m_position2 = (float3)_vtx; // ワールド座標 return output; } ///< テクスチャ2D 通常バイアス float4 SampleTexNoBias( Texture2D tex, float2 uv ) { return tex.Sample( samAnisotropic, uv); } ///< テクスチャ2D バイアス指定 float4 SampleTexBias( Texture2D tex, float2 uv ) { return tex.Sample( samAnisotropicBias, uv ); } ///< テクスチャ3D 通常バイアス float4 SampleTexNoBias( Texture3D tex, float3 uvw ) { return tex.Sample( samAnisotropic3D, uvw); } ///< テクスチャ3D バイアス指定 float4 SampleTexBias( Texture3D tex, float3 uvw ) { return tex.Sample( samAnisotropic3D, uvw); } //============================================================================================================================== // ■ピクセルシェーダー //============================================================================================================================== //---------------------------------------------------- // ピクセルシェーダー //---------------------------------------------------- PS_OUTPUT PS_Texture2D_NormalMap( PS_INPUT input, uniform bool bNormalMap, uniform bool bTexture3D, uniform bool bBias ) { // 出力 PS_OUTPUT output = (PS_OUTPUT)0; output.m_normal.rgba = float4(0.0f,0.0f,0.0f,1.0f); float2 TexUV = input.m_uv; float3 TexUVW = float3(input.m_uv, g_3DTexDepth); // ディフューズテクスチャ float4 diff_tex; if ( bTexture3D ) { if ( bBias ) { diff_tex = SampleTexBias(g_texture_diffuse3D, TexUVW ); ///< バイアスあり } else { diff_tex = SampleTexNoBias(g_texture_diffuse3D, TexUVW ); } } else { if ( bBias ) { diff_tex = SampleTexBias(g_texture_diffuse, TexUV ); ///< バイアスあり } else { diff_tex = SampleTexNoBias(g_texture_diffuse, TexUV ); } } // 反射テクスチャ float4 reflect_tex; if ( bTexture3D ) { if ( bBias ) { reflect_tex = SampleTexBias(g_texture_reflect3D, TexUVW ); ///< バイアスあり } else { reflect_tex = SampleTexNoBias(g_texture_reflect3D, TexUVW ); } } else { if ( bBias ) { reflect_tex = SampleTexBias(g_texture_reflect, TexUV ); ///< バイアスあり } else { reflect_tex = SampleTexNoBias(g_texture_reflect, TexUV ); } } // 発光テクスチャ float4 emission_tex; if ( bTexture3D ) { if ( bBias ) { emission_tex = SampleTexBias(g_texture_emissive3D, TexUVW ); ///< バイアスあり } else { emission_tex = SampleTexNoBias(g_texture_emissive3D, TexUVW ); } } else { if ( bBias ) { emission_tex = SampleTexBias(g_texture_emissive, TexUV ); ///< バイアスあり } else { emission_tex = SampleTexNoBias(g_texture_emissive, TexUV ); } } // スペキュラテクスチャ float4 specular_tex; if ( bTexture3D ) { if ( bBias ) { specular_tex = SampleTexBias(g_texture_specular3D, TexUVW ); ///< バイアスあり } else { specular_tex = SampleTexNoBias(g_texture_specular3D, TexUVW ); } } else { if ( bBias ) { specular_tex = SampleTexBias(g_texture_specular, TexUV ); ///< バイアスあり } else { specular_tex = SampleTexNoBias(g_texture_specular, TexUV ); } } //////////////// // 位置出力 output.m_position = float4(input.m_position2,1); // ステンシルバッファの代わりにpositionのアルファを書きこみフラグに使ってみる //////////////// // 反射強度出力 反射テクスチャに、与えられた定数値を掛ける output.m_reflection.r = reflect_tex.r * g_CubeMapRate; //////////////// // マスク値をgに格納 output.m_reflection.g = g_GP_Mask; /////////////////// /// エミッション // エミッションカラーはマテリアル×低数値×発光マップ float4 emissive = material_emission * g_emissive_rate * emission_tex; // 反射マップを発光マップに使う場合は、マテリアルとは別に追加する。 emissive += reflect_tex * g_reflection_emissive_rate; // エミッション出力には、頂点カラー×ディフューズテクスチャ×マテリアルエミッションを出力 output.m_emissive = emissive * input.m_color * diff_tex; /////////////// // アンビエント // 頂点カラー×ディフューズテクスチャ×マテリアルアンビエントを出力 output.m_ambient = input.m_color * diff_tex * material_ambient; ////////////////// // ディフューズ // 頂点カラー×ディフューズテクスチャ×マテリアルディフューズ、を出力 output.m_diffuse = input.m_color * diff_tex * material_diffuse; ////////////////////// // スペキュラカラー output.m_specular = material_specular.r * specular_tex; // アンビエントマップのアルファにスペキュラ係数格納(整数→8ビットUNORM変換) output.m_ambient.a = material_shininess * 0.0039215f; // / 0xFF; // ライトのグループをディフューズのアルファに格納 output.m_diffuse.a = g_DR_light_group * 0.0039215f; // / 0xFF; // リムライト情報を格納 output.m_reflection.b = 0.0f;///< リムライトなし if( g_use_model_env_map ) { ///< ここでモデル個別のフェイク環境マップテスト float3 eye = normalize(input.m_position2 - g_cam_pos.xyz); float3 nrm = normalize( input.vNormal.xyz ); float3 eyeRef = reflect( eye, nrm.xyz ); eyeRef = normalize(mul( float4(eyeRef, 0), g_matrix_wv).xyz); float4 envMap; envMap = texDP( eyeRef );///< 双放物面マップ output.m_ambient.xyz += envMap.xyz*reflect_tex.r; ///< ライトパスで動的環境マップされないようにここで使用が完了したら消しておきます。 ///< 固定環境マップを行ったら動的環境マップを行う必要はありません。 output.m_reflection.r =0.0f; } // 接空間法線 float3 norm = input.vNormal; // 法線マップあり if ( bNormalMap ) { // テクスチャの値 float4 norm_col; if ( bTexture3D ) { if ( bBias ) { norm_col = SampleTexBias(g_texture_normal3D, TexUVW ); ///< バイアスあり } else { norm_col = SampleTexNoBias(g_texture_normal3D, TexUVW ); } } else { if ( bBias ) { norm_col = SampleTexBias(g_texture_normal, TexUV ); ///< バイアスあり } else { norm_col = SampleTexNoBias(g_texture_normal, TexUV ); } } // 格納(BC5フォーマット(RGのみの2チャンネル法線マップフォーマット)に対応) norm.r = (norm_col.r * 2.0 - 1.0); norm.g = -(norm_col.g * 2.0 - 1.0); norm.b = sqrt(saturate(1-(pow(norm.r, 2) + pow(norm.g, 2)))); float3x3 mtxRot; mtxRot[0] = normalize( input.vTangent ); mtxRot[1] = normalize( input.vBinormal ); mtxRot[2] = normalize( input.vNormal ); norm = normalize( mul( norm, mtxRot ) ); } // -1〜1の場合(SNORM) //output.m_normal = float4(norm,0); //法線MAPテクスチャに深度も追加する(SSAO検証) float4 tDepth = mul(output.m_position,g_matrix_wv); // float len2 = length ( g_cam_pos.xyz - output.m_position.xyz); // float fDepth = (len2 / g_cam_pos.w)*5.0f; float fDepth = tDepth.z/g_cam_pos.w; // float fDepth = len2; // 0〜1の場合(UNORM) output.m_normal = float4((norm + 1.0f)*0.5f,fDepth); // ライティング無効フラグをリフレクションのアルファに格納 output.m_reflection.a = g_GP_no_effect_shadow; return output; } //---------------------------------------------------- // ピクセルシェーダー リムライト //---------------------------------------------------- PS_OUTPUT PS_Rim_Texture2D_NormalMap( PS_INPUT input, uniform bool bNormalMap, uniform bool bTexture3D, uniform bool bBias ) { // 出力 PS_OUTPUT output = (PS_OUTPUT)0; output.m_normal.rgba = float4(0.0f,0.0f,0.0f,1.0f); float2 TexUV = input.m_uv; float3 TexUVW = float3(input.m_uv, g_3DTexDepth); // ディフューズテクスチャ float4 diff_tex; if ( bTexture3D ) { if ( bBias ) { diff_tex = SampleTexBias(g_texture_diffuse3D, TexUVW ); ///< バイアスあり } else { diff_tex = SampleTexNoBias(g_texture_diffuse3D, TexUVW ); } } else { if ( bBias ) { diff_tex = SampleTexBias(g_texture_diffuse, TexUV ); ///< バイアスあり } else { diff_tex = SampleTexNoBias(g_texture_diffuse, TexUV ); } } // 反射テクスチャ float4 reflect_tex; if ( bTexture3D ) { if ( bBias ) { reflect_tex = SampleTexBias(g_texture_reflect3D, TexUVW ); ///< バイアスあり } else { reflect_tex = SampleTexNoBias(g_texture_reflect3D, TexUVW ); } } else { if ( bBias ) { reflect_tex = SampleTexBias(g_texture_reflect, TexUV ); ///< バイアスあり } else { reflect_tex = SampleTexNoBias(g_texture_reflect, TexUV ); } } // 発光テクスチャ float4 emission_tex; if ( bTexture3D ) { if ( bBias ) { emission_tex = SampleTexBias(g_texture_emissive3D, TexUVW ); ///< バイアスあり } else { emission_tex = SampleTexNoBias(g_texture_emissive3D, TexUVW ); } } else { if ( bBias ) { emission_tex = SampleTexBias(g_texture_emissive, TexUV ); ///< バイアスあり } else { emission_tex = SampleTexNoBias(g_texture_emissive, TexUV ); } } // スペキュラテクスチャ float4 specular_tex; if ( bTexture3D ) { if ( bBias ) { specular_tex = SampleTexBias(g_texture_specular3D, TexUVW ); ///< バイアスあり } else { specular_tex = SampleTexNoBias(g_texture_specular3D, TexUVW ); } } else { if ( bBias ) { specular_tex = SampleTexBias(g_texture_specular, TexUV ); ///< バイアスあり } else { specular_tex = SampleTexNoBias(g_texture_specular, TexUV ); } } //////////////// // 位置出力 output.m_position = float4(input.m_position2,1); // ステンシルバッファの代わりにpositionのアルファを書きこみフラグに使ってみる //////////////// // 反射強度出力 反射テクスチャに、与えられた定数値を掛ける output.m_reflection.r = reflect_tex.r * g_CubeMapRate; //////////////// // マスク値をgに格納 output.m_reflection.g = g_GP_Mask; /////////////////// /// エミッション // エミッションカラーはマテリアル×低数値×発光マップ float4 emissive = material_emission * g_emissive_rate * emission_tex; // 反射マップを発光マップに使う場合は、マテリアルとは別に追加する。 emissive += reflect_tex * g_reflection_emissive_rate; // エミッション出力には、頂点カラー×ディフューズテクスチャ×マテリアルエミッションを出力 output.m_emissive = emissive * input.m_color * diff_tex; /////////////// // アンビエント // 頂点カラー×ディフューズテクスチャ×マテリアルアンビエントを出力 output.m_ambient = input.m_color * diff_tex * material_ambient; ////////////////// // ディフューズ // 頂点カラー×ディフューズテクスチャ×マテリアルディフューズ、を出力 output.m_diffuse = input.m_color * diff_tex * material_diffuse; ///< リムライト情報を格納 output.m_reflection.b = g_GP_RimVal;///< リムライトあり ////////////////////// // スペキュラカラー output.m_specular = material_specular.r * specular_tex; // アンビエントマップのアルファにスペキュラ係数格納(整数→8ビットUNORM変換) output.m_ambient.a = material_shininess * 0.0039215f; // / 0xFF; // ライトのグループをディフューズのアルファに格納 output.m_diffuse.a = g_DR_light_group * 0.0039215f; // / 0xFF; if( g_use_model_env_map ) { ///< ここでモデル個別のフェイク環境マップテスト float3 eye = normalize(input.m_position2 - g_cam_pos.xyz); float3 nrm = normalize( input.vNormal.xyz ); float3 eyeRef = reflect( eye, nrm.xyz ); eyeRef = normalize(mul( float4(eyeRef, 0), g_matrix_wv).xyz); float4 envMap; envMap = texDP( eyeRef );///< 双放物面マップ output.m_ambient.xyz += envMap.xyz*reflect_tex.r; ///< ライトパスで動的環境マップされないようにここで使用が完了したら消しておきます。 ///< 固定環境マップを行ったら動的環境マップを行う必要はありません。 output.m_reflection.r =0.0f; } // 接空間法線 float3 norm = input.vNormal; // 法線マップあり if ( bNormalMap ) { // テクスチャの値 float4 norm_col; if ( bTexture3D ) { if ( bBias ) { norm_col = SampleTexBias(g_texture_normal3D, TexUVW ); ///< バイアスあり } else { norm_col = SampleTexNoBias(g_texture_normal3D, TexUVW ); } } else { if ( bBias ) { norm_col = SampleTexBias(g_texture_normal, TexUV ); ///< バイアスあり } else { norm_col = SampleTexNoBias(g_texture_normal, TexUV ); } } // 格納(BC5フォーマット(RGのみの2チャンネル法線マップフォーマット)に対応) norm.r = (norm_col.r * 2.0 - 1.0); norm.g = -(norm_col.g * 2.0 - 1.0); norm.b = sqrt(saturate(1-(pow(norm.r, 2) + pow(norm.g, 2)))); float3x3 mtxRot; mtxRot[0] = normalize( input.vTangent ); mtxRot[1] = normalize( input.vBinormal ); mtxRot[2] = normalize( input.vNormal ); norm = normalize( mul( norm, mtxRot ) ); //norm = normalize( mul( float3(0,0,1), mtxRot ) ); } // -1〜1の場合(SNORM) //output.m_normal = float4(norm,0); //法線MAPテクスチャに深度も追加する(SSAO検証) // float4 tDepth = mul(output.m_position,g_matrix_wv); float len2 = length ( g_cam_pos.xyz - output.m_position.xyz); float fDepth = len2 / (g_cam_pos.w); // float fDepth = tDepth.z/(g_cam_pos.w*0.01f); // float fDepth = len2; // fDepth = 0.9f; // 0〜1の場合(UNORM) output.m_normal = float4((norm + 1.0f)*0.5f,fDepth); // output.m_normal = float4((norm + 1.0f)*0.5f,0.0f); // ライティング無効フラグをリフレクションのアルファに格納 output.m_reflection.a = g_GP_no_effect_shadow; return output; } //---------------------------------------------------- // ピクセルシェーダー ライト無し //---------------------------------------------------- PS_OUTPUT PS_NoLight_Texture2D( PS_INPUT input, uniform bool bTexture3D, uniform bool bBias ) { // 出力 PS_OUTPUT output = (PS_OUTPUT)0; output.m_normal.rgba = float4(0.0f,0.0f,0.0f,1.0f); float2 TexUV = input.m_uv; float3 TexUVW = float3(input.m_uv, g_3DTexDepth); // ディフューズテクスチャ float4 diff_tex; if ( bTexture3D ) { if ( bBias ) { diff_tex = SampleTexBias(g_texture_diffuse3D, TexUVW ); ///< バイアスあり } else { diff_tex = SampleTexNoBias(g_texture_diffuse3D, TexUVW ); } } else { if ( bBias ) { diff_tex = SampleTexBias(g_texture_diffuse, TexUV ); ///< バイアスあり } else { diff_tex = SampleTexNoBias(g_texture_diffuse, TexUV ); } } // 反射テクスチャ float4 reflect_tex; if ( bTexture3D ) { if ( bBias ) { reflect_tex = SampleTexBias(g_texture_reflect3D, TexUVW ); ///< バイアスあり } else { reflect_tex = SampleTexNoBias(g_texture_reflect3D, TexUVW ); } } else { if ( bBias ) { reflect_tex = SampleTexBias(g_texture_reflect, TexUV ); ///< バイアスあり } else { reflect_tex = SampleTexNoBias(g_texture_reflect, TexUV ); } } // 発光テクスチャ float4 emission_tex; if ( bTexture3D ) { if ( bBias ) { emission_tex = SampleTexBias(g_texture_emissive3D, TexUVW ); ///< バイアスあり } else { emission_tex = SampleTexNoBias(g_texture_emissive3D, TexUVW ); } } else { if ( bBias ) { emission_tex = SampleTexBias(g_texture_emissive, TexUV ); ///< バイアスあり } else { emission_tex = SampleTexNoBias(g_texture_emissive, TexUV ); } } // 位置 output.m_position = float4(input.m_position2,1); // ステンシルバッファの代わりにpositionのアルファを使ってみる //////////////// // 反射強度出力 反射テクスチャに、与えられた定数値を掛ける output.m_reflection.r = reflect_tex.r * g_CubeMapRate; /////////////////// /// エミッション // エミッションカラーはマテリアル×低数値×発光マップ float4 emissive = material_emission * g_emissive_rate * emission_tex; // 反射マップを発光マップに使う場合は、マテリアルとは別に追加する。 emissive += reflect_tex * g_reflection_emissive_rate; // エミッション出力には、頂点カラー×ディフューズテクスチャ×マテリアルエミッションを出力 output.m_emissive = emissive * input.m_color * diff_tex; // ライトの影響がない場合は、アンビエントバッファにテクスチャカラーを出力して終わる。 //output.m_ambient = input.m_color * diff_tex;// * material_ambient; // じゃなくて、エミッションに吐くのが正解か output.m_emissive += input.m_color * diff_tex;// * material_ambient; // 環境マップのために、法線計算は必要だった // でも、法線マップは未対応とする? // 接空間法線 float3 norm = input.vNormal; // -1〜1の場合(SNORM) //output.m_normal = float4(norm,0); //法線MAPテクスチャに深度も追加する(SSAO検証) float4 tDepth = mul(output.m_position,g_matrix_wv); // float len2 = length ( g_cam_pos.xyz - output.m_position.xyz); // float fDepth = (len2 / g_cam_pos.w)*5.0f; float fDepth = tDepth.z/g_cam_pos.w; // float fDepth = len2; // 0〜1の場合(UNORM) output.m_normal = float4((norm + 1.0f)*0.5f,fDepth); // シャイネスダミー // 0を入れておくとライトパスでpow(0,0)でNaN返すため output.m_ambient.a = 0.5f; if( g_use_model_env_map ) { ///< ここでモデル個別のフェイク環境マップテスト float3 eye = normalize(input.m_position2 - g_cam_pos.xyz); float3 nrm = normalize( input.vNormal.xyz ); float3 eyeRef = reflect( eye, nrm.xyz ); eyeRef = normalize(mul( float4(eyeRef, 0), g_matrix_wv).xyz); float4 envMap; envMap = texDP( eyeRef );///< 双放物面マップ output.m_emissive.xyz += envMap.xyz*reflect_tex.r; ///< ライトパスで動的環境マップされないようにここで使用が完了したら消しておきます。 ///< 固定環境マップを行ったら動的環境マップを行う必要はありません。 output.m_reflection.r =0.0f; } // ライティング無効フラグをリフレクションのアルファに格納 output.m_reflection.a = g_GP_no_effect_shadow; return output; } // 頂点シェーダ VertexShader vs[] = { CompileShader( vs_4_0, VS_NoWeight() ), // リジッド 法線マップ 無し CompileShader( vs_4_0, VS_NoWeightNormalMap() ), // リジッド 法線マップ あり CompileShader( vs_4_0, VS_Weight1() ), // ウェイト1 法線マップ 無し CompileShader( vs_4_0, VS_Weight1NormalMap() ), // ウェイト1 法線マップ あり CompileShader( vs_4_0, VS_Weight2() ), // ウェイト2 法線マップ 無し CompileShader( vs_4_0, VS_Weight2NormalMap() ), // ウェイト2 法線マップ あり CompileShader( vs_4_0, VS_Weight3() ), // ウェイト3 法線マップ 無し CompileShader( vs_4_0, VS_Weight3NormalMap() ), // ウェイト3 法線マップ あり CompileShader( vs_4_0, VS_Weight4() ), // ウェイト4 法線マップ 無し CompileShader( vs_4_0, VS_Weight4NormalMap() ), // ウェイト4 法線マップ あり CompileShader( vs_4_0, VS_Weight5() ), // ウェイト5 法線マップ 無し CompileShader( vs_4_0, VS_Weight5NormalMap() ), // ウェイト5 法線マップ あり CompileShader( vs_4_0, VS_Weight6() ), // ウェイト6 法線マップ 無し CompileShader( vs_4_0, VS_Weight6NormalMap() ), // ウェイト6 法線マップ あり }; // ライティングするピクセルシェーダ PixelShader ps_normal[] = {/* CompileShader( ps_4_0, PS_Texture2D_NormalMap( false, false, false ) ), //法線マップ無し テクスチャ2D バイアス無し CompileShader( ps_4_0, PS_Texture2D_NormalMap( true, false, false ) ), //法線マップあり テクスチャ2D バイアス無し CompileShader( ps_4_0, PS_Texture2D_NormalMap( false, true, false ) ), //法線マップ無し テクスチャ3D バイアス無し CompileShader( ps_4_0, PS_Texture2D_NormalMap( true, true, false ) ), //法線マップあり テクスチャ3D バイアス無し CompileShader( ps_4_0, PS_Texture2D_NormalMap( false, false, true ) ), //法線マップ無し テクスチャ2D バイアスあり CompileShader( ps_4_0, PS_Texture2D_NormalMap( true, false, true ) ), //法線マップあり テクスチャ2D バイアスあり CompileShader( ps_4_0, PS_Texture2D_NormalMap( false, true, true ) ), //法線マップ無し テクスチャ3D バイアスあり CompileShader( ps_4_0, PS_Texture2D_NormalMap( true, true, true ) ), //法線マップあり テクスチャ3D バイアスあり */ CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, false, false ) ), //法線マップ無し テクスチャ2D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, false, false ) ), //法線マップあり テクスチャ2D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, true, false ) ), //法線マップ無し テクスチャ3D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, true, false ) ), //法線マップあり テクスチャ3D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, false, true ) ), //法線マップ無し テクスチャ2D バイアスあり CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, false, true ) ), //法線マップあり テクスチャ2D バイアスあり CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, true, true ) ), //法線マップ無し テクスチャ3D バイアスあり CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, true, true ) ), //法線マップあり テクスチャ3D バイアスあり }; // ライティングするピクセルシェーダ(リムライトあり) PixelShader ps_rim[] = { CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, false, false ) ), //法線マップ無し テクスチャ2D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, false, false ) ), //法線マップあり テクスチャ2D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, true, false ) ), //法線マップ無し テクスチャ3D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, true, false ) ), //法線マップあり テクスチャ3D バイアス無し CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, false, true ) ), //法線マップ無し テクスチャ2D バイアスあり CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, false, true ) ), //法線マップあり テクスチャ2D バイアスあり CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( false, true, true ) ), //法線マップ無し テクスチャ3D バイアスあり CompileShader( ps_4_0, PS_Rim_Texture2D_NormalMap( true, true, true ) ), //法線マップあり テクスチャ3D バイアスあり }; // ライト処理をしないピクセルシェーダ PixelShader ps_nolight[] = { CompileShader( ps_4_0, PS_NoLight_Texture2D( false, false ) ), // バイアスなし CompileShader( ps_4_0, PS_NoLight_Texture2D( true, false ) ), // バイアスなし CompileShader( ps_4_0, PS_NoLight_Texture2D( false, true ) ), // バイアスあり CompileShader( ps_4_0, PS_NoLight_Texture2D( true, true ) ), // バイアスあり }; // ステンシルバッファに書き込む値を指定する深度ステンシルステート DepthStencilState SetStencilValue { DEPTHENABLE = TRUE; DEPTHWRITEMASK = ALL; DEPTHFUNC = LESS; STENCILENABLE = TRUE; STENCILREADMASK = 0x00; STENCILWRITEMASK = 0xF0; // 上位4ビットを書き込む FRONTFACESTENCILPASS = REPLACE; FRONTFACESTENCILFUNC = ALWAYS; BACKFACESTENCILPASS =REPLACE; BACKFACESTENCILFUNC = ALWAYS; }; technique10 techLight{ pass P0{ SetDepthStencilState( SetStencilValue, stencil_write_value); SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( vs[ g_GP_VSmode ] ); SetGeometryShader( NULL ); SetPixelShader( ps_normal[ g_GP_PSmode ] ); } } technique10 techNoLight{ pass P0{ SetDepthStencilState( SetStencilValue, stencil_write_value); SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( vs[ g_GP_VSmode ] ); SetGeometryShader( NULL ); SetPixelShader( ps_nolight[ g_GP_PSmode_NoLight ] ); } } technique10 techRimLight{ pass P0{ SetDepthStencilState( SetStencilValue, stencil_write_value); SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); SetVertexShader( vs[ g_GP_VSmode ] ); SetGeometryShader( NULL ); SetPixelShader( ps_rim[ g_GP_PSmode ] ); } }