25/4/09

Y llegaron los shaders...



Ya se puede usar GLSL en phpmedia:

Ejemplo: http://phpelegante.googlepages.com/phpmedia_test_glsl.7z


error_reporting(E_ALL | E_STRICT);

Screen::title('Shader test');
$screen = Screen::init(800, 600);
$key = 'Keyboard';

$shader = new Shader("
uniform sampler2D image, mask;
uniform float step;

void main (void) {

gl_FragColor.rgb = texture2D(image, vec2(gl_TexCoord[0])).rgb;

gl_FragColor.a = texture2D(mask , vec2(gl_TexCoord[1])).r + step;

}

");

$mask = Bitmap::fromFile('mask.png');
$image = Bitmap::fromFile('file.jpg');
$arrows = Bitmap::fromFile('arrows.png');

$v = -1.0;

$timer = 0;

while (!$key::pressed($key::ESC)) {
if ($key::down($key::LEFT)) $v -= 0.03;
if ($key::down($key::RIGHT)) $v += 0.03;

Math::clamp($v, -1.0, 1.0);

$screen->blit($image, 0, 0, 1, 0, 1,
$shader, array('mask' => $mask, 'step' => $v));
$screen->blit($arrows, 16, 16, 1, 0, 0.6 + abs(cos($timer / 64)) * 0.8);

$timer++;
Screen::frame();
}

2 comentarios:

  1. Cambiando por este shader, hace un efecto muy guapo :P

    uniform sampler2D image, mask;
    uniform float step;

    void main (void) {
    vec4 m = texture2D(mask , vec2(gl_TexCoord[1]));
    gl_FragColor.rgb = texture2D(image, vec2(gl_TexCoord[0]) + vec2(m.r, m.b) * step).rgb;
    gl_FragColor.a = m.r + step;
    }

    ResponderEliminar
  2. "And llegó los shaders..." is an encounter that completely alters one's perception of seeing. Any graphic project that uses shaders sees a before and after in terms of the quality and realism of the images. This book provides a thorough and approachable explanation of how to understand and use shaders effectively. The examples and practical exercises provide a thorough understanding, even for those who are unfamiliar with the subject. En resumen, this book es un recomendación fundamental para creadores y artistas qui pretenden elevar la calidad de las creaciones visuales.
    flsa lawyer
    personal injury lawyer virginia

    ResponderEliminar