140 lines
4.2 KiB
Plaintext
140 lines
4.2 KiB
Plaintext
|
|
Shader "Custom/ArmorShader" {
|
||
|
|
Properties {
|
||
|
|
_Color ("Color", Color) = (1,1,1,1)
|
||
|
|
_SpeColor ("Specular Color", Color) = (1,1,1,1)
|
||
|
|
_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
||
|
|
//_SpecInt ("Specular intensity", Range(0,2) ) = 0.5
|
||
|
|
//_SpecSat ("Specular saturation", Range(0,1) ) = 1.0
|
||
|
|
_Glossiness ("Smoothness", Range(0,1)) = 0.5
|
||
|
|
////_Shift ("shift", float) = 0.05
|
||
|
|
_Offset ("Offset", Range(0,0.5)) = 0.0
|
||
|
|
_Contrast ("Contrast", float) = 0.5
|
||
|
|
|
||
|
|
[MaterialToggle] _showSpecMap("show spec map", Float) = 0
|
||
|
|
|
||
|
|
//_SpecuColor ("Specular Color", Color) = (0,1,0,1)
|
||
|
|
}
|
||
|
|
SubShader {
|
||
|
|
Tags { "RenderType"="Opaque" }
|
||
|
|
LOD 200
|
||
|
|
|
||
|
|
CGPROGRAM
|
||
|
|
// Physically based Standard lighting model, and enable shadows on all light types
|
||
|
|
#pragma surface surf StandardSpecular fullforwardshadows
|
||
|
|
|
||
|
|
// Use shader model 3.0 target, to get nicer looking lighting
|
||
|
|
#pragma target 3.0
|
||
|
|
|
||
|
|
sampler2D _MainTex;
|
||
|
|
|
||
|
|
struct Input {
|
||
|
|
float2 uv_MainTex;
|
||
|
|
};
|
||
|
|
|
||
|
|
half _Glossiness;
|
||
|
|
//float4 _SpecuColor;
|
||
|
|
float _SpecInt;
|
||
|
|
fixed4 _Color;
|
||
|
|
fixed4 _SpeColor;
|
||
|
|
float _Offset;
|
||
|
|
float _Contrast;
|
||
|
|
float _Shift;
|
||
|
|
float _SpecSat;
|
||
|
|
float _showSpecMap;
|
||
|
|
|
||
|
|
//fixed3 Albedo; // diffuse color
|
||
|
|
//fixed3 Specular; // specular color
|
||
|
|
//fixed3 Normal; // tangent space normal, if written
|
||
|
|
//half3 Emission;
|
||
|
|
//half Smoothness; // 0=rough, 1=smooth
|
||
|
|
//half Occlusion; // occlusion (default 1)
|
||
|
|
// fixed Alpha; // alpha for transparencies
|
||
|
|
|
||
|
|
float3 rgbTohsv(float3 RGB)
|
||
|
|
{
|
||
|
|
float3 HSV;
|
||
|
|
|
||
|
|
float minChannel, maxChannel;
|
||
|
|
if (RGB.x > RGB.y) {
|
||
|
|
maxChannel = RGB.x;
|
||
|
|
minChannel = RGB.y;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
maxChannel = RGB.y;
|
||
|
|
minChannel = RGB.x;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (RGB.z > maxChannel) maxChannel = RGB.z;
|
||
|
|
if (RGB.z < minChannel) minChannel = RGB.z;
|
||
|
|
|
||
|
|
HSV.xy = 0;
|
||
|
|
HSV.z = maxChannel;
|
||
|
|
float delta = maxChannel - minChannel; //Delta RGB value
|
||
|
|
if (delta != 0) { // If gray, leave H S at zero
|
||
|
|
HSV.y = delta / HSV.z;
|
||
|
|
float3 delRGB;
|
||
|
|
delRGB = (HSV.zzz - RGB + 3*delta) / (6.0*delta);
|
||
|
|
if ( RGB.x == HSV.z ) HSV.x = delRGB.z - delRGB.y;
|
||
|
|
else if ( RGB.y == HSV.z ) HSV.x = ( 1.0/3.0) + delRGB.x - delRGB.z;
|
||
|
|
else if ( RGB.z == HSV.z ) HSV.x = ( 2.0/3.0) + delRGB.y - delRGB.x;
|
||
|
|
}
|
||
|
|
return (HSV);
|
||
|
|
}
|
||
|
|
|
||
|
|
float3 hsvTorgb(float3 HSV)
|
||
|
|
{
|
||
|
|
float3 RGB = HSV.z;
|
||
|
|
|
||
|
|
float var_h = HSV.x * 6;
|
||
|
|
float var_i = floor(var_h); // Or ... var_i = floor( var_h )
|
||
|
|
float var_1 = HSV.z * (1.0 - HSV.y);
|
||
|
|
float var_2 = HSV.z * (1.0 - HSV.y * (var_h-var_i));
|
||
|
|
float var_3 = HSV.z * (1.0 - HSV.y * (1-(var_h-var_i)));
|
||
|
|
if (var_i == 0) { RGB = float3(HSV.z, var_3, var_1); }
|
||
|
|
else if (var_i == 1) { RGB = float3(var_2, HSV.z, var_1); }
|
||
|
|
else if (var_i == 2) { RGB = float3(var_1, HSV.z, var_3); }
|
||
|
|
else if (var_i == 3) { RGB = float3(var_1, var_2, HSV.z); }
|
||
|
|
else if (var_i == 4) { RGB = float3(var_3, var_1, HSV.z); }
|
||
|
|
else { RGB = float3(HSV.z, var_1, var_2); }
|
||
|
|
|
||
|
|
return (RGB);
|
||
|
|
}
|
||
|
|
|
||
|
|
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
|
||
|
|
// Albedo comes from a texture tinted by color
|
||
|
|
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
|
||
|
|
|
||
|
|
|
||
|
|
float lum = Luminance(c.rgb) + _Offset;
|
||
|
|
|
||
|
|
//contrast
|
||
|
|
lum = clamp( ((lum - 0.5f) * max(_Contrast, 0)) + 0.5f , 0.0, 1.0 );
|
||
|
|
|
||
|
|
float3 scolHSV = rgbTohsv(_SpeColor.rgb);
|
||
|
|
float3 colHSV = rgbTohsv(c.rgb);
|
||
|
|
//scolHSV.z = _SpecInt;
|
||
|
|
//scolHSV.x += _Shift;
|
||
|
|
scolHSV.y = colHSV.y;
|
||
|
|
|
||
|
|
|
||
|
|
if( _showSpecMap == 1 )
|
||
|
|
{
|
||
|
|
o.Albedo = float4(lum, lum, lum, c.a);
|
||
|
|
o.Specular = float3(0,0,0);
|
||
|
|
o.Smoothness = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
o.Albedo = c.rgb;
|
||
|
|
o.Specular = hsvTorgb(scolHSV);
|
||
|
|
o.Specular *= lum;
|
||
|
|
o.Smoothness = _Glossiness;
|
||
|
|
}
|
||
|
|
|
||
|
|
o.Alpha = c.a;
|
||
|
|
}
|
||
|
|
ENDCG
|
||
|
|
}
|
||
|
|
FallBack "Diffuse"
|
||
|
|
}
|