From 19215a353cdaae025f9475dc3654f59ff5a874c1 Mon Sep 17 00:00:00 2001 From: Sweet Tini Date: Thu, 30 Jan 2020 21:38:52 -0500 Subject: [PATCH] Fix formatting on shaders --- Assets/Shaders/Dither.shader | 138 +++++++++++++++------------- Assets/Shaders/Posterize.shader | 50 +++++----- Assets/Shaders/RetroPixelMax.shader | 64 +++++++------ 3 files changed, 136 insertions(+), 116 deletions(-) diff --git a/Assets/Shaders/Dither.shader b/Assets/Shaders/Dither.shader index 0a34c93..4da946f 100644 --- a/Assets/Shaders/Dither.shader +++ b/Assets/Shaders/Dither.shader @@ -1,106 +1,116 @@ -Shader "Oxysoft/Dither" { - Properties { - _Threshold ("Threshold", Float) = 0.45 - _Strength ("Strength", Float) = 0.45 - _Width ("Width", Int) = 0.45 - _Height ("Height", Int) = 0.45 - _Dither ("Dither", 2D) = "white" {} - _MainTex ("", 2D) = "white" {} +Shader "Oxysoft/Dither" +{ + Properties + { + _Threshold("Threshold", Float) = 0.45 + _Strength("Strength", Float) = 0.45 + _Width("Width", Int) = 0.45 + _Height("Height", Int) = 0.45 + _Dither("Dither", 2D) = "white" {} + _MainTex("", 2D) = "white" {} } - SubShader { + SubShader + { Lighting Off ZTest Always Cull Off ZWrite Off Fog { Mode Off } - Pass { - CGPROGRAM + Pass + { + CGPROGRAM // Upgrade NOTE: excluded shader from DX11, Xbox360, OpenGL ES 2.0 because it uses unsized arrays - #pragma exclude_renderers flash - #pragma vertex vert_img - #pragma fragment frag + #pragma exclude_renderers flash + #pragma vertex vert_img + #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest - #include "UnityCG.cginc" + #include "UnityCG.cginc" - uniform float _Threshold; - uniform float _Strength; - uniform int _Width; - uniform int _Height; + uniform float _Threshold; + uniform float _Strength; + uniform int _Width; + uniform int _Height; - uniform sampler2D _Dither; - uniform sampler2D _MainTex; + uniform sampler2D _Dither; + uniform sampler2D _MainTex; - float luma(fixed3 color) { + float luma(fixed3 color) + { return dot(color, fixed3(0.299, 0.587, 0.114)); } - float luma(fixed4 color) { + float luma(fixed4 color) + { return dot(color.rgb, fixed3(0.299, 0.587, 0.114)); } - fixed4 ditherBayer2(fixed2 position, float brightness) { + fixed4 ditherBayer2(fixed2 position, float brightness) + { int x = fmod(position.x, 4.0); - int y = fmod(position.y, 4.0); + int y = fmod(position.y, 4.0); - int index = x + y * 4; - float lim = 0.0; + int index = x + y * 4; + float lim = 0.0; - if (x < 8) { - if (index == 0) lim = 0.0625; - if (index == 1) lim = 0.5625; - if (index == 2) lim = 0.1875; - if (index == 3) lim = 0.6875; - if (index == 4) lim = 0.8125; - if (index == 5) lim = 0.3125; - if (index == 6) lim = 0.9375; - if (index == 7) lim = 0.4375; - if (index == 8) lim = 0.25; - if (index == 9) lim = 0.75; - if (index == 10) lim = 0.125; - if (index == 11) lim = 0.625; - if (index == 12) lim = 1.0; - if (index == 13) lim = 0.5; - if (index == 14) lim = 0.875; - if (index == 15) lim = 0.375; - } + if (x < 8) { + if (index == 0) lim = 0.0625; + if (index == 1) lim = 0.5625; + if (index == 2) lim = 0.1875; + if (index == 3) lim = 0.6875; + if (index == 4) lim = 0.8125; + if (index == 5) lim = 0.3125; + if (index == 6) lim = 0.9375; + if (index == 7) lim = 0.4375; + if (index == 8) lim = 0.25; + if (index == 9) lim = 0.75; + if (index == 10) lim = 0.125; + if (index == 11) lim = 0.625; + if (index == 12) lim = 1.0; + if (index == 13) lim = 0.5; + if (index == 14) lim = 0.875; + if (index == 15) lim = 0.375; + } - if (brightness < lim * _Strength) - return 0.0; + if (brightness < lim * _Strength) + return 0.0; - return 1.0; + return 1.0; } - fixed3 ditherPattern2(fixed2 position, float brightness) { + fixed3 ditherPattern2(fixed2 position, float brightness) + { int x = fmod(position.x, _Width); - int y = fmod(position.y, _Height); + int y = fmod(position.y, _Height); float lim = 0.0; - lim = tex2D(_Dither, fixed2(x, y) / _Width).r; + lim = tex2D(_Dither, fixed2(x, y) / _Width).r; - if (brightness < lim * _Threshold) - return _Strength; + if (brightness < lim * _Threshold) + return _Strength; - return 1.0; + return 1.0; } - fixed3 ditherBayer(fixed2 position, fixed3 col) { + fixed3 ditherBayer(fixed2 position, fixed3 col) + { return col * ditherBayer2(position, luma(col)); } - fixed3 ditherPattern(fixed2 position, fixed3 col) { - return col * ditherPattern2(position, luma(col)); - } + fixed3 ditherPattern(fixed2 position, fixed3 col) + { + return col * ditherPattern2(position, luma(col)); + } - fixed4 frag (v2f_img i) : COLOR - { - fixed3 col = tex2D (_MainTex, i.uv).rgb; + fixed4 frag(v2f_img i) : COLOR + { + fixed3 col = tex2D(_MainTex, i.uv).rgb; return fixed4(ditherPattern(i.pos.xy, col), 1.0); - } - ENDCG - } + } + ENDCG + } } FallBack "Diffuse" diff --git a/Assets/Shaders/Posterize.shader b/Assets/Shaders/Posterize.shader index 2bb240b..b6de2e1 100644 --- a/Assets/Shaders/Posterize.shader +++ b/Assets/Shaders/Posterize.shader @@ -1,44 +1,48 @@ -Shader "Oxysoft/Posterize" { - Properties { - _Red ("Red", Int) = 8 - _Green ("Green", Int) = 8 - _Blue ("Blue", Int) = 8 - _MainTex ("", 2D) = "white" {} +Shader "Oxysoft/Posterize" +{ + Properties + { + _Red("Red", Int) = 8 + _Green("Green", Int) = 8 + _Blue("Blue", Int) = 8 + _MainTex("", 2D) = "white" {} } - SubShader { + SubShader + { Lighting Off ZTest Always Cull Off ZWrite Off Fog { Mode Off } - Pass { - CGPROGRAM + Pass + { + CGPROGRAM // Upgrade NOTE: excluded shader from DX11, Xbox360, OpenGL ES 2.0 because it uses unsized arrays - #pragma exclude_renderers flash - #pragma vertex vert_img - #pragma fragment frag + #pragma exclude_renderers flash + #pragma vertex vert_img + #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest - #include "UnityCG.cginc" + #include "UnityCG.cginc" - uniform int _Red; - uniform int _Green; - uniform int _Blue; - uniform sampler2D _MainTex; + uniform int _Red; + uniform int _Green; + uniform int _Blue; + uniform sampler2D _MainTex; - fixed4 frag (v2f_img i) : COLOR - { - fixed3 col = tex2D (_MainTex, i.uv).rgb; + fixed4 frag(v2f_img i) : COLOR + { + fixed3 col = tex2D(_MainTex, i.uv).rgb; fixed4 c = fixed4(0.0, 0.0, 0.0, 1.0); c.r = floor(col.r * _Red) / _Red; c.g = floor(col.g * _Green) / _Green; c.b = floor(col.b * _Blue) / _Blue; return c; - } - ENDCG - } + } + ENDCG + } } FallBack "Diffuse" diff --git a/Assets/Shaders/RetroPixelMax.shader b/Assets/Shaders/RetroPixelMax.shader index 4c3a373..a12ea90 100644 --- a/Assets/Shaders/RetroPixelMax.shader +++ b/Assets/Shaders/RetroPixelMax.shader @@ -1,50 +1,56 @@ -Shader "Oxysoft/RetroPixelMax" { - Properties { - _ColorCount ("Color Count", Int) = 8 - _MainTex ("", 2D) = "white" {} +Shader "Oxysoft/RetroPixelMax" +{ + Properties + { + _ColorCount("Color Count", Int) = 8 + _MainTex("", 2D) = "white" {} } - SubShader { + SubShader + { Lighting Off ZTest Always Cull Off ZWrite Off Fog { Mode Off } - Pass { - CGPROGRAM + Pass + { + CGPROGRAM // Upgrade NOTE: excluded shader from DX11, Xbox360, OpenGL ES 2.0 because it uses unsized arrays - #pragma exclude_renderers flash - #pragma vertex vert_img - #pragma fragment frag + #pragma exclude_renderers flash + #pragma vertex vert_img + #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest - #include "UnityCG.cginc" + #include "UnityCG.cginc" - uniform int _ColorCount; + uniform int _ColorCount; uniform fixed4 _Colors[256]; - uniform sampler2D _MainTex; + uniform sampler2D _MainTex; - fixed4 frag (v2f_img i) : COLOR - { - fixed3 original = tex2D (_MainTex, i.uv).rgb; + fixed4 frag(v2f_img i) : COLOR + { + fixed3 original = tex2D(_MainTex, i.uv).rgb; - fixed4 col = fixed4 (0,0,0,0); - fixed dist = 10000000.0; + fixed4 col = fixed4(0,0,0,0); + fixed dist = 10000000.0; - for (int i = 0; i < _ColorCount; i++) { - fixed4 c = _Colors[i]; - fixed d = distance(original, c); + for (int i = 0; i < _ColorCount; i++) + { + fixed4 c = _Colors[i]; + fixed d = distance(original, c); - if (d < dist) { - dist = d; - col = c; - } - } + if (d < dist) + { + dist = d; + col = c; + } + } return col; - } - ENDCG - } + } + ENDCG + } } FallBack "Diffuse"