public ParticleRenderer() { // create the model, which contains the textures that represent the particles. components.Add(model = new DefaultParticleModel(particleArrayWidth, particleArrayHeight)); // create the render target, which is used to write to the model components.Add(renderTarget = new PosColRenderTarget(particleArrayWidth, particleArrayHeight) { DrawOrder = 1, IsFinalOutput = false, SetBuffers = (rt) => { rt.SetOutput(0, model.ParticlePositionWrite); rt.SetOutput(1, model.ParticleColourWrite); } }); // Add operator(s) to renderTarget. The operators write to the render target to alter the particles. renderTarget.Add(operator1 = new ParticleOperator() { IsFinalOutput = true, TextureBinds = () => { if (frameData != null) { frameData.GlobalTextures.SpectrumTex.Bind(TextureUnit.Texture0); frameData.GlobalTextures.AudioDataTex.Bind(TextureUnit.Texture1); model.ParticlePositionRead.Bind(TextureUnit.Texture2); model.ParticlePositionPrevious.Bind(TextureUnit.Texture3); model.ParticleColourRead.Bind(TextureUnit.Texture4); } }, SetShaderUniforms = (sp) => { if (sp != null && frameData != null) { sp .SetUniform("time", (float)(frameData.Time)) .SetUniform("deltaTime", deltaTime) .SetUniform("spectrumTex", 0) .SetUniform("audioDataTex", 1) .SetUniform("particlePosTex", 2) .SetUniform("particlePosPrevTex", 3) .SetUniform("particleColTex", 4) .SetUniform("currentPosition", frameData.GlobalTextures.SamplePositionRelative) .SetUniform("currentPositionEst", frameData.GlobalTextures.EstimatedSamplePositionRelative); } } }); // create the renderer, which renders GL_POINTS using vertices that point to texels in the model textures. components.Add(renderer = new ColourParticleRenderer("Particles/particles_col.vert.glsl", "Particles/particles_col.frag.glsl", particleArrayWidth, particleArrayHeight) { DrawOrder = 2, IsFinalOutput = true, ParticlePositionTextureFunc = () => model.ParticlePositionWrite, ParticleColourTextureFunc = () => model.ParticleColourWrite }); ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(60f), 16f / 9f, 0.0001f, 10f); ViewMatrix = Matrix4.LookAt(new Vector3(0f, 0f, -1f), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)); ModelMatrix = Matrix4.Identity; }
public ParticleTestBench() : base(800, 600, GraphicsMode.Default, "Particles or summin or nuttin") { VSync = VSyncMode.Off; Load += ParticleTestBench_Load; Unload += ParticleTestBench_Unload; UpdateFrame += ParticleTestBench_UpdateFrame; RenderFrame += ParticleTestBench_RenderFrame; Resize += ParticleTestBench_Resize; // set default shader loader ShaderProgram.DefaultLoader = new OpenTKExtensions.Loaders.MultiPathFileSystemLoader(SHADERPATH); //OpenTK.Input.Keyboard.GetState() components.Add(camera = new WalkCamera() { FOV = 75.0f, ZFar = 10.0f, ZNear = 0.001f, MovementSpeed = 0.0001f, LookMode = WalkCamera.LookModeEnum.Mouse1, Position = new Vector3(0f, 0f, 0f), EyeHeight = 0f }, 1); components.Add(resources = new CommonResources()); // Particle model components.Add(model = new MotionParticleModel(particleArrayWidth, particleArrayHeight)); // Particle render target components.Add(particleRenderTarget = new PosVelColRenderTarget(particleArrayWidth, particleArrayHeight) { DrawOrder = 1, SetBuffers = (rt) => { rt.SetOutput(0, model.ParticlePositionWrite); rt.SetOutput(1, model.ParticleVelocityWrite); rt.SetOutput(2, model.ParticleColourWrite); } }); // particle operator particleRenderTarget.Add(new OperatorTest()); /* * particleRenderTarget.Add(particleOperator = new RaymarchOperator() * { * TextureBinds = () => * { * model.ParticlePositionRead.Bind(TextureUnit.Texture0); * model.ParticleVelocityRead.Bind(TextureUnit.Texture1); * model.ParticleColourRead.Bind(TextureUnit.Texture2); * }, * SetShaderUniforms = (sp) => * { * sp.SetUniform("time", (float)timer.Elapsed.TotalSeconds); * sp.SetUniform("particlePositionTexture", 0); * sp.SetUniform("particleVelocityTexture", 1); * sp.SetUniform("particleColourTexture", 2); * } * });*/ // Render particles components.Add(particleRenderer = new ColourParticleRenderer(particleArrayWidth, particleArrayHeight) { DrawOrder = 2, ParticlePositionTextureFunc = () => model.ParticlePositionWrite, ParticleColourTextureFunc = () => model.ParticleColourWrite }); }