Search in sources :

Example 1 with DirectionalLightsAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute in project libgdx by libgdx.

the class Benchmark3DTest method getStatus.

protected void getStatus(final StringBuilder stringBuilder) {
    stringBuilder.setLength(0);
    stringBuilder.append("GL calls: ");
    stringBuilder.append(GLProfiler.calls);
    glCallsLabel.setText(stringBuilder);
    stringBuilder.setLength(0);
    stringBuilder.append("Draw calls: ");
    stringBuilder.append(GLProfiler.drawCalls);
    drawCallsLabel.setText(stringBuilder);
    stringBuilder.setLength(0);
    stringBuilder.append("Shader switches: ");
    stringBuilder.append(GLProfiler.shaderSwitches);
    shaderSwitchesLabel.setText(stringBuilder);
    stringBuilder.setLength(0);
    stringBuilder.append("Texture bindings: ");
    stringBuilder.append(GLProfiler.textureBindings);
    textureBindsLabel.setText(stringBuilder);
    stringBuilder.setLength(0);
    stringBuilder.append("Vertices: ");
    stringBuilder.append(GLProfiler.vertexCount.total);
    vertexCountLabel.setText(stringBuilder);
    DirectionalLightsAttribute dirLights = (DirectionalLightsAttribute) environment.get(DirectionalLightsAttribute.Type);
    PointLightsAttribute pointLights = (PointLightsAttribute) environment.get(PointLightsAttribute.Type);
    stringBuilder.setLength(0);
    stringBuilder.append("Lights: ");
    stringBuilder.append((dirLights == null ? 0 : dirLights.lights.size) + (pointLights == null ? 0 : pointLights.lights.size));
    stringBuilder.append(", Directional: ");
    stringBuilder.append(dirLights == null ? 0 : dirLights.lights.size);
    stringBuilder.append(", Point: ");
    stringBuilder.append(pointLights == null ? 0 : pointLights.lights.size);
    lightsLabel.setText(stringBuilder);
    GLProfiler.reset();
    stringBuilder.setLength(0);
    super.getStatus(stringBuilder);
}
Also used : DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute) PointLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute)

Example 2 with DirectionalLightsAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute in project libgdx by libgdx.

the class MainShader method bindDirectionalShadows.

public void bindDirectionalShadows(final Attributes attributes) {
    final DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
    final Array<DirectionalLight> dirs = dla == null ? null : dla.lights;
    if (dirLightsLoc >= 0) {
        for (int i = 0; i < directionalLights.length; i++) {
            if (dirs == null || dirs.size <= i) {
                continue;
            }
            int idx = dirShadowsLoc + i * dirShadowsSize;
            // Shadow
            ObjectMap<DirectionalLight, LightProperties> dirCameras = shadowSystem.getDirectionalCameras();
            DirectionalLight dl = dirs.get(i);
            if (shadowSystem.hasLight(dl)) {
                // UVTransform
                final TextureRegion tr = dirCameras.get(dl).region;
                Camera cam = dirCameras.get(dl).camera;
                if (cam != null) {
                    program.setUniformf(idx + dirShadowsUvTransformOffset, tr.getU(), tr.getV(), tr.getU2() - tr.getU(), tr.getV2() - tr.getV());
                    // ProjViewTrans
                    idx = dirShadowMapProjViewTransLoc + i * dirShadowMapProjViewTransSize;
                    program.setUniformMatrix(idx, dirCameras.get(dl).camera.combined);
                }
            }
            if (dirLightsSize <= 0)
                break;
        }
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) LightProperties(com.badlogic.gdx.tests.g3d.shadows.system.BaseShadowSystem.LightProperties) Camera(com.badlogic.gdx.graphics.Camera)

Example 3 with DirectionalLightsAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute in project libgdx by libgdx.

the class Environment method remove.

public Environment remove(DirectionalLight light) {
    if (has(DirectionalLightsAttribute.Type)) {
        DirectionalLightsAttribute dirLights = ((DirectionalLightsAttribute) get(DirectionalLightsAttribute.Type));
        dirLights.lights.removeValue(light, false);
        if (dirLights.lights.size == 0)
            remove(DirectionalLightsAttribute.Type);
    }
    return this;
}
Also used : DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)

Example 4 with DirectionalLightsAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute in project libgdx by libgdx.

the class Environment method add.

public Environment add(DirectionalLight light) {
    DirectionalLightsAttribute dirLights = ((DirectionalLightsAttribute) get(DirectionalLightsAttribute.Type));
    if (dirLights == null)
        set(dirLights = new DirectionalLightsAttribute());
    dirLights.lights.add(light);
    return this;
}
Also used : DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)

Example 5 with DirectionalLightsAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute in project libgdx by libgdx.

the class DefaultShader method bindLights.

protected void bindLights(final Renderable renderable, final Attributes attributes) {
    final Environment lights = renderable.environment;
    final DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
    final Array<DirectionalLight> dirs = dla == null ? null : dla.lights;
    final PointLightsAttribute pla = attributes.get(PointLightsAttribute.class, PointLightsAttribute.Type);
    final Array<PointLight> points = pla == null ? null : pla.lights;
    final SpotLightsAttribute sla = attributes.get(SpotLightsAttribute.class, SpotLightsAttribute.Type);
    final Array<SpotLight> spots = sla == null ? null : sla.lights;
    if (dirLightsLoc >= 0) {
        for (int i = 0; i < directionalLights.length; i++) {
            if (dirs == null || i >= dirs.size) {
                if (lightsSet && directionalLights[i].color.r == 0f && directionalLights[i].color.g == 0f && directionalLights[i].color.b == 0f)
                    continue;
                directionalLights[i].color.set(0, 0, 0, 1);
            } else if (lightsSet && directionalLights[i].equals(dirs.get(i)))
                continue;
            else
                directionalLights[i].set(dirs.get(i));
            int idx = dirLightsLoc + i * dirLightsSize;
            program.setUniformf(idx + dirLightsColorOffset, directionalLights[i].color.r, directionalLights[i].color.g, directionalLights[i].color.b);
            program.setUniformf(idx + dirLightsDirectionOffset, directionalLights[i].direction.x, directionalLights[i].direction.y, directionalLights[i].direction.z);
            if (dirLightsSize <= 0)
                break;
        }
    }
    if (pointLightsLoc >= 0) {
        for (int i = 0; i < pointLights.length; i++) {
            if (points == null || i >= points.size) {
                if (lightsSet && pointLights[i].intensity == 0f)
                    continue;
                pointLights[i].intensity = 0f;
            } else if (lightsSet && pointLights[i].equals(points.get(i)))
                continue;
            else
                pointLights[i].set(points.get(i));
            int idx = pointLightsLoc + i * pointLightsSize;
            program.setUniformf(idx + pointLightsColorOffset, pointLights[i].color.r * pointLights[i].intensity, pointLights[i].color.g * pointLights[i].intensity, pointLights[i].color.b * pointLights[i].intensity);
            program.setUniformf(idx + pointLightsPositionOffset, pointLights[i].position.x, pointLights[i].position.y, pointLights[i].position.z);
            if (pointLightsIntensityOffset >= 0)
                program.setUniformf(idx + pointLightsIntensityOffset, pointLights[i].intensity);
            if (pointLightsSize <= 0)
                break;
        }
    }
    if (spotLightsLoc >= 0) {
        for (int i = 0; i < spotLights.length; i++) {
            if (spots == null || i >= spots.size) {
                if (lightsSet && spotLights[i].intensity == 0f)
                    continue;
                spotLights[i].intensity = 0f;
            } else if (lightsSet && spotLights[i].equals(spots.get(i)))
                continue;
            else
                spotLights[i].set(spots.get(i));
            int idx = spotLightsLoc + i * spotLightsSize;
            program.setUniformf(idx + spotLightsColorOffset, spotLights[i].color.r * spotLights[i].intensity, spotLights[i].color.g * spotLights[i].intensity, spotLights[i].color.b * spotLights[i].intensity);
            program.setUniformf(idx + spotLightsPositionOffset, spotLights[i].position);
            program.setUniformf(idx + spotLightsDirectionOffset, spotLights[i].direction);
            program.setUniformf(idx + spotLightsCutoffAngleOffset, spotLights[i].cutoffAngle);
            program.setUniformf(idx + spotLightsExponentOffset, spotLights[i].exponent);
            if (spotLightsIntensityOffset >= 0)
                program.setUniformf(idx + spotLightsIntensityOffset, spotLights[i].intensity);
            if (spotLightsSize <= 0)
                break;
        }
    }
    if (attributes.has(ColorAttribute.Fog)) {
        set(u_fogColor, ((ColorAttribute) attributes.get(ColorAttribute.Fog)).color);
    }
    if (lights != null && lights.shadowMap != null) {
        set(u_shadowMapProjViewTrans, lights.shadowMap.getProjViewTrans());
        set(u_shadowTexture, lights.shadowMap.getDepthMap());
        set(u_shadowPCFOffset, 1.f / (2f * lights.shadowMap.getDepthMap().texture.getWidth()));
    }
    lightsSet = true;
}
Also used : DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) Environment(com.badlogic.gdx.graphics.g3d.Environment) PointLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute) SpotLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) SpotLight(com.badlogic.gdx.graphics.g3d.environment.SpotLight)

Aggregations

DirectionalLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute)6 PointLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.PointLightsAttribute)3 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)3 SpotLightsAttribute (com.badlogic.gdx.graphics.g3d.attributes.SpotLightsAttribute)2 PointLight (com.badlogic.gdx.graphics.g3d.environment.PointLight)2 SpotLight (com.badlogic.gdx.graphics.g3d.environment.SpotLight)2 Camera (com.badlogic.gdx.graphics.Camera)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1 LightProperties (com.badlogic.gdx.tests.g3d.shadows.system.BaseShadowSystem.LightProperties)1