create hilbert worms shader
This commit is contained in:
parent
e507ae5abf
commit
d70686cd51
6 changed files with 251 additions and 50 deletions
86
Assets/test/HilbertWorms.mat
Normal file
86
Assets/test/HilbertWorms.mat
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: HilbertWorms
|
||||||
|
m_Shader: {fileID: 4800000, guid: ffd4b487556580abdbc3004e8739afd7, type: 3}
|
||||||
|
m_ValidKeywords: []
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses: []
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _EmissionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MainTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MetallicGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _OcclusionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Ints:
|
||||||
|
- _Speed: 60
|
||||||
|
m_Floats:
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 0
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0.5
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Level: 6
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _SmallLen: 32
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _Speed: 128
|
||||||
|
- _SrcBlend: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _Worms: 4
|
||||||
|
- _ZWrite: 1
|
||||||
|
m_Colors:
|
||||||
|
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
- _WormColor: {r: 1, g: 0.5, b: 1, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
8
Assets/test/HilbertWorms.mat.meta
Normal file
8
Assets/test/HilbertWorms.mat.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7ee38dc50e5510195a0e2aed30c051a9
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
107
Assets/test/HilbertWorms.shader
Normal file
107
Assets/test/HilbertWorms.shader
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
Shader "CrispyPin/HilbertWorms" {
|
||||||
|
Properties {
|
||||||
|
_Speed ("Speed (px/s)", Integer) = 100
|
||||||
|
[IntRange]_Worms ("Worms", Range(1,10)) = 1
|
||||||
|
[IntRange]_Level ("Level", Range(2,9)) = 3
|
||||||
|
[IntRange]_SmallLen ("Small length", Range(1,32)) = 8
|
||||||
|
_WormColor ("worm color", Color) = (1, 0.5, 1, 1)
|
||||||
|
}
|
||||||
|
SubShader {
|
||||||
|
Tags { "RenderType"="Opaque" }
|
||||||
|
LOD 100
|
||||||
|
Pass {
|
||||||
|
CGPROGRAM
|
||||||
|
#pragma vertex vert
|
||||||
|
#pragma fragment frag
|
||||||
|
|
||||||
|
#include "UnityCG.cginc"
|
||||||
|
|
||||||
|
#define SPEED _Speed
|
||||||
|
#define WORM_COUNT _Worms
|
||||||
|
#define LEVELS _Level
|
||||||
|
#define PIXEL_COUNT (1 << (2 * LEVELS + 2 - WORM_COUNT))
|
||||||
|
#define SMALL_LEN _SmallLen
|
||||||
|
|
||||||
|
float _Speed;
|
||||||
|
uint _Worms;
|
||||||
|
uint _Level;
|
||||||
|
uint _SmallLen;
|
||||||
|
float3 _WormColor;
|
||||||
|
|
||||||
|
struct appdata {
|
||||||
|
float4 vertex : POSITION;
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||||
|
};
|
||||||
|
|
||||||
|
struct v2f {
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
float4 vertex : SV_POSITION;
|
||||||
|
UNITY_VERTEX_OUTPUT_STEREO
|
||||||
|
};
|
||||||
|
|
||||||
|
v2f vert (appdata v) {
|
||||||
|
v2f o;
|
||||||
|
UNITY_SETUP_INSTANCE_ID(v);
|
||||||
|
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
||||||
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||||
|
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||||
|
o.uv = v.uv;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 frag (v2f i) : SV_Target {
|
||||||
|
uint pos = 0;
|
||||||
|
uint mask = 1 << (2 * LEVELS);
|
||||||
|
float2 p = i.uv * 2 - 1;
|
||||||
|
for (uint level = 0; level < LEVELS; level += 1) {
|
||||||
|
bool lower_half = false;
|
||||||
|
bool lower_quarter = false;
|
||||||
|
if (p.x < 0) {
|
||||||
|
lower_half = true;
|
||||||
|
p.x = (p.x * 2) + 1.0;
|
||||||
|
p.y *= -1;
|
||||||
|
} else {
|
||||||
|
pos |= mask;
|
||||||
|
p.x = (p.x - 0.5) * 2;
|
||||||
|
}
|
||||||
|
if (p.y < 0) {
|
||||||
|
p.y = (p.y * 2) + 1.0;
|
||||||
|
pos |= mask/2;
|
||||||
|
} else {
|
||||||
|
lower_quarter = true;
|
||||||
|
p.y = (p.y - 0.5) * 2;
|
||||||
|
}
|
||||||
|
if (lower_half && lower_quarter) {
|
||||||
|
p = float2(-p.y, p.x);
|
||||||
|
} else if (lower_half && !lower_quarter) {
|
||||||
|
p.y *= -1;
|
||||||
|
} else if (!lower_half && !lower_quarter) {
|
||||||
|
p = -p.yx;
|
||||||
|
}
|
||||||
|
mask >>= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint time = ((uint)(_Time.y * SPEED)) % PIXEL_COUNT;
|
||||||
|
uint distance = (time - pos) % PIXEL_COUNT;
|
||||||
|
if (distance < SMALL_LEN) {
|
||||||
|
float worm = 1 - ((float)distance / SMALL_LEN);
|
||||||
|
return float4(_WormColor * worm, 1);
|
||||||
|
} else {
|
||||||
|
// distance = (time/32 - pos/32) % (PIXEL_COUNT/32);
|
||||||
|
// const int tail_length = 4;
|
||||||
|
// if (distance < tail_length) {
|
||||||
|
// float tail = ((float)distance / tail_length);
|
||||||
|
// tail = 1-abs(1-tail*2);
|
||||||
|
// return float4(tail, tail/8, 0, 1);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
// if ((time - pos) % PIXEL_COUNT <= n){
|
||||||
|
// return 1 - ((float)((time - pos) % PIXEL_COUNT) / n);
|
||||||
|
// }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ENDCG
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
Assets/test/HilbertWorms.shader.meta
Normal file
10
Assets/test/HilbertWorms.shader.meta
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ffd4b487556580abdbc3004e8739afd7
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
preprocessorOverride: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -294,7 +294,7 @@ GameObject:
|
||||||
- component: {fileID: 252760296}
|
- component: {fileID: 252760296}
|
||||||
- component: {fileID: 252760295}
|
- component: {fileID: 252760295}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Fold
|
m_Name: HilbertWorms
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
|
@ -313,8 +313,8 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
type: 3
|
type: 3
|
||||||
objectId:
|
objectId: 529809e7-483f-45fb-9d21-a5a0c823ce87
|
||||||
randomNum: 82958344
|
randomNum: 94923040
|
||||||
unityVersion: 2021.3.41f1
|
unityVersion: 2021.3.41f1
|
||||||
cckVersion: 3.10:132
|
cckVersion: 3.10:132
|
||||||
--- !u!114 &252760296
|
--- !u!114 &252760296
|
||||||
|
@ -389,7 +389,7 @@ MeshRenderer:
|
||||||
m_RenderingLayerMask: 1
|
m_RenderingLayerMask: 1
|
||||||
m_RendererPriority: 0
|
m_RendererPriority: 0
|
||||||
m_Materials:
|
m_Materials:
|
||||||
- {fileID: 2100000, guid: 23bf1d7dc807b903f80e2228a8334182, type: 2}
|
- {fileID: 2100000, guid: 7ee38dc50e5510195a0e2aed30c051a9, type: 2}
|
||||||
m_StaticBatchInfo:
|
m_StaticBatchInfo:
|
||||||
firstSubMesh: 0
|
firstSubMesh: 0
|
||||||
subMeshCount: 0
|
subMeshCount: 0
|
||||||
|
@ -1828,7 +1828,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1500710831}
|
m_GameObject: {fileID: 1500710831}
|
||||||
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
|
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
|
||||||
m_LocalPosition: {x: 0, y: 1, z: 1}
|
m_LocalPosition: {x: -2, y: 0, z: 1}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
|
|
|
@ -1,51 +1,41 @@
|
||||||
Shader "CrispyPin/uninit"
|
Shader "CrispyPin/uninit" {
|
||||||
|
Properties {}
|
||||||
|
SubShader {
|
||||||
|
Tags { "RenderType"="Transparent" }
|
||||||
|
LOD 100
|
||||||
|
Pass
|
||||||
{
|
{
|
||||||
Properties
|
CGPROGRAM
|
||||||
{
|
#pragma vertex vert
|
||||||
}
|
#pragma fragment frag
|
||||||
SubShader
|
|
||||||
{
|
|
||||||
Tags { "RenderType"="Transparent" }
|
|
||||||
LOD 100
|
|
||||||
|
|
||||||
Pass
|
#include "UnityCG.cginc"
|
||||||
{
|
|
||||||
CGPROGRAM
|
|
||||||
#pragma vertex vert
|
|
||||||
#pragma fragment frag
|
|
||||||
|
|
||||||
#include "UnityCG.cginc"
|
struct appdata {
|
||||||
|
|
||||||
struct appdata
|
|
||||||
{
|
|
||||||
float4 vertex : POSITION;
|
float4 vertex : POSITION;
|
||||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
struct v2f
|
struct v2f {
|
||||||
{
|
|
||||||
float4 vertex : SV_POSITION;
|
float4 vertex : SV_POSITION;
|
||||||
UNITY_VERTEX_OUTPUT_STEREO
|
UNITY_VERTEX_OUTPUT_STEREO
|
||||||
};
|
};
|
||||||
|
|
||||||
v2f vert (appdata v)
|
v2f vert (appdata v) {
|
||||||
{
|
|
||||||
v2f o;
|
v2f o;
|
||||||
UNITY_SETUP_INSTANCE_ID(v);
|
UNITY_SETUP_INSTANCE_ID(v);
|
||||||
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
||||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||||
|
|
||||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed4 frag (v2f i) : SV_Target
|
fixed4 frag (v2f i) : SV_Target {
|
||||||
{
|
|
||||||
fixed4 col;
|
fixed4 col;
|
||||||
col.a = 0.5f;
|
col.a = 0.5f;
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
ENDCG
|
ENDCG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue