Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sampler2D renderTarget;
- #define SAMPLE_AMOUNT 64
- Texture2D Tex;
- float2 lightPosition;
- float exposure;
- float decay;
- float weight;
- float density;
- SamplerState State = sampler_state
- {
- Texture = <Tex>;
- MipFilter = Point;
- MinFilter = Linear;
- MagFilter = Linear;
- AddressU = Wrap;
- AddressV = Wrap;
- };
- float4x4 MatrixTransform;
- //The default vertex shader of the spriteBatch, implemented manually so it can be compiled in 3_0
- void SpriteVertexShader(inout float4 color : COLOR0,
- inout float2 texCoord : TEXCOORD0,
- inout float4 position : SV_Position)
- {
- position = mul(position, MatrixTransform);
- }
- //Copypasted from the tutorial, only changed some variable names
- float4 main(float2 texCoord : TEXCOORD0) : COLOR0
- {
- // Calculate vector from pixel to light source in screen space.
- half2 deltaTexCoord = (texCoord - lightPosition.xy);
- // Divide by number of samples and scale by control factor.
- deltaTexCoord *= 1.0f / SAMPLE_AMOUNT * density;
- // Store initial sample.
- half3 color = tex2D(State, texCoord);
- // Set up illumination decay factor.
- half illuminationDecay = 1.0f;
- // Evaluate summation from Equation 3 NUM_SAMPLES iterations.
- for (int i = 0; i < SAMPLE_AMOUNT; i++)
- {
- // Step sample location along ray.
- texCoord -= deltaTexCoord;
- // Retrieve sample at new location.
- half3 sample = tex2D(State, texCoord);
- // Apply sample attenuation scale/decay factors.
- sample *= illuminationDecay * weight;
- // Accumulate combined color.
- color += sample;
- // Update exponential decay factor.
- illuminationDecay *= decay;
- }
- // Output final color with a further scale control factor.
- return float4( color * exposure, 1);
- }
- technique Technique1
- {
- pass Pass1
- {
- VertexShader = compile vs_3_0 SpriteVertexShader();
- PixelShader = compile ps_3_0 main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement