The past solutions to this problem don’t seem to be working for me now.
I tried importing the old boat shader from the wiki, and that didn’t work. These shaders are from that wiki.
Also, the Hollowed Mountain solution doesn’t seem to work anymore either. I haven’t downloaded it and tried it since 2.6, but people posting to that thread are saying its not working any more.
My walls are plain geometry with a plain default diffuse shader.
I put this shader for a material for a plane in front of the wall, or it should work inside the wall or behind the wall also I think:
Shader "Masked/Mask" {
SubShader {
// Render the mask after regular geometry, but before masked geometry and
// transparent things.
Tags {"Queue" = "Geometry+10" }
// Turn off lighting, because it's expensive and the thing is supposed to be
// invisible anyway.
Lighting Off
// Draw into the depth buffer in the usual way. This is probably the default,
// but it doesn't hurt to be explicit.
ZTest LEqual
ZWrite On
// Don't draw anything into the RGBA channels. This is an undocumented
// argument to ColorMask which lets us avoid writing to anything except
// the depth buffer.
ColorMask 0
// Do nothing specific in the pass:
Pass {}
}
}
And I put this shader on the window itself :
Shader "Masked/Diffuse Masked" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
// This shader does the same thing as the Diffuse shader, but after masks
// and before transparent things
Tags {"Queue" = "Geometry+20" }
UsePass "Diffuse/BASE"
UsePass "Diffuse/PPL"
}
FallBack "Diffuse", 1
}
and nothing happens. What am I doing wrong? Or, does this not work in Unity 3?
Thank you both for your replies. I’m still stuck here.
Do you have a workaround that might help me?
Meh11: I put that shader on a cube by itself to simplify things and it still appears as a normal diffuse, appearing in front / behind objects as it normally would in space. Any more ideas?
But anything you write yourself in passes, can be referenced in a UsePass. I’ve got an entire game running off one shader file that contains the passes and the shaders I use just UsePass-ing the relevant passes I need.
Can you open the Diffuse shader up and check what it’s Queue settings are? Just to be sure it’s not that.
Also, if you’re referencing the built-in diffuse shader (rather than your own replacement) for UsePass… it won’t work. It doesn’t have named passes as it’s a surface shader. So Meh11’s correct that it’s likely falling back to the regular Diffuse shader.
Try putting this in a shader file and applying this to your mesh (it’s the Diffuse shader, just with Geometry+20 Queue)…
Now it is pink without the fallback command. It wasn’t before I put in that latest shader.
I’ve gotten so good at programming since I’ve been using Unity. Lots of JS, switched to C#, object oriented, passing classes back and forth, organizing all the code, doing great. I can’t figure out why it’s so hard for me to learn shaders. Shouldn’t I be able to take one single shader and change the Queue tag and have this work?
Okay now this is interesting. I just noticed on this shader I get an error “! No subshaders can run on this graphics card.” Just to make sure I updated my drivers today, it’s a Nvidia geforce 9800 gt.
Shader "Masked/Diffuse Masked"
{
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
// This shader does the same thing as the Diffuse shader, but after masks
// and before transparent things
Tags {"Queue" = "Geometry+20" }
UsePass "Diffuse/BASE"
UsePass "Diffuse/PPL"
}
}
confused.
the error goes away when I put a fallback in there.
Great. You guys helped me do it. Thank you both so much.
Final shaders: for the window mask:
Shader "Masked/Mask" {
Properties {
_Color ("Main Color", Color) = (0,0,0,0)
}
SubShader {
// Render the mask after regular geometry, but before masked geometry and
// transparent things.
Tags {"Queue" = "Geometry+10" }
// Turn off lighting, because it's expensive and the thing is supposed to be
// invisible anyway.
Lighting Off
// Draw into the depth buffer in the usual way. This is probably the default,
// but it doesn't hurt to be explicit.
ZTest LEqual
ZWrite On
// Don't draw anything into the RGBA channels. This is an undocumented
// argument to ColorMask which lets us avoid writing to anything except
// the depth buffer.
ColorMask 0
// Do nothing specific in the pass:
Pass {}
}
}
for the window:
Shader "Masked/Diffuse Masked" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
// This shader does the same thing as the Diffuse shader, but after masks
// and before transparent things
Tags {"Queue" = "Geometry+20" }
UsePass "Diffuse/BASE"
UsePass "Diffuse/PPL"
}
FallBack "Diffuse", 1
}
I’m having a little trouble with the way the Mask renders with the skybox. It doesn’t render where the sky box is. You can see in the attached image a doorway on the right, which is regular geometry, and the door on the left which uses our mask. Through the mask the terrain renders normally, but the skybox isn’t showing up.
Now how to write that code in C#. I tried this in a script attached to the main camera, and it compiled:
void Start()
{
// set the render queue of the skybox:
Skybox mySky = gameObject.camera.GetComponent<Skybox>();
print(mySky);
mySky.material.renderQueue = 9;
}
It doesn’t throw any errors, but no matter what number I put in there, the problem persists.
I found the skybox shader, and am wondering what to do to adjust it to be visible through the mask shader above. Here’s the shader. of course it’s pretty long, but the answer should be something like changing the top to change the queue to Geometry+9 (tried, didn’t work by itself, nor other numbers), and change the ‘Render Type’ from background?
Sorry I need so much hand-holding for this process. At least this will be valuable for people who want to drop windows and doors in their buildings and such.