Unity Shader 6 Surface Shaders
Unity Shader 6 Surface Shaders 就是 顶点Shader和片段Sahder的封装。
- Surface Shaders无pass 通道
- Tags 描述渲染类型
- LOD 层次细节
#CGPROGRAM
表示CG代码块开始#ENDCG
表示结束CG代码#pragma surface surf Standard fullforwardshadows
surface 表示按照 surface 方式编写#pragma target 3.0
使用 shader model 3.0
默认代码
Shader "Custom/NewSurfaceShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
//使用硬件 shader 3.0 值越高越好,默认是 2.0 Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex; //纹理必须是sample开头的关键字
struct Input
{
float2 uv_MainTex;//必须以 uv_开头 MainTex表示声明的 sample2D
};
half _Glossiness;//光泽度
half _Metallic;//金属
fixed4 _Color;//颜色
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
/**
struct SurfaceOutputStandard
{
fixed3 Albedo; // 基础(漫反射或镜面反射)颜色 base (diffuse or specular) color
fixed3 Normal; // 切线空间法线(如果写入)tangent space normal, if written
half3 Emission;
half Metallic; // 金属的 0=non-metal, 1=metal
half Smoothness; // 平滑度 0=rough, 1=smooth
half Occlusion; // 剔除 occlusion (default 1)
fixed Alpha; // 透明 alpha for transparencies
};
*/
//定义一个方法 inout 引用传递 SurfaceOutputStandard 基于物理的光照模型
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
禁止转载
分类:
unity
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2017-11-22 建立标准编码规则(三)-CodeFixProvider 给代码分析器增加修复建议