GL.createProgram( cg.compile( """ float2 r90(float2 v) { return float2(v.y, -v.x); } float2 rn90(float2 v) { return float2(-v.y, v.x); } void main( float4 pos: POSITION, uniform float2 center: C0, uniform float3 zooms: C1, uniform float3 zs: C2, uniform float3 angles: C3, uniform float3 dists: C4, uniform float4 params: C5, out float4 opos: POSITION, out float4 col: COLOR ) { float thickness = 5 + 1000 / (dists.y * dists.y); float pi = 3.14159; float2 targetvector = float2(sin(angles.y), cos(angles.y)); float2 dtargetvector = angles.x * r90(targetvector); float rangle = angles.y + angles.x * pi / 4; float2 touchvector = float2(sin(rangle), cos(rangle)); float sinangle = abs(dot(r90(targetvector), touchvector)); float cosangle = dot(targetvector, touchvector); float2 tangentinters = dists.x * targetvector / cosangle; float4 p0 = float4(0,0,0,1); p0.xy = targetvector * dists.y + dtargetvector * thickness; float4 p2 = float4(0,0,0,1); p2.xy = touchvector * dists.x; float4 p1 = float4(0,0,0,1); p1.xy = lerp(p2.xy, tangentinters, 1-(thickness / dists.x) / sinangle); // weights - multiply all homog coords p0 *= .1; p1 *= 1; p2 *= 5; float4 coeff = float4( pos.x * pos.x, 2 * pos.x * (1-pos.x), (1-pos.x) * (1-pos.x), 0 ); // coeff = float4(.5,.3,.2,0); float4 bez = coeff.x * p0 + coeff.y * p1 + coeff.z * p2; bez /= bez.w; float2 foopos = lerp(p0.xy, // targetvector * dists.y, p1.xy, // touchvector * dists.x, pos.x) ; // bez.xy = lerp(foopos.xy, bez.xy, pos.y); float4 rpos4 = float4(0,0,0,1); rpos4.xy = center + bez.xy + 5 * pos.y * float2(1,1); opos = mul(glstate.matrix.mvp, rpos4); col.xyz = coeff.xyz; col.w = .8; } """, "arbvp1")),
GL.createProgram( cg.compile( """ float edge[5][4] = { {0, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 0, 1}, {1, 0, 0, 1}, {0, 0, 0, 1}, }; float2 inters(float2 what) { float2 ctr = float2(.5,.5); float2 vec = what-ctr; float2 a = abs(vec); // if(a.x + a.y < .001) return float4(0,0,0,1); float mul; if(a.x > a.y) { mul = .5 / a.x; } else { mul = .5 / a.y; } return ctr + vec * mul; } void main( float4 t: TEXCOORD0, float4 pos: POSITION, out float4 opos: POSITION, out float4 ocol : TEXCOORD0 ) { float4 ctr = float4(.5,.5,0,1); float4 ctr1 = mul(glstate.matrix.program[0], ctr); float4 ctr2 = mul(glstate.matrix.program[1], ctr); float4 ctr1_in2 = mul(glstate.matrix.inverse.program[1], ctr1); float4 ctr2_in1 = mul(glstate.matrix.inverse.program[0], ctr2); // Solve eq: find intersections of unit squares float2 inters1 = inters(ctr2_in1.xy); float2 inters2 = inters(ctr1_in2.xy); // float2 inters1 = ctr.xy; // float2 inters2 = ctr.xy; float inter = frac(4*pos.x); float edgeind = fmod(floor(4*pos.x), 4) ; float2 xa = float2(0,0); float2 xb = float2(0,0); xa.x = (edgeind >= 2 && edgeind < 4); xa.y = (edgeind >= 1 && edgeind < 3); xb.x = (edgeind >= 1 && edgeind < 3); xb.y = (edgeind >= 0 && edgeind < 2); /* DOESN'T WORK float4 xa = edge[edgeind]; float4 xb = edge[edgeind+1]; */ float2 x = lerp(xa, xb, inter); // x = float4(pos.x, 0, 0, 1); float shri = 3.7*(pos.y - pos.y*pos.y); float4 sx1; float4 sx2; sx1.xy = lerp(x, inters1, shri); sx2.xy = lerp(x, inters2, shri); sx1.z = 0; sx1.w = 1; sx2.z = 0; sx2.w = 1; float4 x1 = mul(glstate.matrix.program[0], sx1); float4 x2 = mul(glstate.matrix.program[1], sx2); float4 p = lerp(x1, x2, pos.y); float4 pin1 = mul(glstate.matrix.inverse.program[0], p); float4 pin2 = mul(glstate.matrix.inverse.program[1], p); pin1 /= pin1.w; pin2 /= pin2.w; pin1 -= .5; pin2 -= .5; pin1 = abs(pin1) * 2; pin2 = abs(pin2) * 2; pin1 = max(pin1.x, pin1.y); pin2 = max(pin2.x, pin2.y); opos = mul(glstate.matrix.projection, p); ocol.xy = pos.xy; ocol.z = shri; ocol.w = min(pin1, pin2).x; // ocol.w = .5; // oc.z = 1; } """, "arbvp1")),
GL.createProgram( cg.compile( """ void main( float4 pos: POSITION, out float4 ot0 : TEXCOORD0, out float4 ot1 : TEXCOORD1, out float4 ot2 : TEXCOORD2, out float4 ot3 : TEXCOORD3, uniform float4 v0 : register(c0), uniform float4 v1 : register(c1), uniform float4 v2 : register(c2), uniform float4 v3 : register(c3), uniform float4 v4 : register(c4), uniform float4 v5 : register(c5), uniform float4 v6 : register(c6), uniform float4 v7 : register(c7), out float4 opos: POSITION ) { opos = mul(glstate.matrix.mvp, pos); float4 mpos = pos * 2; ot0.x = dot(mpos, v0) ; ot0.y = dot(mpos, v1) ; ot1.x = dot(mpos, v2) ; ot1.y = dot(mpos, v3) ; ot2.x = dot(mpos, v4) ; ot2.y = dot(mpos, v5) ; ot3.x = dot(mpos, v6) ; ot3.y = dot(mpos, v7) ; } """, "arbvp1"))
fp = [ GL.createProgram(cg.compile(""" void main( float2 t : TEXCOORD0, uniform float2 meas: register(c0), uniform sampler2D t0: TEXUNIT0, out half4 color: COLOR) { float2 tx = ddx(t); float2 ty = ddy(t); float le = sqrt(length(tx) * length(ty)); t -= .5*(tx + ty); float c = 1; float2 dx = tx, dy = ty; half4 c0 = tex2D(t0, t + c*(dx+dy)); half4 c1 = tex2D(t0, t + c*(dx)); half4 c2 = tex2D(t0, t + c*(dy)); half4 c3 = tex2D(t0, t ); half4 dists = 256 * 16 * half4( c0.x, c1.x, c2.x, c3.x); float tdx = (dists.x + dists.y - dists.z - dists.w); float tdy = (dists.x + dists.z - dists.y - dists.w); float ax = abs(tdx); float ay = abs(tdy); float maxx = max(ax, ay); float minx = min(ax, ay); float angle = (maxx < .001 ? 0 : minx / maxx); float grayval = .25 * dot(clamp((dists + le) / le, 0,1), half(1).xxxx).x; color.x = (angle * angle); color.y = .25 * dot((dists>float(0.).xxxx), half(1).xxxx).x; color.z = grayval; float tres = (1 - angle*angle); float tt = .25; color.xyz = smoothstep( tt * tres, tt + (1-tt) * (1-tres), grayval ); // color.x = grayval; // color.x = !isfinite(angle); // color.y = !isfinite(tdx); // color.z = !isfinite(tdy); color.w = (grayval < 1); color.w = 1; } """, "fp30")), GL.createProgram(cg.compile(""" void main( float2 t : TEXCOORD0, uniform float2 meas: register(c0), uniform sampler2D t0: TEXUNIT0, out half4 color: COLOR) { // if(tex2D(t0, t).x > 0) discard; half4 ders; ders.xy = ddx(t); ders.zw = ddy(t); half2 dx = ders.xy; half2 dy = ders.zw; half4 dersq = ders * ders; half2 dersums = dersq.xz + dersq.yw; half l = max(dersums.x, dersums.y); l = sqrt(l); // l = max(length(ddx(t)), length(ddy(t))) // * 512 = texture width // / 2 = half, for radius // / 2 = half, for x-sampling pattern half4 maxrad = l * 512 / 2 / 2 * meas.y; half4 c0 = tex2D(t0, t + meas.x*(dx+dy)); half4 c1 = tex2D(t0, t + meas.x*(dx-dy)); half4 c2 = tex2D(t0, t + meas.x*(-dx+dy)); half4 c3 = tex2D(t0, t + meas.x*(-dx-dy)); half4 dists = 256 * 16 * half4( c0.x, c1.x, c2.x, c3.x); fixed c = dot(1-smoothstep(-maxrad, maxrad, dists), fixed4(1,1,1,1)) / 4; fixed rgb = (1 - c); color.xyz = rgb; // color.y = c0.x - maxrad * 1000; // color.z = c0.w + maxrad * 1000; color.w = 1; } """, "fp30")), GL.createProgram(cg.compile(""" void main( float2 t : TEXCOORD0, uniform float2 meas: register(c0), uniform sampler2D t0: TEXUNIT0, out half4 color: COLOR) { float4 tx = tex2D(t0,t); float x = tx.x * 256 * 16; float tex = 5; if(x > tex) color = float4(1,0,1,0); else if(x > 0) color = float4(0,1,0,1); else if(x > -tex) color = float4(0,0,1,1); else color = float4(1,0,0,1); } """, "fp30")), GL.createProgram("""!!FP1.0 DECLARE meas; MOV R10, f[TEX0].xyzw; DDX R8, R10; DDY R9, R10; DP4 R6, R8.xyxy, R8.xyxy; DP4 R7, R9.xyxy, R9.xyxy; MAX R6, R6, R7; MUL R6, R6, .5; RSQ R6, R6.x; RCP R6, R6.x; MUL R6, R6, 512; # R6 = texels per pixel #TEX R0, R10, TEX0, 2D; #MUL R0, R0, 16; # MAD R11, # MAD R0, R0.w, 256, R0.x; # MAD R0, R0.x, 256, R0.w; # Sample in an X pattern. MOV R15, p[0].x; MAD R11, R15, R8, R10; MAD R11, R15, R9, R11; TEX R12, R11, TEX0, 2D; MAD R1.x, R12.w, 256, R12.x; MAD R11, -R15, R8, R10; MAD R11, -R15, R9, R11; TEX R12, R11, TEX0, 2D; MAD R1.y, R12.w, 256, R12.x; MAD R11, R15, R8, R10; MAD R11, -R15, R9, R11; TEX R12, R11, TEX0, 2D; MAD R1.z, R12.w, 256, R12.x; MAD R11, -R15, R8, R10; MAD R11, R15, R9, R11; TEX R12, R11, TEX0, 2D; MAD R1.w, R12.w, 256, R12.x; # Scale up by 256 and down by 16 MUL R1, R1, 16; # Now, R1 contains the 4 texel lengths # of the edges from the 4 points. # Scale # Calculate half the width - i.e. the radius MUL R6, R6, .5; # Further scale down by half for the X sampling pattern MUL R6, R6, .5; # Arbitrary scale MUL R6, R6, p[0].y; SLT R0, R1, R6; # Then, what to do with this? DP4 R0, R0, 1; MUL R0, R0, .25; # SLE R0, R1, 0; # MUL R6, R6, .5; # # SLT R0.x, R1, R6; # # MUL R6, R6, .5; # # SLT R0.y, R1, R6; # # MUL R6, R6, .5; # # SLT R0.z, R1, R6; SUB R0.xyz, 1, R0.w; MOV o[COLR], R0; END"""), GL.createProgram("""!!FP1.0 MOV R10, f[TEX0].xyzw; DDX R8, R10; DDY R9, R10; MUL R18, R8, 1; MUL R19, R9, 1; TXD R0, R10, R18, R19, TEX0, 2D; ADD R11, R10, R18; TXD R1, R11, R18, R19, TEX0, 2D; # ADD R11, R11, R18; # TXD R3, R11, R18, R19, TEX0, 2D; SUB R11, R10, R18; TXD R2, R11, R18, R19, TEX0, 2D; # SUB R11, R11, R18; # TXD R4, R11, R18, R19, TEX0, 2D; ADD R11, R10, R19; TXD R5, R11, R18, R19, TEX0, 2D; SUB R11, R10, R19; TXD R6, R11, R18, R19, TEX0, 2D; # Now we have 3 horizontal samples # in R2, R0, R1 # and 3 vertical in R6, R0, R5. # Set the pixel if it's maximum in one # direction MAX R7.x, R2.w, R1.w; MAX R7.y, R5.w, R6.w; SUB R7, R0.w, R7; RCP R1.w, R0.w; MUL R7.xy, R7, R1.w; # MAX R7.w, R7.x, R7.y; MAX R7.w, R7.x, R7.x; # ADDC_SAT R7.w, R7.w, .1; MOVC_SAT R7.w, R7.w; MOV R7(GT), 1; # SGEC R7.x, R0.w, R2.w; # SGE R7.x(NE), R0.w, R1.w; # SGEC R7.y, R0.w, R5.w; # SGE R7.y(NE), R0.w, R6.w; # ADD R7.w, R7.x, R7.y; MUL R0, R7.w, R0; SUB R0.xyz, 1, R0.w; # MOV R0.xy, R7; MOV R0.w, 1; MOV o[COLR], R0; END """), GL.createProgram("""!!FP1.0 MOV R10, f[TEX0].xyzw; DDX R8, R10; DDY R9, R10; MUL R18, R8, .5; MUL R19, R9, .5; TXD R0, R10, R18, R19, TEX0, 2D; ADD R11, R10, R8; TXD R1, R11, R18, R19, TEX0, 2D; ADD R11, R10, -R8; TXD R2, R11, R18, R19, TEX0, 2D; ADD R11, R10, R9; TXD R3, R11, R18, R19, TEX0, 2D; ADD R11, R10, -R9; TXD R4, R11, R18, R19, TEX0, 2D; ADD R5, R0, R1; ADD R5, R5, R2; ADD R5, R5, R3; ADD R5, R5, R4; MUL R5, R5, .2; MUL R6, R0, R0; MAD R6, R1, R1, R6; MAD R6, R2, R2, R6; MAD R6, R3, R3, R6; MAD R6, R4, R4, R6; MUL R6, R6, .2; MOV R5.x, R5.w; MOV R5.y, R0.w; TEX R0, R5, TEX3, 2D; #SGT R0.w, R0.w, R5.w; #SUB R0.xyz, 1, R0.w; MOV R0.w, 1; MOV o[COLR], R0; END """), GL.createProgram("""!!FP1.0 MOV R10, f[TEX0].xyzw; DDX R8, R10; MUL R8, .3333333333, R8; DDY R9, R10; MAD R10, -3, R8, R10; TXD R0, R10, R8, R9, TEX0, 2D; ADD R10, R8, R10; TXD R1, R10, R8, R9, TEX0, 2D; ADD R10, R8, R10; TXD R2, R10, R8, R9, TEX0, 2D; ADD R10, R8, R10; TXD R3, R10, R8, R9, TEX0, 2D; ADD R10, R8, R10; TXD R4, R10, R8, R9, TEX0, 2D; ADD R10, R8, R10; TXD R5, R10, R8, R9, TEX0, 2D; ADD R10, R8, R10; TXD R6, R10, R8, R9, TEX0, 2D; MUL R0.x, 0.1111, R0.w; MAD R0.x, 0.2222, R1.w, R0.x; MAD R0.x, 0.3333, R2.w, R0.x; MAD R0.x, 0.2222, R3.w, R0.x; MAD R0.x, 0.1111, R4.w, R0.x; MUL R0.y, 0.1111, R1.w; MAD R0.y, 0.2222, R2.w, R0.y; MAD R0.y, 0.3333, R3.w, R0.y; MAD R0.y, 0.2222, R4.w, R0.y; MAD R0.y, 0.1111, R5.w, R0.y; MUL R0.z, 0.1111, R2.w; MAD R0.z, 0.2222, R3.w, R0.z; MAD R0.z, 0.3333, R4.w, R0.z; MAD R0.z, 0.2222, R5.w, R0.z; MAD R0.z, 0.1111, R6.w, R0.z; DP3 R0.w, R0, 1; SUB R0.xyz, 1, R0; MOV o[COLR], R0; END """), GL.createProgram("""!!FP1.0 MOV R10, f[TEX0].xyzw; TEX R0, f[TEX0].xyzw, TEX0, 2D; #SUB R0, R0, {.2,0,.2,0}; SUB R0.xyz, 1, R0.w; MOV R0.w, 1; MOV o[COLR], R0; END """), ]
if GL.hasExtension("GL_NV_fragment_program"): nvBlurProgram = GL.createProgram("""!!FP1.0 # Get the blurred value of the text texture # Texture unit 2 is blurred TEX H2, f[TEX1], TEX2, 2D; # Get the sharp value of the text texture TEX H3, f[TEX1], TEX1, 2D; # Map blurred 'text' texture intensity to background blur # as follows: # 1 -> no bias # 0 -> large bias DP4H H2, {-10,-10,-10,31}, H2; # The derivatives of the paper texture DDXH H0.xy, f[TEX0].xyxy; DDYH H0.zw, f[TEX0].xyxy; # Scale with the DP MULH H0, H2, H0; # Get the blurred value of the background texture TXD H0, f[TEX0], H0.xyxy, H0.zwzw, TEX0, 2D; # Compute the final color MULX o[COLR], H0, H3; END """)
vp = [ GL.createProgram(cg.compile(""" void main( float4 pos: POSITION, float3 norm: NORMAL, float4 tex0: TEXCOORD0, float4 col: COLOR, out float4 opos: POSITION, out float4 ocol: COLOR, out float4 otex0: TEXCOORD0 ) { opos = mul(glstate.matrix.mvp, pos); float4x4 foo = glstate.matrix.modelview[0]; float3 normvec = normalize(float3( dot(foo[0].xyz, norm), dot(foo[1].xyz, norm), dot(foo[2].xyz, norm))); float3 lightvec = normalize(float3(-1, -1, -1)); float3 lightcolor = float3(1, .5, 1); float3 specularcolor = float3(1, 1, 1); float3 lightvec2 = normalize(float3(.5, .5, -1)); float3 light2color = float3(.5, 1, .5); float3 eyevec = float3(0,0,-1); float3 halfvec = normalize(lightvec + eyevec); float diffuse = dot(normvec, lightvec); float diffuse2 = dot(normvec, lightvec2); float specular = dot(normvec, halfvec); float4 lighting = lit(diffuse, specular, 10); float t = (1 - tex0.z); float3 defaultcolor = float3(.2, .2, 1); float3 color = lerp(defaultcolor, col, t * t); ocol.rgb = lighting.y * color * lightcolor + lighting.z * specularcolor + max(diffuse2, 0) * color * light2color //+ max(-normvec.z, 0) * col; ; // Fog // float t = 8*mul(glstate.matrix.mvp, pos).z; // t = 8*mul(glstate.matrix.mvp, pos).z*40; // ocol.rgb = ocol.rgb * (1 - t) + float3(1,.5,.2) * t; ocol.a = 1; otex0 = tex0 * float4(20, 20, 0, 1); } """, "arbvp1")), GL.createProgram(cg.compile(""" void main( float4 pos: POSITION, float4 tex0: TEXCOORD0, float4 col: COLOR, out float4 opos: POSITION, out float4 ocol: COLOR, out float4 otex0: TEXCOORD0 ) { opos = mul(glstate.matrix.mvp, pos); float3 defaultcolor = float3(.2, .2, 1); float t = (1 - tex0.z); ocol.rgb = lerp(defaultcolor, col, t * t); ocol.a = 1; otex0 = tex0 * float4(20, 20, 0, 1); } """, "arbvp1")), ]