Search in sources :

Example 1 with ObjectParticleSystemEntity

use of net.drewke.tdme.engine.ObjectParticleSystemEntity in project tdme by andreasdr.

the class ShadowMap method render.

/**
	 * Renders given objects to shadow map
	 * @param gl
	 * @param objects
	 */
protected void render(Light light, ArrayList<Object3D> objects) {
    // clear visible objects
    visibleObjects.clear();
    // TODO: Spotlights are different!
    // viewers camera
    Camera camera = shadowMapping.engine.getCamera();
    float lightEyeDistance = lightDirection.set(camera.getLookAt()).sub(camera.getLookFrom()).computeLength() * shadowMapping.lightEyeDistanceScale;
    // compute camera from view of light 
    lightDirection.set(light.getSpotDirection()).normalize();
    lightLookAt.set(camera.getLookAt());
    lightLookFrom.set(lightLookAt).sub(lightDirection.scale(lightEyeDistance));
    // determine light camera z far
    float lightCameraZFar = lightEyeDistance * 2.0f;
    if (camera.getZFar() > lightCameraZFar)
        lightCameraZFar = camera.getZFar();
    // set up light camera from view of light
    lightCamera.setZNear(camera.getZNear());
    lightCamera.setZFar(lightCameraZFar);
    lightCamera.getLookFrom().set(lightLookFrom);
    lightCamera.getLookAt().set(lightLookAt);
    lightCamera.computeUpVector(lightCamera.getLookFrom(), lightCamera.getLookAt(), lightCamera.getUpVector());
    lightCamera.update(frameBuffer.getWidth(), frameBuffer.getHeight());
    // Bind frame buffer to shadow map fbo id
    frameBuffer.enableFrameBuffer();
    // clear depth buffer
    shadowMapping.renderer.clear(shadowMapping.renderer.CLEAR_DEPTH_BUFFER_BIT);
    // determine visible objects and objects that should generate a shadow
    for (Entity entity : shadowMapping.engine.getPartition().getVisibleEntities(lightCamera.getFrustum())) {
        if (entity instanceof Object3D) {
            Object3D object = (Object3D) entity;
            if (object.isDynamicShadowingEnabled() == false)
                continue;
            visibleObjects.add(object);
        } else if (entity instanceof ObjectParticleSystemEntity) {
            ObjectParticleSystemEntity opse = (ObjectParticleSystemEntity) entity;
            if (opse.isDynamicShadowingEnabled() == false)
                continue;
            visibleObjects.addAll(opse.getEnabledObjects());
        }
    }
    // generate shadow map texture matrix
    computeDepthBiasMVPMatrix();
    // only draw opaque face entities as shadows will not be produced from transparent objects
    shadowMapping.object3DVBORenderer.render(visibleObjects, true, Object3DVBORenderer.DepthBufferMode.FORCE, null);
}
Also used : ObjectParticleSystemEntity(net.drewke.tdme.engine.ObjectParticleSystemEntity) Entity(net.drewke.tdme.engine.Entity) ObjectParticleSystemEntity(net.drewke.tdme.engine.ObjectParticleSystemEntity) Camera(net.drewke.tdme.engine.Camera) Object3D(net.drewke.tdme.engine.Object3D)

Aggregations

Camera (net.drewke.tdme.engine.Camera)1 Entity (net.drewke.tdme.engine.Entity)1 Object3D (net.drewke.tdme.engine.Object3D)1 ObjectParticleSystemEntity (net.drewke.tdme.engine.ObjectParticleSystemEntity)1