37 |
if GL.hasExtension("GL_EXT_texture_env_dot3"): |
if GL.hasExtension("GL_EXT_texture_env_dot3"): |
38 |
profiles.append("DOT3") |
profiles.append("DOT3") |
39 |
|
|
40 |
profiles.append("STD") |
profiles.append("STD_MULTIPASS") |
41 |
|
profiles.append("STD_CONSTD") |
42 |
profiles.append("STD_4") |
profiles.append("STD_4") |
43 |
|
|
44 |
def getIrreguTex(components, iformat, format, scale = 1, bias = 0, angle = 0, angles = 0, invert = 0): |
def getIrreguTex(components, iformat, format, scale = 1, bias = 0, angle = 0, angles = 0, invert = 0): |
74 |
using_secondary_color = 0 |
using_secondary_color = 0 |
75 |
using_multitex = 0 |
using_multitex = 0 |
76 |
|
|
77 |
|
print "Using profile:", profile |
78 |
|
|
79 |
if profile == "NV_PROG": |
if profile == "NV_PROG": |
80 |
|
print "Using 2-vector HILO displacement texture with GL_NV_fragment_program" |
81 |
using_fragprog = 1 |
using_fragprog = 1 |
82 |
|
|
83 |
radius = 2 |
radius = 2 |
84 |
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) ] |
85 |
|
|
86 |
|
global prog_inner, prog_outer |
87 |
|
|
88 |
prog_inner = GL.createProgram("""!!FP1.0 |
prog_inner = GL.createProgram("""!!FP1.0 |
89 |
# f[TEX0].xyw texture coordinates |
# f[TEX0].xyw texture coordinates |
90 |
# f[TEX2].xy texture HI and LO component weights |
# f[TEX2].xy texture HI and LO component weights |
382 |
getIrreguTex(4, "RGBA", "RGBA", scale = .25, bias = .75, angles = 3, invert = 1), |
getIrreguTex(4, "RGBA", "RGBA", scale = .25, bias = .75, angles = 3, invert = 1), |
383 |
) |
) |
384 |
|
|
385 |
elif profile == "STD" or profile == "STD_4": |
elif profile == "STD_MULTIPASS" or profile == "STD_CONSTD" or profile == "STD_4": |
386 |
print "Using full displacement resolution texture with standard GL (texture_env_add)" |
print "Using full displacement resolution texture with standard GL (texture_env_add)" |
387 |
|
|
388 |
texenv = """ |
texenv = """ |
433 |
global scaling |
global scaling |
434 |
scaling = scalings[int(k) - 1] |
scaling = scalings[int(k) - 1] |
435 |
init() |
init() |
436 |
elif "F1" <= k <= "F12": |
elif "F1" <= k <= "F9": |
437 |
global profile |
global profile |
438 |
profile = profiles[int(k[1]) - 1] |
profile = profiles[int(k[1]) - 1] |
439 |
init() |
init() |
511 |
Enable TEXTURE_2D |
Enable TEXTURE_2D |
512 |
""" % locals() |
""" % locals() |
513 |
|
|
514 |
|
# One-pixel difference of displacement |
515 |
|
borderalpha = 1.0 / (scale * ripple_scale * texscale) |
516 |
|
|
517 |
if using_multitex and outer: |
if using_multitex and outer: |
518 |
# XXX: scaling doesn't work properly because the coordinate |
# XXX: scaling doesn't work properly because the coordinate |
519 |
# transformation is not known here |
# transformation is not known here |
522 |
# alpha: value added to the displacement values |
# alpha: value added to the displacement values |
523 |
# blue: value added to the middle displacement (in addition to alpha) |
# blue: value added to the middle displacement (in addition to alpha) |
524 |
m = 1.0 / (striplen * scale) |
m = 1.0 / (striplen * scale) |
525 |
alpha = 1.5 / (scale * ripple_scale * texscale) |
alpha = 1.5 * borderalpha |
526 |
blue = 1.0 / (scale * ripple_scale * texscale) |
blue = 1.0 * borderalpha |
527 |
|
|
528 |
#print m*scale,alpha*256,blue*256 |
#print m*scale,alpha*256,blue*256 |
529 |
|
|
579 |
dx = cos(angle) |
dx = cos(angle) |
580 |
dy = sin(angle) |
dy = sin(angle) |
581 |
|
|
|
m = 1.0 / (striplen * scale) |
|
582 |
# Note: dx,dy below are applied after texture matrix |
# Note: dx,dy below are applied after texture matrix |
583 |
vec = (dx / scale, |
vec = (dx / scale, |
584 |
dy / scale, |
dy / scale, |
585 |
0, |
0, |
586 |
1.0 / (scale * ripple_scale * texscale), |
borderalpha, |
587 |
) |
) |
588 |
|
|
589 |
texcoords += [ [ vec, vec, vec, vec, ], |
texcoords += [ [ vec, vec, vec, vec, ], |
635 |
ActiveTexture TEXTURE0 |
ActiveTexture TEXTURE0 |
636 |
""" % edgelodbias |
""" % edgelodbias |
637 |
|
|
638 |
|
|
639 |
if alphalevel: |
if alphalevel: |
640 |
|
da = (profile == "STD_CONSTD") * outer * borderalpha * 3 |
641 |
|
|
642 |
code += """ |
code += """ |
643 |
Enable ALPHA_TEST |
Enable ALPHA_TEST |
644 |
AlphaFunc LESS %s |
AlphaFunc LESS %s |
645 |
""" % alphalevel |
""" % (alphalevel - da) |
646 |
|
|
647 |
if outer: |
if outer: |
648 |
code += texenv_outer % locals() |
code += texenv_outer % locals() |
812 |
self.initIrregu() |
self.initIrregu() |
813 |
|
|
814 |
if self.use_stencil: |
if self.use_stencil: |
815 |
if texenv_inner == texenv_outer and angles == 0: |
if profile == "STD_MULTIPASS": |
816 |
vs.map.put(getDListNocoords("PushMatrix\n" |
vs.map.put(getDListNocoords("PushMatrix\n" |
817 |
"Translate -2 0 0")) |
"Translate -2 0 0")) |
818 |
vs.map.put(self.stencil_init) |
vs.map.put(self.stencil_init) |