Example usage for com.badlogic.gdx.graphics.g3d.attributes ColorAttribute Specular

List of usage examples for com.badlogic.gdx.graphics.g3d.attributes ColorAttribute Specular

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.attributes ColorAttribute Specular.

Prototype

long Specular

To view the source code for com.badlogic.gdx.graphics.g3d.attributes ColorAttribute Specular.

Click Source Link

Usage

From source file:ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader.java

License:Apache License

@Override
public void render(Renderable renderable) {
    ShaderProgram program;//from  w  w  w .  j a v a 2  s .c  om
    int index;
    boolean bonesEnabled;
    Vector3 lightPosition;
    Color diffuseLightColor;
    Color diffuseColor;
    Color specularColor;
    Color ambientColor;
    float shininess;

    // Get material colors.
    if (renderable.environment != null && renderable.environment.directionalLights != null
            && renderable.environment.directionalLights.size >= 1) {
        lightPosition = renderable.environment.directionalLights.get(0).direction;
        diffuseLightColor = renderable.environment.directionalLights.get(0).color;
    } else {
        lightPosition = DEFAULT_LIGHT;
        diffuseLightColor = Color.WHITE;
    }

    if (renderable.material.has(ColorAttribute.Diffuse))
        diffuseColor = ((ColorAttribute) renderable.material.get(ColorAttribute.Diffuse)).color;
    else
        diffuseColor = Color.WHITE;

    if (renderable.material.has(ColorAttribute.Specular))
        specularColor = ((ColorAttribute) renderable.material.get(ColorAttribute.Specular)).color;
    else
        specularColor = Color.BLACK;

    if (renderable.environment != null && renderable.environment.has(ColorAttribute.AmbientLight))
        ambientColor = ((ColorAttribute) renderable.environment.get(ColorAttribute.AmbientLight)).color;
    else
        ambientColor = Color.BLACK;

    if (renderable.material.has(FloatAttribute.Shininess))
        shininess = ((FloatAttribute) renderable.material.get(FloatAttribute.Shininess)).value;
    else
        shininess = DEFAULT_SHININESS;

    if (renderable.mesh.getVertexAttribute(VertexAttributes.Usage.BoneWeight) != null) {
        program = skinningProgram;
        index = 0;
        bonesEnabled = true;
    } else {
        program = baseProgram;
        index = 1;
        bonesEnabled = false;
    }

    program.begin();

    // Set camera dependant uniforms.
    program.setUniformMatrix(u_projTrans[index], this.camera.combined);
    program.setUniformf(u_cameraPos[index], this.camera.position);

    // Set model dependant uniforms.
    program.setUniformMatrix(u_geomTrans[index], renderable.worldTransform);
    program.setUniformMatrix(u_normalMatrix[index],
            normalMatrix.set(renderable.worldTransform).toNormalMatrix());
    program.setUniformf(u_lightPos[index], lightPosition);
    program.setUniformf(u_lightDiffuse[index], diffuseLightColor);
    program.setUniformf(u_materialDiffuse[index], diffuseColor);
    program.setUniformf(u_specular[index], specularColor);
    program.setUniformf(u_ambient[index], ambientColor);
    program.setUniformf(u_shiny[index], shininess);

    // Set the bones uniforms.
    if (bonesEnabled) {
        for (int i = 0; i < MAX_NUM_BONES; i++) {
            if (renderable.bones != null && i < renderable.bones.length && renderable.bones[i] != null)
                skinningProgram.setUniformMatrix(u_bones[i], renderable.bones[i]);
            else
                skinningProgram.setUniformMatrix(u_bones[i], IDENTITY);
        }
    }

    renderable.mesh.render(program, renderable.primitiveType, renderable.meshPartOffset,
            renderable.meshPartSize);

    program.end();
}