1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
using System;
using Clutter;
public class ShaderTest
{
static int current_shader = 0;
static string[] shader_sources = {
@"uniform sampler2D tex;
uniform float x_step, y_step;
uniform float brightness, contrast;
void main ()
{
vec4 color = texture2D (tex, vec2(gl_TexCoord[0]));
color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + vec3 (brightness + 0.5, brightness + 0.5, brightness + 0.5);
gl_FragColor = color;
gl_FragColor = gl_FragColor * gl_Color;
}",
@"uniform sampler2D tex;
uniform float x_step, y_step;
void main ()
{
vec4 color = texture2D (tex, vec2(gl_TexCoord[0]));
vec4 colorB = texture2D (tex, vec2(gl_TexCoord[0].ts));
float avg = (color.r + color.g + color.b) / 3.0;
color.r = avg;
color.g = avg;
color.b = avg;
color = (color + colorB)/2.0;
gl_FragColor = color;
gl_FragColor = gl_FragColor * gl_Color;
}",
@"uniform sampler2D tex;
uniform float x_step, y_step;
void main ()
{
vec4 color = texture2D (tex, vec2(gl_TexCoord[0]));
float avg = (color.r + color.g + color.b) / 3.0;
color.r = avg;
color.g = avg;
color.b = avg;
gl_FragColor = color;
gl_FragColor = gl_FragColor * gl_Color;
}"
};
public static void HandleActorButtonPress(object sender, ButtonPressEventArgs args)
{
int new_no;
if (args.Event.Button == 1)
new_no = current_shader + 1;
else
new_no = current_shader - 1;
if (new_no >= 0 & new_no < shader_sources.Length)
{
current_shader = new_no;
Shader shader = new Shader ();
shader.FragmentSource = shader_sources[current_shader];
shader.Compile ();
Actor actor = sender as Actor;
actor.SetShader (shader);
actor.SetShaderParam ("radius", 3.0f);
}
}
public static void Main ()
{
ClutterRun.Init ();
Stage stage = Stage.Default;
stage.SetSize(512, 384);
Shader shader = new Shader ();
shader.FragmentSource = shader_sources[current_shader];
shader.Compile ();
stage.Title = "Shader Test";
stage.Color = new Clutter.Color (0x61, 0x64, 0x8c, 0xff);
Timeline timeline = new Timeline(360, 60);
timeline.Loop = true;
stage.AddActor (new Label ("Mono 16", "Press the Hand"));
Texture actor = new Texture("redhand.png");
actor.SetShader (shader);
actor.Reactive = true;
actor.ButtonPressEvent += HandleActorButtonPress;
stage.AddActor (actor);
actor.SetShaderParam("brightness", 0.4f);
actor.SetShaderParam("contrast", -1.9f);
actor.SetPosition (0, 20);
stage.ShowAll ();
timeline.Start ();
ClutterRun.Main ();
}
}
|