当前位置:网站首页>GAMES104 作业2-ColorGrading
GAMES104 作业2-ColorGrading
2022-06-28 02:22:00 【什么时候才能坚持做好一件事啊】
ColorGrading网上资料很就多就不介绍了,简单来说就是将ps中一个像素的r-g-b值转换成x-y-z坐标映射到一个三维的颜色的颜色表(LUT)得到新的颜色,从而使场景更具电影感和好看。
以104中的色链LUT为例(ps中导出的LUT为矩形,但原理相同)
对色链LUT简单图解就如上图所示,以颜色RG为xy值形成一个2d贴图,将一系列这样的2d贴图以B值作为索引连接在一起,成为一个可以使用RGB作为XYZ坐标进行索引查找颜色值的3维数组,注意这里B值不是连续的(为了降低LUT内存占用,压缩),后续具体颜色值通过插值获得。
以上图的点p为例,现在场景中一个像素点p的颜色值为(r, g, b),去查找表中发现b值位于b2和b3之间,则取b2贴图和b3贴图中(r,g)对应的两个点L,R做线性lerp即可得到p映射后的值。
先求出2d贴图数量
blockNum = lut.width / lut.height
求出b值位置
blockPLeft = floor(blockNum * p.r)
blockPRight = ceil(blockNum * p.r)
求出左贴图和右贴图中对应像素(L、R)的u值。除以lut长度归一化到0-1范围
uL = (blockPLeft * lut.height + p.r * lut.height) / lut.width
uR= (blockPRight * lut.height + p.r * lut.height) / lut.width
求出v值,注意计算方式和lut的格式有关系
v = p.g
根据uv值对lut进行采样
pixelL = texture(lut, vec2(uL, v))
pixelR = texture(lut, vec2(uR, v))
根据b值对采样结果进行插值
weight = fract(blockNum * p.r)
outColor = pixelL * weight + pixelR * (1 - weight)
对于104的作业,只需要改color_grading.frag即可,还是比较简单的
highp ivec2 lut_tex_size = textureSize(color_grading_lut_texture_sampler, 0);
highp vec4 color = subpassLoad(in_color).rgba;
highp vec2 lutSize = vec2(lut_tex_size.x, lut_tex_size.y);
highp float blockNum = lutSize.x / lutSize.y;
highp float blockIndexL = floor(color.b * blockNum);
highp float blockIndexR = ceil(color.b * blockNum);
highp float lutCoordXL = (blockIndexL * lutSize.y + color.r * lutSize.y) / lutSize.x;
highp float lutCoordXR = (blockIndexR * lutSize.y + color.r * lutSize.y) / lutSize.x;
highp float lutCoorY = color.g;
highp vec2 lutCoordL = vec2(lutCoordXL, lutCoorY);
highp vec2 lutCoordR = vec2(lutCoordXR, lutCoorY);
highp vec4 lutcolorL = texture(color_grading_lut_texture_sampler, lutCoordL);
highp vec4 lutcolorR = texture(color_grading_lut_texture_sampler, lutCoordR);
highp float weight = fract(color.b * lutSize.y);
out_color = mix(lutcolorL, lutcolorR, weight);
注意出现这种花纹可能是没有正确混合b值
最后我的结果。
104小引擎中的color grading是post-tonemapping的,根据real-time rendering4th 8.2.3章指出,现在业界更多喜欢使用pre-tonemapping的colorgrading,可以提高更高的画面质量和保真度。
但是我太菜了呜呜,完全不会用vulkan,改了很久pre-tonemapping没有成功。想加一个pass做个描边,加上去才发现不知道怎么给ps传深度。。。学习路任重而道远,后续补上。
边栏推荐
- PHP 代码 微信、公众号、企业微信 发送表情符号 [U+1F449]
- R language penalty logistic regression, linear discriminant analysis LDA, generalized additive model GAM, multiple adaptive regression splines Mars, KNN, quadratic discriminant analysis QDA, decision
- R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022
- 2022年R1快开门式压力容器操作特种作业证考试题库及答案
- Domain Name System
- 被校园暴力,性格内向的马斯克凄惨而励志的童年
- QEMU monitor usage
- be fond of the new and tired of the old? Why do it companies prefer to spend 20K on recruiting rather than raise salaries to retain old employees
- windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
- 没错,是水的一篇
猜你喜欢
ETCD数据库源码分析——集群间网络层服务端RaftHandler
【小程序】使用font-awesome字体图标的解决文案(图文)
Relative path writing of files
访问网站提示:您未被授权查看该页恢复办法
Tencent games released more than 40 products and projects, including 12 new games
View the SQL execution plan according to explain and optimize the SQL
分布式事务解决方案Seata-Golang浅析
【iptables&icmp】iptables默认策略中关于icmp协议的说明
導入Excel文件,解决跳過空白單元格不讀取,並且下標前移的問題,以及RETURN_BLANK_AS_NULL報紅
拾光者,云南白药!
随机推荐
The first in the industry! MOS sub evaluation model for subjective video quality experience that can run on mobile devices!
Arduino esp8266 web LED control
买股票通过券商经理的开户链接开户资金是否安全?想开户炒股
[postgraduate] bit by bit
云成本优化有哪些优秀实践?
Inference optimization implementation of tensorrt model
Build your own website (17)
业内首个!可运行在移动设备端的视频画质主观体验MOS分评估模型!
劲爆!YOLOv6又快又准的目标检测框架开源啦(附源代码下载)
Flow based depth generation model
被校园暴力,性格内向的马斯克凄惨而励志的童年
您的物联网安全性是否足够强大?
ETCD数据库源码分析——集群间网络层服务端RaftHandler
访问网站提示:您未被授权查看该页恢复办法
测试要掌握的技术有哪些?软件测试必懂的数据库设计大全篇
Basic operation of stack (implemented in C language)
apache、iis6、ii7独立ip主机屏蔽限制ip访问
RichView TRVStyle ParaStyles
[issue 21] face to face experience of golang engineer recruited by Zhihu Society
Apache, IIS6, ii7 independent IP host shielding restricts IP access