URP(一)
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@10.8/manual/writing-shaders-urp-unlit-color.html
只有外部一个颜色输入的着色器
tags添加"RenderPipeline" = "UniversalPipeline"
include文件改成#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
顶点着色器之前添加CBUFFER代码,基本逻辑和内置管线一样
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
CBUFFER_END
// This shader fills the mesh shape with a color that a user can change using the
// Inspector window on a Material.
Shader "Example/URPUnlitShaderColor"
{
// The _BaseColor variable is visible in the Material's Inspector, as a field
// called Base Color. You can use it to select a custom color. This variable
// has the default value (1, 1, 1, 1).
Properties
{
_BaseColor("Base Color", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
};
// To make the Unity shader SRP Batcher compatible, declare all
// properties related to a Material in a a single CBUFFER block with
// the name UnityPerMaterial.
CBUFFER_START(UnityPerMaterial)
// The following line declares the _BaseColor variable, so that you
// can use it in the fragment shader.
half4 _BaseColor;
CBUFFER_END
Varyings vert(Attributes IN)
{
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
return OUT;
}
half4 frag() : SV_Target
{
// Returning the _BaseColor value.
return _BaseColor;
}
ENDHLSL
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端