Unity Shader sheet record

unity创建新的工程时出现问题。 解决办法:取消勾选↓。 阅读详情


// This cheatsheet primarily focuses on VERTEX/FRAMGENT shaders and not on SURFACE shaders,
// but some of the surface shader things are mentioned in a separate category on the bottom. see SURFACE

// #STRUCTURE

// #VERT/FRAG shader

Shader "Custom/Name"
{
    Properties // See PROPERTIES
    {
        
    }

    Tags // See TAGS
    Blend // See BLEND MODES

    Pass
    {
        CGPROGRAM

        #include // See INCLUDES

        #pragma vertex vert // See PRAGMAS
        #pragma fragment frag

        // custom variables

        struct appdata { }; // not necessary if using one of predefined ones, see #APPDATA

        struct v2f { }; // see #STRUCTS
    
        v2f vert (appdata v) { };
    
        fixed4 frag (v2f i) : SV_Target { };
    
        ENDCG
    }

    Pass // Another pass...
    {

    }
}

// #PROPERTIES

Properties
{
    // Syntax: _VariableName ("Label in the inspector", Type) = default value
    _RangedFloat ("Ranged Float", Range (min, max)) = number
    _Float ("Float", Float) = number
    _Int ("Int", Int) = number
    _Color ("Some Color", Color) = (1,1,1,1)
    _Vector ("Some Vector", Vector) = (0,0,0,0)
    _Texture ("Texture", 2D) = "white" {} // "", “white” (1,1,1,1), “black” (0,0,0,0), “gray” (0.5,0.5,0.5,0.5), “bump” (0.5,0.5,1,0.5) or “red” (1,0,0,0)
    _Cubemap ("Cubemap", CUBE) = "" {}
    _3DTexture ("3DTexture", 3D) = "defaulttexture" {}

    // Standard properties:
    // Unity's builtin shaders use _MainTex ss the main diffuse/albedo slot,
    // so it is advised to use this 
    _MainTex ("Main Tex", 2D) = "white" {}
    _BumpMap ("Bumpmap", 2D) = "bump" {}

    // Attiributes:
    [HideInInspector]
    [NoScaleOffset] // no texture tiling/offset fields in inspector
    [Normal] // expects a normal map and adds a "Fix Now" button to convert
    [HDR] // expects an HDR
    [Gamma] // indicates that a float/vector property is specified as sRGB value in the UI (just like colors are), and possibly needs conversion according to color space used
    [PerRendererData] // indicates that a texture property will be coming from per-renderer data in the form of a MaterialPropertyBlock. Material inspector changes the texture slot UI for these properties.

    // Sliders
    [PowerSlider(3.0)] _Shininess ("Shininess", Range (0.01, 1)) = 0.08 // A slider with "power of" (in this case ^3) response curve
    [IntRange] _Alpha ("Alpha", Range (0, 255)) = 100 // integer slider for specified range (0 to 255)

    // Decorators
    [Space(50)] _Prop2 ("Prop2", Float) = 0 // creates space before property
    [Header(A group of things)] _Prop1 ("Prop1", Float) = 0 // creates a header before property

    [Enum(UnityEngine.Rendering.BlendMode)] _Blend ("Blend mode", Float) = 1 // blend mode popup menu
    [Enum(One,1,SrcAlpha,5)] _Blend2 ("Blend mode subset", Float) = 1 // a subset of blend mode values, just "One" (value 1) and "SrcAlpha" (value 5)

    // multi_compile Shader Keywords
    [Toggle(THINGY)] _Fancy ("Thingy", Float) = 0 // toggles a THINGY multi_compile shader keyword, see #MULTI_COMPILE
    [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0
}

// They would be accessed in HSLS code as:
half _Float;
fixed _Float;
float _Float;

int _Int;
uint _Int;

// half, fixed, float + 2,3,4 are all possible combinations for example:
fixed4 _Color; // low precision type is usually enough for colors
float4 _Vector;

float4x4 _Matrix;

sampler2D _Texture;
samplerCUBE _Cubemap;
sampler3D _3DTexture;

// Tiling and Offset information can be obtain by [TEXTURE NAME]_ST, that needs to be defined separately
float4 _Texture_ST; // (x = x tiling, y = y tiling, z = x offset, w = y offset)

// Texture size can be obtained through the Vector4 [TEXTURE NAME]_TexelSize
float4 _Texture_TexelSize; // x = 1.0/width, y = 1.0/height, z = width, w = height

// Never personally used, see in official docs
float4 _Texture_HDR

// #TAGS

Tags { 
    "Queue" = "Background" | "Geometry" | "AlphaTest" | "Transparent" | "Overlay"
    // special cases with +number, e.g. "Geometry+1"
    "RenderType" = "Transparent" | "TransparentCutout" | "Background" | "Overlay"
                    | "TreeOpaque" | "TreeTransparentCutout" | "TreeBillboard" | "Grass" | "GrassBillboard"
    "IgnoreProjector" = "True" 
    "DisableBatching" = "True" | "False" | "LODFading"
    "ForceNoShadowCasting" = "True"
    "IgnoreProjector" = "True"
    "CanUseSpriteAtlas" = "False" // if the shader is meant for sprites, and will not work when they are packed into atlases
    "PreviewType" = "Sphere" | "Plane" | "Skybox" // how should the inspector preview the material, Plane is 2D
}

// incomplete

// #BLEND MODES

Blend Off

Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency
Blend One OneMinusSrcAlpha // Premultiplied transparency
Blend One One // Additive
Blend OneMinusDstColor One // Soft Additive
Blend DstColor Zero // Multiplicative
Blend DstColor SrcColor // 2x Multiplicative

BlendOp colorOp // provide a custom operation
BlendOp colorOp, alphaOp
AlphaToMask On | Off // aka Alpha to coverage, allows MSAA to be used on pixels of an alpha test shader

// #Culling & Z

Cull Back | Front | Off
ZWrite On | Off
ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
Offset Factor, Units
Name "PassName" // Name a pass so that it can be reused by calling UsePass from other shaders
ColorMask RGB | A | 0 | any combination of R, G, B, A // used to select which channel to use with blending

// #PRAGMAS ==

// Pragmas are compilation directives
// They written inside the CGPROGRAM ENDCG block
#pragma vertex name // function that acts on every mesh vertex
#pragma fragment name // function that acts on every visible pixel
#pragma geometry name // DX10 geometry shader function. Acts per triangle. Turns on #pragma target 4.0
// Used for tessellation:
#pragma hull name // DX11 hull shader function. Acts once per patch. Turns on #pragma target 5.0
#pragma domain name // DX11 domain shader function. Turns on #pragma target 5.0
// Shader keywords:
#pragma multi_compile KEYWORD1 KEYWORD2 // enables multiple shader variants, see MULTI_COMPILE
#pragma skip_variants KEYWORD2 KEYWORD3 // skips compiling variants that you are sure are not used in the project
#pragma hardware_tier_variants renderer // automatically creates 3 variants: UNITY_HARDWARE_TIER1, UNITY_HARDWARE_TIER2 and UNITY_HARDWARE_TIER3
#pragma shader_feature KEYWORD // similar to multi_compile but unused variants will not be included in the build

// #VERTEX STRUCTS

// built-in shortcut appdatas:
appdata_base // position, normal and one texture coordinate.
appdata_tan // position, tangent, normal and one texture coordinate.
appdata_full // position, tangent, normal, four texture coordinates and color.
appdata_img // vertex shader input with position and one texture coordinate.

// or custom struct like:
struct appdata {
    // built in types:
    float4 vertex : POSITION;
    float3 normal : NORMAL;
    float4 tangent : TANGENT;
    fixed4 color : COLOR;

    float4 texcoord : TEXCOORD0; // or some people write "uv"
    float3 mycustomthing : TEXCOORD1; // for other custom things use TEXCOORD-number
};

// this is what appdata_full has:
struct appdata_full {
    float4 vertex : POSITION;
    float4 tangent : TANGENT;
    float3 normal : NORMAL;
    float4 texcoord : TEXCOORD0;
    float4 texcoord1 : TEXCOORD1;
    fixed4 color : COLOR;
#if defined(SHADER_API_XBOX360)
    half4 texcoord2 : TEXCOORD2;
    half4 texcoord3 : TEXCOORD3;
    half4 texcoord4 : TEXCOORD4;
    half4 texcoord5 : TEXCOORD5;
#endif
};

// #STRUCTS
// #VERTEX TO FRAGMENT STRUCT

// COLOR0, COLOR2.. etc is used for low precision 0-1 values
// TEXCOORD0, TEXCOORD1.. etc is used for high precision
// ^ this only matters on older, dx9 hardware

// Note: COLOR is the same as COLOR0, the same goes for TEXCOORD and TEXCOORD0 (TODO: check if true)

struct v2f {
    float4 pos : SV_POSITION;
    fixed4 color : COLOR; // this didn't neeed to be COLOR (see above)

    float4 uv : TEXCOORD0;
    float3 normal : TEXCOORD1;

    uint vid : SV_VertexID // vertex ID, needs to be uint, requires #pragma target 3.5
}; // NOTE THE SEMICOLON HERE AFTER STRUCT!

// #VERTEX SHADER

// If you only need position, you can return just a float4 in clip space
float4 vert (float4 vertex : POSITION) : SV_POSITION
{
    return UnityObjectToClipPos(vertex);
}

// if you have more data, you need to return a custom structure (see VERTEX TO FRAGMENT STRUCT)

// The values output from the vertex shader will be interpolated across the face of the rendered triangles,
// and the values at each pixel will be passed as inputs to the fragment shader.

v2f vert (appdata_base v)
{
    v2f o;
    o.pos = UnityObjectToClipPos(v.vertex); // clip pos, NOT object position
    // uv
    o.uv = float4( v.texcoord.xy, 0, 0 );
    // vertex color
    o.color = v.color;

    // VIEW (camera) - camera view
    o.viewDir = normalize(WorldSpaceViewDir(v.vertex));
    return o;
} // NO SEMICOLON AFTER FUNCTIONS!

o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
vs
o.vertex = UnityObjectToClipPos(v.vertex);
?

// #FRAGMENT SHADER

// usually, you would use : SV_Target semantic, like:
fixed4 frag (v2f i) : SV_Target
{
    return i.color // to visualize vertex color for eg.
}

// ---------

// but you can also return custom structure if you need additional colors (as in multiple render targets):
struct fragOutput
{
    fixed4 color : SV_Target;
    fixed4 color2 : SV_Target0; // for additional render targets .. add as many SV_TargetN as you need
    fixed4 depth : SV_Depth; // overrides the z buffer value. Note on some GPUs it turns off depth buffer optimizations
};

fragOutput frag (v2f i)
{
    fragOutput o;
    o.color = fixed4(i.uv, 0, 0);
    o.color2 = i.color;
    o.depth = 0;
    return o;
}

// ---------

// You can use VPOS to obtain screen space vertex position in pixels
// requires #pragma target 3.0
fixed4 frag (v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
{
    return fixed4(screenPos.xy, 0, 0); // X Y is in pixels!
}

// You can use VFACE to obtain face facing
// VFACE input positive for frontbaces,negative for backfaces
// requires #pragma target 3.0
fixed4 frag (fixed facing : VFACE) : SV_Target
{
    return facing > 0 ? _ColorFront : _ColorBack;
}

// ---------

// #BUILT-IN FUNCTIONS

// #INCLUDES

#include HLSLSupport.cginc // (automatically included) Helper macros and definitions for cross-platform shader compilation.
#include UnityShaderVariables.cginc // (automatically included) Commonly used global variables.

#include UnityCG.cginc // commonly used helper functions.
#include AutoLight.cginc // lighting & shadowing functionality, e.g. surface shaders use this file internally.
#include Lighting.cginc // standard surface shader lighting models; automatically included when you’re writing surface shaders.
#include TerrainEngine.cginc // helper functions for Terrain & Vegetation shaders.

// Vertex transformation functions in UnityCG.cginc
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.
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.

// Generic helper functions in UnityCG.cginc
float3 WorldSpaceViewDir (float4 v)    // Returns world space direction (not normalized) from given object space vertex position towards the camera.
float3 ObjSpaceViewDir (float4 v)    // Returns object space direction (not normalized) from given object space vertex position towards the camera.
float2 ParallaxOffset (half h, half height, half3 viewDir)    // calculates UV offset for parallax normal mapping.
fixed Luminance (fixed3 c)    // Converts color to luminance (grayscale).
fixed3 DecodeLightmap (fixed4 color)    // Decodes color from Unity lightmap (RGBM or dLDR depending on platform).
float4 EncodeFloatRGBA (float v)    // Encodes [0..1) range float into RGBA color, for storage in low precision render target.
float DecodeFloatRGBA (float4 enc)    // Decodes RGBA color into a float.
float2 EncodeFloatRG (float v)    // Encodes [0..1) range float into a float2.
float DecodeFloatRG (float2 enc)    // Decodes a previously-encoded RG float.
float2 EncodeViewNormalStereo (float3 n)    // Encodes view space normal into two numbers in 0..1 range.
float3 DecodeViewNormalStereo (float4 enc4)    // Decodes view space normal from enc4.xy.

// Only in forward rendering
float3 WorldSpaceLightDir (float4 v)    //Computes world space direction (not normalized) to light, given object space vertex position.
float3 ObjSpaceLightDir (float4 v)    //Computes object space direction (not normalized) to light, given object space vertex position.
float3 Shade4PointLights (...)    //Computes illumination from four point lights, with light data tightly packed into vectors. Forward rendering uses this to compute per-vertex lighting

// Screen-space helper functions in UnityCG.cginc
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.
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.
float3 ShadeVertexLights (float4 vertex, float3 normal)    // Computes illumination from four per-vertex lights and ambient, given object space position & normal.

UnityObjectToWorldNormal(normal); // To convert normals to world space

tex2D(_Tex, float2); // Texture sampling

// #BUILT-IN VARIABLES

// #Transformations
// TODOL CHeck if these still work
UNITY_MATRIX_MVP    // Current model * view * projection matrix.
UNITY_MATRIX_MV    // Current model * view matrix.
UNITY_MATRIX_V    // Current view matrix.
UNITY_MATRIX_P    // Current projection matrix.
UNITY_MATRIX_VP    // Current view * projection matrix.
UNITY_MATRIX_T_MV    // Transpose of model * view matrix.
UNITY_MATRIX_IT_MV    // Inverse transpose of model * view matrix.

unity_WorldToObject // Inverse of current world matrix. _World2Object is obsolete
unity_ObjectToWorld // Current model matrix. _Object2World is obsolete

// To get UVs
newUV = TRANSFORM_TEX(oldUV, _MainTex); // replace with the name of your texture
// also remember to declare the float4 _MainTex_ST; variable before using the macro

// #Camera & Screen
_WorldSpaceCameraPos    // float3    World space position of the camera.
_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.
_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.
_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).
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.
unity_CameraProjection    // float4x4    Camera’s projection matrix.
unity_CameraInvProjection    // float4x4    Inverse of camera’s projection matrix.
unity_CameraWorldClipPlanes[6]    // float4    Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far.

// #Time
_Time    // float4    Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders.
_SinTime    // float4    Sine of time: (t/8, t/4, t/2, t).
_CosTime    // float4    Cosine of time: (t/8, t/4, t/2, t).
unity_DeltaTime    // float4    Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).

// #Lights
_LightColor0 // (declared in Lighting.cginc)    fixed4    Light color
_WorldSpaceLightPos0    // float4    Directional lights: (world space direction, 0). Other lights: (world space position, 1).
_LightMatrix0 // (declared in AutoLight.cginc)    float4x4    World-to-light matrix. Used to sample cookie & attenuation textures.
// forward only:
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0    // float4    (ForwardBase pass only) world space positions of first four non-important point lights.
unity_4LightAtten0    // float4    (ForwardBase pass only) attenuation factors of first four non-important point lights.
unity_LightColor    // half4[4]    (ForwardBase pass only) colors of of first four non-important point lights.
// deffered:
_LightColor    //float4    Light color.
_LightMatrix0    //float4x4    World-to-light matrix. Used to sample cookie & attenuation textures.
// vertex lit:
unity_LightColor    // half4[8]    Light colors.
unity_LightPosition    // float4[8]    View-space light positions. (-direction,0) for directional lights; (position,1) for point/spot lights.
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.
unity_SpotDirection    // float4[8]    View-space spot light positions; (0,0,1,0) for non-spot lights.

// #Ambient
unity_AmbientSky    // fixed4    Sky ambient lighting color in gradient ambient lighting case.
unity_AmbientEquator    // fixed4    Equator ambient lighting color in gradient ambient lighting case.
unity_AmbientGround    // fixed4    Ground ambient lighting color in gradient ambient lighting case.

// #Fog
// UNITY_LIGHTMODEL_AMBIENT    // fixed4    Ambient lighting color (sky color in gradient ambient case). Legacy variable.
unity_FogColor    // fixed4    Fog color.
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.

// #LOD
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.

//-------------------
//-- #TRANSPARENCY --
//-------------------


// #ALPHA TEST TRANSPARENCY == // (aka #CUTOFF, #CUTOUT)

// To make a thing transparent:
// Make sure you use have these 2 tags:
Tags {
    "Queue" = "AlphaTest" 
    "RenderType" = "TransparentCutout"
}

// In frag shader add:
clip(col.a - 0.5); // this 0.5 is the cutoff value, you can put it in a variable or property


// #ALPHA BLEND TRANSPARENCY

Tags { 
    "Queue"="Transparent" 
    "RenderType"="Transparent"
}

// Use one of the Blend modes see BLEND MODES
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
ZWrite Off
//Cull Off // optional

//----------
//-- #FOG --
//----------

// Unity provides some useful macros for implementing built-in fog that can be configured in Lighting tab
#pragma multi_compile_fog

#include "UnityCG.cginc"

// inside your v2f struct add:
struct v2f {
    ...
    UNITY_FOG_COORDS(1) // the number (1) is an unused TEXCOORD-number, so if you already have TEXCOORD1, use (2)
}

// in the vert shader add UNITY_TRANSFER_FOG
v2f vert (appdata_t v) {
    v2f o;
    ...
    UNITY_TRANSFER_FOG(o,o.vertex);
    return o;
}

// add UNITY_APPLY_FOG to your frag shader like
fixed4 frag (v2f i) : SV_Target {
    ...
    UNITY_APPLY_FOG(i.fogCoord, col); // i.fogCoord is generated by UNITY_FOG_COORDS
    return col;
}


//-----------------------------------
//-- #GPU INSTANCING - #INSTANCING --
//-----------------------------------

#pragma multi_compile_instancing

#include "UnityCG.cginc"

struct appdata_t {
    ...
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

// It seems that this block required even tho you don't have any per instance properties
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color) // Make _Color an instanced property (i.e. an array)
#define _Color_arr Props
UNITY_INSTANCING_BUFFER_END(Props)

v2f vert (appdata_t v)
{
    v2f o;
    UNITY_SETUP_INSTANCE_ID(v);
    ...
    return o;
}

//-------------------------------
//-- #VR - #STEREO SINGLE PASS --
//-------------------------------

// To support stereo single pass you need to put these macros to pass the eye index to the fragment shader.
// For example, if you’re using any of the view or projection matrices or the camera position in the fragment shader
// these need the eye index to give the correct value, otherwise you’ll always access the left eye.

#include "UnityCG.cginc"

struct appdata_t {
    ...
    UNITY_VERTEX_INPUT_INSTANCE_ID
}

struct v2f {
    ...
    UNITY_VERTEX_OUTPUT_STEREO
}

v2f vert (appdata_t v)
{
    v2f o;
    UNITY_SETUP_INSTANCE_ID(); // for single pass instanced. Not necessary?
    UNITY_INITIALIZE_OUTPUT(v2f, o); // for single pass instanced. Not necessary?
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    ...
    return o;
}

// in frag shader, eye can be accessed with
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i)
// but it is not necessary, unless you are writing a post shader for example

//---------------------------------------------------
//-- #MULTI_COMPILE #SHADER KEYWORDS #KEYWORDS ------
//---------------------------------------------------

// using multi_compile directives enables making multiple shader variants #pragma multi_compile VARIANT_1 VARIANT_2 etc..

//-------------
// 2 VARIANTS

// with 2 variants, using __ will assume the "off" variant, you can write it like:
#pragma multi_compile __ THINGY

// use in code as:
#if defined(THINGY)
    // do something when enabled
#else
    // do something when disabled
#endif

// to create a property that will toggle it:
[Toggle(THINGY)] _Thingy("Thingy", Float) = 0 // the name of the property (_Thingy in this case) doesn't seem to be relevant

// or you can toggle from code using Shader.EnableKeyword/DisableKeyword or Material.EnableKeyword/DisableKeyword

//--------------------
// MULTIPLE VARIANTS

#pragma multi_compile _SOMETHING_THIS _SOMETHING_ELSE _SOMETHING_OTHERWISE

// use similar to the above:
#if defined(_SOMETHING_THIS)
    // do something only when SOMETHING_1 is defined
#endif

// Auto-property for more than 2 variants.
// Each name will enable "property name" + underscore + "enum name", uppercased, shader keyword. Up to 9 names can be provided.
[KeywordEnum(This, Else, Otherwise)] _Something("Something?", Float) = 0 // Here the property name IS relevant

//-------------------------------
//-- #SHADOW CASTING ------------
//-------------------------------

// incomplete, not tested

Pass
{
    Tags{ "LightMode" = "ShadowCaster" }

    Fog{ Mode Off }
    ZWrite On ZTest Less Cull Off
    Offset 1, 1

    CGPROGRAM
            
        #pragma vertex vert
        #pragma fragment frag
        #pragma multi_compile_shadowcaster
        #pragma fragmentoption ARB_precision_hint_fastest
        
        #include "UnityCG.cginc"

        struct v2f
        {
            V2F_SHADOW_CASTER;
        };

        v2f vert(appdata_base v)
        {
            v2f o;
            TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
            return o;
        }

        float4 frag(v2f i) : COLOR
        {
            SHADOW_CASTER_FRAGMENT(i)
        }

    ENDCG
}

//-----------------------------------------------//
//-----------------------------------------------//
//----------   SURFACE     SHADERS   ------------//
//-----------------------------------------------//
//-----------------------------------------------//

// #SURFACE SHADERS

Shader "Example/Diffuse Simple" 
{
    Properties // See PROPERTIES
    {
        
    }

    SubShader // Note, SubShader, unlike "Pass" in vert/frag shaders
    {
        Tags // see tags. Note, tags inside the SubShader {} unlike vert/frag shaders

        CGPROGRAM
        #pragma surface surf Lambert
        
        struct Input {
            float4 color : COLOR;
        };

        void surf (Input IN, inout SurfaceOutput o) {
            o.Albedo = 1;
        }

        ENDCG
    }
    Fallback "Diffuse"
  }

//
IN.worldNormal
IN.viewDir

 

STM32F407 CubeMX UART DMA高效解析BNO085九轴数据 本文详细介绍了如何在STM32F407平台上使用CubeMX配置UART和DMA高效解析BNO085九轴传感器数据。通过DMA循环接收机制实现低CPU占用的实时数据采集,并分享数据解析技巧、错误处理及实战调试经验,为嵌入式开发者提供完整解决方案。 阅读详情

相关推荐

引入 CloudWeGo 后飞书管理后台平台化改造的演进史

飞书管理后台是飞书套件专为企业管理员提供的信息管理平台,它通过引入 Kitex 泛化调用对飞书管理后台进行平台化改造,成为了企业统一数字化管理平台。本文将从三个方面为大家讲解 Kitex 泛化调用在飞书管理后台平台化改造过程中的落地实践。...

weixin_44186218的博客 1762

Unity官方第三人称控制资源包Starter Assets导入后错误却一堆?

Property _OutlineWidthTexture already exists in the property sheet with a different type: 4 The namespace 'StarterAssets' already contains a definition for 'StarterAssetsInputs' 如果选择universal 3d sample这个核心模板,然后又导入官方第三人称资源报,估计就是这样的错误。

weixin_63205365的博客 1171

6G网络的关键技术、应用前景与挑战并存的科技征途

移动通信技术正以前所未有的速度迭代更新,而6G技术的研发进程渐渐成为了当前科技领域的热点。全球各国已纷纷将目光投向了充满想象的6G时代。本文将探讨全球6G技术研发的最新进展,以及6G技术的核心创新与潜在应用。

fiberroad的博客 2423

Spring整合出现的错误,那位大神帮一下!!!!!!!!!

java.lang.NoSuchMethodError: org.apache.commons.pool.impl.GenericObjectPool: method ()V not found at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1165) at org.apache

zftzyw的专栏 647

扣子工作流实战演练

例如,你可以在代码节点的输入中引用大模型节点的输出,这样代码节点就可以使用大模型节点的输出。扣子的工作流节点并不是固定的,而是由一系列可以任意添加的节点组成的,每个节点都有其特定的功能和用途。扣子工作流中常见的节点类型如图4-2所示。在图像生成节点中设置模型为人像,输入参数名为input,变量值引用开始节点的renwu,正向提示词为{{input}},如图4-19所示。然后添加两个节点,选择“图像生成”和“画板”,将“开始”节点、“图像生成”节点、“画板”节点、“结束”节点依次串联,如图4-17所示。

夏天又到了的专栏 1583

【论文阅读|小目标分割算法ASF-YOLO】

论文题目:ASF-YOLO: A novel YOLO model with attentional scale sequence fusion for cell instance segmentation 论文链接: https://arxiv.org/abs/2312.06458 代码链接:https://github.com/mkang315/ASF-YOLO 摘要(Abstract) 作者提出了一种新颖的基于 "You Only Look Once"(YOLO)的注意力尺度序列融合框架(ASF-YO

dally2的博客 8118

Material Shader Graphs doesn‘t have a texture property ‘_MainTex‘解决方法

Material Shader Graphs doesn't have a texture property '_MainTex'解决方法

jkjj00的博客 3145

从部署到养成:Hermes智能体接入DeepSeek与微信机器人的完整实战指南

智能体(Agent)正成为大模型从“对话”走向“行动”的关键形态。它通过拆解指令、调用工具、执行任务,让AI真正参与工作流。Hermes作为可本地部署的开源智能体框架,支持接入DeepSeek等主流大模型,并提供网关、工具调用、记忆管理等模块化能力。从Docker容器部署到微信机器人桥接,从自动化定时任务到Computer Use桌面控制,Hermes将个人助理从概念落地为可运行的工程系统。本文基于真实实践,梳理架构原理、部署流程、API配置与高频故障排查,为技术玩家提供一套从零到一的上手指南。

weixin_29045001的博客 263

org.eclipse.mat.SnapshotException: SnapshotImpl_Error_ObjectNotFound

* FAILURE: org.eclipse.mat.SnapshotException: SnapshotImpl_Error_ObjectNotFound at org.eclipse.mat.parser.internal.SnapshotImpl.mapAddressToId(SnapshotImpl.java:1194) at org.eclipse.mat.snapshot.mo

bright789的博客 2250

软考中级网络工程师通关指南:从学习到实战

本文是软考中级网络工程师备考实用指南,先介绍备考前准备,包括考试时间、形式、分值等基本信息,及引导读者评估自身基础以制定学习计划;再推荐官方教材、辅导书籍、在线课程平台和学习社区等优质资源。随后梳理网络协议、设备配置、安全、规划设计等重点知识,剖析企业网络故障排查与园区网络设计典型案例。还分享真题使用、解题技巧、错题本建立等习题解答方法,给出分阶段备考、时间安排与总结反思的备考计划,最后提供考场答题顺序、检查及心态调整策略,助力考生高效备考、顺利通关。

邓邓子的博客 1851

DMA engine initialization failed rk3568的原因及解决方案

刚开始调试 switch 芯片的时候由于rgmii 时钟是output , rk3568的 GMAC 需要 switch 芯片提供 125M的时钟,如果没有这个时钟就会初始化失败,进入文件系统后 ethx 不会出现(当然,如果屏蔽掉这里ethx 会出现,但是引发更多的问题,笔者在这块耍小聪明,导致耗费了近一个月时间,把网络这块整个查了一遍 -----)dma 软复位是在进入文件系统后,网络系统启动的时候,我想如果在这个之前只要提供合适的时钟那么就是可以的,那么------以上是官方的文档说明。

Nyiragongo的博客 4571

unity path already exists

一个比较搞笑,但是如果反应不过来会很费时间的小毛病。 你只需要把自己创建项目的地址写下来就行。

雪比图 953

[特殊字符] RK3588 平台上基于 Panfrost 的 Mesa 驱动编译全过程

摘要: 本文详细记录了在RK3588平台(Ubuntu 20.04 aarch64)上编译基于Panfrost的Mesa驱动的全过程。内容包括:1)系统依赖安装;2)libdrm编译;3)Mesa配置参数优化;4)LLVM 15与SPIRV工具链的安装方法;5)SPIRV-Tools版本问题的解决方案;6)最终编译命令及常见错误处理。关键点在于正确设置工具链路径(PKG_CONFIG_PATH)和版本匹配(LLVM 15对应SPIRV-LLVM-Translator v15.0.0),推荐将组件安装在/op

梁俊星的博客 938

Unity3d_shader_Transparency(解决透明材质物体重叠穿透问题)

解决两个透明材质物体穿透问题。

yangzhen_010的博客 1919

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【Python】解决类中特性(property)覆盖同名属性(attribute)报错问题

解决 Python 装饰器 property 覆盖同名 attribute 报错问题。

东寻的博客 852

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Package already exists with a different case.

出错的原因是包已存在,但具有不同的大小写。 在java中,包名是不区分大小写的,但包的命名规范是一律小写。

weixin_44479107的博客 1129

【Unity问题】遇到 `global::' already contains a definition怎么办

Assets/Scripts/LHtest.cs(7,14): error CS0101: The namespace `global::' already contains a definition for `LHtest' 首先看代码是否没问题。如果关闭UNITY,VS。再打开,没有效果。 那么就把完整的正确的代码复制粘贴到另外一个新建.CS文件中。再运行这个新建的.CS文

BuladeMian的博客,菜得抠脚,菜得真实 1万+

excel中自定义公式_Excel中的自定义文档属性

excel中自定义公式When developing Excel applications, it's a common need to be able to store settings or non-sheet data so that they are available the next time you open Excel. Some examples of data you migh...

cunchi8090的博客 791

关于 HSSF 和 XSSF 功能的开发者入门指南 (Apache POI 操作 Excel)

关于 HSSF 和 XSSF 功能的开发者入门指南 笔者深夜无眠,特此对本文翻译一部分,未完成部分待后续更新 本文源文地址 意欲使用 HSSF 和 XSSF 功能快熟读写电子表格?那本文就是为你而写的。如果你之后想要更深入的了解 HSSF 和 XSSF 的用户 API , 请阅读 HOWTO guide ,它包含了如何使用这些东西的详细描述。 功能索引 How to create...

baobei78316的博客 1138

一个很简单的错误

  不知道是我变笨了,还是脑子短路了,在用代码动态添加控件之前,先移除所有控件,否则就会重复。 转载于:https://www.cnblogs.com/android-yus/p/5591242.html...

weixin_38168382的博客 275

unity报错解决办法汇总(持续更新)

unity报错解决办法汇总(持续更新) 问题:GUIText has been removed. Use UI.Text instead 解决办法:引入头文件UI:UnityEngine.UI;然后将GUIText替换成Text。

头号玩家的博客 1342

有关属性对话框(property sheet )的几个提示

有关属性对话框(property sheet )的几个提示闻怡洋下面的所有例子,都假定你从CPropertySheet中派生了新类。1、隐藏APPLY按钮使用 PSH_NOAPPLYNOW 标志. propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;2、增加新的子窗口使用成员变量。CEdit m_edit.BOOL CMyPropShee

1228

该行已属于另一个表的解决办法

dt.Rows.Add(dr[i])这种情况下,会出现改行已属于另一个表 解决方法为dt.Rows.Add(dr[i].ItemArray) 转载于:https://www.cnblogs.com/ZXdeveloper/p/3805810.html

weixin_30908707的博客 122

使用Navicat连接MySQL时报错:Connection with same connection name already exists in the project.

报错: Connection with same connection name already exists in the project. 原因: 项目中已经存在相同连接名称的连接。 解决方案: 点击连接名test右击删除连接,再建一个新的连接即可。

蓝多多的小仓库 1万+

iphone 开发中属性 property 和 synthesize 权威的介绍

在Objective-c 2 .0中引入了 property 和 synthesize 为方便存取   1 让大家认识一下 property  and  synthesize  吧 @property预编译命令的作用是自动声明属性的setter和getter方法  @synthesize也是一种新的编译器功能,表示“创建该属性的访问器” 废话少说~~ 下面更精彩哦~~~ 下面我们来对比一下...

cuichang 167

Property Sheet

1.When create a CPropertySheet derived class object on a dialog, must modify the style of the window when init, else when the MainWnd lose its focus, the application will be death:BOOL CMySheet::O

唐昊的专栏 951

属性项目的定义(property)

http://c.gzl.name/archives/tag/nonatomic @property (copy, nonatomic) NSString *title; 什么是assign,copy,retain之间的区别? assign: 简单赋值,不更改索引计数(Reference Counting)。 copy: 建立一个索引计数为1的对象,

leonpengweicn的专栏 1434
上一篇: Unity 代码片段2021篇 (记录)
下一篇: UGUI原理及优化建议
警醒与鞭策
博客等级 码龄16年 2万+粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值