Beispiel #1
0
void ActorSet::moveObject(ActorSet &dest, OBJECT_ID id)
{
	ASSERT(isMember(id), "The object is not a member of this set");
	ASSERT(!dest.isMember(id), "The object is already a member of the other set");

	// Add it to the other set
	dest.insert(  make_pair(id, toActor(*find(id)))  );

	// Remove it from this set
	erase(find(id));
}
Beispiel #2
0
void Shadow::bind(const ActorSet &zoneActors, unsigned int textureUnit) const
{
	if(light!=0 && zoneActors.isMember(actorID))
	{
		CHECK_GL_ERROR();

		// Bind shadow texture
		glActiveTextureARB(textureStages[textureUnit]);
		glClientActiveTextureARB(textureStages[textureUnit]);
		glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
		glEnable(GL_TEXTURE_2D);

		// Define the matrix
		const float row1[4] = {textureMatrix.m[0], textureMatrix.m[4], textureMatrix.m[8], textureMatrix.m[12]};
		const float row2[4] = {textureMatrix.m[1], textureMatrix.m[5], textureMatrix.m[9], textureMatrix.m[13]};
		const float row3[4] = {textureMatrix.m[2], textureMatrix.m[6], textureMatrix.m[10], textureMatrix.m[14]};
		const float row4[4] = {textureMatrix.m[3], textureMatrix.m[7], textureMatrix.m[11], textureMatrix.m[15]};

		// Enable tex coord generation
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
		glEnable(GL_TEXTURE_GEN_R);
		glEnable(GL_TEXTURE_GEN_Q);

		// Define the parameters of the generation
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

		// Pass the texture matrix we defined above
		glTexGenfv(GL_S, GL_EYE_PLANE, row1);
		glTexGenfv(GL_T, GL_EYE_PLANE, row2);
		glTexGenfv(GL_R, GL_EYE_PLANE, row3);
		glTexGenfv(GL_Q, GL_EYE_PLANE, row4);

		// Enable shadow comparison
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
		glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);

		CHECK_GL_ERROR();
	}
}
Beispiel #3
0
void Shadow::update(const ActorSet &zoneActors, float deltaTime)
{
	if(light!=0 && zoneActors.isMember(actorID))
	{
		const Actor &actor = zoneActors.get(actorID);

		// Update the shadow when something has changed
		needsUpdate |= (actor.hasAnimated || actor.hasMoved);

		// Update when necessary or requested
		if(needsUpdate)
		{
			float lx=0, ly=0;

			calculateAngularSpread(actor, lightViewMatrix, lx, ly);

			calculateMatrices(*light, actor, shadowMapSize, lightProjectionMatrix, lightViewMatrix, textureMatrix, lx, ly);

			frustum = calculateFrustum(lightProjectionMatrix, lightViewMatrix);

			if(g_Application.displayDebugData)
			{
				calculateFrustumVertices(*light, actor, lx, ly, ntl, ntr, nbl, nbr, ftl, ftr, fbl, fbr);
			}

			renderToShadow(shadowMapTexture, shadowMapSize, actor, lightProjectionMatrix, lightViewMatrix);

			needsUpdate=false;
		}

		// Periodically take some time to determine the actors that be receiving this shadow
		periodicTimer-=deltaTime;
		if(periodicTimer<0)
		{
			periodicTimer = 250.0f + FRAND_RANGE(100.0f, 250.0f); // stagger
			receivers = calculateReceivers(zoneActors, lightProjectionMatrix, lightViewMatrix);
		}
	}
}