ShaderSpecificBuiltin.cginc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
  2. // UNITY_SHADER_NO_UPGRADE
  3. #ifndef _VLB_SHADER_SPECIFIC_INCLUDED_
  4. #define _VLB_SHADER_SPECIFIC_INCLUDED_
  5. // POSITION TRANSFORM
  6. #if UNITY_VERSION < 540
  7. #define __VLBMatrixWorldToObject _World2Object
  8. #define __VLBMatrixObjectToWorld _Object2World
  9. #define __VLBMatrixV UNITY_MATRIX_V
  10. inline float4 VLBObjectToClipPos(in float3 pos) { return mul(UNITY_MATRIX_MVP, float4(pos, 1.0)); }
  11. #else
  12. #if VLB_CUSTOM_INSTANCED_OBJECT_MATRICES
  13. #define __VLBMatrixWorldToObject UNITY_ACCESS_INSTANCED_PROP(Props, _WorldToLocalMatrix)
  14. #define __VLBMatrixObjectToWorld UNITY_ACCESS_INSTANCED_PROP(Props, _LocalToWorldMatrix)
  15. #define __VLBMatrixV unity_MatrixV
  16. inline float4 VLBObjectToClipPos(in float3 pos) { return mul(mul(unity_MatrixVP, __VLBMatrixObjectToWorld), float4(pos, 1.0)); }
  17. #else
  18. #define __VLBMatrixWorldToObject unity_WorldToObject
  19. #define __VLBMatrixObjectToWorld unity_ObjectToWorld
  20. #define __VLBMatrixV UNITY_MATRIX_V
  21. #define VLBObjectToClipPos UnityObjectToClipPos
  22. #endif
  23. #endif
  24. inline float4 VLBObjectToWorldPos(in float4 pos) { return mul(__VLBMatrixObjectToWorld, pos); }
  25. #define VLBWorldToViewPos(pos) (mul(__VLBMatrixV, float4(pos.xyz, 1.0)).xyz)
  26. // FRUSTUM PLANES
  27. #define VLBFrustumPlanes unity_CameraWorldClipPlanes
  28. // CAMERA
  29. inline float3 __VLBWorldToObjectPos(in float3 pos) { return mul(__VLBMatrixWorldToObject, float4(pos, 1.0)).xyz; }
  30. inline float3 VLBGetCameraPositionObjectSpace(float3 scaleObjectSpace)
  31. {
  32. return __VLBWorldToObjectPos(_WorldSpaceCameraPos).xyz * scaleObjectSpace;
  33. }
  34. // DEPTH
  35. #ifndef UNITY_DECLARE_DEPTH_TEXTURE // handle Unity pre 5.6.0
  36. #define UNITY_DECLARE_DEPTH_TEXTURE(tex) sampler2D_float tex
  37. #endif
  38. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  39. #define VLBSampleDepthTexture(/*float4*/uv) (SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, (uv)/(uv.w)))
  40. #define VLBLinearEyeDepth(depth) (LinearEyeDepth(depth))
  41. // FOG
  42. #define VLB_FOG_UNITY_BUILTIN_COORDS
  43. #if VLB_ALPHA_AS_BLACK
  44. #define VLB_FOG_APPLY(color) \
  45. float4 fogColor = unity_FogColor; \
  46. fogColor.rgb *= color.a; \
  47. UNITY_APPLY_FOG_COLOR(i.fogCoord, color, fogColor);
  48. // since we use this shader with Additive blending, fog color should be modulated by general alpha
  49. #else
  50. #define VLB_FOG_APPLY(color) UNITY_APPLY_FOG(i.fogCoord, color);
  51. #endif
  52. #endif // _VLB_SHADER_SPECIFIC_INCLUDED_