Hello, I am kind of new to shaders (my most advanced effect is a wiggly sobel outline effect)
Anyways, I wanted to add some cool effects to my shadows and there’s a texture in Unity called _ScreenSpaceShadowmapTexture. From my understanding, I can create lots of cool effects by multiplying my texture to this.
However I am not sure how to access this. Preferably I’d like this texture in a shader graph. So I have been trying to get it in RenderTexture somewhere.
My past attempts:
First, I tried to access the texture in my shader graph itself by using Texture2D Asset and referecing it as _ScreenSpaceShadowmapTexture (it didn’t work, I was getting an error that my texture was already defined.
Next, I came across some posts that directly reference the texture itself and copy it using Blit. But it seems like it stopped working based on this post.
In the end, I was able to use the following code to write some cameraColor information to my render texture.
Is there a way to get screen space shadow texture in this renderingData stage? I also tried to write some low level shaders but I am not that familiar with them, and my attempts gave me gray textures. Is there an easy way to get this texture? Sorry if some of the things that I said didn’t make too much sense! I learned about Blit, CommandBuffer and everything by trying to solve this issue haha
Thank you for your response, I really appreciate it. I linked your answer in my original question too. However this seems to give me a completely blank render texture Are you on unity version 2022?
The steps to create render texture are following, correct?
Project → Right Click → Render Texture → Attach to property
Interestingly, there seems to be correct data in the rt variable if you look over here
So I am not sure why it’s giving me a black render texture. Either I am setting something incorrectly, or Blit isn’t working. I messed around with my render texture settings too but it seems to not change anything. I appreciate your help
To create a render texture, use context menu in your project Create -> Render Texture then assign it to the shadowMapCopy property of this script in inspector by drag & dropping.
This script must be attached to your camera which does the rendering.
You also have to add the ScreenSpaceShadows in your renderer feature list, in your assigned URP renderer, which also has to be chosen as the renderer within your camera.
I think if all that seems correct to you, I might try to change Unity versions as this one seems to be cursed and I want my textured shadows haha. Thank you for helping me
It all indeed seems correct. Did you try settings a breakpoint in CameraRender method to check that it actually runs? It seems like nothing gets blitted in your case.
Also, do you see the unnamed command buffer in your frame debugger?
Yep, seems like that’s exactly the problem. Your command buffer isn’t being executed. That’s a good direction to dig into further.
You have the proper state within the rendering pipeline, you get the data because your RT isn’t null and we see no unnammed command buffer with your render texture in the frame debugger.
@HikeOnARainyDay I did some research and the only difference I see is that I render with multiple cameras, while you have only one camera and my camera with shadow map copy blit command is not the last one. So maybe it gets automatically submitted. Maybe you need to explicitly submit the command buffer? Look at this example
Adding a simple context.Submit() fixed it for me, thanks a lot!
On a slightly unrelated note, how do I get into CommandBuffers, RenderTextures and ScriptableRenderPipeline side of things in Unity? It seems like the API is constantly changing and I can’t find many tutorials on them. I tend to learn best through tutorials/courses, do you recommend any?
To be honest, all the courses and answers online date so fast, it’s hard to find something that’s gonna work right out of the box most of the time, unless it’s super trivial. And you’re already kinda in it, if you’re working on this stuff.