└── ShaderCheatsheet.shader /ShaderCheatsheet.shader: -------------------------------------------------------------------------------- 1 | 2 | 3 | ███████╗██╗ ██╗ █████╗ ██████╗ ███████╗██████╗ ██╗ ██╗███████╗██╗ ██████╗ ██╗ 4 | ██╔════╝██║ ██║██╔══██╗██╔══██╗██╔════╝██╔══██╗ ██║ ██║██╔════╝██║ ██╔══██╗██║ 5 | ███████╗███████║███████║██║ ██║█████╗ ██████╔╝ ███████║█████╗ ██║ ██████╔╝██║ 6 | ╚════██║██╔══██║██╔══██║██║ ██║██╔══╝ ██╔══██╗ ██╔══██║██╔══╝ ██║ ██╔═══╝ ╚═╝ 7 | ███████║██║ ██║██║ ██║██████╔╝███████╗██║ ██║ ██║ ██║███████╗███████╗██║ ██╗ 8 | ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 9 | 10 | // - Or - I will never learn how to write shaders by heart 11 | 12 | // I wrote all text preceeding with // so that shader highlighting can be used in your favourite software (like sublime) 13 | 14 | // All categories mentioned in comments for searching are written in caps, for example "see MY TITLE" 15 | // To navigate to a category, like MY TITLE find it with hashtag like "#MY TITLE" 16 | 17 | // #STRUCTURE 18 | 19 | // #VERT/FRAG shader 20 | 21 | // Every "See.." Has a category below 22 | 23 | Shader "Custom/Name" 24 | { 25 | Properties 26 | { 27 | // See PROPERTIES 28 | } 29 | 30 | Tags // See TAGS 31 | Blend // See BLEND MODES 32 | 33 | Pass 34 | { 35 | CGPROGRAM 36 | 37 | #include // See INCLUDES 38 | 39 | #pragma vertex vert // See PRAGMAS 40 | #pragma fragment frag 41 | 42 | // custom variables 43 | 44 | struct v2f { }; 45 | 46 | v2f vert () { }; 47 | 48 | fixed4 frag (v2f i) : SV_Target {}; 49 | 50 | ENDCG 51 | } 52 | 53 | Pass // Another pass... 54 | { 55 | 56 | } 57 | } 58 | 59 | // #SURFACE SHADER 60 | 61 | Shader "Example/Diffuse Simple" 62 | { 63 | // Properties, same as above 64 | 65 | SubShader // Note, SubShader instead of Pass 66 | { 67 | Tags // see tags. Note, tags inside the SubShader {} unlike vert/frag shaders 68 | 69 | CGPROGRAM 70 | #pragma surface surf Lambert 71 | 72 | struct Input { 73 | float4 color : COLOR; 74 | }; 75 | 76 | void surf (Input IN, inout SurfaceOutput o) { 77 | o.Albedo = 1; 78 | } 79 | 80 | ENDCG 81 | } 82 | Fallback "Diffuse" 83 | } 84 | 85 | // #PROPERTIES 86 | 87 | Properties 88 | { 89 | _RangedFloat ("Ranged Float", Range (min, max)) = number 90 | _Float ("Float", Float) = number 91 | _Int ("Int", Int) = number 92 | _Color ("Some Color", Color) = (1,1,1,1) 93 | _Vector ("Some Vector", Vector) = (0,0,0,0) 94 | _Texture ("Texture", 2D) = "white" {} 95 | _Cubemap ("Cubemap", CUBE) = "" {} 96 | _3DTexture ("3DTexture", 3D) = "defaulttexture" {} 97 | 98 | // Standard properties: 99 | _MainTex ("Main Tex", 2D) = "white" {} 100 | // Missing - color, normal map 101 | } 102 | 103 | // They would be accessed in HSLS code as: 104 | half _Float; 105 | fixed _Float; 106 | float _Float; 107 | 108 | int _Int; // uint for unsigned 109 | uint _Int; // TODO: Check if viable ?? 110 | 111 | fixed4 _Color; // low precision type is usually enough for colors 112 | float4 _Vector; 113 | 114 | sampler2D _Texture; 115 | samplerCUBE _Cubemap; 116 | sampler3D _3DTexture; 117 | 118 | // Tiling and Offset information can be obtain by [TEXTURE NAME]_ST 119 | float4 _Texture_ST; // (x = x tiling, y = y tiling, z = x offset, w = y offset) 120 | 121 | // #TAGS 122 | 123 | Tags { 124 | "Queue"="Transparent" 125 | "RenderType"="Transparent" 126 | "IgnoreProjector"="True" 127 | // TODO 128 | } 129 | 130 | // incomplete 131 | 132 | // #BLEND MODES 133 | 134 | Blend Off 135 | 136 | Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency 137 | Blend One OneMinusSrcAlpha // Premultiplied transparency 138 | Blend One One // Additive 139 | Blend OneMinusDstColor One // Soft Additive 140 | Blend DstColor Zero // Multiplicative 141 | Blend DstColor SrcColor // 2x Multiplicative 142 | 143 | BlendOp colorOp 144 | BlendOp colorOp, alphaOp 145 | AlphaToMask On | Off 146 | 147 | // #Culling & Z 148 | 149 | Cull Back | Front | Off 150 | ZWrite On | Off 151 | ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always 152 | Offset Factor, Units 153 | Name "PassName" // Name a pass so that it can be reused by calling UsePass from other shaders 154 | ColorMask RGB | A | 0 | any combination of R, G, B, A // used to select which channel to use with blending 155 | 156 | // #PRAGMAS == 157 | 158 | // Pragmas are compilation directives 159 | // They written inside the CGPROGRAM ENDCG block 160 | #pragma vertex name // function that acts on every mesh vertex 161 | #pragma fragment name // function that acts on every visible pixel 162 | #pragma geometry name // DX10 geometry shader function. Acts per triangle. Turns on #pragma target 4.0 163 | // Used for tessellation: 164 | #pragma hull name // DX11 hull shader function. Acts once per patch. Turns on #pragma target 5.0 165 | #pragma domain name // DX11 domain shader function. Turns on #pragma target 5.0 166 | 167 | // #VERTEX STRUCTS 168 | 169 | // built-in shortcut appdatas: 170 | appdata_base // position, normal and one texture coordinate. 171 | appdata_tan // position, tangent, normal and one texture coordinate. 172 | appdata_full // position, tangent, normal, four texture coordinates and color. 173 | appdata_img // vertex shader input with position and one texture coordinate. 174 | 175 | // or custom struct like: 176 | struct appdata { 177 | // built in types: 178 | float4 vertex : POSITION; 179 | float3 normal : NORMAL; 180 | float4 tangent : TANGENT; 181 | fixed4 color : COLOR; 182 | 183 | float4 texcoord : TEXCOORD0; // or some people write "uv" 184 | float3 mycustomthing : TEXCOORD1; // for other custom things use TEXCOORD-number 185 | }; 186 | 187 | // this is what appdata_full has: 188 | struct appdata_full { 189 | float4 vertex : POSITION; 190 | float4 tangent : TANGENT; 191 | float3 normal : NORMAL; 192 | float4 texcoord : TEXCOORD0; 193 | float4 texcoord1 : TEXCOORD1; 194 | fixed4 color : COLOR; 195 | #if defined(SHADER_API_XBOX360) 196 | half4 texcoord2 : TEXCOORD2; 197 | half4 texcoord3 : TEXCOORD3; 198 | half4 texcoord4 : TEXCOORD4; 199 | half4 texcoord5 : TEXCOORD5; 200 | #endif 201 | }; 202 | 203 | // #STRUCTS 204 | // #VERTEX TO FRAGMENT STRUCT 205 | 206 | // COLOR0, COLOR2.. etc is used for low precision 0-1 values 207 | // TEXCOORD0, TEXCOORD1.. etc is used for high precision 208 | // ^ this only matters on older, dx9 hardware 209 | 210 | // Note: COLOR is the same as COLOR0, the same goes for TEXCOORD and TEXCOORD0 (TODO: check if true) 211 | 212 | struct v2f { 213 | float4 pos : SV_POSITION; 214 | fixed4 color : COLOR; // this didn't neeed to be COLOR (see above) 215 | 216 | float4 uv : TEXCOORD0; 217 | float3 normal : TEXCOORD1; 218 | 219 | uint vid : SV_VertexID // vertex ID, needs to be uint, requires #pragma target 3.5 220 | }; // NOTE THE SEMICOLON HERE AFTER STRUCT! 221 | 222 | // #VERTEX SHADER 223 | 224 | // If you only need position, you can return just a float4 in clip space 225 | float4 vert (float4 vertex : POSITION) : SV_POSITION 226 | { 227 | return UnityObjectToClipPos(vertex); 228 | } 229 | 230 | // if you have more data, you need to return a custom structure (see VERTEX TO FRAGMENT STRUCT) 231 | 232 | // The values output from the vertex shader will be interpolated across the face of the rendered triangles, 233 | // and the values at each pixel will be passed as inputs to the fragment shader. 234 | 235 | v2f vert (appdata_base v) 236 | { 237 | v2f o; 238 | o.pos = UnityObjectToClipPos(v.vertex); // clip pos, NOT object position 239 | // uv 240 | o.uv = float4( v.texcoord.xy, 0, 0 ); 241 | // vertex color 242 | o.color = v.color; 243 | 244 | // VIEW (camera) - camera view 245 | o.viewDir = normalize(WorldSpaceViewDir(v.vertex)); 246 | return o; 247 | } // NO SEMICOLON AFTER FUNCTIONS! 248 | 249 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 250 | vs 251 | o.vertex = UnityObjectToClipPos(v.vertex); 252 | ? 253 | 254 | 255 | 256 | // #FRAGMENT SHADER 257 | 258 | // usually, you would use : SV_Target semantic, like: 259 | fixed4 frag (v2f i) : SV_Target 260 | { 261 | return i.color // to visualize vertex color for eg. 262 | } 263 | 264 | // --------- 265 | 266 | // but you can also return custom structure if you need additional colors (as in multiple render targets): 267 | struct fragOutput 268 | { 269 | fixed4 color : SV_Target; 270 | fixed4 color2 : SV_Target0; // for additional render targets .. add as many SV_TargetN as you need 271 | fixed4 depth : SV_Depth; // overrides the z buffer value. Note on some GPUs it turns off depth buffer optimizations 272 | }; 273 | 274 | fragOutput frag (v2f i) 275 | { 276 | fragOutput o; 277 | o.color = fixed4(i.uv, 0, 0); 278 | o.color2 = i.color; 279 | o.depth = 0; 280 | return o; 281 | } 282 | 283 | // --------- 284 | 285 | // You can use VPOS to obtain screen space vertex position in pixels 286 | // requires #pragma target 3.0 287 | fixed4 frag (v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target 288 | { 289 | return fixed4(screenPos.xy, 0, 0); // X Y is in pixels! 290 | } 291 | 292 | // You can use VFACE to obtain face facing 293 | // VFACE input positive for frontbaces,negative for backfaces 294 | // requires #pragma target 3.0 295 | fixed4 frag (fixed facing : VFACE) : SV_Target 296 | { 297 | return facing > 0 ? _ColorFront : _ColorBack; 298 | } 299 | 300 | // --------- 301 | 302 | // #BUILT-IN FUNCTIONS 303 | 304 | // #INCLUDES 305 | 306 | #include HLSLSupport.cginc // (automatically included) Helper macros and definitions for cross-platform shader compilation. 307 | #include UnityShaderVariables.cginc // (automatically included) Commonly used global variables. 308 | 309 | #include UnityCG.cginc // commonly used helper functions. 310 | #include AutoLight.cginc // lighting & shadowing functionality, e.g. surface shaders use this file internally. 311 | #include Lighting.cginc // standard surface shader lighting models; automatically included when you’re writing surface shaders. 312 | #include TerrainEngine.cginc // helper functions for Terrain & Vegetation shaders. 313 | 314 | // Vertex transformation functions in UnityCG.cginc 315 | float4 UnityObjectToClipPos(float3 pos) // Transforms a point from object space to the camera’s clip space in homogeneous coordinates. This is the equivalent of mul(UNITY_MATRIX_MVP, float4(pos, 1.0)), and should be used in its place. 316 | float3 UnityObjectToViewPos(float3 pos) // Transforms a point from object space to view space. This is the equivalent of mul(UNITY_MATRIX_MV, float4(pos, 1.0)).xyz, and should be used in its place. 317 | 318 | // Generic helper functions in UnityCG.cginc 319 | float3 WorldSpaceViewDir (float4 v) // Returns world space direction (not normalized) from given object space vertex position towards the camera. 320 | float3 ObjSpaceViewDir (float4 v) // Returns object space direction (not normalized) from given object space vertex position towards the camera. 321 | float2 ParallaxOffset (half h, half height, half3 viewDir) // calculates UV offset for parallax normal mapping. 322 | fixed Luminance (fixed3 c) // Converts color to luminance (grayscale). 323 | fixed3 DecodeLightmap (fixed4 color) // Decodes color from Unity lightmap (RGBM or dLDR depending on platform). 324 | float4 EncodeFloatRGBA (float v) // Encodes [0..1) range float into RGBA color, for storage in low precision render target. 325 | float DecodeFloatRGBA (float4 enc) // Decodes RGBA color into a float. 326 | float2 EncodeFloatRG (float v) // Encodes [0..1) range float into a float2. 327 | float DecodeFloatRG (float2 enc) // Decodes a previously-encoded RG float. 328 | float2 EncodeViewNormalStereo (float3 n) // Encodes view space normal into two numbers in 0..1 range. 329 | float3 DecodeViewNormalStereo (float4 enc4) // Decodes view space normal from enc4.xy. 330 | 331 | // Only in forward rendering 332 | float3 WorldSpaceLightDir (float4 v) //Computes world space direction (not normalized) to light, given object space vertex position. 333 | float3 ObjSpaceLightDir (float4 v) //Computes object space direction (not normalized) to light, given object space vertex position. 334 | float3 Shade4PointLights (...) //Computes illumination from four point lights, with light data tightly packed into vectors. Forward rendering uses this to compute per-vertex lighting 335 | 336 | // Screen-space helper functions in UnityCG.cginc 337 | float4 ComputeScreenPos (float4 clipPos) // Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position. The function takes care of platform differences in render texture coordinates. 338 | float4 ComputeGrabScreenPos (float4 clipPos) //Computes texture coordinate for sampling a GrabPass texure. Input is clip space position. The function takes care of platform differences in render texture coordinates. 339 | float3 ShadeVertexLights (float4 vertex, float3 normal) // Computes illumination from four per-vertex lights and ambient, given object space position & normal. 340 | 341 | UnityObjectToWorldNormal(normal); // To convert normals to world space 342 | 343 | tex2D(_Tex, float2); // Texture sampling 344 | 345 | // #BUILT-IN VARIABLES 346 | 347 | // #Transformations 348 | // TODOL CHeck if these still work 349 | UNITY_MATRIX_MVP // Current model * view * projection matrix. 350 | UNITY_MATRIX_MV // Current model * view matrix. 351 | UNITY_MATRIX_V // Current view matrix. 352 | UNITY_MATRIX_P // Current projection matrix. 353 | UNITY_MATRIX_VP // Current view * projection matrix. 354 | UNITY_MATRIX_T_MV // Transpose of model * view matrix. 355 | UNITY_MATRIX_IT_MV // Inverse transpose of model * view matrix. 356 | 357 | unity_WorldToObject // Inverse of current world matrix. _World2Object is obsolete 358 | unity_ObjectToWorld // Current model matrix. _Object2World is obsolete 359 | 360 | // To get UVs 361 | newUV = TRANSFORM_TEX(oldUV, _MainTex); // replace with the name of your texture 362 | // also remember to declare the float4 _MainTex_ST; variable before using the macro 363 | 364 | // #Camera & Screen 365 | _WorldSpaceCameraPos // float3 World space position of the camera. 366 | _ProjectionParams // float4 x is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), y is the camera’s near plane, z is the camera’s far plane and w is 1/FarPlane. 367 | _ScreenParams // float4 x is the camera’s render target width in pixels, y is the camera’s render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height. 368 | _ZBufferParams // float4 Used to linearize Z buffer values. x is (1-far/near), y is (far/near), z is (x/far) and w is (y/far). 369 | unity_OrthoParams // float4 x is orthographic camera’s width, y is orthographic camera’s height, z is unused and w is 1.0 when camera is orthographic, 0.0 when perspective. 370 | unity_CameraProjection // float4x4 Camera’s projection matrix. 371 | unity_CameraInvProjection // float4x4 Inverse of camera’s projection matrix. 372 | unity_CameraWorldClipPlanes[6] // float4 Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far. 373 | 374 | // #Time 375 | _Time // float4 Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders. 376 | _SinTime // float4 Sine of time: (t/8, t/4, t/2, t). 377 | _CosTime // float4 Cosine of time: (t/8, t/4, t/2, t). 378 | unity_DeltaTime // float4 Delta time: (dt, 1/dt, smoothDt, 1/smoothDt). 379 | 380 | // #Lights 381 | _LightColor0 // (declared in Lighting.cginc) fixed4 Light color 382 | _WorldSpaceLightPos0 // float4 Directional lights: (world space direction, 0). Other lights: (world space position, 1). 383 | _LightMatrix0 // (declared in AutoLight.cginc) float4x4 World-to-light matrix. Used to sample cookie & attenuation textures. 384 | // forward only: 385 | unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 // float4 (ForwardBase pass only) world space positions of first four non-important point lights. 386 | unity_4LightAtten0 // float4 (ForwardBase pass only) attenuation factors of first four non-important point lights. 387 | unity_LightColor // half4[4] (ForwardBase pass only) colors of of first four non-important point lights. 388 | // deffered: 389 | _LightColor //float4 Light color. 390 | _LightMatrix0 //float4x4 World-to-light matrix. Used to sample cookie & attenuation textures. 391 | // vertex lit: 392 | unity_LightColor // half4[8] Light colors. 393 | unity_LightPosition // float4[8] View-space light positions. (-direction,0) for directional lights; (position,1) for point/spot lights. 394 | unity_LightAtten // half4[8] Light attenuation factors. x is cos(spotAngle/2) or –1 for non-spot lights; y is 1/cos(spotAngle/4) or 1 for non-spot lights; z is quadratic attenuation; w is squared light range. 395 | unity_SpotDirection // float4[8] View-space spot light positions; (0,0,1,0) for non-spot lights. 396 | 397 | // #Ambient 398 | unity_AmbientSky // fixed4 Sky ambient lighting color in gradient ambient lighting case. 399 | unity_AmbientEquator // fixed4 Equator ambient lighting color in gradient ambient lighting case. 400 | unity_AmbientGround // fixed4 Ground ambient lighting color in gradient ambient lighting case. 401 | 402 | // #Fog 403 | // UNITY_LIGHTMODEL_AMBIENT // fixed4 Ambient lighting color (sky color in gradient ambient case). Legacy variable. 404 | unity_FogColor // fixed4 Fog color. 405 | unity_FogParams // float4 Parameters for fog calculation: (density / sqrt(ln(2)), density / ln(2), –1/(end-start), end/(end-start)). x is useful for Exp2 fog mode, y for Exp mode, z and w for Linear mode. 406 | 407 | // #LOD 408 | unity_LODFade // float4 Level-of-detail fade when using LODGroup. x is fade (0..1), y is fade quantized to 16 levels, z and w unused. 409 | 410 | // IN SURFACE SHADERS: 411 | IN.worldNormal 412 | IN.viewDir 413 | 414 | 415 | // TODO: Add HSLS functions 416 | 417 | 418 | 419 | // TODO: 420 | == SURFACE SHADER CUSTOM LIGHTING == 421 | 422 | //Shader again: 423 | 424 | //------------------- 425 | //-- #TRANSPARENCY -- 426 | //------------------- 427 | 428 | 429 | // #ALPHA TEST TRANSPARENCY == // (aka #CUTOFF, #CUTOUT) 430 | 431 | // To make a thing transparent: 432 | // Make sure you use have these 2 tags: 433 | Tags { 434 | "Queue" = "AlphaTest" 435 | "RenderType" = "TransparentCutout" 436 | } 437 | 438 | // In frag shader add: 439 | clip(col.a - 0.5); // this 0.5 is the cutoff value, you can put it in a variable or property 440 | 441 | 442 | // #ALPHA BLEND TRANSPARENCY 443 | 444 | Tags { 445 | "Queue"="Transparent" 446 | "RenderType"="Transparent" 447 | } 448 | 449 | // Use one of the Blend modes see BLEND MODES 450 | Blend SrcAlpha OneMinusSrcAlpha 451 | ColorMask RGB 452 | ZWrite Off 453 | //Cull Off // optional 454 | 455 | //---------- 456 | //-- #FOG -- 457 | //---------- 458 | 459 | // Unity provides some useful macros for implementing built-in fog that can be configured in Lighting tab 460 | #pragma multi_compile_fog 461 | 462 | #include "UnityCG.cginc" 463 | 464 | // inside your v2f struct add: 465 | struct v2f { 466 | ... 467 | UNITY_FOG_COORDS(1) // the number (1) is an unused TEXCOORD-number, so if you already have TEXCOORD1, use (2) 468 | } 469 | 470 | // in the vert shader add UNITY_TRANSFER_FOG 471 | v2f vert (appdata_t v) { 472 | v2f o; 473 | ... 474 | UNITY_TRANSFER_FOG(o,o.vertex); 475 | return o; 476 | } 477 | 478 | // add UNITY_APPLY_FOG to your frag shader like 479 | fixed4 frag (v2f i) : SV_Target { 480 | ... 481 | UNITY_APPLY_FOG(i.fogCoord, col); // i.fogCoord is generated by UNITY_FOG_COORDS 482 | return col; 483 | } 484 | 485 | 486 | //----------------------------------- 487 | //-- #GPU INSTANCING - #INSTANCING -- 488 | //----------------------------------- 489 | 490 | #pragma multi_compile_instancing 491 | 492 | #include "UnityCG.cginc" 493 | 494 | struct appdata_t { 495 | ... 496 | UNITY_VERTEX_INPUT_INSTANCE_ID 497 | }; 498 | 499 | // It seems that this block required even tho you don't have any per instance properties 500 | UNITY_INSTANCING_BUFFER_START(Props) 501 | UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color) // Make _Color an instanced property (i.e. an array) 502 | #define _Color_arr Props 503 | UNITY_INSTANCING_BUFFER_END(Props) 504 | 505 | v2f vert (appdata_t v) 506 | { 507 | v2f o; 508 | UNITY_SETUP_INSTANCE_ID(v); 509 | ... 510 | return o; 511 | } 512 | 513 | //------------------------------- 514 | //-- #VR - #STEREO SINGLE PASS -- 515 | //------------------------------- 516 | 517 | // To support stereo single pass you need to put these macros to pass the eye index to the fragment shader. 518 | // For example, if you’re using any of the view or projection matrices or the camera position in the fragment shader 519 | // these need the eye index to give the correct value, otherwise you’ll always access the left eye. 520 | 521 | #include "UnityCG.cginc" 522 | 523 | struct appdata_t { 524 | ... 525 | UNITY_VERTEX_INPUT_INSTANCE_ID 526 | } 527 | 528 | struct v2f { 529 | ... 530 | UNITY_VERTEX_OUTPUT_STEREO 531 | } 532 | 533 | v2f vert (appdata_t v) 534 | { 535 | v2f o; 536 | UNITY_SETUP_INSTANCE_ID(); // for single pass instanced. Not necessary? 537 | UNITY_INITIALIZE_OUTPUT(v2f, o); // for single pass instanced. Not necessary? 538 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 539 | ... 540 | return o; 541 | } 542 | 543 | // in frag shader, eye can be accessed with 544 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i) 545 | // but it is not necessary, unless you are writing a post shader for example 546 | 547 | 548 | 549 | 550 | 551 | // SAMPLE 552 | 553 | Pass 554 | { 555 | Tags{ "LightMode" = "ShadowCaster" } 556 | 557 | Fog{ Mode Off } 558 | ZWrite On ZTest Less Cull Off 559 | Offset 1, 1 560 | 561 | CGPROGRAM 562 | 563 | #pragma vertex vert 564 | #pragma fragment frag 565 | #pragma multi_compile_shadowcaster 566 | #pragma fragmentoption ARB_precision_hint_fastest 567 | 568 | #include "UnityCG.cginc" 569 | 570 | struct v2f 571 | { 572 | V2F_SHADOW_CASTER; 573 | }; 574 | 575 | v2f vert(appdata_base v) 576 | { 577 | v2f o; 578 | TRANSFER_SHADOW_CASTER_NORMALOFFSET(o) 579 | return o; 580 | } 581 | 582 | float4 frag(v2f i) : COLOR 583 | { 584 | SHADOW_CASTER_FRAGMENT(i) 585 | } 586 | 587 | ENDCG 588 | } --------------------------------------------------------------------------------