Example #1
0
    def LoadVertexHaloShader(self):
        vp = '''\
!!ARBvp1.0\n\
\n\
ATTRIB pos = vertex.position;\n\
ATTRIB dataA = vertex.texcoord[0];\n\
ATTRIB dataB = vertex.texcoord[1];\n\
\n\n\
PARAM  mat[4] = { state.matrix.mvp };\n\
PARAM  matP[4] = { state.matrix.projection };\n\
\n\
TEMP p,po, disp, dataout, tmp;\n\
\n\
# Transform by concatenation of the\n\
# MODELVIEW and PROJECTION matrices.\n\
DP4 p.x, mat[0], pos;\n\
DP4 p.y, mat[1], pos;\n\
DP4 p.z, mat[2], pos;\n\
DP4 p.w, mat[3], pos;\n\
#MOV p.w, 1; \n\
\n\
MOV dataout, dataA;\n\
MOV dataout.z, dataB.y;\n\n\
MUL disp, dataA, dataB.x; \n\
MUL disp, disp, program.env[0].x; \n\
#MUL disp.x, disp.x, matP[0].x;\n\
#MUL disp.y, disp.y, matP[1].y;\n\
MAD p, {1,1,0,0},  disp, p;\n\
MOV result.position, p;\n\
MOV result.texcoord, dataout;\n\
\nEND\n'''

        glew.glProgramStringARB(glew.GL_VERTEX_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, vp);
        if not _checkProgramError(vp): return False
        else: return True
Example #2
0
    def MakeDrawAOShader(self):
        fp  = '''\
!!ARBfp1.0  \n\
PARAM  Smat0 = program.env[0];\n\
PARAM  Smat1 = program.env[1];\n\
PARAM  Smat2 = program.env[2];\n\
PARAM  param = program.env[3];\n\
ATTRIB tc   = fragment.texcoord;  \n\
ATTRIB data   = fragment.texcoord[1];  \n\
TEMP tmp,nor, pos,origpos, abs,l;\n\
\n\
# Find shpere normal... \n\
CMP abs, tc, -tc, tc;\n\
MAD nor, -abs, {1,1,0,0}, +1;\n\
CMP tmp.x, tc.x, -nor.y, nor.y;    # tmp_i = sign_i*( 1-abs_i) \n\
CMP tmp.y, tc.y, -nor.x, nor.x;    # tmp_i = sign_i*( 1-abs_i) \n\
ADD nor.z, abs.x, abs.y; \n\
ADD nor.z, nor.z, -1; \n\
CMP nor.x, -nor.z, tmp.x, tc.x;\n\
CMP nor.y, -nor.z, tmp.y, tc.y;\n\
# Normalize \n\
DP3 tmp.x, nor, nor; \n\
RSQ tmp.x, tmp.x; \n\
MUL nor, nor, tmp.x; \n\
\n\
# Find pos \n\
MAD origpos, data.w, nor, data;\n\
MOV origpos.w, 1;\n'''
        fp += self.addDrawAOShaderSnippet()

        glew.glProgramStringARB(glew.GL_FRAGMENT_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, fp)
        if not _checkProgramError(fp): return False
        else: return True
Example #3
0
    def setBallVertexProgram(self):
        vertex_prog = '''\
!!ARBvp1.0\n\
\n\
ATTRIB pos = vertex.position;\n\
ATTRIB data = vertex.normal;\n\
\n'''

        if (self.P_texture>0): vertex_prog += 'ATTRIB offset = vertex.texcoord;\n'

        vertex_prog += '''\
\n\
PARAM  mat[4] = { state.matrix.mvp };\n\
PARAM  matP[4] = { state.matrix.projection };\n\
\n\
TEMP p,po, disp, dataout, tmp;\n\
\n\
# Transform by concatenation of the\n\
# MODELVIEW and PROJECTION matrices.\n\
DP4 p.x, mat[0], pos;\n\
DP4 p.y, mat[1], pos;\n\
DP4 p.z, mat[2], pos;\n\
DP4 p.w, mat[3], pos;\n\
#MOV p.w, 1; \n\
\n\
MOV dataout, data;\n\
MUL dataout.z, dataout.z, program.env[0].x;\n'''
        # Enlarge impostors to include borders
        if (self._border_outside() != 0): vertex_prog += '''\
RSQ tmp.y,  dataout.z ;\n\
#MUL tmp.y,  tmp.y , tmp.y; # Comment to 'almost'\n\
MUL tmp.x,  %7.5f , tmp.y;\n\
ADD dataout.w,  tmp.x , 1;\n\
MUL dataout.xy, dataout, dataout.w ;\n\
MAD dataout.w,  dataout.w, dataout.w, -1;\n'''%(self._border_outside())

        vertex_prog += '''\n\
MUL disp, dataout, dataout.z; \n\
#MUL disp.x, disp.x, matP[0].x;\n\
#MUL disp.y, disp.y, matP[1].y;\n\
MAD p, {1,1,0,0},  disp, p;\n\
\n\
MOV result.position, p;\n\
\n\
#MOV dataout.w, p.w;\n\
MOV result.texcoord, dataout;\n\
'''

        if ((self.P_col_atoms_sat>0) and (self.P_col_atoms_bri>0)): vertex_prog += "MOV result.color, vertex.color;\n"
        if (self.P_texture>0): vertex_prog += "MOV result.texcoord[2], offset;\n"
        if (self.P_use_shadowmap() ): vertex_prog +=" MOV result.texcoord[3], vertex.position;\n"
        vertex_prog += "\nEND\n"

        glew.glProgramStringARB(glew.GL_VERTEX_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, vertex_prog)
        if not _checkProgramError(vertex_prog): return False
        else: return True
Example #4
0
    def MakeHaloShader(self, powres):
        fp = '''\
!!ARBfp1.0\n\
\n\
ATTRIB data   = fragment.texcoord;  \n\
\n\
TEMP tmp,tmp2,tmp3, t,t0,t1,t2,nor,n,nabs,nsign,disp,res,depth,pos,\n\
     lighting;  \n\
\n\
MOV nor, data;  \n\
MUL tmp, data, data;  \n\
ADD tmp2.x, tmp.x, tmp.y;\n\
ADD tmp2.z, -tmp2.x, 1;\n\
KIL tmp2.z;\n\
\n\
MAD tmp2.x, -data.z, tmp2.x, data.z;\n\
\n\
#TEST!\n\
#ADD tmp2.x, tmp2.x, %10.8f;\n\
#CMP result.color, tmp2.x, {1,0,0,1}, {0,0,1,1};\n\
\n\
MUL tmp, fragment.position, {%14.12f, %14.12f, 0, 0};\n\
#MAD tmp, fragment.position, {0.5, 0.5, 0, 0}, {0.5, 0.5, 0, 0};\n\
TEX tmp.z, tmp, texture[1], 2D; # tmp.z = old depth \n\
ADD tmp.z, tmp.z, -fragment.position.z; \n\
MUL_SAT tmp.z, tmp.z, program.env[0].x; \n\
MUL tmp.z, tmp.z, tmp2.x; \n\
MUL tmp.z, tmp.z, tmp2.x;  # again for smoother edges\n'''%(self.P_halo_str-1, 1.0/(1<<powres), 1.0/(1<<powres))
        if (self.P_halo_str<1.0): fp += "MUL tmp.z , tmp.z, %10.8f;\n"%(self.P_halo_str)
        if not self.doingAlphaSnapshot:
            fp += "MAD result.color, {0,0,0,1}, tmp.z, {%5.4f,%5.4f,%5.4f,0.0} ;\n"%(self.P_halo_col,self.P_halo_col,self.P_halo_col)
        else:
            if (self.P_halo_col==1.0): fp += "MOV result.color, tmp.z;\n"
            else: fp += "MUL result.color, {0,0,0,1}, tmp.z;\n"
        fp += "END\n"

        glew.glProgramStringARB(glew.GL_FRAGMENT_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, fp)
        if not _checkProgramError(fp): return False
        else: return True
Example #5
0
    def MakeDrawAOShaderSticks(self):
        fp = '''\
!!ARBfp1.0  \n\
PARAM  Smat0 = program.env[0];\n\
PARAM  Smat1 = program.env[1];\n\
PARAM  Smat2 = program.env[2];\n\
PARAM  param = program.env[3];\n\
PARAM  radius = program.env[4];\n\
ATTRIB axispos= fragment.texcoord[1];  \n\
ATTRIB data   = fragment.texcoord;  \n\
TEMP tmp,n,nor, pos,origpos, abs,l;\n\
\n\n\
# find norm in cyl space \n\
MAD n.y, data.y, -2, 0; \n\
CMP n.y, n.y, -n.y, n.y; \n\
ADD n.x, 2, -n.y; \n\
MIN n.x, n.x, n.y; \n\
CMP n.x, data.y, n.x, -n.x; \n\
MAD n, n, {1,1,0,0}, {0,-1,0,0};\n\
\n\
# normalize \n\
DP3 tmp.x, n, n;\n\
RSQ tmp.x, tmp.x;\n\
MUL n, tmp.x, n;\n\
\n\
# rotate \n\
MUL nor, -n.x, fragment.texcoord[2];\n\
MAD nor,  n.y, fragment.texcoord[3], nor;\n\
\n\
# find position \n\
MAD origpos, nor, radius.y, axispos; \n\
MOV origpos.w, 1;\n'''
        fp += self.addDrawAOShaderSnippet()
        glew.glProgramStringARB(glew.GL_FRAGMENT_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, fp)
        if not _checkProgramError(fp): return False
        else: return True
Example #6
0
    def setBallFragmentProgram(self):
        CgUtil.shaderHasChanged = True
        frag_prog = ''
        if (self.shadowmapBuilding):
            frag_prog += '''\
!!ARBfp1.0  \n\
\n\
ATTRIB data = fragment.texcoord;  \n\
TEMP tmp; \n\
\n\
MAD tmp.x, data.x, data.x, -1;  \n\
MAD tmp.x, data.y, data.y, tmp.x;  \n\
KIL -tmp.x;\n'''
            if (self.accurateShadowmapBuilding):
                frag_prog += '''\
RSQ tmp.x, tmp.x;  \n\
RCP tmp.x, tmp.x;  \n\
MUL tmp.x, tmp.x, data.z; \n\
MAD result.depth, -tmp.x, 0.005, fragment.position.z;\n'''

            frag_prog += '''\
MOV result.color, 1;\n\
END\n'''

            glew.glProgramStringARB(glew.GL_FRAGMENT_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, frag_prog)
            if not _checkProgramError(frag_prog): return False
            else: return True

        #####
        ## Fragment program ball
        ####
        frag_prog += '''\
!!ARBfp1.0  \n\
\n\
ATTRIB data = fragment.texcoord;  \n\
ATTRIB offset = fragment.texcoord[2];\n\
ATTRIB basecol = fragment.color;  \n\
'''
        if self.P_use_shadowmap():
            frag_prog += '''\
PARAM  Smat0  = program.env[3];   \n\
PARAM  Smat1  = program.env[4];   \n\
PARAM  Smat2  = program.env[5];   \n\
#PARAM  ratio  = program.env[6];   \n\
ATTRIB origpos = fragment.texcoord[3];  \n'''

        if (moltextureCanvas.GetHardRes()==0): TNORM=0
        else: TNORM = 1.0/moltextureCanvas.GetHardRes()
        frag_prog += '''\n\
TEMP tmp,tmp2,tmp3, t,t0,t1,t2,nor,n,nabs,nsign,disp,res,depth,\n\
     lighting, border, posScreen;  \n\
PARAM TNORM={%10.9f,%10.9f,0,0};  \n\
\n\
PARAM LIGHT= state.light[0].position ;  \n\
PARAM hwv  = state.light[0].half;\n\
\n\
PARAM  mat[4] = { state.matrix.projection };  \n\
PARAM  mat0 = program.env[0];\n\
PARAM  mat1 = program.env[1];\n\
PARAM  mat2 = program.env[2];\n\
\n'''%(TNORM,TNORM)

        frag_prog += '''MOV nor, data;  \n'''

        frag_prog += '''\
MUL tmp, data, data;  \n\
MOV tmp.z, 1;          \n\
DP3 border.x, tmp, {1,1,-1,0};  \n'''

        if (self._border_outside() > 0):
            frag_prog += '''\
ADD tmp2.y, -border.x, data.w;  # allow for border (part ii)  \n\
#MAD tmp2.y, data.z, -border.x, %7.5f;\n\
#MAD tmp2.y, data.z, tmp2.y, %7.5f;\n\
KIL tmp2.y;  \n'''%(-2*self._border_outside(), self._border_outside()*self._border_outside())
        else: frag_prog += '''\n\nKIL -border.x;  \n'''

        frag_prog += '''\
RSQ tmp2.y, border.x;  \n\
RCP tmp2.x, tmp2.y;  \n\
MOV nor.z, tmp2.x;  \n\
\n\
MAD tmp2.y, tmp2.x, data.z, 0;  # note: add an extra range of 0 \n\n
MAD depth.x, -tmp2.y, 0.005, fragment.position.z; # ortho \n'''

        frag_prog += self.addDepthAdjustSnippet()

        if ((self.P_texture>0) or (self.P_use_shadowmap())):
            frag_prog += '''\n\n\
# rotate normal           \n\
DP3 n.x, mat0, nor;        \n\
DP3 n.y, mat1, nor;         \n\
DP3 n.z, mat2, nor;          \n\
MOV n.w, 0;                   \n\n'''

        frag_prog += self.addDirectLightingSnippet()
        if (self.P_use_shadowmap()): frag_prog += self.addShadowMapComputation()

        if (self.P_texture>0):
            CSIZE = hardSettings.CSIZE
            frag_prog += '''\n\n\
## TEXTURING OCTAMAP STYLE    \n\
#                              \n\
CMP nabs, n, -n, n;             \n\
DP3 tmp.y, {1,1,1,0}, nabs;      \n\
RCP tmp.z, tmp.y;                 \n\
MUL t0, n, tmp.z;                  \n\
MAD t1, nabs, tmp.z, -1;            \n\
#   t1= -(1-abs(t))                  \n\
CMP t2.x, n.x, t1.y, -t1.y;           \n\
CMP t2.y, n.y, t1.x, -t1.x;            \n\
CMP t0, n.z, t0, t2;                    \n\
MAD t, t0, {%5.2f, %5.2f, 0,0},          \n\
           {%5.2f, %5.2f, 0,0};           \n\n'''%(CSIZE/2.0 - self.gap, CSIZE/2.0 - self.gap, CSIZE/2.0, CSIZE/2.0)

        frag_prog += self.addTexturingSnippet()
        frag_prog += '''\
ADD result.color, res, {0,0,0,1};\n\n\
END\n'''
        glew.glProgramStringARB(glew.GL_FRAGMENT_PROGRAM_ARB, glew.GL_PROGRAM_FORMAT_ASCII_ARB, frag_prog)
        if not _checkProgramError(frag_prog): return False
        else: return True