Example #1
0
void Scene::Render(Camera *targetCamera) {
	
	if(!targetCamera && !activeCamera)
		return;
	
	if(!targetCamera)
		targetCamera = activeCamera;
	
	// prepare lights...
	for(int i=0; i<entities.size();i++) {
		entities[i]->doUpdates();		
		entities[i]->updateEntityMatrix();
	}	
	
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	targetCamera->rebuildTransformMatrix();
		
	if(useClearColor)
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b);	
	
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		
	
	CoreServices::getInstance()->getRenderer()->clearLights();
	
	for(int i=0; i < lights.size(); i++) {
		SceneLight *light = lights[i];
		if(!light->enabled)
			continue;
			
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;		
		direction.y = 0;
		direction.z = -1;
		
		
		direction = light->getConcatenatedMatrix().rotateVector(direction);
		direction.Normalize();
		
		Texture *shadowMapTexture = NULL;
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
//				textureMatrix.identity();
				
				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );
				
								
				light->renderDepthMap(this);
				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
				matrixPtr = &textureMatrix;				
			//	CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
				shadowMapTexture = light->getZBufferTexture();
			}
		}
		
		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
		CoreServices::getInstance()->getRenderer()->addLight(light->getLightImportance(), position, direction, light->getLightType(), light->lightColor, light->specularLightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr, shadowMapTexture);
	}	
	
	targetCamera->doCameraTransform();
	targetCamera->buildFrustrumPlanes();
	
	if(targetCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->_setOrthoMode();
	}
	
	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);	
	if(fogEnabled) {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, fogDensity, fogStartDepth, fogEndDepth);
	} else {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, 0.0, fogStartDepth, fogEndDepth);	
	}
	
	
	for(int i=0; i<entities.size();i++) {
		if(entities[i]->getBBoxRadius() > 0) {
			if(targetCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
				entities[i]->transformAndRender();
		} else {
			entities[i]->transformAndRender();		
		}
	}
	
	if(targetCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->setPerspectiveMode();
	}
	
}
Example #2
0
void Scene::Render(Camera *targetCamera, Texture *targetFramebuffer) {
    if(!targetCamera && !activeCamera)
        return;
    if(!targetCamera)
        targetCamera = activeCamera;
    
    GPUDrawBuffer *drawBuffer = new GPUDrawBuffer();
    drawBuffer->clearColor = clearColor;
    drawBuffer->clearColorBuffer = useClearColor;
    drawBuffer->clearDepthBuffer = useClearDepth;
    drawBuffer->targetFramebuffer = targetFramebuffer;
    drawBuffer->viewport = targetCamera->getViewport();
    drawBuffer->globalMaterial = overrideMaterial;	
		
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	targetCamera->rebuildTransformMatrix();
    
    drawBuffer->projectionMatrix = targetCamera->createProjectionMatrix();
    drawBuffer->viewMatrix = targetCamera->getConcatenatedMatrix().Inverse();
    drawBuffer->cameraMatrix = targetCamera->getConcatenatedMatrix();
/*
	if(useClearColor) {
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b, clearColor.a);	
	}
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);
*/
	
	for(int i=0; i < lights.size(); i++) {
		SceneLight *light = lights[i];
		if(!light->enabled)
			continue;
			
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;
		direction.y = 0.0;
		direction.z = -1.0;
		direction.Normalize();
		
		direction = light->getConcatenatedMatrix().rotateVector(direction);
		
		Texture *shadowMapTexture = NULL;
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );
				
				light->renderDepthMap(this);
				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
				matrixPtr = &textureMatrix;
				shadowMapTexture = light->getZBufferTexture();
			}
		}
		
		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
        
        
        drawBuffer->lights.push_back(light->getLightInfo());
        drawBuffer->lights[drawBuffer->lights.size()-1].position = position;
        drawBuffer->lights[drawBuffer->lights.size()-1].direction = direction;
	}	
		
    	/*
    if(_doVisibilityChecking) {
        targetCamera->buildFrustumPlanes();
        setEntityVisibility(&rootEntity, targetCamera);
    }
         */
	rootEntity.transformAndRender(drawBuffer, NULL);

    
    renderer->processDrawBuffer(drawBuffer);
    
}
Example #3
0
void GenericScene::Render() {
	
	if(!defaultCamera)
		return;
	
	// prepare lights...
	for(int i=0; i<entities.size();i++) {
		entities[i]->doUpdates();		
		entities[i]->updateEntityMatrix();
	}	
	
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	defaultCamera->rebuildTransformMatrix();
	
	if(virtualScene)
		return;
	
	if(useClearColor)
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b);	
	
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		

	CoreServices::getInstance()->getRenderer()->clearLights();
	
	for(int i=0; i < lights.size(); i++) {
		
		SceneLight *light = lights[i];
		
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;		
		direction.y = 1;
		direction.z = 0;

		direction = light->getConcatenatedMatrix().rotateVector(direction);
		direction.Normalize();
		
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
				textureMatrix.identity();

				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );

				textureMatrix =  defaultCamera->getConcatenatedMatrix() * light->getLightViewMatrix() * matTexAdj;
			
				matrixPtr = &textureMatrix;
				light->renderDepthMap(this);
				CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
			}
		}

		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
		CoreServices::getInstance()->getRenderer()->addLight(position, direction, light->getLightType(), light->lightColor, light->getDistance(), light->getIntensity(), matrixPtr);
	}	
	
	defaultCamera->doCameraTransform();
	defaultCamera->buildFrustrumPlanes();
	
	if(defaultCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->_setOrthoMode();
	}
	
	for(int i=0; i<entities.size();i++) {
		if(entities[i]->getBBoxRadius() > 0) {
			if(defaultCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
				entities[i]->transformAndRender();
		} else {
			entities[i]->transformAndRender();		
		}
	}
	
	if(defaultCamera->getOrthoMode()) {
		CoreServices::getInstance()->getRenderer()->setPerspectiveMode();
	}
	
}
Example #4
0
void Scene::Render(Camera *targetCamera) {	
	if(!targetCamera && !activeCamera)
		return;
    
    renderer->setOverrideMaterial(overrideMaterial);
	
	if(!targetCamera)
		targetCamera = activeCamera;
		
	//make these the closest
	
	Matrix4 textureMatrix;
	Matrix4 *matrixPtr;
	
	
	targetCamera->rebuildTransformMatrix();
		
	if(useClearColor) {
		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b, clearColor.a);	
	}
	if (useClearColor || useClearDepth) {
		CoreServices::getInstance()->getRenderer()->clearScreen(useClearColor, useClearDepth);
	}
	
	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		
	
	CoreServices::getInstance()->getRenderer()->clearLights();
	
	for(int i=0; i < lights.size(); i++) {
		SceneLight *light = lights[i];
		if(!light->enabled)
			continue;
			
		Vector3 direction;
		Vector3 position;
		matrixPtr = NULL;				
		direction.x = 0;
		direction.y = 0.0;
		direction.z = -1.0;
		direction.Normalize();
		
		direction = light->getConcatenatedMatrix().rotateVector(direction);
		
		Texture *shadowMapTexture = NULL;
		if(light->areShadowsEnabled()) {
			if(light->getType() == SceneLight::SPOT_LIGHT) {
//				textureMatrix.identity();
				
				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
								  0.0f,	0.5f,	0.0f,	0.0f,
								  0.0f,	0.0f,	0.5f,	0.0f,
								  0.5f,	0.5f,	0.5f,	1.0f );
				
				light->renderDepthMap(this);
				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
				matrixPtr = &textureMatrix;				
			//	CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
				shadowMapTexture = light->getZBufferTexture();
			}
		}
		
		position = light->getPosition();
		if(light->getParentEntity() != NULL) {
			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
		}
		CoreServices::getInstance()->getRenderer()->addLight(light->getLightImportance(), position, direction, light->getLightType(), light->lightColor, light->specularLightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr, shadowMapTexture);
	}	
		
	targetCamera->doCameraTransform();
    
	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);
	if(fogEnabled) {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, fogDensity, fogStartDepth, fogEndDepth);
	} else {
		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, 0.0, fogStartDepth, fogEndDepth);	
	}
	
    if(_doVisibilityChecking) {
        targetCamera->buildFrustumPlanes();
        setEntityVisibility(&rootEntity, targetCamera);
    }
	rootEntity.transformAndRender();		
}