- Home /
RESETS to OpenGL by default, if scripts used to keep it Graphics Emulation = No Emulation, then there are issues while building, can't export apk to phone.
My Custom shader doesn't work in Unity OpenGL ES3.0, so quick way round was to Graphics Emulation> No Emulation. But when i build for my android it resets to OpenGL. Used many solutions as well, but they only work until I refrain builds for my android..., it builds but never gets implemented in the phone build so hence back to zero. Any way around this? Tried all possible alterations of GPU SKINNING, API Automatic etc... So i believe there must be a way to assign Graphics Emulation to No Emulation once in phone via script? The only thing that got me a step closer : Reference; *https://answers.unity.com/questions/817842/set-graphics-emulation-to-no-emulation-as-default.html?childToView=1599239#answer-1599239* Used this, it worked until i built it for android. Apparently, The UnityEditor namespace can not be used in builds, and i built it using #if UNITY EDITOR, it by passed the whole code so nothing happened in my phone built. Any ideas?
Answer by Bunny83 · Feb 07, 2019 at 06:03 PM
I think there's a major misconception of what the graphics emulation is about, so i really recommend to read the documentation. The graphics emulation is a Unity editor feature. It has no effect on build games. It's a tool to roughly restrict the editor to the same capabilities as your current selected target platform.
No matter what you set in the emulation setting, a build game always will use whatever the hardware provides. If you have a shader that uses some high level shader capabilities which simply aren't supported on your android device, there is nothing you can do to make it work. If you set the emulation to "no emulation", the Unity editor will be able to use all features that your PC and your GPU provides. However when you run your build game on the actual android device, OpenGL ES is the only thing that can be used on Android. And depending on the capabilities of your android device, this may vary heavily
Answer by Mitochondria_PC · Feb 07, 2019 at 06:40 PM
I was so confused. Thank you. So could you help me with how can i change my shader to make it work for my phone...perhaps android for now? Here's the snippet... Thanks.
Shader "Custom/SMtracks" {
Properties {
_Tess ("Tessellation", Range(1,32)) = 4
_SnowColor ("Snow Color", Color) = (1,1,1,1)
_SnowTex ("Snow (RGB)", 2D) = "white" {}
_GroundColor ("Ground Color", Color) = (1,1,1,1)
_GroundTex ("Ground (RGB)", 2D) = "white" {}
_Splat("SplatMap", 2D) = "black" {}
_Displacement ("Displacement", Range(0, 1.0)) = 0.3
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags {
"RenderType"="Opaque"
}
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:disp tessellate:tessDistance
#pragma target 4.6
#include "Tessellation.cginc"
struct appdata {
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
float _Tess;
float4 tessDistance (appdata v0, appdata v1, appdata v2) {
float minDist = 10.0;
float maxDist = 25.0;
return UnityDistanceBasedTess(v0.vertex, v1.vertex, v2.vertex, minDist, maxDist, _Tess);
}
sampler2D _Splat;
float _Displacement;
void disp (inout appdata v)
{
float d = tex2Dlod(_Splat, float4(v.texcoord.xy,0,0)).r * _Displacement;
v.vertex.xyz -= v.normal * d;
v.vertex.xyz += v.normal * _Displacement;
}
sampler2D _GroundTex;
fixed4 _GroundColor;
sampler2D _SnowTex;
fixed4 _SnowColor;
struct Input {
float2 uv_GroundTex;
float2 uv_SnowTex;
float2 uv_Splat;
};
half _Glossiness;
half _Metallic;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
half amount = tex2Dlod(_Splat, float4(IN.uv_Splat, 0, 0)).r;
fixed4 c = lerp(tex2D (_SnowTex, IN.uv_SnowTex) * _SnowColor, tex2D (_GroundTex, IN.uv_GroundTex) * _GroundColor, amount);
// fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
and another shader is used so that whenever my car passes through, its tire marks are imprinted using splat..giving an effect of a car impriniting its tires on the terrain and leaving marks of its tires.
Shader "Unlit/DrawTracks"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Coordinate("Coordinate", Vector) = ( 0, 0, 0, 0 )
_Color("Draw Color", Color) = (1, 0, 0, 0)
_Size("Size", Range(1, 500)) = 1
_Strength("Strength", Range(0, 1)) = 1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Coordinate, _Color;
half _Size, _Strength;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
// fixed4 col = tex2D(_MainTex, i.uv);
fixed4 col = tex2Dlod(_MainTex, float4(i.uv, 0, 0));
float draw = pow(saturate(1 - distance(i.uv, _Coordinate.xy)), 500/ _Size);
fixed drawcol = _Color *(draw * _Strength);
return saturate(col + drawcol);
// return col;
}
ENDCG
}
}
}
Perhaps there is some thing I'm missing in between these lines that is hindering me from using it for my phone? Thanks in advance @Bunny83 .
Your answer
Follow this Question
Related Questions
How to recover Auto Graphics API for Android back to default? 0 Answers
Using stencil buffer with OnRenderImage()/Blit 0 Answers
LWRP - Placing markers on terrain and gameobject dynamically 0 Answers
post shader: reconstruct worldspace plane coordinates 1 Answer
materials in editor look good but in run-time ineditor(android) they are pink 0 Answers