From dce6916eb18d596cb1b6677350101908efffa3d1 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sun, 25 Jun 2023 18:08:22 +0200 Subject: [PATCH] update shaders for spi support --- Assets/automata/WireWorld/wireworld.shader | 8 +- Assets/automata/gol.shader | 128 +++++++++++---------- Assets/pen/UnlitWithColor.shader | 91 ++++++++------- Assets/test/uninit.shader | 78 +++++++------ 4 files changed, 163 insertions(+), 142 deletions(-) diff --git a/Assets/automata/WireWorld/wireworld.shader b/Assets/automata/WireWorld/wireworld.shader index 7141105..e1d165f 100644 --- a/Assets/automata/WireWorld/wireworld.shader +++ b/Assets/automata/WireWorld/wireworld.shader @@ -23,13 +23,14 @@ { float4 vertex : POSITION; float2 uv : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float2 uv : TEXCOORD0; - float4 vertex : SV_POSITION; + UNITY_VERTEX_OUTPUT_STEREO }; sampler2D _LastFrame; @@ -38,9 +39,12 @@ 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; } diff --git a/Assets/automata/gol.shader b/Assets/automata/gol.shader index 15ffdf0..63650a9 100644 --- a/Assets/automata/gol.shader +++ b/Assets/automata/gol.shader @@ -1,75 +1,81 @@ Shader "CrispyPin/gol" { - Properties - { - _LastFrame ("Texture", 2D) = "white" {} - } - SubShader - { - Tags { "RenderType"="Opaque" } - LOD 100 + Properties + { + _LastFrame ("Texture", 2D) = "white" {} + } + SubShader + { + Tags { "RenderType"="Opaque" } + LOD 100 - Pass - { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag - #include "UnityCG.cginc" + #include "UnityCG.cginc" - struct appdata - { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - }; + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; - struct v2f - { - float2 uv : TEXCOORD0; - float4 vertex : SV_POSITION; - }; + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + UNITY_VERTEX_OUTPUT_STEREO + }; - sampler2D _LastFrame; + sampler2D _LastFrame; - v2f vert (appdata v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.uv = v.uv; - return o; - } + v2f vert (appdata v) + { + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - int state(half2 uv, half x, half y){ - return tex2D(_LastFrame, uv + half2(x, y)).r > 0; - } + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + return o; + } - fixed4 frag (v2f i) : SV_Target - { - const half d = 1.0/256.0; + int state(half2 uv, half x, half y){ + return tex2D(_LastFrame, uv + half2(x, y)).r > 0; + } - int count = state(i.uv, -d, -d)+ - state(i.uv, 0, -d)+ - state(i.uv, d, -d)+ - 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; + fixed4 frag (v2f i) : SV_Target + { + const half d = 1.0/256.0; - if (this.r > 0){ - state = count > 1 && count < 4; - // col = count > 0 && count < 6; // mazetric - } - else { - state = count == 3; - } + int count = state(i.uv, -d, -d)+ + state(i.uv, 0, -d)+ + state(i.uv, d, -d)+ + 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; - float4 col = float4(i.uv * state, 0.5 * state, 1); - return col; - } - ENDCG - } - } + if (this.r > 0){ + state = count > 1 && count < 4; + // col = count > 0 && count < 6; // mazetric + } + else { + state = count == 3; + } + + float4 col = float4(i.uv * state, 0.5 * state, 1); + return col; + } + ENDCG + } + } } diff --git a/Assets/pen/UnlitWithColor.shader b/Assets/pen/UnlitWithColor.shader index e4d2c3d..b34d0d5 100644 --- a/Assets/pen/UnlitWithColor.shader +++ b/Assets/pen/UnlitWithColor.shader @@ -1,53 +1,58 @@ Shader "Custom/UnlitWithColor" { - Properties - { - _Color ("Color", Color) = (1,1,1,1) - _MainTex ("Texture", 2D) = "white" {} - } - SubShader - { - Tags { "RenderType" = "Opaque" } - LOD 100 + Properties + { + _Color ("Color", Color) = (1,1,1,1) + _MainTex ("Texture", 2D) = "white" {} + } + SubShader + { + Tags { "RenderType" = "Opaque" } + LOD 100 - Pass - { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag - #include "UnityCG.cginc" + #include "UnityCG.cginc" - struct appdata - { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - }; + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; - struct v2f - { - float2 uv : TEXCOORD0; - float4 vertex : SV_POSITION; - }; + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + UNITY_VERTEX_OUTPUT_STEREO + }; - sampler2D _MainTex; - float4 _MainTex_ST; - fixed4 _Color; + sampler2D _MainTex; + float4 _MainTex_ST; + fixed4 _Color; - v2f vert (appdata v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.uv, _MainTex); - return o; - } + v2f vert (appdata v) + { + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - fixed4 frag (v2f i) : SV_Target - { - fixed4 col = tex2D(_MainTex, i.uv); - return col * _Color; - } - ENDCG - } - } + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + return tex2D(_MainTex, i.uv) * _Color; + } + ENDCG + } + } } diff --git a/Assets/test/uninit.shader b/Assets/test/uninit.shader index 6ea9393..33e783f 100644 --- a/Assets/test/uninit.shader +++ b/Assets/test/uninit.shader @@ -1,45 +1,51 @@ Shader "CrispyPin/uninit" { - Properties - { - } - SubShader - { - Tags { "RenderType"="Transparent" } - LOD 100 + Properties + { + } + SubShader + { + Tags { "RenderType"="Transparent" } + LOD 100 - Pass - { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag - #include "UnityCG.cginc" + #include "UnityCG.cginc" - struct appdata - { - float4 vertex : POSITION; - }; + struct appdata + { + float4 vertex : POSITION; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; - struct v2f - { - float4 vertex : SV_POSITION; - }; + struct v2f + { + float4 vertex : SV_POSITION; + UNITY_VERTEX_OUTPUT_STEREO + }; - v2f vert (appdata v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - return o; - } + v2f vert (appdata v) + { + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_OUTPUT(v2f, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - fixed4 frag (v2f i) : SV_Target - { - fixed4 col; - col.a = 0.5f; - return col; - } - ENDCG - } - } + o.vertex = UnityObjectToClipPos(v.vertex); + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + fixed4 col; + col.a = 0.5f; + return col; + } + ENDCG + } + } }