Example #1
0
void CubeMapApp::initApp()
{
	D3DApp::initApp();

	fx::InitAll(md3dDevice);
	InputLayout::InitAll(md3dDevice);
	GetTextureMgr().init(md3dDevice);


	mTech                = fx::CubeMapFX->GetTechniqueByName("CubeMapTech");
	mfxLightVar          = fx::CubeMapFX->GetVariableByName("gLight");
	mfxEyePosVar         = fx::CubeMapFX->GetVariableByName("gEyePosW");
	mfxWVPVar            = fx::CubeMapFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar          = fx::CubeMapFX->GetVariableByName("gWorld")->AsMatrix();
	mfxTexMtxVar         = fx::CubeMapFX->GetVariableByName("gTexMtx")->AsMatrix();
	mfxReflectMtrlVar    = fx::CubeMapFX->GetVariableByName("gReflectMtrl")->AsVector();
	mfxCubeMapEnabledVar = fx::CubeMapFX->GetVariableByName("gCubeMapEnabled")->AsScalar();
	mfxDiffuseMapVar     = fx::CubeMapFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
	mfxSpecMapVar        = fx::CubeMapFX->GetVariableByName("gSpecMap")->AsShaderResource();
	mfxCubeMapVar        = fx::CubeMapFX->GetVariableByName("gCubeMap")->AsShaderResource();

 
	//mClearColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);

	GetCamera().position() = D3DXVECTOR3(0.0f, 1.8f, -10.0f);

	mBallMapRV        = GetTextureMgr().createTex(L"blackdiffuse.dds");
	//mSpecMapRV        = GetTextureMgr().createTex(L"spec.dds");
	mDefaultSpecMapRV = GetTextureMgr().createTex(L"defaultspec.dds");
	mEnvMapRV         = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds");

	mFloor.init(md3dDevice, 41, 21, 1.0f);
	mBase.init(md3dDevice, 2.0f);
	mBall.init(md3dDevice, 0.5f, 30, 30);
	mColumn.init(md3dDevice, 0.25f, 1.0f, 3.0f, 30, 30);
	mSky.init(md3dDevice, mEnvMapRV, 5000.0f);

 
	mParallelLight.dir      = D3DXVECTOR3(0.57735f, -0.57735f, 0.57735f);
	mParallelLight.ambient  = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
	mParallelLight.diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mParallelLight.specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
}
Example #2
0
void Terrain::init(ID3D10Device* device, const InitInfo& initInfo)
{
	md3dDevice = device;

	mTech          = fx::TerrainFX->GetTechniqueByName("TerrainTech");
	mfxWVPVar      = fx::TerrainFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar    = fx::TerrainFX->GetVariableByName("gWorld")->AsMatrix();
	mfxDirToSunVar = fx::TerrainFX->GetVariableByName("gDirToSunW")->AsVector();
	mfxLayer0Var   = fx::TerrainFX->GetVariableByName("gLayer0")->AsShaderResource();
	mfxLayer1Var   = fx::TerrainFX->GetVariableByName("gLayer1")->AsShaderResource();
	mfxLayer2Var   = fx::TerrainFX->GetVariableByName("gLayer2")->AsShaderResource();
	mfxLayer3Var   = fx::TerrainFX->GetVariableByName("gLayer3")->AsShaderResource();
	mfxLayer4Var   = fx::TerrainFX->GetVariableByName("gLayer4")->AsShaderResource();
	mfxBlendMapVar = fx::TerrainFX->GetVariableByName("gBlendMap")->AsShaderResource();

	mInfo = initInfo;

	mNumVertices = mInfo.NumRows*mInfo.NumCols;
	mNumFaces    = (mInfo.NumRows-1)*(mInfo.NumCols-1)*2;

	loadHeightmap();
	smooth();

	buildVB();
	buildIB();

	mLayer0   = GetTextureMgr().createTex(initInfo.LayerMapFilename0);
	mLayer1   = GetTextureMgr().createTex(initInfo.LayerMapFilename1);
	mLayer2   = GetTextureMgr().createTex(initInfo.LayerMapFilename2);
	mLayer3   = GetTextureMgr().createTex(initInfo.LayerMapFilename3);
	mLayer4   = GetTextureMgr().createTex(initInfo.LayerMapFilename4);
	mBlendMap = GetTextureMgr().createTex(initInfo.BlendMapFilename);
}
Example #3
0
void TerrainApp::initApp()
{
	D3DApp::initApp();

	fx::InitAll(md3dDevice);
	InputLayout::InitAll(md3dDevice);
	GetTextureMgr().init(md3dDevice);

	mClearColor = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	GetCamera().position() = D3DXVECTOR3(0.0f, 10.0f, -10.0f);

	mEnvMapRV = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds");
	mSky.init(md3dDevice, mEnvMapRV, 5000.0f);

	Terrain::InitInfo tii;
	tii.HeightmapFilename = L"coastMountain513.raw";
	tii.LayerMapFilename0 = L"grass.dds";
	tii.LayerMapFilename1 = L"lightdirt.dds";
	tii.LayerMapFilename2 = L"darkdirt.dds";
	tii.LayerMapFilename3 = L"stone.dds";
	tii.LayerMapFilename4 = L"snow.dds";
	tii.BlendMapFilename  = L"blend.dds";
	tii.HeightScale  = 0.35f;
	tii.HeightOffset = -20.0f;
	tii.NumRows      = 513;
	tii.NumCols      = 513;
	tii.CellSpacing  = 1.0f;

	mLand.init(md3dDevice, tii);
 
	mParallelLight.dir      = D3DXVECTOR3(0.707f, -0.707f, 0.0f);
	mParallelLight.ambient  = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
	mParallelLight.diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mParallelLight.specular = D3DXCOLOR(0.5f, 0.4843f, 0.3f, 1.0f);

	mLand.setDirectionToSun(-mParallelLight.dir);
}
Example #4
0
void OutBuilding::init (ID3D10Device* device, const InitInfo& initInfo, float w, float h, float d){
	md3dDevice=		device;
	mTech			= fx::OutBuildingFX->GetTechniqueByName("MultiTexTech");
	mfxWVPVar		= fx::OutBuildingFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar		= fx::OutBuildingFX->GetVariableByName("gWorld")->AsMatrix();
	mfxLayer0Var	= fx::OutBuildingFX->GetVariableByName("gLayer0")->AsShaderResource();
	mfxLayer1Var	= fx::OutBuildingFX->GetVariableByName("gLayer1")->AsShaderResource();
	mfxLayer2Var	= fx::OutBuildingFX->GetVariableByName("gLayer2")->AsShaderResource();
	mfxBlendMapVar	= fx::OutBuildingFX->GetVariableByName("gBlendMap")->AsShaderResource();
	mfxSpecMapVar	= fx::OutBuildingFX->GetVariableByName("gSpecMap")->AsShaderResource();
	mfxEyePosVar	= fx::OutBuildingFX->GetVariableByName("gEyePosW");
	mfxLightVar		= fx::OutBuildingFX->GetVariableByName("gLight");
	mfxLightType	= fx::OutBuildingFX->GetVariableByName("gLightType")->AsScalar();

	mInfo = initInfo;

	build(w, h, d);

	mLayer0   = GetTextureMgr().createTex(initInfo.LayerMapFilename0);
	mLayer1   = GetTextureMgr().createTex(initInfo.LayerMapFilename1);
	mLayer2   = GetTextureMgr().createTex(initInfo.LayerMapFilename2);
	mBlendMap = GetTextureMgr().createTex(initInfo.BlendMapFilename);
	mSpecMap  = GetTextureMgr().createTex(initInfo.SpecMapFilename);
}
Example #5
0
bool CRenderSystem::prepareMaterial(/*const */CMaterial& material, float fOpacity) // 由于使用了自动注册纹理的机制,很遗憾的导致不能用“const”
{
	CTextureMgr& TM = GetTextureMgr();
	for (size_t i=0;i<8;++i)
	{
		if (material.uTexture[i]==-1)
		{
			material.uTexture[i] = TM.RegisterTexture(material.getTexture(i));
		}
		// ----
		SetTexture(i, material.uTexture[i]);
		// ----
		if (material.uTexture[i]==0)
		{
			break;
		}
	}
	if (material.uShader==-1)
	{
		material.uShader = GetShaderMgr().registerItem(material.getShader());
	}
	// ----
	SetLightingEnabled(material.bLightingEnabled);
	SetCullingMode((CullingMode)material.uCull);
	// ----
	SetAlphaTestFunc(material.bAlphaTest, (CompareFunction)material.nAlphaTestCompare, material.uAlphaTestValue);
	SetBlendFunc(material.bBlend, (SceneBlendOperation)material.nBlendOP, (SceneBlendFactor)material.nBlendSrc, (SceneBlendFactor)material.nBlendDest);
	SetDepthBufferFunc(material.bDepthTest,material.bDepthWrite);
	// ----
	if (0==material.uShader)
	{
		for (size_t i=0;i<8;++i)
		{
			CMaterial::TextureOP& texOP = material.textureOP[i];
			SetTextureColorOP(i, (TextureBlendOperation)texOP.nColorOP, (TextureBlendSource)texOP.nColorSrc1, (TextureBlendSource)texOP.nColorSrc2);
			SetTextureColorOP(i, (TextureBlendOperation)texOP.nAlphaOP, (TextureBlendSource)texOP.nAlphaSrc1, (TextureBlendSource)texOP.nAlphaSrc2);
			if (TBOP_DISABLE == texOP.nColorOP)
			{
				break;
			}
		}
	}
	else
	{
		CShader* pShader = GetShaderMgr().getSharedShader();
		if (pShader)
		{
			// for Terrain
			pShader->setVec2D("g_fScaleUV",material.vUVScale);
		}
		SetShader(material.uShader);
	}
	return true;
/*	if (material.bLightingEnabled)
	{
		SetMaterial(material.vAmbient,material.vDiffuse);
	}

	if (0==material.uShader)
	{
		//SetSamplerAddressUV(0,ADDRESS_WRAP,ADDRESS_WRAP);
		if (material.vTexAnim.lengthSquared()>0.0f)
		{
			Matrix matTex=Matrix::UNIT;
			float fTime = (float)GetGlobalTimer().GetTime();
			matTex._13=fTime*material.vTexAnim.x;
			matTex._23=fTime*material.vTexAnim.y;
			setTextureMatrix(0, TTF_COUNT3, matTex);
		}

		Color32 cFactor = material.cEmissive;
		if (material.m_fOpacity<0.0f)
		{
			fOpacity = (float)(rand()%255)/255.0f;
		}
		else
		{
			fOpacity *= material.m_fOpacity;
		}

		if (material.uDiffuse)
		{
			SetTexture(0, material.uDiffuse);
			cFactor.a=(unsigned char)(cFactor.a*fOpacity);
			SetTextureFactor(cFactor);
			if (material.bLightingEnabled)
			{
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_DIFFUSE);
			}
			else
			{
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR);
			}
			if(material.bBlend||material.m_fOpacity<1.0f)
			{
				SetBlendFunc(true, BLENDOP_ADD, SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
			}

			if (material.m_fOpacity<1.0f)
			{
				SetTextureAlphaOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR);
			}
			else if (material.bAlphaTest||material.bBlend)
			{
				SetTextureAlphaOP(0, TBOP_SOURCE1, TBS_TEXTURE);
			}
			else
			{
				SetTextureAlphaOP(0, TBOP_DISABLE);
			}

			//////////////////////////////////////////////////////////////////////////
			if (material.uSpecular)
			{
				SetTexture(1, material.uSpecular);
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_DIFFUSE);
				setResultARGToTemp(1,true);
				SetTextureColorOP(1, TBOP_MODULATE_X2, TBS_TEXTURE, TBS_SPECULAR);
				SetTextureColorOP(2, TBOP_ADD, TBS_CURRENT, TBS_TEMP);

				SetTexCoordIndex(0,0);
				SetTexCoordIndex(1,0);
				SetTexCoordIndex(2,0);
			}
			else if (material.uReflection)
			{
				SetTextureColorOP(1, TBOP_MODULATE_X2, TBS_CURRENT, TBS_TEXTURE);
				SetTexCoordIndex(1,TCI_CAMERASPACE_NORMAL|TCI_CAMERASPACE_POSITION);
				SetTexture(1, material.uReflection);
			}
			else if (material.uLightMap)
			{
				SetTextureColorOP(1, TBOP_MODULATE, TBS_CURRENT, TBS_TEXTURE);
				SetTexCoordIndex(1,1);
				SetTexture(1, material.uLightMap);
			}
			else if (material.uEmissive)
			{
				SetTextureColorOP(1, TBOP_ADD, TBS_CURRENT, TBS_TEXTURE);
				SetTexture(1, material.uEmissive);
			}
			else if(!material.bBlend&&material.m_fOpacity>=1.0f)
			{
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_DIFFUSE);
			}
		}
		else
		{
			SetTextureFactor(cFactor);
			if (material.uSpecular)
			{
				//SetTexture(0, material.uSpecular);
				SetTextureColorOP(0, TBOP_SOURCE1, TBS_SPECULAR);
				SetTexCoordIndex(0,0);
			}
			else if(material.uReflection)
			{
				cFactor.r=(unsigned char)(cFactor.r*fOpacity);
				cFactor.g=(unsigned char)(cFactor.g*fOpacity);
				cFactor.b=(unsigned char)(cFactor.b*fOpacity);
				SetTextureFactor(cFactor);
				if (material.bBlend)
				{
					SetBlendFunc(true, BLENDOP_ADD, SBF_DEST_COLOUR, SBF_ONE);
				}
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR);
				SetTextureAlphaOP(0, TBOP_DISABLE);
				SetTexCoordIndex(0,TCI_CAMERASPACE_NORMAL|TCI_CAMERASPACE_POSITION);
				SetTexture(0, material.uReflection);
			}
			else if (material.uLightMap)
			{
				if (material.bBlend)
				{
					SetBlendFunc(true, BLENDOP_ADD, SBF_DEST_COLOUR, SBF_ZERO);
				}
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR);
				SetTextureAlphaOP(0, TBOP_DISABLE);
				SetTexture(0, material.uLightMap);
			}
			else if (material.uEmissive)
			{
				cFactor.r=(unsigned char)(cFactor.r*fOpacity);
				cFactor.g=(unsigned char)(cFactor.g*fOpacity);
				cFactor.b=(unsigned char)(cFactor.b*fOpacity);
				SetTextureFactor(cFactor);
				if (material.bBlend)
				{
					SetBlendFunc(true, BLENDOP_ADD, SBF_ONE, SBF_ONE);
				}
				SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR);
				SetTextureAlphaOP(0, TBOP_DISABLE);
				SetTexture(0, material.uEmissive);
			}
			else if (material.uNormal)
			{
				CShader* pShader = GetShaderMgr().getSharedShader();
				if (pShader)
				{
					static size_t s_uShaderID = GetShaderMgr().registerItem("EngineRes\\fx\\SpaceBump.fx");
					pShader->setTexture("g_texNormal",material.uNormal);
					SetShader(s_uShaderID);
				}
				//SetBlendFunc(true, BLENDOP_ADD, SBF_DEST_COLOUR, SBF_ZERO);
				//SetTextureColorOP(0, TBOP_MODULATE, TBS_TEXTURE, TBS_TFACTOR);
				//SetTextureAlphaOP(0, TBOP_DISABLE);
				//SetTexture(0, uLightMap);
			}
			else
			{
				SetTextureColorOP(0,TBOP_SOURCE2);
				if (material.bBlend)
				{
					SetTextureAlphaOP(0,TBOP_SOURCE2);
				}
				else
				{
					SetTextureAlphaOP(0,TBOP_DISABLE);
				}
				//return false;
			}
		}
	}
	else
	{
		CShader* pShader = GetShaderMgr().getSharedShader();
		if (pShader)
		{
			pShader->setTexture("g_texDiffuse",material.uDiffuse);
			pShader->setTexture("g_texLight",material.uLightMap);
			pShader->setTexture("g_texNormal",material.uNormal);
			//pShader->setTexture("g_texEnvironment",uEmissive);
			//pShader->setTexture("g_texEmissive",uEmissive);
			pShader->setTexture("g_texSpecular",material.uSpecular);
			// for Terrain
			pShader->setVec2D("g_fScaleUV",material.vUVScale);
		}
		SetShader(material.uShader);
	}
	return true;*/
}
void DeferredDemo::initApp(void)
{
    	D3DApp::initApp();

	fx::InitAll(md3dDevice);
	InputLayout::InitAll(md3dDevice);
	GetTextureMgr().init(md3dDevice);

    m_normalRT= new RenderTexture(md3dDevice, 1024,1024, DXGI_FORMAT_R16G16B16A16_FLOAT );
    m_diffusespecRT = new RenderTexture(md3dDevice, 1024, 1024, DXGI_FORMAT_R16G16B16A16_FLOAT);
    m_lightRT = new RenderTexture(md3dDevice, 1024, 1024, DXGI_FORMAT_R16G16B16A16_FLOAT);
    m_quad = new NDCQuad(md3dDevice, D3DXVECTOR3(0.5f, -0.5f,0.0f), D3DXVECTOR3(0.5f, 0.5f,0.0f));
    m_finalQuad = new NDCQuad(md3dDevice, D3DXVECTOR3(0.0f, 0.0f,0.0f), D3DXVECTOR3(1.0f,1.0f,1.0f));

    //create solid rasterizer state
    D3D10_RASTERIZER_DESC rsDesc;
    ZeroMemory(&rsDesc, sizeof(rsDesc));
    rsDesc.CullMode = D3D10_CULL_BACK;
    rsDesc.FillMode = D3D10_FILL_SOLID ;
    rsDesc.FrontCounterClockwise = false;
    rsDesc.DepthClipEnable = true;
    
    HR(md3dDevice->CreateRasterizerState(&rsDesc, &m_solidMode));


    /*std::vector<D3DXVECTOR3> vb;
    std::vector<uint16_t>  ib;
    ::CreateConeMesh(vb,ib,0,1,2,12);*/
	mTech                = fx::ShadowFX->GetTechniqueByName("ShadowTech");
	mfxLightVar          = fx::ShadowFX->GetVariableByName("gLight");
	mfxEyePosVar         = fx::ShadowFX->GetVariableByName("gEyePosW");
	mfxLightWVPVar       = fx::ShadowFX->GetVariableByName("gLightWVP")->AsMatrix();
	mfxWVPVar            = fx::ShadowFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar          = fx::ShadowFX->GetVariableByName("gWorld")->AsMatrix();
	mfxTexMtxVar         = fx::ShadowFX->GetVariableByName("gTexMtx")->AsMatrix();
	mfxReflectMtrlVar    = fx::ShadowFX->GetVariableByName("gReflectMtrl")->AsVector();
	mfxCubeMapEnabledVar = fx::ShadowFX->GetVariableByName("gCubeMapEnabled")->AsScalar();
	mfxDiffuseMapVar     = fx::ShadowFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
	mfxSpecMapVar        = fx::ShadowFX->GetVariableByName("gSpecMap")->AsShaderResource();
	mfxNormalMapVar      = fx::ShadowFX->GetVariableByName("gNormalMap")->AsShaderResource();
	mfxShadowMapVar      = fx::ShadowFX->GetVariableByName("gShadowMap")->AsShaderResource();
	mfxCubeMapVar        = fx::ShadowFX->GetVariableByName("gCubeMap")->AsShaderResource();

	mBuildShadowMapTech            = fx::BuildShadowMapFX->GetTechniqueByName("BuildShadowMapTech");
	mfxBuildShadowMapLightWVPVar   = fx::BuildShadowMapFX->GetVariableByName("gLightWVP")->AsMatrix();
	mfxBuildShadowMapDiffuseMapVar = fx::BuildShadowMapFX->GetVariableByName("gDiffuseMap")->AsShaderResource();

    //GBuffer technique and technique variables
    m_genGBufferTech    =fx::GenGBufferFX->GetTechniqueByName("GBufferTech");
    m_ObjectModelVar    = fx::GenGBufferFX->GetVariableByName("gWorld")->AsMatrix();
    m_CameraViewVar     = fx::GenGBufferFX->GetVariableByName("gView")->AsMatrix();
    m_CameraProjVar     = fx::GenGBufferFX->GetVariableByName("gProject")->AsMatrix();
    m_TexMtx            = fx::GenGBufferFX->GetVariableByName("gTexMtx")->AsMatrix();
    m_Shininese         = fx::GenGBufferFX->GetVariableByName("gShininese")->AsScalar();
    m_DiffuseMapVar     = fx::GenGBufferFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
    m_SpecMapVar        = fx::GenGBufferFX->GetVariableByName("gSpecMap")->AsShaderResource();
    m_NormalMapVar      = fx::GenGBufferFX->GetVariableByName("gNormalMap")->AsShaderResource();
    m_CubeMapVar        = fx::GenGBufferFX->GetVariableByName("gCubeMap")->AsShaderResource();
    m_CubeMapEnabledVar    = fx::GenGBufferFX->GetVariableByName("gCubeMapEnabled")->AsScalar();
    m_EyePosVar         = fx::GenGBufferFX->GetVariableByName("gEyePosW");

    m_depthTex.init(md3dDevice,1024,1024,false,DXGI_FORMAT_UNKNOWN);
    //lighting pass tech 
    m_pointLightTech = fx::LightingFX->GetTechniqueByName("DeferredPointTech");
    m_parallelLightTech = fx::LightingFX->GetTechniqueByName("DeferredDirectionalTech");
    m_lightSourceTech = fx::LightingFX->GetTechniqueByName("LightTech");
    m_pointLightVar  = fx::LightingFX->GetVariableByName("gLight");
    m_lightPosVVar      = fx::LightingFX->GetVariableByName("gLightPosV");
    m_pointLightWVPVar = fx::LightingFX->GetVariableByName("gWorldViewProj")->AsMatrix();
    m_pointLightWVVar           = fx::LightingFX->GetVariableByName("gWorldView")->AsMatrix();
    m_depthVar       = fx::LightingFX->GetVariableByName("gDepthMap")->AsShaderResource();
    m_gbufferVar     = fx::LightingFX->GetVariableByName("gGBufferMap")->AsShaderResource();
    m_lightDirVar    = fx::LightingFX->GetVariableByName("gLigthDirES");

    //final shading tech
    m_shadingTech  = fx::ShadingFX->GetTechniqueByName("ShadingTech");
    m_diffuseVar   = fx::ShadingFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
    m_lightingVar  = fx::ShadingFX->GetVariableByName("gLightingMap")->AsShaderResource();

    //gen shadow map
	mDrawShadowMapTech     = fx::DrawShadowMapFX->GetTechniqueByName("DrawShadowMapTech");
	mfxDrawShadowMapTexVar = fx::DrawShadowMapFX->GetVariableByName("gShadowMap")->AsShaderResource();

	//buildNDCQuad();

	mShadowMap.init(md3dDevice, 2048, 2048, false, DXGI_FORMAT_UNKNOWN);
 
	mClearColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);

	GetCamera().position() = D3DXVECTOR3(0.0f, 1.8f, -10.0f);

	mFloorMapRV         = GetTextureMgr().createTex(L"floor_diffuse.dds");
	mFloorNormalMapRV   = GetTextureMgr().createTex(L"floor_normal.dds");
	mBaseMapRV          = GetTextureMgr().createTex(L"stone_diffuse.dds");
	mBaseNormalMapRV    = GetTextureMgr().createTex(L"stone_normal.dds");
	mBallMapRV          = GetTextureMgr().createTex(L"blackdiffuse.dds");
	mColumnMapRV        = GetTextureMgr().createTex(L"bricks_diffuse.dds");
	mColumnNormalMapRV  = GetTextureMgr().createTex(L"bricks_normal.dds");
	mSpecMapRV          = GetTextureMgr().createTex(L"spec.dds");
	mDefaultSpecMapRV   = GetTextureMgr().createTex(L"defaultspec.dds");
	mDefaultNormalMapRV = GetTextureMgr().createTex(L"default_normal.dds");
	mEnvMapRV           = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds");

	mFloor.init(md3dDevice, 41, 21, 1.0f);
	mBase.init(md3dDevice, 2.0f);
	mBall.init(md3dDevice, 0.5f, 30, 30);
	mColumn.init(md3dDevice, 0.25f, 1.0f, 3.0f, 30, 30);
	mSky.init(md3dDevice, mEnvMapRV, 5000.0f);

 
	// direction updated at runtime
	mParallelLight.ambient  = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
	mParallelLight.diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mParallelLight.specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);

    m_pointLight.ambient  = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
    m_pointLight.diffuse  = D3DXCOLOR(0.3f, 1.0f, 0.6f, 1.0f);
    m_pointLight.specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
    m_pointLight.pos       = D3DXVECTOR3(0.0f, 2.0f,3.0f);
    m_pointLight.att      =  D3DXVECTOR3(0.0f, 1.0f, 0.0f);
    m_pointLight.range    = 3.0f;
    m_pointLightMesh = new LightBoxMesh(md3dDevice, 50.0f);

    D3DXCOLOR   colors[] = {
        WHITE,
        RED,
        GREEN,
        BLUE,
        YELLOW
    };
    for(int i = 0 ; i < 5; ++i)
    {
        float x = 2.5f * cosf(i*2*PI/5 );
        float z = 2.5f * sinf(i*2*PI/5);
        m_pointLights[i].ambient  = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
        m_pointLights[i].diffuse  = colors[i];
        m_pointLights[i].specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
        m_pointLights[i].pos      = D3DXVECTOR3(x, 2.0f, z);
        m_pointLights[i].att      = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
        m_pointLights[i].range    = 3.0f;
    }


	D3DXMatrixOrthoLH(&mLightVolume, 30.0f, 30.0f, 1.0f, 100.0f);
}
Example #7
0
Scene::Scene(HWND TheWindow, unsigned int WindowWidth, unsigned int WindowHeight):
MyD3D10Code::Direct3D10Class(TheWindow, WindowWidth, WindowHeight),
m_FX(0),
m_Tech(0),
m_fxWVPVar(0),
m_VertexLayout(0),
m_Theta(0.0f),
m_Phi(PI*0.25f),
m_Box(m_Direct3DDevice),
// Delete 5 below variables later from init list
m_FxEyePosVar(0),
m_FxLightVar(0),
m_SpecMapRV(0),
m_FxSpecMapVar(0),
m_FxTexMatVar(0),
m_FxBoxWorldVar(0),
m_EnvironmentMapRV(0),
m_Roof(m_Direct3DDevice),
m_Floor(m_Direct3DDevice)
{
	// Initialise world view projection matrix
	D3DXMatrixIdentity(&m_WorldViewProjection);

	// Set the position of the camera
	GetCamera().position() = D3DXVECTOR3(0.0f, 1.8f, -10.0f);

	// Set the camera up
	float aspect = (float)m_WindowWidth/m_WindowHeight;		// Used in D3DXMatrixPerspectiveFovLH()
	GetCamera().setLens(0.25f*PI, aspect, 0.5f, 1000.0f);

	// Create effects and vertex layouts 
	BuildFX();
	BuildVertexLayouts();
	fx::InitAll(m_Direct3DDevice);
	InputLayout::InitAll(m_Direct3DDevice);

	// Initialise texture manager
	GetTextureMgr().init(m_Direct3DDevice);

	// Create crate resource view
	HR( D3DX10CreateShaderResourceViewFromFile(m_Direct3DDevice,	// The device to create the texture with
											   L"GreyBricks.jpg",	// The name of the file
											   0,					// Optional image info, specify null to use source dimensions and to creat a full chain of mipmap levels
											   0,					// Used to spawn a new thread to load resources, pPump
											   &m_DiffuseMapRV,		// The pointer that is used to interface with the new resource
											   0) );				// Used with pPump

	// Create specular map resource view
	HR( D3DX10CreateShaderResourceViewFromFile(m_Direct3DDevice,	// The device to create the texture with
											   L"defaultspec.dds",	// The name of the file to sue
											   0,					// Optional image info, specify null to use source dimensions and to creat a full chain of mipmap levels 
											   0,					// Used to spawn a new thread to load resources, pPump
											   &m_SpecMapRV,		// The pointer that is used to interface with the new resource
											   0) );				// Used with pPump

	// Create crate resource view
	HR( D3DX10CreateShaderResourceViewFromFile(m_Direct3DDevice,	// The device to create the texture with
											   L"Tiles.jpg",		// The name of the file
											   0,					// Optional image info, specify null to use source dimensions and to creat a full chain of mipmap levels
											   0,					// Used to spawn a new thread to load resources, pPump
											   &m_RoofTilesRV,		// The pointer that is used to interface with the new resource
											   0) );				// Used with pPump

	// Create crate resource view
	HR( D3DX10CreateShaderResourceViewFromFile(m_Direct3DDevice,	// The device to create the texture with
											   L"Grass.jpg",		// The name of the file
											   0,					// Optional image info, specify null to use source dimensions and to creat a full chain of mipmap levels
											   0,					// Used to spawn a new thread to load resources, pPump
											   &m_GrassRV,			// The pointer that is used to interface with the new resource
											   0) );				// Used with pPump

	// Set the sky texture up
	m_EnvironmentMapRV	= GetTextureMgr().createCubeTex(L"grassenvmap1024.dds");

	// Set up parallel light
	m_ParallelLight.dir		 = D3DXVECTOR3(0.57735f, -0.57735f, -0.25f);	// Reveresed
	m_ParallelLight.ambient	 = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
	m_ParallelLight.diffuse	 = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	m_ParallelLight.specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	// Set box position
	m_Box.SetPosition(0.0f, 1.0f, 0.0f);

	m_Floor.ScaleXZ(10, 10);
	// Initialise sky
	m_Sky.init(m_Direct3DDevice, m_EnvironmentMapRV, 5000.0f);
}