예제 #1
0
	//------------------------------------------------------------------------------------
	Mesh* SceneManager::CreatePlaneMesh( float w, float h )
	{
		float halfW = w / 2;
		float halfH = h / 2;

		SVertex vert[4] =
		{
			SVertex(VEC3(-w,0,+h), VEC2(0,0), VEC3::UNIT_Y),
			SVertex(VEC3(+w,0,+h), VEC2(1,0), VEC3::UNIT_Y),
			SVertex(VEC3(+w,0,-h), VEC2(1,1), VEC3::UNIT_Y),
			SVertex(VEC3(-w,0,-h), VEC2(0,1), VEC3::UNIT_Y),
		};

		DWORD dwIndex[6] = {0,1,3,1,2,3};

		Mesh* pMesh =  new Mesh;
		SubMesh* pSubmesh = new SubMesh;

		pSubmesh->InitVertData(eVertexType_General, vert, 4, true);
		pSubmesh->InitIndexData(dwIndex, 6, true);

		pMesh->AddSubMesh(pSubmesh);

		return pMesh;
	}
예제 #2
0
	//------------------------------------------------------------------------------------
	void TerrainQuadTreeNode::CreateEntity()
	{
		// Create the entity.
		if (isRenderedAtCurrentLod() && !mEntity)
		{
			Mesh* pMesh = new Mesh;
			SubMesh* pSubmesh = new SubMesh;

			pMesh->SetPrimitiveType(ePrimitive_TriangleStrip);
			pSubmesh->InitTerrainVertData(getVertexDataRecord()->gpuPosVertexBuf, getVertexDataRecord()->gpuDeltaVertexBuf,
				mLodLevels[mCurrentLod]->pIndexBuf, mLodLevels[mCurrentLod]->nIndexCount);

			pMesh->AddSubMesh(pSubmesh);
			mEntity = new Entity(pMesh);
			mEntity->SetCastShadow(false);

			// vertex data is generated in terrain space
			mEntity->SetPosition(mTerrain->getPosition());

			static uint32 iMat = 0;
			++iMat;
			char szMatName[64];
			sprintf_s(szMatName, 64, "Mtl_TerrainSector_%d", iMat);

			Material* pMaterial = MaterialManager::GetSingleton().NewMaterial(szMatName, eVertexType_Terrain);

			pMaterial->SetTexture(0, mTerrain->getTerrainNormalMap());
			pMaterial->SetTexture(1, mTerrain->getLayerBlendTexture(0));

			SSamplerDesc& samDesc = pMaterial->GetSamplerStateDesc(0);
			samDesc.AddressU = eTextureAddressMode_WRAP;
			samDesc.AddressV = eTextureAddressMode_WRAP;
			samDesc.Filter = SF_MIN_MAG_MIP_LINEAR;
			pMaterial->SetSamplerStateDesc(0, samDesc);
			pMaterial->SetSamplerStateDesc(1, samDesc);

			for (uint32 i = 0; i < mTerrain->getLayerCount(); ++i)
			{
				pMaterial->SetTexture(2+i*2, g_env.pRenderer->GetRenderSys()->LoadTexture(mTerrain->getLayerTextureName(i, 0), eTextureType_2D, 0, true));
				pMaterial->SetTexture(2+i*2+1, g_env.pRenderer->GetRenderSys()->LoadTexture(mTerrain->getLayerTextureName(i, 1)));

				pMaterial->SetSamplerStateDesc(2 + i * 2, samDesc);
				pMaterial->SetSamplerStateDesc(2 + i * 2 + 1, samDesc);
			}

			pMaterial->InitShader("Terrain", eShader_Terrain, 0, nullptr, "VS_GBuffer", "PS_GBuffer");
			mEntity->SetMaterial(pMaterial);
		}

		if (mChildren[0])
		{
			mChildren[0]->CreateEntity();
			mChildren[1]->CreateEntity();
			mChildren[2]->CreateEntity();
			mChildren[3]->CreateEntity();
		}
	}
예제 #3
0
파일: Decal.cpp 프로젝트: mavaL/NeoEngine
	//------------------------------------------------------------------------------------
	Decal::Decal(const VEC3& pos, float size, const QUATERNION& rot)
		: m_vPos(pos)
		, m_fSize(size)
		, m_pMaterial(nullptr)
	{
		if (!m_pUnitCube)
		{
			SVertex vert[8] =
			{
				SVertex(VEC3(-0.5f, -0.5f, +0.5f), VEC2(0, 0)),
				SVertex(VEC3(+0.5f, -0.5f, +0.5f), VEC2(0, 0)),
				SVertex(VEC3(+0.5f, -0.5f, -0.5f), VEC2(0, 0)),
				SVertex(VEC3(-0.5f, -0.5f, -0.5f), VEC2(0, 0)),
				SVertex(VEC3(-0.5f, +0.5f, +0.5f), VEC2(0, 0)),
				SVertex(VEC3(+0.5f, +0.5f, +0.5f), VEC2(0, 0)),
				SVertex(VEC3(+0.5f, +0.5f, -0.5f), VEC2(0, 0)),
				SVertex(VEC3(-0.5f, +0.5f, -0.5f), VEC2(0, 0)),
			};

			DWORD dwIndex[36] = {
				0,2,1,0,3,2,		// bottom
				4,5,7,5,6,7,		// top
				4,7,0,7,3,0,		// left
				6,5,2,5,1,2,		// right
				7,6,3,6,2,3,		// behind
				5,4,1,4,0,1,		// front
			};

			Mesh* pMesh = new Mesh;
			SubMesh* pSubmesh = new SubMesh;

			pSubmesh->InitVertData(eVertexType_General, vert, 8, true);
			pSubmesh->InitIndexData(dwIndex, 36, true);

			pMesh->AddSubMesh(pSubmesh);

			m_pUnitCube = new Entity(pMesh);
			m_pUnitCube->SetCastShadow(false);

			m_pCB_Decal = g_env.pRenderer->GetRenderSys()->CreateConstantBuffer(sizeof(cBufferDecal), 10);
		}

		m_cbDecal.matRotation = rot.ToRotationMatrix().Transpose();
		m_cbDecal.fProjClip = 10000.f;
	}
예제 #4
0
	//------------------------------------------------------------------------------------
	Mesh* SceneManager::CreateFrustumMesh( const VEC3& minBottom, const VEC3& maxBottom, const VEC3& minTop, const VEC3& maxTop )
	{
		Neo::SVertex vert[24];

		// front side
		vert[0].pos.Set(minBottom.x, minBottom.y, maxBottom.z);
		vert[0].uv.Set(0, 1);
		vert[1].pos.Set(maxBottom.x, minBottom.y, maxBottom.z);
		vert[1].uv.Set(1, 1);
		vert[2].pos.Set(maxTop.x, minTop.y, maxTop.z);
		vert[2].uv.Set(1, 0);
		vert[3].pos.Set(minTop.x, minTop.y, maxTop.z);
		vert[3].uv.Set(0, 0);

		// back side
		vert[4].pos.Set(maxBottom.x, minBottom.y, minBottom.z);
		vert[4].uv.Set(0, 1);
		vert[5].pos.Set(minBottom.x, minBottom.y, minBottom.z);
		vert[5].uv.Set(1, 1);
		vert[6].pos.Set(minTop.x, minTop.y, minTop.z);
		vert[6].uv.Set(1, 0);
		vert[7].pos.Set(maxTop.x, minTop.y, minTop.z);
		vert[7].uv.Set(0, 0);

		// left side
		vert[8].pos.Set(minBottom.x, minBottom.y, minBottom.z);
		vert[9].pos.Set(minBottom.x, minBottom.y, maxBottom.z);
		vert[10].pos.Set(minTop.x, minTop.y, maxTop.z);
		vert[11].pos.Set(minTop.x, minTop.y, minTop.z);
		vert[8].uv.Set(0, 1);
		vert[9].uv.Set(1, 1);
		vert[10].uv.Set(1, 0);
		vert[11].uv.Set(0, 0);

		// right side
		vert[12].pos.Set(maxBottom.x, minBottom.y, maxBottom.z);
		vert[13].pos.Set(maxBottom.x, minBottom.y, minBottom.z);
		vert[14].pos.Set(maxTop.x, minTop.y, minTop.z);
		vert[15].pos.Set(maxTop.x, minTop.y, maxTop.z);
		vert[12].uv.Set(0, 1);
		vert[13].uv.Set(1, 1);
		vert[14].uv.Set(1, 0);
		vert[15].uv.Set(0, 0);

		// up side
		vert[16].pos.Set(minTop.x, minTop.y, maxTop.z);
		vert[17].pos.Set(maxTop.x, minTop.y, maxTop.z);
		vert[18].pos.Set(maxTop.x, minTop.y, minTop.z);
		vert[19].pos.Set(minTop.x, minTop.y, minTop.z);
		vert[16].uv.Set(0, 1);
		vert[17].uv.Set(1, 1);
		vert[18].uv.Set(1, 0);
		vert[19].uv.Set(0, 0);

		// down side
		vert[20].pos.Set(minBottom.x, minBottom.y, minBottom.z);
		vert[21].pos.Set(maxBottom.x, minBottom.y, minBottom.z);
		vert[22].pos.Set(maxBottom.x, minBottom.y, maxBottom.z);
		vert[23].pos.Set(minBottom.x, minBottom.y, maxBottom.z);
		vert[20].uv.Set(0, 1);
		vert[21].uv.Set(1, 1);
		vert[22].uv.Set(1, 0);
		vert[23].uv.Set(0, 0);

		DWORD faces[6*2*3] = {
			// front
			0,1,2,
			0,2,3,

			// back
			4,5,6,
			4,6,7,

			// left
			8,9,10,
			8,10,11,

			// right
			12,13,14,
			12,14,15,

			// up
			16,17,18,
			16,18,19,

			// down
			20,21,22,
			20,22,23
		};

		Mesh* pMesh =  new Mesh;
		SubMesh* pSubmesh = new SubMesh;

		pSubmesh->InitVertData(eVertexType_General, vert, 24, true);
		pSubmesh->InitIndexData(faces, 6*2*3, true);

		pMesh->AddSubMesh(pSubmesh);

		return pMesh;
	}
예제 #5
0
	//------------------------------------------------------------------------------------
	Mesh* SceneManager::CreateCubeMesh( const VEC3& minPt, const VEC3& maxPt )
	{
		SVertex vert[24];

		// front side
		vert[0].pos.Set(minPt.x, minPt.y, maxPt.z);
		vert[0].uv.Set(0, 1);
		vert[1].pos.Set(maxPt.x, minPt.y, maxPt.z);
		vert[1].uv.Set(1, 1);
		vert[2].pos.Set(maxPt.x, maxPt.y, maxPt.z);
		vert[2].uv.Set(1, 0);
		vert[3].pos.Set(minPt.x, maxPt.y, maxPt.z);
		vert[3].uv.Set(0, 0);

		vert[0].normal = vert[1].normal = vert[2].normal = vert[3].normal = VEC3::UNIT_Z;

		// back side
		vert[4].pos.Set(maxPt.x, minPt.y, minPt.z);
		vert[4].uv.Set(0, 1);
		vert[5].pos.Set(minPt.x, minPt.y, minPt.z);
		vert[5].uv.Set(1, 1);
		vert[6].pos.Set(minPt.x, maxPt.y, minPt.z);
		vert[6].uv.Set(1, 0);
		vert[7].pos.Set(maxPt.x, maxPt.y, minPt.z);
		vert[7].uv.Set(0, 0);

		vert[4].normal = vert[5].normal = vert[6].normal = vert[7].normal = VEC3::NEG_UNIT_Z;

		// left side
		vert[8].pos.Set(minPt.x, minPt.y, minPt.z);
		vert[9].pos.Set(minPt.x, minPt.y, maxPt.z);
		vert[10].pos.Set(minPt.x, maxPt.y, maxPt.z);
		vert[11].pos.Set(minPt.x, maxPt.y, minPt.z);
		vert[8].uv.Set(0, 1);
		vert[9].uv.Set(1, 1);
		vert[10].uv.Set(1, 0);
		vert[11].uv.Set(0, 0);

		vert[8].normal = vert[9].normal = vert[10].normal = vert[11].normal = VEC3::NEG_UNIT_X;

		// right side
		vert[12].pos.Set(maxPt.x, minPt.y, maxPt.z);
		vert[13].pos.Set(maxPt.x, minPt.y, minPt.z);
		vert[14].pos.Set(maxPt.x, maxPt.y, minPt.z);
		vert[15].pos.Set(maxPt.x, maxPt.y, maxPt.z);
		vert[12].uv.Set(0, 1);
		vert[13].uv.Set(1, 1);
		vert[14].uv.Set(1, 0);
		vert[15].uv.Set(0, 0);

		vert[12].normal = vert[13].normal = vert[14].normal = vert[15].normal = VEC3::UNIT_X;

		// up side
		vert[16].pos.Set(minPt.x, maxPt.y, maxPt.z);
		vert[17].pos.Set(maxPt.x, maxPt.y, maxPt.z);
		vert[18].pos.Set(maxPt.x, maxPt.y, minPt.z);
		vert[19].pos.Set(minPt.x, maxPt.y, minPt.z);
		vert[16].uv.Set(0, 1);
		vert[17].uv.Set(1, 1);
		vert[18].uv.Set(1, 0);
		vert[19].uv.Set(0, 0);

		vert[16].normal = vert[17].normal = vert[18].normal = vert[19].normal = VEC3::UNIT_Y;

		// down side
		vert[20].pos.Set(minPt.x, minPt.y, minPt.z);
		vert[21].pos.Set(maxPt.x, minPt.y, minPt.z);
		vert[22].pos.Set(maxPt.x, minPt.y, maxPt.z);
		vert[23].pos.Set(minPt.x, minPt.y, maxPt.z);
		vert[20].uv.Set(0, 1);
		vert[21].uv.Set(1, 1);
		vert[22].uv.Set(1, 0);
		vert[23].uv.Set(0, 0);

		vert[20].normal = vert[21].normal = vert[22].normal = vert[23].normal = VEC3::NEG_UNIT_Y;

		DWORD faces[6*2*3] = {
			// front
			0,1,2,
			0,2,3,

			// back
			4,5,6,
			4,6,7,

			// left
			8,9,10,
			8,10,11,

			// right
			12,13,14,
			12,14,15,

			// up
			16,17,18,
			16,18,19,

			// down
			20,21,22,
			20,22,23
		};

		Mesh* pCube =  new Mesh;
		SubMesh* pSubmesh = new SubMesh;

		pSubmesh->InitVertData(eVertexType_General, vert, 24, true);
		pSubmesh->InitIndexData(faces, 6*2*3, true);

		pCube->AddSubMesh(pSubmesh);

		return pCube;
	}