当前位置:网站首页>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传深度。。。学习路任重而道远,后续补上。
边栏推荐
- 嵌入式DSP音频开发
- Heartless sword English Chinese bilingual poem 004 Meditation
- 2022 operation of simulated examination platform of special operation certificate examination question bank for safety management personnel of hazardous chemical business units
- 栈的基本操作(C语言实现)
- 分布式事务—基于消息补偿的最终一致性方案(本地消息表、消息队列)
- Necessary software tools in embedded software development
- Redis cluster setup [simple]
- 剑指 Offer 47. 礼物的最大价值(DP)
- 访问网站提示:您未被授权查看该页恢复办法
- 暴雨去哪儿?天气预报不准谁的锅?
猜你喜欢
项目实战!手把手教你 Jmeter 性能测试
2022 safety officer-c certificate examination question bank simulated examination platform operation
音视频技术开发周刊 | 251
Simple file transfer protocol TFTP
R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022
Thesis reading: General advantageous transformers
2022安全员-C证考试题库模拟考试平台操作
在excel文件上设置下拉选项
TensorRT 模型推理优化实现
matlab习题 —— 矩阵的常规运算
随机推荐
matlab习题 —— 符号运算相关练习
剑指 Offer 47. 礼物的最大价值(DP)
【522. 最长特殊序列 II】
matlab习题 —— 矩阵的常规运算
买股票通过券商经理的开户链接开户资金是否安全?想开户炒股
项目实战!手把手教你 Jmeter 性能测试
国泰君安证券靠谱吗?开证券账户安全吗?
Apache——阿帕奇简介
【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
Object类,以及__new__,__init__,__setattr__,__dict__
RichView TRVStyle
Import an excel file, solve the problem of skipping blank cells without reading and moving the subscript forward, and return_ BLANK_ AS_ Null red
RichView TRVStyle TextStyles
论文阅读:Generative Adversarial Transformers
十年职场软件工程师感悟
R语言惩罚逻辑回归、线性判别分析LDA、广义加性模型GAM、多元自适应回归样条MARS、KNN、二次判别分析QDA、决策树、随机森林、支持向量机SVM分类优质劣质葡萄酒十折交叉验证和ROC可视化
AgilePLM异常解决-Session篇
Mysql database operation - stored procedure, view, transaction, index, database backup
买股票应该下载什么软件最好最安全?
s32ds跳转到DefaultISR