예제 #1
0
/*--------------------------
  set rendering target data
  C.Wang 0522, 2006
 ---------------------------*/
void FuCShadowModify::SetRenderTarget(int w, float *bgColor)
{
   FnScene scene;
   FnWorld gw;
   FnViewport vp;
   char shadowName[256];

   scene.Object(mHost);
   gw.Object(scene.GetWorld());
   gw.DeleteMaterial(mRenderTarget);
   gw.DeleteViewport(mViewport);

   // create the viewport with the associated size
   mViewport = gw.CreateViewport(0, 0, w, w);

   // create the render target material
   mRenderTarget = gw.CreateMaterial(NULL, NULL, NULL, 1.0f, NULL);

   // generate a unique shadow texture name
   sprintf(shadowName, "shadow%d", mRenderTarget);

   FnMaterial mat;
   mat.Object(mRenderTarget);
   mat.AddRenderTargetTexture(0, 0, shadowName, TEXTURE_32, mViewport);
   mat.SetTextureAddressMode(0, CLAMP_TEXTURE);

   // set render target
   vp.Object(mViewport);
   vp.SetRenderTarget(mRenderTarget, 0, 0, 0);
   vp.SetBackgroundColor(bgColor[0], bgColor[1], bgColor[2]);
}
예제 #2
0
/*-------------------------------
  create the material for shadow
  C.Wang 0522, 2006
 --------------------------------*/
void FuCShadowModify::CreateShadowMaterial(float *color)
{
   FnWorld gw;
   FnScene scene;
   scene.Object(mHost);
   gw.Object(scene.GetWorld());

   if (mShadowMat != FAILED_MATERIAL_ID) {
      gw.DeleteMaterial(mShadowMat);
   }

   // create the material
   float blackColor[3];

   blackColor[0] = blackColor[1] = blackColor[2] = 0.0f;
   mShadowMat = gw.CreateMaterial(blackColor, blackColor, blackColor, 1.0f, color);
}
예제 #3
0
/*------------------------------------
  destructor of classic shadow object
  C.Wang 0522, 2006
 -------------------------------------*/
FuCShadowModify::~FuCShadowModify()
{
   // delete the associated camera
   FnScene scene;
   FnWorld gw;
   scene.Object(mHost);
   gw.Object(scene.GetWorld());

   gw.DeleteViewport(mViewport);
   mViewport = FAILED_ID;

   gw.DeleteMaterial(mShadowMat);
   mShadowMat = FAILED_MATERIAL_ID;

   gw.DeleteMaterial(mRenderTarget);
   mRenderTarget = FAILED_MATERIAL_ID;

   scene.DeleteCamera( m_lightCam.Object() );
   m_lightCam.Object( FAILED_ID );

   scene.DeleteObject(mSeed);
   mSeed = FAILED_ID;

}
예제 #4
0
/*----------------------------------
  display the shadow on the terrain
  C.Wang 0522, 2006
 -----------------------------------*/
void FuCShadowModify::Display()
{
	TPROFILE("Shadow Display");

	if ( m_fyActor.Object() == FAILED_ID ) 
		return;

	FnObject model;
	model.Object(mSeed);
	if (!model.GetVisibility()) 
		return;

	WORLDid wID;
	FnTriangle tT;
	FnScene scene;
	FnTerrain terrain;
	int vLen , texLen = 2, tri[3];
	float M[16], *G, vLC[3];
	
	// get all neighboring triangles
	//nList = terrain.GetAllVertexNeighborTriangles(iOne, list, 64);
	//if (nList <= 0) return;

	// get the matrix to character's base coordinate
	m_lightCam.SetWorldPosition( m_actorPos );
	G = m_lightCam.GetMatrix(TRUE);
	FyInverseM16(G, M);

	tT.Object( m_terrain.Object() , 0);
	scene.Object(mHost);
	wID = scene.GetWorld();

	// reset all rendering states
	FyResetRenderStates(wID);
	FySetD3DRenderState(wID, D3DRS_LIGHTING, FALSE);
	FySetD3DRenderState(wID, D3DRS_FOGENABLE, FALSE);
	FySetD3DRenderState(wID, D3DRS_ZWRITEENABLE, FALSE);

	// set current material
	FySetCurrentMaterial(wID, mRenderTarget, FALSE, 1.0f);

	FySetD3DRenderState(wID, D3DRS_ALPHABLENDENABLE, TRUE);
	FySetD3DRenderState(wID, D3DRS_ALPHATESTENABLE, FALSE);
	FySetD3DRenderState(wID, D3DRS_SRCBLEND, D3DBLEND_ZERO);
	FySetD3DRenderState(wID, D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);

	LPDIRECT3DDEVICE9 dev = FyGetD3DDevice(wID);
	float pos[16];


	FuLitedVertex v[3];

	// display these triangles
	vLen = 6;

	v[0].diffuse = D3DCOLOR_RGBA(255, 255, 255, 255);
	v[1].diffuse = D3DCOLOR_RGBA(255, 255, 255, 255);
	v[2].diffuse = D3DCOLOR_RGBA(255, 255, 255, 255);

	int nTri = m_triIDVec.size();
	for ( int i = 0; i < nTri ; i++) 
	{
		// get the triangle vertices
		tT.GetTopology( m_triIDVec[i] , tri);

		for ( int j = 0; j < 3; ++j ) 
		{
			tT.GetVertex(tri[2-j], pos);
			v[j].pos[0] = pos[0];
			v[j].pos[1] = pos[1];
			v[j].pos[2] = pos[2] + mShadowHeightOffset;

			// calculate the texture coordinate
			FUTransformVertexWithM16_Simple(vLC, v[j].pos, M);
			CalculateShadowUV(vLC, v[j].uv);
		}

		FyDrawTriangles(wID, XYZ_DIFFUSE, 3 , 1 , &texLen, (float *) &v[0] );

	}

}