Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by jay_jindani · Feb 23, 2015 at 04:03 PM · shadershadersshader programming

Shader Problem

alt text

I have a problem to reuse my old shader i dont know whats the problem of the highlights

always render vertically even i change the position of my uv maps always got a same result

please help me to fix this

see my shader code hope it will help

hader "Toon/Hair" { Properties { _Color("Color(RGBA)", Color) = (1,1,1,1) _MainTex("Texture", 2D) = "white" {} _SphereAddTex("Texture(Sphere)", 2D) = "black" {} _Shininess ("Shininess(0.0:)", Float) = 1.0

     _ShadowThreshold ("Shadow Threshold(0.0:1.0)", Float) = 0.5
     _ShadowColor ("Shadow Color(RGBA)", Color) = (0,0,0,0.5)
     _ShadowSharpness ("Shadow Sharpness(0.0:)", Float) = 100
 }

 SubShader
 {
     // Settings
     Tags {"Queue" = "Transparent" "IgnoreProjector"="True" "RenderType" = "Transparent"}
     //Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}

     // Surface Shader Pass ( Front )
     Cull Off
     ZWrite On
     Blend SrcAlpha OneMinusSrcAlpha
     CGPROGRAM
     //#pragma surface surfHair ToonHair vertex:vert
     #pragma surface surfHair ToonHair vertex:vert
     //    Toon Hair Surface Shader for Unity
     //    File        :    ToonSurfaceHair.cginc
     //    Title        :    Toon Surface Shader with Alpha
     //    Language    :    Cg Language
     //    Include        :    ToonSurfaceHair.cginc
     /*
         How To Use    :
         
         CGPROGRAM
         #pragma surface surfHair ToonHair vertex:vert
         #include "ToonSurfaceHair.cginc"
         ENDCG
     */

     float4 _Color;
     sampler2D _MainTex;
     float    _ShadowThreshold;
     float4    _ShadowColor;
     float    _ShadowSharpness;
     float    _Shininess;
     sampler2D _SphereAddTex;



     struct ToonSurfaceOutput
     {
         half3 Albedo;
         half3 Normal;
         half3 Emission;
         half3 Gloss;
         half Specular;
         half Alpha;
         half4 Color;
     };

     inline half4 LightingToonHair (ToonSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
     {
         //Lighting paramater
         float4    lightColor = _LightColor0 * atten;
         float    lightStrength = dot(lightDir, s.Normal) * 0.5 + 0.5;
             
         //ToonMapping
         half shadowRate = abs( max( -1, ( min( lightStrength, _ShadowThreshold ) -_ShadowThreshold)*_ShadowSharpness ) )*_ShadowColor.a;
         float4 toon = float4(1,1,1,1) * (1-shadowRate) +  _ShadowColor *shadowRate;
         
         //Output
         //float4 color = saturate( _Color * lightColor*2 ) * s.Color;
         float4 color = _Color * (lightColor) * s.Color * (atten*2) * _Shininess;
         color *= toon;
         color.a = s.Alpha;
         return color;
     }


     struct Input
     {
         float2 uv_MainTex;
         float3 customColor;
     };

     void vert (inout appdata_full v, out Input o) {
         UNITY_INITIALIZE_OUTPUT(Input,o);
         //o.customColor = abs(v.normal);
         o.customColor = v.normal;
     }

     void surfHair (Input IN, inout ToonSurfaceOutput o)
     {

         // Defaults
         o.Albedo = 0.0;
         o.Emission = 0.0;
         o.Gloss = 0.0;
         o.Specular = 0.0;
         
         
         // Sphere Map
         float3 viewNormal = normalize( IN.customColor );
         float3 viewNormal2 = normalize( mul( UNITY_MATRIX_MV, float4(normalize(o.Normal), 0.0) ).xyz );
         
         viewNormal = normalize(viewNormal*0.7 + viewNormal2*0.3);
         
         float2 sphereUv = viewNormal.xz * 0.5 + 0.5;
         
         float4 sphereAdd = tex2D( _SphereAddTex, sphereUv );
         
         
         half4 c        = tex2D(_MainTex, IN.uv_MainTex) * _Color;
         o.Color        = c;
         o.Color        += sphereAdd*0.2 * step(0,viewNormal.y); // SphereAddTex
         o.Alpha        = c.a;
     }

     ENDCG
 
 }

 // Other Environment
 Fallback "Transparent/Diffuse"

}

problem.png (38.8 kB)
Comment
Add comment · Show 1
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 Owen-Reynolds · Feb 23, 2015 at 06:20 PM 0
Share

Is that grey line (on the black area) the specular highlight? It looks like the shader is fine, and maybe the light is simply in a different place.

In both pictures, the light is on the right side, so the highlight in image #1 seems correct. I wonder if you don't just want to hand-draw a highlight on the texture.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is it possible to avoid writing to certain g-buffers? 1 Answer

Shader issue with a 170 upper angle 0 Answers

UnityObjectToClipPos is inverted? 0 Answers

post shader: reconstruct worldspace plane coordinates 1 Answer

Shader Color 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