//Dark Sylinc's Bloom
compositor Bloom
{
    technique
    {
        // Temporary textures
        texture rt_output target_width target_height PF_BYTE_RGB
        texture rt0 target_width_scaled 0.25 target_height_scaled 0.25 PF_BYTE_RGB
        texture rt1 target_width_scaled 0.25 target_height_scaled 0.25 PF_BYTE_RGB

        target rt_output
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target rt0
        {
            // Start with clear texture
            input none
            // Horizontal blur pass
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/BrightPass2
                input 0 rt_output
            }
        }

        target rt1
        {
            // Start with clear texture
            input none
            // Horizontal blur pass
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/BlurV
                input 0 rt0
            }
        }

        target rt0
        {
            // Start with clear texture
            input none
            // Horizontal blur pass
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/BlurH
                input 0 rt1
            }
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/BloomBlend2
                input 0 rt_output
                input 1 rt0
            }
        }
    }
}

//! [glass_script]
compositor Glass
{
    technique
    {
        texture rt0 target_width target_height PF_BYTE_RGB

        target rt0 { input previous }

        target_output
        {
            // Start with clear output
            input none

            pass render_quad
            {
                material Ogre/Compositor/GlassPass
                input 0 rt0
            }
        }
    }
}
//! [glass_script]

compositor "Old TV"
{
    technique
    {
        texture rt0 target_width target_height PF_BYTE_RGB

        // render scene to a texture
        target rt0 { input previous }

        target_output
        {
            // Start with clear output
            input none

            pass render_quad
            {
                // convert the previous render target to a black and white image, add some noise, distort it,
                // then render to scene aligned quad
                material Ogre/Compositor/OldTV
                input 0 rt0
            }
        }
    }
}

//! [manual_sample]
// Black and white effect
compositor B&W
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/BlackAndWhite
                input 0 rt0
            }
        }
    }
}
//! [manual_sample]

compositor DoF
{
   technique
   {
       // Temporary textures
       texture scene target_width target_height PF_BYTE_RGBA PF_DEPTH16
       texture blur target_width_scaled 0.25 target_height_scaled 0.25 PF_BYTE_RGBA

       target scene
       {
           // Render original scene
           input previous
       }

       target blur
       {
           input none
           // blur pass
           pass render_quad
           {
               material Ogre/Compositor/DOF_Blur
               input 0 scene 0
           }
       }

       target_output
       {
           // Start with clear output
           input none
           // Draw a fullscreen quad
           pass render_quad
           {
                material Ogre/Compositor/DOF_Blend
                input 0 scene 0
                input 1 scene 1
                input 2 blur
           }
       }
   }
}

// Embossed (fake bump) effect
compositor Embossed
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/Embossed
                input 0 rt0
            }
        }
    }
}

// SharpenEdges
compositor "Sharpen Edges"
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/SharpenEdges
                input 0 rt0
            }
        }
    }
}

// Invert
compositor Invert
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/Invert
                input 0 rt0
            }
        }
    }
}

// Posterize
compositor Posterize
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/Posterize
                input 0 rt0
            }
        }
    }
}

// Laplace
compositor Laplace
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/Laplace
                input 0 rt0
            }
        }
    }
}

// Tiling
compositor Tiling
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/Tiling
                input 0 rt0
            }
        }
    }
}

// Old Movie
compositor "Old Movie"
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_A8B8G8R8

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/OldMovie
                input 0 rt0
            }
        }
    }
}

// HDR
compositor HDR
{
	// floating point only for now
	technique
	{
		compositor_logic HDR
		
        // Temporary textures
		// Fullsize HDR render target, used as tone mapping source
        texture rt_full target_width target_height PF_FLOAT16_RGB
		// Targets used for luminance evaluation (3x3 downsample, point filtering)
		texture rt_lum0 1 1 PF_FLOAT16_RGB
		texture rt_lum1 4 4 PF_FLOAT16_RGB
		texture rt_lum2 16 16 PF_FLOAT16_RGB
		texture rt_lum3 64 64 PF_FLOAT16_RGB
		texture rt_lum4 128 128 PF_FLOAT16_RGB
		// Bright-pass filtered target (tone mapped)
		texture rt_brightpass 128 128 PF_BYTE_RGB
		// Bloom filter targets
		texture rt_bloom0 128 128 PF_BYTE_RGB
		texture rt_bloom1 128 128 PF_BYTE_RGB


		target rt_full
		{
			// No input, render differently
			input none

			// Use float target HDR material scheme (unclamped shaders)
			material_scheme HDR

			pass clear
			{
			}

			pass render_scene
			{
			}

		}

		// Downsample the original HDR scene to extract luminence value
		target rt_lum4
		{
            input none
            pass render_quad
            {
                // Downsample using a 2x2 filter and convert to greyscale
                material Ogre/Compositor/HDR/Downsample2x2Luminence
                input 0 rt_full
                identifier 994
            }
		}
		target rt_lum3
		{
            input none
            pass render_quad
            {
				// Downsample using a 3x3 filter
                material Ogre/Compositor/HDR/Downsample3x3
                input 0 rt_lum4
                identifier 993
            }
		}
		target rt_lum2
		{
            input none
            pass render_quad
            {
                // Downsample using a 3x3 filter
                material Ogre/Compositor/HDR/Downsample3x3
                input 0 rt_lum3
                identifier 992
            }
		}
		target rt_lum1
		{
            input none
            pass render_quad
            {
                // Downsample using a 3x3 filter
                material Ogre/Compositor/HDR/Downsample3x3
                input 0 rt_lum2
                identifier 991
            }
		}
		target rt_lum0
		{
            input none
            pass render_quad
            {
                // Downsample using a 3x3 filter
                material Ogre/Compositor/HDR/Downsample3x3
                input 0 rt_lum1
                identifier 990
            }
		}


		target rt_brightpass
		{
            input none
            pass render_quad
            {
                // Downsample using a 3x3 filter, hi-pass and tone map
                material Ogre/Compositor/HDR/Downsample3x3Brightpass
                input 0 rt_full
		        input 1 rt_lum0
				identifier 800
            }
		}

		target rt_bloom1
		{
			input none
			pass render_quad
			{
				// Blur horizontally
				material Ogre/Compositor/HDR/GaussianBloom
				input 0 rt_brightpass
				identifier 701
			}
		}
		target rt_bloom0
		{
			input none
			pass render_quad
			{
				// Blur horizontally
				material Ogre/Compositor/HDR/GaussianBloom
				input 0 rt_bloom1
				identifier 700
			}
		}


		// Final output combines tone mapping of the original scene, with an
		// exposure setting passed in as a GPU parameter, and an additive bloom
		// effect
		target_output
		{
			input none
			pass render_quad
			{
				material Ogre/Compositor/HDR/ToneMapping
				input 0 rt_full
				input 1 rt_bloom0
				input 2 rt_lum0
			}
		}


	}

}


// Gaussian blur effect
compositor "Gaussian Blur"
{
    technique
    {
		compositor_logic GaussianBlur
		
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA
        texture rt1 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target rt1
        {
            // Blur horizontally
            input none
			pass render_quad
			{
				material Ogre/Compositor/HDR/GaussianBloom
				input 0 rt0
				identifier 700
			}
        }

		target_output
        {
            // Start with clear output
            input none
            // Blur vertically
            pass render_quad
            {
                // Renders a fullscreen quad with a material
				material Ogre/Compositor/HDR/GaussianBloom
                input 0 rt1
				identifier 701
            }
        }
    }
}

//Radial blur effect
compositor "Radial Blur"
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

		target_output
        {
            // Start with clear output
            input none
            // Blur vertically
            pass render_quad
            {
                // Renders a fullscreen quad with a material
				material Ogre/Compositor/Radial_Blur
                input 0 rt0
            }
        }
    }
}

// ASCII effect
compositor ASCII
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA
        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/ASCII
                input 0 rt0
            }
        }
    }
}

// Halftone effect
compositor Halftone
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_BYTE_RGBA

        target rt0
        {
            // Render output from previous compositor (or original scene)
            input previous
        }

        target_output
        {
            // Start with clear output
            input none
            // Draw a fullscreen quad with the black and white image
            pass render_quad
            {
                // Renders a fullscreen quad with a material
                material Ogre/Compositor/Halftone
                input 0 rt0
            }
        }
    }
}

//Night Vision effect
compositor "Night Vision"
{
    technique
    {
        texture rt0 target_width target_height PF_BYTE_RGBA
	
	target rt0
	{
	    input previous
	}
	
	target_output
	{
	    input none
	   
	    pass render_quad
	    {
	    	material Ogre/Compositor/NightVision
	    	input 0 rt0
	    }
	}
    }
}

//Dither effect
compositor Dither
{
    technique
    {
        texture rt0 target_width target_height PF_BYTE_RGBA
	
	target rt0
	{
	    input previous
	}
	
	target_output
	{
	    input none
	   
	    pass render_quad
	    {
	    	material Ogre/Compositor/Dither
	    	input 0 rt0
	    }
	}
    }
}

compositor Compute
{
    technique
    {
        target_output
        {
            // just do normal rendering
            input previous
            // execute compute shaders post-render
            pass compute
            {
                material Compute/Compositor
                // the texture size is 256x256x1 and we have 16x16x1 threads per group
                // so we have to launch 16x16x1 groups
                thread_groups 16 16 1
            }
        }
    }
}

// abstract node to avoid copy & paste
abstract target CubeFace
{
    visibility_mask 0xF0 // avoid ogrehead in the reflection
    pass clear {}
    pass render_scene
    {
        camera CubeMapCamera align_to_face
    }
}

compositor CubeMap
{
    technique
    {
        texture tex 128 128 PF_BYTE_RGB cubic
        target tex 0 : CubeFace {}
        target tex 1 : CubeFace {}
        target tex 2 : CubeFace {}
        target tex 3 : CubeFace {}
        target tex 4 : CubeFace {}
        target tex 5 : CubeFace {}

        target_output
        {
            input previous
        }
    }
}

compositor Fresnel
{
    technique
    {
        texture reflection 512 512 PF_BYTE_RGB
        texture refraction 512 512 PF_BYTE_RGB
        target reflection
        {
            visibility_mask 0x00F // SURFACE objects
            input previous
        }
        target refraction
        {
            visibility_mask 0x0F0 // SUBMERGED objects
            input previous
        }
        target_output
        {
            input previous
        }
    }
}

compositor WBOIT
{
    technique
    {
        texture opaque target_width target_height PF_BYTE_RGBA no_fsaa depth_pool 1
        texture accum target_width target_height PF_FLOAT16_RGBA PF_FLOAT16_R no_fsaa depth_pool 1

        target opaque
        {
            pass clear {}
            pass render_scene
            {
                last_render_queue 90
            }
        }

        target accum
        {
            pass clear
            {
                buffers colour
                colour_value 0 0 0 1
            }
            pass render_scene
            {
                // RTSS must use be used for transparents
                material_scheme ShaderGeneratorDefaultScheme
                first_render_queue 95
                last_render_queue 95
            }
        }

        target_output
        {
            input none
            pass clear {}
            pass render_quad
            {
                material Compositor/Copy
                input 0 opaque
            }
            pass render_quad
            {
                material Compositor/WBOIT
                input 0 accum 0
                input 1 accum 1
            }
        }
    }
}