gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx demo/texturelab.py libtexture/TubeFrame...


From: Tuomas J. Lukka
Subject: [Gzz-commits] gzz/gfx demo/texturelab.py libtexture/TubeFrame...
Date: Thu, 05 Sep 2002 07:19:33 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Tuomas J. Lukka <address@hidden>        02/09/05 07:19:33

Modified files:
        gfx/demo       : texturelab.py 
        gfx/libtexture : TubeFrame.texture 
        gfx/libutil    : Perlin.hxx 

Log message:
        Now the frame is getting to look more like it should

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/texturelab.py.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libtexture/TubeFrame.texture.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/Perlin.hxx.diff?tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: gzz/gfx/demo/texturelab.py
diff -c gzz/gfx/demo/texturelab.py:1.9 gzz/gfx/demo/texturelab.py:1.10
*** gzz/gfx/demo/texturelab.py:1.9      Thu Sep  5 05:49:52 2002
--- gzz/gfx/demo/texturelab.py  Thu Sep  5 07:19:32 2002
***************
*** 8,32 ****
  def js(list):
      return " ".join([str(el) for el in list])
  
  
  t = {
!  "tfamb": ( 256, 256, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
!     "TubeFrame", ["light", "ambient" ]),
!  "tfdiff": ( 256, 256, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
!     "TubeFrame", ["light", "diffuse" ]),
!  "tfspec": ( 256, 256, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
!     "TubeFrame", ["light", "specular" ]),
  }
  
  curtex = [
      "tfamb", "tfdiff", "tfspec"
  ]
  
! shaded = { }
  
! def shadedquad(color, tex):
      return getDList("""
-               Color %(color)s
                BindTexture TEXTURE_2D %(tex)s
                  TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
                Enable TEXTURE_2D
--- 8,42 ----
  def js(list):
      return " ".join([str(el) for el in list])
  
+ lpars = [
+     "spec_low", "0.95",
+     "spec_high", "1.0",
+     "shadowlen", "0.1",
+     "lx", "-0.5",
+     "ly", "0.4",
+     "npredger", "0.1",
+ ]
  
+ scal = 1024
  t = {
!  "tfamb": ( scal, scal, 0, 2, "LUMINANCE_ALPHA", "LUMINANCE_ALPHA",
!     "TubeFrame", ["light", "ambient" ] + lpars),
!  "tfdiff": ( scal, scal, 0, 2, "INTENSITY", "LUMINANCE_ALPHA",
!     "TubeFrame", ["light", "diffuse" ] + lpars),
!  "tfspec": ( scal, scal, 0, 2, "INTENSITY", "LUMINANCE_ALPHA",
!     "TubeFrame", ["light", "specular" ] + lpars),
  }
  
  curtex = [
      "tfamb", "tfdiff", "tfspec"
  ]
  
! if not locals().has_key("shaded"):
!     print "Reset shaded"
!     shaded = { }
  
! def shadedquad(tex):
      return getDList("""
                BindTexture TEXTURE_2D %(tex)s
                  TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
                Enable TEXTURE_2D
***************
*** 42,70 ****
                End
            """ % {
                "tex" : tex.getTexId(),
-               "color" : js(color),
                })
  
  class ShaderScene:
      def __init__(self):
        self.shade()
      def key(self, k):
        if k == "s":
            retexture()
              self.shade()
            AbstractUpdateManager.setNoAnimation()
!       if k == "c":
!           rotate(self.colors)
      def shade(self):
-       self.t = []
        for texname in curtex:
!           texture = GZZGL.createTexture()
!           apply(texture.shade, t[texname])
!           self.t.append(texture)
  
      def scene(self, vs):
  
!       putnoc(vs, background((1.0,0.5,0.5)))
  
        putnoc(vs, getDList("""
            PushAttrib POLYGON_BIT ENABLE_BIT
--- 52,83 ----
                End
            """ % {
                "tex" : tex.getTexId(),
                })
  
  class ShaderScene:
      def __init__(self):
        self.shade()
+       self.s0 = [50, 400, 800, 1000, 1050]
      def key(self, k):
        if k == "s":
+           global shaded
+           shaded = { }
            retexture()
              self.shade()
            AbstractUpdateManager.setNoAnimation()
!       elif k == "z":
!           rotatelist(self.s0)
      def shade(self):
        for texname in curtex:
!           if not shaded.has_key(texname):
!               print "Shade: no key ",texname
!               texture = GZZGL.createTexture()
!               apply(texture.shade, t[texname])
!               shaded[texname] = texture
  
      def scene(self, vs):
  
!       putnoc(vs, background((0.5,0.5,0.5)))
  
        putnoc(vs, getDList("""
            PushAttrib POLYGON_BIT ENABLE_BIT
***************
*** 73,88 ****
            Enable BLEND
            BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA
            Disable TEXTURE_3D
        """))
  
-       print "T: ",self.t
-       s = shadedquad("1 0 0 1", self.t[0]);
-       print s
-       vs.put(s, "0", 10, 0, 0, 500, 500);
-       vs.put(shadedquad("1 0 0 1", self.t[1]),
-           "1", 10, 0, 500, 500,500);
-       vs.put(shadedquad("1 0 0 1", self.t[2]),
-           "2", 10, 500, 000, 500,500);
  
        putnoc(vs, getDList("""
            PopAttrib
--- 86,120 ----
            Enable BLEND
            BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA
            Disable TEXTURE_3D
+           Color 0 1 0 1
+       """))
+       s0 = self.s0[0] 
+       s1 = 1100 - s0
+ 
+       samb = shadedquad( shaded["tfamb"]);
+       sdiff = shadedquad( shaded["tfdiff"]);
+       sspec = shadedquad( shaded["tfspec"]); 
+       vs.put(samb, "0", 10, 0, 0, s0, s0);
+       vs.put(sdiff, "1", 10, 0, 500, s0,s0);
+       vs.put(sspec, "2", 10, 500, 000, s0,s0);
+ 
+ 
+       putnoc(vs, getDList("""
+           Color 0.6 0.0 0.05 1
+       """))
+       vs.put(samb, "3", 10, s0, s0, s1, s1);
+ 
+       putnoc(vs, getDList("""
+           Color 0.2 0.5 0.7 1
+           BlendFunc ONE ONE_MINUS_SRC_ALPHA
+       """))
+       vs.put(sdiff, "4", 10, s0, s0, s1,s1);
+ 
+       putnoc(vs, getDList("""
+           Color 1.0 1.0 0.1 1
        """))
+       vs.put(sspec, "5", 10, s0, s0, s1,s1);
  
  
        putnoc(vs, getDList("""
            PopAttrib
Index: gzz/gfx/libtexture/TubeFrame.texture
diff -c gzz/gfx/libtexture/TubeFrame.texture:1.2 
gzz/gfx/libtexture/TubeFrame.texture:1.3
*** gzz/gfx/libtexture/TubeFrame.texture:1.2    Thu Sep  5 05:49:53 2002
--- gzz/gfx/libtexture/TubeFrame.texture        Thu Sep  5 07:19:32 2002
***************
*** 1,4 ****
--- 1,5 ----
  // -*-C++-*-
+ #define FPARAM(name, default) float name = params->getFloat(#name, default);
  
  #include <math.h>
  #include <string.h>
***************
*** 7,17 ****
    float irad = params->getFloat("irad", 0.9f);
    float orad = params->getFloat("orad", 0.995f);
    float tubeheight = params->getFloat("height", orad - irad);
    int power = (int)params->getFloat("power", 8);
!   float shadow = params->getFloat("shadowlen", 1);
  
    int type = 0;
!   float L[3] = { -.5, .5, 1/sqrt(2) };
    float E[3] = { 0, 0, 1 };
  
    const char *light = params->getString("light", "ambient");
--- 8,25 ----
    float irad = params->getFloat("irad", 0.9f);
    float orad = params->getFloat("orad", 0.995f);
    float tubeheight = params->getFloat("height", orad - irad);
+   FPARAM(npredger, 0.05);
    int power = (int)params->getFloat("power", 8);
!   float shadow = params->getFloat("shadowlen", 0.5);
! 
!   FPARAM(spec_low, 0.85);
!   FPARAM(spec_high, 0.9);
! 
!   FPARAM(lx, -.7);
!   FPARAM(ly, .7);
  
    int type = 0;
!   float L[3] = { lx, ly, sqrt(1 - lx*lx - ly*ly) };
    float E[3] = { 0, 0, 1 };
  
    const char *light = params->getString("light", "ambient");
***************
*** 20,26 ****
    }
    else if (strcmp(light, "specular") == 0) {
      type = 2;
!     L[0] += E[0];
      L[1] += E[1];
      L[2] += E[2];
      float m = 1 / sqrt(L[0] * L[0] + L[1] * L[1] + L[2] * L[2]);
--- 28,34 ----
    }
    else if (strcmp(light, "specular") == 0) {
      type = 2;
!     L[0] += E[0]; // Eye vector
      L[1] += E[1];
      L[2] += E[2];
      float m = 1 / sqrt(L[0] * L[0] + L[1] * L[1] + L[2] * L[2]);
***************
*** 45,55 ****
--- 53,69 ----
        float dot = 0;
        float alpha = r >= 0 && r <= 1;
  
+       float nprforce = 0;
+ 
        float a = (rad - irad) * sqrt(width * height) * .5;
        float b = (orad - rad) * sqrt(width * height) * .5;
        if (a > -.5 && a < .5) alpha = a + .5;
        if (b > -.5 && b < .5) alpha = b + .5;
  
+       if(r >= 0 && r <= 1 &&
+         (r <= 0 + npredger || r >= 1 - npredger)) {
+           nprforce = 1;
+       }
  
        if (type) {
        if (r > 0 && r < 1) {
***************
*** 61,68 ****
--- 75,90 ----
          
          float pos0[2] = {x*128,y*128}, der0[2];
          float pos2[2] = {x*32,y*32}, der2[2];
+ 
+         der0[0] = 0;
+         der0[1] = 0;
+         der2[0] = 0;
+         der2[1] = 0;
+ 
+         /*
          Perlin::noise2(pos0, der0);
          Perlin::noise2(pos2, der2);
+         */
  
          float dx = rad_x * dh + .1*der0[0] + .05*der2[0];
          float dy = rad_y * dh + .1*der0[1] + .05*der2[1];
***************
*** 78,86 ****
--- 100,112 ----
          if (dot < 0) dot = 0;
  
          if (type == 2) {
+           dot = Perlin::smooth_step(dot, spec_low, spec_high);
+           /* Too photorealistic
            for (int p = power; p >>= 1; )
              dot *= dot;
+           */
          }
+         if(nprforce) dot = 0;
        } 
        } else {
        float x_ = x + L[0] * tubeheight / L[2] * shadow;
***************
*** 91,96 ****
--- 117,123 ----
        float r2 = (rad - irad) / (orad - irad);
        
        dot = alpha;
+       if(nprforce) dot = 0;
        if (alpha < 1 && r2 >= r && r2 <= 1)
          {
            float t = 1 - r2;
Index: gzz/gfx/libutil/Perlin.hxx
diff -c gzz/gfx/libutil/Perlin.hxx:1.3 gzz/gfx/libutil/Perlin.hxx:1.4
*** gzz/gfx/libutil/Perlin.hxx:1.3      Tue Aug 20 05:58:08 2002
--- gzz/gfx/libutil/Perlin.hxx  Thu Sep  5 07:19:33 2002
***************
*** 39,43 ****
--- 39,52 ----
          float par[3] = {arg1, arg2, arg3};
          return noise3(par); 
      }
+ 
+     inline float smooth_step(float t) {
+       if(t <= 0) return 0;
+       if(t >= 1) return 1;
+       return ( t * t * (3. - 2. * t) );
+     }
+     inline float smooth_step(float t, float low, float high) {
+       return smooth_step( (t-low) / (high-low) );
+     }
  }
  #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]