Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "shadergen:/autogenConditioners.h"
  23. #include "../postFx.hlsl"
  24.  
  25. uniform sampler2D frameSampler : register( s0 );
  26. uniform sampler2D backBuffer : register( s1 );
  27.  
  28. uniform float3 camForward;
  29. uniform float3 lightDirection;
  30. uniform float2 screenSunPos;
  31. uniform float2 oneOverTargetSize;
  32. uniform int numSamples;
  33. uniform float density;
  34. uniform float weight;
  35. uniform float decay;
  36. uniform float exposure;
  37.  
  38. float4 main( PFXVertToPix IN ) : COLOR0
  39. {
  40. float4 texCoord = float4( IN.uv0.xy, 0, 0 );
  41.  
  42. // Store initial sample.
  43. half3 color = (half3)tex2D( frameSampler, texCoord.xy ).rgb;
  44.  
  45. // Store original bb color.
  46. float4 bbCol = tex2D( backBuffer, IN.uv1 );
  47.  
  48. // Set up illumination decay factor.
  49. half illuminationDecay = 1.0;
  50.  
  51. float amount = saturate( dot( -lightDirection, camForward ) );
  52.  
  53. int samples = numSamples * amount;
  54.  
  55. if ( samples <= 0 )
  56. return bbCol;
  57.  
  58. // Calculate vector from pixel to light source in screen space.
  59. half2 deltaTexCoord = (half2)( texCoord.xy - screenSunPos );
  60.  
  61. // Divide by number of samples and scale by control factor.
  62. deltaTexCoord *= (half)(1.0 / samples * density);
  63.  
  64. // Evaluate summation from Equation 3 NUM_SAMPLES iterations.
  65. for ( int i = 0; i < samples; i++ )
  66. {
  67. // Step sample location along ray.
  68. texCoord.xy -= deltaTexCoord;
  69.  
  70. // Retrieve sample at new location.
  71. half3 sample = (half3)tex2Dlod( frameSampler, texCoord );
  72.  
  73. // Apply sample attenuation scale/decay factors.
  74. sample *= half(illuminationDecay * weight);
  75.  
  76. // Accumulate combined color.
  77. color += sample;
  78.  
  79. // Update exponential decay factor.
  80. illuminationDecay *= half(decay);
  81. }
  82.  
  83. //return saturate( amount ) * color * Exposure;
  84. //return bbCol * decay;
  85.  
  86. // Output final color with a further scale control factor.
  87. //return saturate( amount ) * float4( color * exposure, 1 ) + bbCol;
  88. //return saturate( amount ) * float4( color * exposure, 1 ) + bbCol;
  89.  
  90. float b = 0;
  91.  
  92. //float4 base = tex2D(backBuffer, ( texCoord.xy - screenSunPos ));
  93. float4 base = tex2D(backBuffer, IN.uv0);
  94. float2 uv = IN.uv0;
  95.  
  96. [loop] for (int i = 1; i <= samples; i++)
  97. {
  98. uv -= b;
  99. uv *= amount;
  100. b = (1-(1*pow(abs(amount), i))) / 2;
  101. uv += b;
  102. base += tex2Dlod(backBuffer, float4(uv.x, uv.y, 0, 0));
  103. }
  104.  
  105. //return base / (samples + 1);
  106.  
  107. uv = IN.uv0;
  108. float BlurStart = 1.0;
  109. float BlurWidth = 0.2;
  110. half4 c = 0;
  111. texCoord.xy = float4( IN.uv0.xy, 0, 0 );
  112. float2 Center = ( texCoord.xy - screenSunPos );
  113.  
  114. for (int i = 1; i <= samples; i++)
  115. {
  116. texCoord.xy -= Center;
  117. Center = ( texCoord.xy - screenSunPos ); //comment this to see the wide ef
  118. float scale = BlurStart + BlurWidth*(i/(float) (samples-1.0));
  119. texCoord.xy += float2(1.0-scale,1.0-scale);
  120. //c += tex2Dlod(backBuffer, float4(( uv.x*scale + Center.x),(uv.y*scale + Center.y),0,0 ));
  121. c += tex2Dlod(frameSampler, float4(( uv.x*scale + Center.x),(uv.y*scale + Center.y),0,0 ));
  122. }
  123.  
  124. c /=samples;
  125. return c;
  126.  
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement