Custom Shader IOS Build
Hello Everyone,
I'm making Endless Runner with Bend Shader, Shader bends tiles, when player comes closer tiles get more straight.
I have no problem on Android build but When I build my game on IOS I don't see curve and I don't see curved part of tiles.
Here is my shader;
Shader "Custom/Bendy diffuse - Radial" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} }
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Lighting Off
CGPROGRAM
#pragma surface surf Unlit vertex:vert addshadow
#pragma multi_compile __ HORIZON_WAVES
#pragma multi_compile __ BEND_ON
// Global properties to be set by BendControllerRadial script
uniform half3 _CurveOrigin;
uniform fixed3 _ReferenceDirection;
uniform half _Curvature;
uniform fixed3 _Scale;
uniform half _FlatMargin;
uniform half _HorizonWaveFrequency;
// Per material properties
sampler2D _MainTex;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
};
half4 Bend(half4 v)
{
half4 wpos = mul (unity_ObjectToWorld, v);
half2 xzDist = (wpos.xz - _CurveOrigin.xz) / _Scale.xz;
half dist = length(xzDist);
fixed waveMultiplier = 1;
#if defined(HORIZON_WAVES)
half2 direction = lerp(_ReferenceDirection.xz, xzDist, min(dist, 1));
half theta = acos(clamp(dot(normalize(direction), _ReferenceDirection.xz), -1, 1));
waveMultiplier = cos(theta * _HorizonWaveFrequency);
#endif
dist = max(0, dist - _FlatMargin);
wpos.y -= dist * dist * _Curvature * waveMultiplier;
wpos = mul (unity_WorldToObject, wpos);
return wpos;
}
void vert (inout appdata_full v)
{
#if defined(BEND_ON)
v.vertex = Bend(v.vertex);
#endif
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten)
{
return half4(s.Albedo, s.Alpha);
}
ENDCG
}
Fallback "Legacy Shaders/Diffuse"
here is my script that I use to Bend objects
public class BendControllerRadial : MonoBehaviour {
[SerializeField] bool m_bendOn = true;
[SerializeField] Transform m_curveOrigin;
[SerializeField] Transform m_referenceDirection;
[SerializeField] float m_curvature = 0f;
[Range(0.5f, 2f)]
[SerializeField] float m_xScale = 1f;
[Range(0.5f, 2f)]
[SerializeField] float m_zScale = 1f;
[SerializeField] float m_flatMargin = 0f;
[SerializeField] bool m_horizonWaves = false;
[Range(0f, 10f)]
[SerializeField] float m_horizonWaveFrequency = 0f;
private int m_curveOriginId;
private int m_referenceDirectionId;
private int m_curvatureId;
private int m_scaleId;
private int m_flatMarginId;
private int m_horizonWaveFrequencyId;
private Vector3 m_scale = Vector3.zero;
void Start()
{
if(FindObjectOfType<BendControllerRadial>() != this)
{
Destroy(this);
}
m_curveOriginId = Shader.PropertyToID("_CurveOrigin");
m_referenceDirectionId = Shader.PropertyToID("_ReferenceDirection");
m_curvatureId = Shader.PropertyToID("_Curvature");
m_scaleId = Shader.PropertyToID("_Scale");
m_flatMarginId = Shader.PropertyToID("_FlatMargin");
m_horizonWaveFrequencyId = Shader.PropertyToID("_HorizonWaveFrequency");
m_bendOn = true;
if (m_curveOrigin == null)
SetCurveOrigin();
}
void Update()
{
m_scale.x = m_xScale;
m_scale.z = m_zScale;
if (m_horizonWaves)
Shader.EnableKeyword("HORIZON_WAVES");
else
Shader.DisableKeyword("HORIZON_WAVES");
if (m_bendOn)
Shader.EnableKeyword("BEND_ON");
else
Shader.DisableKeyword("BEND_ON");
Shader.SetGlobalVector(m_curveOriginId, m_curveOrigin.position);
Shader.SetGlobalVector(m_referenceDirectionId, m_referenceDirection.forward);
Shader.SetGlobalFloat(m_curvatureId, m_curvature * 0.00001f);
Shader.SetGlobalVector(m_scaleId, m_scale);
Shader.SetGlobalFloat(m_flatMarginId, m_flatMargin);
Shader.SetGlobalFloat(m_horizonWaveFrequencyId, m_horizonWaveFrequency);
}
private void SetCurveOrigin()
{
//m_curveOrigin = Camera.main.transform;
}
private void OnDisable()
{
Shader.SetGlobalVector(m_curveOriginId, Vector3.zero);
Shader.SetGlobalFloat(m_curvatureId, 0);
}
Your answer
Follow this Question
Related Questions
Why do dots appear on pbr materials when I use iOS Platform module?, 1 Answer
Custom Outline Shader acting weird on iOS builds. 1 Answer
Shader makes other objects transparent aswell,Shader Makes everything transparent 0 Answers
Overlap 2d image than blend color with shader 1 Answer
material.SetColor causing Hidden/InternalErrorShader 1 Answer