英文:
Why is my shader working in the Scene View but not in the Game View (Unity) (Built-in Render Pipeline)?
问题
Shader(着色器)在“Scene View”(场景视图)中运行正常:Shader在Scene View中的效果
但在“Game View”(游戏视图)中,圆圈奇怪地锚定在世界空间的中心:
我不知道是什么原因导致这种差异。
英文:
So, i made a little unlit shader in Unity. I want the shader to display a circle at the center of the mesh. Here is the code :
Shader "Unlit/UnlitBasicShader"
{
Properties
{
_Color("Tint", Color) = (1.0, 1.0, 1.0, 1.0)
_ColorCenterOfMass("Color of the center of mass", Color) = (1.0, 1.0, 1.0, 1.0)
_SizeCenterOfMass("Size of the center of mass", Float) = 1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 worldPos : TEXCOORD1;
float4 vertex : SV_POSITION;
};
float4 _Color;
float4 _ColorCenterOfMass;
float _SizeCenterOfMass;
v2f vert (appdata v)
{
v2f o;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float3 localSpace = i.worldPos - mul(unity_ObjectToWorld,float4(0,0,0,1)).xyz;
float distance = sqrt(localSpace.x * localSpace.x + localSpace.y * localSpace.y);
float circleCenterOfMass = step(distance,_SizeCenterOfMass);
fixed4 col = lerp(_Color, _ColorCenterOfMass, circleCenterOfMass);
return col;
}
ENDCG
}
}
}
The shader is working just fine in the Scene View :
Shader in the Scene View
But the circle is weirdly anchored at the center of World Space in the Game View:
Shader in the Game View with a little circle
Shader in the Game View with a bigger circle
I have no clue of what is causing this difference
答案1
得分: 0
问题相当复杂,需要更多的信息,该信息未在问题中指定(即检查器窗口、具有着色器的材质、相机检查器窗口等)。
常见问题可能包括:
- 在相机上启用后期处理
- 检查你的渲染管线设置
- 查看你的材质,可能有一些未选择的设置(使用错误的渲染管线等)。
这里有一个参考链接:https://answers.unity.com/questions/1404471/billboard-shader-works-in-scene-view-but-not-game.html
希望这有所帮助!
英文:
The problem is rather complicated and requires way more information, that is not specified in the question(i.e inspector window, material with the shader, camera inspector window, etc.)
The common issues could be:
- Enable post processing on the camera
- Check your pipeline settings
- Look at your material, there may be some settings unselected(wrong pipeline used, etc.)
Here is a reference: https://answers.unity.com/questions/1404471/billboard-shader-works-in-scene-view-but-not-game.html
Hope this helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论