sampler defaultSampler = sampler_state
{
    AddressU                = Wrap;
    AddressV                = Wrap;
    AddressW                = Wrap;
    BorderColor             = 0;
    MagFilter               = Point;
    MaxAnisotropy           = 1;
    MaxMipLevel             = 0;
    MinFilter               = Point;
    MipFilter               = None;
    MipMapLodBias           = 0.0f;
    SRGBTexture             = false;
    
    //<ヘルプ未記載>
    ElementIndex            = 0;
    // DmapOffset のデフォルト値には混乱があって，D3DSAMPLERSTATETYPE Enumerated Type では 0 となっている．
    // いくつかのドライバも 0 を返すようだが，Debug Runtime の自己診断は 256 が正しいとしている．
    DMapOffset              = 256; 
    //</ヘルプ未記載>
};

stateblock defaultState = stateblock_state
{
    //<ヘルプ未記載>
    PatchEdgeStyle          = Discrete;
    // DebugMonitorToken       = 0; // 一度しかセットできない
    PositionDegree          = Cubic;
    NormalDegree            = Linear;
    ScissorTestEnable       = false;
    AntialiasedLineEnable   = false;
    MinTessellationLevel    = 1.0f;
    MaxTessellationLevel    = 1.0f;
    AdaptiveTess_X          = 0.0f;
    AdaptiveTess_Y          = 0.0f;
    AdaptiveTess_Z          = 1.0f;
    AdaptiveTess_W          = 0.0f;
    EnableadAptiveTessellation = false;
    TwoSidedStencilMode     = false;
    CCW_StencilFail         = Keep;
    CCW_StencilZFail        = Keep;
    CCW_StencilPass         = Keep;
    CCW_StencilFunc         = Always;
    ColorWriteEnable1       = 0x0000000f;
    ColorWriteEnable2       = 0x0000000f;
    ColorWriteEnable3       = 0x0000000f;
    BlendFactor             = 0xffffffff;
    SRGBWriteEnable         = false;
    SeparateAlphaBlendEnable = false;
    SrcBlendAlpha           = One;
    DestBlendAlpha          = Zero;
    BlendOpAlpha            = Add;
    BlendOpAlpha            = Add;
    //</ヘルプ未記載>

    // --------------------------------------------------------------------------------
    // ライティングステート
    // --------------------------------------------------------------------------------

    LightAmbient[0]         = float4(0.0f, 0.0f, 0.0f, 0.0f);
    LightAttenuation0[0]    = 0.0f;
    LightAttenuation1[0]    = 0.0f;
    LightAttenuation2[0]    = 0.0f;
    LightDiffuse[0]         = float4(1.0f, 1.0f, 1.0f, 0.0f);
    LightDirection[0]       = float3(0.0f, 0.0f, 1.0f);
    LightEnable[0]          = false;
    LightFalloff[0]         = 0.0f;
    LightPhi[0]             = 0.0f;
    LightPosition[0]        = float3(0.0f, 0.0f, 1.0f);
    LightRange[0]           = 0.0f;
    LightSpecular[0]        = float4(1.0f, 1.0f, 1.0f, 0.0f);
    LightTheta[0]           = 0.0f;
    LightType[0]            = Directional;
    
    // --------------------------------------------------------------------------------
    // マテリアルステート
    // --------------------------------------------------------------------------------
    MaterialAmbient         = float4(0.0f, 0.0f, 0.0f, 0.0f);
    MaterialDiffuse         = float4(0.0f, 0.0f, 0.0f, 0.0f);
    MaterialEmissive        = float4(0.0f, 0.0f, 0.0f, 0.0f);
    MaterialPower           = 0.0f;
    MaterialSpecular        = float4(0.0f, 0.0f, 0.0f, 0.0f);

    // --------------------------------------------------------------------------------
    // ピクセル パイプライン レンダリング ステート
    // --------------------------------------------------------------------------------
    AlphaBlendEnable        = false;
    AlphaFunc               = Always;
    AlphaRef                = 0;
    AlphaTestEnable         = false;
    BlendOp                 = Add;
    ColorWriteEnable        = 0x0000000f;
    DepthBias               = 0;
    DestBlend               = InvSrcAlpha;
    DitherEnable            = false;
    FillMode                = Solid;
    LastPixel               = true;
    ShadeMode               = Gouraud;
    SlopeScaleDepthBias     = 0.0f;
    SrcBlend                = One;
    StencilEnable           = false;
    StencilFail             = Keep;
    StencilFunc             = Always;
    StencilMask             = 0xffffffff;
    StencilPass             = Keep;
    StencilRef              = 0;
    StencilWriteMask        = 0xffffffff;
    StencilZFail            = Keep;
    TextureFactor           = 0xffffffff;
    Wrap0                   = 0;
    Wrap1                   = 0;
    Wrap2                   = 0;
    Wrap3                   = 0;
    Wrap4                   = 0;
    Wrap5                   = 0;
    Wrap6                   = 0;
    Wrap7                   = 0;
    Wrap8                   = 0;
    Wrap9                   = 0;
    Wrap10                  = 0;
    Wrap11                  = 0;
    Wrap12                  = 0;
    Wrap13                  = 0;
    Wrap14                  = 0;
    Wrap15                  = 0;
    // ZEnable                 = true; // 深度ステンシルバッファが作られなかったときにはfalse
    ZFunc                   = LessEqual;
    ZWriteEnable            = true;

    // --------------------------------------------------------------------------------
    // 頂点パイプライン レンダリング ステート
    // --------------------------------------------------------------------------------
    Ambient                 = 0;
    AmbientMaterialSource   = Material;
    Clipping                = true;
    ClipPlaneEnable         = 0;
    ColorVertex             = True;
    CullMode                = CCW;
    DiffuseMaterialSource   = Color1;
    EmissiveMaterialSource  = Material;
    FogColor                = 0;
    FogDensity              = 1.0f;
    FogEnable               = false;
    FogEnd                  = 1.0f;
    FogStart                = 0.0f;
    FogTableMode            = None;
    FogVertexMode           = None;
    IndexedVertexBlendEnable = false;
    Lighting                = true;
    LocalViewer             = true;
    MultiSampleAntialias    = true;
    MultiSampleMask         = 0xffffffff;
    NormalizeNormals        = false;
    PatchSegments           = 0.0f;
    PointScale_A            = 1.0f;
    PointScale_B            = 0.0f;
    PointScale_C            = 0.0f;
    PointScaleEnable        = false;
    // PointSize               = 1.0f; // Driver dependent
    PointSize_Min           = 1.0f;
    PointSize_Max           = 64.0f;
    PointSpriteEnable       = false;
    RangeFogEnable          = false;
    SpecularEnable          = false;
    SpecularMaterialSource  = Color2;
    TweenFactor             = 0.0f;
    VertexBlend             = Disable;

    // --------------------------------------------------------------------------------
    // サンプラ ステージ ステート
    // --------------------------------------------------------------------------------
    Sampler[0]              = (defaultSampler);
    Sampler[1]              = (defaultSampler);
    Sampler[2]              = (defaultSampler);
    Sampler[3]              = (defaultSampler);
    Sampler[4]              = (defaultSampler);
    Sampler[5]              = (defaultSampler);
    Sampler[6]              = (defaultSampler);
    Sampler[7]              = (defaultSampler);
    Sampler[8]              = (defaultSampler);
    Sampler[9]              = (defaultSampler);
    Sampler[10]             = (defaultSampler);
    Sampler[11]             = (defaultSampler);
    Sampler[12]             = (defaultSampler);
    Sampler[13]             = (defaultSampler);
    Sampler[14]             = (defaultSampler);
    Sampler[15]             = (defaultSampler);

    // --------------------------------------------------------------------------------
    // テクスチャ ステート
    // --------------------------------------------------------------------------------
    Texture[0]              = null;
    Texture[1]              = null;
    Texture[2]              = null;
    Texture[3]              = null;
    Texture[4]              = null;
    Texture[5]              = null;
    Texture[6]              = null;
    Texture[7]              = null;
    
    // --------------------------------------------------------------------------------
    // ピクセル シェーダ ステート
    // --------------------------------------------------------------------------------
    PixelShader = null;    
    // --------------------------------------------------------------------------------
    // 頂点シェーダ ステート
    // --------------------------------------------------------------------------------
    VertexShader = null;
    // --------------------------------------------------------------------------------
    // テクスチャ ステージ ステート
    // --------------------------------------------------------------------------------
    AlphaOp[0]              = SelectArg1;
    AlphaArg0[0]            = Current;
    AlphaArg1[0]            = Texture;
    AlphaArg2[0]            = Current;
    ColorArg0[0]            = Current;
    ColorArg1[0]            = Texture;
    ColorArg2[0]            = Current;
    ColorOp[0]              = Modulate;
    BumpEnvLScale[0]        = 0.0f;
    BumpEnvLOffset[0]       = 0.0f;
    BumpEnvMat00[0]         = 0.0f;
    BumpEnvMat01[0]         = 0.0f;
    BumpEnvMat10[0]         = 0.0f;
    BumpEnvMat11[0]         = 0.0f;
    ResultArg[0]            = Current;
    TexCoordIndex[0]        = PassThru | 0;
    TextureTransformFlags[0]    = Disable;

    AlphaOp[1]              = Disable;
    AlphaArg0[1]            = Current;
    AlphaArg1[1]            = Texture;
    AlphaArg2[1]            = Current;
    ColorArg0[1]            = Current;
    ColorArg1[1]            = Texture;
    ColorArg2[1]            = Current;
    ColorOp[1]              = Disable;
    BumpEnvLScale[1]        = 0.0f;
    BumpEnvLOffset[1]       = 0.0f;
    BumpEnvMat00[1]         = 0.0f;
    BumpEnvMat01[1]         = 0.0f;
    BumpEnvMat10[1]         = 0.0f;
    BumpEnvMat11[1]         = 0.0f;
    ResultArg[1]            = Current;
    TexCoordIndex[1]        = PassThru | 1;
    TextureTransformFlags[1]    = Disable;

    AlphaOp[2]              = Disable;
    AlphaArg0[2]            = Current;
    AlphaArg1[2]            = Texture;
    AlphaArg2[2]            = Current;
    ColorArg0[2]            = Current;
    ColorArg1[2]            = Texture;
    ColorArg2[2]            = Current;
    ColorOp[2]              = Disable;
    BumpEnvLScale[2]        = 0.0f;
    BumpEnvLOffset[2]       = 0.0f;
    BumpEnvMat00[2]         = 0.0f;
    BumpEnvMat01[2]         = 0.0f;
    BumpEnvMat10[2]         = 0.0f;
    BumpEnvMat11[2]         = 0.0f;
    ResultArg[2]            = Current;
    TexCoordIndex[2]        = PassThru | 2;
    TextureTransformFlags[2]    = Disable;

    AlphaOp[3]              = Disable;
    AlphaArg0[3]            = Current;
    AlphaArg1[3]            = Texture;
    AlphaArg2[3]            = Current;
    ColorArg0[3]            = Current;
    ColorArg1[3]            = Texture;
    ColorArg2[3]            = Current;
    ColorOp[3]              = Disable;
    BumpEnvLScale[3]        = 0.0f;
    BumpEnvLOffset[3]       = 0.0f;
    BumpEnvMat00[3]         = 0.0f;
    BumpEnvMat01[3]         = 0.0f;
    BumpEnvMat10[3]         = 0.0f;
    BumpEnvMat11[3]         = 0.0f;
    ResultArg[3]            = Current;
    TexCoordIndex[3]        = PassThru | 3;
    TextureTransformFlags[3]    = Disable;

    AlphaOp[4]              = Disable;
    AlphaArg0[4]            = Current;
    AlphaArg1[4]            = Texture;
    AlphaArg2[4]            = Current;
    ColorArg0[4]            = Current;
    ColorArg1[4]            = Texture;
    ColorArg2[4]            = Current;
    ColorOp[4]              = Disable;
    BumpEnvLScale[4]        = 0.0f;
    BumpEnvLOffset[4]       = 0.0f;
    BumpEnvMat00[4]         = 0.0f;
    BumpEnvMat01[4]         = 0.0f;
    BumpEnvMat10[4]         = 0.0f;
    BumpEnvMat11[4]         = 0.0f;
    ResultArg[4]            = Current;
    TexCoordIndex[4]        = PassThru | 4;
    TextureTransformFlags[4]    = Disable;

    AlphaOp[5]              = Disable;
    AlphaArg0[5]            = Current;
    AlphaArg1[5]            = Texture;
    AlphaArg2[5]            = Current;
    ColorArg0[5]            = Current;
    ColorArg1[5]            = Texture;
    ColorArg2[5]            = Current;
    ColorOp[5]              = Disable;
    BumpEnvLScale[5]        = 0.0f;
    BumpEnvLOffset[5]       = 0.0f;
    BumpEnvMat00[5]         = 0.0f;
    BumpEnvMat01[5]         = 0.0f;
    BumpEnvMat10[5]         = 0.0f;
    BumpEnvMat11[5]         = 0.0f;
    ResultArg[5]            = Current;
    TexCoordIndex[5]        = PassThru | 5;
    TextureTransformFlags[5]    = Disable;

    AlphaOp[6]              = Disable;
    AlphaArg0[6]            = Current;
    AlphaArg1[6]            = Texture;
    AlphaArg2[6]            = Current;
    ColorArg0[6]            = Current;
    ColorArg1[6]            = Texture;
    ColorArg2[6]            = Current;
    ColorOp[6]              = Disable;
    BumpEnvLScale[6]        = 0.0f;
    BumpEnvLOffset[6]       = 0.0f;
    BumpEnvMat00[6]         = 0.0f;
    BumpEnvMat01[6]         = 0.0f;
    BumpEnvMat10[6]         = 0.0f;
    BumpEnvMat11[6]         = 0.0f;
    ResultArg[6]            = Current;
    TexCoordIndex[6]        = PassThru | 6;
    TextureTransformFlags[6]    = Disable;

    AlphaOp[7]              = Disable;
    AlphaArg0[7]            = Current;
    AlphaArg1[7]            = Texture;
    AlphaArg2[7]            = Current;
    ColorArg0[7]            = Current;
    ColorArg1[7]            = Texture;
    ColorArg2[7]            = Current;
    ColorOp[7]              = Disable;
    BumpEnvLScale[7]        = 0.0f;
    BumpEnvLOffset[7]       = 0.0f;
    BumpEnvMat00[7]         = 0.0f;
    BumpEnvMat01[7]         = 0.0f;
    BumpEnvMat10[7]         = 0.0f;
    BumpEnvMat11[7]         = 0.0f;
    ResultArg[7]            = Current;
    TexCoordIndex[7]        = PassThru | 7;
    TextureTransformFlags[7]    = Disable;

    // --------------------------------------------------------------------------------
    // トランスフォーム ステート
    // --------------------------------------------------------------------------------

    // float の 4 × 4 行列。D3DTS_ プレフィックスが付かない、D3DTS_PROJECTION と同じ値。
    ProjectionTransform     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    // float の 4 × 4 行列。D3DTS_ プレフィックスが付かない、D3DTRANSFORMSTATETYPE と同じ値。
    TextureTransform[0]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[1]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[2]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[3]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[4]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[5]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[6]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    TextureTransform[7]     = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    // float の 4 × 4 行列。D3DTS_ プレフィックスが付かない、D3DTS_VIEW と同じ値。
    ViewTransform           = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
    // float の 4 × 4 行列。
    WorldTransform[0]       = float4x4( 1.0f, 0.0f, 0.0f, 0.0f,
                                        0.0f, 1.0f, 0.0f, 0.0f,
                                        0.0f, 0.0f, 1.0f, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);
};

Cs  = rgba( Rs, Gs, Bs, As )
Ds  = rgba( Rd, Gd, Bd, Ad ) 


<Color BrendFactor>
SRCCOLOR       : rgb( Rs, Gs, Bs )
INVSRCCOLOR    : rgb( 1-Rs, 1-Gs, 1-Bs ) 
SRCALPHA       : rgb( As, As, As )
INVSRCALPHA    : rgb( 1-As, 1-As, 1-As )
DESTCOLOR      : rgb( Rd, Gd, Bd, Ad )
INVDESTCOLOR   : rgb( 1-Rd, 1-Gd, 1-Bd )
DESTALPHA      : rgb( Ad, Ad, Ad )
INVDESTALPHA   : rgb( 1-Ad, 1-Ad, 1-Ad )
ZERO           : rgb( 0, 0, 0 )
ONE            : rgb( 1, 1, 1 )
SRCALPHASAT    : rgb( f, f, f )　f = min( As, 1-Ad )
<alpha>
ZERO         : 0
ONE          : 1
SRCALPHA     : As
INVSRCALPHA  : 1-As
DESTALPHA    : Ad
INVDESTALPHA : 1-Ad



～不透明合成～
そのまま、上書きするだけです。

計算式 : src = dest


アルファブレンドの基本式（③⑥は演算）
計算式 rgb : (Cs.rgb * ①) ③ (Cd.rgb * ②)
       α  : (Cs.a   * ④) ⑥ (Cd.a   * ⑤)

①SrcBlend
②DestBlend
③BlendOp
④SrcBlendAlpha
⑤DestBlendAlpha
⑥BlendOpAlpha
---------------------------------------------------------------------


～半透明合成～
後ろの画像が透けて見えます。
煙のエフェクトなどで良く使います。

rgb :  (Cs.rgb * As) + (Cd.rgb * (1-As)) 
α  :  (Cs.a   * 1 ) + (Cd.a   * 0     )
---------------------------------------
AlphaBlendEnable = true;          //default は false
SeparateAlphaBlendEnable = true;  //アルファの演算を別途指定 default は false
SrcBlend  = SrcAlpha;             
DestBlend = InvSrcAlpha;          
BlendOp = Add;                    
SrcBlendAlpha = One;              //default
DestBlendAlpha = Zero;            //default
BlendOpAlpha = Add;               //default

デフォルトを省略して書くと

AlphaBlendEnable = true;
SrcBlend  = SrcAlpha;
DestBlend = InvSrcAlpha;
BlendOp = Add;

---------------------------------------

～加算合成～
単純に色を足し合わせます。
結果、白色に近付き明るく見えます。
魔法や炎など、エフェクトで一番良く使われています。

rgb :  (Cs.rgb * As) + (Cd.rgb * 1) 
α  :  (Cs.a   * 1 ) + (Cd.a   * 0)
---------------------------------------
AlphaBlendEnable = true;              //default は false
SeparateAlphaBlendEnable = true;      //アルファの演算を別途指定 default は false
SrcBlend  = SrcAlpha;                 
DestBlend = One;
BlendOp = Add;                        
SrcBlendAlpha = One;                  //default
DestBlendAlpha = Zero;                //default
BlendOpAlpha = Add;                   //default

デフォルトを省略して書くと

AlphaBlendEnable = true;
SrcBlend  = SrcAlpha;
DestBlend = One;
BlendOp = Add;

---------------------------------------

～減算合成～
加算合成とは逆に色を減算します。

rgb : (Cd.rgb * 1) - (Cs.rgb * As) = dest rgb    ※CdとCsが順番逆に注意、Asを入れることで減算半透明合成。
α  : (Cs.a   * 1) + (Cs.d   * 0 )
---------------------------------------
AlphaBlendEnable = true;              //default は false
SeparateAlphaBlendEnable = true;      //アルファの演算を別途指定 default は false
DestBlend = One;
SrcBlend  = SrcAlpha;
BlendOp = RevSubtract;
SrcBlendAlpha = One;                  //default
DestBlendAlpha = Zero;                //default
BlendOpAlpha = Add;                   //default

デフォルトを省略して書くと

AlphaBlendEnable = true;
DestBlend = One;
SrcBlend  = SrcAlpha;
BlendOp = RevSubtract;

---------------------------------------



～乗算合成～
色を乗算すると、
色付のセロハンテープの効果が出ます。

計算式 : Cd.rgb * Cs.rgb = dest
次のようにして考える
(Cs.rgb * Cd.rgb) + (Cd.rgb * 0) = dest

AlphaBlendEnable = true;
SrcBlend  = SrcColor;
DestBlend = Zero;
BlendOp = Add;

または

(Cs.rgb * 0) + (Cd * Cs.rgb) = dest

AlphaBlendEnable = true;
SrcBlend  = Zero;
DestBlend = DestColor;
BlendOp = Add;

どちらでも効果は同じ



～ハイライト（覆い焼き）～
計算方法は特殊なんですが、
効果としては、明るい色ほどより明るくなります。
光り輝いてるって感じですね。

計算式 : Cd + Cs * Cd = dest

～リバース（反転）～
ネガポジの効果です。

計算式 : (1-Cd) * Cs = dest



デバイスのポインタ->SetRenderState(D3DRS_ALPHAREF, 0x00000066);
デバイスのポインタ->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); 
デバイスのポインタ->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

Max(DestAlpha,SrcAlpha) + (DestAlpha × SrcAlpha)
がしたい。
