Hello,
I’m trying to copy point lights cubemaps to custom RT.
commandBuffer.Blit works only with dimension:tex2D
commandBuffer.CopyTexture(BuiltinRenderTextureType.CurrentActive, customCubemap) works correctly in case of the both textures have the same size.
But point lights shadow map size is variable (because it relative to distance to camera), so how can I get the current size of the BuiltinRenderTextureType.CurrentActive?
Found the solution.
if (currentLight.type == LightType.Point)
{
cmd.SetGlobalTexture("ShadowmapNameCopy", target);
var tex = (RenderTexture)Shader.GetGlobalTexture("ShadowmapNameCopy");
if (tex != null)
{
InitializeShadowMapTex(tex.width, dimension);
cmd.CopyTexture(tex, shadowMapRT);
}
}
It’s worked perfectly,
but why I can’t use “Shadowmap” and should create the name copy?
var tex = (RenderTexture)Shader.GetGlobalTexture("Shadowmap");//doesn't work
cmd.SetGlobalTexture("ShadowmapNameCopy", target);
var tex = (RenderTexture)Shader.GetGlobalTexture("ShadowmapNameCopy"); //works correctly
In render code I see that name:

Also I tried to use compute shader and it works
RWStructuredBuffer<int> _ShadowMapTexSize;
[numthreads(1, 1, 1)]
void GetShadowTextureSize(uint3 id : SV_DispatchThreadID)
{
uint width;
uint height;
uint levels;
ShadowMap.GetDimensions(0, width, height, levels);
_ShadowMapTexSize[0] = width;
}
int GetShadowTextureSize(CommandBuffer cmd)
{
if (computeShader == null) computeShader = (ComputeShader)Resources.Load("KWS_CopyShadowParams");
if (computeBuffer == null) computeBuffer = KWS_CoreUtils.GetOrUpdateBuffer<float>(ref computeBuffer, 1);
computeShader.SetBuffer(0, "RawTestData", computeBuffer);
cmd.SetComputeTextureParam(computeShader, 0, "ShadowMap", BuiltinRenderTextureType.CurrentActive);
cmd.DispatchCompute(computeShader, 0, 1, 1, 1);
var size = new int[1];
computeBuffer_GetShadowMapSize.GetData(size);
if (size[0] == 0 || size[0] > 4097) return -1;
else return size[0];
}
///
currentLight.AddCommandBuffer(LightEvent.AfterShadowMap, cmd);
But by some reason I get 0 and 1253252345 value in first frames and I have errors in some cases with different source and destination. =/
