这个位置可以看到ppsspp的特殊处理

文件位置

来看看这些特效

用来测试的未加特效图片

ppsspp:

传说系列一生爱---英杰传说

最后的战士

aacolor

是关于饱和度,亮度,对比度,色调的调节,
ppsspp中的默认参数为饱和度加强1.2倍,对比度增强1.25倍,在unity中我们可以设为外部变量自己调节

关键代码:

		float4 frag(v2f i) :COLOR
{
float size = 1 / _Size; float3 c10 = tex2D(_MainTex, i.uv_MainTex + float2(0, -1)*size).rgb;
float3 c01 = tex2D(_MainTex, i.uv_MainTex + float2(-1, 0)*size).rgb;
float3 c11 = tex2D(_MainTex, i.uv_MainTex).rgb;
float3 c21 = tex2D(_MainTex, i.uv_MainTex + float2(1, 0)*size).rgb;
float3 c12 = tex2D(_MainTex, i.uv_MainTex + float2(0, 1)*size).rgb; float3 dt = float3(1.0, 1.0, 1.0);
float k1 = dot(abs(c01 - c21), dt);
float k2 = dot(abs(c10 - c12), dt); float3 color = (k1*(c10 + c12) + k2*(c01 + c21) + 0.001*c11) / (2.0*(k1 + k2) + 0.001); float x = sqrt(dot(color, color)); color.r = pow(color.r + 0.001, _A);
color.g = pow(color.g + 0.001, _A);
color.b = pow(color.b + 0.001, _A); //饱和度,亮度,对比度,色调映射
return float4(contrast4(x)*normalize(color*_C_ch)*_B,1); }

ppsspp中实测

unity中实测

bloom

辉光效果
ppsspp中的辉光在unity种效果并不好,模糊处理不够,亮度过量,采样方式为grid采样
之前写过一篇详细博文关于HDR(与bloom相似)

关键代码:

	float4 frag(v2f i) :COLOR
{
float size = 1 / _Size;
float2 uv = i.uv_MainTex; float3 color = tex2D(_MainTex, i.uv_MainTex);
float4 sum = 0;
float3 bloom; for (int i = -3; i < 3; i++)
{
sum += tex2D(_MainTex, uv + float2(-1, i)*size) * _Amount;
sum += tex2D(_MainTex, uv + float2(0, i)*size) * _Amount;
sum += tex2D(_MainTex, uv + float2(1, i)*size) * _Amount;
} if (color.r < 0.3 && color.g < 0.3 && color.b < 0.3)
{
bloom = sum.rgb*sum.rgb*0.012 + color;
}
else
{
if (color.r < 0.5 && color.g < 0.5 && color.b < 0.5)
{
bloom = sum.xyz*sum.xyz*0.009 + color;
}
else
{
bloom = sum.xyz*sum.xyz*0.0075 + color;
}
} bloom = mix(color, bloom, _Power); return float4(bloom, 1);
}

ppsspp中实测

unity中实测

cartoon

卡通效果的post processing
颜色总共分为四层,把颜色灰度每层段数值再加上减到最少的小数部分,产生一些过渡效果
再用得出的灰度乘上原色值,保留了原来的颜色只是明暗分为四层,层之间有过度
通过边缘检测描边,着色道理与之前写过的一篇详细博文像似,但不完全相同,

关键代码:

	float4 frag(v2f i) :COLOR
{
float size = 1 / _Size; float3 c00 = tex2D(_MainTex, i.uv_MainTex + float2(-1, -1)*size).rgb;
float3 c10 = tex2D(_MainTex, i.uv_MainTex + float2(0, -1)*size).rgb;
float3 c20 = tex2D(_MainTex, i.uv_MainTex + float2(1, -1)*size).rgb;
float3 c01 = tex2D(_MainTex, i.uv_MainTex + float2(-1, 0)*size).rgb;
float3 c11 = tex2D(_MainTex, i.uv_MainTex).rgb;
float3 c21 = tex2D(_MainTex, i.uv_MainTex + float2(1, 0)*size).rgb;
float3 c02 = tex2D(_MainTex, i.uv_MainTex + float2(-1, 1)*size).rgb;
float3 c12 = tex2D(_MainTex, i.uv_MainTex + float2(0, 1)*size).rgb;
float3 c22 = tex2D(_MainTex, i.uv_MainTex + float2(1, 1)*size).rgb;
float3 dt = float3(1.0, 1.0, 1.0); float d1 = dot(abs(c00 - c22), dt);
float d2 = dot(abs(c20 - c02), dt);
float hl = dot(abs(c01 - c21), dt);
float vl = dot(abs(c10 - c12), dt);
float d = _Bb*(d1 + d2 + hl + vl) / (dot(c11, dt) + 0.15); float lc = 4.0*length(c11); float f = frac(lc);
f *= f;
lc = 0.25*(floor(lc) + f*f) + 0.05;
//颜色总共分为四层,把颜色灰度每层段数值再加上减到最少的小数部分,产生一些过渡效果 c11 = 4.0*normalize(c11);
float3 frct = frac(c11);
frct *= frct;
c11 = floor(c11) + 0.05*dt + frct*frct;
return float4(0.25*lc*(1.1 - d*sqrt(d))*c11,1);
//再用得出的灰度乘上原色值,保留了原来的颜色只是明暗分为四层,层之间有过度
//通过边缘检测描边,着色道理与之前的一篇文章像似,但不完全相同, }

ppsspp中实测

unity中实测

CRT

CRT是模拟以前大脑袋电脑的阴极射线管(Cathode Ray Tube)的显示器的特殊效果,频闪之类的特效,用过大脑袋的都懂。

关键代码:

		float4 frag(v2f i) :COLOR
{ // scanlines
float vPos = float((i.uv_MainTex.y + _Time.z * 0.5) * 272.0);
float j = 2;
float line_intensity = modf(float(vPos), j); // color shift
float off = line_intensity *0.00001;
float2 shift = float2(off, 0); // shift R and G channels to simulate NTSC color bleed
float2 colorShift = float2(0.001, 0);
float r = tex2D(_MainTex, i.uv_MainTex + colorShift + shift).x;
float g = tex2D(_MainTex, i.uv_MainTex - colorShift + shift).y;
float b = tex2D(_MainTex, i.uv_MainTex).z; float4 c = float4(r, g * 0.99, b, 1) * clamp(line_intensity, 0.85, 1); float rollbar = sin((i.uv_MainTex.y + _Time.z) * 30); return c + (rollbar * 0.02);
}

ppsspp中实测

unity中实测

fxaa

ppsspp的fxaa抗锯齿效果在unity上异常的好,耗费很少,
四个采样点来进行边缘检测(边缘检测的很粗糙),边缘处两个点之间模糊

关键代码:

	float4 frag(v2f i) :COLOR
{ float u_texelDelta = 1 / _Size; float FXAA_SPAN_MAX = 8.0;
float FXAA_REDUCE_MUL = 1.0 / 8.0;
float FXAA_REDUCE_MIN = (1.0 / 128.0); float3 rgbNW = tex2D(_MainTex, i.uv_MainTex + (float2(-1.0, -1.0) * u_texelDelta)).xyz;
float3 rgbNE = tex2D(_MainTex, i.uv_MainTex + (float2(+1.0, -1.0) * u_texelDelta)).xyz;
float3 rgbSW = tex2D(_MainTex, i.uv_MainTex + (float2(-1.0, +1.0) * u_texelDelta)).xyz;
float3 rgbSE = tex2D(_MainTex, i.uv_MainTex + (float2(+1.0, +1.0) * u_texelDelta)).xyz;
float3 rgbM = tex2D(_MainTex, i.uv_MainTex).xyz; float3 luma = float3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma); float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); float2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN); float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce); dir = min(float2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * u_texelDelta; float3 rgbA = (1.0 / 2.0) * (
tex2D(_MainTex, i.uv_MainTex + dir * (1.0 / 3.0 - 0.5)).xyz +
tex2D(_MainTex, i.uv_MainTex + dir * (2.0 / 3.0 - 0.5)).xyz);
float3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * (
tex2D(_MainTex, i.uv_MainTex + dir * (0.0 / 3.0 - 0.5)).xyz +
tex2D(_MainTex, i.uv_MainTex + dir * (3.0 / 3.0 - 0.5)).xyz); float lumaB = dot(rgbB, luma); if ((lumaB < lumaMin) || (lumaB > lumaMax)){
return float4( rgbA,1);
}
else {
return float4(rgbB, 1);
}
//整体上是一个边缘检测,在边缘处进行采样模糊 }

ppsspp中实测

unity中实测

grayscale

灰度
白光的亮度用Y表示,它和红绿蓝三色光的关系:
Y = 0.299R+0.587G+0.114B    NTSC美制电视制式亮度公式
Y = 0.222R+0.707G+0.071B    PAL(相位逐行交变)电视制式
ppsspp使用的是NTSC美制,Unity中的Luminance函数使用的是PAL制式

关键代码:

float4 frag(v2f i) :COLOR
{ float3 rgb = tex2D(_MainTex, i.uv_MainTex).rgb;
float luma = dot(rgb, float3(0.299, 0.587, 0.114)); return luma; }

ppsspp中实测

unity中实测

inversecolors

反色

关键代码:

		float4 frag(v2f i) :COLOR
{ float3 rgb = tex2D(_MainTex, i.uv_MainTex).rgb;
float luma = dot(rgb, float3(0.299, 0.587, 0.114));
// luma = Luminance(rgb);
float3 gray = float3(luma, luma, luma) - 0.5;
rgb -= float3(0.5, 0.5, 0.5); return float4(mix(rgb, gray, 2.0) + 0.5, 1); }

ppsspp中实测

unity中实测

natural

使颜色变得自然
把颜色从RGB转到YIQ色彩空间在进行变换

关键代码:

	float4 frag(v2f i) :COLOR
{
float3 val00 = float3(1.2, 1.2, 1.2);
float3x3 RGBtoYIQ = float3x3(0.299, 0.596, 0.212,
0.587, -0.275, -0.523,
0.114, -0.321, 0.311); float3x3 YIQtoRGB = float3x3(1.0, 1.0, 1.0,
0.95568806036115671171, -0.27158179694405859326, -1.1081773266826619523,
0.61985809445637075388, -0.64687381613840131330, 1.7050645599191817149); float4 c = tex2D(_MainTex, i.uv_MainTex);
float3 c1 =mul( RGBtoYIQ,c.rgb); c1 = float3(pow(c1.x, val00.x), c1.yz*val00.yz);
//转换到YIQ色彩空间再加强GB颜色1.2倍
return float4(mul(YIQtoRGB,c1), 1);
}

ppsspp中实测

unity中实测

scanlines

屏幕上的线的效果

关键代码:

	float4 frag(v2f i) :COLOR
{ float pos0 = ((i.uv_MainTex.y + 1.0) * 170.0*_Amount);
float pos1 = cos((frac(pos0) - 0.5)*3.1415926*_Inten)*1.5;
float4 rgb = tex2D(_MainTex, i.uv_MainTex); // slight contrast curve
float4 color = rgb*0.5 + 0.5*rgb*rgb*1.2; // color tint
color *= float4(0.9, 1.0, 0.7, 0.0); // vignette
color *= 1.1 - 0.6 * (dot(i.uv_MainTex - 0.5, i.uv_MainTex - 0.5) * 2.0); return mix(float4(0, 0, 0, 0), color, pos1);
}

ppsspp中实测

unity中实测

sharpen

锐化
取上下两个采样点,采样点之间的颜色差越大(边缘,色差大等处),sharp越明显

关键代码:

		float4 frag(v2f i) :COLOR
{
float4 c = tex2D(_MainTex, i.uv_MainTex);
c -= tex2D(_MainTex, i.uv_MainTex + _Size)*7.0*_Inten;
c += tex2D(_MainTex, i.uv_MainTex - _Size)*7.0*_Inten;
//采样点之间的颜色差越大(边缘,色差大等处),sharp越明显
return c;
}

ppsspp中实测

unity中实测

vignette

晕影效果

关键代码:

			float4 frag(v2f i) :COLOR
{ float vignette = 1.1 - 0.6 * (dot(i.uv_MainTex - 0.5, i.uv_MainTex - 0.5) * 2.0);
float3 rgb = tex2D(_MainTex, i.uv_MainTex).rgb;
return float4(vignette * rgb, 1); }

ppsspp中实测

unity中实测

4xhqglsl

平滑效果

ppsspp中实测

upscale_spline36

缩放滤镜
基于样条线的缩放(Spline based resizers)分别有spline16 spline36 spline64这三个缩放滤镜基于样条插值算法。样条差值算法在放大时尽可能的锐化图像,减少失真
该算法原作者为Panorama tools的开发者
详细算法的介绍请看forum.doom9.org/showthread.php?t=147117

ppsspp中实测

用一张不同的图做测试,在比例2X的情况下全屏拉伸,图像会变模糊,使用缩放滤镜进行放大,效果就像4X一样清楚

未开启

开启

全部代码已上传至GitHub

                                    --------by wolf96

unity3d ppsspp模拟器中的post processing shader在unity中使用的更多相关文章

  1. Unity中加入Android项目的Build步骤

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 简介: 有的项目需要在Android中加入Unity功能,例如ANDROID应用中嵌入Un ...

  2. 3D语音天气球(源码分享)——在Unity中使用Android语音服务

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 这个项目准备分四部分介绍: 一:创建可旋转的"3D球":3 ...

  3. 骨骼动画的原理及在Unity中的使用

    制作骨骼动画 我们看看这几步操作后,我们得到了那些数据: 1.每个皮肤顶点的初始世界坐标. 2.每个骨骼关节顶点的初始世界坐标. 3.每个顶点被骨骼顶点的影响信息. 4.骨骼如何移动. 骨骼动画原理 ...

  4. java程序员图文并茂细说Unity中调用Android的接口

    http://bbs.csdn.net/topics/391876421 最近做一个项目,为同事提供接口,能使他在Unity中调用Android中的函数来实现QQ登陆并获取用户信息.按照一些书上和一些 ...

  5. 【Unity编程】Unity中的欧拉旋转

    欧拉角的定义 在写这篇博客之前,我搜索了网上很多关于欧拉角的定义,发现大部分引用自维基百科的定义,我这里也引述一下: 维基百科定义 莱昂哈德·欧拉用欧拉角来描述刚体在三维欧几里得空间的取向.对于任何参 ...

  6. C#使用ProtocolBuffer(ProtoBuf)进行Unity中的Socket通信

    首先来说一下本文中例子所要实现的功能: 基于ProtoBuf序列化对象 使用Socket实现时时通信 数据包的编码和解码 下面来看具体的步骤: 一.Unity中使用ProtoBuf 导入DLL到Uni ...

  7. Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug

    问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...

  8. Unity中让Update中的方法执行一次

    Unity中让Update中的方法执行一次 Unity中,很多时候,代码需要放在Update中时刻监测状态,一旦状态符合,又只需要代码执行一次:其实可以通过设置控制量的方式,让代码只执行一次:方法:设 ...

  9. 二叉树遍历在Unity中的实现

    前言:今天放一天,想到要放国庆假了就心烦气躁,躺床上又焦虑,回想起面试官的一副扑克脸,马上跳起来看了看数据结构. 今天复习了二叉树,包括一些基本概念和特性,当看到二叉树遍历的章节时,马上联想到了Uni ...

随机推荐

  1. php 表单的活用

    一般表单都是用过POST 方式对数据进行隐秘的传输用, 可以偶尔你也会发现这样的用法,表单不止能够进行隐秘的传输.还能够进行URL的传输,并且是同时进行的 提交页面,在action 后面加了URL后缀 ...

  2. web 自定义监听器中设置加载系统相关的静态变量及属性

    直接上代码: 在src下新建一个StartListener 实现接口ServletContextListener,: /** * @Title:StartListener.java * @Packag ...

  3. C#DbHelperOleDb,Access数据库帮助类 (转载)

    主要功能如下数据访问抽象基础类 主要是访问Access数据库主要实现如下功能 .数据访问基础类(基于OleDb)Access数据库, .得到最大值:是否存在:是否存在(基于OleDbParameter ...

  4. android自定义样式大全:shape,selector,layer-list,style,动画全部内容

    原文:http://keeganlee.me/post/android/20150830 以下摘取了部分内容: shape 一般用shape定义的xml文件存放在drawable目录下,若项目没有该目 ...

  5. Java 中判断char 是否为空格 和空

    //判断是否char是否为空import java.util.*; public class test{ public static void main(String[] args){ String ...

  6. iOS支付总结

    内容大纲: 一.常见的支付方案简介 二.第三方支付SDK 三.苹果官方支付方案 四.Web支付方案 正文: 一.常见的支付方案简介 在微信支付中 微信支付的网址是: https://pay.weixi ...

  7. GridView 编辑、删除 、分页

    类似代码都差不多,记录一下,便于以后查看使用. 前台页面: <asp:GridView ID="gdvList" runat="server" AutoG ...

  8. 深入理解JAVA多态原理

    之前一直知道多态是什么东西,平时敲代码也经常用到多态,但一直没有真正了解多态底层的运行机制到底是怎么样的,这两天才研究明白点,特地写下来,跟各位同学一起进步,同时也希望各位大神指导和指正. 多态的概念 ...

  9. [lua]再版jobSchedule与脚本描述范型

    首先贴上代码 -- CPM:关键路径法(Critical Path Method) jobSchedule = { todos = { -- todo list ... ["finale&q ...

  10. python 元组问题解决

    a = (1,2,{'k1':'b2'}) a[2]['k1'] = 5 print(a) (1, 2, {'k1': 5}) 为什么元素'b2' = 5 应该是元素'k1' = 5 求解 a[2][ ...