1.结构:经常在片段着色器里做一些UV变换
#pragma surface surf Lambert finalColor:mycolor vertex:myvert
2.Input Struct 成员变量:
(1)Uv+纹理变量的名字
struct Input
{
float2 uv_MainTex;
};
(2)还有其他的:
3.片段着色器的输出:
inout SurfaceOutput o
struct SurfaceOutput
{
fixed3 Albedo; // diffuse color
fixed3 Normal; // tangent space normal, if written
fixed3 Emission;
half Specular; // specular power in 0..1 range
fixed Gloss; // specular intensity
fixed Alpha; // alpha for transparencies
};
Shader "Custom/TestFragMent"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_ScollerX ("ScollerX",float) = 1
_ScollerY ("ScollerY",float) = 1
}
SubShader
{
// Tags { "RenderType"="Opaque" }
// LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
//#pragma surface surf Standard fullforwardshadows
#pragma surface surf Lambert
// Use shader model 3.0 target, to get nicer looking lighting
//#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
float _ScollerX;
float _ScollerY;
// 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)
void surf (Input IN, inout SurfaceOutput o)
{
float2 tmpUV = IN.uv_MainTex;
tmpUV.x += _Time.x * _ScollerX;
tmpUV.y += _Time.y * _ScollerY;
//从_MainTex进行纹理采样
o.Albedo = tex2D(_MainTex,tmpUV).rgb;
}
ENDCG
}
FallBack "Diffuse"
}
标签:surf,MainTex,tmpUV,float,图形学,Unity,pragma,Input,着色器
From: https://blog.csdn.net/woshiyuyanjia/article/details/143905416