I am using this script to flip the image rendered by the camera.
It works as expected. But as soon as I activate any Post Process effect on the same camera, those effects look totally broken and exaggerated. Without the flipping script the pp effects are ok.
Is there a way to have both the custom behaviour and the pp effects?
(I am using Unity 2019.1.7f)
Ok, I solved by implementing my own post process effect.
FlipCamera.cs:
using System;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
///////////////////////////////////////////////////////////////////////////
[Serializable]
[PostProcess(typeof(FlipCameraRenderer), PostProcessEvent.AfterStack, "Custom/FlipHorizontaly")]
public sealed class FlipCamera : PostProcessEffectSettings
{
}
///////////////////////////////////////////////////////////////////////////
public sealed class FlipCameraRenderer : PostProcessEffectRenderer<FlipCamera>
{
private static readonly Shader shader = Shader.Find("Hidden/Custom/FlipHorizontaly");
public override void Render(PostProcessRenderContext ctx)
{
PropertySheet sheet = ctx.propertySheets.Get(shader);
ctx.command.BlitFullscreenTriangle(ctx.source, ctx.destination, sheet, 0);
}
}
FlipHorizontaly.shader:
Shader "Hidden/Custom/FlipHorizontaly"
{
HLSLINCLUDE
#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
float4 Frag(VaryingsDefault i) : SV_Target
{
float2 flippedCoord = i.texcoord;
flippedCoord.x = 1 - flippedCoord.x;
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, flippedCoord);
}
ENDHLSL
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment Frag
ENDHLSL
}
}
}