Moved common uniforms to top of precipitation subgraph.

Added a run of the SpatializeGroupVisitor to create a balanced subgraph.

Changed the quad to particle transistion distance from 100 to 50m.
This commit is contained in:
Robert Osfield
2006-04-12 09:42:25 +00:00
parent 3be10b5a2a
commit 19a1d83f33
4 changed files with 54 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ uniform vec3 dv_k;
uniform float inversePeriod;
uniform float startTime;
uniform vec4 particleColour;
uniform float particleSize;
uniform float osg_FrameTime;
uniform float osg_DeltaFrameTime;
@@ -16,8 +17,6 @@ varying vec2 texCoord;
void main(void)
{
const float particleSize = 0.01;
vec3 pos = position + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y);
float offset = gl_Vertex.z;

View File

@@ -347,7 +347,7 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
{
osg::LOD* lod = new osg::LOD;
float nearDistance = 100.0;
float nearDistance = 50.0;
float farDistance = 200.0;
// high res LOD.
@@ -403,30 +403,35 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
static osg::Uniform* startTime = new osg::Uniform("startTime",0.0f);
stateset->addUniform(position_Uniform); // vec3
stateset->addUniform(dv_i_Uniform); // vec3 could be float
stateset->addUniform(dv_j_Uniform); // vec3 could be float
stateset->addUniform(dv_k_Uniform); // vec3
stateset->addUniform(inversePeriodUniform); // float
stateset->addUniform(startTime); // float
// make it render after the normal transparent bin
stateset->setRenderBinDetails(11,"DepthSortedBin");
#if 0
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
stateset->addUniform(position_Uniform);
stateset->addUniform(dv_i_Uniform);
stateset->addUniform(dv_j_Uniform);
stateset->addUniform(dv_k_Uniform);
stateset->addUniform(inversePeriodUniform);
stateset->addUniform(startTime);
stateset->addUniform(new osg::Uniform("particleColour", osg::Vec4(0.6,0.6,0.6,1.0)));
static osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0);
stateset->addUniform(baseTextureSampler);
static osg::Texture2D* texture = new osg::Texture2D(createSpotLightImage(osg::Vec4(1.0f,1.0f,1.0f,1.0f),osg::Vec4(1.0f,1.0f,1.0f,0.0f),32,1.0));
stateset->setTextureAttribute(0, texture);
// make it render after the normal transparent bin
stateset->setRenderBinDetails(11,"DepthSortedBin");
stateset->addUniform(new osg::Uniform("particleColour", osg::Vec4(0.6,0.6,0.6,1.0)));
stateset->addUniform(new osg::Uniform("particleSize", 0.01f));
osg::Uniform* previousModelViewUniform = new osg::Uniform("previousModelViewMatrix",osg::Matrix());
stateset->addUniform(previousModelViewUniform);
lod->setCullCallback(new CullCallback(previousModelViewUniform));
#endif
}
@@ -436,8 +441,8 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
osg::Node* createCellRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocity, unsigned int numParticles)
{
unsigned int numX = 50;
unsigned int numY = 50;
unsigned int numX = 80;
unsigned int numY = 80;
unsigned int numCells = numX*numY;
unsigned int numParticlesPerCell = numParticles/numCells;
@@ -465,6 +470,34 @@ osg::Node* createCellRainEffect(const osg::BoundingBox& bb, const osg::Vec3& vel
group->addChild(createRainEffect(bbLocal, velocity));
}
}
#if 1
osgUtil::Optimizer::SpatializeGroupsVisitor sgv;
group->accept(sgv);
sgv.divide();
#endif
#if 1
osg::StateSet* stateset = group->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0);
stateset->addUniform(baseTextureSampler);
osg::Texture2D* texture = new osg::Texture2D(createSpotLightImage(osg::Vec4(1.0f,1.0f,1.0f,1.0f),osg::Vec4(1.0f,1.0f,1.0f,0.0f),32,1.0));
stateset->setTextureAttribute(0, texture);
stateset->addUniform(new osg::Uniform("particleColour", osg::Vec4(0.6,0.6,0.6,1.0)));
stateset->addUniform(new osg::Uniform("particleSize", 0.01f));
osg::Uniform* previousModelViewUniform = new osg::Uniform("previousModelViewMatrix",osg::Matrix());
stateset->addUniform(previousModelViewUniform);
group->setCullCallback(new CullCallback(previousModelViewUniform));
#endif
return group;
}

View File

@@ -6,6 +6,7 @@ uniform vec3 dv_k;
uniform float inversePeriod;
uniform float startTime;
uniform vec4 particleColour;
uniform float particleSize;
uniform float osg_FrameTime;
@@ -14,8 +15,6 @@ varying vec2 texCoord;
void main(void)
{
const float particleSize = 0.01;
vec3 pos = position + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y);
texCoord = gl_MultiTexCoord0.xy;
@@ -29,5 +28,5 @@ void main(void)
float pointSize = min(abs(1280*particleSize / gl_Position.w), 20.0);
gl_PointSize = max(ceil(pointSize),2);
colour.a = 0.1+(pointSize)/(gl_PointSize);
colour.a = 0.05+(pointSize)/(gl_PointSize);
}

View File

@@ -6,6 +6,7 @@ uniform vec3 dv_k;
uniform float inversePeriod;
uniform float startTime;
uniform vec4 particleColour;
uniform float particleSize;
uniform float osg_FrameTime;
uniform float osg_DeltaFrameTime;
@@ -16,9 +17,6 @@ varying vec2 texCoord;
void main(void)
{
const float particleSize = 0.01;
const float particleSize2 = 0.0001;//particleSize*particleSize;
vec3 pos = position + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y);
float offset = gl_Vertex.z;
@@ -39,7 +37,7 @@ void main(void)
vec2 dp = vec2( -dv_normalized.y, dv_normalized.x ) * particleSize;
float area = length(dv.xy)*length(dp);
colour.a = 0.2+(particleSize2)/area;
colour.a = 0.05+(particleSize*particleSize)/area;
v1.xyz += dv*texCoord.y;