0
Not a bug

Microsoft Windows Phone 8

Luca Eberhart 10 years ago updated by Freya Holmér (Developer) 9 years ago 15
Hi,
on a Nokia Lumia 1520 my shaders are black.
There is a way to make a working shader on Microsoft Windows Phone 8?

Answer

Answer
Not a bug
I don't think that's possible in that case, I'm guessing the shader is simply too complex for the platform in question.

So, in general, the closest you can get, is to enable d3d11_9x and enable SM2.0 in the experimental settings.
Under review
No idea what could be wrong. Try it with super cheap shaders (Color into emission), and see if there are errors in any log somewhere
Here is a simple material that becomes black on Nokia Lumia 1520.
If you have any hint on different shader settings I can do further testing.

Does it work when you check OpenGL ES?
Do simple colors work?
Unfortunately it doesn't work.
Not even a vector 3 into emission
Still black and I do not detect any error in the Visual Studio log.
Probably you've already read this document.

Graphics Issues
All Windows Phone 8 devices have GPUs that support feature level 9_3 of Microsoft Direct3D 11.
Here are a few of the issues you might run into if you bring your own shaders:
Semantics are required on all variables passed between shader stages.
The example below will create an error:
struct vertOut {
float4 pos:SV_POSITION;
float4 scrPos; //ERROR! no semantic
};
The fix is easy:
struct vertOut {
float4 pos:SV_POSITION;
float4 scrPos: TEXCOORD0; // <-- FIX! add semantic.
};
The convention is to use TEXCOORD[n] for a general purpose semantic, so that is a good choice if
none has been assigned.
Fog is not implemented.
You may need to implement it manually. Unity has shared a sample shader for fog at
http://files.unity3d.com/tomas/Metro/Examples/MyCu...
There is also a sample Unity package within the Sample Unity Project code base here
/UnityPorting/blob/master/Resources/ShaderIssueExamples.unitypackage that reproes a few of the
issues you might run into in Windows and Phone. In the package, you will find:
 MissingSemanticShader.shader demonstrates the missing semantics issue. You may need to
build and run from VisualStudio to see this issue. The shader code is commented to
demonstrate the fix.
 MyCustomFogLinear.shader and MyCustomFogExp2.shader demonstrate two
implementations of fog in shader code. They are hardcoded to Linear and Exp2 fog
respectively.
I'm pretty sure I'm using semantics on all variables passed through though, strange
I think the problem is similar to the one explained in this post by Jason.

http://shaderforge.userecho.com/topic/390943-shade...
Hello Joachim, I have been testing the shaders Luca made on my Lumia.
Winodws Phone 8 uses DirectX 11 9.3 with shader model 3. I noticed that the shader generated by Shader Forge excludes it from the list of targets by using #pragma exclude_renderers xbox360 ps3 flash d3d11_9x. I guess this means that the shader is not even compiled into d3d11. As soon as I removed d3d11_9x from the #pragma unity  posted this warning "Shader warning in 'Shader Forge/Terrain': Program 'frag', error X4506: ps_4_0_level_9_1 input limit (8) exceeded, shader uses 9 inputs. (compiling for d3d11_9x) at line 23". Which I guess was the reason why d3d11 was left out. I guess that since the shader is excluded from compilation (and even if it was compiled it would fail) unity defaults to the black material. This is confirmed by Jason's post in the thread Luca posted "Often, when a shader fails on a platform, it will fail silently and just draw black". Do you believe I may be right (I'm a shaders noob :)) ? If yes, can a solution be found to fix this ?
Removing d3d11_9x should have the same effect as checking DX11 for windows RT in the shader render settings, although people are still having issues with it.

If it has 9 inputs, I would presume it has too many interpolators, which could mean the shader you tested was simply too expensive.

Heavily appreciate the writeups here anyhow - I'm unable to test any of this myself
I tried running this shader that only sets emissive to green  :

// Shader created with Shader Forge Beta 0.34
// Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:0.34;sub:START;pass:START;ps:flbk:,lico:0,lgpr:1,nrmq:1,limd:0,uamb:True,mssp:True,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:1,x:32719,y:32712|emission-18-OUT;n:type:ShaderForge.SFN_Vector3,id:18,x:32999,y:32812,v1:0,v2:1,v3:0;pass:END;sub:END;*/
Shader "Shader Forge/MobileTest" {
Properties {
}
SubShader {
Tags {
"RenderType"="Opaque"
}
Pass {
Name "ForwardBase"
Tags {
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma exclude_renderers gles xbox360 ps3 flash
#pragma target 3.0
struct VertexInput {
float4 vertex : POSITION;
};
struct VertexOutput {
float4 pos : SV_POSITION;
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
////// Lighting:
////// Emissive:
float3 emissive = float3(0,1,0);
float3 finalColor = emissive;
/// Final Color:
return fixed4(finalColor,1);
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}

in a scene with only a cube, this is the result :


If I use the standard Diffuse shader everything works.
The weird thing is that if I look at the compiled shader every SubProgram tagged with "d3d11" (wich I assume is the windows phone target) looks more or less like this :

SubProgram "d3d11 " {
Keywords { "DIRECTIONAL" "LIGHTMAP_ON" "DIRLIGHTMAP_ON" "SHADOWS_OFF" }
Bind "vertex" Vertex
ConstBuffer "UnityPerDraw" 336 // 64 used size, 6 vars
Matrix 0 [glstate_matrix_mvp] 4
BindCB "UnityPerDraw" 0
// 5 instructions, 1 temp regs, 0 temp arrays:
// ALU 4 float, 0 int, 0 uint
// TEX 0 (0 load, 0 comp, 0 bias, 0 grad)
// FLOW 1 static, 0 dynamic
"vs_4_0
eefiecedijhpljdppnfhjnjaadaickkmhicpkjbcabaaaaaaheabaaaaadaaaaaa
cmaaaaaagaaaaaaajeaaaaaaejfdeheocmaaaaaaabaaaaaaaiaaaaaacaaaaaaa
aaaaaaaaaaaaaaaaadaaaaaaaaaaaaaaapapaaaafaepfdejfeejepeoaaklklkl
epfdeheocmaaaaaaabaaaaaaaiaaaaaacaaaaaaaaaaaaaaaabaaaaaaadaaaaaa
aaaaaaaaapaaaaaafdfgfpfaepfdejfeejepeoaafdeieefcniaaaaaaeaaaabaa
dgaaaaaafjaaaaaeegiocaaaaaaaaaaaaeaaaaaafpaaaaadpcbabaaaaaaaaaaa
ghaaaaaepccabaaaaaaaaaaaabaaaaaagiaaaaacabaaaaaadiaaaaaipcaabaaa
aaaaaaaafgbfbaaaaaaaaaaaegiocaaaaaaaaaaaabaaaaaadcaaaaakpcaabaaa
aaaaaaaaegiocaaaaaaaaaaaaaaaaaaaagbabaaaaaaaaaaaegaobaaaaaaaaaaa
dcaaaaakpcaabaaaaaaaaaaaegiocaaaaaaaaaaaacaaaaaakgbkbaaaaaaaaaaa
egaobaaaaaaaaaaadcaaaaakpccabaaaaaaaaaaaegiocaaaaaaaaaaaadaaaaaa
pgbpbaaaaaaaaaaaegaobaaaaaaaaaaadoaaaaab"
}

This is the full compiled shader https://www.dropbox.com/s/l22iqmex4qhcy59/Compiled... maybe it will mean something more to you than it does to me :).
I'll see if I can find out some more tomorrow, if you have something you want me to try just tell !! 
I've encoutered the same issue. Have anyone solved it?
Same happens when setting Graphic emulation to DirectX 11 9.1 or 9.3, also on Windows Phone 8.1 device.
I just found that if you remove the line "#pragma target 3.0" from the shader code, it will render normally. d3d11_9x shader model level is 2.0. However, it doesn't draw complex shaders. Check the following lines from the log:

Shader error in 'ColorReplacement': Compiled shader code uses too many instruction slots (102). Max. allowed by the target (ps_2_0) is 96. at line 1 (on d3d11_9x)
Shader error in 'ColorReplacement': Too many math instructions for SM2.0 (101 needed, max is 64). Try #pragma target 3.0 at line 84 (on d3d11_9x)

I need this shader for my project, how can I overcome this?
Answer
Not a bug
I don't think that's possible in that case, I'm guessing the shader is simply too complex for the platform in question.

So, in general, the closest you can get, is to enable d3d11_9x and enable SM2.0 in the experimental settings.