Синтаксис:
Используется csharp
Shader "Custom/MyShader" {
Properties {
_MainTint ("Diffuse Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_SpecularColor ("Specular Tint", Color) = (1,1,1,1)
_LightColorO ("Light Color", Color) = (1,1,1,1) // данной строчки в книге не было
_SpecularMask ("Specular Texture", 2D) = "white" {}
_SpecPower ("Specular Power", Range(0.1, 120)) = 3
}
SubShader {
CGPROGRAM
#pragma surface surf CustomPhong
sampler2D _MainTex;
sampler2D _SpecularMask;
float4 _MainTint;
float4 _SpecularColor;
float4 _LightColorO; // данной строчки в книге небыло, но без неё обишка
float _SpecPower;
struct SurfaceCustomOutput
{
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
fixed3 SpecularColor;
half Specular;
fixed Gloss;
fixed Alpha;
};
inline fixed4 LightingCustomPhong (SurfaceCustomOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
float diff = dot(s.Normal, lightDir);
float3 reflectionVector = normalize(2.0 * s.Normal * diff - lightDir);
float spec = pow(max(0.0f,dot(reflectionVector, viewDir)), _SpecPower) * s.Specular;
float3 finalSpec = s.Specular * spec * _SpecularColor.rgb;
fixed4 c;
c.rgb = (s.Albedo * _LightColorO.rgb * diff) + (_LightColorO.rgb * finalSpec);
c.a = s.Alpha;
return c;
}
struct Input
{
float2 uv_MainTex;
float2 uv_SpecularMask;
};
void surf (Input IN, inout SurfaceCustomOutput o)
{
float4 c = tex2D(_MainTex, IN.uv_MainTex) * _MainTint;
float4 specMask = tex2D(_SpecularMask, IN.uv_SpecularMask) * _SpecularColor;
o.Albedo = c.rgb;
o.Specular = specMask.r;
o.SpecularColor = specMask.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
Properties {
_MainTint ("Diffuse Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_SpecularColor ("Specular Tint", Color) = (1,1,1,1)
_LightColorO ("Light Color", Color) = (1,1,1,1) // данной строчки в книге не было
_SpecularMask ("Specular Texture", 2D) = "white" {}
_SpecPower ("Specular Power", Range(0.1, 120)) = 3
}
SubShader {
CGPROGRAM
#pragma surface surf CustomPhong
sampler2D _MainTex;
sampler2D _SpecularMask;
float4 _MainTint;
float4 _SpecularColor;
float4 _LightColorO; // данной строчки в книге небыло, но без неё обишка
float _SpecPower;
struct SurfaceCustomOutput
{
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
fixed3 SpecularColor;
half Specular;
fixed Gloss;
fixed Alpha;
};
inline fixed4 LightingCustomPhong (SurfaceCustomOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
float diff = dot(s.Normal, lightDir);
float3 reflectionVector = normalize(2.0 * s.Normal * diff - lightDir);
float spec = pow(max(0.0f,dot(reflectionVector, viewDir)), _SpecPower) * s.Specular;
float3 finalSpec = s.Specular * spec * _SpecularColor.rgb;
fixed4 c;
c.rgb = (s.Albedo * _LightColorO.rgb * diff) + (_LightColorO.rgb * finalSpec);
c.a = s.Alpha;
return c;
}
struct Input
{
float2 uv_MainTex;
float2 uv_SpecularMask;
};
void surf (Input IN, inout SurfaceCustomOutput o)
{
float4 c = tex2D(_MainTex, IN.uv_MainTex) * _MainTint;
float4 specMask = tex2D(_SpecularMask, IN.uv_SpecularMask) * _SpecularColor;
o.Albedo = c.rgb;
o.Specular = specMask.r;
o.SpecularColor = specMask.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
https://dropmefiles.com/j33RI - файл шейдера