Exemple #1
0
//----------------------------------------------------------------------------
bool FxCompiler::UpdateEffect (const Program& vProgram,
    const Program& pProgram)
{
    InputArray vInputs, pInputs;
    OutputArray vOutputs, pOutputs;
    ConstantArray vConstants, pConstants;
    SamplerArray vSamplers, pSamplers;

    if (!Process(vProgram, vInputs, vOutputs, vConstants, vSamplers))
    {
        return false;
    }

    if (!Process(pProgram, pInputs, pOutputs, pConstants, pSamplers))
    {
        return false;
    }

    if (!UpdateShader(mVShader, vProgram, vInputs, vOutputs, vConstants,
        vSamplers))
    {
        return false;
    }

    if (!UpdateShader(mPShader, pProgram, pInputs, pOutputs, pConstants,
        pSamplers))
    {
        return false;
    }

    return true;
}
Exemple #2
0
bool DirectxEngine::InitialiseScene(const IScene& scene)
{
    m_data->shadows = std::make_unique<DxQuadMesh>(scene.Shadows(),
        [this](const D3DXMATRIX& world, int texture){ UpdateShader(world, texture); });

    m_data->textures.reserve(scene.Textures().size());
    for(const auto& texture : scene.Textures())
    {
        m_data->textures.push_back(std::unique_ptr<DxTexture>(
            new DxTexture(*texture)));
    }

    m_data->shaders.reserve(scene.Shaders().size());
    for(const auto& shader : scene.Shaders())
    {
        m_data->shaders.push_back(std::unique_ptr<DxShader>(
            new DxShader(*shader)));
    }

    m_data->meshes.reserve(scene.Meshes().size());
    for(const auto& mesh : scene.Meshes())
    {
        m_data->meshes.push_back(std::unique_ptr<DxMesh>(new DxMesh(*mesh,
            [this](const D3DXMATRIX& world, int texture){ UpdateShader(world, texture); })));
    }

    m_data->terrain.reserve(scene.Terrains().size());
    for(const auto& terrain : scene.Terrains())
    {
        m_data->terrain.push_back(std::unique_ptr<DxMesh>(new DxMesh(*terrain,
            [this](const D3DXMATRIX& world, int texture){ UpdateShader(world, texture); })));
    }

    m_data->waters.reserve(scene.Waters().size());
    for(const auto& water : scene.Waters())
    {
        m_data->waters.push_back(std::unique_ptr<DxMesh>(new DxMesh(*water,
            [this](const D3DXMATRIX& world, int texture){ UpdateShader(world, texture); })));
    }

    m_data->emitters.reserve(scene.Emitters().size());
    for(const auto& emitter : scene.Emitters())
    {
        m_data->emitters.push_back(std::unique_ptr<DxEmitter>(new DxEmitter(*emitter,
            [this](const D3DXMATRIX& world, const Particle& data){ UpdateShader(world, data); })));
    }

    return ReInitialiseScene();
}
Exemple #3
0
bool DirectxEngine::UpdateShader(const Water& water, 
                                 const IScene& scene, 
                                 float timer)
{
    if (UpdateShader(water, scene, true, timer))
    {
        auto& shader = m_data->shaders[water.ShaderID()];
        shader->UpdateConstantFloat("speed", &water.Speed(), 1);
        shader->UpdateConstantFloat("bumpIntensity", &water.Bump(), 1);
        shader->UpdateConstantFloat("bumpScale", &water.BumpScale().x, 2);
        shader->UpdateConstantFloat("uvScale", &water.UVScale().x, 2);
        shader->UpdateConstantFloat("deepColor", &water.Deep().r, 4);
        shader->UpdateConstantFloat("shallowColor", &water.Shallow().r, 4);
        shader->UpdateConstantFloat("reflectionTint", &water.ReflectionTint().r, 3);
        shader->UpdateConstantFloat("reflectionIntensity", &water.ReflectionIntensity(), 1);
        shader->UpdateConstantFloat("fresnal", &water.Fresnal().x, 3);

        const auto& waves = water.Waves();
        for (unsigned int i = 0; i < waves.size(); ++i)
        {
            const int offset = i*4; // Arrays pack in buffer of float4
            shader->UpdateConstantFloat("waveFrequency", &waves[i].amplitude, 1, offset);
            shader->UpdateConstantFloat("waveAmplitude", &waves[i].frequency, 1, offset);
            shader->UpdateConstantFloat("wavePhase", &waves[i].phase, 1, offset);
            shader->UpdateConstantFloat("waveDirectionX", &waves[i].directionX, 1, offset);
            shader->UpdateConstantFloat("waveDirectionZ", &waves[i].directionZ, 1, offset);
        }
        return true;
    }
    return false;
}
Exemple #4
0
bool DirectxEngine::UpdateShader(const Mesh& mesh, const IScene& scene)
{
    if (UpdateShader(mesh, scene, false))
    {
        SendAttributes(mesh);
        return true;
    }
    return false;
}
Exemple #5
0
bool DirectxEngine::UpdateShader(const Terrain& terrain, 
                                 const IScene& scene)
{
    if (UpdateShader(terrain, scene, false))
    {
        SendAttributes(terrain);
        return true;
    }
    return false;
}
Exemple #6
0
void DirectxEngine::RenderWater(const IScene& scene, float timer)
{
    for (auto& water : m_data->waters)
    {
        if (UpdateShader(water->GetWater(), scene, timer))
        {
            water->Render(m_data->context);
        }
    }
}
Exemple #7
0
void DirectxEngine::RenderTerrain(const IScene& scene)
{
    for (auto& terrain : m_data->terrain)
    {
        if (UpdateShader(terrain->GetTerrain(), scene))
        {
            terrain->Render(m_data->context);
        }
    }
}
Exemple #8
0
void DirectxEngine::RenderMeshes(const IScene& scene)
{
    for (auto& mesh : m_data->meshes)
    {
        if (UpdateShader(mesh->GetMesh(), scene))
        {
            mesh->Render(m_data->context);
        }
    }
}
Exemple #9
0
void LightManager::RemoveLight(LightHandle handle) {
	lights_.erase(handle);

	ScopedShader ss(*shader_);
	shader_->SetUniformInt(num_lights_unif_, lights_.size());

	UpdateShader();

	std::cout << "Removed light. Current number of lights: " << lights_.size() << "\n";
}
Exemple #10
0
void DirectxEngine::RenderShadows()
{
    if (UpdateShader(m_data->shadows->GetData()))
    {
        EnableDepthWrite(false);

        m_data->shadows->Render(m_data->context);

        EnableDepthWrite(true);
    }
}
Exemple #11
0
void DirectxEngine::RenderEmitters(const IScene& scene)
{
    EnableDepthWrite(false);

    for (auto& emitter : m_data->emitters)
    {
        if (UpdateShader(emitter->GetEmitter(), scene))
        {
            emitter->Render(m_data->context, 
                m_data->cameraPosition, m_data->cameraUp);
        }
    }

    EnableDepthWrite(true);
}
void LightPass::Start(Camera& camera){
	m_gbuffer->BindForLightingPass();

	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT);
	glStencilFunc(GL_NOTEQUAL, 0, 0xFF);

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendEquation(GL_FUNC_ADD);
	glBlendFunc(GL_ONE, GL_ONE);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);

	
	UpdateShader(camera);
}
void UpdateShaders()
{
	if (shaderupdatelistlock == 1)
		return;
	shaderupdatelistlock = 1;

	// update shaders and get a list of all dependent programs that must be relinked
	std::set<int> relink_programs;
	for (int n = 0; n < shaderupdatelist.size(); n++)
	{
		UpdateShader(shaderupdatelist[n], relink_programs);
	}
	shaderupdatelist.clear();

	for (std::set<int>::iterator it = relink_programs.begin(); it != relink_programs.end(); ++it)
	{
		RelinkProgram(*it);
	}

	shaderupdatelistlock = 0;
}
Exemple #14
0
void AppGUI::Tick(RenderEngine& engine)
{
    UpdateShader(engine);
    switch (m_cache->PageSelected.Get())
    {
    case PAGE_SCENE:
        UpdateScene(engine);
        break;
    case PAGE_AREA:
        UpdateTerrain(engine);
        UpdateTexture(engine);
        break;
    case PAGE_MESH:
        UpdateMesh();
        UpdateWater();
        UpdateEmitter();
        break;
    case PAGE_POST:
        UpdateLight();
        UpdatePost(engine);
        break;
    }
}