/[gzz]/gzz/gfx/demo/vpbuoy.py
ViewVC logotype

Diff of /gzz/gfx/demo/vpbuoy.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by tjl, Sun Dec 15 09:06:46 2002 UTC revision 1.5 by tjl, Sun Dec 15 20:08:42 2002 UTC
# Line 1  Line 1 
1  from gfx.util.misc import *  from gfx.util.misc import *
2  from gfx.util import vparb  from gfx.util import vparb, cg
3    
4    
5  class Scene:  class Scene:
# Line 12  class Scene: Line 12  class Scene:
12          rad = 400.0          rad = 400.0
13          recrad = 1/400.0          recrad = 1/400.0
14    
15          if 0:          if 1:
16              func = """              cgprog = """
17                  # Shift              struct outs {
18                  TEMP shift;                  float4 pos : POSITION;
19                  MUL shift, cent, radius.y;                  float4 color : COLOR;
20              """                  float4 pointsize : PSIZE;
21          else:              };
22              func = """              float4x4 pmat;
   
                 PARAM lines[] = {  
                             { -100, -100, 1, 0 },  
                             { 0, 0, .1, 0 },  
                             { .2, .02, 9, 0 },  
                             { .3, .92, .1, 0 },  
                             { .75, 1, 1, 0 }  
                         };  
   
                 TEMP var;  
                 SUB var, amplen, absamo;  
                 ADD var, var, 1;  
                 MUL var, var, .5;  
   
                 ADDRESS iadr;  
                 TEMP ind;  
                 SGE ind.x, var, lines[1].x;  
                 SGE ind.y, var, lines[2].x;  
                 SGE ind.z, var, lines[3].x;  
                 SGE ind.w, var, lines[4].x;  
                 DP4 ind, ind, ind;  
                 ARL iadr.x, ind.x;  
   
                 # Shift  
                 TEMP shift;  
                 MOV shift, var;  
   
                 SUB shift, var, lines[iadr.x].x;  
                 MUL shift, shift, lines[iadr.x].z;  
                 ADD shift, shift, lines[iadr.x].y;  
   
   
                 SUB shift, shift, var;  
   
                 # See where we fall; 5 line pieces  
   
                 MUL shift, shift, radius.y;  
             """  
   
         self.prog = GL.createProgram("""!!ARBvp1.0  
               
             # x,y = coordinates  
             # z = 0: no shift, 1 = shift  
             # w = 0  
             ATTRIB orig = vertex.position;  
23    
24              PARAM center = { 512, 350, 0, 0 };              outs main( float4 orig : POSITION,
25              PARAM p = { 112, 350, 0, 0 };                      float4 texcoord : TEXCOORD0,
26              PARAM radius = { %(recrad)s, %(rad)s, 0, 0 };                      float4 color : COLOR
27              PARAM zeroone = { 0, 1, 5, 0 };                      ) {
28                    float4 p = { 100, 300, 0, 0 };
29                    float4 origin = { 300, 300, 0, 0};
30                    float rad = 200;
31    
32                    outs o;
33    
34              PARAM pm[4] = { state.matrix.program[0] };                  float4x4 pmat = glstate.matrix.program[0];
             PARAM mvp[4] = { state.matrix.mvp };  
35    
36              TEMP anchor;                  float4 anchor = mul(pmat, orig);
             DP4 anchor.x, pm[0], orig;  
             DP4 anchor.y, pm[1], orig;  
             MOV anchor.z, orig.z;  
             MOV anchor.w, 0;  
37    
38              # A - O                  float a2o = distance(anchor.xy, origin.xy) / rad;
             TEMP amo;  
             MOV amo, zeroone.x;  
             SUB amo.xy, anchor, center;  
39    
40              # | A - O |                  float4 buoy;
             TEMP absamo;  
             DP3 absamo, amo, amo;  
             RSQ absamo.x, absamo.x;  
             MUL absamo, absamo.x, absamo.y;  
             MUL absamo, absamo, radius.x;  
41    
42              # cent = 1-|A-O|                  buoy = anchor;
             TEMP cent;  
             SUB cent, zeroone.y, absamo.x;  
             MAX cent, cent, 0;  
43    
44              TEMP scale;                  o.pos = mul(glstate.matrix.mvp, buoy);
45              ADD scale, cent, zeroone.y;                  o.color = float4(color.x, color.y, a2o, color.w);
46                    o.pointsize = float4(15.0, 0, 0, 0);
47    
48              TEMP amp;                  return o;
49              SUB amp, anchor, p;              }
50                """
51              TEMP ampnor;              pstr = cg.compile_arbvp1(cgprog)
52              TEMP amplen;              # fix a really silly compiler bug
53              DP3 amplen, amp, amp;              # For some reason, only the mvp matrix works,
54              RSQ ampnor, amplen.x;              # the others produce this type of garbage in the output.
55              MUL amplen, amplen.x, ampnor.x;              pstr = pstr.replace("s327[32]", "s327[4]")
56              MUL amplen, amplen.x, radius.x;              pstr = pstr.replace("s0[327]", "s327[0]")
57              MUL ampnor, ampnor, amp;              pstr = pstr.replace("s328", "s327[1]")
58                pstr = pstr.replace("s329", "s327[2]")
59              # Function to determine shift              pstr = pstr.replace("s330", "s327[3]")
             %(func)s  
   
             MUL shift, shift, anchor.z;  
   
             # buoy position  
             TEMP buoy;  
             MAD buoy, ampnor, shift, anchor;  
   
             MOV buoy.zw, zeroone.xyxy;  
             ADD buoy.z, buoy.z, -scale;  
   
             ADD buoy.xyz, buoy, vertex.texcoord[0];  
60    
61              DP4 result.position.x, mvp[0], buoy;              self.prog = GL.createProgram(pstr)
62              DP4 result.position.y, mvp[1], buoy;          
             DP4 result.position.z, mvp[2], buoy;  
             DP4 result.position.w, mvp[3], buoy;  
63    
64              # MOV result.color, vertex.color;          else:
             SWZ result.color, cent, x, x, x, 1;  
65    
66              ALIAS ps0 = anchor;              if 0:
67              MAD ps0, zeroone.z, anchor.z, zeroone.z;                  func = """
68              MUL result.pointsize, scale, ps0;                      # Shift
69                        TEMP shift;
70                        MUL shift, cent, radius.y;
71                    """
72                else:
73                    func = """
74    
75                        PARAM lines[] = {
76                                    { -100, -100, 1, 0 },
77                                    { 0, 0, .1, 0 },
78                                    { .2, .02, 9, 0 },
79                                    { .3, .92, .1, 0 },
80                                    { .75, 1, 1, 0 }
81                                };
82    
83                        TEMP var;
84                        SUB var, amplen, absamo;
85                        ADD var, var, 1;
86                        MUL var, var, .5;
87    
88                        ADDRESS iadr;
89                        TEMP ind;
90                        SGE ind.x, var, lines[1].x;
91                        SGE ind.y, var, lines[2].x;
92                        SGE ind.z, var, lines[3].x;
93                        SGE ind.w, var, lines[4].x;
94                        DP4 ind, ind, ind;
95                        ARL iadr.x, ind.x;
96    
97                        # Shift
98                        TEMP shift;
99                        MOV shift, var;
100    
101                        SUB shift, var, lines[iadr.x].x;
102                        MUL shift, shift, lines[iadr.x].z;
103                        ADD shift, shift, lines[iadr.x].y;
104    
105    
106                        SUB shift, shift, var;
107    
108                        # See where we fall; 5 line pieces
109    
110                        MUL shift, shift, radius.y;
111                    """
112    
113                self.prog = GL.createProgram("""!!ARBvp1.0
114                    
115                    # x,y = coordinates
116                    # z = 0: no shift, 1 = shift
117                    # w = 0
118                    ATTRIB orig = vertex.position;
119    
120                    PARAM center = { 512, 350, 0, 0 };
121                    PARAM p = { 112, 350, 0, 0 };
122                    PARAM radius = { %(recrad)s, %(rad)s, 0, 0 };
123                    PARAM zeroone = { 0, 1, 5, 0 };
124    
125    
126                    PARAM pm[4] = { state.matrix.program[0] };
127                    PARAM mvp[4] = { state.matrix.mvp };
128    
129                    TEMP anchor;
130                    DP4 anchor.x, pm[0], orig;
131                    DP4 anchor.y, pm[1], orig;
132                    MOV anchor.z, orig.z;
133                    MOV anchor.w, 0;
134    
135                    # A - O
136                    TEMP amo;
137                    MOV amo, zeroone.x;
138                    SUB amo.xy, anchor, center;
139    
140                    # | A - O |
141                    TEMP absamo;
142                    DP3 absamo, amo, amo;
143                    RSQ absamo.x, absamo.x;
144                    MUL absamo, absamo.x, absamo.y;
145                    MUL absamo, absamo, radius.x;
146    
147                    # cent = 1-|A-O|
148                    TEMP cent;
149                    SUB cent, zeroone.y, absamo.x;
150                    MAX cent, cent, 0;
151    
152                    TEMP scale;
153                    ADD scale, cent, zeroone.y;
154    
155                    TEMP amp;
156                    SUB amp, anchor, p;
157    
158                    TEMP ampnor;
159                    TEMP amplen;
160                    DP3 amplen, amp, amp;
161                    RSQ ampnor, amplen.x;
162                    MUL amplen, amplen.x, ampnor.x;
163                    MUL amplen, amplen.x, radius.x;
164                    MUL ampnor, ampnor, amp;
165    
166                    # Function to determine shift
167                    %(func)s
168    
169                    MUL shift, shift, anchor.z;
170    
171                    # buoy position
172                    TEMP buoy;
173                    MAD buoy, ampnor, shift, anchor;
174    
175                    MOV buoy.zw, zeroone.xyxy;
176                    ADD buoy.z, buoy.z, -scale;
177    
178                    ADD buoy.xyz, buoy, vertex.texcoord[0];
179    
180                    DP4 result.position.x, mvp[0], buoy;
181                    DP4 result.position.y, mvp[1], buoy;
182                    DP4 result.position.z, mvp[2], buoy;
183                    DP4 result.position.w, mvp[3], buoy;
184    
185                    # MOV result.color, vertex.color;
186                    SWZ result.color, cent, x, x, x, 1;
187    
188                    ALIAS ps0 = anchor;
189                    MAD ps0, zeroone.z, anchor.z, zeroone.z;
190                    MUL result.pointsize, scale, ps0;
191    
192    
193              END                  END
194    
195    
196              """ % locals())                  """ % locals())
197    
198          vparb.dump(self.prog.getProgId())          vparb.dump(self.prog.getProgId())
199          if 0: self.prog = GL.createProgram("""!!ARBvp1.0          if 0: self.prog = GL.createProgram("""!!ARBvp1.0

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26