Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #include "Common.cginc"
  2.  
  3. #define USE_AURA
  4.  
  5. float4 Aura_FrustumRange;
  6. sampler3D Aura_VolumetricDataTexture;
  7. sampler3D Aura_VolumetricLightingTexture;
  8.  
  9. //////////// Helper functions
  10. float Aura_RescaleDepth(float depth)
  11. {
  12. half rescaledDepth = InverseLerp(Aura_FrustumRange.x, Aura_FrustumRange.y, depth);
  13. return GetBiasedNormalizedDepth(rescaledDepth);
  14. }
  15.  
  16. float3 Aura_GetFrustumSpaceCoordinates(float4 inVertex)
  17. {
  18. float4 clipPos = UnityObjectToClipPos(inVertex);
  19.  
  20. float z = -UnityObjectToViewPos(inVertex).z;
  21.  
  22. float4 cameraPos = ComputeScreenPos(clipPos);
  23. cameraPos.xy /= cameraPos.w;
  24. cameraPos.z = z;
  25.  
  26. return cameraPos.xyz;
  27. }
  28.  
  29. //////////// Lighting
  30. float4 Aura_SampleLightingTexture(float3 position)
  31. {
  32. return tex3Dlod(Aura_VolumetricDataTexture, float4(position, 0));
  33. }
  34. float4 Aura_GetLightingValue(float3 screenSpacePosition)
  35. {
  36. return Aura_SampleLightingTexture(float3(screenSpacePosition.xy, Aura_RescaleDepth(screenSpacePosition.z)));
  37. }
  38.  
  39. void Aura_ApplyLighting(inout float3 colorToApply, float3 screenSpacePosition, float lightingFactor)
  40. {
  41. screenSpacePosition.xy += GetBlueNoise(screenSpacePosition.xy, 1).xy;
  42.  
  43. float3 lightingValue = Aura_GetLightingValue(screenSpacePosition).xyz * lightingFactor;
  44.  
  45. float3 noise = GetBlueNoise(screenSpacePosition.xy, 2).xyz;
  46.  
  47. colorToApply = lightingValue + noise;
  48. }
  49.  
  50. //////////// Fog
  51. float4 Aura_GetFogValue(float3 screenSpacePosition)
  52. {
  53. return tex3Dlod(Aura_VolumetricLightingTexture, float4(screenSpacePosition.xy, Aura_RescaleDepth(screenSpacePosition.z), 0));
  54. }
  55.  
  56. void Aura_ApplyFog(inout float3 colorToApply, float3 screenSpacePosition)
  57. {
  58. screenSpacePosition.xy += GetBlueNoise(screenSpacePosition.xy, 3).xy;
  59.  
  60. float4 fogValue = Aura_GetFogValue(screenSpacePosition);
  61. float4 noise = GetBlueNoise(screenSpacePosition.xy, 4);
  62.  
  63. colorToApply = colorToApply * (fogValue.w + noise.w) + (fogValue.xyz + noise.xyz);
  64. }
  65.  
  66. // From https://github.com/Unity-Technologies/VolumetricLighting/blob/master/Assets/Scenes/Materials/StandardAlphaBlended-VolumetricFog.shader
  67. void Aura_ApplyFog(inout float4 colorToApply, float3 screenSpacePosition)
  68. {
  69. screenSpacePosition.xy += GetBlueNoise(screenSpacePosition.xy, 5).xy;
  70.  
  71. float4 fogValue = Aura_GetFogValue(screenSpacePosition);
  72.  
  73. float4 noise = GetBlueNoise(screenSpacePosition.xy, 6);
  74.  
  75. // Always apply fog attenuation - also in the forward add pass.
  76. colorToApply.xyz *= (fogValue.w + noise.w);
  77.  
  78. // Alpha premultiply mode (used with alpha and Standard lighting function, or explicitly alpha:premul)
  79. #if _ALPHAPREMULTIPLY_ON
  80. fogValue.xyz *= colorToApply.w;
  81. #endif
  82.  
  83. // Add inscattering only once, so in forward base, but not forward add.
  84. #ifndef UNITY_PASS_FORWARDADD
  85. colorToApply.xyz += (fogValue.xyz + noise.xyz);
  86. #endif
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement