Combiner smoothness et metallic avec un fragment shader

Questions à propos du scripting Shader.
Namnam
Messages : 1
Inscription : 23 Fév 2018 13:27

Combiner smoothness et metallic avec un fragment shader

Message par Namnam » 23 Fév 2018 13:46

Bonjour à tous,

J'essai depuis quelques jours d'ajouter smoothness et metallic à mon shader afin que les textures soit sombres lorsqu'il n'y a pas d'éclairage pour un cycle Day/Night.

Pour le moment, j'ai une planet procédurale et mon shader dessine une textures selon la hauteur c'est à dire la distance entre le centre de la planète et les points à sa surface.
Jusqu'ici tout va bien, cela fonctionne.

Mais la je n'arrive pas à ajouter smoothness et metallic à mes textures de ma planet procédurale.
En effet, avec mon shader que j'ai actuellement, les textures sont de couleur noires et je ne sais pas pourquoi.

Pourtant lorsque je regarde l'icône de mon material, je vois bien que l'effet smoothness et metallic est appliqué mais les textures reste couleur noir peu importe les valeurs que je choisi, idem pour la couleur.

Je précise qu'il y a bien de l'éclairage autour de la planet.

Je n'arrive pas à résoudre ce problème malgré les recherche que j'ai fait sur le web pour combiner smoothness et metallic avec un fragment.

Pouvez vous m'éclairer sur ce qui ne va pas dans ce shader s'il vous plaît j'ai vraiment besoin d'aide.

Je suis novice en programmation de shader c'est pourquoi je suis bloqué.

Merci d'avance.

Voici mon custom shader :

Code : Tout sélectionner

Shader "Custom/Planet" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         _Tex0 ("Tex 0", 2D) = "white" {}
         _Tex1 ("Tex 1", 2D) = "white" {}
         _Tex2 ("Tex 2", 2D) = "white" {}
         _Tex3 ("Tex 3", 2D) = "white" {}
         _Tex4 ("Tex 4", 2D) = "white" {}
 
         _Blend0to1and1to2 ("Blend between 0 and 1, 1 and 2", Vector) = (0,1,2,3)
         _Blend2to3and3to4 ("Blend between 2 and 3, 3 and 4", Vector) = (0,1,2,3)
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _Metallic ("Metallic", Range(0,1)) = 0.0
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
 
         Pass
          {
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
 
                     #pragma vertex vert
                     #pragma fragment frag
                 
                     #include "UnityCG.cginc"
                     #pragma target 3.0
 
                     sampler2D _Tex0;
                     sampler2D _Tex1;
                     sampler2D _Tex2;
                     sampler2D _Tex3;
                     sampler2D _Tex4;
 
                     float4 _Blend0to1and1to2;
                     float4 _Blend2to3and3to4;
 
                     uniform float4 _Tex0_ST;
                     uniform float4 _Tex1_ST;
                     uniform float4 _Tex2_ST;
                     uniform float4 _Tex3_ST;
 
 
                 
                     struct appData {
 
                         float4 vertex : POSITION;
                         float2 uv1 : TEXCOORD0;
                         float2 uv2 : TEXCOORD1;
                         float2 uv3 : TEXCOORD2;
                         float2 uv4 : TEXCOORD3;
 
                     };
 
                     struct v2f {
                         float4 pos : SV_POSITION;
                         float2 uv1 : TEXCOORD0;
                         float2 uv2 : TEXCOORD1;
                         float2 uv3 : TEXCOORD2;
                         float2 uv4 : TEXCOORD3;
                         float4 col : COLOR;
                        
                     };
                           #define PI 3.141592653589793
 
                      inline float2 RadialCoords(float3 a_coords)
                      {
                          float3 a_coords_n = normalize(a_coords);
                          float lon = atan2(a_coords_n.z, a_coords_n.x);
                          float lat = acos(a_coords_n.y);
                          float2 sphereCoords = float2(lon, lat) * (1.0 / PI);
                          return float2(sphereCoords.x * 0.5 + 0.5, 1 - sphereCoords.y);
                          
                      }
                     v2f vert (appData vInput) {
                         v2f output;
                         output.pos = UnityObjectToClipPos (vInput.vertex);
                         output.uv1 = TRANSFORM_TEX(vInput.uv1, _Tex0);
                         output.uv2 = TRANSFORM_TEX(vInput.uv2, _Tex1);
                          output.uv3 = TRANSFORM_TEX(vInput.uv3, _Tex2);
                           output.uv4 = TRANSFORM_TEX(vInput.uv4, _Tex3);
                         output.col = length(vInput.vertex);
                         return output;
                     }
 
                      half4 frag (v2f fInput) : COLOR {
 
                     half4 c0 = tex2D (_Tex0, fInput.uv1);
 
 
                     half4 c1 = tex2D (_Tex1, fInput.uv2);
 
 
                     half4 c2 = tex2D (_Tex2, fInput.uv3);
                      
                     half4 c3 = tex2D (_Tex3, fInput.uv4);
                     half4 c4 = tex2D (_Tex4, fInput.uv1);
 
                     if (fInput.col.x < _Blend0to1and1to2.x) {
                         
                         return c0;
                     }
                     if (fInput.col.x > _Blend0to1and1to2.x  && fInput.col.x < _Blend0to1and1to2.y) {
                         return lerp(c0,c1,((fInput.col.x - _Blend0to1and1to2.x)/(_Blend0to1and1to2.y-_Blend0to1and1to2.x)));
                     }
                     if (fInput.col.x > _Blend0to1and1to2.y  && fInput.col.x < _Blend0to1and1to2.z) {
                         return c1;
                     }
                     if (fInput.col.x > _Blend0to1and1to2.z  && fInput.col.x < _Blend0to1and1to2.w) {
                         return lerp(c1,c2,((fInput.col.x - _Blend0to1and1to2.z)/(_Blend0to1and1to2.w-_Blend0to1and1to2.z)));
                     }
                     if (fInput.col.x > _Blend0to1and1to2.w  && fInput.col.x < _Blend2to3and3to4.x) {
                         return c2;
                     }
                     if (fInput.col.x > _Blend2to3and3to4.x  && fInput.col.x < _Blend2to3and3to4.y) {
                         return lerp(c2,c3,((fInput.col.x - _Blend2to3and3to4.x)/(_Blend2to3and3to4.y-_Blend2to3and3to4.x)));
                     }
                     if (fInput.col.x > _Blend2to3and3to4.y  && fInput.col.x < _Blend2to3and3to4.z) {
                         return c3;
                     }
                     if (fInput.col.x > _Blend2to3and3to4.z  && fInput.col.x < _Blend2to3and3to4.w) {
                         return lerp(c3,c4,((fInput.col.x - _Blend2to3and3to4.z)/(_Blend2to3and3to4.w-_Blend2to3and3to4.z)));
                     }
                     return c4;
                 }
              
             ENDCG
          }
 
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Standard fullforwardshadows
 
         // Use shader model 3.0 target, to get nicer looking lighting
         #pragma target 3.0
 
         sampler2D _Tex1;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         half _Glossiness;
         half _Metallic;
         fixed4 _Color;
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             // Albedo comes from a texture tinted by color
             fixed4 c = tex2D (_Tex1, 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"
 }

Répondre

Revenir vers « les Shaders »