LayaPBRSpecularLighting.cginc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "LayaBRDF.cginc"
  2. half4 SpecularGloss(float2 uv)
  3. {
  4. half4 sg;
  5. #ifdef SpecularTexture
  6. #if Smoothness_DiffuseTexture_Alpha
  7. sg.rgb = tex2D(_SpecGlossMap, uv).rgb;
  8. sg.a = tex2D(_MainTex, uv).a;
  9. #else
  10. sg = tex2D(_SpecGlossMap, uv);
  11. #endif
  12. sg.a *= _GlossMapScale;
  13. #else
  14. sg.rgb = _SpecColor.rgb;
  15. #ifdef Smoothness_DiffuseTexture_Alpha
  16. sg.a = tex2D(_MainTex, uv).a * _GlossMapScale;
  17. #else
  18. sg.a = _Glossiness;
  19. #endif
  20. #endif
  21. return sg;
  22. }
  23. inline half4 LayaPBRSpecularLighting(half4 diffuseColor, half3 specularColor, half smoothness, half3 normal, half3 viewDir, half3 lightDir, LayaGI gi)
  24. {
  25. normal = normalize(normal);
  26. half oneMinusReflectivity;
  27. half3 diffColor;
  28. half alpha;
  29. diffColor = LayaEnergyConservationBetweenDiffuseAndSpecular(diffuseColor.rgb, specularColor, /*out*/ oneMinusReflectivity);
  30. diffColor = LayaPreMultiplyAlpha(diffColor, diffuseColor.a, oneMinusReflectivity, /*out*/alpha);
  31. half4 c = BRDF1_Laya_PBS(diffColor, specularColor, oneMinusReflectivity, smoothness, normal, viewDir, lightDir, gi);
  32. c.a = alpha;
  33. return c;
  34. }