Readme.txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. Version 1.0.9
  2. My email is "kripto289@gmail.com"
  3. Discord Kripto#6346
  4. You can contact me for any questions.
  5. My English is not very good, and if I have any translation errors, you can write me :)
  6. Package includes 17 prefabs of the blood effects (blood mesh + decal) and prefab for shot point decal.
  7. Support platforms: all platforms (PC/Consoles/VR/Mobiles/URP/HDRP)
  8. ------------------------------------------------------------------------------------------------------------------------------------------
  9. IMPORTANT
  10. For all platforms required format "RGBA half" or compressed "RGB9e5 23 bit Shared Exponent Float" for textures with the name "blood_norm" and "blood_pos"
  11. RGB9e5 this is a lossy format so the blood drops will be sharper.
  12. For mobile devices you must to do "texture overide for android -> RGBA half/RGB9e5", because by default unity used RGBM encoding for android and this format does not work correctly.
  13. For HDRP and URP you need to import patches from the folder "\Assets\KriptoFX\VolumetricBloodFX\URP and HDRP Patches"
  14. For correct rendering of screen space decals you need:
  15. -For STANDARD FORWARD: MainCamera -> Add the script "BFX_RenderDepth"
  16. -For URP rendering mainCamera -> DepthTexture = ON
  17. -For HDRP depth rendering works by default
  18. ------------------------------------------------------------------------------------------------------------------------------------------
  19. Effects using:
  20. 1) Insantiate effect:
  21. The blood should be rotated to the right angle.
  22. Since the animation is baked and gravity must flow down. If you turn the effect up (for example) then the gravity animation will flow left/right.
  23. var direction = .... //you must assign the direction, for example Physics.Raycast(ray, out hit); direction = hit.normal;
  24. float angle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + 180;
  25. var instance = Instantiate(bloodPrefab, hit.point, Quaternion.Euler(0, angle + 90, 0));
  26. 2) Set the start height position for decal. It's your terrain/floor transform position Y
  27. instance.GetComponent<BFX_BloodSettings>().GroundHeight = ...
  28. Decal at the shot point (for example, on the character) may have problems with moved object.
  29. Unfortunately, there is no way to add a blood decal withoit visible arefacts to any object with different shaders and different UV.
  30. Therefore, the only method is to attach the decal as child to a bone or object. But this will produce visual artifacts (when the decal moves separately from the mesh).
  31. I use follow code for find nearest bone in the hit point:
  32. Transform GetNearestBone(Transform characterTransform, Vector3 hitPos)
  33. {
  34. var closestPos = 10f;
  35. Transform closestBone = null;
  36. var childs = characterTransform.GetComponentsInChildren<Transform>();
  37. foreach (var child in childs)
  38. {
  39. var dist = Vector3.Distance(child.position, hitPos);
  40. if (dist < closestPos)
  41. {
  42. closestPos = dist;
  43. closestBone = child;
  44. }
  45. }
  46. var distRoot = Vector3.Distance(characterTransform.position, hitPos);
  47. if (distRoot < closestPos)
  48. {
  49. closestPos = distRoot;
  50. closestBone = characterTransform;
  51. }
  52. return closestBone;
  53. }
  54. Code example:
  55. if (Input.GetMouseButtonDown(0)) //create blood splashes at mouse position (by left mouse button click)
  56. {
  57. var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  58. RaycastHit hit;
  59. if (Physics.Raycast(ray, out hit))
  60. {
  61. var nearestBone = GetNearestObject(hit.transform.root, hit.point);
  62. if(nearestBone == null) return;
  63. var attachedBloodInstance = Instantiate(attachedBloodDecal, nearestBone);
  64. var bloodT = attachedBloodInstance.transform;
  65. bloodT.position = hit.point;
  66. bloodT.localRotation = Quaternion.identity;
  67. bloodT.LookAt(hit.point + hit.normal, direction);
  68. bloodT.Rotate(90, 0, 0);
  69. Destroy(attachBloodInstance, 20);
  70. }
  71. }
  72. ------------------------------------------------------------------------------------------------------------------------------------------
  73. Effect optimisations:
  74. 1) You can change texture format for textures with the name "blood_norm" and "blood_pos".
  75. Click on current platform (not a "default" tab!) -> override for "current platform name" -> select format "RGB9e5 23 bit Shared Exponent Float"
  76. This format available with unity 2019.x+. Visual quality will suffer a little bit.
  77. 2) You can decrease height of decals. The decals is drawn in the form of a cube. Smaller the height of the cube -> the less pixels are drawn.
  78. Open blood prefab -> select decal -> change transform "y"
  79. 3) You can remove shadows and depth writing. With directional light and depth rendering you can decrease number of triangles x4 times!
  80. Open BFX_Blood shader -> find ths lines "//start remove line " and "//end remove light"
  81. Remove the code from the "start" to "end" lines. (150 -> 231 line number)
  82. 4) Use lower resolution for mobile devices :)
  83. Do you really need to render the game in 2-4k on screen with size 5-7 inches?? Even not many pc games can work in 4k. I find this unnecessary.
  84. For example use half resolution = 4x faster!
  85. Screen.SetResolution((int)(Screen.width * 0.5f), (int)(Screen.height * 0.5f), FullScreenMode.ExclusiveFullScreen, 60);
  86. ------------------------------------------------------------------------------------------------------------------------------------------
  87. Effect settings:
  88. For scaling just change a prefab transform scale.
  89. You can draw decals for only some layers.
  90. For that just add the script "BFX_BloodDecalLayers" on the main camera and select a layers for decal drawing.
  91. You can change the "decal rendering mode" to draw or ignore the selected layers.
  92. But this method has overhead since the selected layers need to be drawn in the depth buffer. You can optimize it (with a small artefacts) using smaller texture size. Just change the "LayerDepthResoulution" property.
  93. Each prefab of a blood (blood1 - blood 15) have the attached script "BFX_BloodSettings"
  94. 1) AnimationSpeed
  95. Speed of a fluid animation and a decal appearing animation.
  96. 2) GroundHeight
  97. You should set the start height of a blood decal. It's your ground/floor/terrain world height position (transform -> position.y). The blood decal will be projected at this point.
  98. I can't find the correct ground/floor height because some object doesn't have a collider.
  99. In other cases (when you use a character/monster with a collider) I can't find a correct height because the "raycast" can intersect the monster collider instead of floor collider.
  100. So you need to set this height manually.
  101. In some cases you can use the "layer" mask for project decals on the floor/ground only (without monster/characters/..., etc). And then you can just increase the scale of "bloodPrefab -> decal" (transform -> scale.y).
  102. For example instead of the default 2 meters you can use 6 meters or more. In this case the decal will be projected  to world height position from -3 to 3 meters.
  103. 3) LightIntensityMultiplier [0 - 1]
  104. Brightness intensity of blood and light glare. For day light use 1, for night use 0, etc.
  105. 4) FreezeDecalDisappearance
  106. Default animation of blood (include decal fadeout) ~15 second.
  107. You can stop(freeze) the disappearance animation of decal. if necessary, you can continue the animation, for example after 100 seconds, just by unfreezing the animation.
  108. 5) DecalRenderingMode (floorXZ/AverageRay)
  109. By default, decal works as a projector. In most cases, it is sufficient to project a decal onto the floor along the XZ axis.
  110. But sometimes it's necessary to project a decal onto the walls and floor in the same time. In this case, you can use the average angle between floor up vector and blood forward vector.
  111. This method requires more resources for projection, so more pixel shader calculations are required. I recommend use this method with caution.
  112. 6) ClampDecalSideSurface
  113. Trim the strong stretch of the blood texture at borders. (for example, when the projection look down and strong stretching on the sides is visible)
  114. ------------------------------------------------------------------------------------------------------------------------------------------