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 /
avatar image
0
Question by TheMagican2 · Feb 16, 2016 at 02:46 PM · shadersblack

why does this custom shader not work?

i found this shader on a very old post and it was the thing i just needed, sadly i cant get it to work and i dont know why.

 Shader "Global-Mapper" {
     Properties{
         _PeakColor("PeakColor", Color) = (0.8,0.9,0.9,1)
         _PeakLevel("PeakLevel", Float) = 300
         _Level3Color("Level3Color", Color) = (0.75,0.53,0,1)
         _Level3("Level3", Float) = 200
         _Level2Color("Level2Color", Color) = (0.69,0.63,0.31,1)
         _Level2("Level2", Float) = 100
         _Level1Color("Level1Color", Color) = (0.65,0.86,0.63,1)
         _WaterLevel("WaterLevel", Float) = 0
         _WaterColor("WaterColor", Color) = (0.37,0.78,0.92,1)
         _Slope("Slope Fader", Range(0,1)) = 0
     }
         SubShader{
         Tags{ "RenderType" = "Opaque" }
         Fog{ Mode Off }
         Tags{ "LightMode" = "Always" }
         CGPROGRAM
 #pragma surface surf Lambert vertex:vert
     struct Input {
         float3 customColor;
         float3 worldPos;
     };
     void vert(inout appdata_full v, out Input o) {
         UNITY_INITIALIZE_OUTPUT(Input, o);
         o.customColor = abs(v.normal.y);
 
     }
     float _PeakLevel;
     float4 _PeakColor;
     float _Level3;
     float4 _Level3Color;
     float _Level2;
     float4 _Level2Color;
     float _Level1;
     float4 _Level1Color;
     float _Slope;
     float _WaterLevel;
     float4 _WaterColor;
     void surf(Input IN, inout SurfaceOutput o) {
         if (IN.worldPos.y >= _PeakLevel)
             o.Albedo = _PeakColor;
         if (IN.worldPos.y <= _PeakLevel)
             o.Albedo = lerp(_Level3Color, _PeakColor, (IN.worldPos.y - _Level3) / (_PeakLevel - _Level3));
         if (IN.worldPos.y <= _Level3)
             o.Albedo = lerp(_Level2Color, _Level3Color, (IN.worldPos.y - _Level2) / (_Level3 - _Level2));
         if (IN.worldPos.y <= _Level2)
             o.Albedo = lerp(_Level1Color, _Level2Color, (IN.worldPos.y - _WaterLevel) / (_Level2 - _WaterLevel));
         if (IN.worldPos.y <= _WaterLevel)
             o.Albedo = _WaterColor;
         o.Albedo *= saturate(IN.customColor + _Slope);
     }
     ENDCG
     }
         Fallback "Diffuse"
 }


i hope that some1 can help me with this

Comment
Add comment · Show 4
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 16, 2016 at 03:09 PM 2
Share

What's it supposed to do??

Check out this awesome WikiBook. Work through it (its quite straightforward) and by Chapter 2 you will have a good understanding of debugging shaders.

https://en.wikibooks.org/wiki/Cg_Program$$anonymous$$g/Unity

avatar image TheMagican2 meat5000 ♦ · Feb 17, 2016 at 10:33 AM 0
Share

its supposed to change collor depending on the y value for a terrain. like high thing become white and low things become green and lower is green for something like a beach

avatar image meat5000 ♦ TheMagican2 · Feb 17, 2016 at 11:15 AM 0
Share

So if I put this on a cube it should change colour based on the height of the terrain underneath it?

The first part of debugging a shader is finding out why its black and making it be anything other than black; to get you back in to the working range.

Some changes to shaders in Unity 5 broke old shaders, like some automatic 2x light intensity that used to be applied is not there anymore (or something to that effect).

avatar image Bunny83 · Feb 17, 2016 at 11:11 AM 0
Share

"cant get it to work" tells us nothing about your problem. Also like meat5000 said, it would make sense to actually tell us what the shader is supposed to do (which you did now in a comment but that information should be in the question).

Also you should describe what happens ins$$anonymous$$d and how your actual setup looks like. On what kind of object do you use that shader? Are you sure you set your levels correctly and the object is placed at the right "y" value?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TheMagican2 · Feb 17, 2016 at 03:54 PM

thank you so much, it was indeed the lighting. i removed

 Tags{ "LightMode" = "Always" }

and now its fixed and i can go on improving this shader. ty so much

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 meat5000 ♦ · Feb 17, 2016 at 04:14 PM 1
Share

Ok I said the word "light" but I can't claim credit. You found this on your own; good job ;)

i accepted the answer for you so you got some rep (You dont get it for accepting your own).

avatar image TheMagican2 meat5000 ♦ · Mar 12, 2016 at 11:13 PM 0
Share

litle bit late for my response but ty ^^

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

U5 shader coming out solid black on newer iOS devices (iPad 2 Air / iPhone 6) 1 Answer

Shaders do not work in build. 0 Answers

Aaah what happened to my Strumpy shaders? (all black after 3.5 final!) 2 Answers

Fresnel shader and mixed textures 0 Answers

Tutorials on shaders? 3 Answers


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