Hi all,
I have encountered this problem multiple times. Most of the time, it involves using some camera data such as camera space position or rendertexture.
Unity version: 2021.3.5f1
URP version: 12.1.7
A new project with URP 3D template.
The left side is the scene view and I am rotating the view angle. On the right side is the game view, there are two places where the result is affected in this example.
First, the shadow of the bucket. It uses the code at the bottom. The vertices of the bucket are translated based on the camera transform.
Secondly, a post-processing blur filter that follows this guide: Unity URP custom render feature for UI Blur · GitHub. This filter is supposed to blur the pixels behind it, but now it is showing the blur version of the scene view. In addition, when I only show game view without the scene view, the rendertexture is missing.
I created a new project just to recreate this bug. There could be other errors in the code that does not make sense, but the game view result should not be affected by the scene view camera at the very least.
// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Test1"
{
Properties
{
_Float0("Test", Float) = 0
}
SubShader
{
LOD 0
Tags { "RenderPipeline"="UniversalPipeline" "RenderType"="Opaque" "Queue"="Geometry" }
Cull Back
ZWrite On
ZTest LEqual
Offset 0 , 0
AlphaToMask Off
HLSLINCLUDE
#pragma target 3.0
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
ENDHLSL
Pass
{
Name "Forward"
Tags { "LightMode"="UniversalForward" }
Blend One Zero, One Zero
ColorMask RGBA
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
struct VertexInput
{
float4 vertex : POSITION;
};
struct VertexOutput
{
float4 clipPos : SV_POSITION;
};
float _Float0;
VertexOutput vert ( VertexInput v )
{
VertexOutput o = (VertexOutput)0;
float3 vertexValue = ( mul( unity_WorldToCamera, float4(1,0,0,1) ) * _Float0 ).xyz;
v.vertex.xyz += vertexValue;
float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
float4 positionCS = TransformWorldToHClip( positionWS );
o.clipPos = positionCS;
return o;
}
half4 frag ( VertexOutput IN ) : SV_Target
{
return half4(0,0,0,1);
}
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags { "LightMode"="ShadowCaster" }
ZWrite On
ZTest LEqual
AlphaToMask Off
ColorMask 0
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
struct VertexInput
{
float4 vertex : POSITION;
};
struct VertexOutput
{
float4 clipPos : SV_POSITION;
};
float _Float0;
VertexOutput vert ( VertexInput v )
{
VertexOutput o = (VertexOutput)0;
float3 vertexValue = ( mul( unity_WorldToCamera, float4(1,0,0,1) ) * _Float0 ).xyz;
v.vertex.xyz += vertexValue;
float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
float4 positionCS = TransformWorldToHClip( positionWS );
o.clipPos = positionCS;
return o;
}
half4 frag ( VertexOutput IN ) : SV_Target
{
return half4(0,0,0,1);
}
ENDHLSL
}
}
CustomEditor "UnityEditor.ShaderGraphLitGUI"
Fallback "Hidden/InternalErrorShader"
}