diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2009-09-05 00:04:04 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2009-09-05 00:23:41 +0100 |
commit | 4162ad998584593af0cff252766b31ea2f1bded8 (patch) | |
tree | 6c3f22dfe1b3749ea776f6552fec464a2a620eb1 | |
parent | 2f9ac6869b832f8d07e367e1cceb68f688cae347 (diff) | |
download | clutter-gst-4162ad998584593af0cff252766b31ea2f1bded8.tar.gz |
[VideoSink] Make the alpha component of the GL color play with the shaders
The idea here is to generate a premultiplied alpha texture of the video
so the user can blend it in a clutter scene and do some fancy effects.
Through the use of clutter_actor_set_opacity() on the texture, we are
now able to make a video transparent.
This is for the YUV -> RGB shaders only for now. RGB uploads + alpha
will have to wait a bit.
-rw-r--r-- | clutter-gst/shaders/I420.cg | 4 | ||||
-rw-r--r-- | clutter-gst/shaders/I420.h | 30 | ||||
-rw-r--r-- | clutter-gst/shaders/I420.pso | 39 | ||||
-rw-r--r-- | clutter-gst/shaders/YV12.cg | 4 | ||||
-rw-r--r-- | clutter-gst/shaders/YV12.h | 30 | ||||
-rw-r--r-- | clutter-gst/shaders/YV12.pso | 39 |
6 files changed, 80 insertions, 66 deletions
diff --git a/clutter-gst/shaders/I420.cg b/clutter-gst/shaders/I420.cg index fe93b85..79e97e3 100644 --- a/clutter-gst/shaders/I420.cg +++ b/clutter-gst/shaders/I420.cg @@ -28,6 +28,7 @@ struct I420_output struct I420_input { + float4 color : COLOR; float2 Y : TEXCOORD0; sampler2D Y_tex : TEXUNIT0; sampler2D U_tex : TEXUNIT2; @@ -45,7 +46,8 @@ I420_output I420_main (I420_input IN) OUT.color.r = y + 1.59765625 * v; OUT.color.g = y - 0.390625 * u - 0.8125 * v; OUT.color.b = y + 2.015625 * u; - OUT.color.a = 1.0; + OUT.color.rgb *= IN.color.a; + OUT.color.a = IN.color.a; return OUT; } diff --git a/clutter-gst/shaders/I420.h b/clutter-gst/shaders/I420.h index f81a1d1..a5affef 100644 --- a/clutter-gst/shaders/I420.h +++ b/clutter-gst/shaders/I420.h @@ -9,26 +9,28 @@ * This define is the size of the shader in bytes. More precisely it's the * sum of strlen() of every string in the array. */ -#define I420_FP_SZ 526 +#define I420_FP_SZ 564 static const char *I420_fp[] = { "!!ARBfp1.0\n", - "PARAM c[2] = { { 1, 1.1640625, 0.0625, 2.015625 },\n", - "{ 0.5, 0.390625, 0.8125, 1.5976562 } };\n", + "PARAM c[2] = { { 1.1640625, 0.0625, 2.015625, 0.5 },\n", + "{ 0.390625, 0.8125, 1.5976562 } };\n", "TEMP R0;\n", - "TEX R0.y, fragment.texcoord[0], texture[0], 2D;\n", - "ADD R0.x, R0.y, -c[0].z;\n", - "TEX R0.y, fragment.texcoord[0], texture[2], 2D;\n", - "ADD R0.z, R0.y, -c[1].x;\n", - "MUL R0.x, R0, c[0].y;\n", - "MAD result.color.z, R0, c[0].w, R0.x;\n", + "TEMP R1;\n", + "TEX R1.y, fragment.texcoord[0], texture[0], 2D;\n", + "ADD R0.x, R1.y, -c[0].y;\n", "TEX R0.y, fragment.texcoord[0], texture[1], 2D;\n", - "ADD R0.y, R0, -c[1].x;\n", - "MAD R0.z, -R0, c[1].y, R0.x;\n", - "MAD result.color.y, -R0, c[1].z, R0.z;\n", - "MAD result.color.x, R0.y, c[1].w, R0;\n", - "MOV result.color.w, c[0].x;\n", + "TEX R1.y, fragment.texcoord[0], texture[2], 2D;\n", + "MUL R0.x, R0, c[0];\n", + "ADD R0.w, R1.y, -c[0];\n", + "MAD R0.z, R0.w, c[0], R0.x;\n", + "ADD R0.y, R0, -c[0].w;\n", + "MAD R0.w, -R0, c[1].x, R0.x;\n", + "MAD R0.x, R0.y, c[1].z, R0;\n", + "MAD R0.y, -R0, c[1], R0.w;\n", + "MUL result.color.xyz, fragment.color.primary.w, R0;\n", + "MOV result.color.w, fragment.color.primary;\n", "END\n", NULL }; diff --git a/clutter-gst/shaders/I420.pso b/clutter-gst/shaders/I420.pso index 6b6ac3e..c82c69c 100644 --- a/clutter-gst/shaders/I420.pso +++ b/clutter-gst/shaders/I420.pso @@ -1,33 +1,36 @@ !!ARBfp1.0 -# cgc version 2.0.0015, build date May 15 2008 +# cgc version 2.1.0017, build date Feb 17 2009 # command line args: -profile arbfp1 # source file: I420.cg #vendor NVIDIA Corporation -#version 2.0.0.15 +#version 2.1.0.17 #profile arbfp1 #program I420_main #semantic I420_main.IN +#var float4 IN.color : $vin.COLOR : COL0 : 0 : 1 #var float2 IN.Y : $vin.TEXCOORD0 : TEX0 : 0 : 1 #var sampler2D IN.Y_tex : TEXUNIT0 : texunit 0 : 0 : 1 #var sampler2D IN.U_tex : TEXUNIT2 : texunit 2 : 0 : 1 #var sampler2D IN.V_tex : TEXUNIT1 : texunit 1 : 0 : 1 #var float4 I420_main.color : $vout.COLOR : COL : -1 : 1 -#const c[0] = 1 1.1640625 0.0625 2.015625 -#const c[1] = 0.5 0.390625 0.8125 1.5976562 -PARAM c[2] = { { 1, 1.1640625, 0.0625, 2.015625 }, - { 0.5, 0.390625, 0.8125, 1.5976562 } }; +#const c[0] = 1.1640625 0.0625 2.015625 0.5 +#const c[1] = 0.390625 0.8125 1.5976562 +PARAM c[2] = { { 1.1640625, 0.0625, 2.015625, 0.5 }, + { 0.390625, 0.8125, 1.5976562 } }; TEMP R0; -TEX R0.y, fragment.texcoord[0], texture[0], 2D; -ADD R0.x, R0.y, -c[0].z; -TEX R0.y, fragment.texcoord[0], texture[2], 2D; -ADD R0.z, R0.y, -c[1].x; -MUL R0.x, R0, c[0].y; -MAD result.color.z, R0, c[0].w, R0.x; +TEMP R1; +TEX R1.y, fragment.texcoord[0], texture[0], 2D; +ADD R0.x, R1.y, -c[0].y; TEX R0.y, fragment.texcoord[0], texture[1], 2D; -ADD R0.y, R0, -c[1].x; -MAD R0.z, -R0, c[1].y, R0.x; -MAD result.color.y, -R0, c[1].z, R0.z; -MAD result.color.x, R0.y, c[1].w, R0; -MOV result.color.w, c[0].x; +TEX R1.y, fragment.texcoord[0], texture[2], 2D; +MUL R0.x, R0, c[0]; +ADD R0.w, R1.y, -c[0]; +MAD R0.z, R0.w, c[0], R0.x; +ADD R0.y, R0, -c[0].w; +MAD R0.w, -R0, c[1].x, R0.x; +MAD R0.x, R0.y, c[1].z, R0; +MAD R0.y, -R0, c[1], R0.w; +MUL result.color.xyz, fragment.color.primary.w, R0; +MOV result.color.w, fragment.color.primary; END -# 12 instructions, 1 R-regs +# 13 instructions, 2 R-regs diff --git a/clutter-gst/shaders/YV12.cg b/clutter-gst/shaders/YV12.cg index c6e1888..776c764 100644 --- a/clutter-gst/shaders/YV12.cg +++ b/clutter-gst/shaders/YV12.cg @@ -28,6 +28,7 @@ struct YV12_output struct YV12_input { + float4 color : COLOR; float2 Y : TEXCOORD0; sampler2D Y_tex : TEXUNIT0; sampler2D U_tex : TEXUNIT1; @@ -45,7 +46,8 @@ YV12_output YV12_main (YV12_input IN) OUT.color.r = y + 1.59765625 * v; OUT.color.g = y - 0.390625 * u - 0.8125 * v; OUT.color.b = y + 2.015625 * u; - OUT.color.a = 1.0; + OUT.color.rgb *= IN.color.a; + OUT.color.a = IN.color.a; return OUT; } diff --git a/clutter-gst/shaders/YV12.h b/clutter-gst/shaders/YV12.h index b36348a..5b5b771 100644 --- a/clutter-gst/shaders/YV12.h +++ b/clutter-gst/shaders/YV12.h @@ -9,26 +9,28 @@ * This define is the size of the shader in bytes. More precisely it's the * sum of strlen() of every string in the array. */ -#define YV12_FP_SZ 526 +#define YV12_FP_SZ 564 static const char *YV12_fp[] = { "!!ARBfp1.0\n", - "PARAM c[2] = { { 1, 1.1640625, 0.0625, 2.015625 },\n", - "{ 0.5, 0.390625, 0.8125, 1.5976562 } };\n", + "PARAM c[2] = { { 1.1640625, 0.0625, 2.015625, 0.5 },\n", + "{ 0.390625, 0.8125, 1.5976562 } };\n", "TEMP R0;\n", - "TEX R0.y, fragment.texcoord[0], texture[0], 2D;\n", - "ADD R0.x, R0.y, -c[0].z;\n", - "TEX R0.y, fragment.texcoord[0], texture[1], 2D;\n", - "ADD R0.z, R0.y, -c[1].x;\n", - "MUL R0.x, R0, c[0].y;\n", - "MAD result.color.z, R0, c[0].w, R0.x;\n", + "TEMP R1;\n", + "TEX R1.y, fragment.texcoord[0], texture[0], 2D;\n", + "ADD R0.x, R1.y, -c[0].y;\n", "TEX R0.y, fragment.texcoord[0], texture[2], 2D;\n", - "ADD R0.y, R0, -c[1].x;\n", - "MAD R0.z, -R0, c[1].y, R0.x;\n", - "MAD result.color.y, -R0, c[1].z, R0.z;\n", - "MAD result.color.x, R0.y, c[1].w, R0;\n", - "MOV result.color.w, c[0].x;\n", + "TEX R1.y, fragment.texcoord[0], texture[1], 2D;\n", + "MUL R0.x, R0, c[0];\n", + "ADD R0.w, R1.y, -c[0];\n", + "MAD R0.z, R0.w, c[0], R0.x;\n", + "ADD R0.y, R0, -c[0].w;\n", + "MAD R0.w, -R0, c[1].x, R0.x;\n", + "MAD R0.x, R0.y, c[1].z, R0;\n", + "MAD R0.y, -R0, c[1], R0.w;\n", + "MUL result.color.xyz, fragment.color.primary.w, R0;\n", + "MOV result.color.w, fragment.color.primary;\n", "END\n", NULL }; diff --git a/clutter-gst/shaders/YV12.pso b/clutter-gst/shaders/YV12.pso index 800ead8..1069a5e 100644 --- a/clutter-gst/shaders/YV12.pso +++ b/clutter-gst/shaders/YV12.pso @@ -1,33 +1,36 @@ !!ARBfp1.0 -# cgc version 2.0.0015, build date May 15 2008 +# cgc version 2.1.0017, build date Feb 17 2009 # command line args: -profile arbfp1 # source file: YV12.cg #vendor NVIDIA Corporation -#version 2.0.0.15 +#version 2.1.0.17 #profile arbfp1 #program YV12_main #semantic YV12_main.IN +#var float4 IN.color : $vin.COLOR : COL0 : 0 : 1 #var float2 IN.Y : $vin.TEXCOORD0 : TEX0 : 0 : 1 #var sampler2D IN.Y_tex : TEXUNIT0 : texunit 0 : 0 : 1 #var sampler2D IN.U_tex : TEXUNIT1 : texunit 1 : 0 : 1 #var sampler2D IN.V_tex : TEXUNIT2 : texunit 2 : 0 : 1 #var float4 YV12_main.color : $vout.COLOR : COL : -1 : 1 -#const c[0] = 1 1.1640625 0.0625 2.015625 -#const c[1] = 0.5 0.390625 0.8125 1.5976562 -PARAM c[2] = { { 1, 1.1640625, 0.0625, 2.015625 }, - { 0.5, 0.390625, 0.8125, 1.5976562 } }; +#const c[0] = 1.1640625 0.0625 2.015625 0.5 +#const c[1] = 0.390625 0.8125 1.5976562 +PARAM c[2] = { { 1.1640625, 0.0625, 2.015625, 0.5 }, + { 0.390625, 0.8125, 1.5976562 } }; TEMP R0; -TEX R0.y, fragment.texcoord[0], texture[0], 2D; -ADD R0.x, R0.y, -c[0].z; -TEX R0.y, fragment.texcoord[0], texture[1], 2D; -ADD R0.z, R0.y, -c[1].x; -MUL R0.x, R0, c[0].y; -MAD result.color.z, R0, c[0].w, R0.x; +TEMP R1; +TEX R1.y, fragment.texcoord[0], texture[0], 2D; +ADD R0.x, R1.y, -c[0].y; TEX R0.y, fragment.texcoord[0], texture[2], 2D; -ADD R0.y, R0, -c[1].x; -MAD R0.z, -R0, c[1].y, R0.x; -MAD result.color.y, -R0, c[1].z, R0.z; -MAD result.color.x, R0.y, c[1].w, R0; -MOV result.color.w, c[0].x; +TEX R1.y, fragment.texcoord[0], texture[1], 2D; +MUL R0.x, R0, c[0]; +ADD R0.w, R1.y, -c[0]; +MAD R0.z, R0.w, c[0], R0.x; +ADD R0.y, R0, -c[0].w; +MAD R0.w, -R0, c[1].x, R0.x; +MAD R0.x, R0.y, c[1].z, R0; +MAD R0.y, -R0, c[1], R0.w; +MUL result.color.xyz, fragment.color.primary.w, R0; +MOV result.color.w, fragment.color.primary; END -# 12 instructions, 1 R-regs +# 13 instructions, 2 R-regs |