//===============================================================================================================================
void OceanEnvironment::Render()
{
	//mCubeAboveWater->SetLightBuffer(ZShadeSandboxLighting::LightManager::Instance()->GetLightBuffer());
	//mCubeAboveWater->SetLightBuffer(ZShadeSandboxLighting::LightManager::Instance()->GetSunLightBuffer());

	//mCubeBelowWater->SetLightBuffer(ZShadeSandboxLighting::LightManager::Instance()->GetLightBuffer());
	//mCubeBelowWater->SetLightBuffer(ZShadeSandboxLighting::LightManager::Instance()->GetSunLightBuffer());

	//Quick wireframe mode
	if( Quickwire() )
	{
		mWater->SetWireframe(true);
		//mOceanSurface->SetWireframe(true);
		mSky->SetWireframe(true);
		mCubeAboveWater->SetWireframe(true);
		mCubeBelowWater->SetWireframe(true);
		mLakeBed->SetWireframe(true);
		m_D3DSystem->TurnOnWireframe();
	}
	
	//
	// Render the mesh representing the floor of the water system
	//
	
	//mLakeBed->SetDepthMap(mShadowTexture->SRView);
	mLakeBed->Render(m_CameraSystem, mDirLight1->Perspective());
	
	//
	// Render a cube in the water
	//
	
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	mrp.light = mDirLight1;
	mrp.useInstancing = false;
	
	mCubeAboveWater->SetFarPlane(m_EngineOptions->fFarPlane);
	mCubeAboveWater->SetShadowMapSRV(mShadowTexture->SRView);
	mCubeAboveWater->Render(mrp);
	mCubeBelowWater->SetFarPlane(m_EngineOptions->fFarPlane);
	mCubeBelowWater->SetShadowMapSRV(mShadowTexture->SRView);
	mCubeBelowWater->Render(mrp);
	
	//
	// Render the ocean
	//
	
	if (!bWireframeMode && !Quickwire()) m_D3DSystem->TurnOffCulling();
	if (Quickwire())
	{
		mWater->SetWireframe(true);
		m_D3DSystem->TurnOnWireframe();
	}
	mWater->SetFarPlane(m_EngineOptions->fFarPlane);
	mWater->Render(m_CameraSystem, false, mReflectionTexture->SRView, mRefractionTexture->SRView);
	//mOceanSurface->SetReflectionMap(mReflectionTexture->SRView);
	//mOceanSurface->SetRefractionMap(mRefractionTexture->SRView);
	//mOceanSurface->Render(m_CameraSystem.get(), fSeaLevel, fFrameTime);
	if (!bWireframeMode && !Quickwire()) m_D3DSystem->TurnOnCulling();
}
Esempio n. 2
0
//===============================================================================================================================
void RoomEnvironment::Render()
{
	if( Quickwire() )
	{
		mRoom->SetWireframe(true);
		ToggleSpawnedMeshItemsWireframe(true);
		ToggleLightMeshWireframe(true);
		
		m_D3DSystem->TurnOnWireframe();
	}
	else
	{
		if (!bWireframeMode)
		{
			m_D3DSystem->TurnOffCulling();
		}
	}
	
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	mrp.light = mDirLight1;
	
	mRoom->Render(mrp);
	
	RenderSpawnedMeshItems(mrp);
	RenderLightMesh(mrp);
}
//===============================================================================================================================
void VolumeEnvironment::Render()
{
	//Quick wireframe mode
	if( Quickwire() )
	{
		mCube->SetWireframe( true );
		mVolume->SetWireframe( true );
		m_D3DSystem->TurnOnWireframe();
	}
	
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	
	//
	// Render the cube with defaults
	//
	
	mCube->Render(mrp);
	
	//
	// Render the volume with defaults
	//
	
	m_D3DSystem->TurnOnWireframe();
	mVolume->Render(mrp);
}
//===============================================================================================================================
void IndoorEnvironment::Render()
{
	if( Quickwire() )
	{
		mCube->SetWireframe( true );
		
		m_D3DSystem->TurnOnWireframe();
	}
	else
	{
		// We want to see inside the cube
		if (!bWireframeMode)
			m_D3DSystem->TurnOffCulling();
	}
	
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	mCube->Render(mrp);
}
//===============================================================================================================================
void BlurredEnvironment::Render()
{
	if( Quickwire() )
	{
		m_pCube->SetWireframe( true );
		m_pNoBlurCube->SetWireframe( true );
		m_D3DSystem->TurnOnWireframe();
	}

	m_D3DSystem->TurnOnZBuffer();
	
	// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	m_pCube->Render(mrp);
	//m_pNoBlurCube->Render(mCamera, TriangleList, false, true);

	/*if (m_VertextProcessEnable)
	{
		ID3D11ShaderResourceView* pInputSRV = mD3DSystem->GetColorRenderTarget()->GetSRV();
		DepthStencilBuffer* pDepth = mD3DSystem->GetDepthStencilBuffer();
		ID3D11RenderTargetView* pOutputRTV = mD3DSystem->GetBackBufferRTV();

		m_pSimplePP->Render(pInputSRV, pOutputRTV);

		Reset the backbuffer and viewports after Vertext processing and turn the z buffer back on
		mD3DSystem->SetBackBufferRenderTarget(m_VertextProcessEnable);
		mD3DSystem->ResetViewport();
		mD3DSystem->TurnOnZBuffer();
	}*/

	RenderSceneToTexture();
	DownSampleTexture();
	RenderHorizontalBlurToTexture();
	RenderVerticalBlurToTexture();
	UpSampleTexture();
	Render2DTextureScene();
}
//===============================================================================================================================
void TerrainEnvironment::Render()
{
	//RenderTerrainShadowSSAO();

	//We now get the position of the camera and then get the height of the triangle that would
	//be directly underneath it. Once we get the height back we set the height of the camera two
	//units directly above the triangle's height. This way when the camera moves it automatically
	//follows the exact height of the terrain.
	if (bClipCameraToTerrain)
	{
		float height = 0.0f;
		XMFLOAT3 eye = m_CameraSystem->Position();

		// Apply simple gravity
		//m_CameraSystem->SetPositionY(eye.y - 1.0f);

		// Get the height of the triangle that is directly underneath the given camera position.
		if (m_pQuadTreeMesh->GetHeightAtPosition(eye, height))
		{
			// If there was a triangle under the camera then position the camera just above it by two units.
			m_CameraSystem->SetPositionY(height + 4.0f);
		}
	}

	// Mouse Picking Terrain Collision Test
	mPickingRay = m_CameraSystem->PickingRay(mLastMousePos.x, mLastMousePos.y, m_pQuadTreeRenderer->GetWorld());

	if (mPickingRay != NULL)
	{
		//if (bLeftMouseDown)
		{
			//bLeftMouseDown = false;
			bool hit = false;
			XMFLOAT3 hitPoint;
			ZShadeSandboxMath::Ray ray = *mPickingRay;
			m_pQuadTreeMesh->Intersects(ray, hit, hitPoint);
			if (hit)
			{
				// Create a sphere at the point of intersection
				mPickingSphere->Position() = hitPoint;
			}
		}
	}

	if (!bWireframeMode)
		m_D3DSystem->TurnOnCulling();

	//Quick wireframe mode
	if (Quickwire())
	{
		m_pQuadTreeRenderer->SetWireframe(true);

		vector<ZShadeSandboxMesh::CustomMesh*>::iterator it = m_SpawnedMeshContainer.begin();
		for (; it != m_SpawnedMeshContainer.end(); it++)
		{
			(*it)->SetWireframe(true);
		}

		mSky->SetWireframe(true);

		m_D3DSystem->TurnOnWireframe();
	}

	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	mrp.light = mDirLight1;

	vector<ZShadeSandboxMesh::CustomMesh*>::iterator it = m_SpawnedMeshContainer.begin();
	for (; it != m_SpawnedMeshContainer.end(); it++)
	{
		if ((*it)->MeshType() == ZShadeSandboxMesh::EMeshType::CYLINDER)
		{
			if (!bWireframeMode && !Quickwire())
				m_D3DSystem->TurnOffCulling();
		}

		(*it)->Render(mrp);

		if ((*it)->MeshType() == ZShadeSandboxMesh::EMeshType::CYLINDER)
		{
			if (!bWireframeMode && !Quickwire())
				m_D3DSystem->TurnOnCulling();
		}
	}

	mrp.tessellate = false;
	mrp.renderType = ZShadeSandboxMesh::ERenderType::eTriangleList;

	//
	//Render the terrain
	//

	float    fMinTessellation = 0.0f;
	float    fMaxTessellation = 64.0f;

	XMFLOAT4 fogColor;
	XMStoreFloat4(&fogColor, DXColors::Silver);

	ZShadeSandboxTerrain::TerrainShadingConst tsc;
	tsc.g_EyePosW = m_CameraSystem->Position();
	tsc.g_fogThinning = 1000;
	tsc.g_fogAltitude = 10;
	tsc.g_fogNear = 5.0f;
	tsc.g_fogFar = 1000.0f;
	tsc.g_fogColor = fogColor;
	tsc.g_TextureAmount = 1; // Amount of Layer textures (Not needed)
	tsc.g_seaLevel = fSeaLevel;
	tsc.g_waterBodyColor = XMFLOAT4(0.07f, 0.15f, 0.2f, 0.0f);
	tsc.g_useClippingPlane = 0;
	tsc.g_UseSobelFilter = 0;
	tsc.g_useNormalMap = (bToggleTerrainNormalMap == true) ? 1 : 0;
	tsc.g_useShadowMap = (bToggleTerrainShadow == true) ? 1 : 0;
	tsc.g_useSSAO = (bToggleTerrainSSAO == true) ? 1 : 0;
	tsc.g_MinDist = fMinDist;
	tsc.g_MaxDist = fMaxDist;
	tsc.g_MinTess = fMinTessellation;
	tsc.g_MaxTess = fMaxTessellation;
	tsc.g_FrustumCull = 0;
	tsc.g_HeightScale = fHeightScale;// gHeightScale;
	tsc.g_TerrSize = fTerrSize;// gTerrSize;
	tsc.g_TextureWidth = fMapSize;
	tsc.g_TextureHeight = fMapSize;
	tsc.g_TexelCellSpaceU = (1 / fMapSize);
	tsc.g_TexelCellSpaceV = (1 / fMapSize);
	tsc.g_ClipPlane = XMFLOAT4(0, 0, 0, 0);
	tsc.g_FarPlane = mEngineOptions->fFarPlane;
	tsc.g_MapSize = fMapSize;
	tsc.g_DetailBrightness = 1.8f;
	tsc.g_useReflection = false;

	m_pQuadTreeMesh->HeightScale() = fHeightScale;
	m_pQuadTreeMesh->TerrainZScale() = fTerrSize;

	m_pQuadTreeRenderer->Render(m_CameraSystem, mDirLight1, tsc);

	//
	// Render the picking sphere
	//

	if (mPickingSphere != NULL)
	{
		mPickingSphere->Render(mrp);
	}

	//
	// Render the sphere mesh for the lights in the scene
	//

	RenderLightMesh(mrp);
}
//===============================================================================================================================
void ModelEnvironment::Render()
{
	// Mouse Picking
	XMMATRIX world = XMMatrixIdentity();
	mPickingRay = m_CameraSystem->PickingRay(mLastMousePos.x, mLastMousePos.y, world);
	if (mPickingRay != NULL)
	{
		if (bLeftMouseDown)
		{
			bLeftMouseDown = false;
			bool hit = false;
			XMFLOAT3 hitPoint;
			ZShadeSandboxMath::Ray ray = *mPickingRay;
			// Picking Test goes here
			if (hit)
			{
				// Place the sphere at the point of intersection
				mPickingSphere->Position() = hitPoint;
			}
		}
	}
	
	if (!bWireframeMode)
	{
		m_D3DSystem->TurnOnCulling();
	}
	
	//Quick wire mode to view the objects underlying triangles quickly
	if( Quickwire() )
	{
		mPlane->SetWireframe(true);
		
		ToggleSpawnedMeshItemsWireframe(true);
		
		mPickingSphere->SetWireframe(true);
		
		mSpaceCompound->SetWireframe(true);
		mHuman->SetWireframe(true);
		
		ToggleLightMeshWireframe(true);
		
		m_D3DSystem->TurnOnWireframe();
	}
	
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	mrp.light = mDirLight1;
	
	RenderSpawnedMeshItems(mrp);

	mrp.useInstancing = false;
	
	// Render the plane in tessellation mode
	//m_D3DSystem->TurnOnWireframe();
	//mPlane->SetWireframe(true);
	//mrp.fTessellationFactor = m_TessFactor;
	//mrp.bTessellate = true;
	//mrp.renderType = ZShadeSandboxMesh::ERenderType::e3ControlPointPatchList;
	mPlane->EnableShadowMap(bEnableShadows);
	mPlane->SetShadowMapSRV(mShadowTexture->SRView);
	mPlane->SetSSAOMapSRV(0);
	mPlane->Render(mrp);
	
	// Uncomment if using the picking sphere
	//mrp.bTessellate = false;
	//mrp.rt = RenderType::eTriangleList;
	//mPickingSphere->EnableShadowMap(bEnableShadows);
	//mPickingSphere->SetShadowMapSRV(mShadowTexture->SRView);
	//mPickingSphere->SetSSAOMapSRV(0);
	mPickingSphere->Render(mrp);
	
	//ZShadeSandboxMesh::OBJMeshRenderParameters omrp;
	//omrp.camera = m_CameraSystem.get();
	//omrp.renderType = ZShadeSandboxMesh::ERenderType::eTriangleList;
	//omrp.renderType = ZShadeSandboxMesh::ERenderType::e3ControlPointPatchList;
	//omrp.maxTess = 64.0f;
	//omrp.minTess = 0.0f;
	//omrp.maxTessDist = 500.0f;
	//omrp.minTessDist = 20.0f;
	//omrp.tessellate = true;
	mSpaceCompound->Render(mrp);
	mHuman->Render(mrp);
	
	RenderLightMesh(mrp);
	
	m_D3DSystem->TurnOffCulling();
}