Advertisement
Guest User

God Rays Shader [bugged]

a guest
Jun 22nd, 2014
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. sampler2D renderTarget;
  2.  
  3. #define SAMPLE_AMOUNT 64
  4.  
  5. Texture2D Tex;
  6. float2 lightPosition;
  7. float exposure;
  8. float decay;
  9. float weight;
  10. float density;
  11.  
  12. SamplerState State = sampler_state
  13. {
  14. Texture = <Tex>;
  15. MipFilter = Point;
  16. MinFilter = Linear;
  17. MagFilter = Linear;
  18. AddressU = Wrap;
  19. AddressV = Wrap;
  20. };
  21.  
  22. float4x4 MatrixTransform;
  23.  
  24. //The default vertex shader of the spriteBatch, implemented manually so it can be compiled in 3_0
  25. void SpriteVertexShader(inout float4 color : COLOR0,
  26. inout float2 texCoord : TEXCOORD0,
  27. inout float4 position : SV_Position)
  28. {
  29. position = mul(position, MatrixTransform);
  30. }
  31.  
  32. //Copypasted from the tutorial, only changed some variable names
  33. float4 main(float2 texCoord : TEXCOORD0) : COLOR0
  34. {
  35. // Calculate vector from pixel to light source in screen space.
  36. half2 deltaTexCoord = (texCoord - lightPosition.xy);
  37. // Divide by number of samples and scale by control factor.
  38. deltaTexCoord *= 1.0f / SAMPLE_AMOUNT * density;
  39. // Store initial sample.
  40. half3 color = tex2D(State, texCoord);
  41. // Set up illumination decay factor.
  42. half illuminationDecay = 1.0f;
  43. // Evaluate summation from Equation 3 NUM_SAMPLES iterations.
  44. for (int i = 0; i < SAMPLE_AMOUNT; i++)
  45. {
  46. // Step sample location along ray.
  47. texCoord -= deltaTexCoord;
  48. // Retrieve sample at new location.
  49. half3 sample = tex2D(State, texCoord);
  50. // Apply sample attenuation scale/decay factors.
  51. sample *= illuminationDecay * weight;
  52. // Accumulate combined color.
  53. color += sample;
  54. // Update exponential decay factor.
  55. illuminationDecay *= decay;
  56. }
  57. // Output final color with a further scale control factor.
  58. return float4( color * exposure, 1);
  59. }
  60.  
  61. technique Technique1
  62. {
  63. pass Pass1
  64. {
  65. VertexShader = compile vs_3_0 SpriteVertexShader();
  66. PixelShader = compile ps_3_0 main();
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement