尝试使用后处理(URP)时以低质量筛选的统一摄像机渲染(URP)
在大量搜索之后,我找到了与2D URP渲染器一起使用自定义后处理的着色器与2D URP渲染器一起使用的麻烦,我找到了一种解决方案,让我通过使用摄像头堆叠和渲染功能在2D中使用后处理效果。我这样做是通过将大部分场景作为基础摄像机呈现的摄像机来做到这一点,该基础摄像机呈现2D灯(我使用URP的主要原因)和第二台覆盖摄像机,从而呈现后处理效果。问题是,由于某种原因,当我拥有应用后处理效果的相机时,质量会下降很多。这是几个示例:
启用后处理摄像头 ”>
目前,着色器不应做任何事情,但是如果我确实可以做类似的颜色,那么如果我启用了相机,效果确实会应用。 UI具有自己的相机,因此不受低质量和着色器的影响。我发现禁用渲染功能也会带来质量的恢复,但是它似乎并不是这样做的着色器,因为我可以在不破坏功能和低质量的情况下从功能上解开着色器。不过,我仍然对着色器很新,所以如果我的着色器出现了问题,这是代码:
Shader "PixelationShader"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
ZWrite Off Cull Off
Pass
{
Name "PixelationShader"
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionHCS : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings vert(Attributes input)
{
Varyings output;
// Note: The pass is setup with a mesh already in clip
// space, that's why, it's enough to just output vertex
// positions
output.positionCS = float4(input.positionHCS.xyz, 1.0);
#if UNITY_UV_STARTS_AT_TOP
output.positionCS.y *= -1;
#endif
output.uv = input.uv;
return output;
}
TEXTURE2D_X(_CameraOpaqueTexture);
SAMPLER(sampler_CameraOpaqueTexture);
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float4 color = SAMPLE_TEXTURE2D_X(_CameraOpaqueTexture, sampler_CameraOpaqueTexture, input.uv);
//color.rgb = 1 - color.rgb;
return color;
}
ENDHLSL
}
}
}
如果您有任何想法,请告诉我,谢谢!另外,如果有人知道如何删除或修复屏幕边缘的白色线条,您也可以在图像中看到的编辑器灯图标也开始出现在游戏中,这也非常方便地
编辑:我'注意到,我发送的图像的质量差异不是很明显,但是在实际玩游戏时,它更加明显
I've been having troubles with getting custom post-processing shaders to work with the 2D URP renderer, after a lot of searching I found a solution that let me use post-processing effects in 2D with URP by using camera stacking and render features. I do this by having a camera that renders most of the scene as a base camera that renders the 2D lights (the main reason I'm using URP) and a second overlay camera that renders the post-processing effect. The issue is that for some reason the quality drops a lot when I have the camera that's applying the post-processing effect enabled. Here's a couple examples:
With post-processing camera enabled
With post-processing camera disabled
The shader shouldn't be doing anything at the moment, but if I do make it do something like inverting the colors, the effect does get applied if I have the camera enabled. The UI has it's own camera so it's unaffected by both the low quality and the shader. I've found that disabling the render feature brings the quality back as well, but it doesn't seem to be the shader that's doing this because I can unattach the shader from the feature without disabling the feature and the low quality stays. I'm still pretty new with shaders though, so in case there is something wrong with my shader that's causing this, here's the code:
Shader "PixelationShader"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
ZWrite Off Cull Off
Pass
{
Name "PixelationShader"
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionHCS : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings vert(Attributes input)
{
Varyings output;
// Note: The pass is setup with a mesh already in clip
// space, that's why, it's enough to just output vertex
// positions
output.positionCS = float4(input.positionHCS.xyz, 1.0);
#if UNITY_UV_STARTS_AT_TOP
output.positionCS.y *= -1;
#endif
output.uv = input.uv;
return output;
}
TEXTURE2D_X(_CameraOpaqueTexture);
SAMPLER(sampler_CameraOpaqueTexture);
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float4 color = SAMPLE_TEXTURE2D_X(_CameraOpaqueTexture, sampler_CameraOpaqueTexture, input.uv);
//color.rgb = 1 - color.rgb;
return color;
}
ENDHLSL
}
}
}
Please let me know if you have any ideas, thanks! Also, the editor light icons you can see in the images just started appearing in game as well, if anyone knows how to remove those or fix the white lines at the edges of the screen, that would be handy to know as well
Edit: I've noticed that the quality difference in the images I sent isn't very noticeable, but it's much more noticeable when actually playing the game
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
_cameraopaquetexture默认情况下使用双线性下降采样。您可以在使用的通用渲染管道资产中更改它:
“ rendering/opaque downsmpling”下的下拉需要无需
_CameraOpaqueTexture uses bilinear downsampling by default. You can change that in the universal render pipeline asset that you use:
dropdown under "Rendering/opaque downsampling" needs to be none
尝试了一堆不同的事情之后,我决定从项目中删除URP,然后在2D Sprites上使用3D灯
After trying a bunch of different things, I decided to just remove URP from my project and use 3D lights on 2D sprites instead