Added support for point sprite particle effects.
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include <osg/PointSprite>
|
||||
#include <osg/Program>
|
||||
#include <osg/Fog>
|
||||
#include <osg/Point>
|
||||
#include <osg/PointSprite>
|
||||
#include <osg/io_utils>
|
||||
|
||||
float random(float min,float max) { return min + (max-min)*(float)rand()/(float)RAND_MAX; }
|
||||
@@ -252,7 +254,7 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
|
||||
osg::Geometry* line_geometry = 0;
|
||||
osg::Geometry* point_geometry = 0;
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
quad_geometry = new PrecipitationGeometry;
|
||||
quad_geometry->setUseVertexBufferObjects(true);
|
||||
quad_geometry->setInitialBound(bb);
|
||||
@@ -269,7 +271,7 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if 0
|
||||
line_geometry = new PrecipitationGeometry;
|
||||
line_geometry->setUseVertexBufferObjects(true);
|
||||
line_geometry->setInitialBound(bb);
|
||||
@@ -287,7 +289,7 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
point_geometry = new PrecipitationGeometry;
|
||||
point_geometry->setUseVertexBufferObjects(true);
|
||||
point_geometry->setInitialBound(bb);
|
||||
@@ -300,7 +302,14 @@ osg::Node* createRainEffect(const osg::BoundingBox& bb, const osg::Vec3& velocit
|
||||
|
||||
// get shaders from source
|
||||
program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, osgDB::findDataFile("point_rain.vert")));
|
||||
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile("point_rain.frag")));
|
||||
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile("rain.frag")));
|
||||
|
||||
/// Setup the point sprites
|
||||
osg::PointSprite *sprite = new osg::PointSprite();
|
||||
point_stateset->setTextureAttributeAndModes(0, sprite, osg::StateAttribute::ON);
|
||||
|
||||
point_stateset->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
uniform sampler2D baseTexture;
|
||||
uniform vec4 particleColour;
|
||||
varying vec2 texCoord;
|
||||
varying vec4 colour;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
gl_FragColor = particleColour * texture2D( baseTexture, texCoord);
|
||||
gl_FragColor = colour * texture2D( baseTexture, texCoord);
|
||||
}
|
||||
|
||||
@@ -5,18 +5,29 @@ uniform vec3 dv_k;
|
||||
|
||||
uniform float inversePeriod;
|
||||
uniform float startTime;
|
||||
uniform vec4 particleColour;
|
||||
|
||||
uniform float osg_FrameTime;
|
||||
|
||||
varying vec4 colour;
|
||||
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;
|
||||
|
||||
vec3 v_current = pos + dv_k * fract( (osg_FrameTime - startTime)*inversePeriod - gl_Vertex.z);
|
||||
|
||||
colour = particleColour;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(v_current,1.0);
|
||||
|
||||
float pointSize = min(abs(1280*particleSize / gl_Position.w), 20.0);
|
||||
gl_PointSize = max(ceil(pointSize),2);
|
||||
|
||||
colour.a = 0.2+(pointSize)/(gl_PointSize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user