Hi, I’m trying to make a full screen render pass shader to make a fixed visual distortion in front of the player’s eyes: like a swirl or a flawed lens. No matter what I try, I always end up with double vision, with the shader effect placed in the center of each eye rather than the center of the “screen”
I’m using Quest 2, and my shader looks like this:
The Render pass code looks like this - I got it from Claude so if anyone knows of any real examples that would be great.
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering.RenderGraphModule;
internal class ShaderRenderPass : ScriptableRenderPass
{
private Material material;
private class PassData
{
public TextureHandle source;
public Material material;
}
public ShaderRenderPass(Material mat)
{
material = mat;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
if (material == null) return;
var cameraData = frameData.Get<UniversalCameraData>();
if (cameraData.camera.cameraType != CameraType.Game) return;
var resourceData = frameData.Get<UniversalResourceData>();
var descriptor = cameraData.cameraTargetDescriptor;
descriptor.depthBufferBits = 0;
descriptor.msaaSamples = 1;
TextureHandle source = resourceData.activeColorTexture;
TextureHandle tempTex = UniversalRenderer.CreateRenderGraphTexture(
renderGraph, descriptor, "_ShaderTempTex", false);
using (var builder = renderGraph.AddRasterRenderPass<PassData>("Shader Effect", out var passData))
{
passData.source = source;
passData.material = material;
builder.SetRenderAttachment(tempTex, 0);
builder.UseTexture(source, AccessFlags.Read);
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
{
Blitter.BlitTexture(context.cmd, data.source, Vector2.one, data.material, 0);
});
}
// Copy back to active color
using (var builder = renderGraph.AddRasterRenderPass<PassData>("Shader Copy", out var passData))
{
passData.source = tempTex;
builder.SetRenderAttachment(source, 0);
builder.UseTexture(tempTex, AccessFlags.Read);
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
{
Blitter.BlitTexture(context.cmd, data.source, Vector2.one, 0, false);
});
}
}
}
