The task is: shader takes in a constant color, then generates pixel colors according to their positions by replacing two of four color components (RGBA) with texture coordinates. With hardcoded component set it will be like:
float4 inputColor : register(c0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 color = 0;
color.a = inputColor.a;
color.r = inputColor.r;
color.g = uv.x;
color.b = uv.y;
return color;
}
Now I'd like to pass in a parameter(s) specifying which components should be replaced with uv.x and uv.y. Let's say inputColor has -1 and -2 in these components. Or there are uint xIndex and yIndex parameters specifying positions in vector4 to be replaced. HLSL does not allow "color[xIndex] = uv.x".
Currently I've done that in ugly way with a bunch of if-else. But I feel like there is some cross-product or matrix multiplication solution. Any ideas?