I am beginner to ShaderLab, so excuse me if my problem is trivial. I am thinking of a shader, which would be a mask for another shader. I know how to write a shader, which encapsulates both textures (mask + masked), but have no idea how to create materials for separate textures/objects.
If you take a look at the pictures, the situation would be:
Plane1 has alpha texture with mask shader,
Plane2 has some other texture with ie. diffuse shader,
Plane3 has texture with masked shader.
I would like the outcome for each pixel to be something like this:
color = Plane3.color * Plane1.alpha + Plane2.color * (1 - Plane1.alpha)
If anything appears on mask texture, Plane3 is rendered.
Depth mask seems to be solution, but it provides binary alpha, which is unacceptalbe for me. Anyone could help me with this?
This is exactly what I’m looking for, except for I need two or more shaders. One of them would be mask shader (Plane1), and other shader(s) would provide input for the mask.
I don’t think I understand what it is you’re trying to do. Do you want each of the the input textures to be rendered before passing them into the shader I linked? You could do that using separate cameras which render to texture. You could then render each texture using whatever shader you like. However, I don’t see the point of rendering a texture using for example the diffuse shader you mentioned: diffuse lighting applies to geometry, not textures. Also, I have no idea what a ‘mask shader’ is.
on three planes in Unity. Referencing this example:
First plane (farthest from camera) would have flowers texture,
Second plane would have black texture,
The last and topmost (closest to camera) would be mask plane.
User input would affect mask plane position only.
Maybe my approach is wrong here, and there’s easier way to obtain this effect?
Your first plane should be the one with the flowers on it. Make a second plane on top of that and attach a material to it with the Particles/Multiply shader on it. Put a texture with the shape of your mask area in the shader. If your texture is set to Clamp, you can play with the tiling settings of the texture in the shader to control its size and location within the plane.
The texture should be black and white (no alpha channel needed). Black is fully masked, white is fully visible, grey values are in-between.
Make sure the mask plane is at least 3x as big as the background image and has the mask exactly in the center. Move the mask by letting the user control the (x, y) coordinates of the mask plane.
Note that this will not include the blur effect present in your example. You would need an image processing shader (and Unity pro) for that.