23 |
if (GL.hasExtension("GL_NV_register_combiners") and |
if (GL.hasExtension("GL_NV_register_combiners") and |
24 |
GL.hasExtension("GL_EXT_secondary_color")): |
GL.hasExtension("GL_EXT_secondary_color")): |
25 |
profiles.append("NV_COMB") |
profiles.append("NV_COMB") |
26 |
|
profiles.append("NV_COMB4") |
27 |
|
|
28 |
if GL.hasExtension("GL_EXT_texture_env_dot3"): |
if GL.hasExtension("GL_EXT_texture_env_dot3"): |
29 |
profiles.append("DOT3") |
profiles.append("DOT3") |
30 |
|
|
31 |
profiles.append("STD") |
profiles.append("STD") |
32 |
|
|
33 |
|
def getIrreguTex(components, iformat, format, scale = 1, bias = 0, angles = 0, invert = 0): |
34 |
|
|
35 |
|
return getCachedTexture([texsize, texsize, 0, components, iformat, format, "irregu", |
36 |
|
["radius", "2", |
37 |
|
"ripple_scale", str(ripple_scale), |
38 |
|
"scale", str(scale), |
39 |
|
"bias", str(bias), |
40 |
|
"angles", str(angles), |
41 |
|
"eps", ".125", |
42 |
|
"invert", str(invert), |
43 |
|
]], |
44 |
|
shade_all_levels = 1) |
45 |
|
|
46 |
def init(profile): |
def init(profile): |
47 |
global tex, texinv |
global tex, texinv |
48 |
global texenv_inner, texenv_outer, alphalevel, w0, w1 |
global texenv_inner, texenv_outer, alphalevel, w0, w1 |
104 |
def colmap1(dotvec): return (1,1,1) |
def colmap1(dotvec): return (1,1,1) |
105 |
|
|
106 |
angles = 0 |
angles = 0 |
107 |
tex_scale = 1 |
tex = ( getIrreguTex(2, "HILO_NV", "HILO_NV"), |
108 |
tex_bias = 0 |
) |
|
tex_format = [ 2, "HILO_NV", "HILO_NV" ] |
|
109 |
|
|
110 |
elif profile == "NV_COMB": |
elif profile == "NV_COMB" or profile == "NV_COMB4": |
111 |
print "Using full displacement resolution textures with GL_NV_register_combiners" |
print "Using full displacement resolution textures with GL_NV_register_combiners" |
112 |
|
|
113 |
using_secondary_color = 1 |
using_secondary_color = 1 |
142 |
FCI G SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA |
FCI G SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA |
143 |
""") |
""") |
144 |
|
|
|
texenv_inner = texenv % "0 0 0 1" |
|
|
texenv_outer = texenv % "%(dotvec)s 0" |
|
|
|
|
145 |
alphalevel = 1 |
alphalevel = 1 |
146 |
w0,w1 = 1,1 |
w0,w1 = 1,1 |
147 |
def colmap0(dotvec): return (1,1,1) |
def colmap0(dotvec): return (1,1,1) |
148 |
def colmap1(dotvec): return (0,0,0) |
def colmap1(dotvec): return (0,0,0) |
149 |
|
|
150 |
angles = 3 |
if profile == "NV_COMB": |
151 |
tex_scale = 1 |
texenv_inner = texenv % "0 0 0 1" |
152 |
tex_bias = 0 |
texenv_outer = texenv % "%(dotvec)s 0" |
153 |
tex_format = [ 4, "RGBA", "RGBA" ] |
angles = 3 |
154 |
|
tex = ( getIrreguTex(4, "RGBA", "RGBA", angles = angles), |
155 |
|
getIrreguTex(4, "RGBA", "RGBA", angles = angles, invert = 1), |
156 |
|
) |
157 |
|
else: |
158 |
|
texenv_inner = texenv % "0 0 0 1" |
159 |
|
texenv_outer = texenv % "%(dotvec)s" |
160 |
|
angles = 4 |
161 |
|
tex = ( getIrreguTex(1, "INTENSITY", "LUMINANCE"), |
162 |
|
getIrreguTex(1, "INTENSITY", "LUMINANCE", invert = 1), |
163 |
|
getIrreguTex(4, "RGBA", "RGBA", angles = angles), |
164 |
|
getIrreguTex(4, "RGBA", "RGBA", angles = angles, invert = 1), |
165 |
|
) |
166 |
|
|
167 |
|
|
168 |
elif profile == "DOT3": |
elif profile == "DOT3": |
169 |
print "Using 1/4 displacement resolution textures with GL_EXT_texture_env_dot3" |
print "Using 1/4 displacement resolution textures with GL_EXT_texture_env_dot3" |
186 |
def colmap1(dotvec): return [.5 + .25 * c for c in dotvec] |
def colmap1(dotvec): return [.5 + .25 * c for c in dotvec] |
187 |
|
|
188 |
angles = 3 |
angles = 3 |
189 |
tex_scale = .25 |
tex = ( getIrreguTex(4, "RGBA", "RGBA", scale = .25, bias = .75, angles = 3), |
190 |
tex_bias = .75 |
getIrreguTex(4, "RGBA", "RGBA", scale = .25, bias = .75, angles = 3, invert = 1), |
191 |
tex_format = [ 4, "RGBA", "RGBA" ] |
) |
192 |
|
|
193 |
elif profile == "STD": |
elif profile == "STD": |
194 |
print "Using full displacement resolution texture with standard GL" |
print "Using full displacement resolution texture with standard GL (texture_env_add)" |
195 |
|
|
196 |
texenv = """ |
texenv = """ |
197 |
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD |
TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD |
205 |
def colmap1(dotvec): return (0,0,0,0) |
def colmap1(dotvec): return (0,0,0,0) |
206 |
|
|
207 |
angles = 0 |
angles = 0 |
208 |
tex_scale = 1 |
tex = ( getIrreguTex(1, "INTENSITY", "LUMINANCE"), |
209 |
tex_bias = 0 |
getIrreguTex(1, "INTENSITY", "LUMINANCE", invert = 1), |
210 |
tex_format = [ 1, "INTENSITY", "LUMINANCE" ] |
) |
211 |
else: |
else: |
212 |
assert(0) |
assert(0) |
213 |
|
|
214 |
|
|
215 |
args = ["radius", "2", "ripple_scale", str(ripple_scale), |
print "Using", angles, "precomputed slicing angles" |
|
"scale", str(tex_scale), "bias", str(tex_bias), |
|
|
"angles", str(angles), "eps", ".125"] |
|
|
|
|
|
|
|
|
tex = getCachedTexture([texsize, texsize, 0] + tex_format + |
|
|
["irregu", args], shade_all_levels = 1) |
|
|
texinv = getCachedTexture([texsize, texsize, 0] + tex_format + |
|
|
["irregu", args + ["invert", "1"]], |
|
|
shade_all_levels = 1) |
|
216 |
|
|
217 |
global reinit |
global reinit |
218 |
reinit = 1 |
reinit = 1 |
258 |
|
|
259 |
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): |
260 |
|
|
261 |
if invert and not using_shader: |
if len(tex) == 1: |
262 |
texid = texinv.getTexId() |
texid = tex[0].getTexId() |
263 |
|
elif len(tex) == 2: |
264 |
|
texid = tex[invert].getTexId() |
265 |
|
elif len(tex) == 4: |
266 |
|
texid = tex[invert + 2 * outer].getTexId() |
267 |
else: |
else: |
268 |
texid = tex.getTexId() |
assert(0) |
269 |
|
|
270 |
striplen = sqrt((x1 - x0)**2 + (y1 - y0)**2) |
striplen = sqrt((x1 - x0)**2 + (y1 - y0)**2) |
271 |
|
|
272 |
m = 0.5 * ripple_scale * texscale / striplen |
m = 0.5 * ripple_scale * texscale / striplen |
320 |
|
|
321 |
dotvec = js(vec) |
dotvec = js(vec) |
322 |
|
|
323 |
if not using_shader: |
if not using_shader and angles < 4: |
324 |
# Interpolate outer edge towards inner edge with NV_COMB |
# Interpolate outer edge towards inner edge with NV_COMB |
325 |
a = 2**-edgelodbias |
a = 2**-edgelodbias |
326 |
dotvec = js(vecmul(vec,a) + [1-a]) + " #" |
dotvec = js(vecmul(vec,a) + [1-a]) + " #" |