Java Code Examples for com.badlogic.gdx.graphics.glutils.ShaderProgram#setUniformf()
The following examples show how to use
com.badlogic.gdx.graphics.glutils.ShaderProgram#setUniformf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IBLBuilder.java From gdx-gltf with Apache License 2.0 | 6 votes |
private void render(CubemapSide side, ShapeRenderer shapes, ShaderProgram shader, float strength, float exponent){ shader.begin(); shader.setUniformf("u_exponent", exponent); shader.setUniformf("u_ambient", color.r, color.g, color.b, 0f); shader.setUniformf("u_diffuse", color.r, color.g, color.b, strength); localDir.set(side.direction); localUp.set(side.up); // XXX patch if(side == CubemapSide.NegativeX || side == CubemapSide.PositiveX){ localDir.x = -localDir.x; } matrix.setToLookAt(localDir, localUp).tra(); localSunDir.set(direction).scl(-1, -1, 1).mul(matrix); // XXX patch again shader.setUniformf("u_direction", localSunDir); shapes.begin(ShapeType.Filled); shapes.rect(0, 0, 1, 1); shapes.end(); }
Example 2
Source File: ImageBasedLightSystem.java From seventh with GNU General Public License v2.0 | 6 votes |
@Override public void update(TimeStep timeStep) { ShaderProgram shader = this.shader.getShader(); shader.begin(); { // 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()); //SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH, SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT); } shader.end(); for(int i = 0; i < this.lights.size(); i++) { Light light = this.lights.get(i); light.update(timeStep); } }
Example 3
Source File: GameWorldRenderer.java From uracer-kotd with Apache License 2.0 | 5 votes |
private void renderTilemapPlane () { ShaderProgram shader = shNormalDepthNoDiffuse; float meshZ = -(camPersp.far - camPersp.position.z) + (camPersp.far * (1 - (camOrtho.zoom))); float k = OrthographicAlignedStillModel.BlenderToURacer; float scalex = 6, scalez = 4; Matrix4 model = mtx; tmpvec.set(camPersp.position.x, camPersp.position.y, meshZ + 0.5f); model.idt(); model.translate(tmpvec); model.rotate(1, 0, 0, 90); model.scale(scalex * k, 1, scalez * k); mtx2.set(camPersp.view).mul(model); nmat.set(mtx2).inv().transpose(); shader.begin(); shader.setUniformf("inv_depth_scale", DefaultSsaoScale); shader.setUniformf("near", camPersp.near); shader.setUniformf("far", camPersp.far); shader.setUniformMatrix("proj", camPersp.projection); shader.setUniformMatrix("view", camPersp.view); shader.setUniformMatrix("nmat", nmat); shader.setUniformMatrix("model", model); plane.render(shader, GL20.GL_TRIANGLE_FAN); shader.end(); }
Example 4
Source File: LightMap.java From box2dlights with Apache License 2.0 | 5 votes |
public void render() { boolean needed = rayHandler.lightRenderedLastFrame > 0; 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(); rayHandler.diffuseBlendFunc.apply(); shader.setUniformf("ambient", c.r, c.g, c.b, c.a); } else { shader.begin(); rayHandler.shadowBlendFunc.apply(); shader.setUniformf("ambient", c.r * c.a, c.g * c.a, c.b * c.a, 1f - c.a); } // shader.setUniformi("u_texture", 0); lightMapMesh.render(shader, GL20.GL_TRIANGLE_FAN); shader.end(); } else if (needed) { rayHandler.simpleBlendFunc.apply(); withoutShadowShader.begin(); // withoutShadowShader.setUniformi("u_texture", 0); lightMapMesh.render(withoutShadowShader, GL20.GL_TRIANGLE_FAN); withoutShadowShader.end(); } Gdx.gl20.glDisable(GL20.GL_BLEND); }
Example 5
Source File: CubesShaderProvider.java From Cubes with MIT License | 5 votes |
@Override public void begin(ShaderProgram program, Camera camera, RenderContext context) { WorldClient worldClient = ((WorldClient) Cubes.getClient().world); float distance = Settings.getIntegerSettingValue(Settings.GRAPHICS_VIEW_DISTANCE) * Area.SIZE_BLOCKS; float fogDistance = MathUtils.clamp(distance * 0.1f, 8f, 16f); program.setUniformf(u_cameraposition, Cubes.getClient().player.position); program.setUniformf(u_skycolor, worldClient.getSkyColour()); program.setUniformf(u_fogdistance, fogDistance); program.setUniformf(u_minfogdistance, distance - fogDistance); }
Example 6
Source File: CubesShaderProvider.java From Cubes with MIT License | 5 votes |
@Override public void begin(ShaderProgram program, Camera camera, RenderContext context) { TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute(); ao_unit = context.textureBinder.bind(textureAttribute.textureDescription); program.setUniformi(u_aoTexture, ao_unit); program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV, textureAttribute.scaleU, textureAttribute.scaleV); program.setUniformf(u_aoStrength, AmbientOcclusion.getStrength().strength); }
Example 7
Source File: ExplosionEffect.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public void update(TimeStep timeStep) { /* Always clear out the data, this will get * overridden by the next loop if the explosion * is active */ for(int i = 0; i < this.instances.length; i++) { this.shaderData[i ] = -0.1f; this.shaderData[i+1] = -0.1f; this.shaderData[i+2] = 0; } int activeCount = 0; for(int i = 0; i < this.instances.length; i++) { this.instances[i].update(timeStep); if(this.instances[i].isActive()) { this.instances[i].set(shaderData, activeCount++); } } ShaderProgram shader = ExplosionEffectShader.getInstance().getShader(); shader.begin(); shader.setUniform3fv("shockData", this.shaderData, 0, this.shaderData.length); shader.setUniformf("shockParams", 10.0f, 0.08f, 0.1f); shader.end(); }
Example 8
Source File: GameWorldRenderer.java From uracer-kotd with Apache License 2.0 | 4 votes |
private boolean renderCar (Car car, boolean depthOnly, boolean nightMode) { CarStillModel model = car.getStillModel(); if (Config.Debug.FrustumCulling && !camPersp.frustum.boundsInFrustum(model.boundingBox)) { return false; } ShaderProgram shader = null; if (depthOnly) { shader = shNormalDepth; } else { if (nightMode) { shader = OrthographicAlignedStillModel.shaderNight; } else { shader = OrthographicAlignedStillModel.shader; } } gl.glEnable(GL20.GL_CULL_FACE); shader.begin(); Art.meshCar.get(car.getCarPreset().type.regionName).bind(); // common matrices if (depthOnly) { shader.setUniformMatrix("proj", camPersp.projection); shader.setUniformMatrix("view", camPersp.view); shader.setUniformi("u_texture", 0); } else { shader.setUniformf("alpha", model.getAlpha()); if (nightMode) { shader.setUniformf("u_ambient", treesAmbientColor); } } // car body { if (depthOnly) { mtx.set(camPersp.view).mul(model.mtxbody); nmat.set(mtx).inv().transpose(); shader.setUniformMatrix("nmat", nmat); shader.setUniformMatrix("model", model.mtxbody); } else { shader.setUniformMatrix("u_projTrans", model.mtxbodytransformed); } model.body.render(shader, model.smBody.primitiveType); } // car left tire { if (depthOnly) { mtx.set(camPersp.view).mul(model.mtxltire); nmat.set(mtx).inv().transpose(); shader.setUniformMatrix("nmat", nmat); shader.setUniformMatrix("model", model.mtxltire); } else { shader.setUniformMatrix("u_projTrans", model.mtxltiretransformed); } model.leftTire.render(shader, model.smLeftTire.primitiveType); } // car right tire { if (depthOnly) { mtx.set(camPersp.view).mul(model.mtxrtire); nmat.set(mtx).inv().transpose(); shader.setUniformMatrix("nmat", nmat); shader.setUniformMatrix("model", model.mtxrtire); } else { shader.setUniformMatrix("u_projTrans", model.mtxrtiretransformed); } model.rightTire.render(shader, model.smRightTire.primitiveType); } return true; }
Example 9
Source File: ColorAttribute.java From uracer-kotd with Apache License 2.0 | 4 votes |
@Override public void bind (ShaderProgram program) { program.setUniformf(name, color.r, color.g, color.b, color.a); }
Example 10
Source File: LightMap.java From uracer-kotd with Apache License 2.0 | 4 votes |
public void render( Rectangle viewport, FrameBuffer dest ) { boolean needed = rayHandler.lightRenderedLastFrame > 0; // this way lot less binding if( needed && rayHandler.blur ) gaussianBlur(); frameBuffer.getColorBufferTexture().bind( 0 ); if( dest != null ) { dest.begin(); } else { Gdx.gl.glViewport( (int)viewport.x, (int)viewport.y, (int)viewport.width, (int)viewport.height ); } Gdx.gl20.glEnable( GL20.GL_BLEND ); // 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 ); } // shader.setUniformi( "u_texture", 0 ); 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(); } if( dest != null ) dest.end(); }
Example 11
Source File: Palette.java From vis-ui with Apache License 2.0 | 4 votes |
@Override protected void setShaderUniforms (ShaderProgram shader) { shader.setUniformf("u_h", pickerHue); }
Example 12
Source File: ExtendedColorPicker.java From vis-ui with Apache License 2.0 | 4 votes |
@Override public void setShaderUniforms (ShaderProgram shader) { shader.setUniformf("u_r", color.r); shader.setUniformf("u_g", color.g); shader.setUniformf("u_b", color.b); }
Example 13
Source File: ExtendedColorPicker.java From vis-ui with Apache License 2.0 | 4 votes |
@Override public void setShaderUniforms (ShaderProgram shader) { shader.setUniformf("u_h", hBar.getValue() / 360.0f); shader.setUniformf("u_s", sBar.getValue() / 100.0f); shader.setUniformf("u_v", vBar.getValue() / 100.0f); }
Example 14
Source File: Box2dLightCustomShaderTest.java From box2dlights with Apache License 2.0 | 4 votes |
private ShaderProgram createLightShader () { // Shader adapted from https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6 final String vertexShader = "attribute vec4 vertex_positions;\n" // + "attribute vec4 quad_colors;\n" // + "attribute float s;\n" + "uniform mat4 u_projTrans;\n" // + "varying vec4 v_color;\n" // + "void main()\n" // + "{\n" // + " v_color = s * quad_colors;\n" // + " gl_Position = u_projTrans * vertex_positions;\n" // + "}\n"; final String fragmentShader = "#ifdef GL_ES\n" // + "precision lowp float;\n" // + "#define MED mediump\n" + "#else\n" + "#define MED \n" + "#endif\n" // + "varying vec4 v_color;\n" // + "uniform sampler2D u_normals;\n" // + "uniform vec3 u_lightpos;\n" // + "uniform vec2 u_resolution;\n" // + "uniform float u_intensity = 1.0;\n" // + "void main()\n"// + "{\n" + " vec2 screenPos = gl_FragCoord.xy / u_resolution.xy;\n" + " vec3 NormalMap = texture2D(u_normals, screenPos).rgb; " + " vec3 LightDir = vec3(u_lightpos.xy - screenPos, u_lightpos.z);\n" + " vec3 N = normalize(NormalMap * 2.0 - 1.0);\n" + " vec3 L = normalize(LightDir);\n" + " float maxProd = max(dot(N, L), 0.0);\n" + "" // + " gl_FragColor = v_color * maxProd * u_intensity;\n" // + "}"; ShaderProgram.pedantic = false; ShaderProgram lightShader = new ShaderProgram(vertexShader, fragmentShader); if (!lightShader.isCompiled()) { Gdx.app.log("ERROR", lightShader.getLog()); } lightShader.begin(); lightShader.setUniformi("u_normals", 1); lightShader.setUniformf("u_resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); lightShader.end(); return lightShader; }
Example 15
Source File: Shader.java From seventh with GNU General Public License v2.0 | 4 votes |
public Shader setParam(String name, float v) { ShaderProgram shader = getShader(); shader.setUniformf(name, v); return this; }
Example 16
Source File: Shader.java From seventh with GNU General Public License v2.0 | 4 votes |
public Shader setParam(String name, float v1, float v2) { ShaderProgram shader = getShader(); shader.setUniformf(name, v1, v2); return this; }