명도(Brightness)와 채도(Saturation)을 조절할 수 있는 Shader.
Hue(색상)과 Contrast(대비)를 조절할 수 있는 Shader에 비해 이쪽은 구현이 간단~
자세한 정보는 링크 참조 : https://forum.unity.com/threads/hue-saturation-brightness-contrast-shader.260649/
Shader "UnityKorea/StandardRoughnessDemoSBShift" {
Properties {
[Header(Simple StandardShader for Properties)]
[Space(20)]
_Color ("Color", Color) = (1.0, 1.0, 1.0 , 1.0)
_Bright("Brightness", Range(0,2)) = 2
_Sat("Staturation", Range(0,1)) = 1
[Space(20)]
_MainTex ("Albedo (RGB)", 2D) = "white" {}
[Space(20)]
[Normal][NoScaleOffset]_BumpMap("Normal Map", 2D) = "bump" {}
_BumpScale("Normal Intensity", Float) = 1.0
[Space(20)]
[NoScaleOffset]_MetallicMap("Meatllic", 2D) = "white" {}
_Metallic("Metallic", Range(0,1)) = 0.5
[Space(20)]
[NoScaleOffset]_RoughMap("Roughness", 2D) = "white" {}
_Glossiness("Roughness", Range(0,1)) = 0.5
[Space(20)]
[MaterialToggle(_Ocu_ON)] _Ocu("Occlusion Toggle", float) = 0
[NoScaleOffset]_OCMap("Occlusion", 2D) = "white" {}
_OccInten("Occlusion", Range(0, 1)) = 1
[Space(30)]
[Header(Emissive Parameter)]
[MaterialToggle(_Emi_ON)] _Emi("Emissive Toggle", float) = 0
_EmissiveColor("Emissive Color", Color) = (1.0, 1.0, 1.0, 1.0)
_EmissiveTex ("Emissive Texture(RGB)", 2D) = "white" {}
_EmissiveInten("Emissive Inten", Range(0, 5)) = 1
[Space(20)]
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Off : 2side", Float) = 2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull [_Cull]
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
#pragma shader_feature _Emi_ON
#pragma shader_feature _Ocu_ON
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _MetallicMap;
sampler2D _RoughMap;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
half _BumpScale;
fixed4 _Color;
half _Bright;
half _Sat;
#if _Ocu_ON
half _OccInten;
sampler2D _OCMap;
#endif
#if _Emi_ON
sampler2D _EmissiveTex;
fixed4 _EmissiveColor;
half _EmissiveInten;
#endif
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
fixed3 nm = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
fixed sg = tex2D(_MetallicMap, IN.uv_MainTex).r;
fixed sr = tex2D(_RoughMap, IN.uv_MainTex).r;
float3 Grayvalue = dot(c.rgb, float3(0.299, 0.587, 0.114));
o.Albedo = lerp(Grayvalue, c.rgb, _Sat) * _Bright;
o.Normal = nm * fixed3(1, _BumpScale, 1);
o.Metallic = sg * _Metallic;
o.Smoothness = sr * (1.0f - _Glossiness);
#if _Ocu_ON
fixed oc = tex2D(_OCMap, IN.uv_MainTex).r;
o.Occlusion = oc * _OccInten;
#endif
#if _Emi_ON
fixed3 em = tex2D(_EmissiveTex, IN.uv_MainTex);
o.Emission = em * _EmissiveColor * _EmissiveInten;
#endif
//o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}
inline float3 applyHue(float3 aColor, float aHue)
{
float angle = radians(aHue);
float3 k = float3(0.57735, 0.57735, 0.57735);
float cosAngle = cos(angle);
//Rodrigues' rotation formula
return aColor * cosAngle + cross(k, aColor) * sin(angle) + k * dot(k, aColor) * (1 - cosAngle);
}
inline float4 applyHSBEffect(float4 startColor, fixed4 hsbc)
{
float _Hue = 360 * hsbc.r;
float _Brightness = hsbc.g * 2 - 1;
float _Contrast = hsbc.b * 2;
float _Saturation = hsbc.a * 2;
float4 outputColor = startColor;
outputColor.rgb = applyHue(outputColor.rgb, _Hue);
outputColor.rgb = (outputColor.rgb - 0.5f) * (_Contrast) + 0.5f;
outputColor.rgb = outputColor.rgb + _Brightness;
float3 intensity = dot(outputColor.rgb, float3(0.299,0.587,0.114));
outputColor.rgb = lerp(intensity, outputColor.rgb, _Saturation);
return outputColor;
}
'Technical Report > Unity Shader' 카테고리의 다른 글
Unity Unlit Receive Shadow (0) | 2018.02.05 |
---|---|
Material properties and the GI system (0) | 2018.02.05 |
StandardRoughnessDemo (0) | 2018.01.25 |
Unity Standard Shader Smoothness AlphaTest Occlusion/Emissive toggle 분기 (0) | 2018.01.18 |
[번역]Unity Labs: AutoLOD – Experimenting with automatic performance improvements (0) | 2018.01.14 |