Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Namnam · Feb 22, 2018 at 08:52 PM · shadermaterialtexturescustom

Combine smoothness and metallic with frag Shader

Hi,


I'm trying to add some Smoothness and Metallic to my custom shader in order to have dark texture for day/night cycle.


For the moment, i have a procedurale planet and my shader draw different textures based on height (distance between center of planet and vertex at surface).

Until there, it works !


Now I really need to add Smoothness and Metallic to material but with my shader the textures of my procedurale planet is black and dont know why ? I have a pass for frag and then a surf function for smoothness and metallic. Why this doesn't work please ?


However when I look at the material icon and I change value it looks nice but procedurale planet is always black no matter of value i change and the color i set.


Can't solve this problem since too long time. Please need some help.

Thanks in advance.


Here is my shader :

 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"
 }










Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Feb 22, 2018 at 08:50 PM 0
Share

Debugging shaders is real hard work. Start by trying to get anything other than black ofc. Sometimes the problem is further back in the code than you think and sometimes its due to changes, which are listed in the Unity $$anonymous$$anual and Scripting API. I can't pretend I can do this for you without it taking me all day but I can point you in the direction of the CG in Unity book I read that showed me how to debug shaders. Its free and online. I dont know your level of shader writing ability, if you are a beginner then its a fantastic read, if you are a veteran then its always good to get back to basics.

avatar image Namnam · Feb 22, 2018 at 09:19 PM 0
Share

Thanks for your comment and your link, first i'm beginner for ability to write the shaders. It's why I need some help. Then, do you see a potential error on this shader that can cause the black color of the textures ? If not, I will try to debug this shader but as you say i'ts a hard work.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Namnam · Feb 23, 2018 at 09:35 AM

Does anyone else can tell me what is wrong in this shader and why it result black color to all textures please ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to hide objects inside an invisible object? 0 Answers

Sorting (rendering) order of materials in mesh renderer 1 Answer

I can see the objects through the terrain. 1 Answer

Material.SetTexture doesn't work if not "_MainTex" 0 Answers

Shader Forge outputting gray instead of black 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges