Hey Everyone,
I’m running into issues trying to get 3D Textures working on Android. Pink (error) materials are appearing on objects that are using this shader.
Below is the 3D Texture shader. This works fine in windows builds and in the editor. But not with Android.
Please let me know if you need any more information. My hunch is that Android doesn’t support 3D textures. (Unity - Manual: 3D textures) Though, I’ve tried searching for proof and cannot seem to find anything. I’m no Android / OpenGL / Shader whizz so I may be missing something simple!
Is there any reason the below shader wouldn’t work on Android?
Thanks in advance,
Harrison
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/_3DTextureTest_Trans"
{
Properties
{
_MainTex("Texture", 3D) = "white" {}
_Alpha("Alpha", Range(0, 1)) = 0.2
}
SubShader
{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float3 wpos : TEXCOORD1;
};
sampler3D _MainTex;
float4 _MainTex_ST;
float _Alpha;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.wpos = worldPos;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// sample the texture
float3 texcoord = i.wpos.xzy;
//texcoord.xy = texcoord.yx;
texcoord.z += 1.5f;
texcoord.z = texcoord.z / (3*3);
texcoord.x /= 13.6875;
texcoord.y /= 10;
texcoord.x /= 30;
texcoord.y /= 30;
fixed4 col = tex3D(_MainTex, texcoord );
if (texcoord.x > 1)
col = float4(0, 0, 0, 1);
if (texcoord.x < 0)
col = float4(0, 0, 0, 1);
if (texcoord.y > 1)
col = float4(0, 0, 0, 1);
if (texcoord.y < 0)
col = float4(0, 0, 0, 1);
col.a = _Alpha;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}