from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "win-size 1280 768")
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from direct.showbase.ShowBase import ShowBase
import sys, random, math
from panda3d.core import *
class FlowerData():
def __init__(self):
self.palette = PNMImage("tex/palette01.png")
self.sprites = []
model = loader.loadModel("spriteflower01")
tex01 = loader.loadTexture('tex/flower01.png')
tex01.setMagfilter(Texture.FTNearest)
tex01.setMinfilter(Texture.FTNearest)
stagetex01 = TextureStage("tex01")
model.setTexture(stagetex01, tex01)
self.sprites.append(model)
model = loader.loadModel("spriteflower01")
tex02 = loader.loadTexture('tex/flower02.png')
tex02.setMagfilter(Texture.FTNearest)
tex02.setMinfilter(Texture.FTNearest)
stagetex02 = TextureStage("tex02")
model.setTexture(stagetex02, tex02)
self.sprites.append(model)
model = loader.loadModel("spriteflower01")
tex03 = loader.loadTexture('tex/flower03.png')
tex03.setMagfilter(Texture.FTNearest)
tex03.setMinfilter(Texture.FTNearest)
stagetex03 = TextureStage("tex0")
model.setTexture(stagetex03, tex03)
self.sprites.append(model)
def pickSprite(self):
random.seed()
n = random.randint(0,2)
print n
return self.sprites[n]
def pickColor(self):
x = random.randint(0,7)
y = random.randint(0,7)
Rcol = self.palette.getXelA(x,y)
Rcol = Vec4(Rcol[0],Rcol[1], Rcol[2],Rcol[3])
return Rcol
class FlowerType():
def __init__(self,flowerdata):
self.rcolor = flowerdata.pickColor()
self.gcolor = flowerdata.pickColor()
self.bcolor = flowerdata.pickColor()
self.sprite = flowerdata.pickSprite().copyTo(render)
self.sprite.setShaderInput("rcol", Vec4(self.rcolor))
self.sprite.setShaderInput("gcol", Vec4(self.gcolor))
self.sprite.setShaderInput("bcol", Vec4(self.bcolor))
myshader = Shader.load("colorshader.sha", Shader.SLCg)
self.sprite.setShader(myshader)
fd = FlowerData()
ft = []
for i in range(8):
for j in range(8):
f = FlowerType(fd)
f.sprite.setX(i*4)
f.sprite.setY(j*4)
ft.append(f)
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(1, 1, 1, 1))
render.setLight(render.attachNewNode(ambientLight))
run()
//Cg
/* lesson2.sha */
void vshader(
uniform float4x4 mat_modelproj,
in float4 vtx_position : POSITION,
out float4 l_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
out float2 l_textcoord : TEXCOORD0)
{
l_position = mul(mat_modelproj, vtx_position);
l_textcoord = vtx_texcoord0;
};
void fshader( float2 l_texcoord0 : TEXCOORD0,
uniform sampler2D tex_0,
uniform float4 rcol,
uniform float4 gcol,
uniform float4 bcol,
out float4 o_color : COLOR)
{
float4 color = tex2D(tex_0, l_texcoord0);
if (color.a == 0)
// alpha value less than user-specified threshold?
{
discard; // yes: discard this fragment
}
else
{if (color.g ==0 & color.b ==0 & color.r >0){
float r = rcol.r*color.r;
float g = rcol.g*color.r;
float b = rcol.b*color.r;
o_color = float4(r,g,b,1);
}
else if (color.r ==0 & color.b ==0 & color.g >0){
float r = gcol.r*color.g;
float g = gcol.g*color.g;
float b = gcol.b*color.g;
o_color = float4(r,g,b,1);
}
else if (color.g ==0 & color.r ==0 & color.b >0){
float r = bcol.r*color.b;
float g = bcol.g*color.b;
float b = bcol.b*color.b;
o_color = float4(r,g,b,1);
}
else{
o_color = color;}
}
}
Hey eleazzaar ! Been ages, glad to see you againIf you want a real variety in appearance, you need to assemble the base sprite from components.
Howdy!Hey eleazzaar ! Been ages, glad to see you again
from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "win-size 1280 768")
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from direct.showbase.ShowBase import ShowBase
import sys, random, math
from panda3d.core import *
class FlowerData():
def __init__(self):
self.palette = PNMImage("tex/palette01.png")
self.sprites = []
self.model = loader.loadModel("spriteflower01")
# tex01 = loader.loadTexture('tex/flower01.png')
# self.sprites.append(tex01)
# tex02 = loader.loadTexture('tex/flower02.png')
# self.sprites.append(tex02)
# tex03 = loader.loadTexture('tex/flower03.png')
# self.sprites.append(tex03)
self.sprites.append(loader.loadTexture("tex/flbase01.png"))
self.sprites.append(loader.loadTexture("tex/flbase02.png"))
self.sprites.append(loader.loadTexture("tex/flbase03.png"))
self.sprites.append(loader.loadTexture("tex/flbase04.png"))
self.sprites.append(loader.loadTexture("tex/flmid01.png"))
self.sprites.append(loader.loadTexture("tex/flmid02.png"))
self.sprites.append(loader.loadTexture("tex/flmid03.png"))
self.sprites.append(loader.loadTexture("tex/flmid04.png"))
self.sprites.append(loader.loadTexture("tex/fltop01.png"))
self.sprites.append(loader.loadTexture("tex/fltop02.png"))
self.sprites.append(loader.loadTexture("tex/fltop03.png"))
self.sprites.append(loader.loadTexture("tex/fltop04.png"))
def pickSprite(self):
random.seed()
np = NodePath()
model = self.model.copyTo(np)
n = random.randint(0,3)
tex = self.sprites[n]
tex.setMagfilter(Texture.FTNearest)
tex.setMinfilter(Texture.FTNearest)
stagetex = TextureStage("tex")
stagetex.setSort(0)
stagetex.setMode(TextureStage.MDecal)
model.setTexture(stagetex, tex)
n = random.randint(4,7)
tex2 = self.sprites[n]
tex2.setMagfilter(Texture.FTNearest)
tex2.setMinfilter(Texture.FTNearest)
stagetex2 = TextureStage("tex2")
stagetex2.setSort(1)
stagetex2.setMode(TextureStage.MDecal)
model.setTexture(stagetex2, tex2)
n = random.randint(8,11)
tex3 = self.sprites[n]
tex3.setMagfilter(Texture.FTNearest)
tex3.setMinfilter(Texture.FTNearest)
stagetex3 = TextureStage("tex3")
stagetex3.setSort(2)
stagetex3.setMode(TextureStage.MDecal)
model.setTexture(stagetex3, tex3)
return model
def pickColor(self):
x = random.randint(0,7)
y = random.randint(0,7)
Rcol = self.palette.getXelA(x,y)
Rcol = Vec4(Rcol[0],Rcol[1], Rcol[2],Rcol[3])
return Rcol
class FlowerType():
def __init__(self,flowerdata):
self.rcolor = flowerdata.pickColor()
self.gcolor = flowerdata.pickColor()
self.bcolor = flowerdata.pickColor()
# self.sprite = flowerdata.pickSprite().copyTo(render)
self.sprite = flowerdata.pickSprite()
self.sprite.reparentTo(render)
self.sprite.setShaderInput("rcol", Vec4(self.rcolor))
self.sprite.setShaderInput("gcol", Vec4(self.gcolor))
self.sprite.setShaderInput("bcol", Vec4(self.bcolor))
myshader = Shader.load("colorshader.sha", Shader.SLCg)
self.sprite.setShader(myshader)
fd = FlowerData()
ft = []
for i in range(8):
for j in range(8):
f = FlowerType(fd)
f.sprite.setX(i*4)
f.sprite.setY(j*4)
ft.append(f)
base.setBackgroundColor(0, 0, 0, 1)
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(1, 1, 1, 1))
render.setLight(render.attachNewNode(ambientLight))
run()
//Cg
/* lesson2.sha */
void vshader(
uniform float4x4 mat_modelproj,
in float4 vtx_position : POSITION,
out float4 l_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
out float2 l_textcoord : TEXCOORD0)
{
l_position = mul(mat_modelproj, vtx_position);
l_textcoord = vtx_texcoord0;
};
void fshader( float2 l_texcoord0 : TEXCOORD0,
uniform sampler2D tex_0,
uniform sampler2D tex_3,
uniform sampler2D tex_2,
uniform float4 rcol,
uniform float4 gcol,
uniform float4 bcol,
out float4 o_color : COLOR)
{
float4 color1= tex2D(tex_0, l_texcoord0);
float4 color2 = tex2D(tex_2, l_texcoord0);
float4 color3 = tex2D(tex_3, l_texcoord0);
float4 color ;
if (color1.a == 0 & color2.a==0 & color3.a ==0)
// alpha value less than user-specified threshold?
{
discard; // yes: discard this fragment
}
else
{
if(color1.a >0){color=color1;};
if (color2.a >0){color=color2;};
if (color3.a >0){color=color3;};
//color = color3;
if (color.g ==0 & color.b ==0 & color.r >0){
float r = rcol.r*color.r;
float g = rcol.g*color.r;
float b = rcol.b*color.r;
o_color = float4(r,g,b,1);
}
else if (color.r ==0 & color.b ==0 & color.g >0){
float r = gcol.r*color.g;
float g = gcol.g*color.g;
float b = gcol.b*color.g;
o_color = float4(r,g,b,1);
}
else if (color.g ==0 & color.r ==0 & color.b >0){
float r = bcol.r*color.b;
float g = bcol.g*color.b;
float b = bcol.b*color.b;
o_color = float4(r,g,b,1);
}
else{
o_color = color;}
}
}
Cool, i think i'll give the making of some decent graphics for this a shot.So, here is a prototype using eleazzaar sprites combination. The palette is certainly a bit to psychedelic and the sprites probably need to be done differently so as to make the different flowers more distinct, but on the principle it works.
I don't think i would want to use pure B&W on a plant, but you could always make an exception for pure B&W, and use the rest of the greyscale for a fourth color.No i didnt use grey. My original idea was to not change the grey color at all, so as to have "pure" black and white at least (allways usefull). Buut yeah there is the possibility to use it as a fourth color, as you suggest.
I don't think i would want to use pure B&W on a plant, but you could always make an exception for pure B&W, and use the rest of the greyscale for a fourth color.