文档

Unity Engine


User Manual

Script Reference

Unity Engine


Single color shader example in the Built-In Render Pipeline

Example of a shader that renders a single color.
阅读时间1 分钟最后更新于 1 个月前

重要
The Built-In Render Pipeline is deprecated and will be made obsolete in a future release.
It remains supported, including bug fixes and maintenance, through the full Unity 6.7 LTS lifecycle.

A cat-like character rendered using a single color, to create a silhouette.

Shader "Unlit/SingleColor"{ Properties { // Color property for material inspector, default to white _Color ("Main Color", Color) = (1,1,1,1) } SubShader { Pass { HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" // vertex shader // this time instead of using "appdata" struct, just spell inputs manually, // and instead of returning v2f struct, also just return a single output // float4 clip position float4 vert (float4 vertex : POSITION) : SV_POSITION { return mul(UNITY_MATRIX_MVP, vertex); } // color from the material half4 _Color; // pixel shader, no inputs needed half4 frag () : SV_Target { return _Color; // just return it } ENDHLSL } }}