Unity信号干扰shader(参照崩坏3源码翻译剧情对话效果)_program "vp" {-程序员宅基地

技术标签: 电视故障  信号干扰  Shader  崩坏  电视扭曲  

最近做的项目是二次元,二次元的标杆就是崩坏3,效果真的好

学习崩坏3里面shader最好的方法就是看源码

可以AssetStudio来看资源,因为崩坏3资源是没有加密直接可以看


 

不过shader源码是已经编译好的,其实大概算法都在

我已经研究角色身上的shader,这个有空写博客,用到顶点绘制的工具来填充颜色来处理阴影

这次我参考崩坏里面的信号干扰的shader

之前搞个一个类似信号干扰

https://blog.csdn.net/SnoopyNa2Co3/article/details/84673736

下面效果

我看了一下没有特别的算法,那个噪音的都是经验公式,了解的话可以自行搜索一下

下面是编译过的shader

Shader "miHoYo/UI/Image TV Distortion" {
Properties {
_MainTex ("Sprite Texture", 2D) = "white" { }
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
_BackgroundColor ("Barckground Color (RGBA)", Color) = (0,0,0,1)
_AdjustColor ("Adjust Color (RGB)", Color) = (0,0,0,1)
_DistortionTex ("Distortion Tex (RG)", 2D) = "gray" { }
_DistortionFrequency ("Distortion Frequency", Float) = 1
_DistortionAmplitude ("Distortion Amplitude", Range(0, 1)) = 1
_DistortionAnmSpeed ("Distortion Animation Speed", Float) = 1
_ColorScatterStrength ("Color Scatter Strength", Range(-0.1, 0.1)) = 0.01
_NoiseTex ("Noise Tex (RGB)", 2D) = "black" { }
_NoiseAnmSpeed ("Noise Animation Speed", Float) = 1
_NoiseStrength ("Noise Strength", Float) = 1
_BloomFactor ("Bloom Factor", Float) = 1
[Toggle(RECT_MASK)] _RectMask ("Rect Mask", Float) = 0
_RMRect ("Rect Mask Rect", Vector) = (0,0,1,1)
_RMTransitWidth ("Rect Mask Transit Width", Vector) = (0,0,0,0)
}
SubShader {
 Tags { "CanUseSpriteAtlas" = "true" "IGNOREPROJECTOR" = "true" "PreviewType" = "Plane" "QUEUE" = "Transparent+1" "RenderType" = "Transparent" }
 Pass {
  Tags { "CanUseSpriteAtlas" = "true" "IGNOREPROJECTOR" = "true" "PreviewType" = "Plane" "QUEUE" = "Transparent+1" "RenderType" = "Transparent" }
  ZClip Off
  ZTest Off
  ZWrite Off
  Cull Off
  GpuProgramID 59740
Program "vp" {
SubProgram "gles hw_tier00 " {
"#version 100

#ifdef VERTEX
attribute vec4 _glesVertex;
attribute vec4 _glesColor;
attribute vec4 _glesMultiTexCoord0;
uniform highp vec4 _Time;
uniform highp vec4 _SinTime;
uniform highp vec4 _CosTime;
uniform highp mat4 unity_ObjectToWorld;
uniform highp mat4 unity_MatrixVP;
uniform mediump float _DistortionFrequency;
uniform mediump float _DistortionAnmSpeed;
uniform highp vec4 _NoiseTex_ST;
uniform highp float _NoiseAnmSpeed;
uniform lowp vec4 _Color;
varying lowp vec4 xlv_COLOR;
varying mediump vec2 xlv_TEXCOORD0;
varying mediump vec2 xlv_TEXCOORD1;
varying mediump vec2 xlv_TEXCOORD2;
void main ()
{
  highp vec2 tmpvar_1;
  tmpvar_1 = _glesMultiTexCoord0.xy;
  lowp vec4 tmpvar_2;
  mediump vec2 tmpvar_3;
  mediump vec2 tmpvar_4;
  mediump vec2 tmpvar_5;
  highp vec4 tmpvar_6;
  tmpvar_6.w = 1.0;
  tmpvar_6.xyz = _glesVertex.xyz;
  tmpvar_3 = tmpvar_1;
  highp vec2 tmpvar_7;
  tmpvar_7.x = (_Time.y * _DistortionAnmSpeed);
  tmpvar_7.y = (_glesMultiTexCoord0.y * _DistortionFrequency);
  tmpvar_4 = tmpvar_7;
  tmpvar_5 = ((_glesMultiTexCoord0.xy * _NoiseTex_ST.xy) + _NoiseTex_ST.zw);
  highp vec3 tmpvar_8;
  tmpvar_8 = fract((sin(
    (_SinTime.w * vec3(12.9898, 78.233, 45.5432))
  ) * 43758.55));
  highp vec3 tmpvar_9;
  tmpvar_9 = fract((sin(
    (_CosTime.x * vec3(12.9898, 78.233, 45.5432))
  ) * 43758.55));
  tmpvar_5.x = (tmpvar_5.x + ((tmpvar_8.x + tmpvar_9.x) * _NoiseAnmSpeed));
  highp vec3 tmpvar_10;
  tmpvar_10 = fract((sin(
    (_SinTime.x * vec3(12.9898, 78.233, 45.5432))
  ) * 43758.55));
  highp vec3 tmpvar_11;
  tmpvar_11 = fract((sin(
    (_CosTime.w * vec3(12.9898, 78.233, 45.5432))
  ) * 43758.55));
  tmpvar_5.y = (tmpvar_5.y + ((tmpvar_10.x + tmpvar_11.x) * _NoiseAnmSpeed));
  tmpvar_2 = (_glesColor * _Color);
  gl_Position = (unity_MatrixVP * (unity_ObjectToWorld * tmpvar_6));
  xlv_COLOR = tmpvar_2;
  xlv_TEXCOORD0 = tmpvar_3;
  xlv_TEXCOORD1 = tmpvar_4;
  xlv_TEXCOORD2 = tmpvar_5;
}


#endif
#ifdef FRAGMENT
uniform mediump vec4 _BackgroundColor;
uniform mediump vec3 _AdjustColor;
uniform sampler2D _DistortionTex;
uniform mediump float _DistortionAmplitude;
uniform mediump float _ColorScatterStrength;
uniform sampler2D _NoiseTex;
uniform mediump float _NoiseStrength;
uniform sampler2D _MainTex;
varying lowp vec4 xlv_COLOR;
varying mediump vec2 xlv_TEXCOORD0;
varying mediump vec2 xlv_TEXCOORD1;
varying mediump vec2 xlv_TEXCOORD2;
void main ()
{
  lowp vec4 tmpvar_1;
  mediump vec4 color_2;
  mediump float offset_3;
  lowp float tmpvar_4;
  tmpvar_4 = (texture2D (_DistortionTex, xlv_TEXCOORD1) - 0.498).x;
  offset_3 = tmpvar_4;
  offset_3 = (offset_3 * _DistortionAmplitude);
  color_2.yz = vec2(0.0, 0.0);
  mediump vec2 tmpvar_5;
  tmpvar_5.y = 0.0;
  tmpvar_5.x = _ColorScatterStrength;
  lowp vec4 tmpvar_6;
  mediump vec2 P_7;
  P_7 = ((xlv_TEXCOORD0 + offset_3) + tmpvar_5);
  tmpvar_6 = texture2D (_MainTex, P_7);
  color_2.xw = tmpvar_6.xw;
  lowp vec4 tmpvar_8;
  mediump vec2 P_9;
  P_9 = (xlv_TEXCOORD0 + offset_3);
  tmpvar_8 = texture2D (_MainTex, P_9);
  color_2.yw = (color_2.yw + tmpvar_8.yw);
  mediump vec2 tmpvar_10;
  tmpvar_10.y = 0.0;
  tmpvar_10.x = _ColorScatterStrength;
  lowp vec4 tmpvar_11;
  mediump vec2 P_12;
  P_12 = ((xlv_TEXCOORD0 + offset_3) - tmpvar_10);
  tmpvar_11 = texture2D (_MainTex, P_12);
  color_2.zw = (color_2.zw + tmpvar_11.zw);
  color_2.xyz = (color_2.xyz * xlv_COLOR.xyz);
  color_2.w = clamp (color_2.w, 0.0, 1.0);
  mediump vec4 tmpvar_13;
  if ((color_2.w < 0.5)) {
    tmpvar_13 = _BackgroundColor;
  } else {
    tmpvar_13 = color_2;
  };
  color_2.w = tmpvar_13.w;
  color_2.xyz = (1.0 - ((1.0 - tmpvar_13.xyz) * (1.0 - _AdjustColor)));
  lowp vec4 tmpvar_14;
  tmpvar_14 = texture2D (_NoiseTex, xlv_TEXCOORD2);
  color_2.xyz = (1.0 - ((1.0 - color_2.xyz) * (1.0 - 
    (tmpvar_14 * _NoiseStrength)
  .xyz)));
  tmpvar_1 = color_2;
  gl_FragData[0] = tmpvar_1;
}

就不多说如果会shader应该会翻译上面的shader,就直接放出来,里面有一些注释方便学习

下面直接放我根据上面源码实现的unity shader

Shader "Custom/TVDistortion" 
{
	Properties 
	{
		_MainTex("Sprite Texture", 2D) = "white" { }
		_Color("Tint", Color) = (1,1,1,1)
		_BackgroundColor("Barckground Color (RGBA)", Color) = (0,0,0,1)
		_AdjustColor("Adjust Color (RGB)", Color) = (0,0,0,1)
		_DistortionTex("Distortion Tex (RG)", 2D) = "gray" { }
		_DistortionFrequency("Distortion Frequency", Float) = 1
		_DistortionAmplitude("Distortion Amplitude", Range(0, 1)) = 1
		_DistortionAnmSpeed("Distortion Animation Speed", Float) = 1
		_ColorScatterStrength("Color Scatter Strength", Range(-0.1, 0.1)) = 0.01
		_NoiseTex("Noise Tex (RGB)", 2D) = "black" { }
		_NoiseAnmSpeed("Noise Animation Speed", Float) = 1
		_NoiseStrength("Noise Strength", Float) = 1
	}

	SubShader
	{
		Pass
		{
			ZTest Always Cull Off ZWrite Off
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma target 3.0
			#pragma multi_compile_fog
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};
			struct v2f
			{
				float4 uv : TEXCOORD0;
				float4 Color : COLOR;
				float4 Distortion_UV : TEXCOORD1;
				float4 Noise_UV : TEXCOORD2;
				UNITY_FOG_COORDS(1)
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			float4 _Color;
			float4 _BackgroundColor;
			float4 _AdjustColor;
			sampler2D _DistortionTex;
			float _DistortionFrequency;
			float _DistortionAmplitude;
			float _DistortionAnmSpeed;
			float _ColorScatterStrength;
			sampler2D _NoiseTex;
			float4 _NoiseTex_ST;
			float _NoiseAnmSpeed;
			float _NoiseStrength;

		v2f vert(appdata v)
		{
			v2f o;
			o.uv.xy = v.uv.xy;
			o.vertex = UnityObjectToClipPos(v.vertex);

			float4 distortUV;
			//扭曲图UV
			distortUV.x = (_Time.y * _DistortionAnmSpeed);
			distortUV.y = (v.uv.y * _DistortionFrequency);
			o.Distortion_UV = distortUV;

			//噪音图UV
			float2 noiseUV = TRANSFORM_TEX(v.uv, _NoiseTex);
			float3 noise1 = frac((sin((_SinTime.w * float3(12.9898, 78.233, 45.5432))) * 43758.55));
			float3 noise2 = frac((sin((_CosTime.x * float3(12.9898, 78.233, 45.5432))) * 43758.55));
			noiseUV.x = (noiseUV.x + ((noise1.x + noise2.x) * _NoiseAnmSpeed));

			float3 noise3 = frac((sin((_SinTime.x * float3(12.9898, 78.233, 45.5432))) * 43758.55));
			float3 noise4 = frac((sin((_CosTime.w * float3(12.9898, 78.233, 45.5432))) * 43758.55));
			noiseUV.y = (noiseUV.y + ((noise3.x + noise4.x) * _NoiseAnmSpeed));


			o.Noise_UV = float4(noiseUV, 0, 0);
			UNITY_TRANSFER_FOG(o, o.vertex);
			return o;
		}

		half4 frag(v2f i) : SV_Target
		{
			float4 color;
			color.yz = float2(0.0, 0.0);
			//获取扭曲图的偏移位置
			half offset = (tex2D(_DistortionTex, i.Distortion_UV.xy) - 0.498).x * _DistortionAmplitude;
			//颜色偏移强度(左右)
			float2 ColorStrength = float2(_ColorScatterStrength, 0.0);
			//红色偏移
			float4 redOffset = tex2D(_MainTex, ((i.uv.xy + offset) + ColorStrength));
			color.xw = redOffset.xw;
			//绿色位置不变
			float4 greenOffset = tex2D(_MainTex, i.uv.xy + offset);
			color.yw = (color.yw + greenOffset.yw);
			//蓝色偏移
			float4 blueOffset = tex2D(_MainTex,(i.uv.xy + offset) - ColorStrength);
			color.zw = (color.zw + blueOffset.zw);

			color.w = clamp(color.w, 0.0, 1.0);
			//如果是半透则使用背景颜色
			if ((color.w < 0.5)) 
			{
				color = _BackgroundColor;
			}

			//颜色调整
			color.xyz = (1.0 - ((1.0 - color.xyz) * (1.0 - _AdjustColor)));

			//噪音图叠加
			float4 noiseColor;
			noiseColor = tex2D(_NoiseTex, i.Noise_UV.xy);
			color.xyz = (1.0 - ((1.0 - color.xyz) * (1.0 -(noiseColor * _NoiseStrength).xyz)));
			return color;
		}
			ENDCG
		}
	}
	FallBack "Diffuse"
}

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/SnoopyNa2Co3/article/details/86629436

智能推荐

Spring(五)Spring整合Hibernate-程序员宅基地

文章浏览阅读275次。Spring整合Hibernate_spring整合hibernate

Eclipse 常用快捷键及使用技巧-程序员宅基地

文章浏览阅读78次。做 java 开发的,经常会用 Eclipse 或者 MyEclise 集成开发环境,一些实用的 Eclipse 快捷键和使用技巧,可以在平常开发中节约出很多时间提高工作效率,下面我就结合自己开发中的使用和大家分享一下 Eclipse 中常用到的快捷键和技巧。15 个 Eclipse 常用开发快捷键使用技巧1、alt+?或alt+/:自动补全代码或者提示代码这个是我最得意的快捷键组..._eclipese 使用技巧大全

42 SAP报错:作业类型 ACT001 没有为成本中心 1088 1200990001 设置(Activity type ATC001 not set up for cost center XXX)_作业类型 lab 没有为成本中心 ql99 1001 设置-程序员宅基地

文章浏览阅读567次,点赞6次,收藏11次。解决方案:CO模块使用前台事务码KP26维护活动类型价格,即可。业务操作:PP模块前台事务码CR02维护活动类型时,报错如上。报错原因:CO模块没有为活动类型进行价格维护。CO模块KP26维护作业类型价格完毕。2024年1月26日 写于上海。事务码KP26进入,_作业类型 lab 没有为成本中心 ql99 1001 设置

TortoiseGit解决TortoiseGitPlink要求输入密码-程序员宅基地

文章浏览阅读3.2k次,点赞4次,收藏10次。解决TortoiseGitPlink要求输入密码_tortoisegitplink

什么是大端存储和小端存储-程序员宅基地

文章浏览阅读4.7k次,点赞2次,收藏5次。详细了解大端和小端的存储_大端存储和小端存储

【共读】企业信息安全建设与运维指南(一)_信息安全运营服务实施指南研究-程序员宅基地

文章浏览阅读6.3k次,点赞5次,收藏49次。一、从零开始建设企业信息安全系统:企业信息安全体系分为:信息安全技术体系和信息安全管理体系 信息安全技术体系: 两个层面: 1.需建设安全相关基础设施和系统,以具备解决相关安全问题的能力。 2.需具备安全运营能力,只有正确部署和使用设备,才能真正保障信息安全。 信息安全管理体系: 两个层面: 1.具备信息安全相关的制度、规范、流程及策略。 2.具..._信息安全运营服务实施指南研究

随便推点

@SuppressLint or @TargetApi_you can suppress the error with @suppresslint-程序员宅基地

文章浏览阅读788次。@TargetApi and @SuppressLint have the same core effect: they suppress the Lint error.The difference is that with @TargetApi, you declare, via the parameter, what API level you have addressed i_you can suppress the error with @suppresslint

关于Error in callback for watcher “data“: “TypeError: data.indexOf is not a function“的错误_error in callback for watcher "data": "typeerror: -程序员宅基地

文章浏览阅读2.8w次,点赞10次,收藏12次。关于Error in callback for watcher “data”: "TypeError: data.indexOf is not a function"的错误说明原因:表格显示需要数组包含对象的形式,每个对象是一行数据,拿到的数据格式不对。错误例子:从后台获取数据res.data,显示在表格中。只有一条数据,六个内容,应该是一行六列,但是出现了六行六列,且都为空。报三个..._error in callback for watcher "data": "typeerror: data.indexof is not a func

Tomcat Session(CVE-2020-9484)反序列化漏洞复现_禁止使用session持久化功能filestore-程序员宅基地

文章浏览阅读1.2k次。北京时间2020年05月20日,Apache官方发布了 Apache Tomcat 远程代码执行 的风险通告,该漏洞编号为 CVE-2020-9484。Apache Tomcat 是一个开放源代码、运行servlet和JSP Web应用软件的基于Java的Web应用软件容器。当Tomcat使用了自带session同步功能时,使用不安全的配置(没有使用EncryptInterceptor)会存在反序列化漏洞,攻击者通过精心构造的数据包, 可以对使用了自带session同步功能的Tomcat服务器进行攻击。_禁止使用session持久化功能filestore

java漏洞提权_CVE-2018-3211:Java Usage Tracker本地提权漏洞分析-程序员宅基地

文章浏览阅读170次。一、前言我们发现Java Usage Tracker中存在设计缺陷(或者脆弱点),攻击者可以利用该缺陷创建任意文件、注入攻击者指定的参数以及提升本地权限。这些攻击手段也能组合使用实现权限提升,以便访问受影响系统中其他应用或者用户不能访问的某些保护资源。我们通过Zero Day Initiative与Oracle合作修复了这个漏洞,厂商已经在10月份补丁中推出了安全更新。因此,用户以及企业应当尽快安..._java防范代码问题的提权脱库

关系型数据库(Sql)和非关系型数据库(NoSql)区别_sql关系 非关系-程序员宅基地

文章浏览阅读1.8k次。Sql与NoSql的区别Sql与NoSql的区别数据库关系型数据库非关系型数据库Sql与NoSql的区别数据库1.简单来说,就是存放各种数据的一个仓库,也就是一些数据按照某种模型存放到存储器的一个数据集合。简称DB,DataBase2.那么,数据有了,就需要管理,用来操纵和管理数据的软件就是数据管理系统 简称DBMS,DataBase Managent System3.那么 把上面这两个放到一起,也就是带有数据库并配置了管理系统的计算机系统 就是数据库系统 简称DBS,DataBase Syst_sql关系 非关系

MATLAB实现imrotate函数_imrotate函数matlab-程序员宅基地

文章浏览阅读5.1k次,点赞2次,收藏11次。编写算法实现图像绕中心点旋转功能先找到四个顶点旋转后的位置,然后求出新图像的大小找到旋转后的图像对应的原图像的位置,将原图像的颜色属性赋给相应位置的新图像(旋转思想为先将图像中心点移到坐标原点,然后进行旋转,最后再将坐标值换为实际的坐标值进行像素颜色属性的赋值)a=input('Enter the picture address:');b=input('Enter the angle:');R..._imrotate函数matlab

推荐文章

热门文章

相关标签