Java Code Examples for com.badlogic.gdx.graphics.glutils.ShaderProgram#end()
The following examples show how to use
com.badlogic.gdx.graphics.glutils.ShaderProgram#end() .
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: 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 2
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 3
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 4
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 5
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 6
Source File: RayHandler.java From box2dlights with Apache License 2.0 | 4 votes |
/** * Prepare all lights for rendering. * * <p>You should need to use this method only if you want to render lights * on a frame buffer object. Use {@link #render()} otherwise. * * <p><b>NOTE!</b> Don't call this inside of any begin/end statements. * * @see #renderOnly() * @see #render() */ public void prepareRender() { lightRenderedLastFrame = 0; Gdx.gl.glDepthMask(false); Gdx.gl.glEnable(GL20.GL_BLEND); simpleBlendFunc.apply(); boolean useLightMap = (shadows || blur); if (useLightMap) { lightMap.frameBuffer.begin(); Gdx.gl.glClearColor(0f, 0f, 0f, 0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); } ShaderProgram shader = customLightShader != null ? customLightShader : lightShader; shader.begin(); { shader.setUniformMatrix("u_projTrans", combined); if (customLightShader != null) updateLightShader(); for (Light light : lightList) { if (customLightShader != null) updateLightShaderPerLight(light); light.render(); } } shader.end(); if (useLightMap) { if (customViewport) { lightMap.frameBuffer.end( viewportX, viewportY, viewportWidth, viewportHeight); } else { lightMap.frameBuffer.end(); } boolean needed = lightRenderedLastFrame > 0; // this way lot less binding if (needed && blur) lightMap.gaussianBlur(); } }
Example 7
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 8
Source File: Shader.java From seventh with GNU General Public License v2.0 | 4 votes |
public Shader end() { ShaderProgram shader = getShader(); shader.end(); return this; }