// vertex shader demonstrating vertex warping and render to texture // // overall external key controls (each in a decrement/increment pair): // 1/2: vertex.color.r: smoothly interp from position to texture // 3/4: vertex.color.g: smoothly interp from above to normal/gauss map // 5/6: vertex.color.b: free // 7/8: vertex.color.b: free // all are passed to shader in the attribute 'Kout' vec4 L = vec4(-2.,2.,5.,.01); // light position float Ke = 32.; // specular power vec4 Ks = vec4(1,1,1,0); // specular color vec4 Kd = vec4(.9,.7,.5,0); // diffuse color vec4 Ka = vec4(.1,.14,.18,1); // ambient color void main() { // input from standard GL vec4 Kin = gl_Color; // key input // compute lighting vec4 V = gl_ModelViewMatrix*gl_Vertex; vec4 E = gl_ProjectionMatrixInverse*vec4(0,0,-1,0); vec3 nl = normalize(L.xyz*V.w - V.xyz*L.w); vec3 ni = normalize(E.xyz*V.w - V.xyz*E.w); vec3 nh = normalize(nl+ni); vec3 nn = normalize(gl_NormalMatrix*gl_Normal); gl_FrontColor = Ka + Kd*max(vec4(0,0,0,1),dot(nn,nl)) + Ks*max(vec4(0,0,0,1),pow(dot(nn,nh),Ke)); // screen position from vertex, texture and normal vec4 Vp = ftransform(); vec4 Tp = vec4(gl_MultiTexCoord0.xy*1.8-.9, 0,1); vec4 Np = vec4(nn*.9,1); // interpolate between Vp, Tp and Np gl_Position = Vp; gl_Position = mix(Tp,gl_Position,pow(1.-Kin.x,8.)); gl_Position = mix(Np,gl_Position,pow(1.-Kin.y,8.)); // copy to output gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = Vp; gl_TexCoord[3] = Kin; }