Shader global _VRChatCameraMode incorrectly set in main camera
needs more information
~nono~
I have an Enlighten RTGI setup with an emissive quad on the MirrorReflection layer so that it is not visible to the player. To also hide this quad from personal mirrors, facecams, and cameras, I'm using the VRChat provided shader globals _VRChatCameraMode and VRChatMirrorMode and testing whether they are greater than zero.
I found that when I open my stream cam in game, all lighting effect disappear in the main VR game view. Somehow the _VRChatCameraMode is greater than zero in the main camera and I don't believe this is intended.
I tested the following scenarios:
Desktop
- Photo camera: works fine
- Stream camera (spout off): works fine
- Stream camera (spout on): works fine
VR
- Photo camera: works fine
- Stream camera (spout off): broken! *******
- Stream camera (spout on): works fine
Seems like a bug that it is broken only with Spout off and only in VR. There is also a possibility that this is a bug with the MirrorReflection layer, but I haven't created an isolated test scenario to confirm.
Code I'm using in a surface shader to reproduce:
if(_VRChatCameraMode > 0 || _VRChatMirrorMode > 0)
{
clip( -1.0 );
}
Log In
MisutaaAsriel
StormRel please note that there is variation between this issue and the issue of mine merged, indicating a wider issue as a whole.
My issue occurs with spout on, stream camera, UI dismissed, in
desktop
mode, and occurs because _VRChatCameraMode is 0 when it shouldn't be,
rather than it being non-zero when it shouldn't. Effectively, the complete opposite.StormRel
Merged in a post:
_VRChatCameraMode set to 0 with Spout Stream
MisutaaAsriel
When using shaders which omit themselves when
_VRChatCameraMode
is set to 0
, objects using these shaders are non-visible in the spout stream camera when the camera UI is closed.This is not expected and presumably not intended behavior.
_VRChatCameraMode
is being set to 0 when the camera UI is closed, despite an active camera still going, and said shaders rendering properly when camera UI is open.Example Shader:
Shader "LiveDimensions/ScreenSpaceTexture"
{
Properties
{
_Color("Shader Color", Color) = (0.3,0.3,0.3,1)
_MainTex ("Texture", 2D) = "white" {}
[Toggle] _NoPlayerRender ("Render Highlight in Camera Only", float) = 0
}
SubShader
{
Tags {"Queue" = "Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
blend One OneMinusSrcAlpha
//INSIDE OF SPHERE (USES RENDER TEXTURE)
Pass
{
//Cull back faces so we can write front faces over the last pass
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 vert(appdata_base v) : SV_POSITION
{
return UnityObjectToClipPos(v.vertex);
}
float _VRChatCameraMode;
fixed4 frag(float4 i : VPOS) : SV_Target
{
[branch] switch(_VRChatCameraMode){
case 0: {
return fixed4(0.0,0.0,0.0,0.0);
break;
}
default: {
fixed4 tex = tex2D(_MainTex, ((i.xy / _ScreenParams.xy)));
UNITY_OPAQUE_ALPHA(tex.a);
return tex;
break;
}
}
}
ENDCG
}
//OUTSIDE OF SPHERE (USES RENDER TEXTURE * COLOR)
Pass
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
// AlphaTest Greater 0.01
// blend SrcAlpha OneMinusSrcAlpha
blend OneMinusDstColor One, One OneMinusSrcAlpha
//Cull front faces first
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
UNITY_FOG_COORDS(0)
UNITY_VERTEX_OUTPUT_STEREO
};
fixed4 _Color;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
float _VRChatCameraMode;
float _NoPlayerRender;
fixed4 frag (v2f i) : COLOR
{
fixed4 col = _Color;
[branch] switch(_VRChatCameraMode){
case 0: {
[branch] switch(_NoPlayerRender){
case 0: {
break;
}
default: {
col = fixed4(0.0,0.0,0.0,0.0);
break;
}
}
break;
}
default: {
break;
}
}
UNITY_APPLY_FOG(i.fogCoord, col);
UNITY_OPAQUE_ALPHA(col.a);
return col;
}
ENDCG
}
}
}
(Modified from https://github.com/LiveDimensions/VRC-ScreenSpace-CameraOverride)
_
_tau_
needs more information
Unable to reproduce. Test setup:
- Steam Link VR w/ Quest Pro on current live version, 1606
- Shader displaying the current value of _VRChatCameraMode
- Using Stream Camera mode and pointing it at a quad rendering with said shader
-> Number reads 1 on desktop window and viewfinder, number reads 0 when looking at it directly - as expected.
Tested with a mirror in view and without, no difference.
If you have a world with simple reproduction steps, feel free to post a link. In that case please also post the shader source for reference. Perhaps screenshots/video could help too.
~nono~
_tau_
The issue is apparent in my test world (old url removed to avoid confusion, see link in comment below)
The area with lighting on the MirrorReflection layer is from on the stage pointing towards the room. I'll try to come back to this with a simpler world example if I find time. It's hard in VR to record this because the issue happens specifically happens when you toggle on/off the Spout option.
Also I'm using a Valve Index on Windows 11 with an nvidia card if that makes any difference in reproducing.
~nono~
Recorded a video as best I could. I'll try to replicate in a simpler world later next week. This does not happen in desktop mode. https://youtu.be/w49F_2lLgCg
So the video doesn't really show the full context, because with Spout off you obviously only see the camera view itself in the video. The issue is that the lighting also disappears in VR, which I can't show here.
Here is the world from the video: https://vrchat.com/home/world/wrld_071227d4-9035-4728-ab2b-e60f0ae0c683/info
~nono~
Shader source attached. The include file is just audiolink data lookups and color math. It's failing to upload for some reason, but not relevant.
StormRel
tracked