Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Oct 24, 2017 at 08:43 PM by Khena_B for the following reason:

Putting this aside for now

avatar image
0
Question by Khena_B · Oct 22, 2017 at 09:04 PM · shaderrendertexturealphamasklights

Shader problem with 2D fake lighting

Hey,

I'm rendering my game on a rendertexture, i'm also rendering some black sprites with the Layer tag "Masks" on a second rendertexture against a white background, in shader i'm lerping between my game rendertexture and a black color, using the "mask" rendertexture as the lerp's alpha, the black color is shadowing my scene and the sprite masks act as 2D lights, digging in that shadow.

I'm trying to have some sprites not be affected by this shadow, but still render behind some of the sprites that are affected by it, the only solution i can think of is having that sprite have a second identical black sprite that acts as a mask, but that will also cut through the shadow while the sprite is behind other sprites, and the only solution that i can think of for that is for those other sprites to have a second identical white sprite that acts as a counter-mask.

I'm trying to find an alternative to having to add a mask to each sprites in the game, could this somehow be done in shader instead?

Here's a detailed visual explanation:

alt text

alt text

Some help would be extremely appreciated.

2dlights.png (199.7 kB)
dagger.png (368.8 kB)
Comment
Add comment · Show 3
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 theLittleSettler · Oct 23, 2017 at 12:54 PM 0
Share

have you looked at replacement shaders?

avatar image Khena_B theLittleSettler · Oct 23, 2017 at 05:53 PM 0
Share

I'm not sure what a replacement shader is, i'll look it up, thanks for the suggestion.

avatar image Khena_B theLittleSettler · Oct 23, 2017 at 09:45 PM 0
Share

I've looked at replacement shaders and tried them a bit, they're really interesting but i don't see how they can help me in this case, maybe if you could give me an example that would help me get started.

1 Reply

  • Sort: 
avatar image
0

Answer by Petroglyph · Oct 23, 2017 at 11:39 PM

Hello KhenaB!


Why not having all the "shadow-free" objects in a separate layer, rendered exclusively by a second camera with a higher depth than your main camera? In this setup, the main camera would be say depth 0 with a culling mask including everything but the shadow-free objects. It would have the post-render process that you currently use to add shadows. Then the second camera with eg. depth 1 would add any objects it renders over the scene, but still occluded by the scene. It is a setup I used several times and it worked well for my needs. Do you think that would work for you?


Your game looks cool, by the way!

Comment
Add comment · Show 6 · 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 Khena_B · Oct 23, 2017 at 11:56 PM 0
Share

Thanks for answering,

I've thought about doing this but i don't understand how those shadow free objects could be occluded by some of the other sprites rendered by the main camera, i blend all my rendertextures in one shader.

Thanks again

avatar image Khena_B · Oct 24, 2017 at 12:06 AM 0
Share

The part i don't get is "but still occluded by the scene", if i render the shadow-free objects on a separate rendertexture they will be rendered alone without the sprites that occludes them, so when i'll render that over the main scene and the shadows it won't be occluded!

avatar image Petroglyph Khena_B · Oct 24, 2017 at 12:49 AM 0
Share

I see, the setup I mentioned will work with both cameras rendering to the screen directly, and with a Blit on the $$anonymous$$ain Camera to achieve a post-process screen effect that applies shadows. Have you tried this? I'm not sure if it would break your setup.

avatar image Khena_B Petroglyph · Oct 24, 2017 at 12:58 AM 0
Share

I haven't, but it's important that my cameras output to a rendertexture, that is then captured by the final camera.

avatar image Petroglyph Khena_B · Oct 24, 2017 at 01:00 AM 0
Share

I am unsure about your setup, but I overlooked the part where you would blend all the RendertTextures in one shader. If so, then you have to check for depth buffer manually and do basically what a Blit does in itself.

I invite you to visit the Unity Doc for this function: https://docs.unity3d.com/ScriptReference/Graphics.Blit.html

I think you might find this an interesting lead. It seems to me it would be easier to achieve by letting the Camera render to screen and using their depth values though, but eitherway doable.

avatar image Khena_B Petroglyph · Oct 24, 2017 at 01:23 AM 0
Share

I'm rendering on a rendertexture because i'm rendering the game at a lower res, then upscaling, something like this: http://www.returnofthebrain.co.uk/pixel-perfect-virtual-camera-unity3d/

I'll give what you linked a read and see if it could be of any help, thanks again

Follow this Question

Answers Answers and Comments

112 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

Related Questions

Shader mask using greyscale instead of alpha? 0 Answers

Masked RenderTexture not working in WebPlayer 1 Answer

How to control the alpha output of vertex lit shaders? 0 Answers

Alpha values not blending in RenderTexture 2 Answers

shader problem 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