当前位置:网站首页>Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
2022-07-02 18:22:00 【Touch fleeting time】
Think of the original form of torture 2 The picture of being beaten with residual blood inside is only reserved for red , Everything else is grey and black . It's similar to this
Got an original picture , As UI Of ScreenSapce-Camera Imaging as a camera , Be careful ScreenSapce-Overlay Of UI Will not participate in screen post-processing .
Because the red part will not turn black , So the idea is that the red part should be the original color , Instead of lack of saturation , The code is as follows
// The stronger the red, the more invariant the gray , The weaker the area, the more use _Saturation To adjust
float grayDegree = lerp(_Saturation, 1, renderTex.r);
finalColor = lerp(grayColor, finalColor, grayDegree );
Set the saturation to 0,
The effect is as follows , Red does obviously remain , But there are other places that retain color .
Because many other colors have r component , We need to be below a certain level r Discard the source of the component r The influence of component
So I made a little change to the code , The idea is to treat the red part below a certain threshold as red 0,
Then treat red as 0 Part of , Use the original red value to adjust the saturation .
float redLerpValue = renderTex.r - _LeastRed < 0 ? 0 : renderTex.r;
// The stronger the red, the more invariant the gray , The weaker the area, the more use _Saturation To adjust
float grayDegree = lerp(_Saturation, 1, redLerpValue);
finalColor = lerp(grayColor, finalColor, grayDegree );
The parameters and effects are as follows :
It's only red , Just use the original saturation value directly after it is less than a certain value, so that the transition of the film source with the red value above and below the threshold will be very contrary . When I was stuck in difficulties, I suddenly wondered whether these models with special effects were painted with vertex colors when they left the factory , Then the film source makes color reservation according to the value of vertex color , In this way, the parts that should not retain color are strictly limited , But post-processing shader Vertex colors belonging to a single model cannot be read , At most, it is to reconstruct the world coordinates according to the depth map or do some other operations .
Now is to keep the red , If red is lower than a certain value, it turns gray , And the transition is not inconsistent , Think of an effect carefully analyzed before , Unity Grid Programming Notes [ Four ] Press the sphere to compress It's used in pow, Under the same coefficient , He can make the distance between his relatively small decimal and his relatively large decimal , And the larger the coefficient, the larger the drive , But be pow After treatment, the effect is continuous and will not be disconnected, which can simulate the transition
So I made some changes .
float redLerpValue = pow(renderTex.r, _RedPowerValue) ;
// The stronger the red, the more invariant the gray , The weaker the area, the more use _Saturation To adjust
float grayDegree = lerp(_Saturation, 1, redLerpValue);
finalColor = lerp(grayColor, finalColor, grayDegree );
I feel better , But the white part of the sky doesn't turn black and white , The sky is white , White is generally rgb The three channels are relatively high , Then the values of the three channels are equal .
To achieve the effect in the game , It feels like more than just reading r passageway , Yes. rgb Channel comprehensive judgment , Because when it is untreated, the red part will be kept and will not be grayed out , This part must be r The passage is much larger than gb The tunnel , Only considered r Channels are more inclined to single channel color retention , image unity Of inspector When viewing pictures on the panel, you only see the single channel . We use it r The difference between the mean value of the channel and that of other channels is taken as pow The basic value of , This itself is not the red part , The base value will be small and considered to be used only saturation control , Pay attention because the purpose is to highlight the red area , The delimited area of the red area is R The channel is much larger than gb The average of the channels , It's much bigger than , Instead of simply judging the difference between the two , Because of existence (0,1,1) This color , If such a color is also defined as red, it is incorrect .
So I made some changes .
float redChannelValue = renderTex.r;
float blueChannelValue = renderTex.b;
float greenChannelValue = renderTex.g;
float blueGreenAverage = (blueChannelValue + greenChannelValue) / 2;
float redDeltaBlueGreen = abs(redChannelValue - blueGreenAverage) ;
redDeltaBlueGreen = redChannelValue > blueGreenAverage ? redDeltaBlueGreen : 0;
float redGrayLerpValue = pow(redDeltaBlueGreen, _RedPowerValue) ;
float fullSaturateValue = 1;
// The stronger the red, the more invariant the gray , The weaker the area, the more use _Saturation To adjust
float grayDegree = lerp(_Saturation, fullSaturateValue, redGrayLerpValue);
finalColor = lerp(grayColor, finalColor, grayDegree );
The effect is OK , Because it's the difference , Difference as pow It's better than itself r The channel value should be small , As pow When the cardinality of , The degree of attenuation is greater than r The passage should be larger , You can imagine by comparing any left and right points of the function graph , therefore pow The coefficient range of can be reduced . Because before this post-processing, I did some HDR Color +bloom Or special effects , Then I did the black-and-white post-processing , According to the principle of both , There's no interference with each other , The glowing part still glows .
In the game, in order to highlight the desire for blood and survival when being beaten with residual blood, and the contempt for everything else and unclear vision , Red is highlighted , Darken the black and white colors , These changes actually make the dark darker , The light becomes brighter , That is, contrast enhancement , In addition, put Bloom The coefficient of adjustment is larger , Let the red glow more .
Ordinary contrast enhancement is the overall enhancement rather than the obvious enhancement of red contrast , The contrast of the red part here should be specially treated . So I made some changes :
//contrast Contrast : First calculate the value with the lowest contrast
fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
float redContrastLerpValue = pow(redDeltaBlueGreen, 3) ;
float contrastDegree = lerp(_Contrast, _Contrast * 10, redContrastLerpValue);
// according to Contrast The difference between the image with the lowest contrast and the original image
finalColor = lerp(avgColor, finalColor, contrastDegree);
There may be others when there is residual blood LUT,ToneMapping What's the post-processing of color mapping .
边栏推荐
- vi/vim 删除:一行, 一个字符, 单词, 每行第一个字符 命令
- 再放寬!這些應届生,可直接落戶上海
- 详解Kubernetes网络模型
- Design of the multi live architecture in different places of the king glory mall
- Pychar modify pep8 e501 line too long > 0 characters
- Wechat applet video sharing platform system graduation design completion (1) development outline
- Freemaker+poi realizes dynamic generation and parsing of Excel files
- Deep understanding of ThreadLocal
- Architecture design - ID generator "suggestions collection"
- 微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
猜你喜欢
微信小程序视频分享平台系统毕业设计毕设(3)后台功能
Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案
The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
ESP32-C3入门教程 问题篇⑩——error: implicit declaration of function ‘esp_blufi_close‘;
MySQL --- 數據庫的基本操作
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
Leetcode 面试题 17.01. 不用加号的加法
Chrome officially supports MathML, which is enabled in chromium dev 105 by default
微信核酸检测预约小程序系统毕业设计毕设(5)任务书
SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
随机推荐
微信小程序视频分享平台系统毕业设计毕设(3)后台功能
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
Wechat applet video sharing platform system graduation design completion (1) development outline
Laravel框架安装时遇到的坑
拿起相机,便是最好的艺术疗愈
微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
详解Kubernetes网络模型
【Golang | gRPC】使用openssl生成证书
Yingguang MCU development case
微信核酸检测预约小程序系统毕业设计毕设(1)开发概要
使用NPOI导出Excel文件
Develop a controller that prohibits deleting namespaces
Iframe nesting details
Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
Editor编辑器扩展在Scene View添加按钮和logo
【Golang | gRPC】使用gRPC实现简单远程调用
再放寬!這些應届生,可直接落戶上海
Enter a valid user name and password in the Microsoft LDAP configuration page, and enter a valid user name in the Microsoft LDAP configuration page
[golang | grpc] use grpc to realize simple remote call