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 hawken-2 · Dec 08, 2011 at 06:40 PM · shaderverticesvertex shader

real time vertex shading / color or transparency by vertex height

I have a plane that has many vertices. I have been playing around with a script that deforms the plane by moving the verts up and down (terrain) on run time to deform the plane.

I was wondering if it's possible to change the assigned material's color or transparency by each vertice by its height in run time? With the plane's Y 0 being neutral and transparent or particle/multiply. Then a vertices deviance would add +3 = white -3 = black etc. (imagine snowy peaks and dark troughs.)

Really not good with shaders... any clues welcomed.

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 ScroodgeM · Jul 19, 2012 at 07:37 PM 0
Share

easy to implement. is it actual?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by devin8 · Jan 03, 2013 at 10:06 PM

I made this shader for practice.

 Shader "Custom/HeightShader" {
     Properties {
         _MainTex ("Main Texture", 2D) = "white" {}
         _CenterHeight ("Center Height", Float) = 0.0
         _MaxVariance ("Maximum Variance", Float) = 3.0
         _HighColor ("High Color", Color) = (1.0, 1.0, 1.0, 1.0)
         _LowColor ("Low Color", Color) = (0.0, 0.0, 0.0, 1.0)
     }
     SubShader {
             Tags { "RenderType"="Opaque" }
             Cull Off
             
             CGPROGRAM
             #pragma surface surf Lambert vertex:vert
             #include <UnityCG.cginc>
     
             float _CenterHeight;
             float _MaxVariance;
             float4 _HighColor;
             float4 _LowColor;
             sampler2D _MainTex;
             
             struct Input{
                 float2 uv_MainTex;
                 float4 color : COLOR;
             };
             
             void vert(inout appdata_full v){
                 // Convert to world position
                 float4 worldPos = mul(_Object2World, v.vertex);
                 float diff = worldPos.y - _CenterHeight;
                 float cFactor = saturate(diff/(2*_MaxVariance) + 0.5);
                 
                 //lerp by factor
                 v.color = lerp(_LowColor, _HighColor, cFactor);
             }
             
             void surf(Input IN, inout SurfaceOutput o){
                 o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * IN.color;
             }
             
             ENDCG
     }
     FallBack "Diffuse"
 }

Here's the result..
alt text
You can tune a lot of parameters including center height, variance, colors at extremes and also apply a general texture. This shader also interacts with lights.

Cheers


shader.png (27.4 kB)
Comment
Add comment · Show 1 · 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 LucasTejero · Aug 06, 2014 at 07:43 PM 0
Share

Devin thank you very much for share your shader!!

avatar image
0

Answer by Piflik · Jul 19, 2012 at 08:03 PM

Not sure how to do this with a shader, but you could probably do this with a simple gradient and some UV operations. (each vertex would get an arbitrary U coordinate, the V coordinate would be the height, normalized, so it is between 0 and 1)

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

6 People are following this question.

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

Related Questions

Vertex Shader problem with _WorldSpaceCameraPos 1 Answer

Painted Vertices are Blockly, Looking to smooth them Out 1 Answer

How can I get the attenuation value of a spotlight in a shader? 0 Answers

Setting and storing vertex locations in a shader 0 Answers

Screen shaders that alter geometry at runtime or through camera 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