GLBasic Benutzerhandbuch

Main sections

X_PUTSHADER

X_PUTSHADER name$, wert#



Mit diesem Befehl kann man in den aktuell gesetzten Shader (X_SETSHADER) eine "uniform float" variable √§ndern. Damit kann man z.B. den Wert von GETTIMERALL() oder RGB-Farbwerte √ľbergeben.

// test.frag
uniform float t;
varying float u, v;

void main()
{
u += sin(t);
v += t;
gl_FragColor = vec4(sin(40*u),sin(40*v),0.0,1.0);
}


// test.vert
uniform float t;
const float pi = 3.1415926535;

varying float u, v;

void main()
{
u = (gl_Vertex.x + 5.0) / 10.0 * 2 * pi;
v = (gl_Vertex.y + 5.0) / 10.0 * 2 * pi;
float r = sin(4*u+t)/4+1;
float R = cos(6*cos(u)-t)/4+3;

float a = R+r*cos(v);
vec3 world = vec3(a*cos(u), a*sin(u), r*sin(v));

gl_Position = gl_ModelViewProjectionMatrix * vec4(world,1.0);
}

// --------------------------------- //
// Project: Shaders
// Start: Monday, September 25, 2006
// IDE Version: 3.262

LOCAL shaders$[], num, current$
    IF X_LOADSHADER(13, "toon.vert", "toon.frag") = FALSE
        PRINT "Shader failed to load: ", 100,100
        SHOWSCREEN
        MOUSEWAIT
        END
    ENDIF

    CreateTorus(0, 5, 10, 12, 9, 2, 2, RGB(0xff, 0xff, 0xff))
    // CreateSphere(0, 10, 9, RGB(0xff, 0xff, 0xff) )
    WHILE TRUE
        DRAWRECT 0,0,640,480,RGB(255,128,0)
        X_MAKE3D 1,500, 45
        X_CAMERA 0,0,-100, 0,0,0

        X_SPOT_LT 0, RGB(255,255,255),100,100,-1000, -.1,-.1,1, 360

        X_ROTATION 45, 1,1,0
        X_ROTATION GETTIMERALL()/100, 0,1,.2
        X_SETSHADER 13
        X_PUTSHADER "t", GETTIMERALL()
        X_DRAWOBJ 0, 0
        SHOWSCREEN
    WEND

See also...