Unity信号干扰shader(参照崩坏3源码翻译剧情对话效果)

本文主要是介绍Unity信号干扰shader(参照崩坏3源码翻译剧情对话效果),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近做的项目是二次元,二次元的标杆就是崩坏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 OffZTest OffZWrite OffCull OffGpuProgramID 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 OffCGPROGRAM#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;//扭曲图UVdistortUV.x = (_Time.y * _DistortionAnmSpeed);distortUV.y = (v.uv.y * _DistortionFrequency);o.Distortion_UV = distortUV;//噪音图UVfloat2 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"
}

 

这篇关于Unity信号干扰shader(参照崩坏3源码翻译剧情对话效果)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/608659

相关文章

Java汇编源码如何查看环境搭建

《Java汇编源码如何查看环境搭建》:本文主要介绍如何在IntelliJIDEA开发环境中搭建字节码和汇编环境,以便更好地进行代码调优和JVM学习,首先,介绍了如何配置IntelliJIDEA以方... 目录一、简介二、在IDEA开发环境中搭建汇编环境2.1 在IDEA中搭建字节码查看环境2.1.1 搭建步

基于Python实现PDF动画翻页效果的阅读器

《基于Python实现PDF动画翻页效果的阅读器》在这篇博客中,我们将深入分析一个基于wxPython实现的PDF阅读器程序,该程序支持加载PDF文件并显示页面内容,同时支持页面切换动画效果,文中有详... 目录全部代码代码结构初始化 UI 界面加载 PDF 文件显示 PDF 页面页面切换动画运行效果总结主

React实现原生APP切换效果

《React实现原生APP切换效果》最近需要使用Hybrid的方式开发一个APP,交互和原生APP相似并且需要IM通信,本文给大家介绍了使用React实现原生APP切换效果,文中通过代码示例讲解的非常... 目录背景需求概览技术栈实现步骤根据 react-router-dom 文档配置好路由添加过渡动画使用

无线路由器哪个品牌好用信号强? 口碑最好的三个路由器大比拼

《无线路由器哪个品牌好用信号强?口碑最好的三个路由器大比拼》不同品牌在信号覆盖、稳定性和易用性等方面各有特色,如何在众多选择中找到最适合自己的那款无线路由器呢?今天推荐三款路由器让你的网速起飞... 今天我们来聊聊那些让网速飞起来的路由器。在这个信息爆炸的时代,一个好路由器简直就是家庭网编程络的心脏。无论你

电脑显示hdmi无信号怎么办? 电脑显示器无信号的终极解决指南

《电脑显示hdmi无信号怎么办?电脑显示器无信号的终极解决指南》HDMI无信号的问题却让人头疼不已,遇到这种情况该怎么办?针对这种情况,我们可以采取一系列步骤来逐一排查并解决问题,以下是详细的方法... 无论你是试图为笔记本电脑设置多个显示器还是使用外部显示器,都可能会弹出“无HDMI信号”错误。此消息可能

使用Python实现生命之轮Wheel of life效果

《使用Python实现生命之轮Wheeloflife效果》生命之轮Wheeloflife这一概念最初由SuccessMotivation®Institute,Inc.的创始人PaulJ.Meyer... 最近看一个生命之轮的视频,让我们珍惜时间,因为一生是有限的。使用python创建生命倒计时图表,珍惜时间

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

防近视护眼台灯什么牌子好?五款防近视效果好的护眼台灯推荐

在家里,灯具是属于离不开的家具,每个大大小小的地方都需要的照亮,所以一盏好灯是必不可少的,每个发挥着作用。而护眼台灯就起了一个保护眼睛,预防近视的作用。可以保护我们在学习,阅读的时候提供一个合适的光线环境,保护我们的眼睛。防近视护眼台灯什么牌子好?那我们怎么选择一个优秀的护眼台灯也是很重要,才能起到最大的护眼效果。下面五款防近视效果好的护眼台灯推荐: 一:六个推荐防近视效果好的护眼台灯的

Java ArrayList扩容机制 (源码解读)

结论:初始长度为10,若所需长度小于1.5倍原长度,则按照1.5倍扩容。若不够用则按照所需长度扩容。 一. 明确类内部重要变量含义         1:数组默认长度         2:这是一个共享的空数组实例,用于明确创建长度为0时的ArrayList ,比如通过 new ArrayList<>(0),ArrayList 内部的数组 elementData 会指向这个 EMPTY_EL

如何在Visual Studio中调试.NET源码

今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get