FogVoids.cginc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef VOLUMETRIC_FOG_2_FOG_VOIDS
  2. #define VOLUMETRIC_FOG_2_FOG_VOIDS
  3. #define FOG_MAX_VOID 8
  4. CBUFFER_START(VolumetricFog2FogVoidBuffers)
  5. float4 _VF2_FogVoidPositions[FOG_MAX_VOID];
  6. float4 _VF2_FogVoidSizes[FOG_MAX_VOID];
  7. #if defined(FOG_VOID_ROTATION)
  8. float4x4 _VF2_FogVoidMatrices[FOG_MAX_VOID];
  9. #endif
  10. int _VF2_FogVoidCount;
  11. CBUFFER_END
  12. half ApplyFogVoids(float3 wpos) {
  13. float sdf = 10.0;
  14. for (int k=0;k<_VF2_FogVoidCount;k++) {
  15. // sqr distance to void center
  16. #if defined(FOG_VOID_ROTATION)
  17. float3 vd = mul(_VF2_FogVoidMatrices[k], float4(wpos.xyz, 1.0)).xyz;
  18. vd *= vd;
  19. #else
  20. float3 vd = _VF2_FogVoidPositions[k].xyz - wpos.xyz;
  21. vd *= vd;
  22. // relative to void size
  23. vd *= _VF2_FogVoidSizes[k].xyz;
  24. #endif
  25. // rect
  26. float rect = max(vd.x, max(vd.y, vd.z));
  27. // circle
  28. float circ = vd.x + vd.y + vd.z;
  29. // roundness
  30. float voidd = lerp(rect, circ, _VF2_FogVoidSizes[k].w);
  31. // falloff
  32. voidd = lerp(1.0, voidd, _VF2_FogVoidPositions[k].w);
  33. // merge sdf
  34. sdf = min(sdf, voidd);
  35. }
  36. sdf = 1.0 - sdf;
  37. return saturate(sdf);
  38. }
  39. #endif