ShaderJoy —— “Gamma校正”的实现 【GLSL】
【摘要】
效果图
GLSL代码
算法比较简单,不再赘述,直接看源码和注释。
uniform sampler2D srcTex;uniform vec3 levels; /// Gamma 校正vec3 gammaCorrect(vec3 color, float gamma){ return pow(color, ...
效果图
GLSL代码
算法比较简单,不再赘述,直接看源码和注释。
-
uniform sampler2D srcTex;
-
uniform vec3 levels;
-
-
/// Gamma 校正
-
vec3 gammaCorrect(vec3 color, float gamma){
-
return pow(color, vec3(1.0/gamma));
-
}
-
-
/// 对 color 进行重新映射到 min, max 之间
-
vec3 levelRange(vec3 color, float minInput, float maxInput){
-
return min(
-
max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)),
-
vec3(1.0));
-
}
-
-
vec3 finalLevels(vec3 color, float minInput, float gamma, float maxInput){
-
return gammaCorrect(levelRange(color, minInput, maxInput), gamma);
-
}
-
-
void main(){
-
vec2 uv = gl_FragCoord.xy / vec2(512., 512.);
-
-
vec4 texture = texture2D(srcTex, uv) ;
-
-
// 注意 minInput 和 maxInput 的取值范围为[0, 255]
-
vec3 adjustedLevels = finalLevels(texture.rgb, levels.x/255.0, levels.y, levels.z/255.0);
-
-
gl_FragColor = vec4(adjustedLevels,1.0);
-
-
}
文章来源: panda1234lee.blog.csdn.net,作者:panda1234lee,版权归原作者所有,如需转载,请联系作者。
原文链接:panda1234lee.blog.csdn.net/article/details/52269462
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)