有关亮度和对比度的Pixel Shader效果帮助

时间:2009-06-03 13:22:10

标签: shader

什么是应用亮度和对比度的简单像素着色器脚本效果?

我找到了这个,但它似乎不正确:

sampler2D input : register(s0);
float brightness : register(c0);
float contrast : register(c1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(input, uv); 
    float4 result = color;
    result = color + brightness;
    result = result * (1.0+contrast)/1.0;

    return result;
}

谢谢!

1 个答案:

答案 0 :(得分:24)

这是你在找什么?

float Brightness : register(C0);
float Contrast :   register(C1);

sampler2D Texture1Sampler : register(S0);

float4 main(float2 uv : TEXCOORD) : COLOR
{

   float4 pixelColor = tex2D(Texture1Sampler, uv);
   pixelColor.rgb /= pixelColor.a;

  // Apply contrast.
  pixelColor.rgb = ((pixelColor.rgb - 0.5f) * max(Contrast, 0)) + 0.5f;

  // Apply brightness.
  pixelColor.rgb += Brightness;

  // Return final pixel color.
  pixelColor.rgb *= pixelColor.a;


 return pixelColor;
}

---使用Shazzam Shader Editor进行测试 http://shazzam-tool.com