Preview_DiffuseAndSpecularFromMetallic.shader 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Shader "Hidden/DiffuseAndSpecularFromMetallicNode"
  2. {
  3. Properties
  4. {
  5. _A ("_A", 2D) = "white" {}
  6. _B ("_B", 2D) = "white" {}
  7. }
  8. SubShader
  9. {
  10. Pass
  11. {
  12. CGPROGRAM
  13. #include "UnityCG.cginc"
  14. #include "Preview.cginc"
  15. #include "UnityStandardUtils.cginc"
  16. #pragma vertex vert_img
  17. #pragma fragment frag
  18. sampler2D _A;
  19. sampler2D _B;
  20. float3 ComputeDiffuseAndFresnel0( float3 baseColor, float metallic, out float3 specularColor, out float oneMinusReflectivity )
  21. {
  22. #if defined( UNITY_COLORSPACE_GAMMA )
  23. const float dielectricF0 = 0.220916301;
  24. #else
  25. const float dielectricF0 = 0.04;
  26. #endif
  27. specularColor = lerp( dielectricF0.xxx, baseColor, metallic );
  28. oneMinusReflectivity = 1.0 - metallic;
  29. return baseColor * oneMinusReflectivity;
  30. }
  31. float4 frag( v2f_img i ) : SV_Target
  32. {
  33. float4 baseColor = tex2D( _A, i.uv );
  34. float metallic = tex2D( _B, i.uv ).r;
  35. float3 specularColor = 0;
  36. float oneMinusReflectivity = 0;
  37. float3 diffuseColor = ComputeDiffuseAndFresnel0( baseColor, metallic, specularColor, oneMinusReflectivity );
  38. return float4( diffuseColor, 1 );
  39. }
  40. ENDCG
  41. }
  42. }
  43. }