示例#1
0
def initBuffers(w, h):
    print "initBuffers(%s,%s)" % (w,h)
    global width, height, depthTexture, tmpTexture, directDepthCopy
    if width == w and height == h: return

    depthTexture = GL.createTexture()
    tmpTexture = GL.createTexture()
	
    if not GL.hasExtension("GL_NV_texture_rectangle"): return

    width,height = w,h

    rect = 1
    targ = "TEXTURE_RECTANGLE_NV"
    if directDepthCopy:
        depthTexture.loadNull2D(targ, 0, "DEPTH_COMPONENT24",
				width, height, 0, "DEPTH_COMPONENT", "INT")
    else:
        depthTexture.loadNull2D(targ, 0, "RGBA8",
				width, height, 0, "BGRA", "INT")

	tmpTexture.loadNull2D(targ, 0, "RGB8",
			      width, height, 0, "RGB",  "INT")
	tmpTexture.setTexParameter(targ, "TEXTURE_MIN_FILTER", "LINEAR")
	tmpTexture.setTexParameter(targ, "TEXTURE_MAG_FILTER", "LINEAR")
	
    depthTexture.setTexParameter(targ, "TEXTURE_MIN_FILTER", "LINEAR")
    depthTexture.setTexParameter(targ, "TEXTURE_MAG_FILTER", "LINEAR")
示例#2
0
    def selectCombiner(self):
        # Check which combiners to use.
        if not self.paperopts.use_opengl_1_1 and (
                GL.hasExtension("GL_NV_register_combiners")
                or GL.hasExtension("GL_ARB_fragment_program")):

            # We have at least a NV10, possibly better.
            # Check the number of general combiners to be sure.
            #maxcomb = GL.getGLFloat("MAX_GENERAL_COMBINERS_NV")[0]
            #if maxcomb < 4:
            if 1:  #XXX NV20 version is broken
                # use NV10 version
                if dbg: print "Using NV10 combiners ", maxcomb
                texcomb = vob.paper.texcomb_NV1X
                # from org.nongnu.libvob.paper.texcomb_NV1X import TransparentCombinerPass,DebugCombinerPass
            else:
                # use NV20 version
                if dbg: print "Using NV20 combiners ", maxcomb
                texcomb = vob.paper.texcomb_NV2X
                #from org.nongnu.libvob.paper.texcomb_NV2X import TransparentCombinerPass,DebugCombinerPass
        else:
            # Must use OpenGL 1.1 specified calls.
            if dbg: print "Using OpenGL 1.1 texenv and blending"
            texcomb = vob.paper.texcomb_GL1_1
            self.paperopts.use_opengl_1_1 = 1

        self.TransparentCombinerPass = texcomb.TransparentCombinerPass
        self.DebugCombinerPass = texcomb.DebugCombinerPass
示例#3
0
def getpaper(vecs, cols, x0, y0, x1, y1, t0, t1, tex0comb, isectcomb,
             tex1comb):
    pap = Paper()
    pap.setNPasses(1)
    ppass = pap.getPass(0)
    ppass.setSetupcode("""
    	    PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT
    """)
    ppass.setTeardowncode("""
	    PopAttrib
            ActiveTexture TEXTURE0
    """)

    # texid = vob.paper.textures.ptextures["RGB2"][1].getTexId();
    texid0 = vob.paper.textures.getNamed("RGB2", t0).getTexId()
    texid1 = vob.paper.textures.getNamed("RGB2", t1).getTexId()

    constcode = """
        ActiveTexture TEXTURE0
        Enable TEXTURE_2D
        BindTexture TEXTURE_2D %(texid0)s
        TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT
        TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT
        TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
        TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
        
        ActiveTexture TEXTURE1
        Enable TEXTURE_2D
        BindTexture TEXTURE_2D %(texid1)s
        TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT
        TexParameter TEXTURE_2D TEXTURE_WRAP_T REPEAT
        TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
        TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
        
        Enable BLEND
        BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA 
        BlendEquation FUNC_ADD
        Disable ALPHA_TEST

        Enable REGISTER_COMBINERS_NV
    """ % locals()

    r0, r1 = vecs
    c0, c1, c2, c3 = cols
    constcode += """
        Color %(c0)s
        SecondaryColorEXT %(c1)s
        Fog FOG_COLOR %(c2)s
        CombinerParameterNV CONSTANT_COLOR0_NV %(r0)s
        CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s
    """ % locals()

    return GLRen.createBasisPaperQuad(
        pap, 0, 0, x0, y0, 0, 0, x1, y1,
        GL.createDisplayList(constcode + parsedTexcodes[tex0comb]),
        GL.createDisplayList(constcode + parsedTexcodes[tex1comb]),
        GL.createDisplayList(constcode + parsedTexcodes[isectcomb]))
示例#4
0
文件: dbg.py 项目: fenfire-org/libvob
def option(o, a):
    if o in ("-d", "--dbg"):
        debugger.debugClass(a, 1)
    elif o in ("-G", "--gldbg"):
        GL.loadLib()
        print "Setting GL debug ", a
        GL.setDebugVar(a, 1)
    elif o in ("-D", ):
        m = re.match('^(.*)=(.*)$', a)
        assert m
        prop = System.getProperties()
        prop.setProperty(m.group(1), m.group(2))
        System.setProperties(prop)
示例#5
0
    def __init__(self):
        self.useOpengL11 = None
        self.passMask = None
        self.trueOpenGL11 = None
        self.lastState = None

        # Check which combiners to use.
        if (GL.hasExtension("GL_NV_register_combiners")
                or GL.hasExtension("GL_ARB_fragment_program")):
            self.trueOpenGL11 = 0
            self.useOpenGL11 = 0
        else:
            self.trueOpenGL11 = 1
            self.useOpenGL11 = 1
示例#6
0
def getCachedTexture(args, shade_all_levels=0):
    global texcache

    name = args[6]
    file = "../libvob/src/texture/" + name
    binfile = file + ".bin"
    srcfile = file + ".texture"

    bintime = File(binfile).lastModified()
    srctime = File(srcfile).lastModified()

    if srctime > bintime:
        os.system("make -C ./libvob/src/texture " + name + ".bin")

    key = str((args, shade_all_levels))
    if texcache.has_key(key) and texcache[(key, "ctime")] == srctime:
        #print "Returning cached texture"
        return texcache[key]

    tex = GL.createTexture()
    if shade_all_levels:
        res = tex.shade_all_levels(*args)
    else:
        res = tex.shade(*args)

    texcache[key] = tex
    texcache[(key, "ctime")] = srctime
    if dbg:
        print "SHADER: ", res, tex.getTexId()
    return tex
示例#7
0
def fancyHalo(paperMill=None):
    paperMill = getPaperMill(paperMill)
    if not GL.hasExtension("GL_NV_register_combiners"):
        print "fancy Halo for text not possible without GL_NV_register_combiners"
        print "Punting to standard blend"
        return fancyBlend(paperMill)
    if paperMill == None:
        paperMill = PaperMill.getInstance()
    return (HaloPaperMaker_2tex, [paperMill])
示例#8
0
def getTexture(*args):
    key = str(args)
    if not textures.has_key(key):
        textures[key] = GL.createTexture()
        if dbg:
            print "Generating texture: ", args
        res = textures[key].shade(*args)
        if dbg:
            print "SHADER: ", res
    return textures[key]
示例#9
0
    def compile(self, *args):
        if self.list:
            self.list = None
            return

        list = GL.createDisplayList()
        vs = w.createVobScene()
        self.putGraph(vs, 0, 800)

        list.startCompile(w.window)

        #w.renderStill(vs, 0)
        vs.coords.renderInterp(w.getRenderingSurface(), vs.map, None, None, 0,
                               0, 1)

        list.endCompile(w.window)

        self.list = GLRen.createCallListCoorded(list)
示例#10
0
# The programs here are best-first
# The following program gives a 30% improvement
# to rendering speeds on a GF FX 5600
# by using a biased texture unit instead of
# calculating the bias explicitly in the program.

# Replacing some of the MULH:s with MULX makes
# it faster but it stops working - the results are
# not accurate enough.
# On the 5900, 5700 this should be a lot faster...
# It's sad that we can't take advantage of the fixed-point
# units at all except at the very end.

nvBlurProgram = None
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
示例#11
0
    def __init__(self,
                 x0,
                 y0,
                 x1,
                 y1,
                 border,
                 ripple,
                 typeInt=0,
                 contentColor=java.awt.Color.white,
                 frameColor=java.awt.Color.black,
                 type="square"):

        self.dbg = 0
        if typeInt == 1:
            type = 'square'
        elif typeInt == 2:
            type = 'ellipse'

        if self.dbg:
            print "Texture id:", self.tex.getTexId()

        def code(color):
            return """
                PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT
                Enable ALPHA_TEST
                AlphaFunc GREATER 0.0
		Disable BLEND

		Color %(color)s

                ActiveTexture TEXTURE1
                BindTexture TEXTURE_2D %(boxtex)s
                Enable TEXTURE_2D
                TexImage2D TEXTURE_2D 0 ALPHA 4 4 0 ALPHA 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0
                TexParameter TEXTURE_2D TEXTURE_BASE_LEVEL 0
                TexParameter TEXTURE_2D TEXTURE_MAX_LEVEL 0
		TexParameter TEXTURE_2D TEXTURE_WRAP_S CLAMP
		TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP
		TexParameter TEXTURE_2D TEXTURE_MIN_FILTER NEAREST
		TexParameter TEXTURE_2D TEXTURE_MAG_FILTER NEAREST

                #TexGen S TEXTURE_GEN_MODE EYE_LINEAR
                #Enable TEXTURE_GEN_S
                #TexGen T TEXTURE_GEN_MODE EYE_LINEAR
                #Enable TEXTURE_GEN_T

                ActiveTexture TEXTURE0

                BindTexture TEXTURE_2D %(tex)s
                Enable TEXTURE_2D
                %(comb)s REGISTER_COMBINERS_NV
                CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_A_NV TEXTURE1 UNSIGNED_IDENTITY_NV ALPHA
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_B_NV TEXTURE0 SIGNED_NEGATE_NV ALPHA
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_C_NV TEXTURE1 UNSIGNED_IDENTITY_NV ALPHA
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_D_NV SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE
                CombinerOutputNV COMBINER0_NV ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE FALSE FALSE

                FinalCombinerInputNV VARIABLE_A_NV ZERO UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_B_NV ZERO UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_D_NV PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_G_NV SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
        """ % {
                "boxtex": self.boxtex.getTexId(),
                "tex": self.tex.getTexId(),
                "comb": self.combiners,
                "color": vob.util.ColorUtil.colorGLString(color)
            }

        def code2(color):
            return parseCombiner("""
                PushAttrib ENABLE_BIT TEXTURE_BIT COLOR_BUFFER_BIT
                CombinerParameterNV CONSTANT_COLOR0_NV %(color)s 1

                Enable REGISTER_COMBINERS_NV

                SPARE0 = TEX0 . COL0
                SPARE0.alpha = TEX0.alpha * COL0.alpha + COL1.blue

                SPARE0.alpha = SPARE0.blue + SPARE0.alpha

                alpha = SPARE0.alpha
                color = CONST0

                BindTexture TEXTURE_2D %(tex)s
                TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
                TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
                Enable TEXTURE_2D

                Enable ALPHA_TEST
                AlphaFunc GEQUAL 1.0

                Color 0 0 0 1
        """) % {
                "tex": self.tex2.getTexId(),
                "color": vob.util.ColorUtil.colorGLString(color)
            }

        def code3(color):
            return parseCombiner("""
                PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT COLOR_BUFFER_BIT

                BindTexture TEXTURE_2D %(tex)s
                TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
                TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
                Enable TEXTURE_2D
                TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD

                Enable ALPHA_TEST
                AlphaFunc GEQUAL 1.0

        """) % {
                "tex": self.tex3.getTexId(),
                "color": vob.util.ColorUtil.colorGLString(color)
            }

        if type == "square":
            self._content = GLRen.createIrregularQuad(x0, y0, x1, y1, border,
                                                      ripple, 0,
                                                      code(contentColor),
                                                      self.dicefactor)
            self._frame = GLRen.createIrregularQuad(x0, y0, x1, y1,
                                                    border, ripple, 1,
                                                    code(frameColor),
                                                    self.dicefactor)
        elif type == "ellipse":
            texscale = ripple
            ripple_scale = border / ripple

            ratio = float(ripple_scale) / self.ripple_scale

            if ratio < 3. / 4 or ratio > 4. / 3:
                if self.dbg:
                    print "WARNING: anisotropy ratio", round(
                        ratio, 2), "is far from one"

            # Irregu flags
            Y_COLOR = 1
            Y_SECCOLOR = 2
            DOTVEC_COLOR = 4
            INTERP_DOTVEC = 8
            SLICE_1D = 16
            SLICE_2D = 32
            SHIFTS = 64
            INSIDE = 128
            SHIFTS8 = 256

            if GL.hasExtension("GL_NV_register_combiners"):
                self._content = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0",
                    "", 3, 0, SLICE_1D + Y_SECCOLOR + INSIDE,
                    code2(contentColor), 1.0)

                self._frame = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 3,
                    0, SLICE_1D + Y_SECCOLOR + DOTVEC_COLOR + INTERP_DOTVEC,
                    code2(frameColor), 1.0)
            else:
                self._content = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 0,
                    0, SLICE_1D + Y_COLOR + INSIDE, code3(contentColor), 1.0)

                self._frame = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 0,
                    0, SLICE_1D + Y_COLOR + SHIFTS,
                    code3(frameColor) + """
                    BlendFunc ZERO ZERO
                    Enable BLEND
                    """, 1.0)
示例#12
0
    def key(self, k):
        if 0: pass
        elif k == "Up":
            self.x1 += .2 * cos(self.a1)
            self.y1 += .2 * sin(self.a1)
        elif k == "Down":
            self.x1 -= .2 * cos(self.a1)
            self.y1 -= .2 * sin(self.a1)
        elif k == "Left":
            self.a1 -= .1
        elif k == "Right":
            self.a1 += .1
        elif k == "x":
            self.xs += .1
        elif k == "X":
            self.xs -= .1
        elif k == "y":
            self.ys += .1
        elif k == "Y":
            self.ys -= .1
        elif k == "+":
            self.scale += .1
        elif k == "-":
            self.scale -= .1
        elif k == "c":
            if self.combiners == "Enable":
                self.combiners = "Disable"
            else:
                self.combiners = "Enable"
            self.initirregu()
        elif k == "w":
            self.w += .1
            self.initirregu()
        elif k == "W":
            self.w -= .1
            self.initirregu()
        elif k == "h":
            self.h += .1
            self.initirregu()
        elif k == "H":
            self.h -= .1
            self.initirregu()
        elif k == "b":
            self.border += .01
            self.initirregu()
        elif k == "B":
            self.border -= .01
            self.initirregu()
        elif k == "p":
            self.period += .1
            self.initirregu()
        elif k == "P":
            self.period -= .1
            self.initirregu()
        elif "1" <= k <= "9":
            self.mode ^= 1 << (int(k) - 1)
            print "mode=", [(".", "X")[(self.mode >> i) & 1]
                            for i in range(0, 9)]
        elif k == "t":
            if self.type == "square":
                self.type = "ellipse"
            else:
                self.type = "square"
            self.initirregu()
        elif k == "d":
            self.distort = not self.distort
        elif k == "l":
            GL.call("""
            PolygonMode FRONT_AND_BACK LINE
            """)
        elif k == "L":
            GL.call("""
            PolygonMode FRONT_AND_BACK FILL
            """)

        pass
示例#13
0
_realwin = org.nongnu.libvob.GraphicsAPI.getInstance().createWindow()
_realwin.setLocation(0, 0, 600, 600)

if org.nongnu.libvob.GraphicsAPI.getInstance().getTypeString() == "gl":
    from org.nongnu.libvob.gl import GL
    if GL.workaroundStupidBuggyAtiDrivers:
        # Sorry, ATI doesn't let us use pbuffers on R300 except in FireGL.
        # Because of that, don't put another window in front when using
        # this.
        win = _realwin
    else:
        win = org.nongnu.libvob.GraphicsAPI.getInstance(
        ).createStableOffscreen(500, 500)
        from org.nongnu.libvob.gl import GL, GLCache, GLRen
        _buf = GL.createByteVector(500 * 500 * 3)
        _drawbufvs = _realwin.createVobScene()
        _drawbufvs.map.put(SolidBackdropVob(Color(0, 0, 0.2)))
        _drawbufvs.map.put(
            GLCache.getCallList("""
	    Disable TEXTURE_2D
	    Color 1 1 1 1
	"""))
        cs = _drawbufvs.translateCS(0, "tr", 0, 501)
        _drawbufvs.map.put(
            GLRen.createDrawPixels(500, 500, "RGB", "UNSIGNED_BYTE", _buf), cs)
else:
    win = _realwin

# print "GW: ",win
示例#14
0
def init():
    font = GL.createFont(None, 64)
    font2 = GL.createFont(None, 64)
    vob.putil.demowindow.font = font
    vob.putil.demowindow.font2 = font2

    vob.putil.demowindow.mouser = vob.util.PS2Reader("/dev/input/mouse0")

    fonttexs = []

    fn = jarray.zeros(10*10, 'b')
    fn2 = jarray.zeros(10*10, 'h')

    fn[15] = 1
    fn[14] = 1
    fn[13] = 1
    fn[12] = 1
    fn[25] = 1
    fn[24] = 1
    fn[23] = 1
    fn[22] = 1
    fn[35] = 1
    fn[34] = 1
    fn[33] = 1
    fn[32] = 1
    for i in range(0,20): # exercise JVM
	print "Exercise ",i
	vob.util.TexManip.minDist(fn, fn2, 10, 10, 10)

	for y in range(0,10):
	    print " ".join([str(fn2[10*y + i]) for i in range(0,10)])


    print "Tex: ", font.getNTextures();
    for i in range(0, font.getNTextures()):
	t = font.getTexture(i)
	vob.putil.texture.printTex(t.getTexId())
	w = int(t.getLevelParameter(0, "TEXTURE_WIDTH")[0])
	h = int(t.getLevelParameter(0, "TEXTURE_HEIGHT")[0])
	print "T",i,t,w,h

	fn = jarray.zeros(2*w*h, 'b')
	fn2 = jarray.zeros(w*h, 'h')
	fn3 = jarray.zeros(4*w*h, 'b')

	t.getTexImage(0, "ALPHA", "UNSIGNED_BYTE", fn)
    #    for i in range(0, w*h, 5):
    #	fn[i] += int(20 * sin(i))

    #    for x in range(0,w,20):
    #	for y in range(0,w,20):
    #	    print fn[x + w*y]
	
	# Distance * 16
	vob.util.TexManip.minDist(fn, fn2, w, h, 16)
	print "Maniped1"
	vob.util.TexManip.b2s(fn2, fn3, 4)

	print "Maniped"

    #    for x in range(0,w,20):
    #	for y in range(0,w,20):
    #	    print fn[x + w*y]
       
	t.setTexParameter("TEXTURE_2D", "GENERATE_MIPMAP_SGIS", "TRUE");

	for y in range(0,50):
	    print " ".join([str(fn3[1000*y + i]) for i in range(0,30)])
	t.texImage2D(0, "SIGNED_HILO16_NV", w, h, 0, "HILO_NV", "SHORT", fn3)

	fonttexs.append(t)
示例#15
0
    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")),
示例#16
0
    def setupCode(self, texinputs, texscales, colors, rnd, trans = 0):
	# 4 colors
	colorbase = rnd.nextInt()
	c0, c1, c2, c3 = [ colors.getColorStr(colorbase+i)
				for i in range(0,4) ]

        #print [round( RGBtoLAB(map(float, rgb.split()))[0] ) for rgb in [c0,c1,c2] ]

	r0, r1, r2, r3 = [ colors.getNVDP3VecStr(colorbase+i)
				for i in range(0,4) ]

        # map alpha dot product a \in [0,1] into clamp(1 - (1-a) * alphascale)
        if trans > 0:
            alphascale = 1 - 1.0/trans
        else:
            alphascale = 0
            
        alphascale = alphascale * (1. / 16)

	assert len(texinputs) != 0
	while len(texinputs) < 4:
	    texinputs = texinputs + texinputs
	t0, t1, t2, t3 = texinputs[0:4]

        #c0, c1, c2 = [ "1 1 1", "1 0 1", "0 1 0"]
        
	constantcode = """
            Enable BLEND
            BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA 
	    BlendEquation FUNC_ADD
            Disable ALPHA_TEST

	    Enable REGISTER_COMBINERS_NV
	    CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
	    
	    CombinerParameterNV CONSTANT_COLOR0_NV %(r0)s
	    CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s
	    Color %(c0)s
	    SecondaryColorEXT %(c1)s
	    Fog FOG_COLOR %(c2)s
	""" 

        type = rnd.nextInt(3)
        # types: 0=BAND-LIKE, 1=3-COL-LERP, 2=FRACTION-LINE
        
        # Random scaling of (dot) products
        if trans > 0:
            # Try to keep the textures non-fuzzy
            rndscale = exp(.3*abs(rnd.nextGaussian()))
        else:
            rndscale = exp(.5*rnd.nextGaussian())

        def avg(*args):
            sum = 0
            for arg in args: sum += arg
            return sum / float(len(args))
        
	# Then, select the combiner path type.
	if type == 0:
            scale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)
            bandscale = nvcode.combinerscale(3.0 * exp(.5 * rnd.nextGaussian()))

	    # Band-like texture.
	    #
	    # A little different from what Tjl and Jvk originally
	    # planned, where the EF product would have been used;
	    # Sadly, we forgot that E and F are not signed(!).

            # Make outside of the bands transparent if trans > 0
            if trans > 0:
                finalG = "SPARE1_NV"
            else:
                finalG = "ZERO"

	    c = ("""
                # Band-like texture
                
                # SPARE0 <- (TEX0 . TEX1)
		CI0 RGB A TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
		CI0 RGB B TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
		CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV %(bandscale)s NONE TRUE FALSE FALSE

                # SPARE1 <- SPARE0 * SPARE0
                # SPARE0 <- (TEX0 . CONST0)
		CI1 RGB A SPARE0_NV SIGNED_IDENTITY_NV RGB
		CI1 RGB B SPARE0_NV SIGNED_IDENTITY_NV RGB
		CI1 RGB C TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
		CI1 RGB D CONSTANT_COLOR0_NV EXPAND_NORMAL_NV RGB
		CO1 RGB SPARE1_NV SPARE0_NV DISCARD_NV %(scale)s NONE FALSE TRUE FALSE

                # EF <- SPARE0 * SPARE1
		FCI E SPARE1_NV UNSIGNED_INVERT_NV RGB
		FCI F SPARE0_NV UNSIGNED_IDENTITY_NV RGB

                # lerp(EF, PRI_COL, SEC_COL)
		FCI A E_TIMES_F_NV UNSIGNED_INVERT_NV RGB
		FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		FCI C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		FCI D ZERO UNSIGNED_IDENTITY_NV RGB

		FCI G %(finalG)s UNSIGNED_INVERT_NV BLUE
	    """)
        elif type == 1:
            scale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)
            alphascale = nvcode.combinerscale(exp(.5 * abs(rnd.nextGaussian())))
            
            # Interpolate between three colors:
            # d0 = t0 . r0
            # d1 = t1 . r1
            # lerp(d1, lerp(d0, c0, c1), c2)
            # The alpha value is computed as d0^2 - d1^2

            if trans > 0:
                finalG = "SPARE1_NV UNSIGNED_IDENTITY_NV"
            else:
                finalG = "ZERO UNSIGNED_INVERT_NV"
            
	    c = ("""
                # Interpolate between three colors using two dot products
            
                # SPARE0 <- (TEX0 . CONST0)
                # SPARE1 <- (TEX1 . CONST1)
		CI0 RGB A TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
                CI0 RGB B CONSTANT_COLOR0_NV EXPAND_NORMAL_NV RGB
		CI0 RGB C TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
                CI0 RGB D CONSTANT_COLOR1_NV EXPAND_NORMAL_NV RGB
		CO0 RGB SPARE0_NV SPARE1_NV DISCARD_NV %(scale)s NONE TRUE TRUE FALSE

                # PRI_COL <- lerp(SPARE0, PRI_COL, SEC_COL)
		CI1 RGB A PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB B SPARE0_NV UNSIGNED_INVERT_NV RGB
		CI1 RGB C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB D SPARE0_NV UNSIGNED_IDENTITY_NV RGB
		CO1 RGB DISCARD_NV DISCARD_NV PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE

                # SPARE1.alpha <- SPARE0^2 - SPARE1^2
                CI1 ALPHA A SPARE0_NV SIGNED_IDENTITY_NV BLUE
                CI1 ALPHA B SPARE0_NV SIGNED_IDENTITY_NV BLUE
                CI1 ALPHA C SPARE1_NV SIGNED_NEGATE_NV BLUE
                CI1 ALPHA D SPARE1_NV SIGNED_IDENTITY_NV BLUE
                CO1 ALPHA DISCARD_NV DISCARD_NV SPARE1_NV %(alphascale)s NONE FALSE FALSE FALSE

                # lerp(SPARE1, PRI_COL, FOG)
                FCI A SPARE1_NV UNSIGNED_INVERT_NV RGB
                FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
                FCI C FOG UNSIGNED_IDENTITY_NV RGB
                FCI D ZERO UNSIGNED_IDENTITY_NV RGB

		FCI G %(finalG)s ALPHA
	    """)
        else:
            scale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)
            alphascale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)

            # Interpolate on the fraction line c0,c1,c2:
            # d0 = t0 . t1
            # c(d0) =
            #    -1 -> c0
            #     0 -> c1
            #    +1 -> c2

            # lerp(d1, lerp(d0, c0, c1), c2)
            # The alpha value is computed as d0^2 - d1^2

            if trans > 0:
                finalG = "SPARE1_NV UNSIGNED_IDENTITY_NV"
            else:
                finalG = "ZERO UNSIGNED_INVERT_NV"
            
	    c = ("""
                # Fraction-line color interpolate
                
                # SPARE0 <- (TEX0 . TEX1)  
                # SPARE1 <- -(TEX0 . TEX1) 
		CI0 RGB A TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
		CI0 RGB B TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
		CI0 RGB C TEXTURE%(t0)s EXPAND_NEGATE_NV RGB
		CI0 RGB D TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
		CO0 RGB SPARE0_NV SPARE1_NV DISCARD_NV %(scale)s NONE TRUE TRUE FALSE

                # PRI_COL <- lerp(SPARE1, SEC_COL, PRI_COL)
		CI1 RGB A PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB B SPARE1_NV UNSIGNED_INVERT_NV RGB
		CI1 RGB C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB D SPARE1_NV UNSIGNED_IDENTITY_NV RGB
		CO1 RGB DISCARD_NV DISCARD_NV PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE

                # lerp(SPARE0, PRI_COL, FOG)
                FCI A SPARE0_NV UNSIGNED_INVERT_NV RGB 
                FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB 
                FCI C FOG UNSIGNED_IDENTITY_NV RGB 
                FCI D ZERO UNSIGNED_IDENTITY_NV RGB 

                # SPARE1.alpha <- TEX0.b * CONST0.b + TEX1.b * CONST1.b
                CI1 ALPHA A TEXTURE%(t0)s EXPAND_NORMAL_NV BLUE
                CI1 ALPHA B CONSTANT_COLOR0_NV EXPAND_NORMAL_NV BLUE
                CI1 ALPHA C TEXTURE%(t1)s EXPAND_NORMAL_NV BLUE
                CI1 ALPHA B CONSTANT_COLOR1_NV EXPAND_NORMAL_NV BLUE
                CO1 ALPHA DISCARD_NV DISCARD_NV SPARE1_NV %(alphascale)s NONE FALSE FALSE FALSE
                
		FCI G %(finalG)s ALPHA 
	    """)
            
            
	c = (constantcode + c) % locals()
	c = nvcode.combinercode(c)
	# print "c: ",c

        if not GL.hasExtension("GL_NV_register_combiners"):
            # Kluge: emulate using fragment program
            c = nvcode.convCombiner(c, GL)
	return c
示例#17
0
    def getOptimizedPaper(self,
                          seed,
                          passmask=[1, 1, 1, 1, 1, 1, 1],
                          numcolors=8,
                          minlum=80,
                          blend=0):
        pap = self.getPaper(seed, passmask, numcolors, minlum, blend)

        if not GL.hasExtension("GL_SGIS_generate_mipmap"):
            print "Warning: not returning optimized paper because"
            print "GL_SGIS_generate_mipmap extension is required but not available"
            return pap
        if GL.workaroundStupidBuggyAtiDrivers:
            print "Warning: not returning optimized paper because"
            print "copyTexImage2D has problems on ATI drivers"
            return pap

        # Now, we render a region.
        v = pap.repeat._getSTVectors()

        vs = optimizingWindow.createVobScene()
        vs.map.put(vob.vobs.SolidBackdropVob(java.awt.Color.red))

        cs1 = vs.coords.ortho(0, 0, 0, 0, optimizedPaperSize + 1,
                              optimizedPaperSize + 1)
        cs2 = vs.coords.affine(0, 0, 0, 0, v[0][0], v[0][1], v[1][0], v[1][1])
        vs.map.put(GLRen.createPaperQuad(pap, 0, 0, 1, 1, 1), cs1, cs2)
        optimizingWindow.renderStill(vs, 1)

        tex = GL.createTexture()
        texid = tex.getTexId()
        GL.call("""
	    BindTexture TEXTURE_2D %(texid)s
	    TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 2
	    TexParameter TEXTURE_2D  GENERATE_MIPMAP_SGIS TRUE
	    TexParameter TEXTURE_2D  TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
	    TexParameter TEXTURE_2D  TEXTURE_MAG_FILTER LINEAR
	    BindTexture TEXTURE_2D 0
	""" % locals())

        tex.copyTexImage2D(optimizingWindow.getRenderingSurface(), "FRONT",
                           "TEXTURE_2D", 0, "RGB5", 0, 0, optimizedPaperSize,
                           optimizedPaperSize, 0)

        # Apparently, NV drivers 44.96 (maybe others) have some trouble
        # with the 1x1 mipmap getting clobbered.
        # Usually, that wouldn't be a problem, but papers will be viewed
        # 1) at largely different scales
        # 2) blurred for text background
        # so this matters.
        # We shall forbid the use of that mipmap
        tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_LEVEL",
                            optimizedPaperMaxLevel)

        if dbg:
            vob.putil.texture.printTex(tex.getTexId())

        npap = PaperHanger()
        npap.setNPasses(1)
        npap.cachedTexture = tex
        npap.addDepend(tex)  # Need this for clones to survive

        ppass = npap.getPass(0)

        ppass.setSetupcode("""
            PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT COLOR_BUFFER_BIT CURRENT_BIT
            Disable BLEND
	    ActiveTexture TEXTURE1
	    Disable TEXTURE_2D
	    ActiveTexture TEXTURE0
	    Enable DEPTH_TEST
	    DepthFunc LESS
	    BindTexture TEXTURE_2D %(texid)s
	    TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE
	    Color 0 1 0
	    Enable TEXTURE_2D
	    SecondaryColorEXT 0 0 0
	""" % locals())

        ppass.setNTexGens(1)
        # t = pap.repeat.vecs
        t = v
        if dbg:
            print "T ", t
        ppass.putNormalTexGen(0, [
            t[0][0],
            t[0][1],
            0,
            0,
            -t[1][0],
            -t[1][1],
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
        ])

        ppass.setTeardowncode("""
            PopAttrib
            ActiveTexture TEXTURE0
        """)

        if dbg:
            print "Ret: ", npap.toString(), npap.getPass(0).getNTexGens()

        return npap
示例#18
0
import vob.paper.texcomb_NV1X
import vob.paper.texcomb_NV2X
import vob.paper.texcomb_GL1_1

from org.nongnu.libvob.gl import GL, GLRen, Paper, PaperMill
import java
from java.lang import Math

from org.nongnu.libvob.gl import PaperOptions
paperopt = PaperOptions.instance()

dbg = 1
# Discriminate between different renderers.
# These are for debug output only.
if dbg:
    vendor = GL.getGLString("VENDOR")
    renderer = GL.getGLString("RENDERER")
    version = GL.getGLString("VERSION")
    print "GL strings: '%s' '%s' '%s'" % (vendor, renderer, version)

#
# Now, go through some questions.
#

# Check which texture operations to use.
if not paperopt.use_opengl_1_1 and GL.hasExtension("GL_NV_texture_shader3"):
    # We can use the general texture shaders.
    # XXX Should check separately for texture_shader2,
    # otherwise it'll be SLOW.
    if dbg: print "Using NV20 texture shaders"
    from vob.paper.texops_NV2X import makeNormalShaderPass, scaleFactor
示例#19
0
def makeMipzip(image,
               mipzip,
               maxwidth=-1,
               maxheight=-1,
               texformat=None,
               internalTexFormat=None,
               uncompressedTexType=None):
    """Convert the given image file into a mipzip file.

    image -- the image file name
    mipzip -- the mipzip file name
    maxwidth -- if image is wider than maxwidth, cut off edge
    maxheight -- if image is taller than maxheight, cut off edge
    texformat -- The texture format to use
    internalTexFormat -- The internal texture format to represent the data in
                         for compressed textures, same as texformat
    uncompressedTexType -- The datatype (relevant only for uncompressed
			   textures)
    """

    if texformat == None:
        if not defaultTexFormat:
            _init()
        texformat = defaultTexFormat

    print "TEXFORMAT: ", texformat, defaultTexFormat
    isCompressed = (java.lang.String(texformat).indexOf("COMPRESS") >= 0)

    if internalTexFormat == None:
        internalTexFormat = texformat

    if not isCompressed:
        if uncompressedTexType == None:
            uncompressedTexType = "UNSIGNED_BYTE"

    _init()
    GL.freeQueue()

    im = GL.createImage(image)
    d0 = im.getSize()
    print d0
    d = java.awt.Dimension(
        _clipmax(d0.width, maxwidth),
        _clipmax(d0.height, maxheight),
    )

    w = roundup2(d.width)
    h = roundup2(d.height)
    tex = GL.createTexture()
    tex.loadNull2D('TEXTURE_2D', 0, internalTexFormat, w, h, 0, "RGB", "BYTE")
    print "WH: ", w, h
    tex.loadSubImage(0, im, 0, 0, 0, 0, chomp4(d.width), chomp4(d.height))

    print "Write ", mipzip

    out = zip.ZipOutputStream(java.io.FileOutputStream(mipzip))

    def metaEntry(name, comment):
        entry = zip.ZipEntry(name)
        entry.setComment(comment)
        entry.setSize(0)
        out.putNextEntry(entry)
        out.closeEntry()

    metaEntry("texformat", texformat)

    if not isCompressed:
        metaEntry("internaltexformat", internalTexFormat)
        metaEntry("datatype", uncompressedTexType)

    metaEntry("origsize", "%sx%s" % (d.width / float(w), d.height / float(h)))

    l = 0
    while 1:
        w = int(tex.getLevelParameter(l, "TEXTURE_WIDTH")[0])
        h = int(tex.getLevelParameter(l, "TEXTURE_HEIGHT")[0])
        print "WH: ", w, h

        if isCompressed:
            bytes = tex.getCompressedTexImage(l)
        else:
            bpt = bytesPerTexel(texformat, uncompressedTexType)

            bytes = jarray.zeros(bpt * w * h, "b")
            tex.getTexImage(l, texformat, uncompressedTexType, bytes)

        print "Bytes: ", l, len(bytes)
        entry = zip.ZipEntry(str(l))
        entry.setComment("%sx%s" % (int(w), int(h)))
        entry.setSize(len(bytes))
        out.putNextEntry(entry)
        out.write(bytes)
        out.closeEntry()
        if w == 1 and h == 1: break
        l += 1
    out.close()
    del tex
    java.lang.System.gc()
    GL.freeQueue()
示例#20
0
def getTex(s):
    if not imgs.has_key(s):
        print "Load image ", s
        imgs[s] = GL.createImage(s)
        texs[s] = GL.createTexRect(imgs[s])
    return texs[s]
示例#21
0
    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"))
示例#22
0
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
"""),
]
示例#23
0
    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")),
示例#24
0
# MA  02111-1307  USA
# 

from org.nongnu.libvob.gl import GL, GLRen
from org.nongnu.libvob.util import ColorUtil
from vob.putil import cg
from vob.putil.misc import *
from vob.putil.demokeys import *

from vob.paper.texcache import getCachedTexture
tex = getCachedTexture(
    [1024, 512, 0, 4, "RGBA", "RGBA", "noise", 
     [ "freq", "100", "bias", ".5", "scale", ".8" ]]
    )

tex = GL.createTexture()
GL.call("""
BindTexture TEXTURE_2D %s
TexImage2D TEXTURE_2D 0 ALPHA 16 16 0 ALPHA \
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 \
1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 \