Skip to content

Commit 4986085

Browse files
committed
Possible fix for ghost rendering in older devices
1 parent 5d254d1 commit 4986085

1 file changed

Lines changed: 62 additions & 42 deletions

File tree

Assets/Shaders/GhostShader.shader

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,77 @@
11
Shader "Daggerfall/GhostShader" {
2-
Properties {
2+
Properties {
33
_Color("Color", Color) = (1,1,1,1)
4-
_MainTex ("Albedo (RGB)", 2D) = "white" {}
4+
_MainTex ("Albedo (RGB)", 2D) = "white" {}
55
_BumpMap ("Bumpmap", 2D) = "bump" {}
66
_EmissionMap("Emission Map", 2D) = "white" {}
77
_EmissionColor("Emission Color", Color) = (1,1,1)
88
_Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
9-
_Glossiness ("Smoothness", Range(0.0, 1.0)) = 0.0
10-
_Metallic ("Metallic", Range(0.0, 1.0)) = 0.0
11-
}
12-
SubShader {
13-
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
14-
LOD 200
9+
_Glossiness ("Smoothness", Range(0.0, 1.0)) = 0.0
10+
_Metallic ("Metallic", Range(0.0, 1.0)) = 0.0
11+
}
1512

16-
CGPROGRAM
17-
// Physically based Standard lighting model
18-
#pragma surface surf Standard alpha:blend
19-
20-
// Use shader model 3.0 target, to get nicer looking lighting
21-
#pragma target 3.0
13+
// 1) SM3.0 / GLES3+ variant
14+
SubShader {
15+
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
16+
CGPROGRAM
17+
#pragma surface surf Standard alpha:blend
18+
#pragma target 3.0
2219

2320
half4 _Color;
24-
sampler2D _MainTex;
25-
sampler2D _BumpMap;
26-
sampler2D _EmissionMap;
21+
sampler2D _MainTex, _BumpMap, _EmissionMap;
2722
half4 _EmissionColor;
28-
29-
struct Input {
30-
float2 uv_MainTex;
23+
half _Cutoff, _Glossiness, _Metallic;
24+
25+
struct Input {
26+
float2 uv_MainTex;
3127
float2 uv_BumpMap;
3228
float2 uv_EmissionMap;
33-
};
34-
35-
half _Cutoff;
36-
half _Glossiness;
37-
half _Metallic;
38-
39-
void surf (Input IN, inout SurfaceOutputStandard o) {
40-
// Albedo comes from a texture tinted by color
41-
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
42-
clip (c.a - _Cutoff);
43-
29+
};
30+
31+
void surf (Input IN, inout SurfaceOutputStandard o) {
32+
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
33+
clip(c.a - _Cutoff);
34+
4435
half3 emission = tex2D(_EmissionMap, IN.uv_EmissionMap).rgb * _EmissionColor;
45-
o.Albedo = c.rgb - emission; // Emission cancels out other lights
46-
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
36+
o.Albedo = c.rgb - emission;
37+
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
4738
o.Emission = emission;
48-
// Metallic and smoothness come from slider variables
49-
o.Metallic = _Metallic;
50-
o.Smoothness = _Glossiness;
51-
// Transparency comes from albedo alpha - allows parts some parts of image to be transparent (e.g. body) and other parts opaque (e.g. eyes)
52-
o.Alpha = c.a;
53-
}
54-
ENDCG
55-
}
56-
FallBack "Diffuse"
39+
o.Metallic = _Metallic;
40+
o.Smoothness = _Glossiness;
41+
o.Alpha = c.a;
42+
}
43+
ENDCG
44+
}
45+
46+
// 2) SM2.0 / GLES2 fallback
47+
SubShader {
48+
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
49+
CGPROGRAM
50+
#pragma surface surf Lambert alpha:blend // use a simpler lighting model
51+
#pragma target 2.0
52+
53+
half4 _Color;
54+
sampler2D _MainTex, _BumpMap, _EmissionMap;
55+
half4 _EmissionColor;
56+
half _Cutoff;
57+
58+
struct Input {
59+
float2 uv_MainTex;
60+
float2 uv_BumpMap;
61+
float2 uv_EmissionMap;
62+
};
63+
64+
void surf (Input IN, inout SurfaceOutput o) {
65+
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
66+
clip(c.a - _Cutoff);
67+
68+
o.Albedo = c.rgb;
69+
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
70+
o.Emission = tex2D(_EmissionMap, IN.uv_EmissionMap).rgb * _EmissionColor.rgb;
71+
o.Alpha = c.a;
72+
}
73+
ENDCG
74+
}
75+
76+
FallBack "Diffuse"
5777
}

0 commit comments

Comments
 (0)