- Home /
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!
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]
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 :)
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
Your answer

Follow this Question
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