当前位置:网站首页>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传深度。。。学习路任重而道远,后续补上。
边栏推荐
- 华为设备WLAN基本业务配置命令
- idea自动生成代码
- Le routage des microservices de la passerelle a échoué au chargement des ressources statiques des microservices
- Reading makes people quiet
- 在excel文件上设置下拉选项
- Domain Name System
- 剑指 Offer 53 - I. 在排序数组中查找数字 I(改进二分)
- 【522. 最长特殊序列 II】
- Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
- Gateway微服務路由使微服務靜態資源加載失敗
猜你喜欢
Arduino esp8266 web LED control
剑指 Offer 49. 丑数(三指针法)
[iptables & ICMP] description of ICMP Protocol in iptables default policy
__getitem__和__setitem__
Flow based depth generation model
Importer un fichier Excel, résoudre le problème de sauter les cellules vides et de ne pas lire, et avancer l'indice, et retourner Blank As NULL Red
【小程序】使用font-awesome字体图标的解决文案(图文)
【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
TensorRT 模型推理优化实现
Brief history and future trend of codeless software
随机推荐
The same is MB. Why is the gap so large?
嵌入式软件开发中必备软件工具
音视频技术开发周刊 | 251
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
Relative path writing of files
2022危险化学品经营单位安全管理人员特种作业证考试题库模拟考试平台操作
R语言惩罚逻辑回归、线性判别分析LDA、广义加性模型GAM、多元自适应回归样条MARS、KNN、二次判别分析QDA、决策树、随机森林、支持向量机SVM分类优质劣质葡萄酒十折交叉验证和ROC可视化
View the SQL execution plan according to explain and optimize the SQL
空闲中断无法清除
微信小程序中生成二维码
Why is the service implementation class always red
Apache——阿帕奇简介
Tips for visiting the website: you are not authorized to view the recovery method of this page
2022年R1快開門式壓力容器操作特種作業證考試題庫及答案
Is online stock investment exchange group safe? Is it reliable to open an account for free?
导入Excel文件,解决跳过空白单元格不读取,并且下标前移的问题,以及RETURN_BLANK_AS_NULL报红
2022 safety officer-c certificate examination question bank simulated examination platform operation
collections.defaultdict()的使用
PSM summary