Jak przekazać tekstury do shadera pikseli DirectX 9?

Mam pixel shader

// fxc.exe tiles.fs /T ps_3_0 /Fotiles.fsc /Fctiles.fsl

struct PSInput
{   
    float4 Pos : TEXCOORD0;
    float3 Normal : TEXCOORD1;
    float2 TexcoordUV : TEXCOORD2;
    float2 TexcoordST : TEXCOORD3;
};

sampler2D sampler0; //uniform 
sampler2D sampler1; //uniform 
sampler2D sampler2; //uniform 
sampler2D sampler3; //uniform 
sampler2D alphamap1;//uniform 
sampler2D alphamap2;//uniform 
sampler2D alphamap3;//uniform 
uniform int tex_count = 0;

uniform float4 color_ambient = float4(0.75, 0.75, 0.75, 1.0);
uniform float4 color_diffuse = float4(0.25, 0.25, 0.25, 1.0);
uniform float4 color_specular = float4(1.0, 1.0, 1.0, 1.0);
uniform float shininess = 77.0f;
uniform float3 light_position = float3(12.0f, 32.0f, 560.0f);

float4 main(PSInput In) : COLOR
{
    float3 light_direction = normalize(light_position - (float3)In.Pos);
    float3 normal = normalize(In.Normal);
    float3 half_vector = normalize(light_direction + normalize((float3)In.Pos));
    float diffuse = max(0.0, dot(normal, light_direction));
    float specular = pow(max(0.0, dot(In.Normal, half_vector)), shininess);
    float4 color = tex2D(sampler0, In.TexcoordUV);

    if (tex_count > 0){
        float4 temp = tex2D(sampler1, In.TexcoordUV);
        float4 amap = tex2D(alphamap1, In.TexcoordST);
        color = lerp(color, temp, amap.a);
    }
    if (tex_count > 1){
        float4 temp = tex2D(sampler2, In.TexcoordUV);
        float4 amap = tex2D(alphamap2, In.TexcoordST);
        color = lerp(color, temp, amap.a);
    }
    if (tex_count > 2){
        float4 temp = tex2D(sampler3, In.TexcoordUV);
        float4 amap = tex2D(alphamap3, In.TexcoordST);
        color = lerp(color, temp, amap.a);
    }
    color = color * color_ambient + diffuse * color_diffuse + specular * color_specular;

    return color;
}

cieniowanie wierzchołków

// fxc.exe tiles.vs /T vs_3_0 /Fotiles.vsc /Fctiles.vsl

struct VSInput
{
    float3 Pos : POSITION;
    float3 Normal : NORMAL;
    float2 TexcoordUV : TEXCOORD0;
    float2 TexcoordST : TEXCOORD1;
};

struct PSInput
{   
    float4 Pos : POSITION;
    float3 Normal : TEXCOORD0;
    float2 TexcoordUV : TEXCOORD1;
    float2 TexcoordST : TEXCOORD2;
};

uniform matrix modelMatrix;
uniform matrix projectionMatrix;
uniform matrix lookAtMatrix;

PSInput main(VSInput In)
{
    PSInput Out = (PSInput) 0;

    //projectionMatrix * lookAtMatrix * modelMatrix;
    matrix MVP = mul(modelMatrix, lookAtMatrix); 
    MVP = mul(MVP, projectionMatrix); 

    Out.Normal = mul(In.Normal, (float3x3)modelMatrix);
    Out.Pos = mul(float4(In.Pos, 1.0), MVP);    
    Out.TexcoordUV = In.TexcoordUV;
    Out.TexcoordST = In.TexcoordST;

    return Out;
}

to samo działa w OpenGL + GLSL z wyjątkiemmix zastąpione przezlerp (Mam nadzieję, że to poprawne). Na przykład zhttp://www.two-kings.de/tutorials/dxgraphics/dxgraphics18.html Przechodzę tekstury z:

ps_pConstantTable.SetInt(m_pD3DDevice, texCountHandle, 0);
for i := 0 to texCount - 1 do begin
  tBlp := texture_buf[cx, cy][i];
  if tBlp = nil then
      break;

  m_pD3DDevice.SetTexture(i, tBlp.itex);
  ps_pConstantTable.SetInt(m_pD3DDevice, texCountHandle, i);

  if i > 0 then begin
    // this time, use blending:
    m_pD3DDevice.SetTexture(i + 3, AlphaMaps[cx, cy][i]);
  end;
end;

tak więc porządkowe tekstury mają indeksy 0-3 i alfa 4-6 (max texCount 4). Problem polega na tym, że widzę siatkę (teren), ale jest ona czarna. Czy potrzebuję czegoś innego do ustawienia (bez shaderów również był czarny, dopóki nie przypisałem materiałów i światła)? Czy mogę przekazać takie tekstury? Czy mogę to zrobićsampler2D tak jakuniform (w jaki sposób)?

Edycja: przykład ze źródłami, shaderami, kilkoma używanymi teksturami i alfamapami, danymi wierzchołków z normalnymi w filebeamhttp://fbe.am/nm4 dodany. Jak najmniejszy. Zawiera również DXErr9ab.dll do rejestrowania błędów.

questionAnswers(1)

yourAnswerToTheQuestion