9 |
edgelodbias = 0 |
edgelodbias = 0 |
10 |
texscale = 1 |
texscale = 1 |
11 |
use_texture = 0 |
use_texture = 0 |
|
use_stencil = 1 |
|
12 |
|
|
13 |
matrices = [ "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1", |
matrices = [ "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1", |
14 |
"4 0 0 0.005 0 1 0 0 0 0 1 0 0 0 0 1" ] |
"4 0 0 0.005 0 1 0 0 0 0 1 0 0 0 0 1" ] |
55 |
global tex |
global tex |
56 |
global texenv_inner, texenv_outer, alphalevel, w0, w1 |
global texenv_inner, texenv_outer, alphalevel, w0, w1 |
57 |
global colmap0, colmap1, angles |
global colmap0, colmap1, angles |
58 |
global using_shader, using_secondary_color, using_multitex |
global using_fragprog, using_shader, using_secondary_color, using_multitex |
59 |
|
|
60 |
|
using_fragprog = 0 |
61 |
using_shader = 0 |
using_shader = 0 |
62 |
using_secondary_color = 0 |
using_secondary_color = 0 |
63 |
using_multitex = 0 |
using_multitex = 0 |
64 |
|
|
65 |
if profile == "NV_PROG": |
if profile == "NV_PROG": |
66 |
|
using_fragprog = 1 |
67 |
|
|
68 |
radius = 2 |
radius = 2 |
69 |
dh = [ sqrt(radius**2 - d**2) for d in range(0,radius+1) ] |
dh = [ sqrt(radius**2 - d**2) for d in range(0,radius+1) ] |
70 |
|
|
71 |
|
prog_inner = GL.createProgram("""!!FP1.0 |
72 |
|
# f[TEX0].xy texture coordinates |
73 |
|
# f[TEX2].xy texture HI and LO component weights |
74 |
|
# f[TEX2].w displacement (added to the weighted texture value) |
75 |
|
|
76 |
|
# Read texture |
77 |
|
TEX R0, f[TEX0], TEX0, 2D; |
78 |
|
|
79 |
|
# Weight, add displacement, and use as output color |
80 |
|
DP4 o[COLR], R0, f[TEX2]; |
81 |
|
END |
82 |
|
""") |
83 |
|
|
84 |
code = """!!FP1.0 |
code = """!!FP1.0 |
85 |
# Inputs: |
# Inputs: |
86 |
# f[TEX0].xy texture coordinates |
# f[TEX0].xy texture coordinates |
|
# f[TEX0].z displacement |
|
87 |
# f[TEX1].xy one-pixel difference of texcoords in the 1D slice |
# f[TEX1].xy one-pixel difference of texcoords in the 1D slice |
88 |
# f[TEX1].z one-pixel difference of displacement |
# f[TEX1].w one-pixel difference of displacement |
89 |
|
|
90 |
# Read texture and add dh[0] value multiplied by R0.z |
# f[TEX2].xy texture HI and LO component weights |
91 |
TEX R1, f[TEX0], TEX0, 2D; |
# f[TEX2].w displacement (added to the weighted texture value) |
92 |
MAD R1, %s, f[TEX1].z, R1; |
|
93 |
|
# Read texture, weight, and add displacement |
94 |
|
TEX R0, f[TEX0], TEX0, 2D; |
95 |
|
DP4 R0, R0, f[TEX2]; |
96 |
|
|
97 |
|
# Add dh[0] value multiplied by f[TEX1].w |
98 |
|
MAD R0, %s, f[TEX1].w, R0; |
99 |
|
|
100 |
MOV R2, f[TEX0]; |
MOV R2, f[TEX0]; |
101 |
MOV R3, f[TEX0]; |
MOV R3, f[TEX0]; |
103 |
|
|
104 |
for i in range(1,len(dh)): |
for i in range(1,len(dh)): |
105 |
code += """ |
code += """ |
106 |
# Read texture at +/- r and take the maximum |
# Read texture at +/- r |
107 |
ADD R2, R2, f[TEX1]; |
ADD R2, R2, f[TEX1]; |
108 |
ADD R3, R3, -f[TEX1]; |
ADD R3, R3, -f[TEX1]; |
109 |
TEX R4, R2, TEX0, 2D; |
TEX R4, R2, TEX0, 2D; |
110 |
TEX R5, R3, TEX0, 2D; |
TEX R5, R3, TEX0, 2D; |
111 |
|
|
112 |
|
# Weight, add displacement, and take the maximum |
113 |
|
DP4 R4, R4, f[TEX2]; |
114 |
|
DP4 R5, R5, f[TEX2]; |
115 |
MAX R4, R4, R5; |
MAX R4, R4, R5; |
116 |
""" |
""" |
117 |
|
|
118 |
if dh[i]: |
if dh[i]: |
119 |
code += """ |
code += """ |
120 |
# Add dh[r] value multiplied by f[TEX1].z |
# Add dh[r] value multiplied by f[TEX1].w |
121 |
MAD R4, %s, f[TEX1].z, R4; |
MAD R4, %s, f[TEX1].w, R4; |
122 |
""" % dh[i] |
""" % dh[i] |
123 |
|
|
124 |
code += """ |
code += """ |
125 |
# Store maximum found in R1 |
# Store the maximum found in R0 |
126 |
MAX R1, R1, R4; |
MAX R0, R0, R4; |
127 |
""" |
""" |
128 |
|
|
129 |
code += """ |
code += """ |
130 |
# Add displacement and use as output color |
MOV o[COLR], R0; |
|
ADD o[COLR], R1, f[TEX0].z; |
|
|
|
|
131 |
END |
END |
132 |
""" |
""" |
133 |
|
|
134 |
global fragprog |
prog_outer = GL.createProgram(code) |
135 |
fragprog = GL.createProgram(code) |
|
136 |
|
|
137 |
if profile == "NV_SHAD": |
|
138 |
|
texenv_inner = """ |
139 |
|
BindProgramNV FRAGMENT_PROGRAM_NV %s |
140 |
|
Enable FRAGMENT_PROGRAM_NV |
141 |
|
""" % prog_inner.getProgId() |
142 |
|
|
143 |
|
texenv_outer = """ |
144 |
|
BindProgramNV FRAGMENT_PROGRAM_NV %s |
145 |
|
Enable FRAGMENT_PROGRAM_NV |
146 |
|
""" % prog_outer.getProgId() |
147 |
|
|
148 |
|
|
149 |
|
alphalevel = 1 |
150 |
|
w0,w1 = 1,1 |
151 |
|
def colmap0(dotvec): return (1,1,1) |
152 |
|
def colmap1(dotvec): return (1,1,1) |
153 |
|
|
154 |
|
angles = 0 |
155 |
|
tex = ( getIrreguTex(2, "HILO_NV", "HILO_NV"), |
156 |
|
) |
157 |
|
|
158 |
|
elif profile == "NV_SHAD": |
159 |
print "Using 2-vector HILO displacement texture with GL_NV_texture_shader" |
print "Using 2-vector HILO displacement texture with GL_NV_texture_shader" |
160 |
|
|
161 |
using_shader = 1 |
using_shader = 1 |
549 |
] |
] |
550 |
] |
] |
551 |
|
|
552 |
|
if using_fragprog: |
553 |
|
dx = cos(angle) |
554 |
|
dy = sin(angle) |
555 |
|
|
556 |
|
m = texscale / (striplen * scale) |
557 |
|
vec = (m * (x1 - x0), |
558 |
|
m * (y1 - y0), |
559 |
|
0, |
560 |
|
1.0 / (scale * ripple_scale * texscale), |
561 |
|
) |
562 |
|
|
563 |
|
texcoords += [ [ vec, vec, vec, vec, ], |
564 |
|
[ (dx,dy,0,1.5-.5*(dx+dy)), |
565 |
|
(dx,dy,0,.5-.5*(dx+dy)), |
566 |
|
(dx,dy,0,1.5-.5*(dx+dy)), |
567 |
|
(dx,dy,0,.5-.5*(dx+dy)), |
568 |
|
] |
569 |
|
] |
570 |
|
|
571 |
vec = [ 0 for i in range(0, angles) ] |
vec = [ 0 for i in range(0, angles) ] |
572 |
|
|
573 |
if angles: |
if angles: |
762 |
vs.map.put(getDListNocoords("ActiveTexture TEXTURE2")) |
vs.map.put(getDListNocoords("ActiveTexture TEXTURE2")) |
763 |
vs.map.put(GLRen.createTextureMatrix(), cs4) |
vs.map.put(GLRen.createTextureMatrix(), cs4) |
764 |
vs.map.put(getDListNocoords("ActiveTexture TEXTURE0")) |
vs.map.put(getDListNocoords("ActiveTexture TEXTURE0")) |
765 |
elif using_shader: |
elif using_shader or using_fragprog: |
766 |
vs.map.put(getDListNocoords(""" |
vs.map.put(getDListNocoords(""" |
767 |
ActiveTexture TEXTURE2 |
ActiveTexture TEXTURE2 |
768 |
PushAttrib TRANSFORM_BIT |
PushAttrib TRANSFORM_BIT |