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 smnerat · Apr 16, 2013 at 04:03 PM · shadervertex

Adding shine/reflection to a vertex lit shader.

Hello,

So I've been trying to find and/or piece together a shader for quite a while now. In my game each cube gets its color from setting their vertices in the game. I have been using the mask tint - vertex lit shader that is below. I have been trying to attempt to add something to it.

(And heres the poor part of the question) I'm not sure what I am trying to add, basically I am trying to get a reflective metal look to my pieces. Due to my unfamiliarity with shaders, I've only been able to narrow down what I'm looking for from other shaders I've looked at. It seems like I need to add a specular or reflective aspect to my shader. I'm really not sure how to do this while still keeping my pieces colored via vertices. I can add specular/reflectiveness/shine to the shader but when I get it to work, they all just look like the original material that was put on them.

I would think this is possible (and probably easier than I'm making it out to be) but I'm just not sure how to do it. I'm hoping someone can provide some insight or direction. Below is a copy of the shader that I'm currently using.

Most of the properties are unused, I have them in my shader for when I try to add aspects of other shaders.

Thanks.

 Shader "Custom/TrialShader2" {
 
     Properties {
         _Color ("Main Color", Color) = (1,1,1,1)
         _SpecColor ("Specular Color", Color) = (1, 1, 1, 1)
         _Shininess ("Shininess", Range (0.01, 3)) = 1.5
         //_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
         _Gloss("Gloss", Range (0.00, 1)) = .5
         _Reflection("Reflection", Range (0.00, 1)) = 0.5
         _Cube ("Reflection Cubemap", Cube) = "Black" { TexGen CubeReflect }
         _FrezPow("Fresnel Reflection",Range(0,2)) = .25
         _FrezFalloff("Fresnal/EdgeAlpha Falloff",Range(0,10)) = 4
         _EdgeAlpha("Edge Alpha",Range(0,1)) = 1
         _Metalics("Metalics",Range(0,1)) = .5
         _MainAlpha("MainAlpha", Range(0, 1)) = 1
         _ReflectionAlpha("ReflectionAlpha", Range(0, 1)) = 1
         _TintColor ("Tint Color (RGB)", Color) = (1,1,1)
           _ReflectionTex ("ReflectionTex", 2D) = "white" { TexGen ObjectLinear }
         _MainTex ("Texture  (A = Tint Mask)", 2D) = ""        
     }
 
     SubShader {
     
         Pass {    // iPhone 3GS and later
             GLSLPROGRAM
             varying mediump vec2 uv;
             varying lowp vec3 color;
             
             #ifdef VERTEX
             void main() {
                 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                 uv = gl_MultiTexCoord0.xy;
                 color = gl_Color.rgb;
             }
             #endif
             
             #ifdef FRAGMENT
             uniform lowp sampler2D _MainTex;
             void main() {
                 vec4 texture = texture2D(_MainTex, uv);
                 gl_FragColor = vec4(texture.rgb * (color * texture.a + (1. - texture.a)), 1);
             }
             #endif        
             ENDGLSL
         }
     }
 
     SubShader {
     
         Pass {    // pre-3GS devices, including the September 2009 8GB iPod touch
 
             Material {
             Diffuse [_Color]
             Ambient [_Color]
             Shininess [_Shininess]
             Specular [_SpecColor]
             Emission [_Emission]
            
         }
     
         BindChannels {
             
             Bind "vertex", vertex
             Bind "color", color
             Bind "texcoord", texcoord    
         }
         
         SetTexture [_MainTex] {
                 constantColor [_Color]
                 Combine texture * primary DOUBLE, texture * constant}
                 
          SetTexture[_Cube] { constantColor(0,0,0, [_ReflectionAlpha]) matrix [_ProjMatrix] combine texture * previous, constant}     
                     
         }
     }
 }
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 smnerat · Apr 17, 2013 at 01:04 AM 0
Share

Alternatively, can anyone recommend a different shader?

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

11 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

Related Questions

Need help with using world position in shader 1 Answer

Vertex program max instructions limit 2 Answers

Z-priming alpha-per-vertex 0 Answers

Strange artifacts on Vertex Color Shader 0 Answers

Shader Shininess based on vertex color 0 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