Hi guys,
Im trying to set a global texture with the scene UV (of the objects rendered).
This is done in a custom pass that draws every geometry again with an override material that displays the mesh’s UV as output and sets the result in a global texture. I don’t know if this is the best solution to get the scene UV, but I’m proud that I’ve made it by myself.
I use these UVs in a full screen shader graph to sample from another texture and, while in the scene view everything is fine, in the game view the texture is very pixelated.
Here you can see the pass:
UV Drawer Pass
private class UVDrawerPass : ScriptableRenderPass
{
Material m_UVMaterial;
RTHandle m_Target, m_TargetDepth;
List<ShaderTagId> m_ShaderTagIdList = new List<ShaderTagId>();
FilteringSettings m_FilteringSettings;
int m_SceneUVID;
public UVDrawerPass(Material uvMaterial)
{
m_UVMaterial = uvMaterial;
m_ShaderTagIdList.Add(new ShaderTagId("UniversalForward"));
m_ShaderTagIdList.Add(new ShaderTagId("LightweightForward"));
m_ShaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit"));
RenderQueueRange renderQueueRange = RenderQueueRange.all;
m_FilteringSettings = new FilteringSettings(renderQueueRange, -1);
m_SceneUVID = Shader.PropertyToID("_SceneUV");
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
var desc = renderingData.cameraData.cameraTargetDescriptor;
var descDepth = renderingData.cameraData.cameraTargetDescriptor;
desc.depthBufferBits = 0;
//desc.msaaSamples = 1;
//descDepth.msaaSamples = 1;
RenderingUtils.ReAllocateIfNeeded(ref m_Target, desc);
RenderingUtils.ReAllocateIfNeeded(ref m_TargetDepth, descDepth);
ConfigureTarget(m_Target, m_TargetDepth);
ConfigureClear(ClearFlag.All, Color.clear);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags);
drawingSettings.overrideMaterial = m_UVMaterial;
drawingSettings.overrideMaterialPassIndex = 0;
CommandBuffer cmd = CommandBufferPool.Get();
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings);
cmd.SetGlobalTexture(m_SceneUVID, m_Target);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
The Scene view is exactly what I want, while the Game view is very pixelated.
No, it’s not due to the scale of the view or the “Low resolution aspect ratios” checked.
With a vary basic material and a texture everything is fine, so it’s something related to my code or some hidden setting.
The full screen shader graph is very simple, just use the “_SceneUV” global texture to sample the input texture:
If I output the “_SceneUV”:
Why the Scene view is ok but not the Game view?