Creating cleaning effect in unity3d - unity3d

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!

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:
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.
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

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

Related

How to handle a jank (non-uniform) spritesheet in Unity 2D

I'm trying to rip the among us textures into Unity, but I'm having trouble with the spritesheet for crewmate animations like walking, venting, idle, etc.
Here's the spritesheet I'm talking about: https://github.com/Overload02/among-us-assets/blob/main/Players/Player-sharedassets0.assets-55.png
You can see it is not consistent at all, making a uniform square or rectangle cut impossible.
What I tried originally is just creating all the boxes manually, but this looks terrible.
How does one handle this elagently?
Maybe you could use each sprite as a seperate image instead of a spritesheet. then you could edit the edges of each one seperately.

Custom 2D Lighting System in Unity

Ok so I've been trying to make a custom 2D lighting system in Unity, and I'm at that annoying stage where I know what I want to do but I'm not sure how to do it.
Here's the plan:
There will be dedicated light objects with their own meshes. These meshes determine the shape of the light.
Before the camera renders the whole scene, it does an extra render of just the light meshes with a black background to create a lightmap.
Then the camera renders the scene as normal (does NOT render the light meshes this time). Every object has a shader that will access the lightmap and shade itself appropriately depending on the color of the lightmap at that point.
That's the idea anyway. I sorta threw together a botched form of this. I used a separate camera to render the lightmap into a render texture with a culling mask so that it only rendered the light meshes, which are on their own layer. I then manually passed that texture to the shaders which use their screen uvs to sample from it.
This works sorta ok, but the scene view is completely messed up since it tries to light things as if you were looking at it from the perspective of the lighting camera. I feel like this would make the system hard to use, so I want to try to make some that feels a bit more cohesive.
Here's some screenshots to explain:
The tan-ish box is my "light," which gets rendered to the light cam, visible in scene. This next shot is what renders to the lightmap:
The black background is not from the big black box, the clear flag is just set to Black.
Now according to this lightmap, the middle of the screen should be lit up. and that's exactly what happens:
Notice that in the game view, since the light camera is set up with the same position/rotation/perspective settings as the game camera, it looks fine:
The main problem is figuring out that extra render. Is there anyway to create an extra pass for the main camera before the scene render that only renders the light meshes? I could probably figure out the rest from there. It would also be nice if I could make the lightmap a global shader variable, that way I don't have to pass it to each individual material, but one thing at a time, right?
Thanks so much to anyone who can shed some light on this subject. I'm still pretty new to shaders and rendering, so any help is much appreciated.
If I understand correctly, your problem is the appearance of your lights in Scene View, right ?
For that, you can create a custom Gizmos for them and hide the original objects. There's a tutorial:
https://learn.unity.com/tutorial/creating-custom-gizmos-for-development-2019-2#5fa30655edbc2a002192105c

Unity VideoPlayer with Subtitles

I was going to use the VideoPlayer to render to Camera Near Plane, but I also want to display subtitles for the video for the sake of accessibility. I'm wondering what the best way to do that is.
I can't see anything on a canvas if I render to Near Plane. I'd like the video to appear in front of the scene so that I can have the scene there once the video is complete.
Do I need to be using a render texture to achieve this? Seems like a render texture might incur some unnecessary overhead for my purposes, but I could be wrong.
The idea is this:
Far Background - Scene
Background - Black Image (so i can fade to scene)
Middleground - Video
Foreground - Subtitles
More info:
This is a 2D point and click adventure game with a pre-rendered cutscene.
You could do this with a render texture, place it in front of the camera at an exact distance and size, but I wouldn't. Probably would be a different camera anyway for lighting or clipping purposes.
I would use a second Camera, rendering over top of the Main Camera, with the subtitle UI's canvas targeting the second camera's screen space, and clearing depth only. It will render what it sees, but with a totally transparent background. Then, you can render your video on either the main camera's near plane or the new subtitle camera's far plane.
You could put your black square in front of this camera, too, though it would be in front of the video. It could be UI on the main camera, or stick a third camera in between them. You might have to worry about performance if there are too many cameras, but I have used two or three before to no noticeable performance hit.
Robert Mocks's answer is perfectly tenable and makes sense to me. Thank you for that!
What I decided to do instead was use a RawImage so that I wouldn't have to deal with extra cameras. This way I can use the canvas as I normally would and don't have to deal with render textures.
This involves using the API Only setting along with the following code:
rawImage.texture = videoPlayer.texture;
That seems to work well for me.

What objects and APIs would I use to fill the unity game window with custom graphics?

I need to build an app using Unity which doesn't use a traditional camera to generate the graphics. I'll build them using some custom shaders and a few cameras whose results get stuffed in rendertextures and then frobbed. (Think http://www.purplefrog.com/~thoth/art/kaleidescope/kaleid1.html but even weirder)
I'm not sure what objects I would put in the scene to accomplish this. In any normal app you just put a camera and point it at the right spot and Unity gets the pixels into the window, but that is just not how this thing will work.
I'm not sure if I should be using a UI Canvas or what APIs would be used to copy various render textures into the proper locations.
If you are not targeting WebGL you can create a RenderTexture of the proper size (maybe using RenderTexture.GetTemporary) and use Graphics.CopyTexture or other techniques to assemble the image you want displayed in the game window.
Once you have the pixels you want in the RenderTexture you can use Graphics.Blit(src, (RenderTexture)null); which will copy the pixels into the game window. These pixels will be stretched if the game window is not the same size as the RenderTexture.
This technique worked for me in the editor's game window, but when I compile it to WebGL, all I get is a mostly-grey screen with a really big black rectangle in the bottom left.

Implement Zoom(using UI Canvas) in Unity 2d game

I want to implement as showed in the below image in 2D game, I can find so many tutorials for 3D like mini map concept but for 2D i couldn't find anything. In my game i want to show a secondary
camera as in below image and also i need to zoom the content that will show through it. I developed one concept but it can be done with sprites or with Canvas in World Space mode. So you can see
they won't resize or positioned according to the screen resolution. If you guys have any idea how to do this task,it will be very helpful for me. And i also tried with depth mask shader .Thanks in advance.
Use a camera with target texture
Follow my tutorial here: Particles with Dynamic Text but disregard the parts about the particle system, they are irrelevant for you.
Once you've made a material, stop following the tutorial, and instead:
Create a sprite renderer on a canvas that is "Screen Space - Overlay" and set the material to be the one that you created.