#T#PoiMirrorProperties

//ifex _EnableMirrorOptions==0
[HideInInspector] m_start_mirrorOptions ("Mirror/Camera Visibility--{reference_property:_EnableMirrorOptions,button_help:{text:Tutorial,action:{type:URL,data:https://www.poiyomi.com/special-fx/mirror},hover:Documentation}}", Float) = 0
[HideInInspector][ThryToggle(POI_MIRROR)]_EnableMirrorOptions ("Enable Mirror Options", Float) = 0
[ThryWideEnum(Generic, 0, VRC, 1)] _VisibilityMode ("Mode", Int) = 1
[ThryWideEnum(Show In Both, 0, Show Only In Mirror, 1, Dont Show In Mirror, 2)] _Mirror ("Mirror Visibility--{condition_showS:(_VisibilityMode==0)}", Int) = 0
[ThryToggleUI(True)]_VisibilityVRCRegular 			("Normal (Outside Mirror/Camera)--{condition_showS:(_VisibilityMode==1)}", Int) = 1
[ThryToggleUI(True)]_VisibilityVRCMirrorVR 			("Mirror (VR)--{condition_showS:(_VisibilityMode==1)}", Int) = 1
[ThryToggleUI(True)]_VisibilityVRCMirrorDesktop 	("Mirror (Desktop)--{condition_showS:(_VisibilityMode==1)}", Int) = 1
[ThryToggleUI(True)]_VisibilityVRCCameraVR 			("Camera (VR)--{condition_showS:(_VisibilityMode==1)}", Int) = 1
[ThryToggleUI(True)]_VisibilityVRCCameraDesktop 	("Camera (Desktop)--{condition_showS:(_VisibilityMode==1)}", Int) = 1
[ThryToggleUI(True)]_VisibilityVRCCameraScreenshot 	("Screenshot--{condition_showS:(_VisibilityMode==1)}", Int) = 1
_MirrorColor ("Mirror Tint Color--{reference_property:_MirrorColorThemeIndex}", Color) = (1, 1, 1, 0)
[HideInInspector][ThryWideEnum(Off, 0, Theme Color 0, 1, Theme Color 1, 2, Theme Color 2, 3, Theme Color 3, 4, ColorChord 0, 5, ColorChord 1, 6, ColorChord 2, 7, ColorChord 3, 8, AL Theme 0, 9, AL Theme 1, 10, AL Theme 2, 11, AL Theme 3, 12)] _MirrorColorThemeIndex ("", Int) = 0
[sRGBWarning(true)]_MirrorTexture ("Mirror Texture--{reference_properties:[_MirrorTexturePan, _MirrorTextureUV, _MirrorTextureBlendType]}", 2D) = "white" { }
[HideInInspector][Vector2]_MirrorTexturePan ("Panning", Vector) = (0, 0, 0, 0)
[HideInInspector][ThryWideEnum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Panosphere, 4, World Pos XZ, 5, Polar UV, 6, Distorted UV, 7)] _MirrorTextureUV("UV", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)]_MirrorTextureBlendType ("Blending", Range(0, 1)) = 0
[HideInInspector] m_end_mirrorOptions ("Mirror", Float) = 0
//endex

#T#PoiMirrorKeywords
//ifex _EnableMirrorOptions==0
#pragma shader_feature_local POI_MIRROR
//endex

#T#PoiMirrorVariables
//ifex _EnableMirrorOptions==0
#ifdef POI_MIRROR
	float _VisibilityMode;
    float _Mirror;
	#if defined(PROP_MIRRORTEXTURE) || !defined(OPTIMIZER_ENABLED)
    	Texture2D _MirrorTexture;
	#endif
	float4 _MirrorColor;
	float _MirrorColorThemeIndex;
	float _MirrorTextureBlendType;
	float4 _MirrorTexture_ST;
	float2 _MirrorTexturePan;
	float _MirrorTextureUV;

	float _VisibilityVRCRegular;
	float _VisibilityVRCMirrorVR;
	float _VisibilityVRCMirrorDesktop;
	float _VisibilityVRCCameraVR;
	float _VisibilityVRCCameraDesktop;
	float _VisibilityVRCCameraScreenshot;
#endif
//endex

#T#PoiMirrorFunctions
//ifex _EnableMirrorOptions==0
#ifdef POI_MIRROR
    void applyMirror(inout PoiFragData poiFragData, in PoiMesh poiMesh, in PoiMods poiMods)
    {
		float inMirror = 0;
		if (_VisibilityMode == 1) // VRC
			inMirror = VRCMirrorMode() > 0;
		else // Generic (CVR, etc)
			inMirror = IsInMirror();

		#if (defined(POI_PASS_BASE) || defined(POI_PASS_ADD))
			#if defined(PROP_MIRRORTEXTURE) || !defined(OPTIMIZER_ENABLED)
				float4 mirrorTexture = POI2D_SAMPLER_PAN(_MirrorTexture, _MainTex, poiUV(poiMesh.uv[_MirrorTextureUV], _MirrorTexture_ST), _MirrorTexturePan);
				if (inMirror)
				{
					poiFragData.baseColor.rgb = lerp(poiFragData.baseColor.rgb, customBlend(poiFragData.baseColor.rgb, mirrorTexture.rgb, _MirrorTextureBlendType), mirrorTexture.a * _MirrorColor.a);
					poiFragData.baseColor.rgb *= lerp(1, poiThemeColor(poiMods, _MirrorColor.rgb, _MirrorColorThemeIndex), _MirrorColor.a);
				}
			#else
				if (inMirror)
				{
					poiFragData.baseColor.rgb *= lerp(1, poiThemeColor(poiMods, _MirrorColor.rgb, _MirrorColorThemeIndex), _MirrorColor.a);
				}
			#endif
		#endif
    }
#endif
//endex

#T#PoiMirrorVertexImplementation
//ifex _EnableMirrorOptions==0
#ifdef POI_MIRROR
	float notVisible = 0;

	if (_VisibilityMode == 1) // VRC
	{
		float mirrorMode = VRCMirrorMode();
		float cameraMode = VRCCameraMode();

		notVisible += (!_VisibilityVRCRegular 		&& ((mirrorMode == 0) && (cameraMode == 0)));
		notVisible += (!_VisibilityVRCMirrorVR 		&&  (mirrorMode == 1));
		notVisible += (!_VisibilityVRCMirrorDesktop &&  (mirrorMode == 2));
		notVisible += (!_VisibilityVRCCameraVR			&& (cameraMode == 1));
		notVisible += (!_VisibilityVRCCameraDesktop 	&& (cameraMode == 2));
		notVisible += (!_VisibilityVRCCameraScreenshot 	&& (cameraMode == 3));
	}
	else if (_Mirror != 0) // Generic (CVR, etc)
	{
		notVisible += (_Mirror == 1) ^ IsInMirror();
	}

	if(notVisible) // Early Return skips rest of vertex shader
	{
		return (VertexOut)POI_NAN;
	}
#endif
//endex

#T#PoiMirrorFunctionCalls
//ifex _EnableMirrorOptions==0
#ifdef POI_MIRROR
    applyMirror(poiFragData, poiMesh, poiMods);
#endif
//endex

