use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class MipMapTest method create.
@Override
public void create() {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0, 1.5f, 1.5f);
camera.lookAt(0, 0, 0);
camera.update();
controller = new PerspectiveCamController(camera);
mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE));
mesh.setVertices(new float[] { -1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, -1, 0, 0 });
mesh.setIndices(new short[] { 0, 1, 2, 3 });
shader = new ShaderProgram(Gdx.files.internal("data/shaders/flattex-vert.glsl").readString(), Gdx.files.internal("data/shaders/flattex-frag.glsl").readString());
if (!shader.isCompiled())
throw new GdxRuntimeException("shader error: " + shader.getLog());
textureHW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
MipMapGenerator.setUseHardwareMipMap(false);
textureSW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
currTexture = textureHW;
createUI();
multiplexer = new InputMultiplexer();
Gdx.input.setInputProcessor(multiplexer);
multiplexer.addProcessor(ui);
multiplexer.addProcessor(controller);
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class DistanceFieldFont method createDistanceFieldShader.
/** Returns a new instance of the distance field shader, see https://github.com/libgdx/libgdx/wiki/Distance-field-fonts if the
* u_smoothing uniform > 0.0. Otherwise the same code as the default SpriteBatch shader is used. */
public static ShaderProgram createDistanceFieldShader() {
String vertexShader = //
"attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" + "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + //
";\n" + "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + //
"0;\n" + //
"uniform mat4 u_projTrans;\n" + //
"varying vec4 v_color;\n" + //
"varying vec2 v_texCoords;\n" + //
"\n" + //
"void main() {\n" + " v_color = " + ShaderProgram.COLOR_ATTRIBUTE + //
";\n" + //
" v_color.a = v_color.a * (255.0/254.0);\n" + " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + //
"0;\n" + " gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + //
";\n" + "}\n";
String fragmentShader = //
"#ifdef GL_ES\n" + //
" precision mediump float;\n" + //
" precision mediump int;\n" + //
"#endif\n" + //
"\n" + //
"uniform sampler2D u_texture;\n" + //
"uniform float u_smoothing;\n" + //
"varying vec4 v_color;\n" + //
"varying vec2 v_texCoords;\n" + //
"\n" + //
"void main() {\n" + //
" if (u_smoothing > 0.0) {\n" + //
" float smoothing = 0.25 / u_smoothing;\n" + //
" float distance = texture2D(u_texture, v_texCoords).a;\n" + //
" float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);\n" + //
" gl_FragColor = vec4(v_color.rgb, alpha * v_color.a);\n" + //
" } else {\n" + //
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + //
" }\n" + "}\n";
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false)
throw new IllegalArgumentException("Error compiling distance field shader: " + shader.getLog());
return shader;
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class ShaderProgramLoader method loadSync.
@Override
public ShaderProgram loadSync(AssetManager manager, String fileName, FileHandle file, ShaderProgramParameter parameter) {
String vertFileName = null, fragFileName = null;
if (parameter != null) {
if (parameter.vertexFile != null)
vertFileName = parameter.vertexFile;
if (parameter.fragmentFile != null)
fragFileName = parameter.fragmentFile;
}
if (vertFileName == null && fileName.endsWith(fragmentFileSuffix)) {
vertFileName = fileName.substring(0, fileName.length() - fragmentFileSuffix.length()) + vertexFileSuffix;
}
if (fragFileName == null && fileName.endsWith(vertexFileSuffix)) {
fragFileName = fileName.substring(0, fileName.length() - vertexFileSuffix.length()) + fragmentFileSuffix;
}
FileHandle vertexFile = vertFileName == null ? file : resolve(vertFileName);
FileHandle fragmentFile = fragFileName == null ? file : resolve(fragFileName);
String vertexCode = vertexFile.readString();
String fragmentCode = vertexFile.equals(fragmentFile) ? vertexCode : fragmentFile.readString();
if (parameter != null) {
if (parameter.prependVertexCode != null)
vertexCode = parameter.prependVertexCode + vertexCode;
if (parameter.prependFragmentCode != null)
fragmentCode = parameter.prependFragmentCode + fragmentCode;
}
ShaderProgram shaderProgram = new ShaderProgram(vertexCode, fragmentCode);
if ((parameter == null || parameter.logOnCompileFailure) && !shaderProgram.isCompiled()) {
manager.getLogger().error("ShaderProgram " + fileName + " failed to compile:\n" + shaderProgram.getLog());
}
return shaderProgram;
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class CustomShaderSpriteBatchTest method create.
@Override
public void create() {
batch = new SpriteBatch(10);
ShaderProgram.pedantic = false;
shader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/batch.frag").readString());
batch.setShader(shader);
texture = new Texture("data/badlogic.jpg");
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class EdgeDetectionTest method create.
public void create() {
ShaderProgram.pedantic = false;
/*
* shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
* "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
* "couldn't compile scene shader: " + shader.getLog()); }
*/
batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/convolution.frag").readString());
if (!batchShader.isCompiled()) {
Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
}
ObjLoader objLoader = new ObjLoader();
scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
sceneInstance = new ModelInstance(scene);
modelBatch = new ModelBatch();
fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 0, 10);
cam.lookAt(0, 0, 0);
cam.far = 30;
batch = new SpriteBatch();
batch.setShader(batchShader);
fboRegion = new TextureRegion(fbo.getColorBufferTexture());
fboRegion.flip(false, true);
logger = new FPSLogger();
calculateOffsets();
}
Aggregations