Help with Pixel Shader effect for brightness and contrast

前端 未结 1 407
不思量自难忘°
不思量自难忘° 2020-12-30 07:06

What is a simple pixel shader script effect to apply brightness and contrast?

I found this one, but it doesn\'t seem to be correct:

sampler2D input :         


        
相关标签:
1条回答
  • 2020-12-30 07:52

    Is this what you are looking for?

    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;
    }
    

    --- Tested with Shazzam Shader Editor http://shazzam-tool.com

    0 讨论(0)
提交回复
热议问题