Make pixel lighting like terraria and starbound - unity3d

I'm making a 2D sandbox game like "Terraria" and "Starbound". This is my game
The light is filling the whole terrain but i don't want it. I want following:

You're probably using Directional Lighting, which illuminates the whole terrain equally in the direction you made it.
You could use Spot Lights or Point Lights, which will illuminate only the surface you want to.
Edit: although using this method, this could take way more resources due to the number of single lights placed throughout the map.

Related

Recommendations for clipping an entire scene in Unity

I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.

2D Sprites in Isometric 3D Unity Project

The project works under a isometric orthographic camera, in a 3d space using 2d sprites.
What we are using are billboarding sprites into 3D colliders to archieve the 3d feeling.
The problem is that we don't really believe the way we are doing it it's the most optimal. We are also having problems introducing high areas, because we need to reply the sprite form in isometric perspective as colliders.
Because we are using 3D world, the tilemaps tools conflicts with the other vertical sprites.
We can not use a entire 2d floor billboarding sprite because that suposes to have a huge vertical sprite in front of the camera, so we can not display the others.
We are just researching for a solution before to change to a 2D world.
If you plan on sticking with isometric in 3D, get rid of the tilemaps entirely. They are just going to give you a headache and make your game lag itself to death. If you want to convert to entirely 2D isometric, you can stick with them as they would work fine. Now, a few comparisons between the 2D and 3D approaches, and how best to approach them. This is a jumbled list of drawbacks/advantages to each type, so it's more of a ramble after this point than an answer, but I couldn't be more specific without knowing more about your project's overall requirements and specifications.
Unity recently added Isometric Tilemapping as a dedicated feature. So, if you choose to fake it with 2D, your life will be a lot easier.
Controls are a lot easier in 3D, as the physics won't ever have to be
faked.
3D allows foreground objects to automatically cover up background
objects without having to add an arbitrary system to achieve the same
effect.
2D is fundamentally faster than 3D, and if you're aiming for mobile,
that's going to be very important to your project's success.
3D allows you to rotate your camera if you design it right. (Check out Don't Starve Together for an example of this design).

How can I use baked lighting on sprites? / How to light up a large area in 2D?

I'm having trouble figuring out how to light up large area(s) of sprites in Unity 2D. My previous knowledge on Unity's lighting is zero.
I first tried using a large amount of point lights and using the "Sprites/Diffuse" material, but about only five would actually render at a time, so I guess there's a limit on that.
Then I tried putting in an area light. That didn't do anything, so that's when I started doing research about baked lighting on sprites (and baked lighting in general). I found stuff like this but I couldn't get it to work either because it's outdated or because I don't know what I'm doing. Other answers I've come across seem to assume that the reader knows anything about lighting in Unity in the first place which, to be honest, I don't. Unity's documentation website had some information on it, but no tutorials that go into how to set up baked lighting.
I've tried a bunch of different combinations of materials (like using the "Standard" shader for the sprites instead of "Sprites/Diffuse", emission, ect.) and I enabled "Baked Global Illumination" in Lighting>Settings.
If baked lighting isn't possible on sprites (or isn't worth the trouble), what are the alternatives?
Edit: I made sure not to have the lights pointing the wrong direction, and I do realise that Unity2D is just like painting onto a piece of paper in Unity3D. I was able to get point lights to work, but only a few at a time. I don't need to do the entire screen at once, I need to do a large specific area at once.
some tips...
working with sprites your in 2d... when you add a light, switch to 3d mode, and rotate to make sure your light is pointed at your objects, and oriented so as not to be on the same plane, or level with them, as this will cast all the light behind them.
if your trying to light up everything on the screen(in camera) attach an area light to the camera at the cameras position, point it where the camera points, and then in the inspector on the right, you can change its variables. intensity, range, width, height etc.
Emissive Texture:
https://www.youtube.com/watch?v=oa6kW5HhRd4
For some reason, I never even thought about going into the asset store. I found this for free, and it looks like it will work: Light2D.

Unity Mesh Deformation with Collisions

How to access the 2D mesh of a sprite by code then change the shape of the sprite?
I want to make a game similar to Agario
I just was wondering how to achieve this jelly form when touching objects either by collisions or triggers ?
I would like to see more answers.
Scaling won't get you the kind of deformations you want. Coding deformations the way agar.io does it from scratch is quite difficult. I can see multiple ways of doing this, so I'm going to list them from most recommended to least recommended:
Start with a flat 3D mesh and render your sprite on it as a texture so you basically get a billboard. Then use collision events to get the contact points and use math to figure out how to move the mesh's vertices in response to the contact. You can see someone achieving that effect here and you can see a full blown tutorial for a sphere here, a highly recommended read. Your idea with getting the line from the center of the circle via the contact position and decreasing its length is sound, though the implementation is a bit more complex than that if you want it to behave like agar.io.
Get Anima2D, a free asset that can among other things convert sprites to meshes. Then again use collision events to get the contact points and distort the mesh.
Use Anima2D or a different asset with equivalent capabilities and figure out how to use 2D bones in order to get something like agar.io's effect. You could also try 3D bones on a plane/billboard mesh.
Send the collision data to a vertex shader that is programmed to deform the thing it's rendering.
you can contact gameobjects with Trigger function. That function is working automatically with GameObject's tag names. Here is how you can get Triger function
And also you can change size of GameObjects when they touch each other
More info about scaling
you can code almost anything you want and here is about Mesh of sprite

How to write a custom shader in Unity 3D that lights up a specific pixel or group of pixel?

I'm making a FPS game in Unity, and I want the environment to light up as the player is shooting on his environment.
So say I have a tree. First it would be entirely black or greyish, but if I shoot somewhere, I would see some green.
To accomplish this feature, I'm using a raycast to have the impact point and so I can access any renderer of the point that the player is shooting on.
I guess the next step would be to write a custom shader to light the exact pixel that is shot.
Do you have any idea how I could write this shader or another way of doing this effect?
Regards
If you are using deferred rendering: Deferred decals.
If you are using forward rendering: Projectors.
If you need some more advanced "paint-like" functionality, use render textures coupled with RaycastHit.textureCoord to get the exact UV coordinate at your ray intersection point. You can draw stuff to render textures using Graphics.Blit. Check out this github project for some inspiration on how to do this.