7 |
lodbias = 0 |
lodbias = 0 |
8 |
texscale = 1 |
texscale = 1 |
9 |
use_texture = 0 |
use_texture = 0 |
10 |
|
use_stencil = 1 |
11 |
|
|
12 |
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", |
13 |
"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" ] |
16 |
|
|
17 |
|
|
18 |
if (GL.hasExtension("GL_NV_texture_shader")): |
if (GL.hasExtension("GL_NV_texture_shader")): |
19 |
#profiles.append("NV_SHAD") |
profiles.append("NV_SHAD") |
|
pass |
|
20 |
|
|
21 |
if (GL.hasExtension("GL_NV_register_combiners") and |
if (GL.hasExtension("GL_NV_register_combiners") and |
22 |
GL.hasExtension("GL_EXT_secondary_color")): |
GL.hasExtension("GL_EXT_secondary_color")): |
31 |
global tex, texinv |
global tex, texinv |
32 |
global texenv_inner, texenv_outer, alphalevel, w0, w1 |
global texenv_inner, texenv_outer, alphalevel, w0, w1 |
33 |
global colmap0, colmap1 |
global colmap0, colmap1 |
34 |
|
global using_shader |
35 |
|
|
36 |
|
using_shader = 0 |
37 |
|
|
38 |
if profile == "NV_SHAD": |
if profile == "NV_SHAD": |
39 |
print "Using 2-vector HILO displacement texture with GL_NV_texture_shader" |
print "Using 2-vector HILO displacement texture with GL_NV_texture_shader" |
40 |
|
|
41 |
|
using_shader = 1 |
42 |
|
global use_stencil |
43 |
|
use_stencil = 0 |
44 |
|
edgetex = getCachedTexture([1, 1024, 0, 4, "RGBA", "RGBA", |
45 |
|
"irreguedge", ["line_width", "100"]], shade_all_levels = 1) |
46 |
|
|
47 |
texenv_inner = """ |
texenv_inner = """ |
48 |
|
Enable TEXTURE_SHADER_NV |
49 |
|
|
50 |
|
TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV TEXTURE_2D |
51 |
|
|
52 |
|
ActiveTexture TEXTURE1 |
53 |
|
TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV DOT_PRODUCT_NV |
54 |
TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0 |
TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0 |
|
""" |
|
55 |
|
|
56 |
alphalevel = 1 |
ActiveTexture TEXTURE2 |
57 |
|
TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV DOT_PRODUCT_TEXTURE_2D_NV |
58 |
|
TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0 |
59 |
|
|
60 |
|
BindTexture TEXTURE_2D %s |
61 |
|
Enable TEXTURE_2D |
62 |
|
TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR |
63 |
|
TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR |
64 |
|
TexParameter TEXTURE_2D TEXTURE_WRAP_S REPEAT |
65 |
|
TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP |
66 |
|
|
67 |
|
ActiveTexture TEXTURE0 |
68 |
|
|
69 |
|
Disable ALPHA_TEST |
70 |
|
""" % edgetex.getTexId() |
71 |
|
|
72 |
|
texenv_outer = texenv_inner |
73 |
|
|
74 |
|
alphalevel = None |
75 |
w0,w1 = 1,1 |
w0,w1 = 1,1 |
76 |
def colmap0(dotvec): return (1,1,1) |
def colmap0(dotvec): return (1,1,1) |
77 |
def colmap1(dotvec): return (0,0,0) |
def colmap1(dotvec): return (1,1,1) |
78 |
|
|
79 |
tex_scale = 1 |
tex_scale = 1 |
80 |
tex_bias = 0 |
tex_bias = 0 |
81 |
tex_format = [ 2, "HILO", "HILO" ] |
tex_format = [ 2, "HILO_NV", "HILO_NV" ] |
|
|
|
82 |
|
|
83 |
if profile == "NV_COMB": |
elif profile == "NV_COMB": |
84 |
print "Using full displacement resolution textures with GL_NV_register_combiners" |
print "Using full displacement resolution textures with GL_NV_register_combiners" |
85 |
|
|
86 |
from gfx.libutil.nvcode import combinercode |
from gfx.libutil.nvcode import combinercode |
159 |
|
|
160 |
texenv = """ |
texenv = """ |
161 |
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD |
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD |
162 |
|
Enable ALPHA_TEST |
163 |
|
AlphaFunc LESS 1 |
164 |
""" |
""" |
165 |
texenv_inner = texenv |
texenv_inner = texenv |
166 |
texenv_outer = texenv |
texenv_outer = texenv |
201 |
elif k == "t": |
elif k == "t": |
202 |
global use_texture |
global use_texture |
203 |
use_texture = not use_texture |
use_texture = not use_texture |
204 |
|
elif k == "i": |
205 |
|
global use_stencil |
206 |
|
use_stencil = not use_stencil |
207 |
global lodbias |
global lodbias |
208 |
if k == "b": lodbias += .25; print "lodbias", lodbias |
if k == "b": lodbias += .25; print "lodbias", lodbias |
209 |
elif k == "B": lodbias -= .25; print "lodbias", lodbias |
elif k == "B": lodbias -= .25; print "lodbias", lodbias |
225 |
|
|
226 |
def getIrregu(invert, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0): |
def getIrregu(invert, x0, y0, x1, y1, outer = 0, texscale = 1, texangle = 0): |
227 |
|
|
228 |
if invert: |
if invert and not using_shader: |
229 |
texid = texinv.getTexId() |
texid = texinv.getTexId() |
230 |
else: |
else: |
231 |
texid = tex.getTexId() |
texid = tex.getTexId() |
232 |
|
|
233 |
len = sqrt((x1 - x0)**2 + (y1 - y0)**2) |
striplen = sqrt((x1 - x0)**2 + (y1 - y0)**2) |
234 |
|
|
235 |
m = 0.5 * ripple_scale * texscale / len |
m = 0.5 * ripple_scale * texscale / striplen |
236 |
nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90 |
nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90 |
237 |
|
|
238 |
vertices = [ |
vertices = [ vecmul(vecsub((x0,y0,0,1),nvec), w0), |
239 |
vecmul(vecsub((x0,y0,0,1),nvec), w0), |
vecmul(vecadd((x0,y0,0,1),nvec), w1), |
240 |
vecmul(vecadd((x0,y0,0,1),nvec), w1), |
vecmul(vecsub((x1,y1,0,1),nvec), w0), |
241 |
vecmul(vecsub((x1,y1,0,1),nvec), w0), |
vecmul(vecadd((x1,y1,0,1),nvec), w1) |
242 |
vecmul(vecadd((x1,y1,0,1),nvec), w1) |
] |
243 |
] |
|
244 |
|
texcoords = [ [ vecmul((x0,y0,0,texscale), w0), |
245 |
texcoords = [ |
vecmul((x0,y0,0,texscale), w1), |
246 |
vecmul((x0,y0,0,texscale), w0), |
vecmul((x1,y1,0,texscale), w0), |
247 |
vecmul((x0,y0,0,texscale), w1), |
vecmul((x1,y1,0,texscale), w1) |
248 |
vecmul((x1,y1,0,texscale), w0), |
] |
249 |
vecmul((x1,y1,0,texscale), w1) |
] |
|
] |
|
|
|
|
|
#print "Vertices:" |
|
|
#print vert0, tex0 |
|
|
#print vert1, tex1 |
|
|
#print vert2, tex2 |
|
|
#print vert3, tex3 |
|
250 |
|
|
251 |
angle = atan2(y1 - y0, x1 - x0) - texangle |
angle = atan2(y1 - y0, x1 - x0) - texangle |
252 |
|
|
253 |
dx = str(cos(angle)) |
dx = cos(angle) |
254 |
dy = str(sin(angle)) |
dy = sin(angle) |
255 |
|
|
256 |
|
if using_shader: |
257 |
|
texcoords += [ [ (0, 0, 0), |
258 |
|
(0, 0, 0), |
259 |
|
(0, 0, striplen / texscale*1024), |
260 |
|
(0, 0, striplen / texscale*1024), |
261 |
|
], |
262 |
|
[ (dx,dy,0-.5*(dx+dy)), |
263 |
|
(dx,dy,1-.5*(dx+dy)), |
264 |
|
(dx,dy,0-.5*(dx+dy)), |
265 |
|
(dx,dy,1-.5*(dx+dy)), |
266 |
|
] |
267 |
|
] |
268 |
|
|
269 |
if outer: |
if outer: |
270 |
a = angle * 6 / (2 * pi) |
a = angle * 6 / (2 * pi) |
279 |
|
|
280 |
dotvec = js(vec) |
dotvec = js(vec) |
281 |
|
|
282 |
cols = [ |
cols = [ colmap0(vec), |
283 |
colmap0(vec), |
colmap1(vec), |
284 |
colmap1(vec), |
colmap0(vec), |
285 |
colmap0(vec), |
colmap1(vec) |
286 |
colmap1(vec) |
] |
|
] |
|
287 |
|
|
288 |
code = """ |
code = """ |
289 |
PushAttrib ENABLE_BIT TEXTURE_BIT |
PushAttrib ENABLE_BIT TEXTURE_BIT |
299 |
TexEnv TEXTURE_FILTER_CONTROL_EXT TEXTURE_LOD_BIAS_EXT %s |
TexEnv TEXTURE_FILTER_CONTROL_EXT TEXTURE_LOD_BIAS_EXT %s |
300 |
""" % lodbias |
""" % lodbias |
301 |
|
|
302 |
|
if use_stencil: |
303 |
|
code += """ |
304 |
|
# Create edge stencil |
305 |
|
ColorMask 0 0 0 0 |
306 |
|
StencilMask 255 |
307 |
|
Enable STENCIL_TEST |
308 |
|
StencilFunc ALWAYS 0 255 |
309 |
|
StencilOp INCR INCR INCR |
310 |
|
""" |
311 |
|
|
312 |
|
if alphalevel: |
313 |
|
code += """ |
314 |
|
Enable ALPHA_TEST |
315 |
|
AlphaFunc LESS %s |
316 |
|
""" % alphalevel |
317 |
|
|
318 |
if outer: |
if outer: |
319 |
code += texenv_outer % locals() |
code += texenv_outer % locals() |
320 |
else: |
else: |
326 |
Translate %s |
Translate %s |
327 |
""" % js(vecmul(nvec[:3], 24. / scale)) |
""" % js(vecmul(nvec[:3], 24. / scale)) |
328 |
|
|
|
alpha = alphalevel |
|
|
code += """ |
|
|
# Create edge stencil |
|
329 |
|
|
330 |
Enable ALPHA_TEST |
code += """ |
|
AlphaFunc LESS %(alpha)s |
|
|
ColorMask 0 0 0 0 |
|
|
|
|
|
StencilMask 255 |
|
|
Enable STENCIL_TEST |
|
|
StencilFunc ALWAYS 0 255 |
|
|
StencilOp INCR INCR INCR |
|
|
|
|
331 |
Begin QUAD_STRIP |
Begin QUAD_STRIP |
332 |
""" % locals() |
""" % locals() |
333 |
|
|
335 |
code += """ |
code += """ |
336 |
Color %s |
Color %s |
337 |
TexCoord %s |
TexCoord %s |
338 |
|
""" % (js(cols[i]), js(texcoords[0][i])) |
339 |
|
|
340 |
|
for u in range(1,len(texcoords)): |
341 |
|
code += """ |
342 |
|
MultiTexCoord TEXTURE%s %s |
343 |
|
""" % (u, js(texcoords[u][i])) |
344 |
|
|
345 |
|
code += """ |
346 |
Vertex %s |
Vertex %s |
347 |
""" % (js(cols[i]), js(texcoords[i]), js(vertices[i])) |
""" % js(vertices[i]) |
348 |
|
|
349 |
code += """ |
code += """ |
350 |
End |
End |
351 |
|
|
352 |
ColorMask 1 1 1 1 |
ColorMask 1 1 1 1 |
|
Disable STENCIL_TEST |
|
353 |
PopAttrib |
PopAttrib |
354 |
""" |
""" |
355 |
|
|
358 |
PopMatrix |
PopMatrix |
359 |
""" |
""" |
360 |
|
|
361 |
|
#print code |
362 |
|
|
363 |
return code |
return code |
364 |
|
|
365 |
class IrreguScene: |
class IrreguScene: |
402 |
tex2d = "Enable" |
tex2d = "Enable" |
403 |
else: |
else: |
404 |
tex2d = "Disable" |
tex2d = "Disable" |
405 |
|
|
406 |
paint = """ |
if use_stencil: |
407 |
|
paint = """ |
408 |
PushAttrib ENABLE_BIT |
PushAttrib ENABLE_BIT |
409 |
Enable STENCIL_TEST |
Enable STENCIL_TEST |
410 |
Disable ALPHA_TEST |
Disable ALPHA_TEST |
426 |
Vertex %(x1)s %(y1)s |
Vertex %(x1)s %(y1)s |
427 |
End |
End |
428 |
PopAttrib |
PopAttrib |
429 |
""" % locals() |
""" % locals() |
430 |
|
else: |
431 |
|
paint = """ |
432 |
|
""" |
433 |
|
|
434 |
vs.map.put(getDListNocoords(""" |
vs.map.put(getDListNocoords(""" |
435 |
PushMatrix |
PushMatrix |
437 |
MultMatrix %s |
MultMatrix %s |
438 |
""" % matrices[0])) |
""" % matrices[0])) |
439 |
|
|
440 |
vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,1, texscale, self.angle) + |
if not using_shader: |
441 |
getIrregu(0,+1,y0,+1,y1,1, texscale, self.angle) + |
vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,1, texscale, self.angle) + |
442 |
getIrregu(1,x1,+1,x0,+1,1, texscale, self.angle) + |
getIrregu(0,+1,y0,+1,y1,1, texscale, self.angle) + |
443 |
getIrregu(1,-1,y1,-1,y0,1, texscale, self.angle) + |
getIrregu(1,x1,+1,x0,+1,1, texscale, self.angle) + |
444 |
"Color 0 0 0" + paint), cs3) |
getIrregu(1,-1,y1,-1,y0,1, texscale, self.angle) + |
445 |
|
"Color 0 0 0" + paint), cs3) |
446 |
|
|
447 |
vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,0, texscale, self.angle) + |
vs.map.put(getDList(getIrregu(0,x0,-1,x1,-1,0, texscale, self.angle) + |
448 |
getIrregu(0,+1,y0,+1,y1,0, texscale, self.angle) + |
getIrregu(0,+1,y0,+1,y1,0, texscale, self.angle) + |