update shaders for spi support

This commit is contained in:
Crispy 2023-06-25 18:08:22 +02:00
parent e8ebac67fb
commit dce6916eb1
4 changed files with 163 additions and 142 deletions

View file

@ -23,13 +23,14 @@
{ {
float4 vertex : POSITION; float4 vertex : POSITION;
float2 uv : TEXCOORD0; float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
struct v2f struct v2f
{ {
float2 uv : TEXCOORD0; float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION; float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
}; };
sampler2D _LastFrame; sampler2D _LastFrame;
@ -38,9 +39,12 @@
v2f vert (appdata v) v2f vert (appdata v)
{ {
v2f o; v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex); o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv; o.uv = v.uv;
return o; return o;
} }

View file

@ -1,75 +1,81 @@
Shader "CrispyPin/gol" Shader "CrispyPin/gol"
{ {
Properties Properties
{ {
_LastFrame ("Texture", 2D) = "white" {} _LastFrame ("Texture", 2D) = "white" {}
} }
SubShader SubShader
{ {
Tags { "RenderType"="Opaque" } Tags { "RenderType"="Opaque" }
LOD 100 LOD 100
Pass Pass
{ {
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
struct appdata struct appdata
{ {
float4 vertex : POSITION; float4 vertex : POSITION;
float2 uv : TEXCOORD0; float2 uv : TEXCOORD0;
}; UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f struct v2f
{ {
float2 uv : TEXCOORD0; float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION; float4 vertex : SV_POSITION;
}; UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _LastFrame; sampler2D _LastFrame;
v2f vert (appdata v) v2f vert (appdata v)
{ {
v2f o; v2f o;
o.vertex = UnityObjectToClipPos(v.vertex); UNITY_SETUP_INSTANCE_ID(v);
o.uv = v.uv; UNITY_INITIALIZE_OUTPUT(v2f, o);
return o; UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
}
int state(half2 uv, half x, half y){ o.vertex = UnityObjectToClipPos(v.vertex);
return tex2D(_LastFrame, uv + half2(x, y)).r > 0; o.uv = v.uv;
} return o;
}
fixed4 frag (v2f i) : SV_Target int state(half2 uv, half x, half y){
{ return tex2D(_LastFrame, uv + half2(x, y)).r > 0;
const half d = 1.0/256.0; }
int count = state(i.uv, -d, -d)+ fixed4 frag (v2f i) : SV_Target
state(i.uv, 0, -d)+ {
state(i.uv, d, -d)+ const half d = 1.0/256.0;
state(i.uv, -d, 0)+
state(i.uv, d, 0)+
state(i.uv, -d, d)+
state(i.uv, 0, d)+
state(i.uv, d, d);
half this = tex2D(_LastFrame, i.uv).r;
half state;
if (this.r > 0){ int count = state(i.uv, -d, -d)+
state = count > 1 && count < 4; state(i.uv, 0, -d)+
// col = count > 0 && count < 6; // mazetric state(i.uv, d, -d)+
} state(i.uv, -d, 0)+
else { state(i.uv, d, 0)+
state = count == 3; state(i.uv, -d, d)+
} state(i.uv, 0, d)+
state(i.uv, d, d);
half this = tex2D(_LastFrame, i.uv).r;
half state;
float4 col = float4(i.uv * state, 0.5 * state, 1); if (this.r > 0){
return col; state = count > 1 && count < 4;
} // col = count > 0 && count < 6; // mazetric
ENDCG }
} else {
} state = count == 3;
}
float4 col = float4(i.uv * state, 0.5 * state, 1);
return col;
}
ENDCG
}
}
} }

View file

@ -1,53 +1,58 @@
Shader "Custom/UnlitWithColor" Shader "Custom/UnlitWithColor"
{ {
Properties Properties
{ {
_Color ("Color", Color) = (1,1,1,1) _Color ("Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {} _MainTex ("Texture", 2D) = "white" {}
} }
SubShader SubShader
{ {
Tags { "RenderType" = "Opaque" } Tags { "RenderType" = "Opaque" }
LOD 100 LOD 100
Pass Pass
{ {
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
struct appdata struct appdata
{ {
float4 vertex : POSITION; float4 vertex : POSITION;
float2 uv : TEXCOORD0; float2 uv : TEXCOORD0;
}; UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f struct v2f
{ {
float2 uv : TEXCOORD0; float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION; float4 vertex : SV_POSITION;
}; UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex; sampler2D _MainTex;
float4 _MainTex_ST; float4 _MainTex_ST;
fixed4 _Color; fixed4 _Color;
v2f vert (appdata v) v2f vert (appdata v)
{ {
v2f o; v2f o;
o.vertex = UnityObjectToClipPos(v.vertex); UNITY_SETUP_INSTANCE_ID(v);
o.uv = TRANSFORM_TEX(v.uv, _MainTex); UNITY_INITIALIZE_OUTPUT(v2f, o);
return o; UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
}
fixed4 frag (v2f i) : SV_Target o.vertex = UnityObjectToClipPos(v.vertex);
{ o.uv = TRANSFORM_TEX(v.uv, _MainTex);
fixed4 col = tex2D(_MainTex, i.uv); return o;
return col * _Color; }
}
ENDCG fixed4 frag (v2f i) : SV_Target
} {
} return tex2D(_MainTex, i.uv) * _Color;
}
ENDCG
}
}
} }

View file

@ -1,45 +1,51 @@
Shader "CrispyPin/uninit" Shader "CrispyPin/uninit"
{ {
Properties Properties
{ {
} }
SubShader SubShader
{ {
Tags { "RenderType"="Transparent" } Tags { "RenderType"="Transparent" }
LOD 100 LOD 100
Pass Pass
{ {
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
struct appdata struct appdata
{ {
float4 vertex : POSITION; float4 vertex : POSITION;
}; UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f struct v2f
{ {
float4 vertex : SV_POSITION; float4 vertex : SV_POSITION;
}; UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v) v2f vert (appdata v)
{ {
v2f o; v2f o;
o.vertex = UnityObjectToClipPos(v.vertex); UNITY_SETUP_INSTANCE_ID(v);
return o; UNITY_INITIALIZE_OUTPUT(v2f, o);
} UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
fixed4 frag (v2f i) : SV_Target o.vertex = UnityObjectToClipPos(v.vertex);
{ return o;
fixed4 col; }
col.a = 0.5f;
return col; fixed4 frag (v2f i) : SV_Target
} {
ENDCG fixed4 col;
} col.a = 0.5f;
} return col;
}
ENDCG
}
}
} }