File: GVreplaceconstant.sl

package info (click to toggle)
geomview 1.9.5-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,096 kB
  • sloc: ansic: 93,696; sh: 12,051; cpp: 1,215; makefile: 1,075; objc: 263; perl: 153; yacc: 152; tcl: 76; lex: 74
file content (73 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright (C) 2007 Claus-Justus Heine
 *
 * This file is part of Geomview.
 * 
 * Geomview is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * Geomview is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Geomview; see the file COPYING.  If not, write
 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
 * USA, or visit http://www.gnu.org.
 */

/* Implement Geomview's "apply = blend" for constant shading
 *
 * Maybe mgrib should set bgalpha to 0 if transparency is not enabled
 * (0 because this will leave the alpha channel of the surface
 * unaffected).
 *
 * The additional parameter At interpolates between 1 and Ot; the
 * effective alpha contribution from the texture will be (1-At) + At *
 * Ot.
 */
surface
GVreplaceconstant(string texturename = "";
		  float At = 1;)
{
  /* texture provided color (luminance) and alpha */
  color Ct;
  float Ot;
  /* number of texture channels,
   * < 3: liminance and possibly alpha, > 2: rgb and possibly alpha
   */
  float channels;
  
  if (texturename != "" &&
      textureinfo(texturename, "channels", channels) == 1.0) {
    if (channels < 3) {
      Ct = float texture (texturename[0], "width", 0.0);
      if (channels == 2) {
	Ot = float texture (texturename[1], "width", 0.0);
      }
    } else {
      Ct = color texture (texturename, "width", 0.0);
      if (channels == 4) {
	Ot = float texture (texturename[3], "width", 0.0);
      }
    }
    Ot = (1.0 - At) + At * Ot;
    Ci = Ct * Ot;
    Oi = Ot;
  } else {
    /* no texture: use ordinary constant shader */
    Ci = Cs;
    Oi = Os;
    Ci *= Os;
  }

}

/*
 * Local Variables: ***
 * mode: c ***
 * c-basic-offset: 2 ***
 * End: ***
 */