예제 #1
0
void App::RenderText(const std::wstring& text, Float2 pos)
{
    ID3D11DeviceContext* context = deviceManager.ImmediateContext();

    // Set the backbuffer and viewport
    ID3D11RenderTargetView* rtvs[1] = { deviceManager.BackBuffer() };
    context->OMSetRenderTargets(1, rtvs, NULL);

    float clearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
    context->ClearRenderTargetView(rtvs[0], clearColor);

    SetViewport(context, deviceManager.BackBufferWidth(), deviceManager.BackBufferHeight());

    // Draw the text
    Float4x4 transform;
    transform.SetTranslation(Float3(pos.x, pos.y,0.0f));
    spriteRenderer.Begin(context, SpriteRenderer::Point);
    spriteRenderer.RenderText(font, text.c_str(), transform.ToSIMD());
    spriteRenderer.End();

    // Present
    deviceManager.SwapChain()->Present(0, 0);

    // Pump the message loop
    window.MessageLoop();
}
예제 #2
0
Float4x4 Scene::createBase(float scale, const Float3 &pos, const Quaternion &rot)
{
	// Assume uniform scaling
	Quaternion rotNorm = Quaternion::Normalize(rot);
	Float4x4 ret = rotNorm.ToFloat4x4();
	ret.Scale(Float3(scale));
	ret.SetTranslation(pos);
	return ret;
}
예제 #3
0
void ShadowsApp::RenderMainPass()
{
    PIXEvent event(L"Main Pass");

    ID3D11DeviceContextPtr context = deviceManager.ImmediateContext();

    ID3D11RenderTargetView* renderTargets[1] = { NULL };
    ID3D11DepthStencilView* ds = depthBuffer.DSView;

    context->OMSetRenderTargets(1, renderTargets, ds);

    D3D11_VIEWPORT vp;
    vp.Width = static_cast<float>(colorTarget.Width);
    vp.Height = static_cast<float>(colorTarget.Height);
    vp.TopLeftX = 0.0f;
    vp.TopLeftY = 0.0f;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    context->RSSetViewports(1, &vp);

    float clearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
    context->ClearRenderTargetView(colorTarget.RTView, clearColor);
    context->ClearDepthStencilView(ds, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

    Float4x4 meshWorld = Float4x4::ScaleMatrix(MeshScales[AppSettings::CurrentScene]);
    Float4x4 characterWorld = Float4x4::ScaleMatrix(CharacterScale);
    Float4x4 characterOrientation = Quaternion::ToFloat4x4(AppSettings::CharacterOrientation);
    characterWorld = characterWorld * characterOrientation;
    characterWorld.SetTranslation(CharacterPos);

    {
        ProfileBlock block(L"Depth Prepass");
        if(AppSettings::GPUSceneSubmission)
            meshRenderer.RenderDepthGPU(context, camera, meshWorld, characterWorld, false);
        else
            meshRenderer.RenderDepthCPU(context, camera, meshWorld, characterWorld, false);
    }

    if(AppSettings::AutoComputeDepthBounds)
        meshRenderer.ReduceDepth(context, depthBuffer.SRView, camera);

    if(AppSettings::GPUSceneSubmission)
        meshRenderer.RenderShadowMapGPU(context, camera, meshWorld, characterWorld);
    else
        meshRenderer.RenderShadowMap(context, camera, meshWorld, characterWorld);

    renderTargets[0] = colorTarget.RTView;
    context->OMSetRenderTargets(1, renderTargets, ds);

    context->RSSetViewports(1, &vp);

    Float3 lightDir = AppSettings::LightDirection;
    meshRenderer.Render(context, camera, meshWorld, characterWorld);

    skybox.RenderSky(context, lightDir, true, camera.ViewMatrix(), camera.ProjectionMatrix());
}
예제 #4
0
void ShadowsApp::Initialize()
{
    App::Initialize();

    AppSettings::Initialize(deviceManager.Device());

    TwHelper::SetGlobalHelpText("Shadows Sample - implements various cascaded shadow map techniques, "
                                "as well as several methods for filtering shadow maps");

    ID3D11DevicePtr device = deviceManager.Device();
    ID3D11DeviceContextPtr deviceContext = deviceManager.ImmediateContext();

    // Camera setup
    camera.SetPosition(Float3(40.0f, 5.0f, 5.0f));
    camera.SetYRotation(-XM_PIDIV2);

    // Load the meshes
    for(uint32 i = 0; i < uint32(Scene::NumValues); ++i)
    {
        wstring path(L"..\\Content\\Models\\");
        path += MeshFileNames[i];
        models[i].CreateFromSDKMeshFile(device, path.c_str());
    }

    wstring characterPath(L"..\\Content\\Models\\Soldier\\Soldier.sdkmesh");
    characterMesh.CreateFromSDKMeshFile(device, characterPath.c_str());

    meshRenderer.Initialize(device, deviceManager.ImmediateContext());

    ID3D11DeviceContext* context = deviceManager.ImmediateContext();

    Float4x4 meshWorld = Float4x4::ScaleMatrix(MeshScales[(int)AppSettings::CurrentScene]);
    meshRenderer.SetSceneMesh(context, &models[(int)AppSettings::CurrentScene], meshWorld);

    Float4x4 characterWorld = Float4x4::ScaleMatrix(CharacterScale);
    Float4x4 characterOrientation = Quaternion::ToFloat4x4(AppSettings::CharacterOrientation);
    characterWorld = characterWorld * characterOrientation;
    characterWorld.SetTranslation(CharacterPos);
    meshRenderer.SetCharacterMesh(context, &characterMesh, characterWorld);

    skybox.Initialize(device);

    // Init the post processor
    postProcessor.Initialize(device);
}
예제 #5
0
void Profiler::EndFrame(SpriteRenderer& spriteRenderer, SpriteFont& spriteFont)
{
    // If any profile was previously active but wasn't used this frame, it could still
    // have outstanding queries that we need to keep running
    for(auto iter = profiles.begin(); iter != profiles.end(); iter++)
    {
        const std::wstring& name = (*iter).first;
        ProfileData& profile = (*iter).second;

        if(!profile.CPUProfile && !profile.Active && profile.DisjointQuery[0] != nullptr)
        {
            StartProfile(name);
            EndProfile(name);
            profile.Active = false;
        }
    }

    currFrame = (currFrame + 1) % QueryLatency;

    Float4x4 transform;
    transform.SetTranslation(Float3(25.0f, 100.0f, 0.0f));

    // Iterate over all of the profiles
    for(auto iter = profiles.begin(); iter != profiles.end(); iter++)
    {
        ProfileData& profile = (*iter).second;
        profile.QueryFinished = false;

        float time = 0.0f;
        if(profile.CPUProfile)
        {
            time = (profile.EndTime - profile.StartTime) / 1000.0f;
        }
        else
        {
            if(profile.DisjointQuery[currFrame] == NULL)
                continue;

            // Get the query data
            uint64 startTime = 0;
            while(context->GetData(profile.TimestampStartQuery[currFrame], &startTime, sizeof(startTime), 0) != S_OK);

            uint64 endTime = 0;
            while(context->GetData(profile.TimestampEndQuery[currFrame], &endTime, sizeof(endTime), 0) != S_OK);

            D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointData;
            while(context->GetData(profile.DisjointQuery[currFrame], &disjointData, sizeof(disjointData), 0) != S_OK);

            if(disjointData.Disjoint == false)
            {
                uint64 delta = endTime - startTime;
                float frequency = static_cast<float>(disjointData.Frequency);
                time = (delta / frequency) * 1000.0f;
            }
        }

        profile.TimeSamples[profile.CurrSample] = time;
        profile.CurrSample = (profile.CurrSample + 1) % ProfileData::FilterSize;

        float sum = 0.0f;
        for(UINT i = 0; i < ProfileData::FilterSize; ++i)
            sum += profile.TimeSamples[i];
        time = sum / ProfileData::FilterSize;

        if(profile.Active)
        {
            wstring output = (*iter).first + L": " + ToString(time) + L"ms";
            spriteRenderer.RenderText(spriteFont, output.c_str(), transform, Float4(1.0f, 1.0f, 0.0f, 1.0f));
            transform._42 += 25.0f;
        }

        profile.Active = false;
    }
}
예제 #6
0
Float4x4 Float4x4::TranslationMatrix(const Float3& t)
{
    Float4x4 m;
    m.SetTranslation(t);
    return m;
}