- Home /
Global Shader Question
Right now Im applying a global shader that looks like overdraw mode using
Camera.SetReplacementShader();
That works fine, I can temporarily change everything in the scene to render with my overdraw shader when the function is utilized.
However, Now I have 2 gameobjects in the scene that are a type of tactical overlay. I dont want them to be rendered with my global overdraw shader like every other gameobject in the scene.
So is there a way to use Camera.SetReplacementShader() or something similar to apply a global shader to everything except one or two game objects? or am I out of luck because of the nature of using a global replacement shader?
Answer by Jessy · Jun 13, 2011 at 08:03 PM
There are a couple options I know of. The easiest is probably to just use a separate camera that renders only the tactical overlay mesh.
The other option involves a couple steps: you have to give your tactical overlay material a new replacement tag. (e.g. "RenderType"="TacticalOverlay"). In your replacement shader, you have to copy the SubShader(s) the tactical overlay is using. That way, the shader replaces the SubShader it had been using with identical code, and it only happens for that material.
http://unity3d.com/support/documentation/Components/SL-ShaderReplacement.html
The second way that you mentioned is the way that it needs to be done,However Im not sure how to set it up properly. The tactical overlay actually uses the Flare shader, everything else uses a normal diffuse texture.
So I tried using
Camera.main.SetReplacementShader(overdrawShader,"Opaque");
but when that runs, then nothing is rendered, the replacement tags are already built into unitys shaders right? The only user built shader Im using is the overdraw shader. Do I need to do anything special to that?
Actually when I read your response more clearly I think I got a better idea of what you where trying to say.
Are you saying that I need to copy the subshader code of the flare shader over to the subshader of my overdraw shader? $$anonymous$$y overdraw already has subshader properties so thats why Im confused about it.
Here is my overdraw shader:
Shader "Overdraw" {
Properties {
_$$anonymous$$ainTex ("Base", 2D) = "white" {}
}
SubShader {
Fog { $$anonymous$$ode Off }
ZWrite Off
ZTest Always
Blend One One // additive blending
Cull Off
Tags { "RenderType"="Overdraw" }
Pass {
SetTexture[_$$anonymous$$ainTex] {
constantColor(0.1, 0.04, 0.02, 0)
combine constant, texture
}
}
}
}
You're not using SetReplacementShader right. "RenderType" is the second argument, not "Opaque". Let me know if that clears things up for you.
Your answer
Follow this Question
Related Questions
Using a camera replacement shader but keeping the underlying (original) colors? -4 Answers
Replace shader at runtime 0 Answers
Help with multi-purpose replacement shader for camera 1 Answer
Shader Replacement not working with a very simple shader. 0 Answers
Problem with camera target texture and replacement shader 0 Answers