与您的参考代码类似的 c# 代码是(伪代码)
//Declares the texture/picture i.e. uniform sampler2D tex;
Bitmap x = new Bitmap();
float[] main()
{
// Looks up the color of a pixel for the specified coordinates, the color (as a rule of thumb)
// a normalized value i.e. vec4 pixcol = texture2D(tex, gl_TexCoord[0].xy);
Color pixcolUnnormalized= x.GetPixel();
float[] pixcol = new float[] { pixcolUnnormalized.r / 255.0f, pixcolUnnormalized.g / 255.0f, pixcolUnnormalized.b / 255.0f, pixcolUnnormalized.a / 255.0f);
//Setup coefficients i.e. vec4 colors[3]; colors[0] = vec4(0.,0.,1.,1.); colors[1] = vec4(1.,1.,0.,1.); colors[2] = vec4(1.,0.,0.,1.);
float[] color1[] = new float[] { 0.0,0.0,1.0,1.0 };
float[] color2[] = new float[] { 0.0,0.0,1.0,1.0 };
float[] color3[] = new float[] { 0.0,0.0,1.0,1.0 };
float[ float[] ] colors = new float[] { colors1, colors2, colors3 };
///Obtain luminance value from the pixel.
float lum = (pixcol[0]+pixcol[1] +pixcol[2])/3.;
int ix = (lum < 0.5)? 0:1;
//Interpolate the color values i.e. vec4 thermal = mix(colors[ix],colors[ix+1],(lum-float(ix)*0.5)/0.5);
float[] thermal = new float[] {
colors[ix][0] * ( 1 - (lum-float(ix)*0.5)/0.5) ) + colors[ix + 1][0] * (lum-float(ix)*0.5)/0.5)
colors[ix][1] * ( 1 - (lum-float(ix)*0.5)/0.5) ) + colors[ix + 1][1] * (lum-float(ix)*0.5)/0.5)
colors[ix][2] * ( 1 - (lum-float(ix)*0.5)/0.5) ) + colors[ix + 1][2] * (lum-float(ix)*0.5)/0.5)
colors[ix][3] * ( 1 - (lum-float(ix)*0.5)/0.5) ) + colors[ix + 1][3] * (lum-float(ix)*0.5)/0.5)
};
//return the value
return thermal;
}