Unity 生成原始LUT用于外部校色相机不透明物体截图
在游戏制作后期,项目如果需要风格化校色会设置一个全局优先级最高的volume组件用于应用校色
勤快的项目组一般会准备多种预调色配置,调整各种校色组件及参数
懒一些的则会从网上直接下载成套校色图,替换color lookup组件中的素材
那么继续说懒的方式,如果需要有一两个特殊定制的风格效果时,下载的素材就体现出了不可定制性
我们可以通过unity导出lookup table,导入到各种校色工具中校色,再输出回unity的做法来实现
C#
public class ExportTEST : EditorWindow
{public enum TextureType{png = 0,exr = 1}private string _filePath = "...";private Material _mat;private TextureType _textureType = TextureType.png;[MenuItem("*TEST*/导出场景HDR格式图片")]private static void Init(){ExportHDR window = GetWindowWithRect<ExportHDR>(new Rect(0,0,300,150));window.titleContent = new GUIContent("导出HDR格式场景截图");window.Show();}private void OnGUI(){GUILayout.Label("保存到:" + _filePath);if (GUILayout.Button("保存位置")){_filePath = EditorUtility.OpenFolderPanel("", "", "");}_textureType = (TextureType)EditorGUILayout.EnumPopup("选择LUT保存格式",_textureType);if (GUILayout.Button("生成原始LUT")){try{CreateLUTBase();}catch (Exception e){Console.WriteLine(e);throw;}}if (GUILayout.Button("生成原始场景截图(tga)")){try{CreateSceneBase();}catch (Exception e){Console.WriteLine(e);throw;}}}//我们在打开其他窗口时,焦点不在game视口,获得的screen宽高是激活窗口的public static Vector2 GetMainGameViewSize(){//通过反射获取game宽高System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");System.Reflection.MethodInfo GetSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);System.Object Res = GetSizeOfMainGameView.Invoke(null,null);return (Vector2)Res;}void CreateSceneBase(out string state){var path = _filePath + "/SceneColor_Base.tga";if(File.Exists(path)) File.Delete(path);if (_mat == null){_mat = CoreUtils.CreateEngineMaterial("Hidden/ExportRT");}Vector2 size = GetMainGameViewSize();//这里只是设置图的宽高,实际图像尺寸需要在pipeline设置opaque图压缩质量RenderTexture rt = new RenderTexture((int)size.x, (int)size.y, 0);rt.format = RenderTextureFormat.ARGBFloat;rt.enableRandomWrite = true;rt.wrapMode = TextureWrapMode.Clamp;rt.Create();Graphics.Blit(null, rt, _mat);var originalRT = RenderTexture.active;RenderTexture.active = rt;var tex = new Texture2D(rt.width, rt.height, TextureFormat.ARGB32, false);tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);tex.Apply();var bytes = tex.EncodeToTGA(EncodeToTGAExtension.Compression.None);if(File.Exists(path)) File.Delete(path);File.WriteAllBytes(path, bytes);DestroyImmediate(tex);rt.Release();RenderTexture.active = originalRT;}void CreateLUTBase(out string state){var path = _filePath;if(File.Exists(path)) File.Delete(path);
//这里根据pipeline设置给参数,ldr是1024x32var tex = new Texture2D(1024,32, TextureFormat.RGBAFloat, false);tex.wrapMode = TextureWrapMode.Clamp;tex.filterMode = FilterMode.Point;var colors = new Color[1024,32];for (var b = 0; b < 32; b++){for (var g = 0; g < 32; g++){for (var r = 0; r < 32; r++){colors[r + b * 32, g] = new Color(r/32f,g/32f,b/32f);}}}for (var h = 0; h < 1024; h++){for (var v = 0; v < 32; v++){tex.SetPixel(h, v, colors[h, v]) ;}}tex.Apply();byte[] bytes;switch (_textureType){case TextureType.png:bytes=tex.EncodeToPNG();path = path +"/UnityLUT_Base.png";if(File.Exists(path)) File.Delete(path);File.WriteAllBytes(path,bytes);break;case TextureType.exr:bytes=tex.EncodeToEXR(Texture2D.EXRFlags.None);path = path +"/UnityLUT_Base.exr";if(File.Exists(path)) File.Delete(path);File.WriteAllBytes(path,bytes);break;}DestroyImmediate(tex);}}
Shader
Shader "Hidden/ExportRT"
{Properties{}SubShader{Tags { "Queue" = "Transparent" }LOD 100Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float2 uv : TEXCOORD0;};struct v2f{float2 uv : TEXCOORD0;float4 vertex : SV_POSITION;};sampler2D_float _CameraOpaqueTexture;//sampler2D_float _MainTex;float3 LinearToSRGB(float3 c){float3 sRGBLo = c * 12.92;float3 sRGBHi = (pow(abs(c), float3(1.0/2.4, 1.0/2.4, 1.0/2.4)) * 1.055) - 0.055;float3 sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi;return sRGB;}half3 SRGBToLinear(half3 c){half3 linearRGBLo = c / 12.92;half3 linearRGBHi = pow(abs((c + 0.055) / 1.055), 2.4);half3 linearRGB = (c <= 0.04045) ? linearRGBLo : linearRGBHi;return linearRGB;}v2f vert (appdata v){v2f o;o.vertex = UnityObjectToClipPos(v.vertex);o.uv = v.uv;return o;}float4 frag (v2f i) : SV_Target{// sample the texturefloat4 col = tex2D(_CameraOpaqueTexture, i.uv);//opaque图为linear状态,输出到图需要转sRGB,本身color lookup回读的也是sRGB图return float4(LinearToSRGB(col.rgb), col.a);}ENDCG}}
}
Unity 生成原始LUT用于外部校色相机不透明物体截图相关推荐
- 华为诺亚方舟加拿大实验室提出BANet,双向视觉注意力机制用于单目相机深度估计...
点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 这篇文章的作者是华为加拿大诺亚方舟实验室,是一篇将双向注意力机制用于弹幕深度估计的工作.主要的创新点在 ...
- 武汉大学提出ARGAN:注意力循环生成对抗模型用于检测、去除图像阴影 | ICCV 2019...
作者 | 王红成 出品|AI科技大本营(ID:rgznai100) [导读]如何去除一张图像中的阴影部分?在ICCV 2019会上,武汉大学的一篇论文针对这一问题提出了一种用于阴影检测和去除的注意循环 ...
- 武汉大学提出ARGAN:注意力循环生成对抗模型用于检测、去除图像阴影 | ICCV 2019
[导读]如何去除一张图像中的阴影部分?在ICCV 2019会上,武汉大学的一篇论文针对这一问题提出了一种用于阴影检测和去除的注意循环生成对抗网络--ARGAN.论文中通过生成一张更加准确的注意力图,用 ...
- flink 异步io mysql 缓存_Flink用于外部数据访问的异步I/O
本页阐述了使用Flink的API来进行外部数据存储的异步I/O,对于不熟悉异步或者事件驱动编程的用户,一篇关于Future和事件驱动编程可能会很有用. 注意:关于异步I/O的详细设计和实现可以在异步I ...
- Unity生成随机数
一.Unity生成随机数 generatedSpawnTime = Random.Range(minSpawnTime, maxSpawnTime); //固定代码 生成一个"minSpaw ...
- 基于ZXing Android实现生成二维码图片和相机扫描二维码图片即时解码的功能
NextQRCode ZXing开源库的精简版 **基于ZXing Android实现生成二维码图片和相机扫描二维码图片即时解码的功能 原文博客 附源码下载地址** 与原ZXingMini项目对比 N ...
- Unity 生成APK 出错的解决方法
Unity 生成APK 出错的解决方法 参考文章: (1)Unity 生成APK 出错的解决方法 (2)https://www.cnblogs.com/laomanong/p/5783599.html ...
- Unity 生成 Excel表格
Unity生成Excel需要EPPlus这个库,Editor状态可以使用,打包后需要加入 I18N.CJK 和 I18N 这两个库 代码如下: private void SaveExcel(){Op ...
- Unity 生成二维码 融合图片
Unity 生成二维码,并将二维码和已有背景图片融合,保存到本地,,, 1.场景的搭建 2.代码的编写(参考链接) using System.IO; using UnityEngine; using ...
最新文章
- 让IE6、IE7、IE8支持CSS3的圆角、阴影样式
- 入选 Forrester 领导者象限,阿里云 Serverless 产品能力全球第一
- call、apply和bind的原生实现
- H5的Websocket基本使用
- android 广告弹出层,安卓广告活动弹窗控件 android-adDialog
- Python中list(列表)、tuple(元组)、dict(字典)的基本操作快速入门
- mysql 5.622_新特新解读 | MySQL 8.0 对 count(*)的优化
- c++类成员变量初始化详解
- 计算机桌面软件图标没了,手把手教你电脑桌面图标都不见了怎么办
- c语言程序提速,用C语言加速程序进而加速硬件速度
- linux宿主机文件拷贝,linux 虚拟机和宿主机相互拷贝文件
- 学历学籍管理系统-MVC和工厂模式实现学籍查询与录入
- php js 美国时间转换,洛杉矶时间换算(世界时间换算器在线)
- WPF 使用Microsoft.Ink 做的墨迹输入法
- 木棒拼图(有一个由很多木棒构成的集合,每个木棒有对应的长度,请问能否用集合中的这些木棒以某个顺序首尾相连构成一个面积大于 0 的简单多边形且所有木棒都要用上,简单多边形即不会自交的多边形。)
- iOS 指南针的制作 附带源码
- 面向构件的软件设计问答
- ant调用cmd命令行
- Xubuntu 16.04下安装gtx 960m的NVidia显卡驱动----2017.03.19
- java两玩家石头剪刀布获胜法,石头剪刀布Java实现