Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by AkashicMike · May 01, 2015 at 04:07 AM · shadersshadowmap

Sampling the cascaded shadow maps in a shader

I'm writing a fog volume shader that simulates light scattering and crepuscular rays. I figured the best way to do this would be to sample the depth shadow maps that get generated in the Shadows.RenderShadowmapDir just like the CollectShadows step does, so I wrote a shader that uses a lot of the same code (i.e. from Internal-PrePassCollectShadows)

Simple enough, right? However I just found out that _ShadowMapTexture now refers to the screenspace shadow map instead of the depth cascaded map that the shadow collect step uses, even though they use the same property name. This map isn't useful to me, I need that light depth information too. Some internal Unity step must have bound another render texture. Is there some way I can access that texture?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AkashicMike · May 04, 2015 at 08:59 AM

I just figured out a hack that gets me access to that texture, but I really doubt that this method is safe, supported, or portable in the least.

I figured that since the shadow depth map is being unbound after the collect shadows step, Unity is probably releasing it to the RT pool. If that's the case, then we just might be able to get it back by asking for a "temporary RT" that just so happens to match the resolution and format of the cascaded shadow map. The following code demonstrates this by drawing the shadow depth texture to the screen:

 int shadowMapID = Shader.PropertyToID ("_ShadowDepthMap");

 CommandBuffer commands = new CommandBuffer ();
 commands.name = "Hack up some render targets";
 Camera cam = Camera.main;
 cam.AddCommandBuffer (CameraEvent.AfterEverything, commands);

 // Ask the RT pool to give me a temporary RT that matches the properties of the cascaded shadow map
 // If all goes well, it should just give you the actual RT used for the shadow maps.
 commands.GetTemporaryRT (shadowMapID, 2048, 2048, 16, FilterMode.Bilinear, RenderTextureFormat.Shadowmap);
 commands.Blit (shadowMapID, BuiltinRenderTextureType.CameraTarget);
 

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 jpfranssen · Feb 05, 2016 at 02:45 AM

@AkashicMike not sure if you still need it but there may be a better more full-proof way.

https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.SetShadowSamplingMode.html

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to access shadow map depth values? 0 Answers

Shadow Maps - prevent updates 0 Answers

Possible to have certain objects in the scene cast shadows that have a different colour? 0 Answers

Get the light texture from a spotlight 0 Answers

Normalmap from height produces pixelated output 2 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