LayaUtil.cginc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. half LayaOcclusion(float2 uv)
  2. {
  3. half occ = tex2D(_OcclusionMap, uv).g;
  4. return LerpOneTo (occ, _OcclusionStrength);
  5. }
  6. half3 LayaUnpackScaleNormal(half4 packednormal, half bumpScale)
  7. {
  8. half3 normal;
  9. packednormal.x *= packednormal.w;
  10. normal.xy = (packednormal.xy * 2 - 1);
  11. normal.xy *= bumpScale;
  12. normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
  13. return normal;
  14. }
  15. half2 LayaParallaxOffset(half h, half height, half3 viewDir )
  16. {
  17. h = h * height - height/2.0;
  18. half3 v = normalize(viewDir);
  19. v.z += 0.42;
  20. return h * (v.xy / v.z);
  21. }
  22. half LayaSpecularStrength(half3 specular)
  23. {
  24. return max(max(specular.r, specular.g), specular.b);
  25. }
  26. inline half3 LayaEnergyConservationBetweenDiffuseAndSpecular(half3 albedo, half3 specColor, out half oneMinusReflectivity)
  27. {
  28. oneMinusReflectivity = 1 - LayaSpecularStrength(specColor);
  29. return albedo * oneMinusReflectivity;
  30. }
  31. inline half3 LayaPreMultiplyAlpha(half3 diffColor, half alpha, half oneMinusReflectivity, out half outModifiedAlpha)
  32. {
  33. #if defined(ALPHAPREMULTIPLY_ON)
  34. diffColor *= alpha;
  35. outModifiedAlpha = 1 - oneMinusReflectivity + alpha * oneMinusReflectivity;
  36. #else
  37. outModifiedAlpha = alpha;
  38. #endif
  39. return diffColor;
  40. }