Сообщение от .Squid
B HLSL вершинный и фрагментный шейдеры определяются снаружи техники, поэтому несколько техник могут использовать одинаковые шейдеры. Тут не так, насколько я понимаю?
|
Тут можно использовать общий инклуд на уровне выше Pass, в котором определить общие функции и в каждом пасе указать нужную функцию через директивы. Возможно не один шейдер с несколькими пасами будет в результате, не вдавался в подробности. Но принцип похожий.
что-то типа:
Shader "Custom/NewShader" {
Properties {
_Color ("Text Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" { }
_MaskTex ("Mask", 2D) = "white" { }
_VericalSpeed ("Verical Speed", Range(0,10)) = 1
_HorisontalSpeed ("Horisontal Speed", Range(0,10)) = 1
_VericalPeriod ("Verical Period", Range(1,20)) = 1
_HorisontalPeriod ("Horisontal Period", Range(1,20)) = 1
_VericalAmplitude ("Verical Amplitude", Range(0,1)) = 0.5
_HorisontalAmplitude ("Horisontal Amplitude", Range(0,1)) = 0.5
}
SubShader {
Tags {
"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Lighting Off Cull Off ZWrite Off Fog { Mode Off }
CGINCLUDE
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _MaskTex;
uniform float4 _MainTex_ST;
uniform fixed4 _Color;
float _VericalSpeed;
float _HorisontalSpeed;
float _VericalPeriod;
float _HorisontalPeriod;
float _VericalAmplitude;
float _HorisontalAmplitude;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
ENDCG
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
fixed4 frag (v2f i) : COLOR
{
fixed2 uv = i.texcoord;
fixed4 mask = tex2D (_MaskTex, i.texcoord);
uv.x += (mask.r / 500) * sin(_Time.y * _HorisontalSpeed +
sin(uv.y * _HorisontalPeriod)/_HorisontalAmplitude);
uv.y += (mask.r / 500) * cos(_Time.y * _VericalSpeed +
sin(uv.x * _VericalPeriod) * _VericalAmplitude);
fixed4 c = tex2D (_MainTex, uv) * _Color;
return c;
}
ENDCG
}
Pass {
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
fixed4 frag (v2f i) : COLOR
{
fixed4 c = tex2D (_MainTex, i.texcoord) * _Color;
c.a = 0.25;
return c;
}
ENDCG
}
}
FallBack Off
}
тут #pragma vertex vert указывает на общую функцию