示例#1
0
// 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);
}
示例#2
0
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();
    }
}
示例#3
0
文件: App.cpp 项目: lieff/g3d
// Called before the application loop begins.  Load data here and
// not in the constructor so that common exceptions will be
// automatically caught.
void App::onInit() {
    RenderDevice* rd = renderDevice;

    Vector2 destSize(1024, 1024);
    const Rect2D& dest = Rect2D::xywh(Vector2(0, 0), destSize);

    Args args;
//    args.appendToPreamble("#define KERNEL_RADIUS 9\nfloat gaussCoef[KERNEL_RADIUS] = float[KERNEL_RADIUS](0.00194372, 0.00535662, 0.01289581, 0.02712094, 0.04982645, 0.07996757, 0.11211578, 0.13731514, 0.14691596);");

    rd->push2D(dest); {
        args.setRect(dest);
        LAUNCH_SHADER("apply.*", args);
    } rd->pop2D();

    // Or Equivalently:
    //GaussianBlur::apply(renderDevice, Texture::createEmpty("test",1024,1024));
}