Example usage for org.lwjgl.opengl GL20 glUniform1f

List of usage examples for org.lwjgl.opengl GL20 glUniform1f

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glUniform1f.

Prototype

public static void glUniform1f(@NativeType("GLint") int location, @NativeType("GLfloat") float v0) 

Source Link

Document

Specifies the value of a float uniform variable for the current program object.

Usage

From source file:com.xrbpowered.gl.examples.GLGlass.java

License:Open Source License

@Override
protected void setupResources() {
    super.setupResources();
    glassShader = new GlassShader();

    diffuse = new Texture("checker.png");
    alpha1 = BufferTexture.createPlainColor(4, 4, new Color(0x22777777, true));
    alpha2 = BufferTexture.createPlainColor(4, 4, new Color(0x00ffffff, true));
    normal = new Texture("glass_n.png");
    blurMask = new Texture("glass_blur.png");
    plane = FastMeshBuilder.plane(4f, 1, 1, StandardShader.standardVertexInfo, null);

    Random random = new Random();
    objectActors = new StaticMeshActor[NUM_OBJECTS];
    for (int i = 0; i < NUM_OBJECTS; i++) {
        objectActors[i] = StaticMeshActor.make(scene, plane, StandardShader.getInstance(), diffuse,
                noSpecularTexture, plainNormalTexture);
        objectActors[i].position.x = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        objectActors[i].position.y = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        objectActors[i].position.z = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        objectActors[i].rotation.x = (float) Math.PI / 2f;
        objectActors[i].updateTransform();
    }/*from   ww  w. j  av a2 s .co m*/
    planeActors1 = new StaticMeshActor[NUM_PLANES];
    planeActors2 = new StaticMeshActor[NUM_PLANES];
    for (int i = 0; i < NUM_PLANES; i++) {
        planeActors1[i] = StaticMeshActor.make(scene, plane, StandardShader.getInstance(), alpha1,
                plainSpecularTexture, normal);
        planeActors1[i].setShader(glassShader);
        planeActors2[i] = StaticMeshActor.make(scene, plane, StandardShader.getInstance(), alpha2,
                noSpecularTexture, normal);
        planeActors2[i].setShader(glassShader);
        planeActors1[i].position.x = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        planeActors1[i].position.y = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        planeActors1[i].position.z = random.nextFloat() * OBJECT_RANGE * 2f - OBJECT_RANGE;
        planeActors1[i].rotation.x = (float) Math.PI / 2f;
        planeActors2[i].position = planeActors1[i].position;
        planeActors2[i].rotation = planeActors1[i].rotation;
        planeActors1[i].updateTransform();
        planeActors2[i].updateTransform();
    }

    interBuffers = new OffscreenBuffers(getTargetWidth(), getTargetHeight(), false);
    blurBuffers = new OffscreenBuffers(getTargetWidth() / 6, getTargetHeight() / 6, false);
    postProc = new PostProcessShader("post_blur_f.glsl") {
        @Override
        protected void storeUniformLocations() {
            super.storeUniformLocations();
            GL20.glUseProgram(pId);
            GL20.glUniform1i(GL20.glGetUniformLocation(pId, "numSamples"), 5);
            GL20.glUniform1f(GL20.glGetUniformLocation(pId, "range"), 15f);
            GL20.glUseProgram(0);
        }
    };

    lightActor.rotation = new Vector3f((float) Math.PI, 0, 0);
    lightActor.updateTransform();
}

From source file:com.xrbpowered.gl.examples.GLPoints.java

License:Open Source License

@Override
protected void setupResources() {
    super.setupResources();

    FeedbackVertexInfo tInfo = (FeedbackVertexInfo) new FeedbackVertexInfo()
            .setFeedbackNames(new String[] { "out_Position", "out_Size" }).addAttrib("in_Position", 3)
            .addAttrib("in_Size", 1);
    VertexInfo rInfo = new VertexInfo().addAttrib("in_Position", 4).addAttrib("in_Size", 1);
    VertexInfo simpleInfo = new VertexInfo().addAttrib("in_Position", 3).addAttrib("in_Size", 1);

    pointData = new float[NUM_POINTS * 4];
    indexData = new Integer[NUM_POINTS];
    Random random = new Random();
    int offs = 0;
    for (int i = 0; i < NUM_POINTS; i++) {
        pointData[offs++] = random.nextFloat() * 2f * POINTS_RANGE - POINTS_RANGE;
        pointData[offs++] = random.nextFloat() * 2f * POINTS_RANGE - POINTS_RANGE;
        pointData[offs++] = random.nextFloat() * 2f * POINTS_RANGE - POINTS_RANGE;
        pointData[offs++] = 0.1f;//from  ww w.j  a  va2  s  .  c om
    }
    // points = new StaticMesh(info, pointData, GL11.GL_POINTS, NUM_POINTS, true);

    pointsTShader = new Shader(tInfo, "points_tv.glsl", null) {
        private int projectionMatrixLocation;
        private int viewMatrixLocation;
        private int screenHeightLocation;

        @Override
        protected void storeUniformLocations() {
            projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
            screenHeightLocation = GL20.glGetUniformLocation(pId, "screenHeight");
        }

        @Override
        public void updateUniforms() {
            uniform(projectionMatrixLocation, scene.activeCamera.getProjection());
            uniform(viewMatrixLocation, scene.activeCamera.getView());
            GL20.glUniform1f(screenHeightLocation, getTargetHeight());
        }
    };
    pointsRShader = new Shader(rInfo, "points_pv.glsl", "points_f.glsl") {
        @Override
        protected void storeUniformLocations() {
        }

        @Override
        public void updateUniforms() {
            GL11.glEnable(GL32.GL_PROGRAM_POINT_SIZE);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        }

        @Override
        public void unuse() {
            GL11.glDisable(GL11.GL_BLEND);
            super.unuse();
        }
    };

    points = new FeedbackVertices(pointsTShader, pointsRShader, NUM_POINTS, true);
    points.updateVertexData(pointData);

    simplePointsShader = new Shader(simpleInfo, "points_v.glsl", "points_f.glsl") {
        private int projectionMatrixLocation;
        private int viewMatrixLocation;
        private int screenHeightLocation;

        @Override
        protected void storeUniformLocations() {
            projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix");
            viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
            screenHeightLocation = GL20.glGetUniformLocation(pId, "screenHeight");
        }

        @Override
        public void updateUniforms() {
            GL11.glEnable(GL32.GL_PROGRAM_POINT_SIZE);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            uniform(projectionMatrixLocation, scene.activeCamera.getProjection());
            uniform(viewMatrixLocation, scene.activeCamera.getView());
            GL20.glUniform1f(screenHeightLocation, getTargetHeight());
        }

        @Override
        public void unuse() {
            GL11.glDisable(GL11.GL_BLEND);
            super.unuse();
        }
    };
    simplePoints = new StaticMesh(simpleInfo, pointData, 1, NUM_POINTS, false);

    Client.checkError();
    updateInfo();
}

From source file:com.xrbpowered.gl.res.shaders.PostProcessShader.java

License:Open Source License

@Override
public void updateUniforms() {
    GL20.glUniform1f(timeLocation, time);
}

From source file:com.xrbpowered.gl.res.shaders.StandardShader.java

License:Open Source License

private void setFog(float near, float far, Vector4f color) {
    GL20.glUseProgram(pId);//from   w  ww.  j a  va2  s . c o m
    GL20.glUniform1f(GL20.glGetUniformLocation(pId, "fogNear"), near);
    GL20.glUniform1f(GL20.glGetUniformLocation(pId, "fogFar"), far);
    uniform(GL20.glGetUniformLocation(pId, "fogColor"), color);
    GL20.glUseProgram(0);
}

From source file:com.xrbpowered.gl.res.shaders.StandardShader.java

License:Open Source License

@Override
public void updateUniforms() {
    super.updateUniforms();

    Matrix4f.mul(getActor().scene.activeCamera.getView(), getActor().getTransform(), model);
    norm.m00 = model.m00;//from ww  w.j  a  v  a2  s  .  c o m
    norm.m01 = model.m01;
    norm.m02 = model.m02;
    norm.m10 = model.m10;
    norm.m11 = model.m11;
    norm.m12 = model.m12;
    norm.m20 = model.m20;
    norm.m21 = model.m21;
    norm.m22 = model.m22;
    Matrix3f.invert(norm, norm);
    Matrix3f.transpose(norm, norm);
    uniform(normalMatrixLocation, norm);

    uniform(lightDirLocation, environment.lightDir);
    uniform(lightColorLocation, environment.lightColor);
    uniform(ambientColorLocation, environment.ambientColor);

    GL20.glUniform1f(specPowerLocation, specPower);
    GL20.glUniform1f(alphaLocation, alpha);
    GL20.glUniform1f(timeLocation, environment.time);
}

From source file:com.xrbpowered.gl.ui.UIShader.java

License:Open Source License

public void updateUniforms(float x, float y, float alpha) {
    GL20.glUniform2f(anchorLocation, x, y);
    GL20.glUniform1f(alphaLocation, alpha);
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void uniform1f(int location, float v0) {
    GL20.glUniform1f(location, v0);
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLConfigurableMaterial.java

License:Open Source License

private void uploadUniforms(GLScene.DrawModifier drawModifier) {
    drawModifier.apply(shader);/*  w w  w  .  j av  a2 s  . com*/

    GL20.glUniform4f(shader.getUniformColorAmbient(), ambient.r, ambient.g, ambient.b, ambient.a);
    GL20.glUniform4f(shader.getUniformColorDiffuse(), diffuse.r, diffuse.g, diffuse.b, diffuse.a);
    GL20.glUniform4f(shader.getUniformColorSpecular(), specular.r, specular.g, specular.b, specular.a);

    GL20.glUniform1f(shader.getUniformValueSpecularCoefficient(), specularCoeff);
    // bind texture
    if (hasDiffuseTexture)
        diffuseTexture.use(shader.getTextureImageUnitDiffuse());
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLFrameBufferMaterial.java

License:Open Source License

@Override
public GLShader preparePass(GLScene.PassType passType, GLScene.DrawModifier drawModifier) {
    switch (passType) {
    case Forward:
        if (forwardShader != null) {
            forwardShader.use();/*from   w w w.j a v  a 2 s  .co m*/
            forwardTexture.use(forwardShader.getTextureImageUnitColor0());
        }
        return forwardShader;
    case PostProcess:
        if (postShader != null) {
            postShader.use();
            GL20.glUniform1f(postShader.getUniformValuePixelSizeH(), sizeX);
            GL20.glUniform1f(postShader.getUniformValuePixelSizeV(), sizeY);
            postColor0Texture.use(postShader.getTextureImageUnitColor0());
            postDepthTexture.use(postShader.getTextureImageUnitDepth());
        }
        return postShader;
    case PostProcess2:
        if (post2Shader != null) {
            post2Shader.use();
            GL20.glUniform1f(post2Shader.getUniformValuePixelSizeH(), sizeX);
            GL20.glUniform1f(post2Shader.getUniformValuePixelSizeV(), sizeY);
            post2Color0Texture.use(post2Shader.getTextureImageUnitColor0());
        }
        return post2Shader;
    }
    return null;
}

From source file:eu.over9000.veya.rendering.Scene.java

License:Open Source License

public void render() {
    this.checkCameraPosition();

    ChunkChunkVAOPair addEntry;//from   ww  w  .  java  2  s . c om
    while ((addEntry = this.toAdd.poll()) != null) {
        addEntry.getChunkVAO().create();
        this.displayedChunks.put(addEntry.getChunk(), addEntry.getChunkVAO());
    }

    ChunkChunkVAOPair removeEntry;
    while ((removeEntry = this.toRemove.poll()) != null) {
        this.displayedChunks.remove(removeEntry.getChunk());
        removeEntry.getChunkVAO().dispose();
    }

    ChunkChunkVAOPair updatedEntry;
    while ((updatedEntry = this.updatedUpdateOffRender.poll()) != null) {
        updatedEntry.getChunkVAO().create();
        final ChunkVAO oldVAO = this.displayedChunks.put(updatedEntry.getChunk(), updatedEntry.getChunkVAO());
        if (oldVAO != null) {
            oldVAO.dispose();
        }
    }

    int updates = 0;
    for (final Chunk chunk : displayedChunks.keySet()) {
        if (world.hasChunkChanged(chunk)) {
            if (chunk.getLocation().nextTo(centerChunk)) {

                final ChunkVAO newVAO = new ChunkVAO(chunk);
                final ChunkVAO oldVAO = this.displayedChunks.put(chunk, newVAO);
                oldVAO.dispose();
                newVAO.create();
                chunkUpdateCounterInRender.incrementAndGet();
                updates++;
                if (updates > MAX_CHUNK_UPDATES_PER_FRAME) {
                    break;
                }
            } else {
                toUpdateOffRender.add(chunk);
            }
        }
    }

    shadow.preRender();
    Util.checkGLError();
    internalRender(false);
    Util.checkGLError();
    shadow.postRender();
    Util.checkGLError();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, this.texture_handle);
    internalRender(true);

    if (Veya.debugShadow) {
        Veya.program_debug.use(true);
        GL20.glUniform1f(Veya.program_debug.getUniformLocation("near_plane"), Shadow.SHADOW_NEAR);
        GL20.glUniform1f(Veya.program_debug.getUniformLocation("far_plane"), Shadow.SHADOW_FAR);
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, shadow.getDepthMap());

        shadow.renderQuad();

    }

    Veya.program_normal.use(true);
}