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. normal.xy = (packednormal.wy * 2 - 1);
  10. normal.xy *= bumpScale;
  11. normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
  12. return normal;
  13. }
  14. half2 LayaParallaxOffset(half h, half height, half3 viewDir )
  15. {
  16. h = h * height - height/2.0;
  17. half3 v = normalize(viewDir);
  18. v.z += 0.42;
  19. return h * (v.xy / v.z);
  20. }
  21. half LayaSpecularStrength(half3 specular)
  22. {
  23. return max(max(specular.r, specular.g), specular.b);
  24. }
  25. inline half3 LayaEnergyConservationBetweenDiffuseAndSpecular(half3 albedo, half3 specColor, out half oneMinusReflectivity)
  26. {
  27. oneMinusReflectivity = 1 - LayaSpecularStrength(specColor);
  28. return albedo * oneMinusReflectivity;
  29. }
  30. inline half3 LayaPreMultiplyAlpha(half3 diffColor, half alpha, half oneMinusReflectivity, out half outModifiedAlpha)
  31. {
  32. #if defined(ALPHAPREMULTIPLY_ON)
  33. diffColor *= alpha;
  34. outModifiedAlpha = 1 - oneMinusReflectivity + alpha * oneMinusReflectivity;
  35. #else
  36. outModifiedAlpha = alpha;
  37. #endif
  38. return diffColor;
  39. }