Question

I'm trying to build some simple game(learning) where you will have to clean objects. That means for example you have a monitor with dust on it so you can't see the image. You then uses mouse or finger to move arround monitor to make image visible.

So what I've got so far is 2 images first being the monitor image and second being the dust before it. I've managed to realize when user swipped all image down. But what would I like to do is when user tap the screen somewhere only in that radius r the front image disappears.

I'm guessing I should be using layer mask, but I have no idea how to do it.

I basicly managed to write my own shader that only shows layer with correct image but no idea how to do that you can accualy get some cool effect from it.

Any ideas will be apriciated!

Was it helpful?

Solution

I would use render texture for this. It allows you to use image files as a brush. And it's quite fast. The idea is to use render texture as a mask. You start with black texture. Whenever player touches the screen you render your brush image to this texture. But this feature (render textures) is available only in Unity Pro.

You can still use texture as a mask if you don't want to buy Unity Pro. But this will be definitely slower than render textures. How much slower I don't know. The options are:

  1. Create ordinary texture (Texture2D) and use SetPixel or SetPixels to update mask when player touches the screen. If you want to go this way, I would recommend to use much smaller texture than the screen size (4x, 8x depends on the quality you want to get). Otherwise it will be damn slow.
  2. Create ordinary texture (Texture2D) and use ReadPixels. This works pretty much the same way as render textures but it's slower. This technique is explained here.

Using render texture (requires Unity Pro)

Ok. I've made an example: https://drive.google.com/folderview?id=0B60e_iFEZd1-RlB4LVN6NE84clU&usp=sharing There are:

  • Image that player needs to clear from dust: Image.jpg
  • Image of dust that we draw on top of it: Dust.png
  • Image that we use as an erasing brush: Brush.png
  • Our render texture that we use as mask for dust: Mask.renderTexture
  • Shader that we use to update the mask: MaskConstruction.shader
  • Shader that we use to render dust (it combines Dust.png and render texture): Masked.shader
  • Script that brings everything to life: MaskCamera.cs
  • Main scene: Main.unity

OTHER TIPS

I think this might be helpful. The Main objective of this Code sample is to create a dust/fog removing effect using Unity. Using, Texture Masking shader, Mask Construction Shader, Render Texture, Camera Masking Script and masking camera, you can create your own effect. Read on to know how and download the source code. It’s free!!

http://studio.openxcell.com/remove-dustfog-object-unity-swipe.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top