边缘
This commit is contained in:
@@ -7,8 +7,8 @@ Material:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: DotLine
|
||||
m_Shader: {fileID: 10101, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_Name: CutLineMaterial
|
||||
m_Shader: {fileID: 4800000, guid: 131cdecbc3d0ba246ade9a5536a9ef8d, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
@@ -39,21 +39,33 @@ Material:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SecondaryTex:
|
||||
m_Texture: {fileID: 2800000, guid: d01c0cb5c0aef2748882aee25f266429, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _texcoord:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _BlurSize: 1
|
||||
- _Cutoff: 0.5
|
||||
- _EnableExternalAlpha: 0
|
||||
- _InvFade: 0.01
|
||||
- _LengthScale: 2.6
|
||||
- _Number: 41.2
|
||||
- _RangeCount: 1
|
||||
- _Speed: 55
|
||||
- _SwitchEnd: 0.716
|
||||
- _SwitchStart: 0.419
|
||||
- _TextureScale: 1
|
||||
- _TotalLength: 2.6
|
||||
- __dirty: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Ranges: {r: 0.05, g: 0.2, b: 0.43, a: 0.63}
|
||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _TintColor: {r: 1, g: 0, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,103 @@
|
||||
Shader "Custom/CutLine"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Primary Texture", 2D) = "white" {}
|
||||
_SecondaryTex ("Secondary Texture", 2D) = "white" {}
|
||||
_TextureScale ("Texture Scale", Float) = 1.0
|
||||
_Color ("Tint Color", Color) = (1,1,1,1)
|
||||
_TotalLength ("Total Length", Float) = 1.0
|
||||
_Ranges ("Ranges", Vector) = (0,0,0,0) // 用于传递范围数据
|
||||
_RangeCount("Range Count", Int) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType"="Transparent"
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"PreviewType"="Plane"
|
||||
}
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile_instancing
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
// 定义最大支持的范围对数
|
||||
#define MAX_RANGE_PAIRS 4 // 最多4对范围(8个值)
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float positionRatio : TEXCOORD1;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _SecondaryTex;
|
||||
float _TextureScale;
|
||||
float _TotalLength;
|
||||
fixed4 _Color;
|
||||
|
||||
// 使用数组存储范围数据
|
||||
float4 _Ranges[MAX_RANGE_PAIRS]; // 每个float4存储2对范围(start1,end1,start2,end2)
|
||||
int _RangeCount; // 实际范围对数
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.positionRatio = v.uv.x * _TextureScale / _TotalLength;
|
||||
o.uv = float2(v.uv.x * _TextureScale, v.uv.y);
|
||||
return o;
|
||||
}
|
||||
|
||||
bool is_in_ranges(const float pos)
|
||||
{
|
||||
const float normalized_pos = frac(pos);
|
||||
bool result = false;
|
||||
|
||||
// 遍历所有范围对
|
||||
[loop]
|
||||
for (int i = 0; i < _RangeCount; i++)
|
||||
{
|
||||
// 使用step函数代替分支
|
||||
float4 range = _Ranges[i];
|
||||
const float in_range1 = step(range.x, normalized_pos) * step(normalized_pos, range.y);
|
||||
const float in_range2 = step(range.z, normalized_pos) * step(normalized_pos, range.w);
|
||||
result = result || in_range2 + in_range1 > 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
const bool in_range = is_in_ranges(i.positionRatio);
|
||||
const fixed4 col = in_range ? tex2D(_SecondaryTex, i.uv) : tex2D(_MainTex, i.uv);
|
||||
return col * _Color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 131cdecbc3d0ba246ade9a5536a9ef8d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures:
|
||||
- _MainTex: {instanceID: 0}
|
||||
- _SecondaryTex: {instanceID: 0}
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user