Skip to content

Instantly share code, notes, and snippets.

@piotr-j
Last active August 29, 2015 14:24
Show Gist options
  • Save piotr-j/2abd40be33b94dbfae27 to your computer and use it in GitHub Desktop.
Save piotr-j/2abd40be33b94dbfae27 to your computer and use it in GitHub Desktop.
Modified ligth shader
rayHandler = new RayHandler(world);
rayHandler.setAmbientLight(0f, 0f, 0f, 0.5f);
rayHandler.setBlurNum(0);
rayHandler.setLightShader(createStepLightShader());
private ShaderProgram createStepLightShader () {
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" //
+ "varying float v_s;\n" //
+ "void main()\n" //
+ "{\n" //
+ " v_color = quad_colors;\n"
+ " v_s = s;"
+ " 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" //
+ "varying float v_s;\n" //
+ "void main()\n"//
+ "{\n" //
+ " float a = 0.75 + step(0.25, v_s) * .25;\n"
+ " gl_FragColor = vec4(v_color.rgb, a);\n" //
+ "}";
ShaderProgram.pedantic = false;
ShaderProgram lightShader = new ShaderProgram(vertexShader,
fragmentShader);
if (!lightShader.isCompiled()) {
Gdx.app.log("ERROR", lightShader.getLog());
}
return lightShader;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment