// Helper function static shared_ptr<UniversalMaterial> getSonicSculptureMaterial(int index) { shared_ptr<Texture> lambertianTex = Texture::createEmpty(format("Sonic Sculpture %d", index), 512, 1, ImageFormat::RGBA16F()); static shared_ptr<Framebuffer> fb = Framebuffer::create("Sonic Sculpture Lambertian FB Clearer"); fb->set(Framebuffer::COLOR0, lambertianTex); RenderDevice* rd = RenderDevice::current; rd->push2D(fb); { rd->setColorClearValue(Color3::white() * 0.9f); rd->clear(); } rd->pop2D(); lambertianTex->generateMipMaps(); UniversalMaterial::Specification spec; spec.setLambertian(lambertianTex); static uint32 dummyBytes[512]; for (int i = 0; i < 512; ++i) { dummyBytes[i] = 4294967295; } shared_ptr<Texture> emissiveTex = Texture::fromMemory(format("Sonic Sculpture %d Emissive", index), dummyBytes, ImageFormat::RGBA8(), 512, 1, 1, 1, ImageFormat::RGBA16F()); fb->set(Framebuffer::COLOR0, emissiveTex); rd->push2D(fb); { rd->setColorClearValue(Color3::black()); rd->clear(); } rd->pop2D(); emissiveTex->generateMipMaps(); spec.setEmissive(emissiveTex); //spec.setBump(System::findDataFile("material/10538-bump.jpg")); return UniversalMaterial::create(spec); }
void App::handlePlayPulses() { for (int i = m_currentPlayPulses.size() - 1; i >= 0; --i) { int currentSampleIndex = (g_sampleWindowIndex * g_currentAudioBuffer.size()); shared_ptr<SonicSculpturePiece> piece = m_currentPlayPulses[i].piece; int endIndex = m_currentPlayPulses[i].initialSample + (piece->size() * g_currentAudioBuffer.size()); RenderDevice* rd = RenderDevice::current; static shared_ptr<Framebuffer> playPulseFB = Framebuffer::create("Play Pulse FB"); shared_ptr<UniversalMaterial> material = piece->material(); if (currentSampleIndex >= endIndex) { playPulseFB->set(Framebuffer::COLOR0, material->emissive().texture()); rd->push2D(playPulseFB); { rd->setColorClearValue(Color3::black()); rd->clear(); } rd->pop2D(); material->emissive().texture()->generateMipMaps(); m_currentPlayPulses.remove(i); continue; } float alpha = float(currentSampleIndex - m_currentPlayPulses[i].initialSample) / (endIndex - m_currentPlayPulses[i].initialSample); playPulseFB->set(Framebuffer::COLOR0, material->emissive().texture()); rd->push2D(playPulseFB); { Args args; args.setUniform("pulsePos", alpha * playPulseFB->width()); args.setRect(rd->viewport()); LAUNCH_SHADER("playPulse.pix", args); } rd->pop2D(); material->emissive().texture()->generateMipMaps(); } }