Quantcast
Channel: Questions in topic: "post processing"
Viewing all articles
Browse latest Browse all 713

Post Processing Shader does not work on android device

$
0
0
I have a post-processing shader that works perfectly fine in the editor but when I build to android and try running it on my android phone, the shader doesn't work. Why is this? I am new to writing shaders but it's a really simple shader that doesn't utilize any advanced features (to my knowledge) so why can't it be run on my android device? Shader: Shader "Post-Processing/BarrelDistortionAndBlurredEdges" { Properties { _MainTex ("Texture", 2D) = "white" {} _Distortion("Distortion", float) = 0.0 _Inverse("Inverse", float) = 1.0 _ScreenWidth("ScreenWidth", float) = 0.0 _ScreenHeight("ScreenHeihgt", float) = 0.0 _BlurStart("BlurStart", float) = 0.5 _BlurEnd("BlurEnd", float) = 0.9 _BlurColor("BlurColor", Color) = (1, 1, 1, 1) } SubShader { // No culling or depth Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.uv = v.uv; return o; } sampler2D _MainTex; float _Distortion; float _Inverse; float _BlurStart; float _BlurEnd; fixed4 _BlurColor; float _ScreenWidth; float _ScreenHeight; float2 cartesianToPolar(float2 cartesian) { return float2(sqrt(pow(cartesian.y, 2.0f) + pow(cartesian.x, 2.0f)), atan2(cartesian.y, cartesian.x)); } float2 polarToCartesian(float2 polar) { return float2(polar.x * cos(polar.y), polar.x * sin(polar.y)); } float difference(float r) { return float((-1.0f + sqrt(-4.0f * (pow(r, 2.0f) - r) + 1.0f)) / 2.0f); } float4 frag (v2f i) : SV_Target { float2 src = i.uv; if(_Distortion > 0.0f) { float2 res = i.uv; float2 resNormalized = float2(res.x * 2.0f - 1.0f, res.y * 2.0f - 1.0); float2 resPolar = cartesianToPolar(resNormalized); float2 srcPolar = float2(resPolar.x - _Inverse * cos(radians(45.0f)) * difference(resPolar.x) * _Distortion, resPolar.y); float2 srcNormalized = polarToCartesian(srcPolar); src = (srcNormalized) / 2.0f + 0.5f; } float blur = 0.0f; if(_BlurEnd > _BlurStart) { float d = length(i.uv * 2.0f - 1.0f) - _BlurStart; float blurZone = _BlurEnd - _BlurStart; blur = d / blurZone; } if(blur < 0.0f) { blur = 0.0f; } else if(blur > 1.0f) { blur = 1.0f; } return lerp(tex2D(_MainTex, src), _BlurColor, blur); } ENDCG } } } Script: using UnityEngine; using System.Collections; [ExecuteInEditMode] public class BarrelDistortionAndBlurredEdges : MonoBehaviour { public float distortion = 0.0f; public bool inverse = false; public float blurStart = 0.5f; public float blurEnd = 0.9f; public Color blurColor = Color.white; private Material material; void Awake() { material = new Material (Shader.Find("Post-Processing/BarrelDistortionAndBlurredEdges")); } void OnRenderImage(RenderTexture src, RenderTexture dest) { if (material != null) { material.SetFloat ("_Distortion", distortion); if(inverse) { material.SetFloat ("_Inverse", -1.0f); } else { material.SetFloat ("_Inverse", 1.0f); } material.SetFloat ("_BlurStart", blurStart); material.SetFloat ("_BlurEnd", blurEnd); material.SetColor ("_BlurColor", blurColor); material.SetFloat ("_ScreenWidth", Screen.width); material.SetFloat ("_ScreenHeight", Screen.height); Graphics.Blit (src, dest, material); } else { Graphics.Blit (src, dest); } } }

Viewing all articles
Browse latest Browse all 713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>