0

So I have a pixelshader that blends different textures using a blend map, but I am attempting to make the blending an option. So my solution was that I calculate 3 different float3 which are in an array (0 is no blend, 1 is blend between two textures, and 2 is blend between three textures), and then I thought I could use a value from a constant buffer to determine which one should be used like this roughly.

cbuffer VSConstants : register(b13)
{
    float4 i;
}


int index = i[0];
return float4(finalized[index], 1.0f);

but the result from this is that D3DCompileFromFile returns E_FAIL and then CreatePixelShader crashes with an access violation.

I'm guessing that the compiler doesn't like that I use index as an "index" casuse if I set it to a manual value like 1 it works perfectly fine. The only other way I could think of getting around it is by using if cases to check what i[0] is but from what we learnt if cases are not a good thing to have in shaders from an optimisation view (and seeing how I would need multiple if cases it gets even worse). So does anyone know how I can solve the problem, or alternativly have another solution?

Gamewolf3000
  • 63
  • 2
  • 8
  • You should take a look at the compiler errors. It's probably complaining that you assign a `float` to an `int`. Anyway, the more performant way is probably to create three different shaders and switching them instead of maintaining a dynamic shader for all cases (the no-blend option would have to blend colors anyway and discard them). – Nico Schertler Mar 28 '15 at 10:39
  • what is your "finalized" declaration? – mrvux Mar 29 '15 at 21:27

0 Answers0