您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 newmung 于 2021-7-29 15:49 编辑
我试着修改了下
1、把fixed,fixed4改成float,float4,虽然没报错了,但不知道对不对;
2、UnityObjectToWorldNormal,UnityObjectToClipPos找到对应的方式替换了;
3、UNITY_FOG_COORDS,UNITY_APPLY_FOG_COLOR,LIGHTING_COORDS 没找到URP对应的修改,不知道怎么处理。
附上原Shader代码:
- Shader "Custom/ParticleShader"
- {
- Properties
- {
- _MainTex("Main Texture", 2D) = "white" {}
- _Color("Color", Color) = (1,1,1,1)
- [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("SrcBlend", Float) = 5
- [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("DstBlend", Float) = 1
- [Enum(UnityEngine.Rendering.CullMode)] _FaceCull("FaceCull", Float) = 2
- [Enum(Off, 0, On, 1)] _ZWrite("ZWrite", Float) = 0
- [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 2
- _OffsetFactor("OffsetFactor", float) = 0
- _Luminance("Luminance", Range(0.0, 10.0)) = 1
- _AlphaCullingBias("Alpha Culling Bias", Range(0.0, 1.0)) = 0.0
- [Toggle(_LIGHTTING_ON)] _LighttingEnable("Enable Lighting", Float) = 0
- [Toggle(_MASK_TEXTURE_ON)] _MaskTextureEnable("Enable Mask Texture", Float) = 0
- _MaskTex("Mask Texture", 2D) = "white" {}
- _MaskTexAnimSpeedU("MaskTex Animation Speed U", Range(-100.0, 100.0)) = 0
- _MaskTexAnimSpeedV("MaskTex Animation Speed V", Range(-100.0, 100.0)) = 0
- [Toggle(_FRESNEL_ON)] _FresnelEnable("Enable Fresnel", Float) = 0
- _FresnelPow("FresnelPow", Range(-10.0, 10.0)) = 1
- _FresnelIntensity("FresnelIntensity", Range(-10.0, 10.0)) = 1
- _FresnelColor("FresnelColor", Color) = (1,1,1,0)
- [Toggle(_PARTICLE_DISSOLUTION_RANGE_ON)] _ParticleDissolutionRangeEnable("Enable Particle Dissolution Range", Float) = 0
- _DissolutionTex("Dissolution Texture(R,A)", 2D) = "white" {}
- _DissolutionRange("Dissolution Range", Range(0.0, 1.1)) = 0.5
- [Toggle(_DISSOLUTION_EDGE_ON)] _DissolutionEdgeEnable("Enable Dissolution Edge", Float) = 0
- _DissolutionEdgeWidth("Dissolution Edge Width", Range(0.0, 1.0)) = 0.1
- _DissolutionEdgeColor("Dissolution Edge Color", Color) = (1,1,1,1)
- _DissolutionEdgeIntensity("Dissolution Edge Intensity", Range(0.0, 10.0)) = 1
- [Toggle(_INTERFERENCE_ON)] _InterferenceEnable("Enable Interference", Float) = 0
- _InterferenceTex("Interference Texture(R,G)", 2D) = "gray" {}
- _InterferenceIntensity("Interference Intensity", Range(0.0, 3.0)) = 1
- _InterferenceAnimSpeedU("Interference Animation Speed U", Range(-100.0, 100.0)) = 0
- _InterferenceAnimSpeedV("Interference Animation Speed V", Range(-100.0, 100.0)) = 0
- _UVAnimSpeedU("UV Animation Speed U", Range(-100.0, 100.0)) = 0
- _UVAnimSpeedV("UV Animation Speed V", Range(-100.0, 100.0)) = 0
- [Toggle(_TEXTURE_SHEET_ANIM_ON)] _TextureSheetAnimEnable("Enable Texture Sheet Animation", Float) = 0
- [Toggle(_TEXTURE_SHEET_ANIM_BLEND_ON)] _TextureSheetAnimBlendEnable("Enable Texture Sheet Animation Blend", Float) = 0
- _AnimTilingX("Animation Tiling X", float) = 1
- _AnimTilingY("Animation Tiling Y", float) = 1
- _AnimFrameCount("Animation Frame Count", float) = 1
- _AnimStartFrame("Animation Start Frame", float) = 0
- _AnimFrameTime("Animation Frame Time", float) = 2
- [Toggle(_PARTICLE_UV_ANIM_ON)] _ParticleUVAnimEnable("Enable Particle UV Animation(TEXCOORD1.xy)", Float) = 0
- [Toggle(_PARTICLE_ANIM_RANDOM_ON)] _ParticleAnimRandomEnable("Enable Particle Animation Random(TEXCOORD1.w)", Float) = 0
- }
- Category
- {
- Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" }
- Blend[_SrcBlend][_DstBlend]
- ColorMask RGB
- Cull [_FaceCull]
- Lighting Off
- ZWrite [_ZWrite]
- ZTest[_ZTest]
- Offset [_OffsetFactor], 0
- SubShader
- {
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile_fog
- #pragma multi_compile_instancing
- #pragma shader_feature _LIGHTTING_ON
- #pragma shader_feature _MASK_TEXTURE_ON
- #pragma shader_feature _FRESNEL_ON
- #pragma shader_feature _PARTICLE_DISSOLUTION_RANGE_ON
- #pragma shader_feature _DISSOLUTION_EDGE_ON
- #pragma shader_feature _INTERFERENCE_ON
- #pragma shader_feature _TEXTURE_SHEET_ANIM_ON
- #pragma shader_feature _TEXTURE_SHEET_ANIM_BLEND_ON
- #pragma shader_feature _PARTICLE_UV_ANIM_ON
- #pragma shader_feature _PARTICLE_ANIM_RANDOM_ON
- #define _PARTICLE_Clip 0
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- #include "UnityStandardParticleInstancing.cginc"
- sampler2D _MainTex;
- half4 _Color;
- sampler2D _MaskTex;
- half _MaskTexAnimSpeedU;
- half _MaskTexAnimSpeedV;
- half _AlphaCullingBias;
- fixed _Luminance;
- half _EnvirmentLuminance;
- half _FresnelPow;
- half _FresnelIntensity;
- half4 _FresnelColor;
- sampler2D _DissolutionTex;
- half _DissolutionRange;
- half _DissolutionEdgeWidth;
- half4 _DissolutionEdgeColor;
- half _DissolutionEdgeIntensity;
- sampler2D _InterferenceTex;
- half _InterferenceIntensity;
- half _InterferenceAnimSpeedU;
- half _InterferenceAnimSpeedV;
- half _UVAnimSpeedU;
- half _UVAnimSpeedV;
- half _AnimTilingX;
- half _AnimTilingY;
- half _AnimFrameCount;
- half _AnimStartFrame;
- half _AnimFrameTime;
- fixed _PaticleClip;
- struct appdata_t
- {
- float4 vertex : POSITION;
- fixed4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- #if defined(_PARTICLE_ANIM_RANDOM_ON) || defined(_PARTICLE_UV_ANIM_ON) || defined(_DISSOLUTION_EDGE_ON)
- float4 particleInfo : TEXCOORD1;
- #endif
- UNITY_VERTEX_INPUT_INSTANCE_ID
- #if defined(_FRESNEL_ON) || defined(_LIGHTTING_ON)
- half3 normal : NORMAL;
- #endif
- #ifdef _LIGHTTING_ON
- LIGHTING_COORDS(2,3)
- #endif
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- fixed4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- #ifdef _INTERFERENCE_ON
- float2 InterferenceTexcoord : TEXCOORD1;
- #endif
- UNITY_FOG_COORDS(2)
- UNITY_VERTEX_INPUT_INSTANCE_ID
- UNITY_VERTEX_OUTPUT_STEREO
- #if defined(_FRESNEL_ON) || defined(_LIGHTTING_ON)
- half3 normalWorld : NORMAL;
- #endif
- #ifdef _FRESNEL_ON
- half3 viewDirWorld : TEXCOORD3;
- #endif
- #ifdef _TEXTURE_SHEET_ANIM_ON
- half4 tiledAnimCoord : TEXCOORD4;
- #endif
- #ifdef _MASK_TEXTURE_ON
- half2 maskTexcoord : TEXCOORD5;
- #endif
- #ifdef _DISSOLUTION_EDGE_ON
- half3 dissolutionTexcoord : TEXCOORD6;
- #endif
- float4 worldPosition : TEXCOORD7;
- };
- float4 _MainTex_ST;
- float4 _InterferenceTex_ST;
- float4 _MaskTex_ST;
- float4 _DissolutionTex_ST;
- float4 _ClipRect;
- #ifdef _LIGHTTING_ON
- uniform float4 _LightColor0;
- #endif
- inline float SoftUnityGet2DClipping (in float2 position, in float4 clipRect)
- {
- float _ClipSoftX = 0.001;
- float _ClipSoftY = 0.001;
- float2 xy = (position.xy-clipRect.xy)/float2(_ClipSoftX,_ClipSoftY)*step(clipRect.xy, position.xy);
- float2 zw = (clipRect.zw-position.xy)/float2(_ClipSoftX,_ClipSoftY)*step(position.xy,clipRect.zw);
- float2 factor = clamp(0, zw, xy);
- return saturate(min(factor.x,factor.y));
- }
- v2f vert(appdata_t v)
- {
- v2f o;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.worldPosition = 0;
- if(_PaticleClip > _PARTICLE_Clip)
- {
- o.worldPosition = mul(unity_ObjectToWorld,v.vertex);
- }
- o.color = v.color * _Color;
- o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
- #ifdef _DISSOLUTION_EDGE_ON
- o.dissolutionTexcoord = float3(TRANSFORM_TEX(v.texcoord, _DissolutionTex), v.particleInfo.z);
- #endif
- #ifdef _MASK_TEXTURE_ON
- o.maskTexcoord = TRANSFORM_TEX(v.texcoord, _MaskTex);
- #endif
- #ifdef _INTERFERENCE_ON
- o.InterferenceTexcoord = TRANSFORM_TEX(v.texcoord, _InterferenceTex);
- #endif
- #ifdef _TEXTURE_SHEET_ANIM_ON
- half tileCount = _AnimTilingX * _AnimTilingY;
- half startFrame = _AnimStartFrame;
- #ifdef _PARTICLE_ANIM_RANDOM_ON
- startFrame += floor(v.particleInfo.w * _AnimFrameCount);
- #endif
- half texIndex = fmod(floor(_Time.y / _AnimFrameTime + startFrame), _AnimFrameCount);
- o.tiledAnimCoord.x = (o.texcoord.x + fmod(texIndex, _AnimTilingX)) / _AnimTilingX;
- o.tiledAnimCoord.y = (o.texcoord.y + floor(_AnimTilingY - (texIndex + 0.01) / _AnimTilingX)) / _AnimTilingY;
- #ifdef _TEXTURE_SHEET_ANIM_BLEND_ON
- half texIndexBlend = fmod(texIndex + 1.0, _AnimFrameCount);
- half2 texUVBlend;
- o.tiledAnimCoord.z = (o.texcoord.x + fmod(texIndexBlend, _AnimTilingX)) / _AnimTilingX;
- o.tiledAnimCoord.w = (o.texcoord.y + floor(_AnimTilingY - (texIndexBlend + 0.01) / _AnimTilingX)) / _AnimTilingY;
- #endif
- #endif
- #ifdef _PARTICLE_UV_ANIM_ON
- half2 particleUVAnimOffset = half2(v.particleInfo.xy);
- #ifdef _TEXTURE_SHEET_ANIM_ON
- o.tiledAnimCoord.xy -= particleUVAnimOffset;
- #ifdef _TEXTURE_SHEET_ANIM_ON
- #ifdef _TEXTURE_SHEET_ANIM_BLEND_ON
- o.tiledAnimCoord.zw -= particleUVAnimOffset;
- #endif
- #endif
- #else
- o.texcoord.xy -= particleUVAnimOffset;
- #endif
- #endif
-
- if(_UVAnimSpeedU != 0 || _UVAnimSpeedV != 0)
- {
- half2 uvAnimOffset = half2(_UVAnimSpeedU, _UVAnimSpeedV) * _Time.x;
- #ifdef _TEXTURE_SHEET_ANIM_ON
- o.tiledAnimCoord.xy -= uvAnimOffset;
- #ifdef _TEXTURE_SHEET_ANIM_ON
- #ifdef _TEXTURE_SHEET_ANIM_BLEND_ON
- o.tiledAnimCoord.zw -= uvAnimOffset;
- #endif
- #endif
- #else
- o.texcoord.xy -= uvAnimOffset;
- #endif
- }
- UNITY_TRANSFER_FOG(o,o.vertex);
- #if defined(_FRESNEL_ON) || defined(_LIGHTTING_ON)
- o.normalWorld = UnityObjectToWorldNormal(v.normal);
- #endif
- #ifdef _FRESNEL_ON
- float4 posWorld = mul(unity_ObjectToWorld, v.vertex);
- o.viewDirWorld = normalize(posWorld.xyz - _WorldSpaceCameraPos);
- #endif
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- UNITY_SETUP_INSTANCE_ID(i);
- #ifdef _DISSOLUTION_EDGE_ON
- half2 dissolutionTex = tex2D(_DissolutionTex, i.dissolutionTexcoord.xy).ra;
- half dissolution = dissolutionTex.x * dissolutionTex.y;// *i.dissolutionTexcoord.z;
- #ifdef _PARTICLE_DISSOLUTION_RANGE_ON
- half dissolutionRange = i.dissolutionTexcoord.z;
- #else
- half dissolutionRange = _DissolutionRange;
- #endif
- if (dissolution < dissolutionRange)
- {
- discard;
- }
- #endif
- #ifdef _TEXTURE_SHEET_ANIM_ON
- half2 texUV = i.tiledAnimCoord.xy;
- #ifdef _TEXTURE_SHEET_ANIM_BLEND_ON
- half2 texUVBlend = i.tiledAnimCoord.zw;
- #endif
- #else
- half2 texUV = i.texcoord;
- #endif
- #ifdef _INTERFERENCE_ON
- half2 interferenceUV = i.InterferenceTexcoord;
- if(_InterferenceAnimSpeedU != 0 || _InterferenceAnimSpeedV != 0)
- {
- interferenceUV -= half2(_InterferenceAnimSpeedU, _InterferenceAnimSpeedV) * _Time.x;
- }
- half2 interference = (tex2D(_InterferenceTex, interferenceUV).rg - 0.5) * 2 * _InterferenceIntensity;
- texUV += interference;
- #ifdef _TEXTURE_SHEET_ANIM_ON
- #ifdef _TEXTURE_SHEET_ANIM_BLEND_ON
- texUVBlend += interference;
- #endif
- #endif
- #endif
- fixed4 col = tex2D(_MainTex, texUV);
- #ifdef _TEXTURE_SHEET_ANIM_ON
- #ifdef _TEXTURE_SHEET_ANIM_BLEND_ON
- fixed4 colBlend = tex2D(_MainTex, texUVBlend);
- half blendFactor = fmod(_Time.y, _AnimFrameTime) / _AnimFrameTime;
- //return blendFactor;
- col = col * (1.0 - blendFactor) + colBlend * blendFactor;
- //return col;
- #endif
- #endif
- col *= i.color;
- col.rgb *= _Luminance;
- #ifdef _LIGHTTING_ON
- float3 normalDirection = normalize(i.normalWorld);
- float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
- float3 lightColor = _LightColor0.rgb;
- float attenuation = LIGHT_ATTENUATION(i);
- float3 attenColor = attenuation * _LightColor0.xyz;
- float NdotL = max(0.0,dot( normalDirection, lightDirection ));
- float3 directDiffuse = max( 0.0, NdotL) * attenColor;
- float3 diffuseColor = col.rgb;
- diffuseColor *= directDiffuse + UNITY_LIGHTMODEL_AMBIENT.rgb;
- col.rgb = diffuseColor;
- #else
- col.rgb *= _EnvirmentLuminance;
- #endif
- #ifdef _MASK_TEXTURE_ON
- half2 maskUv = i.maskTexcoord;
- if(_MaskTexAnimSpeedU != 0 || _MaskTexAnimSpeedV != 0)
- {
- maskUv -= half2(_MaskTexAnimSpeedU, _MaskTexAnimSpeedV) * _Time.x;
- }
- col *= tex2D(_MaskTex, maskUv);
- #endif
- if(_AlphaCullingBias > 0)
- {
- if (col.a < _AlphaCullingBias)
- {
- discard;
- }
- }
- #ifdef _FRESNEL_ON
- float fresnel = 1 - abs(dot(normalize(i.viewDirWorld), normalize(i.normalWorld)));
- fresnel = pow(fresnel, _FresnelPow) * _FresnelIntensity;
- col.rgb += fresnel * _FresnelColor.rgb;
- col.a = col.a * (1 - _FresnelColor.a) + col.a * fresnel * _FresnelColor.a;
- #endif
- #ifdef _DISSOLUTION_EDGE_ON
- half s1 = step(dissolution, dissolutionRange);
- half s2 = step(dissolution, dissolutionRange + _DissolutionEdgeWidth);
- half3 dissolutionEdge = (s2 - s1) * _DissolutionEdgeColor * _DissolutionEdgeIntensity;
- col.rgb = col.rgb * (0.5 + dissolutionEdge) + dissolutionEdge * 0.5;
- #endif
-
- if(_PaticleClip > _PARTICLE_Clip)
- {
- col.a*= SoftUnityGet2DClipping(i.worldPosition.xy, _ClipRect);
- }
- UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0, 0, 0, 0)); // fog towards black due to our blend mode
-
- return col;
- }
- ENDCG
- }
- }
- }
- }
点击此处复制文本
|