Java Code Examples for com.badlogic.gdx.graphics.glutils.ShaderProgram

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShaderProgram. These examples are extracted from open source projects. 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
@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 Project: gdx-gltf   Source File: IBLBuilder.java    License: Apache License 2.0 6 votes vote down vote up
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 3
Source Project: RuinsOfRevenge   Source File: ShaderLoader.java    License: MIT License 6 votes vote down vote up
public static ShaderProgram fromString( String vertex, String fragment, String vertexName, String fragmentName, String defines ) {
	ShaderProgram.pedantic = ShaderLoader.Pedantic;
	ShaderProgram shader = new ShaderProgram( defines + "\n" + vertex, defines + "\n" + fragment );
	if( !shader.isCompiled() ) {
		Gdx.app.error( "ShaderLoader", shader.getLog() );
		Gdx.app.exit();
	} else {
		if( defines != null && defines.length() > 0 ) {
			Gdx.app.log( "ShaderLoader", vertexName + "/" + fragmentName + " compiled w/ (" + defines.replace( "\n", ", " )
					+ ")" );
		} else {
			Gdx.app.log( "ShaderLoader", vertexName + "/" + fragmentName + " compiled!" );
		}
	}

	return shader;
}
 
Example 4
Source Project: fluid-simulator-v2   Source File: Renderer20.java    License: Apache License 2.0 6 votes vote down vote up
static private String createVertexShader (boolean hasNormals, boolean hasColors, int numTexCoords) {
	String shader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
		+ (hasNormals ? "attribute vec3 " + ShaderProgram.NORMAL_ATTRIBUTE + ";\n" : "")
		+ (hasColors ? "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + i + ";\n";
	}

	shader += "uniform mat4 u_projModelView;\n";
	shader += (hasColors ? "varying vec4 v_col;\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "varying vec2 v_tex" + i + ";\n";
	}

	shader += "void main() {\n" + "   gl_Position = u_projModelView * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
		+ (hasColors ? "   v_col = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "   v_tex" + i + " = " + ShaderProgram.TEXCOORD_ATTRIBUTE + i + ";\n";
	}
	shader += "   gl_PointSize = 1.0;\n";
	shader += "}\n";
	return shader;
}
 
Example 5
Source Project: seventh   Source File: ClientGameEffects.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void renderFrameBuffer(Canvas canvas, Camera camera, float alpha) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    canvas.setDefaultTransforms();

    frameBufferSprite.setRegion(canvas.getFrameBuffer());
    
    canvas.begin();
    {
        canvas.getFrameBuffer().bind();
        {
            ShaderProgram shader = ExplosionEffectShader.getInstance().getShader();
            
            canvas.setShader(shader);
            canvas.drawImage(frameBufferSprite, 0, 0, 0x0);
        }
    }
    canvas.end();
}
 
Example 6
Source Project: TerraLegion   Source File: GameScreen.java    License: MIT License 6 votes vote down vote up
@Override
public void create() {
	//Load UI
	gameHud = new GameHud(this, world);

	ShaderProgram.pedantic = false;
	program = new ShaderProgram(Gdx.files.internal("shaders/sepia.vsh"), Gdx.files.internal("shaders/sepia.fsh"));
	
	if (!program.isCompiled()) {
		System.out.println(program.getLog());
	}
	
	camera = new OrthoCamera();
	Timer.startGameTime();
	resize(Settings.getWidth(), Settings.getHeight());
}
 
Example 7
Source Project: Mundus   Source File: ShaderUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and links shader.
 *
 * @param vertexShader
 *            path to vertex shader
 * @param fragmentShader
 *            path to fragment shader
 *
 * @return compiled shader program
 */
public static ShaderProgram compile(String vertexShader, String fragmentShader) {
    String vert;
    String frag;

    if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        vert = Gdx.files.internal(vertexShader).readString();
        frag = Gdx.files.internal(fragmentShader).readString();
    } else {
        vert = Gdx.files.classpath(vertexShader).readString();
        frag = Gdx.files.classpath(fragmentShader).readString();
    }

    ShaderProgram program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }

    return program;
}
 
Example 8
Source Project: GdxDemo3D   Source File: GameRenderer.java    License: Apache License 2.0 6 votes vote down vote up
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) {
	this.viewport = viewport;
	this.camera = camera;
	this.engine = engine;

	shapeRenderer = new MyShapeRenderer();
	shapeRenderer.setAutoShapeType(true);

	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.WHITE);
	font.setUseIntegerPositions(false);
	font.getData().setScale(0.01f);
	shadowBatch = new ModelBatch(new DepthShaderProvider());

	ShaderProgram.pedantic = false;
	final String vertUber = Gdx.files.internal("shaders/uber.vert").readString();
	final String fragUber = Gdx.files.internal("shaders/uber.frag").readString();
	modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) {
		@Override
		protected Shader createShader(final Renderable renderable) {
			return new UberShader(renderable, config);
		}
	});
}
 
Example 9
Source Project: fluid-simulator-v2   Source File: Renderer20.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns a new instance of the default shader used by SpriteBatch for GL2 when no shader is specified. */
static public ShaderProgram createDefaultShader (boolean hasNormals, boolean hasColors, int numTexCoords) {
	String vertexShader = createVertexShader(hasNormals, hasColors, numTexCoords);
	String fragmentShader = createFragmentShader(hasNormals, hasColors, numTexCoords);
	ShaderProgram program = new ShaderProgram(vertexShader, fragmentShader);
	return program;
}
 
Example 10
Source Project: gdx-vfx   Source File: VfxGLUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static ShaderProgram compileShader(FileHandle vertexFile, FileHandle fragmentFile, String defines) {
    if (fragmentFile == null) {
        throw new IllegalArgumentException("Vertex shader file cannot be null.");
    }
    if (vertexFile == null) {
        throw new IllegalArgumentException("Fragment shader file cannot be null.");
    }
    if (defines == null) {
        throw new IllegalArgumentException("Defines cannot be null.");
    }

    StringBuilder sb = new StringBuilder();
    sb.append("Compiling \"").append(vertexFile.name()).append('/').append(fragmentFile.name()).append('\"');
    if (defines.length() > 0) {
        sb.append(" w/ (").append(defines.replace("\n", ", ")).append(")");
    }
    sb.append("...");
    Gdx.app.log(TAG, sb.toString());

    String prependVert = prependVertexCode + defines;
    String prependFrag = prependFragmentCode + defines;
    String srcVert = vertexFile.readString();
    String srcFrag = fragmentFile.readString();

    ShaderProgram shader = new ShaderProgram(prependVert + "\n" + srcVert, prependFrag + "\n" + srcFrag);

    if (!shader.isCompiled()) {
        throw new GdxRuntimeException("Shader compile error: " + vertexFile.name() + "/" + fragmentFile.name() + "\n" + shader.getLog());
    }
    return shader;
}
 
Example 11
Source Project: talos   Source File: NoiseImage.java    License: Apache License 2.0 5 votes vote down vote up
public NoiseImage(Skin skin) {
    this.skin = skin;
    white = new Texture(Gdx.files.internal("white.png")); //TODO: not cool
    shaderProgram = new ShaderProgram(Gdx.files.internal("shaders/ui/default.vert"), Gdx.files.internal("shaders/ui/noise.frag"));

    pixmap = new Pixmap(165, 100, Pixmap.Format.RGB888);
}
 
Example 12
Source Project: talos   Source File: NoiseImage.java    License: Apache License 2.0 5 votes vote down vote up
public void drawWithShader(Batch batch, float parentAlpha) {
    ShaderProgram prevShader = batch.getShader();
    batch.setShader(shaderProgram);

    shaderProgram.setUniformf("frequency", frequency);

    // do the rendering
    batch.draw(white, getX(), getY(), getWidth(), getHeight());

    batch.setShader(prevShader);
}
 
Example 13
Source Project: graphicsfuzz   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private Mesh buildMeshFromVertices(List<Double> vertexCoords) {
  if ((vertexCoords.size() % 3) != 0) {
    throw new RuntimeException("Vertex coordinates size is " + vertexCoords.size() + "; must be a multiple of 3");
  }
  float[] data = new float[vertexCoords.size()];
  for (int i = 0; i < vertexCoords.size(); i++) {
    data[i] = (float) vertexCoords.get(i).doubleValue();
  }
  Mesh mesh = new Mesh( true, vertexCoords.size() / 3, 0,
          new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
  mesh.setVertices(data);
  return mesh;
}
 
Example 14
Source Project: graphicsfuzz   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private Mesh buildMeshFromVerticesAndTexCoords(List<Double> vertexCoords, List<Double> texCoords) {
  if ((vertexCoords.size() % 3) != 0) {
    throw new RuntimeException("Vertex coordinates size is " + vertexCoords.size() + "; must be a multiple of 3");
  }
  if ((texCoords.size() % 2) != 0) {
    throw new RuntimeException("Texture coordinates size is " + texCoords.size() + "; must be a multiple of 2");
  }
  if (vertexCoords.size() / 3 != texCoords.size() / 2) {
    throw new RuntimeException("There is vertex data for " + vertexCoords.size() / 3 + " triangle(s), "
            + "and texture data for " + texCoords.size() / 2 + " triangle(s) -- these should match");
  }

  float[] data = new float[vertexCoords.size() + texCoords.size()];
  int vertexIndex = 0;
  int texIndex = 0;
  int dataIndex = 0;
  for (int i = 0; i < vertexCoords.size() / 3; i++) {
    data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue();
    data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue();
    data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue();
    data[dataIndex++] = (float) texCoords.get(texIndex++).doubleValue();
    data[dataIndex++] = (float) texCoords.get(texIndex++).doubleValue();
  }
  Mesh mesh = new Mesh( true, vertexCoords.size() / 3, 0,
          new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
          new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
  mesh.setVertices(data);
  return mesh;
}
 
Example 15
Source Project: gdx-gltf   Source File: GLTFPostProcessingExample.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
	
	sceneManager = createSceneManager();
	sceneManager.camera = camera = new PerspectiveCamera();
	camera.fieldOfView = 50;
	camera.near = 0.01f;
	camera.far = 10f;
	camera.position.set(1, 1, 1).scl(.1f);
	camera.up.set(Vector3.Y);
	camera.lookAt(Vector3.Zero);
	camera.update();
	
	// load user scene
	SceneAsset asset = new GLTFLoader().load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf"));
	sceneManager.addScene(new Scene(asset.scene));
	
	cameraController = new CameraInputController(camera);
	cameraController.translateUnits = .1f;
	Gdx.input.setInputProcessor(cameraController);

	viewport = new FitViewport(1000, 500, camera);
	
	// post processing
	if(postProcessingEnabled){
		fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
		effectShader = new ShaderProgram(Gdx.files.classpath("shaders/effect.vs.glsl"), Gdx.files.classpath("shaders/effect.fs.glsl"));
		batch = new SpriteBatch();
	}
	
}
 
Example 16
Source Project: seventh   Source File: ExplosionEffect.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 17
Source Project: uracer-kotd   Source File: GameWorldRenderer.java    License: Apache License 2.0 5 votes vote down vote up
private void createBackPlane () {
	plane = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
		new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));

	// @formatter:off
	float size = 10f;
	float verts[] = {-size / 2, 0, size / 2, size / 2, 0, size / 2, size / 2, 0, -size / 2, -size / 2, 0, -size / 2};
	// float verts[] = {size, 0, size, size, 0, 0, 0, 0, 0, 0, 0, size};

	float normals[] = {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
	// @formatter:on

	int vidx = 0, nidx = 0;
	int length = 6 * 4;
	float[] vertices = new float[length];
	for (int i = 0; i < length;) {
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = verts[vidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
		vertices[i++] = normals[nidx++];
	}

	plane.setVertices(vertices);
	plane.setIndices(new short[] {0, 1, 2, 3});
}
 
Example 18
Source Project: uracer-kotd   Source File: GameWorldRenderer.java    License: Apache License 2.0 5 votes vote down vote up
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 19
Source Project: uracer-kotd   Source File: TextureAttribute.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void bind (ShaderProgram program) {
	texture.bind(unit);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, minFilter);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER, magFilter);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S, uWrap);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T, vWrap);
	program.setUniformi(name, unit);
}
 
Example 20
Source Project: uracer-kotd   Source File: StillModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void render (ShaderProgram program) {
	int len = subMeshes.length;
	for (int i = 0; i < len; i++) {
		StillSubMesh subMesh = subMeshes[i];
		if (i == 0) {
			subMesh.material.bind(program);
		} else if (!subMeshes[i - 1].material.equals(subMesh.material)) {
			subMesh.material.bind(program);
		}
		subMesh.mesh.render(program, subMesh.primitiveType);
	}
}
 
Example 21
Source Project: uracer-kotd   Source File: UStillModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void render (ShaderProgram program) {
	int len = subMeshes.length;
	for (int i = 0; i < len; i++) {
		StillSubMesh subMesh = subMeshes[i];
		if (i == 0) {
			subMesh.material.bind(program);
		} else if (!subMeshes[i - 1].material.equals(subMesh.material)) {
			subMesh.material.bind(program);
		}
		subMesh.mesh.render(program, subMesh.primitiveType);
	}
}
 
Example 22
Source Project: Cubes   Source File: CubesShaderProvider.java    License: MIT License 5 votes vote down vote up
@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 23
Source Project: uracer-kotd   Source File: DiffuseShader.java    License: Apache License 2.0 5 votes vote down vote up
static final public ShaderProgram createShadowShader() {
	final String vertexShader = "attribute vec4 a_position;\n" //
			+ "attribute vec2 a_texCoord;\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_texCoords = a_texCoord;\n" //
			+ "   gl_Position = a_position;\n" //
			+ "}\n";

	// this is allways perfect precision
	final String fragmentShader = "#ifdef GL_ES\n" //
			+ "precision mediump float;\n" //
			+ "#endif\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "uniform sampler2D u_texture;\n" //
			+ "uniform  vec4 ambient;\n"
				+ "void main()\n"//
			+ "{\n" //
			+ "gl_FragColor = ambient + texture2D(u_texture, v_texCoords);\n"
				+ "}\n";
	ShaderProgram.pedantic = false;
	ShaderProgram shadowShader = new ShaderProgram(vertexShader,
				fragmentShader);
	if (shadowShader.isCompiled() == false) {
		Gdx.app.log("ERROR", shadowShader.getLog());

	}

	return shadowShader;
}
 
Example 24
Source Project: uracer-kotd   Source File: ShadowShader.java    License: Apache License 2.0 5 votes vote down vote up
static final public ShaderProgram createShadowShader() {
	final String vertexShader = "attribute vec4 a_position;\n" //
			+ "attribute vec2 a_texCoord;\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_texCoords = a_texCoord;\n" //
			+ "   gl_Position = a_position;\n" //
			+ "}\n";
	final String fragmentShader = "#ifdef GL_ES\n" //
			+ "#define MED " + RayHandler.getColorPrecision() + "\n" + "precision "
			+ RayHandler.getColorPrecision()
			+ " float;\n" //
			+ "#else\n" + "#define MED \n" + "#endif\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "uniform MED sampler2D u_texture;\n" //
			+ "uniform MED vec4 ambient;\n" + "void main()\n"//
			+ "{\n" //
			+ "vec4 v_c = texture2D(u_texture, v_texCoords);\n" + "v_c.rgb = ambient.rgb + v_c.rgb* v_c.a;\n"//
			+ "v_c.a = ambient.a - v_c.a;\n"//
			+ "gl_FragColor = v_c;\n"//
			+ "}\n";
	ShaderProgram.pedantic = false;
	ShaderProgram shadowShader = new ShaderProgram( vertexShader, fragmentShader );
	if( shadowShader.isCompiled() == false ) {
		Gdx.app.log( "ERROR", shadowShader.getLog() );

	}

	return shadowShader;
}
 
Example 25
Source Project: uracer-kotd   Source File: WithoutShadowShader.java    License: Apache License 2.0 5 votes vote down vote up
static final public ShaderProgram createShadowShader() {
	final String vertexShader = "attribute vec4 a_position;\n" //
			+ "attribute vec2 a_texCoord;\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_texCoords = a_texCoord;\n" //
			+ "   gl_Position = a_position;\n" //
			+ "}\n";

	//this is allways perfect precision
	final String fragmentShader = "#ifdef GL_ES\n" //
			+ "precision mediump float;\n" //
			+ "#endif\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "uniform sampler2D u_texture;\n" //
			+ "void main()\n"//
			+ "{\n" //
			+ "gl_FragColor = texture2D(u_texture, v_texCoords);\n"
			+ "}\n";
	ShaderProgram.pedantic = false;
	ShaderProgram woShadowShader = new ShaderProgram(vertexShader,
			fragmentShader);
	if (woShadowShader.isCompiled() == false) {
		Gdx.app.log("ERROR", woShadowShader.getLog());

	}

	return woShadowShader;
}
 
Example 26
Source Project: Cubes   Source File: FrametimeGraph.java    License: MIT License 5 votes vote down vote up
private static ShaderProgram createShaderProgram() {
  String vertex = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n";
  vertex += "uniform mat4 u_projModelView;\n";
  vertex += "void main() {\n" + "   gl_Position = u_projModelView * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n";
  vertex += "   gl_PointSize = 1.0;\n";
  vertex += "}\n";
  String fragment = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n";
  fragment += "void main() {\n" + "   gl_FragColor = vec4(1, 0, 0, 1)"; //#00ff00ff
  fragment += ";\n}";
  return new ShaderProgram(vertex, fragment);
}
 
Example 27
Source Project: beatoraja   Source File: Skin.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void preDraw(Consumer<ShaderProgram> shaderVariableSetter) {
	if(shaders[current] != shaders[type]) {
		sprite.setShader(shaders[type]);
		current = type;
	}

	if (shaders[type] != null && shaderVariableSetter != null) {
		// シェーダの変数を変更する場合はバッチを切る
		// (shader.begin() - end() で囲うのは正しく動作しないため不可)
		sprite.flush();
		shaderVariableSetter.accept(shaders[type]);
	}

	switch (blend) {
	case 2:
		sprite.setBlendFunction(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
		break;
	case 3:
		// TODO 減算描画は難しいか?
		Gdx.gl.glBlendEquation(GL20.GL_FUNC_SUBTRACT);
		sprite.setBlendFunction(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
		Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD);
		break;
	case 4:
		sprite.setBlendFunction(GL11.GL_ZERO, GL11.GL_SRC_COLOR);
		break;
	case 9:
		sprite.setBlendFunction(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ZERO);
		break;
	}

	if(color != null) {
		orgcolor = sprite.getColor();
		sprite.setColor(color);				
	} else {
		orgcolor = null;
	}
}
 
Example 28
Source Project: beatoraja   Source File: ShaderManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void dispose() {
	for(Entry<String, ShaderProgram> e : shaders.entrySet()) {
		if(e.getValue() != null) {
			e.getValue().dispose();
		}
	}
}
 
Example 29
Source Project: riiablo   Source File: PaletteIndexedBatch.java    License: Apache License 2.0 5 votes vote down vote up
public PaletteIndexedBatch(int size, ShaderProgram shader) {
  super(size);
  this.shader = shader;
  PALETTE_LOCATION    = shader.getUniformLocation("ColorTable");
  COLORMAP_LOCATION   = shader.getUniformLocation("ColorMap");
  BLENDMODE_LOCATION  = shader.getUniformLocation("blendMode");
  COLORMAPID_LOCATION = shader.getUniformLocation("colormapId");
  GAMMA_LOCATION      = shader.getUniformLocation("gamma");
}
 
Example 30
Source Project: Mundus   Source File: EditorTerrainShader.java    License: Apache License 2.0 5 votes vote down vote up
public EditorTerrainShader() {
    String vertexShader = "\n#define PICKER\n" + Gdx.files.classpath(VERTEX_SHADER).readString();
    String fragmentShader = "\n#define PICKER\n" + Gdx.files.classpath(FRAGMENT_SHADER).readString();

    program = new ShaderProgram(vertexShader, fragmentShader);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }
}