All pastes #921590 Raw Edit

Miscellany

public text v1 · immutable
#921590 ·published 2008-02-28 03:59 UTC
rendered paste body
**TOON.ASM**
ps.1.1

def c0, 0.3, 0.59, 0.11, 0

tex t0                     // sample the source image
tex t1                     // sample offset by (-1, -1)
tex t2                     // sample offset by (1, 1)

dp3 r0.rgba, t1, c0        // greyscale sample #1 in r0.a
dp3 r1.rgba, t2, c0        // greyscale sample #2 in r1.a

sub_x4 r0.a, r0, r1        // diagonal edge detect difference
mul_x4_sat r0.a, r0, r0    // square edge difference to get absolute value

mul r0.rgb, r0, 1-r0.a     // output color * edge detect
+ mov r0.a, t0.a           // output alpha


**MATERIAL**
fragment_program Ogre/Compositor/ToonFP asm
{
	source toon.asm
	syntax ps_1_1
}

material Ogre/Compositor/Toon
{
    technique
    {

		pass
		{
			cull_hardware none
			cull_software none
			depth_func always_pass

			vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp
			{
			}

			fragment_program_ref Ogre/Compositor/ToonFP
			{
			}

			texture_unit RT
			{
                		tex_coord_set 0
				tex_address_mode clamp
				filtering trilinear
			}

		}
	}
}



**COMPOSITOR**
// Toon
compositor Toon
{
    technique
    {
        // Temporary textures
        texture rt0 target_width target_height PF_A8R8G8B8

        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/Toon
                input 0 rt0
            }
        }
    }
}