[Résolu] Shader Mobile (Rendu noir sur le device)

Questions à propos du scripting Shader.
Molgy
Messages : 26
Inscription : 12 Mai 2016 04:01

[Résolu] Shader Mobile (Rendu noir sur le device)

Message par Molgy » 01 Juin 2016 15:45

Hello,

Je travaille actuellement sur un projet mobile dans lequel on utilise des Shader via ShaderForge.

Mais visiblement selon les différents mobiles, les shaders s'affichent ou non, d'après les graphistes cela s'affiche correctement sur leurs mobiles, hors sur mon téléphone les shaders s'affichent complètement noir.

Sur l'éditeur dans unity aucun problème.

J'ai tester :
- De changer en Mobile/Diffuse via shaderforger.
- Réduire la taille de la texture.

Je ne comprend pas de où cela peut venir, j'ajoute un exemple de code d'un des shaders si cela peut aider :

Code : Tout sélectionner

// Shader created with Shader Forge v1.26 
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.26;sub:START;pass:START;ps:flbk:Mobile/Diffuse,iptp:0,cusa:False,bamd:0,lico:1,lgpr:1,limd:3,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,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,stcl:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False;n:type:ShaderForge.SFN_Final,id:216,x:32719,y:32712,varname:node_216,prsc:2|diff-2697-OUT,diffpow-2697-OUT,spec-3271-OUT,gloss-466-OUT,normal-9921-RGB,amdfl-2697-OUT,alpha-1168-A,clip-4312-OUT;n:type:ShaderForge.SFN_Tex2d,id:9338,x:32037,y:32373,ptovrint:False,ptlb:node_9338,ptin:_node_9338,varname:node_9338,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:765dc5fc44f09824e950cf62977ab1fb,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:9921,x:32250,y:32955,ptovrint:False,ptlb:Normal,ptin:_Normal,varname:node_9921,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:d6eebc50a092cf1458dcea4bac244cea,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Slider,id:3271,x:32167,y:32680,ptovrint:False,ptlb:Metallic,ptin:_Metallic,varname:node_3271,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_Slider,id:466,x:32167,y:32806,ptovrint:False,ptlb:Roughnes,ptin:_Roughnes,varname:node_466,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_Desaturate,id:9530,x:32337,y:32411,varname:node_9530,prsc:2|COL-9338-RGB;n:type:ShaderForge.SFN_Slider,id:8186,x:32252,y:32298,ptovrint:False,ptlb:Brightness,ptin:_Brightness,varname:node_8186,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.3,max:1;n:type:ShaderForge.SFN_Add,id:440,x:32641,y:32404,varname:node_440,prsc:2|A-8186-OUT,B-9530-OUT;n:type:ShaderForge.SFN_Clamp,id:2697,x:32821,y:32472,varname:node_2697,prsc:2|IN-440-OUT,MIN-6429-OUT,MAX-795-OUT;n:type:ShaderForge.SFN_ValueProperty,id:6429,x:32489,y:32555,ptovrint:False,ptlb:minimum,ptin:_minimum,varname:node_6429,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0.3;n:type:ShaderForge.SFN_ValueProperty,id:795,x:32509,y:32651,ptovrint:False,ptlb:maximum,ptin:_maximum,varname:node_795,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0.8;n:type:ShaderForge.SFN_DDXY,id:6757,x:32426,y:33101,varname:node_6757,prsc:2|IN-9338-A;n:type:ShaderForge.SFN_Subtract,id:4312,x:32523,y:32962,varname:node_4312,prsc:2|A-9338-A,B-6757-OUT;n:type:ShaderForge.SFN_Tex2d,id:1168,x:32236,y:33288,ptovrint:False,ptlb:AlphaStencil,ptin:_AlphaStencil,varname:node_1168,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:4e1a637336bc3f547a22270b456fbd93,ntxv:0,isnm:False;proporder:9338-9921-3271-466-8186-6429-795-1168;pass:END;sub:END;*/

Shader "Custom/LETTERSFOUND" {
    Properties {
        _node_9338 ("node_9338", 2D) = "white" {}
        _Normal ("Normal", 2D) = "white" {}
        _Metallic ("Metallic", Range(0, 1)) = 0
        _Roughnes ("Roughnes", Range(0, 1)) = 0
        _Brightness ("Brightness", Range(0, 1)) = 0.3
        _minimum ("minimum", Float ) = 0.3
        _maximum ("maximum", Float ) = 0.8
        _AlphaStencil ("AlphaStencil", 2D) = "white" {}
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }
        LOD 200
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            Blend SrcAlpha OneMinusSrcAlpha
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #include "UnityPBSLighting.cginc"
            #include "UnityStandardBRDF.cginc"
            #pragma multi_compile_fwdbase
            #pragma multi_compile_fog
            #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 
            #pragma target 3.0
            uniform sampler2D _node_9338; uniform float4 _node_9338_ST;
            uniform sampler2D _Normal; uniform float4 _Normal_ST;
            uniform float _Metallic;
            uniform float _Roughnes;
            uniform float _Brightness;
            uniform float _minimum;
            uniform float _maximum;
            uniform sampler2D _AlphaStencil; uniform float4 _AlphaStencil_ST;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float4 tangent : TANGENT;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 posWorld : TEXCOORD1;
                float3 normalDir : TEXCOORD2;
                float3 tangentDir : TEXCOORD3;
                float3 bitangentDir : TEXCOORD4;
                UNITY_FOG_COORDS(5)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
                o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
                o.posWorld = mul(_Object2World, v.vertex);
                float3 lightColor = _LightColor0.rgb;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
                UNITY_TRANSFER_FOG(o,o.pos);
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
                float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
                float4 _Normal_var = tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal));
                float3 normalLocal = _Normal_var.rgb;
                float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
                float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
                float4 _node_9338_var = tex2D(_node_9338,TRANSFORM_TEX(i.uv0, _node_9338));
                clip((_node_9338_var.a-fwidth(_node_9338_var.a)) - 0.5);
                float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
                float3 lightColor = _LightColor0.rgb;
                float3 halfDirection = normalize(viewDirection+lightDirection);
////// Lighting:
                float attenuation = 1;
                float3 attenColor = attenuation * _LightColor0.xyz;
                float Pi = 3.141592654;
                float InvPi = 0.31830988618;
///////// Gloss:
                float gloss = _Roughnes;
                float specPow = exp2( gloss * 10.0+1.0);
/////// GI Data:
                UnityLight light;
                #ifdef LIGHTMAP_OFF
                    light.color = lightColor;
                    light.dir = lightDirection;
                    light.ndotl = LambertTerm (normalDirection, light.dir);
                #else
                    light.color = half3(0.f, 0.f, 0.f);
                    light.ndotl = 0.0f;
                    light.dir = half3(0.f, 0.f, 0.f);
                #endif
                UnityGIInput d;
                d.light = light;
                d.worldPos = i.posWorld.xyz;
                d.worldViewDir = viewDirection;
                d.atten = attenuation;
                Unity_GlossyEnvironmentData ugls_en_data;
                ugls_en_data.roughness = 1.0 - gloss;
                ugls_en_data.reflUVW = viewReflectDirection;
                UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
                lightDirection = gi.light.dir;
                lightColor = gi.light.color;
////// Specular:
                float NdotL = max(0, dot( normalDirection, lightDirection ));
                float LdotH = max(0.0,dot(lightDirection, halfDirection));
                float node_2697 = clamp((_Brightness+dot(_node_9338_var.rgb,float3(0.3,0.59,0.11))),_minimum,_maximum);
                float3 diffuseColor = float3(node_2697,node_2697,node_2697); // Need this for specular when using metallic
                float specularMonochrome;
                float3 specularColor;
                diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, _Metallic, specularColor, specularMonochrome );
                specularMonochrome = 1-specularMonochrome;
                float NdotV = max(0.0,dot( normalDirection, viewDirection ));
                float NdotH = max(0.0,dot( normalDirection, halfDirection ));
                float VdotH = max(0.0,dot( viewDirection, halfDirection ));
                float visTerm = SmithBeckmannVisibilityTerm( NdotL, NdotV, 1.0-gloss );
                float normTerm = max(0.0, NDFBlinnPhongNormalizedTerm(NdotH, RoughnessToSpecPower(1.0-gloss)));
                float specularPBL = max(0, (NdotL*visTerm*normTerm) * (UNITY_PI / 4) );
                float3 directSpecular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow)*specularPBL*lightColor*FresnelTerm(specularColor, LdotH);
                float3 specular = directSpecular;
/////// Diffuse:
                NdotL = max(0.0,dot( normalDirection, lightDirection ));
                half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
                float3 directDiffuse = ((1 +(fd90 - 1)*pow((1.00001-NdotL), 5)) * (1 + (fd90 - 1)*pow((1.00001-NdotV), 5)) * NdotL) * attenColor;
                float3 indirectDiffuse = float3(0,0,0);
                indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
                indirectDiffuse += float3(node_2697,node_2697,node_2697); // Diffuse Ambient Light
                float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
/// Final Color:
                float3 finalColor = diffuse + specular;
                float4 _AlphaStencil_var = tex2D(_AlphaStencil,TRANSFORM_TEX(i.uv0, _AlphaStencil));
                fixed4 finalRGBA = fixed4(finalColor,_AlphaStencil_var.a);
                UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
                return finalRGBA;
            }
            ENDCG
        }
        Pass {
            Name "FORWARD_DELTA"
            Tags {
                "LightMode"="ForwardAdd"
            }
            Blend One One
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDADD
            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            #include "UnityPBSLighting.cginc"
            #include "UnityStandardBRDF.cginc"
            #pragma multi_compile_fwdadd
            #pragma multi_compile_fog
            #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 
            #pragma target 3.0
            uniform sampler2D _node_9338; uniform float4 _node_9338_ST;
            uniform sampler2D _Normal; uniform float4 _Normal_ST;
            uniform float _Metallic;
            uniform float _Roughnes;
            uniform float _Brightness;
            uniform float _minimum;
            uniform float _maximum;
            uniform sampler2D _AlphaStencil; uniform float4 _AlphaStencil_ST;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float4 tangent : TANGENT;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 posWorld : TEXCOORD1;
                float3 normalDir : TEXCOORD2;
                float3 tangentDir : TEXCOORD3;
                float3 bitangentDir : TEXCOORD4;
                LIGHTING_COORDS(5,6)
                UNITY_FOG_COORDS(7)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
                o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
                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);
                float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
                float4 _Normal_var = tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal));
                float3 normalLocal = _Normal_var.rgb;
                float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
                float4 _node_9338_var = tex2D(_node_9338,TRANSFORM_TEX(i.uv0, _node_9338));
                clip((_node_9338_var.a-fwidth(_node_9338_var.a)) - 0.5);
                float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
                float3 lightColor = _LightColor0.rgb;
                float3 halfDirection = normalize(viewDirection+lightDirection);
////// Lighting:
                float attenuation = LIGHT_ATTENUATION(i);
                float3 attenColor = attenuation * _LightColor0.xyz;
                float Pi = 3.141592654;
                float InvPi = 0.31830988618;
///////// Gloss:
                float gloss = _Roughnes;
                float specPow = exp2( gloss * 10.0+1.0);
////// Specular:
                float NdotL = max(0, dot( normalDirection, lightDirection ));
                float LdotH = max(0.0,dot(lightDirection, halfDirection));
                float node_2697 = clamp((_Brightness+dot(_node_9338_var.rgb,float3(0.3,0.59,0.11))),_minimum,_maximum);
                float3 diffuseColor = float3(node_2697,node_2697,node_2697); // Need this for specular when using metallic
                float specularMonochrome;
                float3 specularColor;
                diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, _Metallic, specularColor, specularMonochrome );
                specularMonochrome = 1-specularMonochrome;
                float NdotV = max(0.0,dot( normalDirection, viewDirection ));
                float NdotH = max(0.0,dot( normalDirection, halfDirection ));
                float VdotH = max(0.0,dot( viewDirection, halfDirection ));
                float visTerm = SmithBeckmannVisibilityTerm( NdotL, NdotV, 1.0-gloss );
                float normTerm = max(0.0, NDFBlinnPhongNormalizedTerm(NdotH, RoughnessToSpecPower(1.0-gloss)));
                float specularPBL = max(0, (NdotL*visTerm*normTerm) * (UNITY_PI / 4) );
                float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow)*specularPBL*lightColor*FresnelTerm(specularColor, LdotH);
                float3 specular = directSpecular;
/////// Diffuse:
                NdotL = max(0.0,dot( normalDirection, lightDirection ));
                half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
                float3 directDiffuse = ((1 +(fd90 - 1)*pow((1.00001-NdotL), 5)) * (1 + (fd90 - 1)*pow((1.00001-NdotV), 5)) * NdotL) * attenColor;
                float3 diffuse = directDiffuse * diffuseColor;
/// Final Color:
                float3 finalColor = diffuse + specular;
                float4 _AlphaStencil_var = tex2D(_AlphaStencil,TRANSFORM_TEX(i.uv0, _AlphaStencil));
                fixed4 finalRGBA = fixed4(finalColor * _AlphaStencil_var.a,0);
                UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
                return finalRGBA;
            }
            ENDCG
        }
        Pass {
            Name "ShadowCaster"
            Tags {
                "LightMode"="ShadowCaster"
            }
            Offset 1, 1
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_SHADOWCASTER
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
            #include "UnityPBSLighting.cginc"
            #include "UnityStandardBRDF.cginc"
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma multi_compile_shadowcaster
            #pragma multi_compile_fog
            #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 
            #pragma target 3.0
            uniform sampler2D _node_9338; uniform float4 _node_9338_ST;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                V2F_SHADOW_CASTER;
                float2 uv0 : TEXCOORD1;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
                TRANSFER_SHADOW_CASTER(o)
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                float4 _node_9338_var = tex2D(_node_9338,TRANSFORM_TEX(i.uv0, _node_9338));
                clip((_node_9338_var.a-fwidth(_node_9338_var.a)) - 0.5);
                SHADOW_CASTER_FRAGMENT(i)
            }
            ENDCG
        }
    }
    FallBack "Mobile/Diffuse"
    CustomEditor "ShaderForgeMaterialInspector"
}
Dernière édition par Molgy le 01 Juin 2016 17:03, édité 1 fois.
T'entraîner tu devras, :!:
Tester tu feras, :?:
Réussite tu auras. 8-)
-- Dayo ! :merci:

Avatar de l’utilisateur
boubouk50
ModoGenereux
ModoGenereux
Messages : 5402
Inscription : 28 Avr 2014 11:57
Localisation : Toulouse

Re: Shader Mobile

Message par boubouk50 » 01 Juin 2016 16:07

Les mobiles n'ont pas tous la même technologie embarquée. Les shaders (comme un peu tout, en fait) nécessite certaines capacités que tous les mobiles n'ont pas. Par exemple, un mobile sans gyroscope ne peut pas faire tourner des apps qui en ont besoin. Pour les shaders c'est pareil, ils n'ont pas tous le même shader model, la même API, la même version d'OpenGL, la même version d'Android, etc.
"Ce n'est pas en améliorant la bougie, que l'on a inventé l'ampoule, c'est en marchant longtemps."
Nétiquette du forum
Savoir faire une recherche
Apprendre la programmation

Molgy
Messages : 26
Inscription : 12 Mai 2016 04:01

Re: Shader Mobile

Message par Molgy » 01 Juin 2016 17:03

Ah nickel, j'ai trouvé, pour ceux qui auraient le problème voilà ce qu'il faut faire :

Dans Shader Forger

-> Shader Settings

-> Cocher OpenGL ES 3.0

Merci Boubouk50 en tout cas :)

Je met le sujet en résolu
T'entraîner tu devras, :!:
Tester tu feras, :?:
Réussite tu auras. 8-)
-- Dayo ! :merci:

Répondre

Revenir vers « les Shaders »