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 jchow · Oct 04, 2013 at 01:20 AM · shadermaterialcompile

anything obvious wrong with my multi_compile?

Hi, I'm trying to get multi_compiled materials working. I'm having trouble figuring out why it doesn't seem to be executing the code within my #if block. First, here's my shader:

http://screencast.com/t/RLM7XR6JE

Here's what the 'shaderKeywords' property of my material looks like: http://screencast.com/t/Qx1wDMdmvdP (Note "OCCLUSION_ON" as the sole entry in the list)

However, the code inside my OCCLUSION_ON block doesn't appear to be executing ( my alpha is at full 1.0). However, if I comment OUT the #if/#endif directives, my meshes look properly faded out. Does anyone see anything obviously wrong with my shader, or how I'm using the #if directive? I've tried:

 #if OCCLUSION_ON
 #ifdef OCCLUSION_ON
 #if defined(OCCLUSION_ON)

with no change. Does anyone have any ideas? Thanks in advance!

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
0

Answer by reefwirrax · Oct 06, 2013 at 08:21 AM

I dont know, it looks right, try switching it on and off with this:

 using UnityEngine;
 using System.Collections;
  
 [ExecuteInEditMode]
 public class ShaderManager : MonoBehaviour {
  
     // Store the camera
     public Camera cam;
     public Texture2D tex;
  
  
     // Before the object gets rendered
     public void OnWillRenderObject ( ) {
  
         cam = Camera.current;
  
         if( !cam )
             return;
  
         Shader shader = renderer.sharedMaterial.shader;
     }
  
     void OnEnable() {
  
         Shader.EnableKeyword("IS_SIMPLE"); // My custom keyword
     }
  
     void OnDisable() {
  
         Shader.DisableKeyword("IS_SIMPLE"); // My custom keyword
     }
 }

i am running this:

[CODE]#pragma multi_compile VERSION_ONE VERSION_TWO

ifdef VERSION_ONE

   some maths

endif

ifdef VERSION_TWO

  some other maths

endif[/CODE]

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 jchow · Oct 15, 2013 at 06:47 PM 0
Share

Thanks reef, but I'm looking for a per-material keyword override so I need to use render.sharedmaterial.shader$$anonymous$$eywords. I can't set them on a global basis (Shader.Enable$$anonymous$$eyword) because that defeats the purpose of a single shader that does different things :)

avatar image
0

Answer by jchow · Oct 15, 2013 at 07:23 PM

Yay I think I got it. You have to supply a keyword for every multicompile defined in your shader. It's not enough to supply

[ "OCCLUSION_ON" ]

you have to do

[ "OCCLUSION_ON", "FOG_OFF" ]

Unity's example only contains one keyword ("REDIFY_ON") so it wasn't very clear

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

15 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

Related Questions

Building a Unity 5 Standard Material at runtime 3 Answers

Material doesn't have a color property '_Color' 4 Answers

How come edititng "_Glossiness" through script doesn't work? 1 Answer

Represent Land 3D Area End 0 Answers

Glowing material/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