bool GraphicsSystem::Frame(Scene *_scene)
{
    m_OpenGL->BeginScene(0.0f, 0.0f, 0.0, 1.0f);

    if (!RenderStaticEnv(_scene))
    {
        return false;
    }

    if (!RenderSceneObjects(_scene))
    {
        return false;
    }

    m_OpenGL->EndScene();

	return true;
}
Exemple #2
0
// Renders all meshes in the model, with shadows
void MeshRenderer::Render(ID3D11DeviceContext* context, const Camera& camera, const Float4x4& world,
                          ID3D11ShaderResourceView* envMap, const SH9Color& envMapSH,
                          Float2 jitterOffset)
{
    PIXEvent event(L"Mesh Rendering");

	//Set Cubemap

	// DoSceneObjectsFrustumTests(camera, false);

    // Set states
    float blendFactor[4] = {1, 1, 1, 1};
    context->OMSetBlendState(_blendStates.BlendDisabled(), blendFactor, 0xFFFFFFFF);

	// TODO: this is super bad coupling... but we are out of time
	if (AppSettings::CurrentShadingTech == ShadingTech::Forward)
	{
		context->OMSetDepthStencilState(_depthStencilStates.DepthEnabled(), 0);
	}
	else if (AppSettings::CurrentShadingTech == ShadingTech::Clustered_Deferred)
	{
		context->OMSetDepthStencilState(_depthStencilStates.DepthWriteEnabled(), 0);
	}
    context->RSSetState(_rasterizerStates.BackFaceCull());

    ID3D11SamplerState* sampStates[3] = {
        _samplerStates.Anisotropic(),
        _evsmSampler,
        _samplerStates.LinearClamp(),
    };

    context->PSSetSamplers(0, 3, sampStates);

	// set PS constants
	// TODO: make deferred a unique structure
	//if (AppSettings::CurrentShadingTech == ShadingTech::Forward)
	{
		// Perframe
		_meshPSConstants.Data.CameraPosWS = camera.Position();
		_meshPSConstants.Data.OffsetScale = OffsetScale;
		_meshPSConstants.Data.PositiveExponent = PositiveExponent;
		_meshPSConstants.Data.NegativeExponent = NegativeExponent;
		_meshPSConstants.Data.LightBleedingReduction = LightBleedingReduction;
		_meshPSConstants.Data.View = Float4x4::Transpose(camera.ViewMatrix());
		_meshPSConstants.Data.Projection = Float4x4::Transpose(camera.ProjectionMatrix());
		_meshPSConstants.Data.EnvironmentSH = envMapSH;
		_meshPSConstants.Data.RTSize.x = float(GlobalApp->DeviceManager().BackBufferWidth());
		_meshPSConstants.Data.RTSize.y = float(GlobalApp->DeviceManager().BackBufferHeight());
		_meshPSConstants.Data.JitterOffset = jitterOffset;
	}

    // Set shaders
    context->DSSetShader(nullptr, nullptr, 0);
    context->HSSetShader(nullptr, nullptr, 0);
    context->GSSetShader(nullptr, nullptr, 0);

	_scene->sortSceneObjects(camera.ViewMatrix());
	RenderSceneObjects(context, world, camera, envMap, envMapSH, jitterOffset, _scene->getStaticOpaqueObjectsPtr(), _scene->getNumStaticOpaqueObjects());
	RenderSceneObjects(context, world, camera, envMap, envMapSH, jitterOffset, _scene->getDynamicOpaqueObjectsPtr(), _scene->getNumDynamicOpaueObjects());

	// TODO: refactor
    ID3D11ShaderResourceView* nullSRVs[8] = { nullptr };
    context->PSSetShaderResources(0, 8, nullSRVs);
}