[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture |
Date: |
Fri, 25 Oct 2002 08:53:39 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/10/25 08:53:38
Modified files:
gfx/demo : irregu3.py
gfx/libtexture : irregu.texture
Log message:
More framework for texture shading version of irregu3
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregu3.py.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libtexture/irregu.texture.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
Patches:
Index: gzz/gfx/demo/irregu3.py
diff -u gzz/gfx/demo/irregu3.py:1.21 gzz/gfx/demo/irregu3.py:1.22
--- gzz/gfx/demo/irregu3.py:1.21 Fri Oct 25 06:39:06 2002
+++ gzz/gfx/demo/irregu3.py Fri Oct 25 08:53:38 2002
@@ -13,9 +13,14 @@
profiles = []
+
+if (GL.hasExtension("GL_NV_texture_shader")):
+ #profiles.append("NV_SHAD")
+ pass
+
if (GL.hasExtension("GL_NV_register_combiners") and
GL.hasExtension("GL_EXT_secondary_color")):
- profiles.append("NV")
+ profiles.append("NV_COMB")
if GL.hasExtension("GL_EXT_texture_env_dot3"):
profiles.append("DOT3")
@@ -26,9 +31,24 @@
global tex, texinv
global texenv_inner, texenv_outer, alphalevel, w0, w1
global colmap0, colmap1
-
- if profile == "NV":
+ if profile == "NV_SHAD":
+ print "Using 2-vector HILO displacement texture with
GL_NV_texture_shader"
+ texenv_inner = """
+ TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE0
+ """
+
+ alphalevel = 1
+ w0,w1 = 1,1
+ def colmap0(dotvec): return (1,1,1)
+ def colmap1(dotvec): return (0,0,0)
+
+ tex_scale = 1
+ tex_bias = 0
+ tex_format = [ 2, "HILO", "HILO" ]
+
+
+ if profile == "NV_COMB":
print "Using full displacement resolution textures with
GL_NV_register_combiners"
from gfx.libutil.nvcode import combinercode
@@ -71,8 +91,8 @@
alphalevel = 1
w0,w1 = 1,1
- def colmap0(dotvec): return "1 1 1"
- def colmap1(dotvec): return "0 0 0"
+ def colmap0(dotvec): return (1,1,1)
+ def colmap1(dotvec): return (0,0,0)
tex_scale = 1
tex_bias = 0
@@ -95,8 +115,8 @@
alphalevel = .5
w0,w1 = 1,.5
- def colmap0(dotvec): return js([.5 + .5 * c for c in dotvec])
- def colmap1(dotvec): return js([.5 + .25 * c for c in dotvec])
+ def colmap0(dotvec): return [.5 + .5 * c for c in dotvec]
+ def colmap1(dotvec): return [.5 + .25 * c for c in dotvec]
tex_scale = .25
tex_bias = .75
@@ -113,8 +133,8 @@
alphalevel = 1
w0,w1 = 1,1
- def colmap0(dotvec): return "1 1 1 1"
- def colmap1(dotvec): return "0 0 0 0"
+ def colmap0(dotvec): return (1,1,1,1)
+ def colmap1(dotvec): return (0,0,0,0)
tex_scale = 1
tex_bias = 0
@@ -178,15 +198,19 @@
m = 0.5 * ripple_scale * texscale / len
nvec = (m * (y1 - y0), -m * (x1 - x0), 0, 0) # cw90
- vert0 = js(vecmul(vecsub((x0,y0,0,1),nvec), w0))
- vert1 = js(vecmul(vecadd((x0,y0,0,1),nvec), w1))
- vert2 = js(vecmul(vecsub((x1,y1,0,1),nvec), w0))
- vert3 = js(vecmul(vecadd((x1,y1,0,1),nvec), w1))
-
- tex0 = js(vecmul((x0,y0,0,texscale), w0))
- tex1 = js(vecmul((x0,y0,0,texscale), w1))
- tex2 = js(vecmul((x1,y1,0,texscale), w0))
- tex3 = js(vecmul((x1,y1,0,texscale), w1))
+ vertices = [
+ vecmul(vecsub((x0,y0,0,1),nvec), w0),
+ vecmul(vecadd((x0,y0,0,1),nvec), w1),
+ vecmul(vecsub((x1,y1,0,1),nvec), w0),
+ vecmul(vecadd((x1,y1,0,1),nvec), w1)
+ ]
+
+ texcoords = [
+ vecmul((x0,y0,0,texscale), w0),
+ vecmul((x0,y0,0,texscale), w1),
+ vecmul((x1,y1,0,texscale), w0),
+ vecmul((x1,y1,0,texscale), w1)
+ ]
#print "Vertices:"
#print vert0, tex0
@@ -194,9 +218,12 @@
#print vert2, tex2
#print vert3, tex3
- if outer:
- angle = atan2(y1 - y0, x1 - x0) - texangle
+ angle = atan2(y1 - y0, x1 - x0) - texangle
+
+ dx = str(cos(angle))
+ dy = str(sin(angle))
+ if outer:
a = angle * 6 / (2 * pi)
while a < 0: a+=3
i = int(a) % 3
@@ -207,10 +234,15 @@
else:
vec = (1,0,0)
- col0 = colmap0(vec)
- col1 = colmap1(vec)
dotvec = js(vec)
+ cols = [
+ colmap0(vec),
+ colmap1(vec),
+ colmap0(vec),
+ colmap1(vec)
+ ]
+
code = """
PushAttrib ENABLE_BIT TEXTURE_BIT
@@ -250,30 +282,22 @@
StencilOp INCR INCR INCR
Begin QUAD_STRIP
+ """ % locals()
- Color %(col0)s
- TexCoord %(tex0)s
- Vertex %(vert0)s
-
- Color %(col1)s
- TexCoord %(tex1)s
- Vertex %(vert1)s
-
- Color %(col0)s
- TexCoord %(tex2)s
- Vertex %(vert2)s
-
- Color %(col1)s
- TexCoord %(tex3)s
- Vertex %(vert3)s
+ for i in range(0,4):
+ code += """
+ Color %s
+ TexCoord %s
+ Vertex %s
+ """ % (js(cols[i]), js(texcoords[i]), js(vertices[i]))
+ code += """
End
ColorMask 1 1 1 1
Disable STENCIL_TEST
PopAttrib
-
- """ % locals()
+ """
if outer and texenv_inner == texenv_outer:
code += """
Index: gzz/gfx/libtexture/irregu.texture
diff -u gzz/gfx/libtexture/irregu.texture:1.9
gzz/gfx/libtexture/irregu.texture:1.10
--- gzz/gfx/libtexture/irregu.texture:1.9 Fri Oct 25 04:48:12 2002
+++ gzz/gfx/libtexture/irregu.texture Fri Oct 25 08:53:38 2002
@@ -6,15 +6,6 @@
#define INVERT(i, x) ((i) + 2 * (0.5 - (i)) * (x))
-float func(float x, float y) {
- x*=2;
- y*=2;
- float t = x*5;
- float u = y*7;
- return .5 + .1 * sin(x*M_PI*2*4) - .1*(t-floor(t)) + .1*sin(y*M_PI*2)
- - .1*(u-floor(u));
-}
-
float filter(float *data, int w, int h, int c, float x, float y) {
int ix0 = (int)floor(x), ix1 = ix0 + 1;
@@ -38,6 +29,7 @@
FPARAM(scale, 1);
FPARAM(eps, .25);
FPARAM(invert, 0);
+ FPARAM(quantize, 255);
// Note: radius is specified in texels
FPARAM(radius, 2);
@@ -47,7 +39,6 @@
float *origdata = data;
if(components != 4) {
- if (components != 1) return;
data = new float[width * height * depth * 4];
}
@@ -79,23 +70,20 @@
fprintf(stderr, "\n");
}
- ind = 3;
- for (j = 0, y = 0; j < height; j++, y += ystep) {
- for (i = 0, x = 0; i < width; i++, x += xstep) {
- float f = INVERT(invert, /*func(x,y)*/data[ind]);
- if (f > 1) f = 1;
- if (f < 0) f = 0;
-
- // Scale down to make space for the border
- f *= (1 - radius / (width * ripple_scale));
- if (f < 0) f = 0;
-
- data[ind] = f * scale + bias;
-
- // Add outer edge to quantized inner edge
- data[ind] = floor(data[ind] * 255.0 + 0.5) / 255.0;
- ind += 4;
- }
+ for (i = 0; i < width * height * depth * 4; i++) {
+ float f = INVERT(invert, data[i]);
+ if (f > 1) f = 1;
+ if (f < 0) f = 0;
+
+ // Scale down to make space for the border
+ f *= (1 - radius / (width * ripple_scale));
+ if (f < 0) f = 0;
+
+ data[i] = f * scale + bias;
+
+ // Add outer edge to quantized inner edge
+ if (components == 4)
+ data[i] = floor(data[i] * quantize + 0.5) / quantize;
}
if (components == 4)
@@ -136,10 +124,10 @@
}
#endif
- if (components != 4) {
- /* components == 1 */
+ if (components < 4) {
for (int i = 0; i < width * height * depth; i++)
- origdata[i] = data[4 * i + 3];
+ for (int c = 0; c < components; c++)
+ origdata[i * components + c] = data[4 * i + 3 - c];
delete[] data;
}
}
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/21
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/21
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/21
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/21
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/22
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/25
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture,
Janne V. Kujala <=
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/28
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/29
- [Gzz-commits] gzz/gfx demo/irregu3.py libtexture/irregu.texture, Janne V. Kujala, 2002/10/29