diff --git a/ogre2/src/Ogre2ParticleNoiseListener.cc b/ogre2/src/Ogre2ParticleNoiseListener.cc index ebf392118..d67cb6f90 100644 --- a/ogre2/src/Ogre2ParticleNoiseListener.cc +++ b/ogre2/src/Ogre2ParticleNoiseListener.cc @@ -17,6 +17,8 @@ #include +#include + #include "ignition/rendering/ogre2/Ogre2Includes.hh" #include "ignition/rendering/ogre2/Ogre2RenderTypes.hh" #include "ignition/rendering/ogre2/Ogre2Scene.hh" @@ -85,6 +87,8 @@ void Ogre2ParticleNoiseListener::preRenderTargetUpdate( pass->getFragmentProgramParameters(); psParams->setNamedConstant("particleStddev", static_cast(particleStddev)); + psParams->setNamedConstant("rnd", + static_cast(ignition::math::Rand::DblUniform(0.0, 1.0))); // get particle scatter ratio value from particle emitter user data // and pass that to the shaders diff --git a/ogre2/src/media/materials/programs/depth_camera_fs.glsl b/ogre2/src/media/materials/programs/depth_camera_fs.glsl index dd9a894ca..0d3109d58 100644 --- a/ogre2/src/media/materials/programs/depth_camera_fs.glsl +++ b/ogre2/src/media/materials/programs/depth_camera_fs.glsl @@ -39,7 +39,8 @@ uniform vec3 backgroundColor; uniform float particleStddev; uniform float particleScatterRatio; -uniform float time; +// rnd is a random number in the range of [0-1] +uniform float rnd; float packFloat(vec4 color) { @@ -106,7 +107,7 @@ void main() if (particle.x > 0 && particleDepth < fDepth) { // apply scatter effect so that only some of the smoke pixels are visible - float r = rand(inPs.uv0 + vec2(time, time)); + float r = rand(inPs.uv0 + vec2(rnd, rnd)); if (r < particleScatterRatio) { // set point to 3d pos of particle pixel @@ -115,14 +116,14 @@ void main() vec3 particlePoint = vec3(-particleViewSpacePos.z, -particleViewSpacePos.x, particleViewSpacePos.y); - float rr = rand(inPs.uv0 + vec2(1.0/time, time)) - 0.5; + float rr = rand(inPs.uv0 + vec2(rnd, rnd)) - 0.5; // apply gaussian noise to particle point cloud data // With large particles, the range returned are all from the first large // particle. So add noise with some mean values so that all the points are // shifted further out. This gives depth readings beyond the first few // particles and avoid too many early returns - vec3 noise = gaussrand(inPs.uv0, vec3(time, time, time), + vec3 noise = gaussrand(inPs.uv0, vec3(rnd, rnd, rnd), particleStddev, rr*rr*particleStddev*0.5).xyz; float noiseLength = length(noise); float particlePointLength = length(particlePoint); diff --git a/ogre2/src/media/materials/programs/gpu_rays_1st_pass_fs.glsl b/ogre2/src/media/materials/programs/gpu_rays_1st_pass_fs.glsl index 6911933bc..600bcfd45 100644 --- a/ogre2/src/media/materials/programs/gpu_rays_1st_pass_fs.glsl +++ b/ogre2/src/media/materials/programs/gpu_rays_1st_pass_fs.glsl @@ -38,7 +38,8 @@ uniform float max; uniform float particleStddev; uniform float particleScatterRatio; -uniform float time; +// rnd is a random number in the range of [0-1] +uniform float rnd; // see gaussian_noise_fs.glsl for documentation on the rand and gaussrand // functions @@ -92,20 +93,20 @@ void main() if (particle.x > 0.0 && particleDepth < fDepth) { // apply scatter effect so that only some of the smoke pixels are visible - float r = rand(inPs.uv0 + vec2(time, time)); + float r = rand(inPs.uv0 + vec2(rnd, rnd)); if (r < particleScatterRatio) { float pd = projectionParams.y / (particleDepth - projectionParams.x); vec3 point = inPs.cameraDir * pd; - float rr = rand(inPs.uv0 + vec2(1.0/time, time)) - 0.5; + float rr = rand(inPs.uv0 + vec2(rnd, rnd)) - 0.5; // apply gaussian noise to particle range data // With large particles, the range returned are all from the first large // particle. So add noise with some mean values so that all the points are // shifted further out. This gives depth readings beyond the first few // particles and avoid too many early returns - vec3 noise = gaussrand(inPs.uv0, vec3(time, time, time), + vec3 noise = gaussrand(inPs.uv0, vec3(rnd, rnd, rnd), particleStddev, rr*rr*particleStddev*0.5).xyz; float noiseLength = length(noise);