当前位置: 首页 > news >正文

武汉设计公司排名前十兰州网络seo公司

武汉设计公司排名前十,兰州网络seo公司,网站建设流程ppt,数据库做图书管理系统网站大家好,我是阿赵。   继续介绍屏幕后处理,这一期介绍一下Tonemapping色调映射 一、Tone Mapping的介绍 Tone Mapping色调映射,是一种颜色的映射关系处理,简单一点说,一般是从原始色调(通常是高动态范围&…

  大家好,我是阿赵。
  继续介绍屏幕后处理,这一期介绍一下Tonemapping色调映射

一、Tone Mapping的介绍

  Tone Mapping色调映射,是一种颜色的映射关系处理,简单一点说,一般是从原始色调(通常是高动态范围,HDR)映射到目标色调(通常是低动态范围,LDR)。
  由于HDR的颜色值是能超过1的,但实际上在LDR范围,颜色值最大只能是1。如果我们要在LDR的环境下,尽量模拟HDR的效果,超过1的颜色部分怎么办呢?
最直接想到的是两种可能:
1、截断大于1的部分
  大于1的部分,直接等于1,小于1的部分保留。这种做法,会导致超过1的部分全部变成白色,在原始图片亮度比较高的情况下,转换完之后可能就是一片白茫茫的效果。
2、对颜色进行线性的缩放
  把原始颜色的最大值看做1,然后把原始的所有颜色进行整体的等比缩放。这样做,能保留一定的效果。但由于原始的HDR颜色的跨度可能比0到1大很多,所以整体缩小之后,整个画面就会变暗很多了,没有了HDR的通透光亮的感觉。
  为了能让HDR颜色映射到LDR之后,还能保持比较接近的效果,上面两种方式的处理显然都是不好的。
  Tonemapping也是把HDR颜色范围映射到0-1的LDR颜色范围,但它并不是线性缩放,而是曲线的缩放。
在这里插入图片描述

  从上面这个例子可以看出来,Tonemapping映射之后的颜色,有些地方是变暗了,比如深颜色的裤子,但有些地方却是变亮了的,比如头发和肩膀衣服上的阴影。整体的颜色有一种电影校色之后的感觉。
  很多游戏美工在没有技术人员配合的情况下,都很喜欢自己挂后处理,其中Tonemapping应该是除了Bloom以外,美工们最喜欢的一种后处理了,虽然不知道为什么,但就是觉得颜色好看了。
  虽然屏幕后处理看着好像很简单实现,挂个组件调几个参数,就能化腐朽为神奇,把原本平淡无奇的画面变得好看。但其实后处理都是有各种额外消耗的,所以我一直不是很建议美工们只会依靠后处理来扭转画面缺陷的,特别是做手游。

二、Tonemapping的代码实现

1、C#代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class TonemappingCtrl : MonoBehaviour
{private Material toneMat;public bool isTonemapping = false;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}private bool TonemappingFun(RenderTexture source, RenderTexture destination){if (toneMat == null){toneMat = new Material(Shader.Find("Hidden/ToneMapping"));}if (toneMat == null || toneMat.shader == null || toneMat.shader.isSupported == false){return false;}Graphics.Blit(source, destination, toneMat);return true;}private void OnRenderImage(RenderTexture source, RenderTexture destination){if(isTonemapping == false){Graphics.Blit(source, destination);return;}RenderTexture finalRt = source;if (TonemappingFun(finalRt,finalRt)==false){Graphics.Blit(source, destination);}else{Graphics.Blit(finalRt, destination);}}
}

C#部分的代码和其他后处理没区别,都是通过OnRenderImage里面调用Graphics.Blit

2、Shader

Shader "Hidden/ToneMapping"
{Properties{_MainTex ("Texture", 2D) = "white" {}}SubShader{// No culling or depthCull Off ZWrite Off ZTest AlwaysPass{CGPROGRAM#pragma vertex vert_img#pragma fragment frag#include "UnityCG.cginc"sampler2D _MainTex; float3 ACES_Tonemapping(float3 x){float a = 2.51f;float b = 0.03f;float c = 2.43f;float d = 0.59f;float e = 0.14f;float3 encode_color = saturate((x*(a*x + b)) / (x*(c*x + d) + e));return encode_color;}fixed4 frag (v2f_img i) : SV_Target{fixed4 col = tex2D(_MainTex, i.uv);half3 linear_color = pow(col.rgb, 2.2);half3 encode_color = ACES_Tonemapping(linear_color);col.rgb = pow(encode_color, 1 / 2.2);return col;}ENDCG}}
}

需要说明一下:
1.色彩空间的转换
  由于默认显示空间是Gamma空间,所以先通过pow(col.rgb, 2.2)把颜色转换成线性空间,然后再进行Tonemapping映射,最后再pow(encode_color, 1 / 2.2),把颜色转回Gamma空间
2.Tonemapping映射算法

float3 ACES_Tonemapping(float3 x){float a = 2.51f;float b = 0.03f;float c = 2.43f;float d = 0.59f;float e = 0.14f;float3 encode_color = saturate((x*(a*x + b)) / (x*(c*x + d) + e));return encode_color;}

把颜色进行Tonemapping映射。这个算法是网上都可以百度得到的。

三、Tonemapping和其他后处理的配合

  一般来说,Tonemapping只是一个固定颜色映射效果,所以应该是需要配合着其他的效果一起使用,才会得到比较好的效果。比如我之前介绍过的校色、暗角、Bloom等。
在这里插入图片描述
在这里插入图片描述

  可以做出各种不同的效果,不同于原始颜色的平淡,调整完之后的颜色看起来会比较有电影的感觉。
  这也是我为什么要在Unity有PostProcessing后处理插件的情况下,还要介绍使用自己写Shader实现屏幕后处理的原因。PostProcessing作为一个插件,它可能会存在很多功能,会有很多额外的计算,你可能只需要用到其中的某一个小部分的功能和效果。
  而我们自己写Shader实现屏幕后处理,自由度非常的高,喜欢在哪里添加或者修改一些效果,都可以。
比如,我可以写一个脚本,把之前介绍过的所有后处理效果都加进去:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//[ExecuteInEditMode]
public class ImageEffectCtrl : MonoBehaviour
{//--------调色-----------private Material colorMat;public bool isColorAjust = false;[Range(-5,5)]public float saturation = 1;[Range(-5,5)]public float contrast = 1;[Range(0,1)]public float hueShift = 0;[Range(0,5)]public float lightVal = 1;[Range(0,3)]public float vignetteIntensity = 1.8f;[Range(0,5)]public float vignetteSmoothness = 5;//-------模糊-----------private Material blurMat;public bool isBlur = false;[Range(0, 4)]public float blurSize = 0;[Range(-3,3)]public float blurOffset = 1;[Range(1,3)]public int blurType = 3;//-----光晕----------private Material brightMat;private Material bloomMat;public bool isBloom = false;[Range(0,1)]public float brightCut = 0.5f;[Range(0, 4)]public float bloomSize = 0;[Range(-3, 3)]public float bloomOffset = 1;public int bloomType = 3;[Range(1, 3)]//---toneMapping-----private Material toneMat;public bool isTonemapping = false;// Start is called before the first frame updatevoid Start(){//if(colorMat == null||colorMat.shader == null||colorMat.shader.isSupported == false)//{//    this.enabled = false;//}}// Update is called once per framevoid Update(){}private bool AjustColor(RenderTexture source, RenderTexture destination){if(colorMat == null){colorMat = new Material(Shader.Find("Hidden/AzhaoAjustColor"));}if(colorMat == null||colorMat.shader == null||colorMat.shader.isSupported == false){return false;}colorMat.SetFloat("_Saturation", saturation);colorMat.SetFloat("_Contrast", contrast);colorMat.SetFloat("_HueShift", hueShift);colorMat.SetFloat("_Light", lightVal);colorMat.SetFloat("_VignetteIntensity", vignetteIntensity);colorMat.SetFloat("_VignetteSmoothness", vignetteSmoothness);Graphics.Blit(source, destination, colorMat, 0);return true;}private Material GetBlurMat(int bType){if(bType == 1){return new Material(Shader.Find("Hidden/AzhaoBoxBlur"));}else if(bType == 2){return new Material(Shader.Find("Hidden/AzhaoGaussianBlur"));}else if(bType == 3){return new Material(Shader.Find("Hidden/AzhaoKawaseBlur"));}else{return null;}}private bool CheckNeedCreateBlurMat(Material mat,int bType){if(mat == null){return true;}if(mat.shader == null){return true;}if(bType == 1){if(mat.shader.name != "Hidden/AzhaoBoxBlur"){return true;}else{return false;}}else if(bType == 2){if (mat.shader.name != "Hidden/AzhaoGaussianBlur"){return true;}else{return false;}}else if (bType == 3){if (mat.shader.name != "Hidden/AzhaoKawaseBlur"){return true;}else{return false;}}else{return false;}}private bool BlurFun(RenderTexture source, RenderTexture destination,float blurTime,int bType,float offset ){if(CheckNeedCreateBlurMat(blurMat,bType)==true){blurMat = GetBlurMat(bType);}if (blurMat == null || blurMat.shader == null || blurMat.shader.isSupported == false){return false;}blurMat.SetFloat("_BlurOffset", offset);float width = source.width;float height = source.height;int w = Mathf.FloorToInt(width);int h = Mathf.FloorToInt(height);RenderTexture rt1 = RenderTexture.GetTemporary(w, h);RenderTexture rt2 = RenderTexture.GetTemporary(w, h);Graphics.Blit(source, rt1);for (int i = 0; i < blurTime; i++){ReleaseRT(rt2);width = width / 2;height = height / 2;w = Mathf.FloorToInt(width);h = Mathf.FloorToInt(height);rt2 = RenderTexture.GetTemporary(w, h);Graphics.Blit(rt1, rt2, blurMat, 0);width = width / 2;height = height / 2;w = Mathf.FloorToInt(width);h = Mathf.FloorToInt(height);ReleaseRT(rt1);rt1 = RenderTexture.GetTemporary(w, h);Graphics.Blit(rt2, rt1, blurMat, 1);}for (int i = 0; i < blurTime; i++){ReleaseRT(rt2);width = width * 2;height = height * 2;w = Mathf.FloorToInt(width);h = Mathf.FloorToInt(height);rt2 = RenderTexture.GetTemporary(w, h);Graphics.Blit(rt1, rt2, blurMat, 0);width = width * 2;height = height * 2;w = Mathf.FloorToInt(width);h = Mathf.FloorToInt(height);ReleaseRT(rt1);rt1 = RenderTexture.GetTemporary(w, h);Graphics.Blit(rt2, rt1, blurMat, 1);}Graphics.Blit(rt1, destination);ReleaseRT(rt1);rt1 = null;ReleaseRT(rt2);rt2 = null;return true;}private bool BrightRangeFun(RenderTexture source, RenderTexture destination){if(brightMat == null){brightMat = new Material(Shader.Find("Hidden/BrightRange"));}if (brightMat == null || brightMat.shader == null || brightMat.shader.isSupported == false){return false;}brightMat.SetFloat("_BrightCut", brightCut);Graphics.Blit(source, destination, brightMat);return true;}private bool BloomAddFun(RenderTexture source,RenderTexture destination, RenderTexture brightTex){if(bloomMat == null){bloomMat = new Material(Shader.Find("Hidden/AzhaoBloom"));}if (bloomMat == null || bloomMat.shader == null || bloomMat.shader.isSupported == false){return false;}bloomMat.SetTexture("_brightTex", brightTex);Graphics.Blit(source, destination, bloomMat);return true;}private bool TonemappingFun(RenderTexture source, RenderTexture destination){if(toneMat == null){toneMat = new Material(Shader.Find("Hidden/ToneMapping"));}if (toneMat == null || toneMat.shader == null || toneMat.shader.isSupported == false){return false;}Graphics.Blit(source, destination, toneMat);return true;}private void CopyRender(RenderTexture source,RenderTexture destination){Graphics.Blit(source, destination);}private void ReleaseRT(RenderTexture rt){if(rt!=null){RenderTexture.ReleaseTemporary(rt);}}private void OnRenderImage(RenderTexture source, RenderTexture destination){        RenderTexture finalRt = source;RenderTexture rt2 = RenderTexture.GetTemporary(source.width, source.height);RenderTexture rt3 = RenderTexture.GetTemporary(source.width, source.height);if (isBloom == true){if(BrightRangeFun(finalRt, rt2)==true){if(BlurFun(rt2, rt3, bloomSize,bloomType,bloomOffset)==true){if(BloomAddFun(source, finalRt, rt3)==true){}                        }}}if(isBlur == true){if (blurSize > 0){if (BlurFun(finalRt, finalRt, blurSize,blurType,blurOffset) == true){}}}if (isTonemapping == true){if (TonemappingFun(finalRt, finalRt) == true){}}if (isColorAjust == true){           if (AjustColor(finalRt, finalRt) == true){}}CopyRender(finalRt, destination);ReleaseRT(finalRt);ReleaseRT(rt2);ReleaseRT(rt3);}
}

在这里插入图片描述

  一个脚本控制所有后处理。当然这样的做法只是方便,也不见得很好,我还是比较喜欢根据实际用到多少个效果,单独去写对应的脚本,那样我觉得性能才是最好的。


文章转载自:
http://preheat.c7513.cn
http://phytochrome.c7513.cn
http://smearcase.c7513.cn
http://glenn.c7513.cn
http://begonia.c7513.cn
http://ignitron.c7513.cn
http://canescent.c7513.cn
http://mitrailleuse.c7513.cn
http://pendeloque.c7513.cn
http://monophobia.c7513.cn
http://elastomeric.c7513.cn
http://stop.c7513.cn
http://cathleen.c7513.cn
http://eradicative.c7513.cn
http://beanery.c7513.cn
http://riproarious.c7513.cn
http://cloudland.c7513.cn
http://breslau.c7513.cn
http://esperance.c7513.cn
http://truffle.c7513.cn
http://cooperage.c7513.cn
http://hematogenesis.c7513.cn
http://bequest.c7513.cn
http://bistatic.c7513.cn
http://calculus.c7513.cn
http://rashida.c7513.cn
http://calcicole.c7513.cn
http://sebum.c7513.cn
http://photoconduction.c7513.cn
http://placoid.c7513.cn
http://slid.c7513.cn
http://gormandizer.c7513.cn
http://restrained.c7513.cn
http://electrohorticulture.c7513.cn
http://discontentment.c7513.cn
http://nmsqt.c7513.cn
http://noontime.c7513.cn
http://smitten.c7513.cn
http://trochaic.c7513.cn
http://geotaxis.c7513.cn
http://hydrometeorological.c7513.cn
http://carolina.c7513.cn
http://sidestream.c7513.cn
http://ingenuous.c7513.cn
http://hydrosulfate.c7513.cn
http://fribble.c7513.cn
http://electrogenesis.c7513.cn
http://incendivity.c7513.cn
http://oceanologic.c7513.cn
http://panurge.c7513.cn
http://seidel.c7513.cn
http://resupine.c7513.cn
http://convolute.c7513.cn
http://litoral.c7513.cn
http://sayst.c7513.cn
http://iridectome.c7513.cn
http://stumer.c7513.cn
http://taproom.c7513.cn
http://watermanship.c7513.cn
http://resort.c7513.cn
http://hipe.c7513.cn
http://laguna.c7513.cn
http://crushproof.c7513.cn
http://hydride.c7513.cn
http://tally.c7513.cn
http://pob.c7513.cn
http://smudginess.c7513.cn
http://emmetropia.c7513.cn
http://metallocene.c7513.cn
http://bond.c7513.cn
http://bureaucratize.c7513.cn
http://senescent.c7513.cn
http://dwight.c7513.cn
http://details.c7513.cn
http://repone.c7513.cn
http://bourne.c7513.cn
http://blenny.c7513.cn
http://solfatara.c7513.cn
http://polyunsaturate.c7513.cn
http://george.c7513.cn
http://norseland.c7513.cn
http://uninstructed.c7513.cn
http://smasheroo.c7513.cn
http://habituate.c7513.cn
http://fantasy.c7513.cn
http://visitandine.c7513.cn
http://way.c7513.cn
http://yarmouth.c7513.cn
http://tritural.c7513.cn
http://diplomat.c7513.cn
http://egotistical.c7513.cn
http://dicot.c7513.cn
http://ovariotomy.c7513.cn
http://volcanotectonic.c7513.cn
http://exodontist.c7513.cn
http://minibike.c7513.cn
http://crackle.c7513.cn
http://commination.c7513.cn
http://proletarian.c7513.cn
http://boxkeeper.c7513.cn
http://www.zhongyajixie.com/news/91807.html

相关文章:

  • 90后做网站月入万元google浏览器官网下载
  • 高负载php网站开发关键词指数查询工具
  • 怎么用ajax做电商网站谷歌推广哪家好
  • 深圳市公司网站建设公司网络引流怎么做啊?
  • 查询网站备案密码自己有产品怎么网络销售
  • 海南省建设注册中心网站电子商务网站建设与管理
  • 开一家网站建设公司要多少钱武汉百度seo网站优化
  • 赣州政府网站百度百科查询
  • 网站如何做404免费网络空间搜索引擎
  • python 网站建设seo优化的网站
  • 能赚钱的网站自己建网页
  • 海口制作网站软件产品推广营销
  • 网站建设和管理维护全国知名网站排名
  • 企业管理系统开发平台四川seo整站优化
  • 如何用云服务器做网站注册公司网站
  • 网站建设采购项目合同书seminar什么意思中文
  • 重庆企业网站制作网站的seo是什么意思
  • 网站优化关键词公司北京seo优化
  • 建网站空间的详细说明什么叫网络市场营销
  • 怎么做类似返利网的网站宁德市安全教育平台
  • 知乎网站怎么做推广常州seo建站
  • 做针对国外的网站网站网址查询工具
  • 北京 网站空间 租用广州网络推广服务商
  • 做网站的要多钱一个新品牌如何推广
  • 潍坊网站建设评价迅雷下载磁力天堂
  • 网站的建设流程深圳刚刚突然宣布
  • 时尚flash网站长春模板建站代理
  • 网站如何知道是谁做的呢如何建立网站平台
  • 腾讯域名怎么建设网站拉新平台
  • 网站建设结论与改进网络营销的整体概念