HardSurfaceLighting.cginc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //Hard Surface Shader Package, Written for the Unity engine by Bruno Rime: http://www.behance.net/brunorime brunorime@gmail.com
  2. #ifndef HARD_SURFACE_LIGHTING_INCLUDED
  3. #define HARD_SURFACE_PRO_LIGHTING_INCLUDED
  4. inline fixed4 LightingBlinnPhongHardsurfaceFront (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
  5. {
  6. fixed3 h = normalize (lightDir + viewDir);
  7. fixed diff = dot (s.Normal, lightDir);
  8. fixed difftrans = abs(diff) *1 - s.Alpha;
  9. diff = max(diff,difftrans);
  10. half nh = dot (s.Normal, h);
  11. nh = max(0,nh);
  12. half spec = pow (nh, s.Specular*128.0) * s.Gloss;
  13. fixed4 c;
  14. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten * 2);
  15. c.a = saturate (s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten);
  16. return c;
  17. }
  18. inline fixed4 LightingBlinnPhongHardsurfaceBack (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
  19. {
  20. fixed3 h = normalize (lightDir + viewDir);
  21. fixed diff = dot (-s.Normal, lightDir);
  22. fixed difftrans = abs(diff) *1 - s.Alpha;
  23. diff = max(diff,difftrans);
  24. half nh = dot (-s.Normal, h);
  25. nh = max(0,nh);
  26. half spec = pow (nh, s.Specular*128.0) * s.Gloss;
  27. fixed4 c;
  28. c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec ) * (atten * 2);
  29. c.a = saturate (s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten);
  30. return c;
  31. }
  32. half4 LightingBlinnPhongHardsurfaceFrontSM2 (SurfaceOutput s, half3 lightDir, half atten) {
  33. fixed NdotL = dot (s.Normal, lightDir);
  34. fixed Ntrans = abs(NdotL) * 1- s.Alpha ;
  35. fixed NFinal = max(NdotL,Ntrans);
  36. fixed4 c;
  37. c.rgb = s.Albedo * _LightColor0.rgb * (NFinal * atten * 2);
  38. c.a = s.Alpha;
  39. return c;
  40. }
  41. half4 LightingBlinnPhongHardsurfaceBackSM2 (SurfaceOutput s, half3 lightDir, half atten) {
  42. fixed NdotL = dot (-s.Normal, lightDir);
  43. fixed Ntrans = abs(NdotL) * 1- s.Alpha ;
  44. fixed NFinal = max(NdotL,Ntrans);
  45. fixed4 c;
  46. c.rgb = s.Albedo * _LightColor0.rgb * (NFinal * atten * 2);
  47. c.a = s.Alpha;
  48. return c;
  49. }
  50. #endif