私はシェーダーで少し経験していますが、この奇妙なコンパイルエラーが発生し続け、私を夢中にさせています!
次のピクセル シェーダー コード スニペット:
DirectionVector = normalize(f3LightPosition[i] - PixelPos);
LightVec = PixelNormal - DirectionVector;
// Get the light strenght factor
LightStrFactor = float(abs((LightVec.x + LightVec.y + LightVec.z) / 3.0f));
// TEST!!!
LightStrFactor = 1.0f;
// Add this light to the total light on this pixel
LightVal += f4Light[i] * LightStrFactor;
完全に機能しますが、「LightStrFactor = 1.0f;」を削除するとすぐに つまり、「LightStrFactor」の値を上記の計算の結果にすると、シェーダーのコンパイルに失敗します。
LightStrFactor は float です LightVal & f4Light[i] は float4 です 残りはすべて float3 です。
私の質問は、なぜそれがコンパイルされないのかということに加えて、なぜDXコンパイラはfloatの値を気にするのですか? 私の値が間違っていても、それは実行時ではないでしょうか? シェーダーのコンパイル コードは次のとおりです。
/* Compile the bitch */
if (FAILED(D3DXCompileShaderFromFile(fileName, NULL, NULL, "PS_MAIN", "ps_2_0", 0, &this->m_pCode, NULL, &this->m_constantTable)))
GraphicException("Failed to compile pixel shader!"); // <-- gets here :(
if (FAILED(g_D3dDevice->CreatePixelShader( (DWORD*)this->m_pCode->GetBufferPointer(), &this->m_hPixelShader )))
GraphicException("Failed to create pixel shader!");
this->m_fLoaded = true;
どんな助けでも大歓迎ですありがとう!!! :]