Gregory Igehy

Dancing at hemisphere coordinate

Notes of hardware tessellation

Notes of hardware tessellation

Hull shader


  • パッチ単位の並列化の処理をシェーダで行う
  • 入力 : パッチの制御点
  • 出力 : パッチの制御点, パッチごとの定数
struct HS_ConstantOutput
{
    float fTessFactor[3]    : SV_TessFactor;
    float fInsideTessFactor : SV_InsideTessFactor;
};

struct HS_ConstantOutput_Quad
{
    float fTessFactor[4]       : SV_TessFactor;
    float fInsideTessFactor[2] : SV_InsideTessFactor;
};

// パッチごとの定数を出力する関数
HS_ConstantOutput HS_TrianglesConstant( InputPatch<Position_Input, 3> I )
{
    HS_ConstantOutput O = (HS_ConstantOutput)0;

	float3 rtf; float ritf, itf;
	ProcessTriTessFactorsMax(g_f4TessFactors.xyz, g_f2Modes.y, rtf, ritf, itf);

        O.fTessFactor[0]    = rtf.x;
	O.fTessFactor[1]    = rtf.y;
	O.fTessFactor[2]    = rtf.z;
        O.fInsideTessFactor = ritf;

    return O;
}

// パッチの制御点を変換する関数
[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[patchconstantfunc("HS_TrianglesConstant")]
[outputcontrolpoints(3)]
Position_Input HS_Triangles_integer( InputPatch<Position_Input, 3> I, uint uCPID : SV_OutputControlPointID )
{
    Position_Input O = (Position_Input)0;

    O.f3Position = I[uCPID].f3Position;
    
    return O;
}

Tessellation Stage

Domain shader


struct DS_Output
{
    float4 f4Position : SV_Position;

};

// 三角形の重心座標から, 位置座標を求める関数
[domain("tri")]
PS_RenderSceneInput
DS_Triangles( HS_ConstantOutput HSConstantData,
              const OutputPatch<Position_Input, 3> I,
              float3 f3BarycentricCoords : SV_DomainLocation )
{
    PS_RenderSceneInput O = (PS_RenderSceneInput)0;

    // The barycentric coordinates
    float fU = f3BarycentricCoords.x;
    float fV = f3BarycentricCoords.y;
    float fW = f3BarycentricCoords.z;

    float3 f3Position = I[0].f3Position * fW +
                        I[1].f3Position * fU +
                        I[2].f3Position * fV;

    // Transform model position with view-projection matrix
    O.f4Position = mul( float4( f3Position.xyz, 1.0 ), g_f4x4WorldViewProjection );
        
    return O;
}

Free Textures at rendertextures.com

  • ディフューズアルベド, 法線マップ, ハイトマップ
広告を非表示にする