improved versionā¦

Uploaded with ImageShack.us
'''
Created on 24.04.2011
@author: dirk hochegger (alias:rudolf putz, hieronimus, ditus ...) im sorry for the past
'''
from direct.directbase import DirectStart
from pandac.PandaModules import Geom,GeomNode,GeomVertexFormat,GeomVertexWriter,GeomPoints,GeomVertexData
from pandac.PandaModules import Vec3,NodePath,WindowProperties,FrameBufferProperties
from pandac.PandaModules import GraphicsPipe,Texture,GraphicsOutput,Point3
import random, math
format=GeomVertexFormat.getV3n3cpt2()
vdata=GeomVertexData('square', format, Geom.UHDynamic)
VERT= GeomVertexWriter(vdata, 'vertex')
base.disableMouse()
base.camera.setPos(20,-40,20)
base.camera.lookAt(0,0,0)
base.setBackgroundColor(0,0,0,1)
class verts(object):
'''
classdocs
'''
def __init__(self,count=200000,zSRT = -2,resX = 512,resY = 512):
'''
Constructor
'''
self.renderTEXTURE = Texture()
winprops = WindowProperties.size(resX, resY)
props = FrameBufferProperties()
props.setRgbColor(1)
props.setAlphaBits(1)
props.setDepthBits(1)
props.setStencilBits(1)
self.bufferNEW = base.graphicsEngine.makeOutput(base.pipe, "offscreenBuffer",
zSRT, props, winprops,
GraphicsPipe.BFRefuseWindow,
base.win.getGsg(), base.win)
self.bufferNEW.addRenderTexture(self.renderTEXTURE, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)
self.mycamera = base.makeCamera(self.bufferNEW)
self.time = 0.0
self.PNT = NodePath()
self.drawPOINT(count)
taskMgr.add(self.ml,"ml")
self.turbulence = {}
for i in range(3):
self.turbulenceINFL(i)
self.setSHADER()
def turbulenceINFL(self,id):
self.turbulence[id] = loader.loadModel("smiley")
self.turbulence[id].setPos(random.uniform(-4.0,4.0),
random.uniform(-4.0,4.0),
random.uniform(-4.0,4.0))
self.turbulence[id].reparentTo(render)
self.pandaMovement = self.turbulence[0].hprInterval(2,Vec3(180, 90, 0))
self.turbulence[id].hide()
def drawPOINT(self,count):
pnt=GeomPoints(Geom.UHDynamic)
pnt.closePrimitive()
color=GeomVertexWriter(vdata, 'color')
for i in range(count):
pos = Vec3(random.uniform(-6.0,6.0),
random.uniform(-6.0,6.0),
random.uniform(-6.0,6.0))
dis = (pos-Vec3(0.0,0.0,0.0)).length()
VERT.addData3f(pos)
pnt.addVertex(i)
color.addData4f(random.uniform(0.0,1.0),random.uniform(0.0,1.0),random.uniform(0.0,1.0),1.0)
square=Geom(vdata)
square.addPrimitive(pnt)
snode=GeomNode('square')
snode.addGeom(square)
self.PNT=render.attachNewNode(snode)
self.PNT.setTwoSided(True)
self.PNT.setRenderModeWireframe()
self.PNT.setRenderModeThickness(4)
# self.PNT.setColor(random.uniform(0.0,1.0),random.uniform(0.0,1.0),random.uniform(0.0,1.0),1)
def setSHADER(self):
self.PNT.setShader(loader.loadShader("vertSHADER.sha"))
def ml(self,task):
self.time += 0.1
self.PNT.setShaderInput('time',self.time)
self.turbulence[0].setX(self.turbulence[0].getX()+math.sin(self.time)/250)
self.turbulence[0].setY(self.turbulence[0].getY()+math.cos(self.time)/250)
self.turbulence[0].setZ(self.turbulence[0].getZ()+math.sin(self.time)/250)
self.turbulence[1].setX(self.turbulence[1].getX()-math.sin(self.time)/250)
self.turbulence[1].setY(self.turbulence[1].getY()-math.cos(self.time)/250)
self.turbulence[1].setZ(self.turbulence[1].getZ()-math.sin(self.time)/250)
self.turbulence[2].setX(self.turbulence[2].getX()+math.cos(self.time)/250)
self.turbulence[2].setY(self.turbulence[2].getY()+math.sin(self.time)/250)
self.turbulence[2].setZ(self.turbulence[2].getZ()+math.sin(self.time)/250)
self.PNT.setShaderInput('turbulence',self.turbulence[0])
self.PNT.setShaderInput('camera',self.mycamera)
self.PNT.setShaderInput('projection',self.renderTEXTURE)
self.PNT.setShaderInput('cx',base.camera.getX())
self.PNT.setShaderInput('cy',base.camera.getY())
self.PNT.setShaderInput('cz',base.camera.getZ())
self.PNT.setShaderInput('x',self.turbulence[0].getX())
self.PNT.setShaderInput('y',self.turbulence[0].getY())
self.PNT.setShaderInput('z',self.turbulence[0].getZ())
self.PNT.setShaderInput('x1',self.turbulence[1].getX())
self.PNT.setShaderInput('y1',self.turbulence[1].getY())
self.PNT.setShaderInput('z1',self.turbulence[1].getZ())
self.PNT.setShaderInput('x2',self.turbulence[2].getX())
self.PNT.setShaderInput('y2',self.turbulence[2].getY())
self.PNT.setShaderInput('z2',self.turbulence[2].getZ())
self.PNT.setH(self.time)
return task.cont
verst=verts()
run()
vertSHADER.sha
//Cg
// Dirk hochegger (alias:rudolf putz, hieronimus, ditus ...) im sorry for the past
void vshader(float4 vtx_position : POSITION,
float4 vtx_color : COLOR,
uniform float4x4 mat_modelproj,
uniform float4 k_time,
in uniform float4x4 trans_model_to_clip_of_camera,
uniform float4 k_cx,
uniform float4 k_cy,
uniform float4 k_cz,
uniform float4 k_x,
uniform float4 k_y,
uniform float4 k_z,
uniform float4 k_x1,
uniform float4 k_y1,
uniform float4 k_z1,
uniform float4 k_x2,
uniform float4 k_y2,
uniform float4 k_z2,
out float4 l_color : COLOR0,
out float4 l_color1 : COLOR1,
out float4 l_color2 : COLOR2,
out float l_camDIS,
out float4 l_vtx,
out float3 l_texcoord0 : TEXCOORD0,
out float4 l_position : POSITION)
{
float4 screenPos = mul(trans_model_to_clip_of_camera, vtx_position);
screenPos.xy /= screenPos.w;
screenPos.xy += float2(1,1);
screenPos.xy /= 2;
//l_texcoord0 = screenPos.xyz;
float4 camPOS = float4(k_cx.x,k_cy.x,k_cz.x,0.0);
l_camDIS = length(camPOS-vtx_position);
float time = k_time/4;
float4 pos=mul(mat_modelproj, vtx_position);
float posX = pos.x;
float posY = pos.y;
float posZ = pos.z;
float posW = pos.w;
/*
posX += vtx_color.x*time;
posY += vtx_color.y*time;
posZ += vtx_color.z*time;
posW += vtx_color.w*time;
*/
float4 posTURB = float4(k_x.x,k_y.x,k_z.x,0.0);
float4 posTURB1 = float4(k_x1.x,k_y1.x,k_z1.x,0.0);
float4 posTURB2 = float4(k_x2.x,k_y2.x,k_z2.x,0.0);
float disTURB0 = length(posTURB -vtx_position);
float disTURB1 = length(posTURB1 -vtx_position);
float disTURB2 = length(posTURB2 -vtx_position);
float freqSPD = 2;
posX += sin(time-disTURB0*freqSPD)/(disTURB0/2);
posY += cos(time-disTURB0*freqSPD)/(disTURB0/2);
posZ += sin(time-disTURB0*freqSPD)/(disTURB0/2);
posX += sin(time-disTURB1*freqSPD)/(disTURB0/2);
posY += cos(time-disTURB1*freqSPD)/(disTURB0/2);
posZ += sin(time-disTURB1*freqSPD)/(disTURB0/2);
posX += sin(time-disTURB2*freqSPD)/(disTURB0/2);
posY += cos(time-disTURB2*freqSPD)/(disTURB0/2);
posZ += sin(time-disTURB2*freqSPD)/(disTURB0/2);
float b = vtx_position.x -k_x.x;
float h = vtx_position.y -k_y.x;
float d = vtx_position.z -k_z.x;
float b1 = vtx_position.x -k_x1.x;
float h1 = vtx_position.y -k_y1.x;
float d1 = vtx_position.z -k_z1.x;
float b2 = vtx_position.x -k_x2.x;
float h2 = vtx_position.y -k_y2.x;
float d2 = vtx_position.z -k_z2.x;
posX += b/disTURB0;
posY += h/disTURB0;
posZ += d/disTURB0;
posX += b1/disTURB1;
posY += h1/disTURB1;
posZ += d1/disTURB1;
posX += b2/disTURB2;
posY += h2/disTURB2;
posZ += d2/disTURB2;
l_vtx = vtx_position;
l_position = float4(posX,posY,posZ,posW*1.33);
//l_position = float4(posX,posY,posZ,100.0);
//vtx_color = l_position;
float4 colD = float4(disTURB0/40,disTURB0/40,disTURB0/30,1.0)+float4(disTURB1/40,disTURB1/40,disTURB1/30,1.0)+float4(disTURB2/40,disTURB2/40,disTURB2/30,1.0)/3;
colD += float4(sin(time-disTURB0*freqSPD)/(disTURB0/2),
cos(time-disTURB0*freqSPD)/(disTURB0/2),
sin(time-disTURB0*freqSPD)/(disTURB0/2),1.0);
colD += float4(sin(time-disTURB1*freqSPD)/(disTURB1/2),
cos(time-disTURB1*freqSPD)/(disTURB1/2),
sin(time-disTURB1*freqSPD)/(disTURB1/2),1.0);
colD += float4(sin(time-disTURB2*freqSPD)/(disTURB2/2),
cos(time-disTURB2*freqSPD)/(disTURB2/2),
sin(time-disTURB2*freqSPD)/(disTURB2/2),1.0);
l_color = colD;
}
void fshader(
in float l_camDIS,
in float3 l_texcoord0 : TEXCOORD0,
in float4 l_color : COLOR,
in float4 l_position,
in sampler2D k_projection,
out float4 o_color: COLOR0
)
{
float4 proj = tex2D(k_projection,l_texcoord0);
o_color = float4(l_position.x/4,l_position.y/4,l_position.z/4,1.0);
//o_color = float4(l_position.x/4,l_position.y/4,l_position.z/4,1.0);
o_color = float4(l_camDIS/40,l_camDIS/40,l_camDIS/40,1.0);
o_color = l_color;
}