[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx/libpaper papermill.py texcoords.py NVco...
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] gzz/gfx/libpaper papermill.py texcoords.py NVco... |
Date: |
Mon, 02 Sep 2002 08:56:56 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Tuomas J. Lukka <address@hidden> 02/09/02 08:56:56
Modified files:
gfx/libpaper : papermill.py texcoords.py
Added files:
gfx/libpaper : NVcomb.py texcomb_NV1X.py texcomb_NV2X.py
texops_NV2X.py texops_STD.py textures.py
Log message:
Major update to libpaper
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/NVcomb.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/texcomb_NV1X.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/texcomb_NV2X.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/texops_NV2X.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/texops_STD.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/textures.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/papermill.py.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/texcoords.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gzz/gfx/libpaper/papermill.py
diff -c gzz/gfx/libpaper/papermill.py:1.17 gzz/gfx/libpaper/papermill.py:1.18
*** gzz/gfx/libpaper/papermill.py:1.17 Sat Aug 31 03:06:06 2002
--- gzz/gfx/libpaper/papermill.py Mon Sep 2 08:56:56 2002
***************
*** 1,233 ****
- # Syntax: one tuple per texture unit,
- # ( operation, texture type[, previous texture input] )
- # where
- # operation
- # T1/2/3: TEXTURE_1D / 2D / 3D
- # D: DOT_PRODUCT
- # D2: DOT_PRODUCT_2D
- # O: OFFSET_TEXTURE_2D
- # texture type
- # D2: 2D dot-product -suitable
- # R2: 2D RGB
-
- shaderTypes = [
- [
- ("T2", "D2"),
- ("D", None, 0),
- ("D2", "R2", 0),
- ("T2", "R2")
- ],
- [
- ("T2", "D2"),
- ("T2", "D2"),
- ("D", None, 0),
- ("D2", "R2", 1),
- ],
- [
- ("T3", "R3"),
- ("T3", "R3"),
- ("T3", "R3"),
- ("T3", "R3"),
- ],
- ]
-
- # XXX: kluge: odd and even units are for "-eps" and "+eps"
- embossShaderTypes = [
- [
- ("T2", "R2"),
- ("T2", "R2"),
- ]
- ]
-
- shaderOps = {
- "T2" : "TEXTURE_2D",
- "T3" : "TEXTURE_3D",
- "D" : "DOT_PRODUCT_NV",
- "D2" : "DOT_PRODUCT_TEXTURE_2D_NV",
- "O" : "OFFSET_TEXTURE_2D_NV",
- }
-
- shaderTargets = {
- "T2" : "TEXTURE_2D",
- "T3" : "TEXTURE_3D",
- "D": None,
- "D2": "TEXTURE_2D",
- "O": "TEXTURE_2D",
- }
-
- shaderTexgenTypes = {
- "T2" : "A",
- "T3" : "A3",
- "D" : "C",
- "D2" : "C",
- "O" : "A",
- }
-
dbg = 0
-
- class NoTextureSetForStage:
- pass
-
- class ShaderPass:
- def __init__(self, shaderType):
- self.st = shaderType
- self.tex = [None for texunit in shaderType]
- def getTextureTypes(self):
- "Get the texture type names (D2, R2 ...) for the texture units."
- return [texunit[1] for texunit in self.st]
- def getTexgenTypes(self):
- "Get the texgen letter codes for the texture units."
- return [shaderTexgenTypes[texunit[0]] for texunit in self.st]
- def setTexture(self, ind, texid):
- self.tex[ind] = str(texid)
- def setupCode(self):
- c = """
- Enable TEXTURE_SHADER_NV
- """
- for t in range(0,len(self.st)):
- shortOp = self.st[t][0]
- op = shaderOps[shortOp]
- target = shaderTargets[shortOp]
- c += """
- ActiveTexture TEXTURE%(t)s
-
- TexEnv TEXTURE_SHADER_NV SHADER_OPERATION_NV %(op)s
-
- """ % locals()
- if target != None:
- texid = self.tex[t]
- if texid == None: raise NoTextureSetForStage()
- c += """
- Enable %(target)s
- BindTexture %(target)s %(texid)s
-
- TexParameter %(target)s TEXTURE_WRAP_S REPEAT
- TexParameter %(target)s TEXTURE_WRAP_T REPEAT
- TexParameter %(target)s TEXTURE_MIN_FILTER
LINEAR_MIPMAP_LINEAR
- TexParameter %(target)s TEXTURE_MAG_FILTER LINEAR
- """ % locals()
- if len(self.st[t]) > 2: # Previous texture input
- c += """
- TexEnv TEXTURE_SHADER_NV PREVIOUS_TEXTURE_INPUT_NV TEXTURE%s
- """ % (self.st[t][2])
- return c
- def getRGBoutputs(self):
- """A list of the texture units whose outputs are useful in
- the register combiners.
- """
- return [i for i in range(0,len(self.st))
- if self.st[i][1] in ("R2", "R3")]
-
-
- class DebugCombinerPass:
- "A combinerpass that shows one component (r, g, b) from each of the
textures"
- def setupCode(self, texinputs, *extra):
- """ Setup code for the pass.
-
- Texinputs = the indices of the texture units producing usable RGB.
- """
-
- print "DBG: ",texinputs
- t0 = t1 = t2 = texinputs[0]
- if len(texinputs) > 1:
- t1 = texinputs[1]
- if len(texinputs) > 2:
- t2 = texinputs[2]
- c = """
- Enable REGISTER_COMBINERS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
- CombinerParameterNV CONSTANT_COLOR0_NV 1 0 0 1
- CombinerParameterNV CONSTANT_COLOR1_NV 0 1 0 1
- Color 0 0 1 1
-
- CombinerInputNV COMBINER0_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_B_NV TEXTURE%(t0)s
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_D_NV TEXTURE%(t1)s
SIGNED_IDENTITY_NV RGB
-
- CombinerOutputNV COMBINER0_NV RGB DISCARD_NV DISCARD_NV SPARE0_NV
NONE NONE FALSE FALSE FALSE
-
- FinalCombinerInputNV VARIABLE_A_NV PRIMARY_COLOR_NV
UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_B_NV TEXTURE%(t2)s
UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_D_NV SPARE0_NV UNSIGNED_IDENTITY_NV
RGB
-
- FinalCombinerInputNV VARIABLE_G_NV ZERO UNSIGNED_INVERT_NV ALPHA
-
- """ % locals()
-
- return c
-
execfile("gfx/libcolor/spaces.py")
execfile("gfx/libpaper/texcoords.py")
!
! class SimpleCombinerPass:
! def setupCode(self, texinputs, rnd):
! # 4 colors
! minlum = 60
! c0 = js(getRandomColor(minlum,100, rnd))
! c1 = js(getRandomColor(minlum,minlum + (100-minlum)*0.5, rnd))
! c2 = js(getRandomColor(minlum + (100-minlum)*0.5, 100, rnd))
! c3 = js(getRandomColor(minlum + (100-minlum)*0.5, 100, rnd))
! # 4 random dot product vectors
! r0, r1, r2, r3 = [
! js([rnd.nextDouble() for i in range(0,4)])
! for j in range(0,4)]
!
! assert len(texinputs) != 0
! while len(texinputs) < 4:
! texinputs = texinputs + texinputs
! t0, t1, t2, t3 = texinputs[0:4]
! c = """
! Enable REGISTER_COMBINERS_NV
! Enable PER_STAGE_CONSTANTS_NV
! CombinerParameterNV NUM_GENERAL_COMBINERS_NV 4
!
! CombinerStageParameterNV COMBINER0_NV CONSTANT_COLOR0_NV %(r0)s
! CombinerStageParameterNV COMBINER0_NV CONSTANT_COLOR1_NV %(r1)s
! CombinerStageParameterNV COMBINER1_NV CONSTANT_COLOR0_NV %(r2)s
! CombinerStageParameterNV COMBINER1_NV CONSTANT_COLOR1_NV %(r3)s
!
! CombinerStageParameterNV COMBINER2_NV CONSTANT_COLOR0_NV %(c0)s 1
! CombinerStageParameterNV COMBINER2_NV CONSTANT_COLOR1_NV %(c1)s 1
! CombinerStageParameterNV COMBINER3_NV CONSTANT_COLOR0_NV %(c2)s 1
! CombinerStageParameterNV COMBINER3_NV CONSTANT_COLOR1_NV %(c3)s 1
!
! CombinerInputNV COMBINER0_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
EXPAND_NORMAL_NV RGB
! CombinerInputNV COMBINER0_NV RGB VARIABLE_B_NV TEXTURE%(t0)s
EXPAND_NORMAL_NV RGB
! CombinerInputNV COMBINER0_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
EXPAND_NORMAL_NV RGB
! CombinerInputNV COMBINER0_NV RGB VARIABLE_D_NV TEXTURE%(t1)s
EXPAND_NORMAL_NV RGB
! CombinerOutputNV COMBINER0_NV RGB SPARE0_NV SPARE1_NV DISCARD_NV
SCALE_BY_TWO_NV NONE TRUE TRUE FALSE
!
! CombinerInputNV COMBINER1_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
EXPAND_NORMAL_NV RGB
! CombinerInputNV COMBINER1_NV RGB VARIABLE_B_NV TEXTURE%(t2)s
EXPAND_NORMAL_NV RGB
! CombinerInputNV COMBINER1_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
EXPAND_NORMAL_NV RGB
! CombinerInputNV COMBINER1_NV RGB VARIABLE_D_NV TEXTURE%(t3)s
EXPAND_NORMAL_NV RGB
! CombinerOutputNV COMBINER1_NV RGB PRIMARY_COLOR_NV
SECONDARY_COLOR_NV DISCARD_NV SCALE_BY_TWO_NV NONE TRUE TRUE FALSE
!
! CombinerInputNV COMBINER2_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
SIGNED_IDENTITY_NV RGB
! CombinerInputNV COMBINER2_NV RGB VARIABLE_B_NV SPARE0_NV
UNSIGNED_IDENTITY_NV RGB
! CombinerInputNV COMBINER2_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
SIGNED_IDENTITY_NV RGB
! CombinerInputNV COMBINER2_NV RGB VARIABLE_D_NV SPARE0_NV
UNSIGNED_INVERT_NV RGB
! CombinerOutputNV COMBINER2_NV RGB DISCARD_NV DISCARD_NV SPARE0_NV
NONE NONE FALSE FALSE FALSE
!
! CombinerInputNV COMBINER3_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
SIGNED_IDENTITY_NV RGB
! CombinerInputNV COMBINER3_NV RGB VARIABLE_B_NV SPARE1_NV
UNSIGNED_IDENTITY_NV RGB
! CombinerInputNV COMBINER3_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
SIGNED_IDENTITY_NV RGB
! CombinerInputNV COMBINER3_NV RGB VARIABLE_D_NV SPARE1_NV
UNSIGNED_INVERT_NV RGB
! CombinerOutputNV COMBINER3_NV RGB DISCARD_NV DISCARD_NV SPARE1_NV
NONE NONE FALSE FALSE FALSE
!
!
! FinalCombinerInputNV VARIABLE_A_NV PRIMARY_COLOR_NV
UNSIGNED_IDENTITY_NV RGB
! FinalCombinerInputNV VARIABLE_B_NV SPARE0_NV UNSIGNED_IDENTITY_NV
RGB
! FinalCombinerInputNV VARIABLE_C_NV SPARE1_NV UNSIGNED_IDENTITY_NV
RGB
! FinalCombinerInputNV VARIABLE_D_NV ZERO UNSIGNED_IDENTITY_NV RGB
!
! FinalCombinerInputNV VARIABLE_G_NV ZERO UNSIGNED_INVERT_NV ALPHA
!
! """ % locals()
! return c
!
def randvec(rnd): return [rnd.nextDouble() for i in range(0,3)]
--- 1,9 ----
dbg = 0
execfile("gfx/libcolor/spaces.py")
execfile("gfx/libpaper/texcoords.py")
! execfile("gfx/libpaper/texops_NV2X.py")
! execfile("gfx/libpaper/textures.py")
! execfile("gfx/libpaper/texcomb_NV2X.py")
def randvec(rnd): return [rnd.nextDouble() for i in range(0,3)]
***************
*** 244,427 ****
z = 2 * rnd.nextDouble() - 1
m = 1./Math.sqrt(x*x+y*y+z*z)*.5 * maxlen * rnd.nextDouble()
return [m * x + .5, m * y + .5, m * z + .5]
-
- class TransparentCombinerPass:
- def setupCode(self, texinputs, rnd, trans = 0):
- # 4 colors
- minlum = 66
- while 1:
- col0 = getRandomColor2(minlum,100, rnd)
- col1 = getRandomColor2(minlum,minlum + (100-minlum)*0.5, rnd)
- col2 = getRandomColor2(minlum + (100-minlum)*0.5, 100, rnd)
- col3 = getRandomColor2(minlum + (100-minlum)*0.5, 100, rnd)
- if abdiff(col0, col1) < 40: continue
- #if abdiff(col0, col2) < 40: continue
- #if abdiff(col0, col3) < 40: continue
- #if abdiff(col1, col2) < 40: continue
- #if abdiff(col1, col3) < 40: continue
- if abdiff(col2, col3) < 40: continue
- break
-
- c0 = js(col0)
- c1 = js(col1)
- c2 = js(col2)
- c3 = js(col3)
-
- # 4 random dot product vectors
- r0, r1, r2, r3 = [ js(randvec2(rnd)) + " 1" for j in range(0,4) ]
-
- # map alpha dot product a \in [0,1] into clamp(1 - (1-a) * alphascale)
- if trans > 0:
- alphascale = 1 - 1.0/trans
- else:
- alphascale = 0
-
- alphascale = alphascale * (1. / 16)
-
- assert len(texinputs) != 0
- while len(texinputs) < 4:
- texinputs = texinputs + texinputs
- t0, t1, t2, t3 = texinputs[0:4]
- c = """
- Enable BLEND
- BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA
- Disable ALPHA_TEST
-
- Enable REGISTER_COMBINERS_NV
- Enable PER_STAGE_CONSTANTS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 4
-
- CombinerStageParameterNV COMBINER0_NV CONSTANT_COLOR0_NV %(r0)s
- CombinerStageParameterNV COMBINER0_NV CONSTANT_COLOR1_NV %(r1)s
- CombinerStageParameterNV COMBINER1_NV CONSTANT_COLOR0_NV %(r2)s
- CombinerStageParameterNV COMBINER1_NV CONSTANT_COLOR1_NV %(r3)s
-
- CombinerStageParameterNV COMBINER2_NV CONSTANT_COLOR0_NV %(c0)s
%(alphascale)s
- CombinerStageParameterNV COMBINER2_NV CONSTANT_COLOR1_NV %(c1)s 1
- CombinerStageParameterNV COMBINER3_NV CONSTANT_COLOR0_NV %(c2)s 1
- CombinerStageParameterNV COMBINER3_NV CONSTANT_COLOR1_NV %(c3)s 1
-
- CombinerInputNV COMBINER0_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_B_NV TEXTURE%(t0)s
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_D_NV TEXTURE%(t1)s
EXPAND_NORMAL_NV RGB
- CombinerOutputNV COMBINER0_NV RGB SPARE0_NV SPARE1_NV DISCARD_NV
SCALE_BY_TWO_NV NONE TRUE TRUE FALSE
-
- CombinerInputNV COMBINER1_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER1_NV RGB VARIABLE_B_NV TEXTURE%(t2)s
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER1_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER1_NV RGB VARIABLE_D_NV TEXTURE%(t3)s
EXPAND_NORMAL_NV RGB
- CombinerOutputNV COMBINER1_NV RGB PRIMARY_COLOR_NV
SECONDARY_COLOR_NV DISCARD_NV SCALE_BY_TWO_NV NONE TRUE TRUE FALSE
-
- CombinerInputNV COMBINER2_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER2_NV RGB VARIABLE_B_NV SPARE0_NV
UNSIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER2_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER2_NV RGB VARIABLE_D_NV SPARE0_NV
UNSIGNED_INVERT_NV RGB
- CombinerOutputNV COMBINER2_NV RGB DISCARD_NV DISCARD_NV SPARE0_NV
NONE NONE FALSE FALSE FALSE
-
- CombinerInputNV COMBINER3_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER3_NV RGB VARIABLE_B_NV SPARE1_NV
UNSIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER3_NV RGB VARIABLE_C_NV CONSTANT_COLOR1_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER3_NV RGB VARIABLE_D_NV SPARE1_NV
UNSIGNED_INVERT_NV RGB
- CombinerOutputNV COMBINER3_NV RGB DISCARD_NV DISCARD_NV SPARE1_NV
NONE NONE FALSE FALSE FALSE
-
-
- FinalCombinerInputNV VARIABLE_A_NV PRIMARY_COLOR_NV
UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_B_NV SPARE0_NV UNSIGNED_IDENTITY_NV
RGB
- FinalCombinerInputNV VARIABLE_C_NV SPARE1_NV UNSIGNED_IDENTITY_NV
RGB
- FinalCombinerInputNV VARIABLE_D_NV ZERO UNSIGNED_IDENTITY_NV RGB
-
- CombinerInputNV COMBINER2_NV ALPHA VARIABLE_A_NV CONSTANT_COLOR0_NV
UNSIGNED_IDENTITY_NV ALPHA
- CombinerInputNV COMBINER2_NV ALPHA VARIABLE_B_NV SECONDARY_COLOR_NV
UNSIGNED_INVERT_NV BLUE
- CombinerOutputNV COMBINER2_NV ALPHA SPARE0_NV DISCARD_NV DISCARD_NV
SCALE_BY_FOUR_NV NONE FALSE FALSE FALSE
-
- CombinerInputNV COMBINER3_NV ALPHA VARIABLE_A_NV ZERO
UNSIGNED_INVERT_NV ALPHA
- CombinerInputNV COMBINER3_NV ALPHA VARIABLE_B_NV SPARE0_NV
SIGNED_IDENTITY_NV ALPHA
- CombinerOutputNV COMBINER3_NV ALPHA SPARE0_NV DISCARD_NV DISCARD_NV
SCALE_BY_FOUR_NV NONE FALSE FALSE FALSE
-
- FinalCombinerInputNV VARIABLE_G_NV SPARE0_NV UNSIGNED_INVERT_NV
ALPHA
-
- """ % locals()
- return c
-
-
- class EmbossCombinerPass:
- def setupCode(self, texinputs, rnd, trans = 0):
-
- # 4 random dot product vectors
- r0, r1, r2, r3 = [ js(randvec2(rnd,.5)) + " 1" for j in range(0,4) ]
-
-
- # map alpha dot product a \in [0,1] into clamp(1 - (1-a) * alphascale)
- if trans > 0:
- alphascale = 1 - 1.0/trans
- else:
- alphascale = 0
-
- alphascale = alphascale * (1. / 16)
-
- assert len(texinputs) != 0
- while len(texinputs) < 4:
- texinputs = texinputs + texinputs
-
- # Value at when both textures are at the same level
- level=1
-
- # The lightness is computed clamped in the alpha component and
- # the part overflowing 1.0 is computed in the rgb components.
- # Using "BlendFunc DST_COLOR SRC_ALPHA" allows going beyond
- # the original destination color in brightness and one could even
- # use "BlendFunc ONE SRC_ALPHA" to add the overflowing
- # part as white.
-
- level=js([1-level for i in range(0,3)] + [level])
-
- t0, u0, t1, u1 = texinputs[0:4]
- c = """
- Enable BLEND
- BlendFunc DST_COLOR SRC_ALPHA
- Disable ALPHA_TEST
-
- Enable REGISTER_COMBINERS_NV
- Enable PER_STAGE_CONSTANTS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 3
-
- CombinerStageParameterNV COMBINER0_NV CONSTANT_COLOR0_NV %(r0)s
- CombinerStageParameterNV COMBINER2_NV CONSTANT_COLOR0_NV %(level)s
-
- CombinerInputNV COMBINER0_NV RGB VARIABLE_A_NV CONSTANT_COLOR0_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_B_NV TEXTURE%(t0)s
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_C_NV CONSTANT_COLOR0_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER0_NV RGB VARIABLE_D_NV TEXTURE%(u0)s
EXPAND_NORMAL_NV RGB
- CombinerOutputNV COMBINER0_NV RGB PRIMARY_COLOR_NV
SECONDARY_COLOR_NV DISCARD_NV NONE NONE TRUE TRUE FALSE
-
- CombinerInputNV COMBINER1_NV RGB VARIABLE_A_NV ZERO
EXPAND_NEGATE_NV RGB
- CombinerInputNV COMBINER1_NV RGB VARIABLE_B_NV PRIMARY_COLOR_NV
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER1_NV RGB VARIABLE_C_NV ZERO
EXPAND_NORMAL_NV RGB
- CombinerInputNV COMBINER1_NV RGB VARIABLE_D_NV SECONDARY_COLOR_NV
EXPAND_NORMAL_NV RGB
- CombinerOutputNV COMBINER1_NV RGB DISCARD_NV DISCARD_NV
PRIMARY_COLOR_NV SCALE_BY_FOUR_NV NONE FALSE FALSE FALSE
-
- CombinerInputNV COMBINER2_NV ALPHA VARIABLE_A_NV ZERO
UNSIGNED_INVERT_NV ALPHA
- CombinerInputNV COMBINER2_NV ALPHA VARIABLE_B_NV PRIMARY_COLOR_NV
SIGNED_IDENTITY_NV BLUE
- CombinerInputNV COMBINER2_NV ALPHA VARIABLE_C_NV ZERO
UNSIGNED_INVERT_NV ALPHA
- CombinerInputNV COMBINER2_NV ALPHA VARIABLE_D_NV CONSTANT_COLOR0_NV
UNSIGNED_IDENTITY_NV ALPHA
- CombinerOutputNV COMBINER2_NV ALPHA DISCARD_NV DISCARD_NV
PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE
-
- CombinerInputNV COMBINER2_NV RGB VARIABLE_A_NV ZERO
UNSIGNED_INVERT_NV RGB
- CombinerInputNV COMBINER2_NV RGB VARIABLE_B_NV PRIMARY_COLOR_NV
SIGNED_IDENTITY_NV RGB
- CombinerInputNV COMBINER2_NV RGB VARIABLE_C_NV ZERO
UNSIGNED_INVERT_NV RGB
- CombinerInputNV COMBINER2_NV RGB VARIABLE_D_NV CONSTANT_COLOR0_NV
SIGNED_NEGATE_NV RGB
- CombinerOutputNV COMBINER2_NV RGB DISCARD_NV DISCARD_NV
PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE
-
- FinalCombinerInputNV VARIABLE_A_NV ZERO UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_B_NV ZERO UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_D_NV PRIMARY_COLOR_NV
UNSIGNED_IDENTITY_NV RGB
- FinalCombinerInputNV VARIABLE_G_NV PRIMARY_COLOR_NV
UNSIGNED_IDENTITY_NV ALPHA
-
- """ % locals()
- return c
-
def selectRandom(list, gen):
--- 20,25 ----
***************
*** 430,513 ****
def selectDet(list, type):
return ( list[type % len(list)], type / len(list) )
- class NamedTexture:
- def __init__(self, name, args):
- self.texture = apply(getTexture, args)
- self.name = name
- def getTexId(self):
- return self.texture.getTexId()
- def getName(self):
- return self.name
-
class PaperMill:
- def __init__(self):
- self.textures = None
- def initTextures(self):
- if not self.textures:
- rgbTextures = [
- #("debug", [512, 512, 0, 3,
- # "RGB", "RGB",
- # "debuggrid", []]),
- ("rgbn", [512, 512, 0, 3,
- "RGB", "RGB",
- "noise", ["type", "normal", "freq", "20", "bias",
"0.5"]]),
- ("rgbl", [512, 512, 0, 3,
- "RGB", "RGB",
- "lines1", ["linewidth", "0.1"]]),
- ("rgbw", [512, 512, 0, 3,
- "RGB", "RGB",
- "waves", ["abs", "1", "freq0", "1", "freq1", "1"]]),
- ]
-
- rgb3DTextures = [
- ("rgbw", [128, 128, 128, 3,
- "RGB", "RGB",
- "filereader", ["file",
"lava/gfx/data/map3d_F0.01_k0.0325_eps0.015_teps0.5_iter5000.dat", "scale",
"10", "bias", "-1.5" ]]),
- #("rgbw", [64, 64, 64, 3,
- # "RGB", "RGB",
- # "filereader", ["file", "lava/gfx/map3d.dat",
"scale", "10", "bias", "-3" ]]),
-
- ]
-
- dotTextures = [
- ("dotprodn", [512, 512, 0, 2,
- "SIGNED_HILO_NV", "HILO_NV", # XXX signed
- "noise", ["type", "normal", "freq", "10",
"scale", "0.1"]]),
- ("dotprodt", [512, 512, 0, 2,
- "SIGNED_HILO_NV", "HILO_NV", # XXX signed
- "noise", ["type", "turbulence", "freq", "40"]]),
- ("dotprodw", [512, 512, 0, 2,
- "SIGNED_HILO_NV", "HILO_NV", # XXX signed
- "waves", ["abs", "1", "freq0", "2", "freq1",
"3"]]),
- #("dotprodrd", [128, 128, 0, 2,
- # "SIGNED_HILO_NV", "HILO_NV", # XXX signed
- # "rd1", ["iter", "3000", "F", ".04", "k",
".06"]]),
- ]
-
- self.textures = {
- #"R2": [ NamedTexture(name, args) for (name, args) in
rgbTextures ],
- "R3": [ NamedTexture(name, args) for (name, args) in
rgb3DTextures ],
- #"D2": [ NamedTexture(name, args) for (name, args) in
dotTextures ],
- }
-
def makePaperPass(self, seed, ppass, trans = 0, type = None, emboss = 0):
rnd = java.util.Random(seed)
- self.initTextures()
#sh = ShaderPass(selectRandom(shaderTypes,rnd))
if emboss:
! sh = ShaderPass(embossShaderTypes[0])
else:
! sh = ShaderPass(shaderTypes[2])
types = sh.getTextureTypes()
for i in range(0, len(types)):
if types[i] != None:
! if type != None:
! selectRandom(self.textures[types[i]],rnd)
! (t, type) = selectDet(self.textures[types[i]], type)
! else:
! #print types, self.textures
! t = selectRandom(self.textures[types[i]],rnd)
if emboss:
if (i%2) == 0:
--- 28,46 ----
def selectDet(list, type):
return ( list[type % len(list)], type / len(list) )
class PaperMill:
def makePaperPass(self, seed, ppass, trans = 0, type = None, emboss = 0):
rnd = java.util.Random(seed)
#sh = ShaderPass(selectRandom(shaderTypes,rnd))
if emboss:
! sh = makeEmbossShaderPass()
else:
! sh = makeNormalShaderPass()
types = sh.getTextureTypes()
for i in range(0, len(types)):
if types[i] != None:
! t = getPaperTexture(types[i], rnd)
if emboss:
if (i%2) == 0:
***************
*** 530,537 ****
Disable BLEND
"""
# Set normal depth testing for the first (non-transparent) pass
! # and "equal" depth testing for the latter (transparent) passes
if trans == 0 and emboss == 0:
code += """
--- 63,72 ----
Disable BLEND
"""
+ # Performance optimization:
# Set normal depth testing for the first (non-transparent) pass
! # and "equal" depth testing for the latter (transparent) passes,
! # and don't write to the depth buffer.
if trans == 0 and emboss == 0:
code += """
***************
*** 561,577 ****
ttyp = sh.getTexgenTypes()
ppass.setNTexGens(len(ttyp))
for i in range(0, len(ttyp)):
if ttyp[i] != None:
sca2 = 0.8
! if ttyp[i] == "A":
! #data = getTexMat(rnd)
! data = TexCoords().get2DTexGenData(rnd)
! elif ttyp[i] == "A3":
! data = TexCoords().get3DTexGenData(rnd)
! elif ttyp[i] == "C":
data = [ 0, 0, 0, sca2*rnd.nextGaussian(),
0, 0, 0, sca2*rnd.nextGaussian(),
0, 0, 0, sca2*rnd.nextGaussian() ]
--- 96,116 ----
ttyp = sh.getTexgenTypes()
ppass.setNTexGens(len(ttyp))
+
+ rootrep = TexGenXYRepeatUnit(rnd)
+
for i in range(0, len(ttyp)):
if ttyp[i] != None:
sca2 = 0.8
! if ttyp[i] in ("TexGen2D", "TexGen3D"):
! data = rootrep.getRelated(rnd).texCoords2D(rnd).getVec()
! elif ttyp[i] == "TexGen2D":
! data = TexCoords().texCoords2D(rnd).getVec()
! elif ttyp[i] == "TexGen3D":
! data = TexCoords().texCoords3D(rnd).getVec()
! elif ttyp[i] == "TexGenDotVector":
data = [ 0, 0, 0, sca2*rnd.nextGaussian(),
0, 0, 0, sca2*rnd.nextGaussian(),
0, 0, 0, sca2*rnd.nextGaussian() ]
***************
*** 579,585 ****
assert 0
if len(data) < 12:
for i in (0,0,0,1): data.append(i)
! if emboss and ttyp[i] in ( "A", "A3" ):
if eps > 0:
prev = data
else:
--- 118,124 ----
assert 0
if len(data) < 12:
for i in (0,0,0,1): data.append(i)
! if emboss :
if eps > 0:
prev = data
else:
***************
*** 590,619 ****
else:
if dbg: print "TexGen"+str(i), data
ppass.putNormalTexGen(i, data)
-
-
- def invTexMat(mat):
- m = 1.0 / (mat[0] * mat[5] - mat[1] * mat[4])
- return [ m*mat[5], m*-mat[1], mat[2], mat[3],
- m*-mat[4], m*mat[0], mat[6], mat[7]]
-
- def getTexMat(rnd):
- #sca1 = 10
- #return [ sca1*rnd.nextGaussian(), sca1*rnd.nextGaussian(), 0,
rnd.nextGaussian(),
- # sca1*rnd.nextGaussian(), sca1*rnd.nextGaussian(), 0,
rnd.nextGaussian() ]
-
- a = (.25 + .1*rnd.nextGaussian()) * math.pi
- a *= 1 - 2 * rnd.nextBoolean()
-
- r = .3*rnd.nextGaussian()
- m = .1 * rnd.nextGaussian()
-
- a0 = rnd.nextDouble() * 2 * math.pi
- a1 = a0 + a
-
- r0 = r * math.exp(m)
- r1 = r * math.exp(-m)
-
- return invTexMat([ r0 * math.cos(a0), r1 * math.cos(a1), 0,
rnd.nextDouble(),
- r0 * math.sin(a0), r1 * math.sin(a1), 0,
rnd.nextDouble() ])
--- 129,132 ----
Index: gzz/gfx/libpaper/texcoords.py
diff -c gzz/gfx/libpaper/texcoords.py:1.6 gzz/gfx/libpaper/texcoords.py:1.7
*** gzz/gfx/libpaper/texcoords.py:1.6 Sat Aug 31 02:04:44 2002
--- gzz/gfx/libpaper/texcoords.py Mon Sep 2 08:56:56 2002
***************
*** 1,15 ****
# Texture coordinates
! class TexCoords:
! def _create2DXYVectors(self, rnd):
! """Create the carefully correlated matrix which gives (x,y)
! from the texture coordinates (s,t).
! rnd: A Java random number generator
"""
# The angle between the basis vectors
! angle = (.25 + .1*rnd.nextGaussian()) * math.pi
angle *= 1 - 2 * rnd.nextBoolean()
--- 1,76 ----
# Texture coordinates
+ from __future__ import nested_scopes
+ import math
! def smallIntegerG0(rnd):
! """Return a small integer greater than 0.
! """
! return abs(int(0.5*rnd.nextGaussian()))+1
!
! def smallInteger(rnd):
! """Return a small integer.
! """
! return abs(int(1.5*rnd.nextGaussian()))
!
! class TexGenData:
! def __init__(self, vec):
! self.vec = vec
! def getVec(self):
! return self.vec
! def createCorrelated_xyspace(self, rnd):
! """Create a TexGenData correlated to this so that
! the repetitive unit in the (x,y) coordinates is similar;
! the (s,t,r) coordinates will not be similar.
!
! This is achieved by taking small-rational linear combinations
! of the vectors and adding random offsets.
!
! This operation is useful for creating new shapes, especially
! when 3D textures are not supported."""
! # Initialize with just shift.
! nv = [0, 0, 0, rnd.nextDouble(),
! 0, 0, 0, rnd.nextDouble(),
! 0, 0, 0, rnd.nextDouble()]
!
! # Add a random rational of each.
! for vold in range(0,3):
! for vnew in range(0,3):
! numer = smallIntegerG0(rnd)
! denom = smallIntegerG0(rnd)
! if rnd.nextBoolean():
! sign = 1
! else:
! sign = -1
! for i in range(0,3):
! nv[4*vnew + i] += sign * numer * self.vec[4*vold + i] /
denom
!
! # return the new texgendata
! return TexGenData(nv)
!
! def createCorrelated_strspace(self,rnd):
! """Create a TexGenData correlated to this in every way:
! this represents a slight shift in (s,t,r) coordinates.
"""
+ class TexGenXYRepeatUnit:
+ """ A class representing a parallelogram repeating unit in (x,y)
+ coordinates.
+ """
+ def __init__(self, rnd=None,
+ vecs = None,
+ angle_stddev = .1,
+ avg_length_mean = .5,
+ avg_length_stddev = .25,
+ lendiff_mean = 0,
+ lendiff_stddev = .1):
+
+ if vecs != None:
+ self.vecs = vecs
+ return
+
# The angle between the basis vectors
! angle = (.25 + angle_stddev*rnd.nextGaussian()) * math.pi
angle *= 1 - 2 * rnd.nextBoolean()
***************
*** 20,53 ****
# The (geometric) average of the basis vector lengths
! r = .3*rnd.nextGaussian()
# The difference between basis vector lengths
! m = .1 * rnd.nextGaussian()
# The basis vector lengths
rs = r * math.exp(m)
rt = r * math.exp(-m)
! # Offsets
! soffs = rs * rnd.nextDouble()
! toffs = rt * rnd.nextDouble()
!
! # Return the vectors that give x and y when dotted with (s, t, 0, 1)
!
! mat = [[ rs * math.cos(as), rt * math.cos(at), 0, "?"],
! [ rs * math.sin(as), rt * math.sin(at), 0, "?"]]
!
! # x and y offsets
! mat[0][3] = soffs * mat[0][0] + toffs * mat[0][1]
! mat[1][3] = soffs * mat[1][0] + toffs * mat[1][1]
!
! return mat
!
! def _invert2Dsimple(self, mat):
! """Invert 2 4D vectors given by _create2DXYVectors to get the vectors
! to dot (x,y,0,1) with to get (s,t)
"""
# 1 / determinant
f = 1.0 / (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0])
--- 81,104 ----
# The (geometric) average of the basis vector lengths
! r = avg_length_mean + avg_length_stddev*rnd.nextGaussian()
# The difference between basis vector lengths
! m = lendiff_mean + lendiff_stddev * rnd.nextGaussian()
# The basis vector lengths
rs = r * math.exp(m)
rt = r * math.exp(-m)
! # The vectors that give x and y when dotted with (s, t, 0, 1)
! self.vecs = [[ rs * math.cos(as), rt * math.cos(at)],
! [ rs * math.sin(as), rt * math.sin(at)]]
!
! def _getSTVectors(self, rnd):
! """Get the 2 4-component vectors that (x,y,0,1) should
! be multiplied by to get (s,t).
"""
+ mat = self.vecs
# 1 / determinant
f = 1.0 / (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0])
***************
*** 55,66 ****
r = [[ f * mat[1][1], -f * mat[0][1], 0, "?"],
[ -f * mat[1][0], f * mat[0][0], 0, "?"]]
! # Calculate offsets by matrix-vector multiplication
! r[0][3] = r[0][0] * mat[0][3] + r[0][1] * mat[1][3]
! r[1][3] = r[1][0] * mat[1][3] + r[1][1] * mat[1][3]
!
return r
def _create3DPlane(self, rnd):
"""Get a suitable vector for a plane inside a 3D texture.
--- 106,223 ----
r = [[ f * mat[1][1], -f * mat[0][1], 0, "?"],
[ -f * mat[1][0], f * mat[0][0], 0, "?"]]
! # Random offsets
! r[0][3] = rnd.nextDouble()
! r[1][3] = rnd.nextDouble()
!
return r
+ def texCoords2D(self, rnd):
+ """Get an appropriate texgen vector to use for 2D texture coordinates.
+ The randomness is used only for the shift inside the (s,t) coordinate
+ system.
+ """
+ stv = self._getSTVectors(rnd)
+ return TexGenData([
+ stv[0][0],
+ stv[0][1],
+ stv[0][2],
+ stv[0][3],
+ stv[1][0],
+ stv[1][1],
+ stv[1][2],
+ stv[1][3],
+ 0, 0, 0, 0
+ ])
+
+
+
+ def getRelated(self, rnd):
+ """Create another TexGenXYRepeatUnit so that that unit
+ also repeats with this unit but may repeat more often
+ or be skewed.
+
+ ` The equation between the vectors is:
+ a vn1 + b vn2 = vo1
+ c vn1 + d vn2 = vo2
+ Where a,b,c,d are integers.
+ """
+
+ def chooseInts(rnd):
+ a,b,c,d = [int(rnd.nextGaussian()) for i in range(0,4)]
+ det = a*d-b*c
+ if det == 0: return chooseInts(rnd)
+ return (a,b,c,d)
+ a,b,c,d = chooseInts(rnd)
+ # 1 / determinant
+ f = 1.0 / (a * d - b * c)
+ vecs = [ [ f * self.vecs[1][1], -f*self.vecs[0][1] ],
+ [ -f*self.vecs[1][0], f*self.vecs[0][0] ]
+ ]
+ return TexGenXYRepeatUnit(vecs=vecs)
+
+ class TexGen3DSlice:
+ def __init__(self, rnd):
+ # (s,t,r) of origin
+ self.origin = [rnd.nextDouble(), rnd.nextDouble(), rnd.nextDouble()]
+
+ def chooseInts(rnd):
+ a,b,c,d,e,f = [int(rnd.nextGaussian()) for i in range(0,6)]
+ if a*e-b*d == 0 or a*f-c*e == 0: return chooseInts(rnd)
+ return (a,b,c,d,e,f)
+
+ ints = chooseInts(rnd)
+ self.vecs = [
+ [a,b,c],
+ [d,e,f]
+ ]
+ def mapTexGenData(self, td):
+ """Given a TexGenData object, return a new one which maps to
+ this slice instead of the 2D (s0,t0) coordinate system.
+ """
+ v = [
+ td.vec[0][0]*self.vecs[0][0] + td.vec[1][0]*self.vecs[1][0],
+ td.vec[0][1]*self.vecs[0][0] + td.vec[1][1]*self.vecs[1][0],
+ td.vec[0][2]*self.vecs[0][0] + td.vec[1][2]*self.vecs[1][0],
+ td.vec[0][3]*self.vecs[0][0] + td.vec[1][3]*self.vecs[1][0]
+ + self.origin[0],
+ td.vec[0][0]*self.vecs[0][1] + td.vec[1][0]*self.vecs[1][1],
+ td.vec[0][1]*self.vecs[0][1] + td.vec[1][1]*self.vecs[1][1],
+ td.vec[0][2]*self.vecs[0][1] + td.vec[1][2]*self.vecs[1][1],
+ td.vec[0][3]*self.vecs[0][1] + td.vec[1][3]*self.vecs[1][1]
+ + self.origin[1],
+ td.vec[0][0]*self.vecs[0][2] + td.vec[1][0]*self.vecs[1][2],
+ td.vec[0][1]*self.vecs[0][2] + td.vec[1][1]*self.vecs[1][2],
+ td.vec[0][2]*self.vecs[0][2] + td.vec[1][2]*self.vecs[1][2],
+ td.vec[0][3]*self.vecs[0][2] + td.vec[1][3]*self.vecs[1][2]
+ + self.origin[2],
+ ]
+ return TexGenData(v)
+
+
+ class TexCoords:
+
+ def texCoords2D(self, rnd):
+ """Get the data to pass to texgen for a single, random
+ 2D texture coordinate system.
+ """
+
+
+
+
+ vectors = self._invert2Dsimple(self._create2DXYVectors(rnd))
+ return TexGenData([
+ vectors[0][0],
+ vectors[0][1],
+ vectors[0][2],
+ vectors[0][3],
+ vectors[1][0],
+ vectors[1][1],
+ vectors[1][2],
+ vectors[1][3],
+ 0, 0, 0, 0
+ ])
+
def _create3DPlane(self, rnd):
"""Get a suitable vector for a plane inside a 3D texture.
***************
*** 122,146 ****
return (vec1, vec2, vec3)
!
! def get2DTexGenData(self, rnd):
! """Get the data to pass to texgen for a single, random
! 2D texture coordinate system.
! """
! vectors = self._invert2Dsimple(self._create2DXYVectors(rnd))
! return [
! vectors[0][0],
! vectors[0][1],
! vectors[0][2],
! vectors[0][3],
! vectors[1][0],
! vectors[1][1],
! vectors[1][2],
! vectors[1][3],
! 0, 0, 0, 0
! ]
!
! def get3DTexGenData(self, rnd):
"""Get the data to pass to texgen for a single, random
2D slice of a 3D texture coordinate system.
"""
--- 279,285 ----
return (vec1, vec2, vec3)
! def texCoords3D(self, rnd):
"""Get the data to pass to texgen for a single, random
2D slice of a 3D texture coordinate system.
"""
***************
*** 165,171 ****
# And add the offsets
for i in range(0,3):
vecs[i][3] += planevec[2][i]
! return [
vecs[0][0],
vecs[0][1],
vecs[0][2],
--- 304,310 ----
# And add the offsets
for i in range(0,3):
vecs[i][3] += planevec[2][i]
! return TexGenData([
vecs[0][0],
vecs[0][1],
vecs[0][2],
***************
*** 178,204 ****
vecs[2][1],
vecs[2][2],
vecs[2][3],
! ]
!
! def getCorrelatedTexGenData(self, tg, rnd):
! sca = 0.07
! return [
! tg[0],
! tg[1],
! tg[2],
! tg[3] + sca * rnd.nextGaussian(),
!
! tg[4],
! tg[5],
! tg[6],
! tg[7] + sca * rnd.nextGaussian(),
!
! tg[8],
! tg[9],
! tg[10],
! tg[11] + sca * rnd.nextGaussian(),
! ]
!
!
!
!
--- 317,320 ----
vecs[2][1],
vecs[2][2],
vecs[2][3],
! ])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gfx/libpaper papermill.py texcoords.py NVco...,
Tuomas J. Lukka <=