use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class ProjectiveTextureTest method setupShaders.
public void setupShaders() {
ShaderProgram.pedantic = false;
projTexShader = new ShaderProgram(Gdx.files.internal("data/shaders/projtex-vert.glsl").readString(), Gdx.files.internal("data/shaders/projtex-frag.glsl").readString());
if (!projTexShader.isCompiled())
throw new GdxRuntimeException("Couldn't compile shader: " + projTexShader.getLog());
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class SpriteBatch method createDefaultShader.
/** Returns a new instance of the default shader used by SpriteBatch for GL2 when no shader is specified. */
public static ShaderProgram createDefaultShader() {
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" + //
"{\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" + //
"#define LOWP lowp\n" + //
"precision mediump float;\n" + //
"#else\n" + //
"#define LOWP \n" + //
"#endif\n" + //
"varying LOWP vec4 v_color;\n" + //
"varying vec2 v_texCoords;\n" + //
"uniform sampler2D u_texture;\n" + //
"void main()\n" + //
"{\n" + //
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false)
throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
return shader;
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class DefaultShader method init.
@Override
public void init() {
final ShaderProgram program = this.program;
this.program = null;
init(program, renderable);
renderable = null;
dirLightsLoc = loc(u_dirLights0color);
dirLightsColorOffset = loc(u_dirLights0color) - dirLightsLoc;
dirLightsDirectionOffset = loc(u_dirLights0direction) - dirLightsLoc;
dirLightsSize = loc(u_dirLights1color) - dirLightsLoc;
if (dirLightsSize < 0)
dirLightsSize = 0;
pointLightsLoc = loc(u_pointLights0color);
pointLightsColorOffset = loc(u_pointLights0color) - pointLightsLoc;
pointLightsPositionOffset = loc(u_pointLights0position) - pointLightsLoc;
pointLightsIntensityOffset = has(u_pointLights0intensity) ? loc(u_pointLights0intensity) - pointLightsLoc : -1;
pointLightsSize = loc(u_pointLights1color) - pointLightsLoc;
if (pointLightsSize < 0)
pointLightsSize = 0;
spotLightsLoc = loc(u_spotLights0color);
spotLightsColorOffset = loc(u_spotLights0color) - spotLightsLoc;
spotLightsPositionOffset = loc(u_spotLights0position) - spotLightsLoc;
spotLightsDirectionOffset = loc(u_spotLights0direction) - spotLightsLoc;
spotLightsIntensityOffset = has(u_spotLights0intensity) ? loc(u_spotLights0intensity) - spotLightsLoc : -1;
spotLightsCutoffAngleOffset = loc(u_spotLights0cutoffAngle) - spotLightsLoc;
spotLightsExponentOffset = loc(u_spotLights0exponent) - spotLightsLoc;
spotLightsSize = loc(u_spotLights1color) - spotLightsLoc;
if (spotLightsSize < 0)
spotLightsSize = 0;
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class KTXTest method create.
@Override
public void create() {
// Cubemap test
String cubemapVS = //
"" + //
"attribute vec3 a_position;\n" + //
"uniform mat4 u_projViewTrans;\n" + //
"uniform mat4 u_worldTrans;\n" + //
"\n" + //
"varying vec3 v_cubeMapUV;\n" + //
"\n" + //
"void main() {\n" + //
" vec4 g_position = vec4(a_position, 1.0);\n" + //
" g_position = u_worldTrans * g_position;\n" + //
" v_cubeMapUV = normalize(g_position.xyz);\n" + //
" gl_Position = u_projViewTrans * g_position;\n" + "}";
String cubemapFS = //
"" + //
"#ifdef GL_ES\n" + //
"precision mediump float;\n" + //
"#endif\n" + //
"uniform samplerCube u_environmentCubemap;\n" + //
"varying vec3 v_cubeMapUV;\n" + //
"void main() {\n" + //
" gl_FragColor = vec4(textureCube(u_environmentCubemap, v_cubeMapUV).rgb, 1.0);\n" + "}\n";
modelBatch = new ModelBatch(new DefaultShaderProvider(new Config(cubemapVS, cubemapFS)));
cubemap = new Cubemap(new KTXTextureData(Gdx.files.internal("data/cubemap.zktx"), true));
cubemap.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
perspectiveCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
perspectiveCamera.position.set(10f, 10f, 10f);
perspectiveCamera.lookAt(0, 0, 0);
perspectiveCamera.near = 0.1f;
perspectiveCamera.far = 300f;
perspectiveCamera.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(perspectiveCamera)));
// 2D texture test
String etc1aVS = //
"" + //
"uniform mat4 u_projTrans;\n" + //
"\n" + //
"attribute vec4 a_position;\n" + //
"attribute vec2 a_texCoord0;\n" + //
"attribute vec4 a_color;\n" + //
"\n" + //
"varying vec4 v_color;\n" + //
"varying vec2 v_texCoord;\n" + //
"\n" + //
"void main() {\n" + //
" gl_Position = u_projTrans * a_position;\n" + //
" v_texCoord = a_texCoord0;\n" + //
" v_color = a_color;\n" + //
"}\n";
String etc1aFS = //
"" + //
"#ifdef GL_ES\n" + //
"precision mediump float;\n" + //
"#endif\n" + //
"uniform sampler2D u_texture;\n" + //
"\n" + //
"varying vec4 v_color;\n" + //
"varying vec2 v_texCoord;\n" + //
"\n" + //
"void main() {\n" + //
" vec3 col = texture2D(u_texture, v_texCoord.st).rgb;\n" + //
" float alpha = texture2D(u_texture, v_texCoord.st + vec2(0.0, 0.5)).r;\n" + //
" gl_FragColor = vec4(col, alpha) * v_color;\n" + //
"}\n";
etc1aShader = new ShaderProgram(etc1aVS, etc1aFS);
orthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
image = new Texture("data/egg.zktx");
batch = new SpriteBatch(100, etc1aShader);
}
use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.
the class GLES30Test method create.
@Override
public void create() {
Gdx.app.log("GLES30Test", "GL_VERSION = " + Gdx.gl.glGetString(GL20.GL_VERSION));
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
shaderProgram = new ShaderProgram(Gdx.files.internal("data/shaders/gles30sprite.vert"), Gdx.files.internal("data/shaders/gles30sprite.frag"));
Gdx.app.log("GLES30Test", shaderProgram.getLog());
if (shaderProgram.isCompiled()) {
Gdx.app.log("GLES30Test", "Shader compiled");
batch.setShader(shaderProgram);
}
}
Aggregations