Shader error in 'Unlit/CommonCartoon_Standard': Vertex program 'vert': unknown input semantics NORAML/0 at line 23 (on d3d11)
时间: 2024-04-07 12:30:30 浏览: 15
这个错误通常发生在着色器中指定了一个未知的输入语义。在你的情况下,错误信息显示在顶点程序的第23行,指出了一个未知的输入语义 `NORAML/0`。
这个错误是由于拼写错误引起的。正常情况下,应该是 `NORMAL/0` 而不是 `NORAML/0`。`NORMAL` 是指法线向量的输入语义,用于计算光照和阴影效果。
要解决这个问题,你可以在着色器代码中找到顶点程序,并将 `NORAML/0` 改为 `NORMAL/0`。然后重新编译着色器,这个错误应该就会消失。
希望这可以帮助到你!如果还有其他问题,请随时提问。
相关问题
unity shader入门精要_【Unity Shader】在URP里写Shader(二):从一个Unlit Shader开始
在Unity中,Shader是用来渲染场景的关键部分。在URP中,Shader的编写方式与传统的Shader编写方式略有不同,但其核心思想仍然是相同的。
在本文中,我们将从一个简单的Unlit Shader开始,介绍在URP中编写Shader的基本步骤。
1. 创建Shader
首先,我们需要创建一个新的Shader。在Project视图中右键点击Assets文件夹,选择Create > Shader > Unlit Shader。
2. 编写Shader
打开新创建的Shader文件,我们可以看到如下代码:
```
Shader "Unlit/MyUnlitShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
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
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
这个Shader使用了Unity默认的Unlit Shader模板,并添加了一个_MainTex属性,该属性用于接收贴图,并在渲染过程中使用。
3. 添加SubShader
在URP中,我们需要为Shader添加一个SubShader。在SubShader中,我们可以定义一系列Pass,每个Pass都是对场景中不同物体的渲染。
修改代码如下:
```
Shader "Unlit/MyUnlitShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
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
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag () : SV_Target
{
fixed4 col = fixed4(1, 1, 1, 1);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
在这个代码中,我们添加了一个新的SubShader,并为其添加了一个Pass。这个Pass是一个简单的颜色填充Pass,用于在没有贴图的情况下渲染物体。
4. 测试Shader
最后,我们需要将Shader应用到一个物体上并测试它的效果。在Scene视图中创建一个新的Cube,并将新创建的Shader应用到该Cube上。
现在,你应该能够看到在没有贴图的情况下,该Cube被渲染为白色。如果你将贴图赋给_MainTex属性,你应该能够看到该Cube被渲染为该贴图。
这就是从一个简单的Unlit Shader开始,在URP中编写Shader的基本步骤。通过深入学习Shader编写的过程,你将能够创建更高级、更复杂的Shader,并为你的游戏带来更加出色的视觉效果。
unity EH_SampleShader/ToonShader 把图片效果输出到 png 使用以下代码 Shader sd = Shader.Find("Unlit/ColorToGradient"); Material mt = new Material(sd); mt.SetTexture("_MainTex",tex); mt.SetTexture("_MainTex1",texture1); Graphics.Blit(source, destination, mt);
你可以使用以下代码将 Unity 中的图片效果输出为 PNG 格式:
```csharp
using UnityEngine;
using UnityEditor;
public class ExportToPNG : MonoBehaviour
{
public Texture2D texture;
public string outputPath = "Output.png";
private void Start()
{
// 创建一个临时的 RenderTexture
RenderTexture renderTexture = new RenderTexture(texture.width, texture.height, 0);
Graphics.Blit(texture, renderTexture);
// 将 RenderTexture 保存为 Texture2D
RenderTexture.active = renderTexture;
Texture2D outputTexture = new Texture2D(renderTexture.width, renderTexture.height);
outputTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
outputTexture.Apply();
// 将 Texture2D 保存为 PNG 文件
byte[] bytes = outputTexture.EncodeToPNG();
System.IO.File.WriteAllBytes(outputPath, bytes);
// 释放资源
RenderTexture.active = null;
Destroy(renderTexture);
Destroy(outputTexture);
Debug.Log("Exported to " + outputPath);
}
}
```
将上述脚本附加到一个 GameObject 上,并在 Inspector 面板中指定需要输出的 Texture2D,并设置输出路径。运行场景后,脚本会在指定路径下生成 PNG 文件,其中包含了应用了 Toon Shader 的图片效果。