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 Dajuice · Jun 02, 2015 at 04:58 PM · scripting problemshadertoon

How do I get the textures to work on thir toon shader?

I followed this tune shader tutorial but for some reason my textures aren't working at all? Everything else works fine but I have nod idea what is causing my textures not to appear. Im getting no compile errors or anything like that just no textures... Heres the Code:

 Shader "Toon Test" {
    Properties {
     _Color ("Diffuse Material Color", Color) = (1,1,1,1)
     _UnlitColor ("Unlit Color", Color) = (0.5,0.5,0.5,1)
     _DiffuseThreshold ("Lighting Threshold", Range(-1.1,1)) = 0.1
     _SpecColor ("Specular Material Color", Color) = (1,1,1,1)
     _Shininess ("Shininess", Range(0.5,1)) = 1 
     _OutlineThickness ("Outline Thickness", Range(0,1)) = 0.1
     _MainTex ("Main Texture", 2D) = "AK47" {}
            
         }
    
      SubShader {
      Pass {
         Tags{ "LightMode" = "ForwardBase" }
        
      
         CGPROGRAM
        
         #pragma vertex vert
         
         #pragma fragment frag
        
        
         
         uniform float4 _Color;
         uniform float4 _UnlitColor;
         uniform float _DiffuseThreshold;
         uniform float4 _SpecColor;
         uniform float _Shininess;
         uniform float _OutlineThickness;
      
        
        
         uniform float4 _LightColor0;
         uniform sampler2D _MainTex;
         uniform float4 _MainTex_ST;            
        
         struct vertexInput {
                
        
         float4 vertex : POSITION;
         float3 normal : NORMAL;
         float4 texcoord : TEXCOORD0;
                  
         };
        
         struct vertexOutput {
                
                 float4 pos : SV_POSITION;
                 float3 normalDir : TEXCOORD1;
                 float4 lightDir : TEXCOORD2;
                 float3 viewDir : TEXCOORD3;
                 float2 uv : TEXCOORD0;
         };
        
         vertexOutput vert(vertexInput input)
         {
                 vertexOutput output;
                
                 
                 output.normalDir = normalize ( mul( float4( input.normal, 0.0 ), _World2Object).xyz );
                
               
                 float4 posWorld = mul(_Object2World, input.vertex);
                
                 
                 output.viewDir = normalize( _WorldSpaceCameraPos.xyz - posWorld.xyz ); 
                
                 float3 fragmentToLightSource = ( _WorldSpaceCameraPos.xyz - posWorld.xyz);
                 output.lightDir = float4(
                         normalize( lerp(_WorldSpaceLightPos0.xyz , fragmentToLightSource, _WorldSpaceLightPos0.w) ),
                         lerp(1.0 , 1.0/length(fragmentToLightSource), _WorldSpaceLightPos0.w)
                 );
                
                 
                 output.pos = mul( UNITY_MATRIX_MVP, input.vertex );  
                
                 
                 output.uv =input.texcoord;
                
                 return output;
          
         }
        
         float4 frag(vertexOutput input) : COLOR
         {
  
         float nDotL = saturate(dot(input.normalDir, input.lightDir.xyz));
                        
     
         float diffuseCutoff = saturate( ( max(_DiffuseThreshold, nDotL) - _DiffuseThreshold ) *1000 );
                        
        
         float specularCutoff = saturate( max(_Shininess, dot(reflect(-input.lightDir.xyz, input.normalDir), input.viewDir))-_Shininess ) * 1000;
                        
        
         float outlineStrength = saturate( (dot(input.normalDir, input.viewDir ) - _OutlineThickness) * 1000 );
                
                        
         float3 ambientLight = (1-diffuseCutoff) * _UnlitColor.xyz; 
         float3 diffuseReflection = (1-specularCutoff) * _Color.xyz * diffuseCutoff;
         float3 specularReflection = _SpecColor.xyz * specularCutoff;
                
         float3 combinedLight = (ambientLight + diffuseReflection) * outlineStrength + specularReflection;
                        
         return float4(combinedLight, 1.0); 
  
         }
        
         ENDCG
      
       }
  
    
    }
  
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jun 02, 2015 at 05:00 PM

That's because there's nothing in the frag function that actually makes use of _MainTex... if you want a toon shader, why not just use the Toon Shading package that comes with Unity?

Comment
Add comment · Show 2 · 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
avatar image Dajuice · Jun 02, 2015 at 06:01 PM 0
Share

Well I just wanted one with shadows and high lights. $$anonymous$$inda light suda 51's work example. alt text

Plus Im kind brushing up my codeing as well so I being stubborn and wanna learn how to do it from scratch.

avatar image Dajuice · Jun 02, 2015 at 06:35 PM 0
Share

sorry my bad

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

2 People are following this question.

avatar image avatar image

Related Questions

Easy way to make a custom toon water shader 1 Answer

Adding Shadows to a Shader 1 Answer

Scripts not updating the material's shader properties 1 Answer

How can recreate shader file in URP (Universal Renderer Pipeline) 1 Answer

How to get toon Shader to work with terrains - Answered 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