• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by BlueSin · May 11, 2015 at 01:03 PM · 2dshaderterrainlighting

Terraria / Starbound Style Lighting

So I am currently developing a 2D sandbox game similar to Terraria and Starbound. I would like to set up the lighting for the game at this point similar to that of the games mentioned above. I have never done lighting before so I am curious if there are any guides or methods or anything out there that anybody might suggest.

Here is what we have right now:

alt text

Lighting used is just a simple directional light. We are looking for something more like this:

alt text

As you can see in the second screen shot (Starbound), the light does not penetrate all the way through the terrain. Almost like a fog of war type of effect going on there, except instead of showing previously explored areas it only shows illuminated areas. I am curious how this effect might be achieved, any and all help is appreciated!

P.S. - We are currently using a mesh based system for loading chunks of blocks near the player. Block data is saved to map file in the form of an array of ushorts (for blockID) that makes up the front and back blocks.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

  • Sort: 
avatar image

Answer by Paul-Sinnett · May 11, 2015 at 03:16 PM

I guess if you're building the mesh yourself then you could probably do this by changing the vertex colours. Shared vertex colours between your cells would give you the gradients around the edges.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Cherno · May 11, 2015 at 03:50 PM

I assume that the level tiles are structures in a 2-dimensional array, and that each array position, i.e. each tile, has information about wehter it's filled (doesn't emit light) or not filled (emits light).

You would then go through each tile in the array, and if it's not filled, you then go through all the tiles around it in a certain tile radius. For each of those, you check if they are filled, and if yes, then determine the light amount of that tile by checking the distance between it and the original tile.

The "light", of course, might just be the alpha value of a material's color, which covers the whole scene.

For the rounded shadow shapes, you could alternatively go over each tile, and if it's not filled, use SetPixels() to clear the pixel of the shadow texture overlaying the scene in a radius.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by bluo100 · Jun 19, 2015 at 06:46 PM

Simply make a new 2D material with the sprites>diffuse shader and apply that to your terrain. In the lighting panel set the ambient color to a solid black and finally add lights whereever needed in the world making sure the lights are layered above the terrain they are illuminating.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rewrite shader so that the Sprite-Diffuse shader doesn't take incidence angle into consideration when applying lighting? 1 Answer

Better shader effects on terrain - Bumpmapping or Specular? 2 Answers

Unity 2D Shader Graph Sprite transparent when in shadow 0 Answers

2D Greyscale shader with lighting and color. 1 Answer

How can i make my unlit 2D toon shader get lights the way URP lit shader does 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges