I am currently quite far into developing my 2d sandbox game and I am unhappy with the way my lighting is.
How my lighting works right now is, I have 2 Cameras:
A camera that sees the normal game view without any lighting
A camera that culls everything except that is on light/shadow layer
*those 2 missing images are the same as the one I reattached, somehow I can’t remove them, just ignore them
I take the light / shadow view and put a Gaussian Blur over it and merge that view with the game view.
This has some benefits, it is fast, was simple to implement, easy to create simple light blobs and there it already ends with the positive.
I have a few issues with this approach
The shadow is bleeding over to where it shouldn’t be
if a light source is not in the view, basically it doesn’t exist
Normal maps are impossible
more complex lights, like a flashlight cone, is impossible
I need an extra tilemap layer just to display shadows
This is basically the crux of it. I don’t really like the approach of Terraria where every tile has a light level and the light is quite blocky, I would like a more Starbound approach. Ideally I would like to make a custom Unity 2D light component that acts in the way I describe it, but I am still struggling with writing shaders, but I am willing to grind for it, if someone can give me a direction i can go.
You can fix this by
A)rendering with a larger camera and and only displaying a small part of it
B) render the lights etc. with a larger camera and use the smaller part of this light result
Kind of true, but at least for the example images, the light acts like a global light, which wont be effected by normals either
cant you just make a triangle light source(like a sprite light) and wont it act like a light? You’ll essentially be using the shadow map as a shadow and light map; where the darkest(color<128) areas are in shadow and brightest(color>128) areas are in a light source. In this case color = 128 would be no light or shadow
you could just put a screen sized sprite in front of everything for shadows(and normalless lights?). For normal maps, you’ll have to create a shader to sample the lights but I dont know you’d do this part. For unity’s 2d lights, I am pretty sure they have a list of lights visible by the camera and they just create shadow results, normal results etc. and just multiply(depending on your 2d urp asset’s 2d light settings). You can actually see some of this with the frame debugger.
are you sure starbound has normal lights? I havent taken a good look but the lights looks just like your solution imho
PS2:
If you are not going to use multiple colors for your lights, you can make the aforementioned single light/shadow texture a single channel texture, which’ll give you some memory + performance
Final note: Have you tested out unity’s own 2d lights for this project? I suspect it might just work apart from the fact your shadow casters will have sharp bases. You could even keep the current global shadow system and create 2d lights with unity’s own lighting system. 2023 has 2d soft shadows too btw
sorry for the late respond, i had some ideas i wanted to try based on your input.
The bleeding over of the shadows isn’t verry noticable at daytime, it is just a bit more dark around the boarders of the tiles, not a huge problem it jsut bothers me a bit
That is a good idea, shoud even be quite strait forward to implement
I had the idea that i convert my project to URP, as for now i am using Build-in, and combine my solution with Unity’s 2D lights for smaller lights, as they have a lot of stuff implemented that i want. The problem was tho that i have never realy worked with URP on a level like this and i have no idea on how to convet it. I managed to kinda make a Shader Graph that i coud use but failed to aply it to my main Camera
not realy shure what you mean by that
no i think they don’t use any, but it shoud make the visuals a bit more intresting and dynamic. for the global light i made, i don’t realy need it, as it just dimms and colors the light a bit depending on the time of day
didn’t read that part until now xD. yes that was my thougt too today, but like i sayed i have some truble converting the system to URP
There should be some guides online or in the unity docs. Just make sure you use a 2d renderer asset, or just copy paste the urp assets etc. from a new empty 2d urp project while following the guide
I mean that instead of actually using a new tilemap layer for shadows, you could just use a sprite that is scaled to match the screen size that will only contain black color in the shadowed areas, making the rendering rather simple. Now that I think about it, you’d need to use a render texture for this, which means you’ll need to use a 2d plane instead of a sprite. You can find more information about displaying the render textures online, but if things are already working with minimal performance impact dont worry about all of this.