Jump to content
sigbuserror

Polybrush and iOS build target

Recommended Posts

I recently got PolyBrush to try out on our project and while everything was working fine when targeting a Mac build once switching to iOS anything painted with the tool appears black. Switching back to Mac fixes the issue but it makes the tool basically useless for us. This is using the Standard Texture Blend shader as well. Any ideas?

Share this post


Link to post
Share on other sites

Sounds like there's probably a compile error in the Standard Texture Blend shader.  I don't have an iOS device to test with, but this compiles for me when targeting Android - can you try with this shader?

// define Z_TEXTURE_CHANNELS 4
// define Z_MESH_ATTRIBUTES UV3
// Important!  This is a generated file, any changes will be overwritten
// when the _SfTexBlendSrc suffixed version of this shader is modified.


Shader "Polybrush/Texture Blend (Mobile)" {
    Properties {
        _Texture1 ("Texture 1", 2D) = "white" {}
        
        _Texture2 ("Texture 2", 2D) = "white" {}
        _Texture3 ("Texture 3", 2D) = "white" {}
        _Texture4 ("Texture 4", 2D) = "white" {}
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragma multi_compile_fog
            #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 
            #pragma target 3.0
            uniform float4 _LightColor0;
            uniform sampler2D _Texture1; uniform float4 _Texture1_ST;
            
            uniform sampler2D _Texture2; uniform float4 _Texture2_ST;
            uniform sampler2D _Texture3; uniform float4 _Texture3_ST;
            uniform sampler2D _Texture4; uniform float4 _Texture4_ST;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float4 texcoord0 : TEXCOORD0;
                float4 texcoord2 : TEXCOORD2;
                float4 vertexColor : COLOR;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float4 uv0 : TEXCOORD0;
                float4 uv2 : TEXCOORD1;
                float4 posWorld : TEXCOORD2;
                float3 normalDir : TEXCOORD3;
                float4 vertexColor : COLOR;
                LIGHTING_COORDS(4,5)
                UNITY_FOG_COORDS(6)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.uv2 = v.texcoord2;
                o.vertexColor = v.vertexColor;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.posWorld = mul(_Object2World, v.vertex);
                float3 lightColor = _LightColor0.rgb;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
                UNITY_TRANSFER_FOG(o,o.pos);
                TRANSFER_VERTEX_TO_FRAGMENT(o)
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
                float3 normalDirection = i.normalDir;
                float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
                float3 lightColor = _LightColor0.rgb;
////// Lighting:
                float attenuation = LIGHT_ATTENUATION(i);
                float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
                float NdotL = max(0.0,dot( normalDirection, lightDirection ));
                float3 directDiffuse = max( 0.0, NdotL) * attenColor;
                float3 indirectDiffuse = float3(0,0,0);
                indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
                float4 node_9912 = normalize(float4(i.uv2.r,i.uv2.g,i.uv2.b,i.uv2.a));
                float4 _Texture1_var = tex2D(_Texture1,TRANSFORM_TEX(i.uv0, _Texture1));
                float4 _Texture2_var = tex2D(_Texture2,TRANSFORM_TEX(i.uv0, _Texture2));
                float4 _Texture3_var = tex2D(_Texture3,TRANSFORM_TEX(i.uv0, _Texture3));
                float4 _Texture4_var = tex2D(_Texture4,TRANSFORM_TEX(i.uv0, _Texture4));
                float3 diffuseColor = (i.vertexColor.rgb*(node_9912.r*_Texture1_var.rgb + node_9912.g*_Texture2_var.rgb + node_9912.b*_Texture3_var.rgb + node_9912.a*_Texture4_var.rgb));
                float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
/// Final Color:
                float3 finalColor = diffuse;
                fixed4 finalRGBA = fixed4(finalColor,1);
                UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
                return finalRGBA;
            }
            ENDCG
        }
        Pass {
            Name "FORWARD_DELTA"
            Tags {
                "LightMode"="ForwardAdd"
            }
            Blend One One
            
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDADD
            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            #pragma multi_compile_fwdadd_fullshadows
            #pragma multi_compile_fog
            #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 
            #pragma target 3.0
            uniform float4 _LightColor0;
            uniform sampler2D _Texture1; uniform float4 _Texture1_ST;
            
            uniform sampler2D _Texture2; uniform float4 _Texture2_ST;
            uniform sampler2D _Texture3; uniform float4 _Texture3_ST;
            uniform sampler2D _Texture4; uniform float4 _Texture4_ST;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float4 texcoord0 : TEXCOORD0;
                float4 texcoord2 : TEXCOORD2;
                float4 vertexColor : COLOR;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float4 uv0 : TEXCOORD0;
                float4 uv2 : TEXCOORD1;
                float4 posWorld : TEXCOORD2;
                float3 normalDir : TEXCOORD3;
                float4 vertexColor : COLOR;
                LIGHTING_COORDS(4,5)
                UNITY_FOG_COORDS(6)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.uv2 = v.texcoord2;
                o.vertexColor = v.vertexColor;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.posWorld = mul(_Object2World, v.vertex);
                float3 lightColor = _LightColor0.rgb;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
                UNITY_TRANSFER_FOG(o,o.pos);
                TRANSFER_VERTEX_TO_FRAGMENT(o)
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
                float3 normalDirection = i.normalDir;
                float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
                float3 lightColor = _LightColor0.rgb;
////// Lighting:
                float attenuation = LIGHT_ATTENUATION(i);
                float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
                float NdotL = max(0.0,dot( normalDirection, lightDirection ));
                float3 directDiffuse = max( 0.0, NdotL) * attenColor;
                float4 node_9912 = normalize(float4(i.uv2.r,i.uv2.g,i.uv2.b,i.uv2.a));
                float4 _Texture1_var = tex2D(_Texture1,TRANSFORM_TEX(i.uv0, _Texture1));
                float4 _Texture2_var = tex2D(_Texture2,TRANSFORM_TEX(i.uv0, _Texture2));
                float4 _Texture3_var = tex2D(_Texture3,TRANSFORM_TEX(i.uv0, _Texture3));
                float4 _Texture4_var = tex2D(_Texture4,TRANSFORM_TEX(i.uv0, _Texture4));
                float3 diffuseColor = (i.vertexColor.rgb*(node_9912.r*_Texture1_var.rgb + node_9912.g*_Texture2_var.rgb + node_9912.b*_Texture3_var.rgb + node_9912.a*_Texture4_var.rgb));
                float3 diffuse = directDiffuse * diffuseColor;
/// Final Color:
                float3 finalColor = diffuse;
                fixed4 finalRGBA = fixed4(finalColor * 1,0);
                UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
                return finalRGBA;
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
    CustomEditor "z_BlendMaterialInspector"
}

Share this post


Link to post
Share on other sites

After changing to that new shader I am seeing a texture on the geo, but it is drawing the painted vert colors over the textures themselves. Strangely I wasn't seeing any error for the other shader before.

 

To be clear, I am seeing these changes in the Editor before ever deploying to device.

Share this post


Link to post
Share on other sites

After changing to that new shader I am seeing a texture on the geo, but it is drawing the painted vert colors over the textures themselves

 

Yes, that's intentional.  The shader I posted above supports vertex color tints and texture blending.   If you don't want any vertex color tints just use the painter to paint the whole object with a white color.

Share this post


Link to post
Share on other sites

Ahh I understand now, the thing that confused me was that I hadn't used the tinting at all on the object but it must have been the data from the other channels since the original shader has more texture slots. Now I can see and edit the geo in Unity Editor but the geometry just displays as black on actual iOS devices.

Share this post


Link to post
Share on other sites
Now I can see and edit the geo in Unity Editor but the geometry just displays as black on actual iOS devices.

 

 

Shoot... well that's progress at least :)

 

Are there any errors in the Xcode console when running the project?  Also, if you just use the sculpting parts of Polybrush and use the Unity standard shader does that work properly?

Share this post


Link to post
Share on other sites

Yeah, finally got a build on device and connect to xcode. I am getting this error:

 

Unloading 6 Unused Serialized files (Serialized files now loaded: 0)

WARNING: Shader Unsupported: 'Polybrush/Texture Blend (Mobile)' - Pass 'FORWARD' has no vertex shader

WARNING: Shader Unsupported: 'Polybrush/Texture Blend (Mobile)' - Pass 'FORWARD_DELTA' has no vertex shader

WARNING: Shader Unsupported: 'Polybrush/Texture Blend (Mobile)' - All passes removed

UnloadTime: 3.637541 ms

Share this post


Link to post
Share on other sites

The regular shader meaning Unity's Standard shader, or the Polybrush Standard Texture Blend shader?  I'm currently working on procuring an Apple mobile device to test on, so hopefully supporting it very soon.  If you're referring to Unity's Standard shader, then I'm not sure what I could do - that would sound like a Unity bug to me.

Share this post


Link to post
Share on other sites

Just in case someone else is running into this issue, the shader above works on iOS as long as you remove the Metal exclude flags. Didn't see that for a while!

Can I have more details? Because I'm facing on same issue but dont know how to do it. Thank you so much!!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×