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 Earlybird · Feb 19, 2014 at 08:41 PM · shaderssurfaceshadervertexlitvertex-lit

Surface Shader not working when using Vertex Lit render settings?

Hi, Firstly yes I am new to the world of shaders, I have just about got my head around writing surface shaders but for some reason non of my shaders are rendering when the camera is set to vertex lit?

I have had a read around and think i now need to move onto fixed function shaders which seems a totally different shader language?

Is it true that surface shaders just wont work on vertex lit or is it down to the lighting set up and therefore can be configured to work in both set ups?

Thanks for any advice given I'm looking to learn and progress!

Here is the shader im working with:

 Shader "Custom/UV2AlphaMask" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _AlphaMask ("Alpha Mask (A)", 2D) = "white" {}
         _AlphaAmt ("Alpha Amount", Range(0,1)) = 0.5
     }
     SubShader {
         Tags { "RenderType"="Transparent"  }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert alpha
 
         sampler2D _MainTex, _AlphaMask;
         fixed _AlphaAmt;
 
         struct Input {
             float2 uv_MainTex, uv2_AlphaMask;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D (_MainTex, IN.uv_MainTex);
             half4 mask = tex2D (_AlphaMask, IN.uv2_AlphaMask);
             o.Albedo = c.rgb;
             o.Alpha = mask.a * _AlphaAmt;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }
 




update

As an example I found this shader as part of the unity default terrain shaders, is anyone able/willing to explain a little about how come this seems to be a mix of both surface shader and fragment shader? and possibly a nudge in the right direction for further investigation?

Thanks,

 Shader "Hidden/TerrainEngine/Details/Vertexlit" {
 Properties {
     _MainTex ("Main Texture", 2D) = "white" {  }
 }
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 200
 
 CGPROGRAM
 #pragma surface surf Lambert
 
 sampler2D _MainTex;
 
 struct Input {
     float2 uv_MainTex;
     fixed4 color : COLOR;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 
 ENDCG
 }
 SubShader {
     Tags { "RenderType"="Opaque" }
     Pass {
         Tags { "LightMode" = "Vertex" }
         ColorMaterial AmbientAndDiffuse
         Lighting On
         SetTexture [_MainTex] {
             combine texture * primary DOUBLE, texture * primary
         } 
     }
     Pass {
         Tags { "LightMode" = "VertexLMRGBM" }
         ColorMaterial AmbientAndDiffuse
         BindChannels {
             Bind "Vertex", vertex
             Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
             Bind "texcoord", texcoord1 // main uses 1st uv
         }
         SetTexture [unity_Lightmap] {
             matrix [unity_LightmapMatrix]
             combine texture * texture alpha DOUBLE
         }
         SetTexture [_MainTex] { combine texture * previous QUAD, texture }
     }
 }
 
 Fallback "VertexLit"
 }
 
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

2 Replies

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

Answer by Earlybird · Jun 25, 2014 at 10:54 PM

After some research I have discovered that the above is in fact two shaders contained inside one, rather a separate fallback if the first subshader is unable to render it will move to the next and try to render that. So in short the second shader contains its own fallback.

Surface shader wont render under vertex lit rendering due to them being per pixel shaders rather than just vertex lit shaders.

For vertex lit render path you should look into Fixed Function shaders.

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
avatar image
0

Answer by Ackerka · Aug 09, 2017 at 01:17 PM

I also had a problem of missing transparency in case of using legacy vertex lit rendering path. The surface was opaque instead of semi-transparent. Your posted hint led me to the solution which was to use the Legacy Shaders/Transparent/VertexLit shader for the semi-transparent game object instead of the Standard shader.

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

19 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

Related Questions

Why are some vertexLit shaders not working in the vertexLit rendering path? 0 Answers

Mobile Shaders 0 Answers

How to set up additive blending on a surface shader? 2 Answers

Surface shader with VertexLit causes black object 0 Answers

How to add Zbuffer to Custom Surface Shader 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