Question by
ciaravoh · May 15, 2020 at 09:04 AM ·
iosshader programmingdevice
Shader question for ios - not working on the device
Hello, I'm building a POC to build a terrain with a surface shader I get from a tutorial. the shader is working fine in the editor but it is not correct on the device on in the simulator. I'm lost with the configuration and I would like to understand what's wrong with this shader.
Shader "Custom/Terrain"
{
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Terrain Texture Array", 2DArray) = "white" {}
_GridTex ("Grid Texture", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Specular ("Specular", Color) = (0.2, 0.2, 0.2)
_BackgroundColor ("Background Color", Color) = (0,0,0)
[Toggle(SHOW_MAP_DATA)]_ShowMapData ("Show Map Data", Float) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf StandardSpecular vertex:vert
#pragma target 3.5
#pragma multi_compile _ GRID_ON
#pragma multi_compile _ HEX_MAP_EDIT_MODE
#pragma shader_feature SHOW_MAP_DATA
#include "../HexMetrics.cginc"
#include "../HexCellData.cginc"
UNITY_DECLARE_TEX2DARRAY(_MainTex);
sampler2D _GridTex;
half _Glossiness;
fixed3 _Specular;
fixed4 _Color;
half3 _BackgroundColor;
struct Input {
float4 color : COLOR;
float3 worldPos;
float3 terrain;
float4 visibility;
#if defined(SHOW_MAP_DATA)
float mapData;
#endif
};
void vert (inout appdata_full v, out Input data) {
UNITY_INITIALIZE_OUTPUT(Input, data);
float4 cell0 = GetCellData(v, 0);
float4 cell1 = GetCellData(v, 1);
float4 cell2 = GetCellData(v, 2);
data.terrain.x = cell0.w;
data.terrain.y = cell1.w;
data.terrain.z = cell2.w;
data.visibility.x = cell0.x;
data.visibility.y = cell1.x;
data.visibility.z = cell2.x;
data.visibility.xyz = lerp(0.25, 1, data.visibility.xyz);
data.visibility.w =
cell0.y * v.color.x + cell1.y * v.color.y + cell2.y * v.color.z;
#if defined(SHOW_MAP_DATA)
data.mapData = cell0.z * v.color.x + cell1.z * v.color.y +
cell2.z * v.color.z;
#endif
}
float4 GetTerrainColor (Input IN, int index) {
float3 uvw = float3(
IN.worldPos.xz * (2 * TILING_SCALE),
IN.terrain[index]
);
float4 c = UNITY_SAMPLE_TEX2DARRAY(_MainTex, uvw);
return c * (IN.color[index] * IN.visibility[index]);
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
fixed4 c =
GetTerrainColor(IN, 0) +
GetTerrainColor(IN, 1) +
GetTerrainColor(IN, 2);
fixed4 grid = 1;
#if defined(GRID_ON)
float2 gridUV = IN.worldPos.xz;
gridUV.x *= 1 / (4 * 8.66025404);
gridUV.y *= 1 / (2 * 15.0);
grid = tex2D(_GridTex, gridUV);
#endif
float explored = IN.visibility.w;
o.Albedo = c.rgb * grid * _Color * explored;
#if defined(SHOW_MAP_DATA)
o.Albedo = IN.mapData * grid;
#endif
o.Specular = _Specular * explored;
o.Smoothness = _Glossiness;
o.Occlusion = explored;
o.Emission = _BackgroundColor * (1 - explored);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Comment
Your answer
Follow this Question
Related Questions
How to detect iPhone X or iPad using iOS.DeviceGeneration? 1 Answer
Custom Shader IOS Build 0 Answers
Is it possible to select any iOS Device in Editor Settings 0 Answers
CG shader functions behaving oddly on iPad Pro 0 Answers
Display reflection on iOS 0 Answers