Last active
October 29, 2020 15:41
-
-
Save akirayou/5a80ec60171dce449fe682e4626a1994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/aurora" | |
{ | |
Properties | |
{ | |
_MainTex ("NormalMap", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } | |
//Tags { "RenderType" = "Opaque" } | |
LOD 200 | |
Cull Front | |
CGPROGRAM | |
// Physically based Standard lighting model, and enable shadows on all light types | |
//# pragma surface surfaceFunction lightModel [optionalparams] | |
#pragma surface surf SimplePhong alpha:fade // addshadow //fullforwardshadows | |
//光沢 https://docs.unity3d.com/ja/2019.4/Manual/SL-SurfaceShaderLightingExamples.html | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
float3 rgb2hsv(float3 rgb) | |
{ | |
float3 hsv; | |
// RGBの三つの値で最大のもの | |
float maxValue = max(rgb.r, max(rgb.g, rgb.b)); | |
// RGBの三つの値で最小のもの | |
float minValue = min(rgb.r, min(rgb.g, rgb.b)); | |
// 最大値と最小値の差 | |
float delta = maxValue - minValue; | |
// V(明度) | |
// 一番強い色をV値にする | |
hsv.z = maxValue; | |
// S(彩度) | |
// 最大値と最小値の差を正規化して求める | |
if (maxValue != 0.0) { | |
hsv.y = delta / maxValue; | |
} | |
else { | |
hsv.y = 0.0; | |
} | |
// H(色相) | |
// RGBのうち最大値と最小値の差から求める | |
if (hsv.y > 0.0) { | |
if (rgb.r == maxValue) { | |
hsv.x = (rgb.g - rgb.b) / delta; | |
} | |
else if (rgb.g == maxValue) { | |
hsv.x = 2 + (rgb.b - rgb.r) / delta; | |
} | |
else { | |
hsv.x = 4 + (rgb.r - rgb.g) / delta; | |
} | |
hsv.x /= 6.0; | |
if (hsv.x < 0) | |
{ | |
hsv.x += 1.0; | |
} | |
} | |
return hsv; | |
} | |
float3 hsv2rgb(float3 hsv) | |
{ | |
float3 rgb; | |
if (hsv.y == 0) { | |
// S(彩度)が0と等しいならば無色もしくは灰色 | |
rgb.r = rgb.g = rgb.b = hsv.z; | |
} | |
else { | |
// 色環のH(色相)の位置とS(彩度)、V(明度)からRGB値を算出する | |
hsv.x *= 6.0; | |
float i = floor(hsv.x); | |
float f = hsv.x - i; | |
float aa = hsv.z * (1 - hsv.y); | |
float bb = hsv.z * (1 - (hsv.y * f)); | |
float cc = hsv.z * (1 - (hsv.y * (1 - f))); | |
if (i < 1) { | |
rgb.r = hsv.z; | |
rgb.g = cc; | |
rgb.b = aa; | |
} | |
else if (i < 2) { | |
rgb.r = bb; | |
rgb.g = hsv.z; | |
rgb.b = aa; | |
} | |
else if (i < 3) { | |
rgb.r = aa; | |
rgb.g = hsv.z; | |
rgb.b = cc; | |
} | |
else if (i < 4) { | |
rgb.r = aa; | |
rgb.g = bb; | |
rgb.b = hsv.z; | |
} | |
else if (i < 5) { | |
rgb.r = cc; | |
rgb.g = aa; | |
rgb.b = hsv.z; | |
} | |
else { | |
rgb.r = hsv.z; | |
rgb.g = aa; | |
rgb.b = bb; | |
} | |
} | |
return rgb; | |
} | |
/* | |
float3 viewDir - ビュー方向 | |
float4 with COLOR セマンティック - 補間された頂点ごとの色 | |
float4 screenPos - スクリーンスペース | |
float3 worldPos - ワールド空間の位置を含みます。 | |
float3 worldRefl - ワールドの反射ベクトル | |
float3 worldNormal - ワールドの法線ベクトル。 | |
*/ | |
struct Input | |
{ | |
float2 uv_MainTex; | |
float3 viewDir; | |
INTERNAL_DATA float3 worldNormal; | |
float3 worldRefl; | |
}; | |
// 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) | |
/* | |
struct SurfaceOutput | |
fixed3 Albedo; // ディフューズ色 | |
fixed3 Normal; // 書き込まれる場合は、接線空間法線 | |
fixed3 Emission; | |
half Specular; // 0..1 の範囲のスペキュラーパワー | |
fixed Gloss; // スペキュラー強度 | |
fixed Alpha; // 透明度のアルファ | |
struct SurfaceOutputStandard | |
fixed3 Albedo; // ベース (ディフューズかスペキュラー) カラー | |
fixed3 Normal; // 書き込まれる場合は、接線空間法線 | |
half3 Emission; | |
half Metallic; // 0=非メタル, 1=メタル | |
half Smoothness; // 0=粗い, 1=滑らか | |
half Occlusion; // オクルージョン (デフォルト 1) | |
fixed Alpha; // 透明度のアルファ | |
struct SurfaceOutputStandardSpecular | |
fixed3 Albedo; // ディフューズ色 | |
fixed3 Specular; // スペキュラー色 | |
fixed3 Normal; // 書き込まれる場合は、接線空間法線 | |
half3 Emission; | |
half Smoothness; // 0=粗い, 1=滑らか | |
half Occlusion; // オクルージョン (デフォルト 1) | |
fixed Alpha; // 透明度のアルファ | |
*/ | |
void surf(Input IN, inout SurfaceOutput o) | |
{ | |
half4 n = tex2D(_MainTex, IN.uv_MainTex); | |
o.Normal = UnpackScaleNormal(n,1.0); | |
o.Albedo=1;// texCUBE(_EnvMap, IN.worldRefl).rgb; | |
o.Emission = 0; | |
o.Alpha = 0.3; | |
o.Specular = 0.6; | |
o.Gloss = 1; | |
} | |
void LightingSimplePhong_GI( | |
SurfaceOutput s, | |
UnityGIInput data, | |
inout UnityGI gi) | |
{ | |
gi = UnityGlobalIllumination(data, 1.0, s.Normal); | |
} | |
float3 changeColor(float3 rgb,float hue,float sat) { | |
float3 hsv = rgb2hsv(rgb); | |
hsv.x = hue; | |
hsv.y = sat; | |
hsv.z *= 3; | |
return hsv2rgb(hsv); | |
} | |
half4 MyBlinnPhongLight(SurfaceOutput s, half3 viewDir, UnityLight light,float hue) | |
{ | |
half3 h = normalize(light.dir + viewDir); | |
fixed diff = max(0, dot(s.Normal, light.dir)); | |
float nh = max(0, dot(s.Normal, h)); | |
float spec = pow(nh, s.Specular * 128.0) * s.Gloss ; | |
float3 lc=changeColor(light.color,hue,0.8); | |
//float3 sc=changeColor(_SpecColor.rgb,hue,0.2); | |
float3 sc = changeColor(light.color, hue, 0.5); | |
half4 c; | |
c.rgb = s.Albedo* lc* diff + /*lc **/ sc * spec; | |
c.a = s.Alpha; | |
return c; | |
} | |
half4 LightingSimplePhong(SurfaceOutput s, half3 viewDir, UnityGI gi)//(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) | |
{ | |
float hue = dot(s.Normal, viewDir)*0.5+0.5 ; | |
if (hue > 1)hue -= 1; | |
if (hue < 0)hue += 1; | |
half4 c = MyBlinnPhongLight(s, viewDir, gi.light,hue); | |
/* | |
half NdotL = max(0, dot(s.Normal, lightDir)); | |
float3 R = normalize(-lightDir + 2.0 * s.Normal * NdotL); | |
float3 spec = pow(max(0, dot(R, viewDir)), 2.0); | |
half4 c; | |
c.rgb = s.Albedo * _LightColor0.rgb * NdotL + spec + fixed4(0.1f, 0.1f, 0.1f, 1); | |
*/ | |
//c.rgb += hsv2rgb(hsv); | |
//c.a = s.Alpha; | |
return c; | |
} | |
ENDCG | |
Cull Back | |
CGPROGRAM | |
// Physically based Standard lighting model, and enable shadows on all light types | |
//# pragma surface surfaceFunction lightModel [optionalparams] | |
#pragma surface surf SimplePhong alpha:fade // addshadow //fullforwardshadows | |
//光沢 https://docs.unity3d.com/ja/2019.4/Manual/SL-SurfaceShaderLightingExamples.html | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
float3 rgb2hsv(float3 rgb) | |
{ | |
float3 hsv; | |
// RGBの三つの値で最大のもの | |
float maxValue = max(rgb.r, max(rgb.g, rgb.b)); | |
// RGBの三つの値で最小のもの | |
float minValue = min(rgb.r, min(rgb.g, rgb.b)); | |
// 最大値と最小値の差 | |
float delta = maxValue - minValue; | |
// V(明度) | |
// 一番強い色をV値にする | |
hsv.z = maxValue; | |
// S(彩度) | |
// 最大値と最小値の差を正規化して求める | |
if (maxValue != 0.0) { | |
hsv.y = delta / maxValue; | |
} | |
else { | |
hsv.y = 0.0; | |
} | |
// H(色相) | |
// RGBのうち最大値と最小値の差から求める | |
if (hsv.y > 0.0) { | |
if (rgb.r == maxValue) { | |
hsv.x = (rgb.g - rgb.b) / delta; | |
} | |
else if (rgb.g == maxValue) { | |
hsv.x = 2 + (rgb.b - rgb.r) / delta; | |
} | |
else { | |
hsv.x = 4 + (rgb.r - rgb.g) / delta; | |
} | |
hsv.x /= 6.0; | |
if (hsv.x < 0) | |
{ | |
hsv.x += 1.0; | |
} | |
} | |
return hsv; | |
} | |
float3 hsv2rgb(float3 hsv) | |
{ | |
float3 rgb; | |
if (hsv.y == 0) { | |
// S(彩度)が0と等しいならば無色もしくは灰色 | |
rgb.r = rgb.g = rgb.b = hsv.z; | |
} | |
else { | |
// 色環のH(色相)の位置とS(彩度)、V(明度)からRGB値を算出する | |
hsv.x *= 6.0; | |
float i = floor(hsv.x); | |
float f = hsv.x - i; | |
float aa = hsv.z * (1 - hsv.y); | |
float bb = hsv.z * (1 - (hsv.y * f)); | |
float cc = hsv.z * (1 - (hsv.y * (1 - f))); | |
if (i < 1) { | |
rgb.r = hsv.z; | |
rgb.g = cc; | |
rgb.b = aa; | |
} | |
else if (i < 2) { | |
rgb.r = bb; | |
rgb.g = hsv.z; | |
rgb.b = aa; | |
} | |
else if (i < 3) { | |
rgb.r = aa; | |
rgb.g = hsv.z; | |
rgb.b = cc; | |
} | |
else if (i < 4) { | |
rgb.r = aa; | |
rgb.g = bb; | |
rgb.b = hsv.z; | |
} | |
else if (i < 5) { | |
rgb.r = cc; | |
rgb.g = aa; | |
rgb.b = hsv.z; | |
} | |
else { | |
rgb.r = hsv.z; | |
rgb.g = aa; | |
rgb.b = bb; | |
} | |
} | |
return rgb; | |
} | |
/* | |
float3 viewDir - ビュー方向 | |
float4 with COLOR セマンティック - 補間された頂点ごとの色 | |
float4 screenPos - スクリーンスペース | |
float3 worldPos - ワールド空間の位置を含みます。 | |
float3 worldRefl - ワールドの反射ベクトル | |
float3 worldNormal - ワールドの法線ベクトル。 | |
*/ | |
struct Input | |
{ | |
float2 uv_MainTex; | |
float3 viewDir; | |
INTERNAL_DATA float3 worldNormal; | |
float3 worldRefl; | |
}; | |
// 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) | |
/* | |
struct SurfaceOutput | |
fixed3 Albedo; // ディフューズ色 | |
fixed3 Normal; // 書き込まれる場合は、接線空間法線 | |
fixed3 Emission; | |
half Specular; // 0..1 の範囲のスペキュラーパワー | |
fixed Gloss; // スペキュラー強度 | |
fixed Alpha; // 透明度のアルファ | |
struct SurfaceOutputStandard | |
fixed3 Albedo; // ベース (ディフューズかスペキュラー) カラー | |
fixed3 Normal; // 書き込まれる場合は、接線空間法線 | |
half3 Emission; | |
half Metallic; // 0=非メタル, 1=メタル | |
half Smoothness; // 0=粗い, 1=滑らか | |
half Occlusion; // オクルージョン (デフォルト 1) | |
fixed Alpha; // 透明度のアルファ | |
struct SurfaceOutputStandardSpecular | |
fixed3 Albedo; // ディフューズ色 | |
fixed3 Specular; // スペキュラー色 | |
fixed3 Normal; // 書き込まれる場合は、接線空間法線 | |
half3 Emission; | |
half Smoothness; // 0=粗い, 1=滑らか | |
half Occlusion; // オクルージョン (デフォルト 1) | |
fixed Alpha; // 透明度のアルファ | |
*/ | |
void surf(Input IN, inout SurfaceOutput o) | |
{ | |
half4 n = tex2D(_MainTex, IN.uv_MainTex); | |
o.Normal = UnpackScaleNormal(n, 1.0); | |
o.Albedo = 1;// texCUBE(_EnvMap, IN.worldRefl).rgb; | |
o.Emission = 0; | |
o.Alpha = 0.3; | |
o.Specular = 0.6; | |
o.Gloss = 1; | |
} | |
void LightingSimplePhong_GI( | |
SurfaceOutput s, | |
UnityGIInput data, | |
inout UnityGI gi) | |
{ | |
gi = UnityGlobalIllumination(data, 1.0, s.Normal); | |
} | |
float3 changeColor(float3 rgb, float hue, float sat) { | |
float3 hsv = rgb2hsv(rgb); | |
hsv.x = hue; | |
hsv.y = sat; | |
hsv.z *= 3; | |
return hsv2rgb(hsv); | |
} | |
half4 MyBlinnPhongLight(SurfaceOutput s, half3 viewDir, UnityLight light, float hue) | |
{ | |
half3 h = normalize(light.dir + viewDir); | |
fixed diff = max(0, dot(s.Normal, light.dir)); | |
float nh = max(0, dot(s.Normal, h)); | |
float spec = pow(nh, s.Specular * 128.0) * s.Gloss; | |
float3 lc = changeColor(light.color, hue, 0.8); | |
//float3 sc=changeColor(_SpecColor.rgb,hue,0.2); | |
float3 sc = changeColor(light.color, hue, 0.5); | |
half4 c; | |
c.rgb = s.Albedo * lc * diff + /*lc **/ sc * spec; | |
c.a = s.Alpha; | |
return c; | |
} | |
half4 LightingSimplePhong(SurfaceOutput s, half3 viewDir, UnityGI gi)//(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) | |
{ | |
float hue = dot(s.Normal, viewDir) * 0.5 + 0.5; | |
if (hue > 1)hue -= 1; | |
if (hue < 0)hue += 1; | |
half4 c = MyBlinnPhongLight(s, viewDir, gi.light, hue); | |
/* | |
half NdotL = max(0, dot(s.Normal, lightDir)); | |
float3 R = normalize(-lightDir + 2.0 * s.Normal * NdotL); | |
float3 spec = pow(max(0, dot(R, viewDir)), 2.0); | |
half4 c; | |
c.rgb = s.Albedo * _LightColor0.rgb * NdotL + spec + fixed4(0.1f, 0.1f, 0.1f, 1); | |
*/ | |
//c.rgb += hsv2rgb(hsv); | |
//c.a = s.Alpha; | |
return c; | |
} | |
ENDCG | |
} | |
FallBack "Standard" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment