Example #1
0
ShadowMap   *ShadowMap::createWithMapSize(const Size &mapSize)
{
	ShadowMap *shadowMap = new ShadowMap();
	if (!shadowMap->initWithMapSize(mapSize))
	{
		shadowMap->release();
		shadowMap = nullptr;
	}
	return shadowMap;
}
Example #2
0
ShadowMap    *ShadowMap::createWithMapLayer(const Size &mapSize, const int numberOfLayer)
{
	ShadowMap *map = new ShadowMap();
	if (!map->initWithMapLayer(mapSize, numberOfLayer))
	{
		map->release();
		map = nullptr;
	}
	return map;
}
Example #3
0
void ShadowScene::draw(void) {
	//シャドウマッピングをする場合はカメラの設定をあらかじめ行います。
	Camera *camera = Manager<Camera>::getInstance().get("MyCamera");
	camera->setViewport(getWindowWidth(),getWindowHeight());
	camera->setPerspective(60);
	camera->lookat(camera_position,Vector3<float>(0,0,0),Vector3<float>(0,1,0));
	
	ShadowMap<ShadowScene> *shadow = Manager<ShadowMap<ShadowScene>>::getInstance().get("ShadowMap");
	if (isShadow) {
		glPushMatrix();
			Camera *light_camera = Manager<Camera>::getInstance().get("LightCamera");
			light_camera->position = light_position;
			// 影付きでオブジェクト描画
			shadow->renderSceneWithShadow(light_camera, this, &ShadowScene::renderScene, 0);

			// 光源の描画
			glDisable(GL_LIGHTING);
			glPushMatrix();
				glColor3d(1.0, 0.5, 0.0);
				glTranslated(light_position[0], light_position[1], light_position[2]);
				glutSolidSphere(0.1, 16, 16);
			glPopMatrix();

		glPopMatrix();
	} else {
		glEnable(GL_LIGHTING);
		Shader *shader = Manager<Shader>::getInstance().get("Shader");
		shader->apply();
		renderScene();
		
		shader->disable();
		glUseProgram(0);
		glActiveTexture(GL_TEXTURE0);

		glBindTexture(GL_TEXTURE_2D, 0);
		// 光源の描画
		glDisable(GL_LIGHTING);
		glPushMatrix();
			glColor3d(1.0, 0.5, 0.0);
			glTranslated(light_position[0], light_position[1], light_position[2]);
			glutSolidSphere(0.1, 16, 16);
		glPopMatrix();
	}

	// シャドウマップを描画
	shadow->drawDepthTex(getWindowWidth(), getWindowHeight());

}
Example #4
0
AOgpu2::AOgpu2( Point3f dir, Mol &m, int ndir){
  
  shadowmap.computeAsTexture(dir, true, shadowAOCanvas );
  glFinish();
  
  moltextureCanvas.SetAsOutput();
  
  glDisable(GL_VERTEX_PROGRAM_ARB);
  glEnable(GL_FRAGMENT_PROGRAM_ARB);

  
  aogpu_settings.BindDrawAOShader();
  for (int i=0; i<3; i++) {
    glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, i, 
      matSM[0][i],matSM[1][i],matSM[2][i],matSM[3][i]
    );
    //printf("Sending %d (%f %f %f %f)\n", i, mat[0][i],mat[1][i],mat[2][i],mat[3][i]);
  }
  glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 3, dir[0],dir[1],dir[2], 4.0/ndir );
  glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 4, 
      0,stick_radius,0,0
  );

  m.DrawOnTexture();
  
  glDisable(GL_BLEND);
  
  glEnable(GL_VERTEX_PROGRAM_ARB);
  
};
Example #5
0
  void DrawShadows(const Vec3f& lp) // lightpos
  {
    Assert(m_shadowMap);

//    m_shadowMap->SetLightPos(AmjuGL::Vec3(lp.x, lp.y, lp.z));


    m_shadowMap->Draw();

    AmjuGL::UseShader(0);
  }
Example #6
0
ShadowSG* GetSG()
{
  static ShadowSG* sg = 0;
  if (!sg)
  {
    ShadowMap* sm = (ShadowMap*)AmjuGL::Create(ShadowMap::DRAWABLE_TYPE_ID);
    sm->SetDrawFunc(ShadowMapDrawFunc);
    shaderPass2 = AmjuGL::LoadShader("Shaders/" + AmjuGL::GetShaderDir() + "/shadowpass2");
    shaderPass2->Begin(); // so we find attrib var locations when we build tri list:
    sm->SetShader(shaderPass2);
    sm->Init();

    Camera lightCam;
    lightCam.SetPos(Vec3f(10, 10, 0));
    lightCam.SetDir(Vec3f(-1, -1, 0));
    lightCam.SetNearFar(1.0f, 50.0f);
    sm->SetLight(lightCam);

    Camera viewCam;
    viewCam.SetPos(Vec3f(0, 2, 20));
    viewCam.SetDir(Vec3f(0, -1, -10));
    viewCam.SetNearFar(1.0f, 50.0f);
    sm->SetCamera(viewCam);

    sg = new ShadowSG(sm);
  }

  return sg;
}
Example #7
0
void ShadowScene::initialize(void) {
	//----------------------------------------------------------------
	//ライトの設定
	//----------------------------------------------------------------
	Light *light = Manager<Light>::getInstance().create("MyLight");
	light->ambient  = Vector4<GLfloat>(0.5f, 0.0f, 0.0f, 1.0f);
	light->diffuse  = Vector4<GLfloat>(0.5f, 0.5f, 0.5f, 1.0f);
	light->specular = Vector4<GLfloat>(0.7f, 0.7f, 0.7f, 1.0f);
	glLightfv(GL_LIGHT0, GL_AMBIENT, light->ambient.v);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light->diffuse.v);
	glLightfv(GL_LIGHT0, GL_SPECULAR,light->specular.v);
	
	float spotExp = 5.0;     //LIGHT1
	float spotCutoff = 20.0; //LIGHT1
	float spotDir[3] ;       //LIGHT1
	//LIGHT1はスポットライト(スポットライトは常にワールド空間の原点を向く)
	for(int i = 0; i < 3; i++) spotDir[i] = -light_position[i];
	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotDir);
	glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, spotExp);
	glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, spotCutoff);
	//光の減衰係数
	float kc = 0.8f;
	float k1 = 0.05f;
	float k2 = 0.002f;
	glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, kc);
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, k1);
	glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, k2);

	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHTING);

	const int shadowMapSize = 1024;
	ShadowMap<ShadowScene> *shadow = Manager<ShadowMap<ShadowScene>>::getInstance().get("ShadowMap");
	shadow->initShadow(shadowMapSize, shadowMapSize);

	isShadow = false;
}
Example #8
0
int main( int argc, char *argv[] )
{
    GLFWwindow *window;
    int Edit;
    //File name to load
    string fileName;
    //whether name inputtted is valid
    bool validFile = false;

    //Try to determine file input
    while(validFile == false) {
        printf("Type the file to load (Special options: 'd' = default, 'c' = clean):\n");
        scanf("%s", &fileName[0]);

        ifstream toLoad(&fileName[0]);
        validFile = toLoad.good();

        //If 'c' was entered, then load a clean level
        if(strcmp(&fileName[0], "c") == 0) {
            printf("Loading clean level...\n");
            fileName = "clean";
            validFile = true;
        }
        //If 'd' was entered, then deafult level
        else if(strcmp(&fileName[0], "d") == 0) {
            printf("Loading default level...\n");
            fileName = "default";
            validFile = true;
        }
        else if(validFile == false) {
            printf("Bad file, please type another file to load.\n");
        }
        else if(validFile == true) {
            toLoad.close();
        }
    }

    //Determine mode
    printf("Type 0 to play, any other int to edit\n");
    scanf("%i", &Edit);

    glfwSetErrorCallback(glfwError);
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }

    //If Edit Mode
    if(Edit) {
        //World Edit Init
        //initWorldEdit(window);
        window = glfwCreateWindow(800, 800, "World Editor", NULL, NULL);
        if (!window) {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        srand(time(0));
        glfwMakeContextCurrent(window);
        glfwSetWindowPos(window, 80, 80);
        glfwSetWindowSizeCallback(window, glfwWindowResize);
        glfwSetWindowSize(window,1600,800);
        g_height =800;
        g_width = 1600;
        setDistance(7);
        SetEdit(1);
        paused = false;

        glfwSetKeyCallback( window, glfwEditKeyPress);
        glfwSetCursorPosCallback( window, glfwEditGetCursorPos );
        glfwSetMouseButtonCallback( window, glfwEditMouse );
        glfwSetScrollCallback( window, glfwEditScroll );

        glewInit();
        glInitialize(window);
        physicsInit();
        InitGeom();
        initLevelLoader();
        loadLevel(fileName);
    }
    //If Play Mode
    else {
        //Game Play Init
        //initGamePlay(window);
        window = glfwCreateWindow(800, 800, "Grapple", NULL, NULL);
        if (!window) {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        srand(time(0));
        SetEye(vec3(0, 0, 0));
        glfwMakeContextCurrent(window);
        glfwSetWindowPos(window, 80, 80);
        glfwSetWindowSizeCallback(window, glfwWindowResize);
        glfwSetWindowSize(window,1600,800);
        g_height =800;
        g_width = 1600;
        setDistance(10);
        paused = false;

        glfwSetKeyCallback(window, glfwGameKeyPress);
        glfwSetCursorPosCallback( window, glfwGameGetCursorPos );

        glewInit();
        glInitialize(window);
        physicsInit();
        InitGeom();
        initLevelLoader();
        loadLevel(fileName);
    }

    ShadowMap *shadowMap = new ShadowMap();
    if (shadowMap->MakeShadowMap(g_width, g_height) == -1) {
        printf("SHADOW MAP FAILED\n");
        exit(EXIT_FAILURE);
    }

    // Start the main execution loop.
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
        if(Edit) {
            if(paused == false) {
                //Keep the cursor centered
                glfwSetCursorPos(window,g_width/2,g_height/2);
                renderScene(window, shadowMap);
                glfwEditGetCursorPos(NULL,g_width/2.0,g_height/2.0);
                //glfw Game Keyboard
                glfwEditKeyboard();
            }
        }
        else {
            if(paused == false) {
                //player appy physics controls
                SetLookAt(glm::vec3(physGetPlayerX(),physGetPlayerY(),physGetPlayerZ()));
                SetSpeed(.05*magnitude(getPlayerSpeed()));
                //Keep the cursor centered
                glfwSetCursorPos(window,g_width/2,g_height/2);
                physStep();
                //Draw stuff
                renderScene(window, shadowMap);
                glfwGameGetCursorPos(NULL,g_width/2.0,g_height/2.0);
                //glfw Game Keyboard
                glfwGameKeyboard();
            }
        }
        usleep(15000);
    }

    // Clean up after GLFW.
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Example #9
0
void DuckHuntMain::DrawScene()
{
	//
	// Render the scene to the shadow map.
	//

	mSmap->BindDsvAndSetNullRenderTarget(md3dImmediateContext);

	md3dImmediateContext->RSSetState(0);
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
	md3dImmediateContext->RSSetViewports(1, &mScreenViewport);

	mSsao->SetNormalDepthRenderTarget(mDepthStencilView);

	//
	// Restore the back and depth buffer and viewport to the OM stage.
	//
	ID3D11RenderTargetView* renderTargets[1] = { mRenderTargetView };
	md3dImmediateContext->OMSetRenderTargets(1, renderTargets, mDepthStencilView);

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Silver));

	XMMATRIX view = mCam.View();
	XMMATRIX proj = mCam.Proj();
	XMMATRIX viewProj = mCam.ViewProj();

	float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f };

	// Set per frame constants.
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mCam.GetPosition());
	Effects::BasicFX->SetCubeMap(mSky->CubeMapSRV());
	Effects::BasicFX->SetShadowMap(mSmap->DepthMapSRV());
	Effects::BasicFX->SetSsaoMap(mSsao->AmbientSRV());

	ID3DX11EffectTechnique* tech = Effects::BasicFX->Light3TexTech;
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	XMMATRIX world;
	XMMATRIX worldInvTranspose;
	XMMATRIX worldViewProj;

	// Transform NDC space [-1,+1]^2 to texture space [0,1]^2
	XMMATRIX toTexSpace(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, -0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.0f, 1.0f);

	XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform);

	UINT stride = sizeof(Vertex::PosNormalTexTan);
	UINT offset = 0;

	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);

	if (GetAsyncKeyState('1') & 0x8000)
		md3dImmediateContext->RSSetState(RenderStates::WireframeRS);

	mTerrain.Draw(md3dImmediateContext, mCam, mDirLights);
	//
	// Draw opaque objects.
	//
	D3DX11_TECHNIQUE_DESC techDesc;
	tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT modelIndex = 0; modelIndex < mModelInstances.size(); ++modelIndex)
		{
			world = XMLoadFloat4x4(&mModelInstances[modelIndex].World);
			worldInvTranspose = MathHelper::InverseTranspose(world);
			worldViewProj = world*view*proj;

			Effects::BasicFX->SetWorld(world);
			Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
			Effects::BasicFX->SetWorldViewProj(worldViewProj);
			Effects::BasicFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
			Effects::BasicFX->SetShadowTransform(world*shadowTransform);
			Effects::BasicFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));

			for (UINT subset = 0; subset < mModelInstances[modelIndex].Model->SubsetCount; ++subset)
			{
				Effects::BasicFX->SetMaterial(mModelInstances[modelIndex].Model->Mat[subset]);
				Effects::BasicFX->SetDiffuseMap(mModelInstances[modelIndex].Model->DiffuseMapSRV[subset]);
				//Effects::BasicFX->SetNormalMap(mModelInstances[modelIndex].Model->NormalMapSRV[subset]);

				tech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
				mModelInstances[modelIndex].Model->ModelMesh.Draw(md3dImmediateContext, subset);
			}
		}
	}
	// Turn off wireframe.
	md3dImmediateContext->RSSetState(0);

	// Restore from RenderStates::EqualsDSS
	md3dImmediateContext->OMSetDepthStencilState(0, 0);

	// Debug view SSAO map.
	//DrawScreenQuad(mSsao->AmbientSRV());

	mSky->Draw(md3dImmediateContext, mCam);
	mCrosshair->Draw(md3dImmediateContext, mCam, mScreenViewport.Width, mScreenViewport.Height);
	// restore default states, as the SkyFX changes them in the effect file.
	md3dImmediateContext->RSSetState(0);
	md3dImmediateContext->OMSetDepthStencilState(0, 0);

	// Unbind shadow map and AmbientMap as a shader input because we are going to render
	// to it next frame.  These textures can be at any slot, so clear all slots.
	ID3D11ShaderResourceView* nullSRV[16] = { 0 };
	md3dImmediateContext->PSSetShaderResources(0, 16, nullSRV);



	HR(mSwapChain->Present(0, 0));
}
Example #10
0
int main() {
	ShadowMap e;
	e.run(800, 600);
	check_error();
	return 0;
}
Example #11
0
void Projekt::DrawScene()
{
	//---------------------------------------------------------------------------
	// Render scene to shadow map
	//---------------------------------------------------------------------------
	mShadowMap->BindDsvAndSetNullRenderTarget(mDirect3D->GetImmediateContext());
	mShadowMap->DrawSceneToShadowMap(mGenericInstances, *mGame->GetCamera(), mDirect3D->GetImmediateContext());

	mDirect3D->GetImmediateContext()->RSSetState(0);

	// Restore back and depth buffer and viewport to the OM stage
	ID3D11RenderTargetView* renderTargets[1] = {mDirect3D->GetRenderTargetView()};
	mDirect3D->GetImmediateContext()->OMSetRenderTargets(1, renderTargets, mDirect3D->GetDepthStencilView());
	mDirect3D->GetImmediateContext()->ClearRenderTargetView(mDirect3D->GetRenderTargetView(), reinterpret_cast<const float*>(&Colors::LightSteelBlue));

	mDirect3D->GetImmediateContext()->ClearDepthStencilView(mDirect3D->GetDepthStencilView(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
	mDirect3D->GetImmediateContext()->RSSetViewports(1, &mDirect3D->GetScreenViewport());

	//---------------------------------------------------------------------------

	// Possible Wireframe render state
// 	if (mDirectInput->GetKeyboardState()[DIK_E] && 0x80)
// 		mDirect3D->GetImmediateContext()->RSSetState(RenderStates::WireFrameRS);

	//--------------------------------------------------------------
	// Set shader constants
	//--------------------------------------------------------------
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mGame->GetCamera()->GetPosition());
	Effects::BasicFX->SetShadowMap(mShadowMap->getDepthMapSRV());
	Effects::BasicFX->SetCubeMap(mSky->cubeMapSRV());

	Effects::NormalMapFX->SetDirLights(mDirLights);
	Effects::NormalMapFX->SetEyePosW(mGame->GetCamera()->GetPosition());
	Effects::NormalMapFX->SetShadowMap(mShadowMap->getDepthMapSRV());
	Effects::NormalMapFX->SetCubeMap(mSky->cubeMapSRV());

	// Draw sky
	mSky->draw(mDirect3D->GetImmediateContext(), *mGame->GetCamera(), Gui->InMenu());

	// Draw game
	mGame->Draw(mDirect3D->GetImmediateContext(), mShadowMap);
	
	this->soundModule->updateAndPlay(mGame->GetCamera(), mGame->GetCamera()->GetPosition());

	// Draw the GUI
	Gui->Render(mDirect3D->GetImmediateContext(), mGame->GetPlayer()->GetPosition());

	// Unbind shadow map and AmbientMap as a shader input because we are going to render
	// to it next frame.  These textures can be at any slot, so clear all slots.
	ID3D11ShaderResourceView* nullSRV[16] = { 0 };
	mDirect3D->GetImmediateContext()->PSSetShaderResources(0, 16, nullSRV);

	// Restore default states
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	mDirect3D->GetImmediateContext()->RSSetState(0);
	mDirect3D->GetImmediateContext()->OMSetDepthStencilState(0, 0);
	mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); 

	HR(mDirect3D->GetSwapChain()->Present(0, 0));
}
Example #12
0
void Projekt::DrawScene()
{
	//---------------------------------------------------------------------------
	// Render scene to shadow map
	//---------------------------------------------------------------------------
	mShadowMap->BindDsvAndSetNullRenderTarget(mDirect3D->GetImmediateContext());
	drawSceneToShadowMap();

	mDirect3D->GetImmediateContext()->RSSetState(0);

	// Restore back and depth buffer and viewport to the OM stage
	ID3D11RenderTargetView* renderTargets[1] = {mDirect3D->GetRenderTargetView()};
	mDirect3D->GetImmediateContext()->OMSetRenderTargets(1, renderTargets, mDirect3D->GetDepthStencilView());
	mDirect3D->GetImmediateContext()->ClearRenderTargetView(mDirect3D->GetRenderTargetView(), reinterpret_cast<const float*>(&Colors::LightSteelBlue));

	mDirect3D->GetImmediateContext()->ClearDepthStencilView(mDirect3D->GetDepthStencilView(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
	mDirect3D->GetImmediateContext()->RSSetViewports(1, &mDirect3D->GetScreenViewport());

	// Possible Wireframe render state
	if (GetAsyncKeyState('E') & 0x8000)
		mDirect3D->GetImmediateContext()->RSSetState(WireFrameRS);

	XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform);

	//---------------------------------------------------------------------------
	// Draw terrain
	//---------------------------------------------------------------------------
	//mTerrain.Draw(mDirect3D->GetImmediateContext(), mCam, mDirLights);

	mTerrain.DrawShadowed(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera(), mDirLights,
		mShadowMap->getDepthMapSRV(), &shadowTransform);

	// --------------------------------------------------------------------------

	// Camera matrices
	XMMATRIX view = mPlayer.GetCamera()->getViewMatrix();
	XMMATRIX proj = mPlayer.GetCamera()->getProjMatrix();
	XMMATRIX viewproj = mPlayer.GetCamera()->getViewProjMatrix();

	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};

	// Set per frame constants
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mPlayer.GetCamera()->getPosition());
	Effects::BasicFX->setShadowMap(mShadowMap->getDepthMapSRV());
	Effects::BasicFX->SetCubeMap(mSky->cubeMapSRV());

	Effects::NormalMapFX->SetDirLights(mDirLights);
	Effects::NormalMapFX->SetEyePosW(mPlayer.GetCamera()->getPosition());
	Effects::NormalMapFX->setShadowMap(mShadowMap->getDepthMapSRV());
	Effects::NormalMapFX->SetCubeMap(mSky->cubeMapSRV());

	XMMATRIX world;
	XMMATRIX worldInvTranspose;
	XMMATRIX worldViewProj;

	// Transform NDC space [-1,+1]^2 to texture space [0,1]^2
	XMMATRIX toTexSpace(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, -0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.0f, 1.0f);

	// Vertex size & offset
	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;

	// Draw player
	//mPlayer.Draw(mDirect3D->GetImmediateContext(), mDirLights,
		//mShadowMap->getDepthMapSRV(), &shadowTransform);

	//---------------------------------------------------------------------------
	// Draw opaque objects
	//---------------------------------------------------------------------------
	// Bind information about primitive type, and set input layout
	mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::Basic32);

	// Set our effect technique to use
	ID3DX11EffectTechnique* activeTech = Effects::BasicFX->DirLights3FogTexTech;
	ID3DX11EffectTechnique* activeSkinnedTech = Effects::NormalMapFX->DirLights3TexTech;

	D3DX11_TECHNIQUE_DESC techDesc;

	//--------------------------------------------------------------------------------
	// Draw opaque tessellated objects
	//--------------------------------------------------------------------------------
	Effects::BasicTessFX->SetDirLights(mDirLights);
	Effects::BasicTessFX->SetEyePosW(mPlayer.GetCamera()->getPosition());
	Effects::BasicTessFX->setShadowMap(mShadowMap->getDepthMapSRV());
	Effects::BasicTessFX->SetCubeMap(mSky->cubeMapSRV());

	mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);
	mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::PosNormalTexTan);

	activeTech = Effects::BasicTessFX->TessDirLights3FogTexTech;
	activeTech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT mIndex = 0; mIndex < mGenericInstances.size(); ++mIndex)
		{
			if (mGenericInstances[mIndex].isVisible)
			{
				world = XMLoadFloat4x4(&mGenericInstances[mIndex].world);
				worldInvTranspose = MathHelper::InverseTranspose(world);
				worldViewProj = world*view*proj;

				Effects::BasicTessFX->SetWorld(world);
				Effects::BasicTessFX->SetWorldInvTranspose(worldInvTranspose);
				Effects::BasicTessFX->SetWorldViewProj(worldViewProj);
				Effects::BasicTessFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
				Effects::BasicTessFX->setShadowTransform(world*shadowTransform);
				Effects::BasicTessFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));
				Effects::BasicTessFX->SetMinTessDistance(20.0f);
				Effects::BasicTessFX->SetMaxTessDistance(200.0f);
				Effects::BasicTessFX->SetMinTessFactor(0.0f);
				Effects::BasicTessFX->SetMaxTessFactor(3.0f);
				Effects::BasicTessFX->setFogStart(GameSettings::Instance()->Fog()->fogStart);
				Effects::BasicTessFX->setFogRange(GameSettings::Instance()->Fog()->fogRange);

				
				Effects::BasicTessFX->setFogColor(Colors::Silver);

				for (UINT i = 0; i < mGenericInstances[mIndex].model->meshCount; ++i)
				{
					UINT matIndex = mGenericInstances[mIndex].model->meshes[i].MaterialIndex;

					Effects::BasicTessFX->SetMaterial(mGenericInstances[mIndex].model->mat[matIndex]);

					Effects::BasicTessFX->SetDiffuseMap(mGenericInstances[mIndex].model->diffuseMapSRV[matIndex]);
					//Effects::BasicTessFX->SetNormalMap(mGenericInstances[mIndex].model->normalMapSRV[matIndex]);

					activeTech->GetPassByIndex(p)->Apply(0, mDirect3D->GetImmediateContext());
					mGenericInstances[mIndex].model->meshes[i].draw(mDirect3D->GetImmediateContext());
				}
			}
		}
	}

	// FX sets tessellation stages, but it does not disable them.  So do that here
	// to turn off tessellation.
	mDirect3D->GetImmediateContext()->HSSetShader(0, 0, 0);
	mDirect3D->GetImmediateContext()->DSSetShader(0, 0, 0);

	mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::PosNormalTexTanSkinned);

	// Skinned objects
	activeSkinnedTech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT mIndex = 0; mIndex < mGenSkinnedInstances.size(); ++mIndex)
		{
			if (mGenSkinnedInstances[mIndex].isVisible)
			{
				world = XMLoadFloat4x4(&mGenSkinnedInstances[mIndex].world);
				worldInvTranspose = MathHelper::InverseTranspose(world);
				worldViewProj = world*view*proj;

				Effects::NormalMapFX->SetWorld(world);
				Effects::NormalMapFX->SetWorldInvTranspose(worldInvTranspose);
				Effects::NormalMapFX->SetWorldViewProj(worldViewProj);
				Effects::NormalMapFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
				Effects::NormalMapFX->setShadowTransform(world*shadowTransform);
				Effects::NormalMapFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));
				Effects::NormalMapFX->setFogStart(GameSettings::Instance()->Fog()->fogStart);
				Effects::NormalMapFX->setFogRange(GameSettings::Instance()->Fog()->fogRange);
				Effects::NormalMapFX->setBoneTransforms(&mGenSkinnedInstances[mIndex].FinalTransforms[0],
					mGenSkinnedInstances[mIndex].FinalTransforms.size());


				Effects::BasicTessFX->setFogColor(Colors::Silver);

				for (UINT i = 0; i < mGenSkinnedInstances[mIndex].model->numMeshes; ++i)
				{
					UINT matIndex = mGenSkinnedInstances[mIndex].model->meshes[i].MaterialIndex;

					Effects::NormalMapFX->SetMaterial(mGenSkinnedInstances[mIndex].model->mat[matIndex]);

					Effects::NormalMapFX->SetDiffuseMap(mGenSkinnedInstances[mIndex].model->diffuseMapSRV[matIndex]);

					Effects::NormalMapFX->setNormalMap(mGenSkinnedInstances[mIndex].model->normalMapSRV[matIndex]);

					activeSkinnedTech->GetPassByIndex(p)->Apply(0, mDirect3D->GetImmediateContext());
					mGenSkinnedInstances[mIndex].model->meshes[i].draw(mDirect3D->GetImmediateContext());
				}
			}
		}
	}

	//---------------------------------------------------------------------------
	// Draw particle systems
	//---------------------------------------------------------------------------
	mFire.setEyePos(mPlayer.GetCamera()->getPosition());
	mFire.draw(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera());
	mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); // restore default

	//---------------------------------------------------------------------------
	// Draw sky
	//---------------------------------------------------------------------------
	mSky->draw(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera());

	// Unbind shadow map and AmbientMap as a shader input because we are going to render
	// to it next frame.  These textures can be at any slot, so clear all slots.
	ID3D11ShaderResourceView* nullSRV[16] = { 0 };
	mDirect3D->GetImmediateContext()->PSSetShaderResources(0, 16, nullSRV);

	// Restore default states
	mDirect3D->GetImmediateContext()->RSSetState(0);
	mDirect3D->GetImmediateContext()->OMSetDepthStencilState(0, 0);
	mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); 

	HR(mDirect3D->GetSwapChain()->Present(0, 0));
}