Техника фейковая но картинка получается прикольная. По дефолту настроено на якобы нефрит, мне нравится =)
ссылка на статью: http://www.gamedev.ru/code/articles/Sub ... scattering
Вот картинки, что у меня получились (на картинке для сравнения рядом такой же меш с простым спекурял материалом одинакового цвета) :
Синтаксис:
Используется glsl
Shader "SubSurfaceScattering"
{
Properties
{
_Color ("Main Color", Color) = (1.0, 1.0, 0.6, 1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.03, 1)) = 0.8
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_LightRadius("Light source radius", Float) = 2
_fFalloffPower("Falloff", Float) = 2.0
_fLightSharpness("Light Sharpness", Float) = 16.0
_LightSoftness ("Light Softness", Range (0,1)) = 0.2
}
SubShader
{
Tags { "RenderType" = "Opaque" }
Cull Back
CGPROGRAM
#pragma surface surf SubSurface
float4 _Color;
float _Shininess;
sampler2D _MainTex;
float _LightRadius;
float _fFalloffPower;
float _fLightSharpness;
float _fLinearAttenuation;
float _LightSoftness;
half4 LightingSubSurface (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0) * s.Gloss;
// ШАГ 1 : смягчаем тени
diff = (1 - _LightSoftness + _LightSoftness * diff);
// ШАГ 2 : рассеивание
float fLightDistance = max( 0.0, length(lightDir) - _LightRadius );
float fScattering = min( 1.0, 2.5 / (1.0 + fLightDistance * atten ) );
fScattering = pow( fScattering, _fFalloffPower );
// ШАГ 3 : вычисляем проходящий сквозь объект свет
float3 vLightTovertex = normalize(lightDir);
float3 vViewTovertex = normalize(-viewDir);
float VdotL = max(0.0, dot(vLightTovertex, vViewTovertex));
VdotL = pow(VdotL, _fLightSharpness);
diff += VdotL;
half4 c;
c.rgb = (s.Albedo * diff * fScattering + spec) * (atten * 2) * _LightColor0.rgb;
c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
return c;
}
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
}
ENDCG
}
FallBack "None"
}
{
Properties
{
_Color ("Main Color", Color) = (1.0, 1.0, 0.6, 1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.03, 1)) = 0.8
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_LightRadius("Light source radius", Float) = 2
_fFalloffPower("Falloff", Float) = 2.0
_fLightSharpness("Light Sharpness", Float) = 16.0
_LightSoftness ("Light Softness", Range (0,1)) = 0.2
}
SubShader
{
Tags { "RenderType" = "Opaque" }
Cull Back
CGPROGRAM
#pragma surface surf SubSurface
float4 _Color;
float _Shininess;
sampler2D _MainTex;
float _LightRadius;
float _fFalloffPower;
float _fLightSharpness;
float _fLinearAttenuation;
float _LightSoftness;
half4 LightingSubSurface (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0) * s.Gloss;
// ШАГ 1 : смягчаем тени
diff = (1 - _LightSoftness + _LightSoftness * diff);
// ШАГ 2 : рассеивание
float fLightDistance = max( 0.0, length(lightDir) - _LightRadius );
float fScattering = min( 1.0, 2.5 / (1.0 + fLightDistance * atten ) );
fScattering = pow( fScattering, _fFalloffPower );
// ШАГ 3 : вычисляем проходящий сквозь объект свет
float3 vLightTovertex = normalize(lightDir);
float3 vViewTovertex = normalize(-viewDir);
float VdotL = max(0.0, dot(vLightTovertex, vViewTovertex));
VdotL = pow(VdotL, _fLightSharpness);
diff += VdotL;
half4 c;
c.rgb = (s.Albedo * diff * fScattering + spec) * (atten * 2) * _LightColor0.rgb;
c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
return c;
}
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
}
ENDCG
}
FallBack "None"
}