/** Pigment map shader, to allow easy color customization on objects based on a number of color channels. Copyright (c) 2022 fluffy, https://beesbuzz.biz/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ Shader "Critter/PigmentMapped" { Properties { _MainTex("Fallback texture", 2D) = "white" {} _PigmentMap("Pigment mapping", 2D) = "black" {} _ColorMap("Color table", 2D) = "white" {} _SubsurfaceVCoord("Subsurface V coordinate", Range(0.0, 1.0)) = 0.015625 _SubsurfaceStrength("Subsurface strength", Range(0.0, 1.0)) = 1.0 _MetallicGlossMap("Metallic", 2D) = "white" {} _BumpScale("Scale", Float) = 1.0 [Normal] _BumpMap("Normal Map", 2D) = "bump" {} _OcclusionStrength("Occlusion strength", Range(0.0, 1.0)) = 1.0 _EmissionColor("Color", Color) = (0,0,0) _EmissionMap("Emission", 2D) = "white" {} // Blending state [HideInInspector] _Mode ("__mode", Float) = 0.0 [HideInInspector] _SrcBlend ("__src", Float) = 1.0 [HideInInspector] _DstBlend ("__dst", Float) = 0.0 [HideInInspector] _ZWrite ("__zw", Float) = 1.0 } CGINCLUDE #define UNITY_SETUP_BRDF_INPUT MetallicSetup ENDCG SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surface surf Standard fullforwardshadows nometa #pragma target 3.0 sampler2D _PigmentMap; sampler2D _ColorMap; sampler2D _BumpMap; sampler2D _MetallicGlossMap; float _OcclusionStrength; float _SubsurfaceVCoord; float _SubsurfaceStrength; struct Input { float2 uv_MainTex; }; void surf(Input IN, inout SurfaceOutputStandard o) { o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)); o.Metallic = tex2D(_MetallicGlossMap, IN.uv_MainTex).r; o.Smoothness = tex2D(_MetallicGlossMap, IN.uv_MainTex).a; // r/g -> colormap u/v // b -> subsurface // a -> occlusion float4 lookup = tex2D(_PigmentMap, IN.uv_MainTex); float subsurfaceAmount = lerp(1.0, 1.0 - _SubsurfaceStrength, lookup.b); o.Occlusion = lerp(1.0 - _OcclusionStrength, 1.0, lookup.a); o.Albedo = tex2D(_ColorMap, float2(lookup.r, 1.0 - lookup.g)) * tex2D(_ColorMap, float2(subsurfaceAmount, _SubsurfaceVCoord)) ; } ENDCG } FallBack "Standard" // CustomEditor "StandardShaderGUI" }