Example usage for com.badlogic.gdx.graphics.glutils ShaderProgram setUniformf

List of usage examples for com.badlogic.gdx.graphics.glutils ShaderProgram setUniformf

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.glutils ShaderProgram setUniformf.

Prototype

public void setUniformf(int location, float value1, float value2, float value3, float value4) 

Source Link

Usage

From source file:com.box2dLight.box2dLight.LightMap.java

License:Apache License

public void render(Matrix4 combined, float x1, float x2, float y1, float y2) {

    boolean needed = rayHandler.lightRenderedLastFrame > 0;
    // this way lot less binding
    if (needed && rayHandler.blur)
        gaussianBlur();/*w w  w.j  av  a 2  s  .com*/

    if (lightMapDrawingDisabled) {
        return;
    }
    frameBuffer.getColorBufferTexture().bind(0);

    // at last lights are rendered over scene
    if (rayHandler.shadows) {

        final Color c = rayHandler.ambientLight;
        ShaderProgram shader = shadowShader;
        if (RayHandler.isDiffuse) {
            shader = diffuseShader;
            shader.begin();
            Gdx.gl20.glBlendFunc(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);
            shader.setUniformf("ambient", c.r, c.g, c.b, c.a);
        } else {
            shader.begin();
            Gdx.gl20.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
            shader.setUniformf("ambient", c.r * c.a, c.g * c.a, c.b * c.a, 1f - c.a);
        }
        lightMapMesh.render(shader, GL20.GL_TRIANGLE_FAN);
        shader.end();
    } else if (needed) {

        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
        withoutShadowShader.begin();
        // withoutShadowShader.setUniformi("u_texture", 0);
        lightMapMesh.render(withoutShadowShader, GL20.GL_TRIANGLE_FAN);
        withoutShadowShader.end();
    }

    Gdx.gl20.glDisable(GL20.GL_BLEND);
}

From source file:seventh.client.gfx.ImageBasedLightSystem.java

License:Open Source License

@Override
public void update(TimeStep timeStep) {
    ShaderProgram shader = this.shader.getShader();
    shader.begin();/*w  w w  .  j a  v  a  2  s .  c o  m*/
    {
        //            this.ambientColor.set(0.3f, 0.3f, 0.4f);
        //            this.ambientColor.set(0.9f, 0.9f, 0.9f);
        //            this.ambientIntensity = 0.4f;

        shader.setUniformi("u_lightmap", 1);
        shader.setUniformf("ambientColor", ambientColor.x, ambientColor.y, ambientColor.z, ambientIntensity);
        shader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }
    shader.end();

    for (int i = 0; i < this.lights.size(); i++) {
        Light light = this.lights.get(i);
        light.update(timeStep);
    }

}