Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
2
Question by Bizio · Jul 22, 2020 at 09:51 AM · lighting3drenderingsprites

Using URP how to make sprites lit by 3D Lights again?

I'm working on 3D game and I converted my project to URP. Everything works fine expect sprites that previously were 'Sprite/Diffuse' so they were lit by 3D lights (kind of Doom style, 2D elements in 3D world, always facing you). But now 'Sprite/Diffuse' shader is not supported in URP, it converted my materials to use 'Universal Render Pipeline/Simple Lit' Shader which does not work with sprites, it's for textures. There is 'Universal Render Pipeline/2D/Sprite-Lit-Default' but it's only for using 2D Lights.

How do I make sprites littable by 3D lights again in URP?

Comment
Add comment
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

6 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Fuzzel_ · Sep 27, 2020 at 03:47 PM

As it stands right now you have to write your own sprite shader using the shader graph to create a sprite shader that interacts with regular 3d lights in a 3d world. It mostly works fine besides some problems with GPU instancing.

The main thing you need to do is the following:

  • To get the sprite set inside the sprite renderer you need a shader property called "_MainTex" (in the reference field, not the parameter name)

  • To get tiling and offset support for your texture you need to create a Vector4 parameter called "_MainTex_ST", and use those values to modify the values inside a Tiling and offset node. (The naming ist just a convention, but the _ST suffix is important to automatically generate tiling and offset fields in your custom ShaderGUI using TextureScaleOffsetProperty()

  • Multiply VertexColor with your SampleTexture node to get the color set in the sprite renderer.

When you want to use GPU instancing there are some additional things to consider though. Here are some of the annoyances I found myself with it while writing one for our game:

(This is based of URP 7.4.3 on 2019.4.2f1)

  • The flip X and flip Y toggles on the sprite shader do not work as these actually flip the vertecies of the underlying quad the sprite renderer creats, but these are somehow lost when using gpu instancing. So in order to regain fliping you have to manually write it in your shader and add a seperate component to your sprites that modify the MaterialPropertyBlock. Inside the shader you need to add either two booleans or a Vector2 for the flipping. How you actually flip them can be achieved through two different means:
    • Do the same as the original sprite renderer and flip the vertex positions. Important here is that you need to enable double-sided rendering and that you also properly modify your normals.

    • Flip the texture by flipping the UV properly. This lets you keep double-sideed rendering disabled, but requires that you use "Full Rect" for your sprites. If you use tight, the mesh for the sprite will not fit your flipped texture.

  • A similar problem with the sprite renderer not being able to modify the mesh it is rendering on while gpu instancing is enabled is the color, as this actually sets the vertex colors of the mesh. This is also broken and just stays white. So again like with the flip, create a seperate Color parameter in your shader and update it through your extra component on your sprite using the MaterialPropertyBlock.

  • Lastly, if you use GPU instancing, for whatever reason the normal of the sprite mesh gets inverted. Meaning it points backwards, which in turn makes your whole sprite black. So simply flip it along all 3 axis. Little bonus about this would be if you used the INSTANCING_ON keyword to check in your shader if GPU instancing is enabled and either flip or not flip your normals based on it.

Comment
Add comment · 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
1

Answer by narunsa · Nov 25, 2020 at 11:22 AM

I facing this problem

I set shader of my sprite material to Universal Render Pipeline/Lit and check on alpha clipping box

[1]: /storage/temp/171612-screen-shot-2563-11-25-at-182126.png


screen-shot-2563-11-25-at-182126.png (122.8 kB)
Comment
Add comment · 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
0

Answer by Davidjsap · Aug 11, 2020 at 12:49 AM

Did you find an answer to this?

Comment
Add comment · 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
0

Answer by JohnDoubleUB · Oct 19, 2021 at 10:19 AM

This'll do it! https://hananon.com/how-to-make-2d-sprite-cast-and-receive-shadow-in-3d-world-using-unity-shader-graph/?doing_wp_cron=1612697572.6477820873260498046875

Comment
Add comment · 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
0

Answer by JohnDoubleUB · Oct 18, 2021 at 06:49 PM

I found the top answer to be a little lacking in some of the specifics if you are like me and don't really know you're way around shaders all too well in unity. Luckily this page has a fantastic guide on how to do this (and it's far less wordy!) https://hananon.com/how-to-make-2d-sprite-cast-and-receive-shadow-in-3d-world-using-unity-shader-graph/?doing_wp_cron=1612697572.6477820873260498046875

Comment
Add comment · 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
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

225 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 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 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 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 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 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 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 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 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 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

Improving the look of Unique/User Planned Scenes 0 Answers

Render object only when illuminated by a specific light. 1 Answer

Make a sprite have the same color as the main light of the scene 1 Answer

Lighting 2d Sprites in 3d environment 0 Answers

Triangular Lighting Issue 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