- Home /
Any way to access the Cascaded Shadow Map texture?
I want to perform some effects only on the shadowed areas of the scene.
Is there any way to access the shadows texture of the scene?
Answer by skovacs1 · Oct 04, 2010 at 05:30 PM
It's not that there is anything such as a shadows texture, necessarily. I think your understanding of 3D graphics may be a bit confused, but resolving that goes far beyond simply providing a solution to your use case.
There are 3 ways that you can really create shadows:
- Let Unity's rendering calculate shadows for you
- Create shadows in a projector
- Bake shadows into a texture or lightmap
How are you creating your shadows?
The general solution might be to author an image effect (Pro Only) which will detect shadowed areas based on some computation of what you see as shadowed. This depends on what you would define as shadowed and is quite subjective to your use case. One way could be to use the overall intensity of each pixel in the image for example.
If you are letting the renderer do your shadows, to apply effects to the shadowed areas, you could author a shader which computes the lighting component and performs your effect based on the value. You might consider doing this as a separate render with shader replacement.
If you are using projected shadows, then you could consider doing changes to your cookie or light. A shader solution above might also work. Anything more complex might generally require a second render pass and manipulation of a renderTexture (Pro Only) to get the pixels being hit by your shadow.
If you have baked shadows, you could apply effects to the textures in some script since they are just assets. You could also generally write a shader which gets the shadowed values from the texture or baked lighting texture and applies some effect based on that, but that's more expensive and needless when you could do the work in advance with a script you run in the editor beforehand. If your shadows are baked into your actual texture, depending on your effects, you could apply them directly to the texture where it is shadowed outside of Unity.
Some of this also depends on what kind of effects you are trying to accomplish. If they are just simple visual effects which change the surface's appearance with respect to lighting, you can generally achieve this with shaders. One shader which use to be used in case 1. and 2. was this desaturate darks shader, but it hasn't been updated for Unity 3 and would probably require some tweaking if not a full re-write into a surface shader. It works by getting the lighting component and applying some changes based on this value.
When I say shadow texture, I mean the cascaded shadow map that is generated from my main directional light. Specifically, "_Shadow$$anonymous$$apTexture" in the "Internal-PrePassCollectShadows" if that is even accessible. As a last resort I will consider calculating either a simple Lambert term or do a shader replace - render to texture with a white color. After I deter$$anonymous$$e what is in direct light, I'd like to mask (or exclude from calculation) SSAO in those areas.
_Shadow$$anonymous$$apTexture in Internal-PrePassCollectShadows? That sounds fairly low level and from my knowledge of Unity, inaccessible.
If you're trying to selectively omit objects from the SSAO image effect, then I'd recommend doing a quick render pass with replaced shaders (grayscale is fine) to render to a texture in your SSAO script's SSAO material and then in the composite pass of the SSAO shader, have it use the texture that you've added as a mask by doing something like multiplying the ao term by your mask's pixel values. This way wherever your mask says not to apply SSAO, it won't.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074704im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
shadow problems in unity5 1 Answer
Problems with unitys Particle: Fire_Complex from the Standart assets 0 Answers
How to solve Peter Panning (shadow offset) problem? 1 Answer
Optimize Shadows for Moving Light 0 Answers
Shadows not working 0 Answers