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 Ty1ensen · May 03, 2014 at 11:23 PM · shadershadersspecular

Adding specular to shader

Can someone help me add specular to this shader i have no experience with shaders. thanks in advance i cant really go on with my project without this. Shader "Triplanar Textures/Triplanar Local (Bumped)" {

     Properties {
     _Color ("Diffuse Color", Color) = (1.0, 1.0, 1.0, 1.0)
     _Tiling ("Tiling", Float) = 1
     _TexTop ("Top (RGB)", 2D) = "white" {}
     _BumpTop ("Top (Normal)", 2D) = "white" {}
     }
     
 Category {
     SubShader { 
     //#Blend
     ZWrite On
     //#CatTags
     Tags { "RenderType"="Opaque" }
         //Tags { "RenderType"="Opaque" }
         //#LOD
         LOD 400
         //#GrabPass
         CGPROGRAM
         //#LightingModelTag
         #pragma surface surf BlinnPhong vertex:vert 
         //alphatest:_Cutoff
          
         //#TargetSM
         #pragma target 3.0
         #pragma multi_compile_builtin
         //#UnlitCGDefs
         float _Tiling;
         sampler2D  _TexTop;
         sampler2D _BumpTop;
         float4 _Color;
         
         struct Input {
             //float4 vertex;
             //#UVDefs
             //float3 normal;
             //float2 uvCoords;
             float3 localPos;
             float3 mylocalNormal;
             INTERNAL_DATA
             half3 signs;
         };
         
         void vert (inout appdata_full v, out Input o) {
             o.mylocalNormal = v.normal;
             o.localPos = v.vertex;
             o.signs = sign(o.mylocalNormal);
         }
         
         void surf (Input IN, inout SurfaceOutput o) {
             half3 signs = IN.signs;
             half3 signs2 = IN.signs;
             float4 bumpBase = float4(1.0, 1.0, 1.0, 1.0);
             float4 texBase = 1.0;
             
         //Assign UVs            
             half2 s = float2(_Tiling/10, _Tiling/10);
             half2 tex0 = s * IN.localPos.zy;
             half2 tex1 = s * IN.localPos.zx;
             half2 tex2 = s * IN.localPos.xy;
             half2 tex3 = s * -IN.localPos.zy + 1;
             half2 tex4 = s * -IN.localPos.zx + 1;
             half2 tex5 = s * -IN.localPos.xy + 1;
         
         // =========================
         //         Assign Your Textures Here.
         //        (Don't forget to declare them at lines 33 & 34...)
         // =========================
             half4 color0_ = tex2D(_TexTop, tex0).xyzw; 
             half4 color1_ = tex2D(_TexTop, tex1).xyzw; 
             half4 color2_ = tex2D(_TexTop, tex2).xyzw;
             half4 color3_ = tex2D(_TexTop, tex3).xyzw; 
             half4 color4_ = tex2D(_TexTop, tex4).xyzw; 
             half4 color5_ = tex2D(_TexTop, tex5).xyzw;
             half4 ncolor0_ = tex2D(_BumpTop, tex0).xyzw; 
             half4 ncolor1_ = tex2D(_BumpTop, tex1).xyzw; 
             half4 ncolor2_ = tex2D(_BumpTop, tex2).xyzw;    
             half4 ncolor3_ = tex2D(_BumpTop, tex3).xyzw; 
             half4 ncolor4_ = tex2D(_BumpTop, tex4).xyzw; 
             half4 ncolor5_ = tex2D(_BumpTop, tex5).xyzw;    
             
         // Calculate projections
             half3 blendWeights = IN.mylocalNormal;
             blendWeights.x = max(IN.mylocalNormal.x, 0);
             blendWeights.y = max(IN.mylocalNormal.y, 0);
             blendWeights.z = max(IN.mylocalNormal.z, 0);
             half3 blendBottom;
             blendBottom.x = min(IN.mylocalNormal.x, 0);
             blendBottom.y = min(IN.mylocalNormal.y, 0);
             blendBottom.z = min(IN.mylocalNormal.z, 0);
             blendWeights = saturate(pow(blendWeights*0.25, 10));
             blendBottom = saturate(pow(blendBottom*0.25, 10));
             half3 blendMult = 1/(blendWeights.x + blendBottom.x + blendWeights.y + blendBottom.y + blendWeights.z + blendBottom.z);            
             blendWeights *= blendMult;
             blendBottom *= blendMult;        
         
         // Combine all that stuff...
             texBase = 
             (color0_ * blendWeights.x) + (color3_ * blendBottom.x) +
             (color1_ * blendWeights.y) + (color4_ * blendBottom.y) + 
             (color2_ * blendWeights.z) + (color5_ * blendBottom.z);
             
             bumpBase = 
             (ncolor0_ * blendWeights.x) + (ncolor3_ * blendBottom.x) +
             (ncolor1_ * blendWeights.y) + (ncolor4_ * blendBottom.y) + 
             (ncolor2_ * blendWeights.z) + (ncolor5_ * blendBottom.z);
         
         // Assign results to shader.
             o.Albedo = texBase.rgb * _Color;
             o.Normal = UnpackNormal(bumpBase);
         }
         ENDCG
         }
     }
     FallBack "Triplanar Textures/Triplanar Local"
 }
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

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

20 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

Related Questions

Why are Cubemaps and Specular highlights not equally blurry at the same Roughness / Glossyness value with standard pbr shader? 0 Answers

how to do color separation in specular reflections 1 Answer

Why does the 3D Text shader show specular at certain angles? 2 Answers

UnityObjectToClipPos is inverted? 0 Answers

Unity 5 fragment shader that writes custom depth into the depth texture 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